summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/rtlil.cc11
-rw-r--r--kernel/rtlil.h4
2 files changed, 9 insertions, 6 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index 28a45134..df4d8b09 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -92,12 +92,15 @@ bool RTLIL::Const::as_bool() const
return false;
}
-int RTLIL::Const::as_int() const
+int RTLIL::Const::as_int(bool is_signed) const
{
- int ret = 0;
+ int32_t ret = 0;
for (size_t i = 0; i < bits.size() && i < 32; i++)
if (bits[i] == RTLIL::S1)
ret |= 1 << i;
+ if (is_signed && bits.back() == RTLIL::S1)
+ for (size_t i = bits.size(); i < 32; i++)
+ ret |= 1 << i;
return ret;
}
@@ -2647,14 +2650,14 @@ bool RTLIL::SigSpec::as_bool() const
return false;
}
-int RTLIL::SigSpec::as_int() const
+int RTLIL::SigSpec::as_int(bool is_signed) const
{
cover("kernel.rtlil.sigspec.as_int");
pack();
log_assert(is_fully_const() && SIZE(chunks_) <= 1);
if (width_)
- return chunks_[0].data.as_int();
+ return chunks_[0].data.as_int(is_signed);
return 0;
}
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index ebfe4ca2..d5887357 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -436,7 +436,7 @@ struct RTLIL::Const
bool operator !=(const RTLIL::Const &other) const;
bool as_bool() const;
- int as_int() const;
+ int as_int(bool is_signed = false) const;
std::string as_string() const;
std::string decode_string() const;
@@ -1038,7 +1038,7 @@ public:
bool has_marked_bits() const;
bool as_bool() const;
- int as_int() const;
+ int as_int(bool is_signed = false) const;
std::string as_string() const;
RTLIL::Const as_const() const;
RTLIL::Wire *as_wire() const;