From 61caa5e042ecb59770b2e3bcafdda60bc094cbb2 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Thu, 28 Aug 2025 06:00:50 +0000 Subject: [PATCH] Deprecate Const::bitvectorize() --- kernel/rtlil.cc | 26 +++++++++++++------------- kernel/rtlil.h | 7 +++++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 22467fa8e..0afe2a3c0 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -380,7 +380,7 @@ bool RTLIL::Const::operator !=(const RTLIL::Const &other) const std::vector& RTLIL::Const::bits_internal() { - bitvectorize(); + bitvectorize_internal(); return get_bits(); } @@ -394,7 +394,7 @@ std::vector RTLIL::Const::to_bits() const bool RTLIL::Const::as_bool() const { - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); for (size_t i = 0; i < bv.size(); i++) if (bv[i] == State::S1) @@ -404,7 +404,7 @@ bool RTLIL::Const::as_bool() const int RTLIL::Const::as_int(bool is_signed) const { - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); int32_t ret = 0; for (size_t i = 0; i < bv.size() && i < 32; i++) @@ -496,7 +496,7 @@ std::optional RTLIL::Const::as_int_compress(bool is_signed) const std::string RTLIL::Const::as_string(const char* any) const { - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); std::string ret; ret.reserve(bv.size()); @@ -534,7 +534,7 @@ std::string RTLIL::Const::decode_string() const if (auto str = get_if_str()) return *str; - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); const int n = GetSize(bv); const int n_over_8 = n / 8; @@ -583,7 +583,7 @@ bool RTLIL::Const::empty() const { } } -void RTLIL::Const::bitvectorize() const { +void RTLIL::Const::bitvectorize_internal() const { if (tag == backing_tag::bits) return; @@ -609,7 +609,7 @@ void RTLIL::Const::bitvectorize() const { } void RTLIL::Const::append(const RTLIL::Const &other) { - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); bv.insert(bv.end(), other.begin(), other.end()); } @@ -625,7 +625,7 @@ RTLIL::State RTLIL::Const::const_iterator::operator*() const { bool RTLIL::Const::is_fully_zero() const { - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); cover("kernel.rtlil.const.is_fully_zero"); @@ -638,7 +638,7 @@ bool RTLIL::Const::is_fully_zero() const bool RTLIL::Const::is_fully_ones() const { - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); cover("kernel.rtlil.const.is_fully_ones"); @@ -653,7 +653,7 @@ bool RTLIL::Const::is_fully_def() const { cover("kernel.rtlil.const.is_fully_def"); - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); for (const auto &bit : bv) @@ -667,7 +667,7 @@ bool RTLIL::Const::is_fully_undef() const { cover("kernel.rtlil.const.is_fully_undef"); - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); for (const auto &bit : bv) @@ -681,7 +681,7 @@ bool RTLIL::Const::is_fully_undef_x_only() const { cover("kernel.rtlil.const.is_fully_undef_x_only"); - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); for (const auto &bit : bv) @@ -695,7 +695,7 @@ bool RTLIL::Const::is_onehot(int *pos) const { cover("kernel.rtlil.const.is_onehot"); - bitvectorize(); + bitvectorize_internal(); bitvectype& bv = get_bits(); bool found = false; diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 02c8190dc..0691ac2a6 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -838,6 +838,7 @@ private: bitvectype& get_bits() const; std::string& get_str() const; std::vector& bits_internal(); + void bitvectorize_internal() const; public: Const() : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(std::vector()) {} @@ -866,8 +867,11 @@ public: bool operator ==(const RTLIL::Const &other) const; bool operator !=(const RTLIL::Const &other) const; - [[deprecated]] + [[deprecated("Don't use direct access to the internal std::vector, that's an implementation detail.")]] std::vector& bits() { return bits_internal(); } + [[deprecated("Don't call bitvectorize() directly, it's an implementation detail.")]] + void bitvectorize() const { bitvectorize_internal(); } + bool as_bool() const; // Convert the constant value to a C++ int. @@ -896,7 +900,6 @@ public: std::string decode_string() const; int size() const; bool empty() const; - void bitvectorize() const; void append(const RTLIL::Const &other); void set(int i, RTLIL::State state) {