@@ -204,12 +204,22 @@ const pool<IdString> &RTLIL::builtin_ff_cell_types() {
204204
205205#define check (condition ) log_assert(condition && " malformed Const union" )
206206
207- Const::bitvectype& Const::get_bits () const {
207+ const Const::bitvectype& Const::get_bits () const {
208208 check (is_bits ());
209209 return *get_if_bits ();
210210}
211211
212- std::string& Const::get_str () const {
212+ const std::string& Const::get_str () const {
213+ check (is_str ());
214+ return *get_if_str ();
215+ }
216+
217+ Const::bitvectype& Const::get_bits () {
218+ check (is_bits ());
219+ return *get_if_bits ();
220+ }
221+
222+ std::string& Const::get_str () {
213223 check (is_str ());
214224 return *get_if_str ();
215225}
@@ -395,7 +405,7 @@ bool RTLIL::Const::as_bool() const
395405 return false ;
396406 }
397407
398- bitvectype& bv = get_bits ();
408+ const bitvectype& bv = get_bits ();
399409 for (size_t i = 0 ; i < bv.size (); i++)
400410 if (bv[i] == State::S1)
401411 return true ;
@@ -542,7 +552,7 @@ std::string RTLIL::Const::decode_string() const
542552 if (auto str = get_if_str ())
543553 return *str;
544554
545- bitvectype& bv = get_bits ();
555+ const bitvectype& bv = get_bits ();
546556 const int n = GetSize (bv);
547557 const int n_over_8 = n / 8 ;
548558 std::string s;
@@ -590,7 +600,7 @@ bool RTLIL::Const::empty() const {
590600 }
591601}
592602
593- void RTLIL::Const::bitvectorize_internal () const {
603+ void RTLIL::Const::bitvectorize_internal () {
594604 if (tag == backing_tag::bits)
595605 return ;
596606
@@ -641,7 +651,7 @@ bool RTLIL::Const::is_fully_zero() const
641651 return true ;
642652 }
643653
644- bitvectype& bv = get_bits ();
654+ const bitvectype& bv = get_bits ();
645655
646656 for (const auto &bit : bv)
647657 if (bit != RTLIL::State::S0)
@@ -661,7 +671,7 @@ bool RTLIL::Const::is_fully_ones() const
661671 return true ;
662672 }
663673
664- bitvectype& bv = get_bits ();
674+ const bitvectype& bv = get_bits ();
665675 for (const auto &bit : bv)
666676 if (bit != RTLIL::State::S1)
667677 return false ;
@@ -676,7 +686,7 @@ bool RTLIL::Const::is_fully_def() const
676686 if (is_str ())
677687 return true ;
678688
679- bitvectype& bv = get_bits ();
689+ const bitvectype& bv = get_bits ();
680690 for (const auto &bit : bv)
681691 if (bit != RTLIL::State::S0 && bit != RTLIL::State::S1)
682692 return false ;
@@ -691,7 +701,7 @@ bool RTLIL::Const::is_fully_undef() const
691701 if (auto str = get_if_str ())
692702 return str->empty ();
693703
694- bitvectype& bv = get_bits ();
704+ const bitvectype& bv = get_bits ();
695705 for (const auto &bit : bv)
696706 if (bit != RTLIL::State::Sx && bit != RTLIL::State::Sz)
697707 return false ;
@@ -706,7 +716,7 @@ bool RTLIL::Const::is_fully_undef_x_only() const
706716 if (auto str = get_if_str ())
707717 return str->empty ();
708718
709- bitvectype& bv = get_bits ();
719+ const bitvectype& bv = get_bits ();
710720 for (const auto &bit : bv)
711721 if (bit != RTLIL::State::Sx)
712722 return false ;
0 commit comments