mirror of https://github.com/YosysHQ/yosys.git
Added is_signed argument to SigSpec.as_int() and Const.as_int()
This commit is contained in:
parent
9c5a63c52c
commit
eda603105e
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue