mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-09 07:45:08 +00:00
Stop using mutable in Const.
Now that we only call `bitvectorize()` in non-const methods, we can move the casting-away-const to only happen in `bitvectorize()`, which is deprecated so only some plugins (maybe) are using it. This means `const` `Const` methods don't change the underlying data, which means they'll be safe to use from multiple threads if/when we want to do that.
This commit is contained in:
parent
29810f1e7c
commit
fee2b8992c
2 changed files with 36 additions and 22 deletions
|
|
@ -240,12 +240,22 @@ const pool<IdString> &RTLIL::builtin_ff_cell_types() {
|
|||
|
||||
#define check(condition) log_assert(condition && "malformed Const union")
|
||||
|
||||
Const::bitvectype& Const::get_bits() const {
|
||||
const Const::bitvectype& Const::get_bits() const {
|
||||
check(is_bits());
|
||||
return *get_if_bits();
|
||||
}
|
||||
|
||||
std::string& Const::get_str() const {
|
||||
const std::string& Const::get_str() const {
|
||||
check(is_str());
|
||||
return *get_if_str();
|
||||
}
|
||||
|
||||
Const::bitvectype& Const::get_bits() {
|
||||
check(is_bits());
|
||||
return *get_if_bits();
|
||||
}
|
||||
|
||||
std::string& Const::get_str() {
|
||||
check(is_str());
|
||||
return *get_if_str();
|
||||
}
|
||||
|
|
@ -431,7 +441,7 @@ bool RTLIL::Const::as_bool() const
|
|||
return false;
|
||||
}
|
||||
|
||||
bitvectype& bv = get_bits();
|
||||
const bitvectype& bv = get_bits();
|
||||
for (size_t i = 0; i < bv.size(); i++)
|
||||
if (bv[i] == State::S1)
|
||||
return true;
|
||||
|
|
@ -448,7 +458,7 @@ int RTLIL::Const::as_int(bool is_signed) const
|
|||
ret |= static_cast<unsigned char>((*s)[size - i]) << ((i - 1) * 8);
|
||||
// If is_signed and the string is shorter than 4 bytes then apply sign extension.
|
||||
if (is_signed && size > 0 && size < 4 && ((*s)[0] & 0x80))
|
||||
ret |= -1 << size*8;
|
||||
ret |= UINT32_MAX << size*8;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +468,7 @@ int RTLIL::Const::as_int(bool is_signed) const
|
|||
if (bv[i] == State::S1)
|
||||
ret |= 1 << i;
|
||||
if (is_signed && significant_bits > 0 && significant_bits < 32 && bv.back() == State::S1 )
|
||||
ret |= -1 << significant_bits;
|
||||
ret |= UINT32_MAX << significant_bits;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -579,7 +589,7 @@ std::string RTLIL::Const::decode_string() const
|
|||
if (auto str = get_if_str())
|
||||
return *str;
|
||||
|
||||
bitvectype& bv = get_bits();
|
||||
const bitvectype& bv = get_bits();
|
||||
const int n = GetSize(bv);
|
||||
const int n_over_8 = n / 8;
|
||||
std::string s;
|
||||
|
|
@ -627,7 +637,7 @@ bool RTLIL::Const::empty() const {
|
|||
}
|
||||
}
|
||||
|
||||
void RTLIL::Const::bitvectorize_internal() const {
|
||||
void RTLIL::Const::bitvectorize_internal() {
|
||||
if (tag == backing_tag::bits)
|
||||
return;
|
||||
|
||||
|
|
@ -678,7 +688,7 @@ bool RTLIL::Const::is_fully_zero() const
|
|||
return true;
|
||||
}
|
||||
|
||||
bitvectype& bv = get_bits();
|
||||
const bitvectype& bv = get_bits();
|
||||
|
||||
for (const auto &bit : bv)
|
||||
if (bit != RTLIL::State::S0)
|
||||
|
|
@ -698,7 +708,7 @@ bool RTLIL::Const::is_fully_ones() const
|
|||
return true;
|
||||
}
|
||||
|
||||
bitvectype& bv = get_bits();
|
||||
const bitvectype& bv = get_bits();
|
||||
for (const auto &bit : bv)
|
||||
if (bit != RTLIL::State::S1)
|
||||
return false;
|
||||
|
|
@ -713,7 +723,7 @@ bool RTLIL::Const::is_fully_def() const
|
|||
if (is_str())
|
||||
return true;
|
||||
|
||||
bitvectype& bv = get_bits();
|
||||
const bitvectype& bv = get_bits();
|
||||
for (const auto &bit : bv)
|
||||
if (bit != RTLIL::State::S0 && bit != RTLIL::State::S1)
|
||||
return false;
|
||||
|
|
@ -728,7 +738,7 @@ bool RTLIL::Const::is_fully_undef() const
|
|||
if (auto str = get_if_str())
|
||||
return str->empty();
|
||||
|
||||
bitvectype& bv = get_bits();
|
||||
const bitvectype& bv = get_bits();
|
||||
for (const auto &bit : bv)
|
||||
if (bit != RTLIL::State::Sx && bit != RTLIL::State::Sz)
|
||||
return false;
|
||||
|
|
@ -743,7 +753,7 @@ bool RTLIL::Const::is_fully_undef_x_only() const
|
|||
if (auto str = get_if_str())
|
||||
return str->empty();
|
||||
|
||||
bitvectype& bv = get_bits();
|
||||
const bitvectype& bv = get_bits();
|
||||
for (const auto &bit : bv)
|
||||
if (bit != RTLIL::State::Sx)
|
||||
return false;
|
||||
|
|
@ -779,7 +789,7 @@ Hasher RTLIL::Const::hash_into(Hasher h) const
|
|||
|
||||
// If the bits are all 0/1, hash packed bits using the string hash.
|
||||
// Otherwise hash the leading packed bits with the rest of the bits individually.
|
||||
bitvectype &bv = get_bits();
|
||||
const bitvectype &bv = get_bits();
|
||||
int size = GetSize(bv);
|
||||
std::string packed;
|
||||
int packed_size = (size + 7) >> 3;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue