diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 9bb218f221b..a3801116e13 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -200,13 +200,15 @@ const pool &RTLIL::builtin_ff_cell_types() { return res; } +#define check(condition) log_assert(condition && "malformed Const union") + Const::bitvectype& Const::get_bits() const { - log_assert(is_bits() && "malformed Const union"); + check(is_bits()); return *get_if_bits(); } std::string& Const::get_str() const { - log_assert(is_str() && "malformed Const union"); + check(is_str()); return *get_if_str(); } @@ -260,7 +262,7 @@ RTLIL::Const::Const(const RTLIL::Const &other) { else if (is_bits()) new ((void*)&bits_) bitvectype(other.get_bits()); else - log_assert(false && "malformed Const union"); + check(false); } RTLIL::Const::Const(RTLIL::Const &&other) { @@ -271,7 +273,7 @@ RTLIL::Const::Const(RTLIL::Const &&other) { else if (is_bits()) new ((void*)&bits_) bitvectype(std::move(other.get_bits())); else - log_assert(false && "malformed Const union"); + check(false); } RTLIL::Const &RTLIL::Const::operator =(const RTLIL::Const &other) { @@ -279,7 +281,7 @@ RTLIL::Const &RTLIL::Const::operator =(const RTLIL::Const &other) { if (other.is_str()) { if (!is_str()) { // sketchy zone - log_assert(is_bits() && "malformed Const union"); + check(is_bits()); bits_.~bitvectype(); (void)new ((void*)&str_) std::string(); } @@ -288,14 +290,14 @@ RTLIL::Const &RTLIL::Const::operator =(const RTLIL::Const &other) { } else if (other.is_bits()) { if (!is_bits()) { // sketchy zone - log_assert(is_str() && "malformed Const union"); + check(is_str()); str_.~string(); (void)new ((void*)&bits_) bitvectype(); } tag = other.tag; get_bits() = other.get_bits(); } else { - log_assert(false && "malformed Const union"); + check(false); } return *this; } @@ -306,7 +308,7 @@ RTLIL::Const::~Const() { else if (is_str()) str_.~string(); else - log_assert(false && "malformed Const union"); + check(false); } bool RTLIL::Const::operator<(const RTLIL::Const &other) const @@ -450,7 +452,7 @@ int RTLIL::Const::size() const { if (is_str()) return 8 * str_.size(); else { - log_assert(is_bits() && "malformed Const union"); + check(is_bits()); return bits_.size(); } } @@ -459,7 +461,7 @@ bool RTLIL::Const::empty() const { if (is_str()) return str_.empty(); else { - log_assert(is_bits() && "malformed Const union"); + check(is_bits()); return bits_.empty(); } } @@ -468,7 +470,7 @@ void RTLIL::Const::bitvectorize() const { if (tag == backing_tag::bits) return; - log_assert(is_str() && "malformed Const union"); + check(is_str()); bitvectype new_bits; @@ -596,6 +598,7 @@ RTLIL::Const RTLIL::Const::extract(int offset, int len, RTLIL::State padding) co ret_bv.push_back(i < GetSize(*this) ? (*this)[i] : padding); return RTLIL::Const(ret_bv); } +#undef check /* check(condition) for Const */ bool RTLIL::AttrObject::has_attribute(const RTLIL::IdString &id) const {