@@ -240,12 +240,22 @@ const pool<IdString> &RTLIL::builtin_ff_cell_types() {
240
240
241
241
#define check (condition ) log_assert(condition && " malformed Const union" )
242
242
243
- Const::bitvectype& Const::get_bits () const {
243
+ const Const::bitvectype& Const::get_bits () const {
244
244
check (is_bits ());
245
245
return *get_if_bits ();
246
246
}
247
247
248
- std::string& Const::get_str () const {
248
+ const std::string& Const::get_str () const {
249
+ check (is_str ());
250
+ return *get_if_str ();
251
+ }
252
+
253
+ Const::bitvectype& Const::get_bits () {
254
+ check (is_bits ());
255
+ return *get_if_bits ();
256
+ }
257
+
258
+ std::string& Const::get_str () {
249
259
check (is_str ());
250
260
return *get_if_str ();
251
261
}
@@ -431,7 +441,7 @@ bool RTLIL::Const::as_bool() const
431
441
return false ;
432
442
}
433
443
434
- bitvectype& bv = get_bits ();
444
+ const bitvectype& bv = get_bits ();
435
445
for (size_t i = 0 ; i < bv.size (); i++)
436
446
if (bv[i] == State::S1)
437
447
return true ;
@@ -579,7 +589,7 @@ std::string RTLIL::Const::decode_string() const
579
589
if (auto str = get_if_str ())
580
590
return *str;
581
591
582
- bitvectype& bv = get_bits ();
592
+ const bitvectype& bv = get_bits ();
583
593
const int n = GetSize (bv);
584
594
const int n_over_8 = n / 8 ;
585
595
std::string s;
@@ -627,7 +637,7 @@ bool RTLIL::Const::empty() const {
627
637
}
628
638
}
629
639
630
- void RTLIL::Const::bitvectorize_internal () const {
640
+ void RTLIL::Const::bitvectorize_internal () {
631
641
if (tag == backing_tag::bits)
632
642
return ;
633
643
@@ -678,7 +688,7 @@ bool RTLIL::Const::is_fully_zero() const
678
688
return true ;
679
689
}
680
690
681
- bitvectype& bv = get_bits ();
691
+ const bitvectype& bv = get_bits ();
682
692
683
693
for (const auto &bit : bv)
684
694
if (bit != RTLIL::State::S0)
@@ -698,7 +708,7 @@ bool RTLIL::Const::is_fully_ones() const
698
708
return true ;
699
709
}
700
710
701
- bitvectype& bv = get_bits ();
711
+ const bitvectype& bv = get_bits ();
702
712
for (const auto &bit : bv)
703
713
if (bit != RTLIL::State::S1)
704
714
return false ;
@@ -713,7 +723,7 @@ bool RTLIL::Const::is_fully_def() const
713
723
if (is_str ())
714
724
return true ;
715
725
716
- bitvectype& bv = get_bits ();
726
+ const bitvectype& bv = get_bits ();
717
727
for (const auto &bit : bv)
718
728
if (bit != RTLIL::State::S0 && bit != RTLIL::State::S1)
719
729
return false ;
@@ -728,7 +738,7 @@ bool RTLIL::Const::is_fully_undef() const
728
738
if (auto str = get_if_str ())
729
739
return str->empty ();
730
740
731
- bitvectype& bv = get_bits ();
741
+ const bitvectype& bv = get_bits ();
732
742
for (const auto &bit : bv)
733
743
if (bit != RTLIL::State::Sx && bit != RTLIL::State::Sz)
734
744
return false ;
@@ -743,7 +753,7 @@ bool RTLIL::Const::is_fully_undef_x_only() const
743
753
if (auto str = get_if_str ())
744
754
return str->empty ();
745
755
746
- bitvectype& bv = get_bits ();
756
+ const bitvectype& bv = get_bits ();
747
757
for (const auto &bit : bv)
748
758
if (bit != RTLIL::State::Sx)
749
759
return false ;
@@ -779,7 +789,7 @@ Hasher RTLIL::Const::hash_into(Hasher h) const
779
789
780
790
// If the bits are all 0/1, hash packed bits using the string hash.
781
791
// Otherwise hash the leading packed bits with the rest of the bits individually.
782
- bitvectype &bv = get_bits ();
792
+ const bitvectype &bv = get_bits ();
783
793
int size = GetSize (bv);
784
794
std::string packed;
785
795
int packed_size = (size + 7 ) >> 3 ;
0 commit comments