Skip to content

Commit

Permalink
const: unify printing as string
Browse files Browse the repository at this point in the history
  • Loading branch information
widlarizer committed Aug 15, 2024
1 parent 3191344 commit caf5086
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kernel/cellaigs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Aig::Aig(Cell *cell)
name = mkname_last + stringf(":%d%c", p.second.as_int(), mkname_is_signed ? 'S' : 'U');
} else {
mkname_last = name;
name += stringf(":%d", p.second.as_int());
name += ":" + p.second.pretty_fmt();
}

mkname_a_signed = false;
Expand Down
14 changes: 14 additions & 0 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,20 @@ std::vector<RTLIL::State> RTLIL::Const::to_bits() const
return b;
}

std::string RTLIL::Const::pretty_fmt() const {
if (get_if_str())
return decode_string();
else
return std::to_string(as_int());
}

std::string RTLIL::Const::pretty_fmt_undef() const {
if (get_if_str())
return decode_string();
else
return as_string();
}

bool RTLIL::Const::as_bool() const
{
bitvectorize();
Expand Down
3 changes: 3 additions & 0 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ struct RTLIL::Const
std::string as_string(std::string any = "-") const;
static Const from_string(const std::string &str);
std::vector<RTLIL::State> to_bits() const;
std::string pretty_fmt() const;
std::string pretty_fmt_undef() const;


std::string decode_string() const;
inline size_t size() const {
Expand Down
9 changes: 7 additions & 2 deletions passes/opt/opt_merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ struct OptMergeWorker
hash_conn_strings.push_back(s + "\n");
}

for (auto &it : cell->parameters)
hash_conn_strings.push_back("P " + it.first.str() + "=" + it.second.as_string() + "\n");
for (auto &it : cell->parameters) {
Const c = it.second;
std::string s = "P " + it.first.str() + "=";
s += c.pretty_fmt_undef();
s += "\n";
hash_conn_strings.push_back(s);
}

std::sort(hash_conn_strings.begin(), hash_conn_strings.end());

Expand Down

0 comments on commit caf5086

Please sign in to comment.