From eda603105e2aa72441bfc07662774a20f3b978fe Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Sun, 24 Aug 2014 15:14:00 +0200 Subject: [PATCH] Added is_signed argument to SigSpec.as_int() and Const.as_int() --- kernel/rtlil.cc | 11 +++++++---- kernel/rtlil.h | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 28a451345..df4d8b092 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 ebfe4ca29..d58873570 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; -- 2.30.2