From d55f4daae29da1843f8eb8745429e497cd15fcf4 Mon Sep 17 00:00:00 2001 From: nella Date: Tue, 12 May 2026 17:06:21 +0200 Subject: [PATCH] Cleanup. --- kernel/rtlil.cc | 9 +++++++++ kernel/rtlil.h | 2 ++ passes/cmds/setattr.cc | 8 +------- passes/hierarchy/hierarchy.cc | 16 ++-------------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index a99f0803e..1a7dc6b41 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -615,6 +615,15 @@ int RTLIL::Const::as_int_saturating(bool is_signed) const return as_int(is_signed); } +void RTLIL::Const::tag_bare_integer_const(const std::string &value) +{ + if (value.empty() || value.find('\'') != std::string::npos) + return; + size_t start = (value[0] == '-' || value[0] == '+') ? 1 : 0; + if (start < value.size() && std::all_of(value.begin() + start, value.end(), ::isdigit)) + flags |= RTLIL::CONST_FLAG_SIGNED; +} + int RTLIL::Const::get_min_size(bool is_signed) const { if (empty()) return 0; diff --git a/kernel/rtlil.h b/kernel/rtlil.h index b32f9ea76..e55caf35a 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -1091,6 +1091,8 @@ public: // over/underflow, otherwise the max/min value for int depending on the sign. int as_int_saturating(bool is_signed = false) const; + void tag_bare_integer_const(const std::string &value); + std::string as_string(const char* any = "-") const; static Const from_string(const std::string &str); std::vector to_bits() const; diff --git a/passes/cmds/setattr.cc b/passes/cmds/setattr.cc index 6b30deb00..ef9bd0d34 100644 --- a/passes/cmds/setattr.cc +++ b/passes/cmds/setattr.cc @@ -41,13 +41,7 @@ struct setunset_t if (!RTLIL::SigSpec::parse(sig_value, nullptr, set_value)) log_cmd_error("Can't decode value '%s'!\n", set_value); value = sig_value.as_const(); - - if (!set_value.empty() && set_value.find('\'') == std::string::npos) { - size_t start = (set_value[0] == '-' || set_value[0] == '+') ? 1 : 0; - if (start < set_value.size() && std::all_of(set_value.begin() + start, set_value.end(), ::isdigit)) { - value.flags |= RTLIL::CONST_FLAG_SIGNED; - } - } + value.tag_bare_integer_const(set_value); } } }; diff --git a/passes/hierarchy/hierarchy.cc b/passes/hierarchy/hierarchy.cc index b81255305..34cedfd34 100644 --- a/passes/hierarchy/hierarchy.cc +++ b/passes/hierarchy/hierarchy.cc @@ -986,13 +986,7 @@ struct HierarchyPass : public Pass { if (!RTLIL::SigSpec::parse(sig_value, NULL, para.second)) log_cmd_error("Can't decode value '%s'!\n", para.second); RTLIL::Const c = sig_value.as_const(); - - if (!para.second.empty() && para.second.find('\'') == std::string::npos) { - size_t start = (para.second[0] == '-' || para.second[0] == '+') ? 1 : 0; - if (start < para.second.size() && std::all_of(para.second.begin() + start, para.second.end(), ::isdigit)) - c.flags |= RTLIL::CONST_FLAG_SIGNED; - } - + c.tag_bare_integer_const(para.second); top_parameters[RTLIL::escape_id(para.first)] = c; } } @@ -1082,13 +1076,7 @@ struct HierarchyPass : public Pass { if (!RTLIL::SigSpec::parse(sig_value, NULL, para.second)) log_cmd_error("Can't decode value '%s'!\n", para.second); RTLIL::Const c = sig_value.as_const(); - - if (!para.second.empty() && para.second.find('\'') == std::string::npos) { - size_t start = (para.second[0] == '-' || para.second[0] == '+') ? 1 : 0; - if (start < para.second.size() && std::all_of(para.second.begin() + start, para.second.end(), ::isdigit)) - c.flags |= RTLIL::CONST_FLAG_SIGNED; - } - + c.tag_bare_integer_const(para.second); top_parameters[RTLIL::escape_id(para.first)] = c; }