diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 9cf8715f4..622c3d93c 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -4568,19 +4568,15 @@ const RTLIL::Const &RTLIL::Cell::getParam(RTLIL::IdString paramname) const std::map RTLIL::Cell::getParamsAsInts() const { std::map result; - for (auto ¶m : parameters) { - std::string key = param.first.str(); - if (key.size() > 0 && key[0] == '\\') - key = key.substr(1); - result[key] = param.second.as_int(); - } + for (const auto ¶m : parameters) + result[RTLIL::unescape_id(param.first)] = param.second.as_int(); return result; } double RTLIL::Cell::maxInputConstRatio() const { double max_ratio = 0.0; - for (auto &conn : connections_) { + for (const auto &conn : connections_) { if (input(conn.first)) { double ratio = conn.second.const_ratio(); if (ratio > max_ratio) @@ -4590,6 +4586,24 @@ double RTLIL::Cell::maxInputConstRatio() const return max_ratio; } +std::vector RTLIL::Cell::getOutputPortNames() const +{ + std::vector result; + for (const auto &conn : connections_) { + if (output(conn.first)) + result.push_back(RTLIL::unescape_id(conn.first)); + } + return result; +} + +std::map RTLIL::Cell::getConnectionSizes() const +{ + std::map result; + for (const auto &conn : connections_) + result[RTLIL::unescape_id(conn.first)] = conn.second.size(); + return result; +} + void RTLIL::Cell::sort() { connections_.sort(sort_by_id_str()); diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 3d2e54a1a..7964ac5a5 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -2539,6 +2539,12 @@ public: // Returns the maximum const_ratio() across all input ports, 0.0 if no input ports double maxInputConstRatio() const; + // Returns the names of all output ports (backslash-stripped) + std::vector getOutputPortNames() const; + + // Returns {port_name: sig.size()} for all connections, port names backslash-stripped + std::map getConnectionSizes() const; + void sort(); void check(); void fixup_parameters(bool set_a_signed = false, bool set_b_signed = false);