@@ -204,12 +204,22 @@ const pool<IdString> &RTLIL::builtin_ff_cell_types() {
204
204
205
205
#define check (condition ) log_assert(condition && " malformed Const union" )
206
206
207
- Const::bitvectype& Const::get_bits () const {
207
+ const Const::bitvectype& Const::get_bits () const {
208
208
check (is_bits ());
209
209
return *get_if_bits ();
210
210
}
211
211
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 () {
213
223
check (is_str ());
214
224
return *get_if_str ();
215
225
}
@@ -395,7 +405,7 @@ bool RTLIL::Const::as_bool() const
395
405
return false ;
396
406
}
397
407
398
- bitvectype& bv = get_bits ();
408
+ const bitvectype& bv = get_bits ();
399
409
for (size_t i = 0 ; i < bv.size (); i++)
400
410
if (bv[i] == State::S1)
401
411
return true ;
@@ -542,7 +552,7 @@ std::string RTLIL::Const::decode_string() const
542
552
if (auto str = get_if_str ())
543
553
return *str;
544
554
545
- bitvectype& bv = get_bits ();
555
+ const bitvectype& bv = get_bits ();
546
556
const int n = GetSize (bv);
547
557
const int n_over_8 = n / 8 ;
548
558
std::string s;
@@ -590,7 +600,7 @@ bool RTLIL::Const::empty() const {
590
600
}
591
601
}
592
602
593
- void RTLIL::Const::bitvectorize_internal () const {
603
+ void RTLIL::Const::bitvectorize_internal () {
594
604
if (tag == backing_tag::bits)
595
605
return ;
596
606
@@ -641,7 +651,7 @@ bool RTLIL::Const::is_fully_zero() const
641
651
return true ;
642
652
}
643
653
644
- bitvectype& bv = get_bits ();
654
+ const bitvectype& bv = get_bits ();
645
655
646
656
for (const auto &bit : bv)
647
657
if (bit != RTLIL::State::S0)
@@ -661,7 +671,7 @@ bool RTLIL::Const::is_fully_ones() const
661
671
return true ;
662
672
}
663
673
664
- bitvectype& bv = get_bits ();
674
+ const bitvectype& bv = get_bits ();
665
675
for (const auto &bit : bv)
666
676
if (bit != RTLIL::State::S1)
667
677
return false ;
@@ -676,7 +686,7 @@ bool RTLIL::Const::is_fully_def() const
676
686
if (is_str ())
677
687
return true ;
678
688
679
- bitvectype& bv = get_bits ();
689
+ const bitvectype& bv = get_bits ();
680
690
for (const auto &bit : bv)
681
691
if (bit != RTLIL::State::S0 && bit != RTLIL::State::S1)
682
692
return false ;
@@ -691,7 +701,7 @@ bool RTLIL::Const::is_fully_undef() const
691
701
if (auto str = get_if_str ())
692
702
return str->empty ();
693
703
694
- bitvectype& bv = get_bits ();
704
+ const bitvectype& bv = get_bits ();
695
705
for (const auto &bit : bv)
696
706
if (bit != RTLIL::State::Sx && bit != RTLIL::State::Sz)
697
707
return false ;
@@ -706,7 +716,7 @@ bool RTLIL::Const::is_fully_undef_x_only() const
706
716
if (auto str = get_if_str ())
707
717
return str->empty ();
708
718
709
- bitvectype& bv = get_bits ();
719
+ const bitvectype& bv = get_bits ();
710
720
for (const auto &bit : bv)
711
721
if (bit != RTLIL::State::Sx)
712
722
return false ;
@@ -742,7 +752,7 @@ Hasher RTLIL::Const::hash_into(Hasher h) const
742
752
743
753
// If the bits are all 0/1, hash packed bits using the string hash.
744
754
// Otherwise hash the leading packed bits with the rest of the bits individually.
745
- bitvectype &bv = get_bits ();
755
+ const bitvectype &bv = get_bits ();
746
756
int size = GetSize (bv);
747
757
std::string packed;
748
758
int packed_size = (size + 7 ) >> 3 ;
0 commit comments