From ca9d1e5fd8e15a544b41da27596f963fc117812c Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Mon, 8 Sep 2025 12:59:13 +0200 Subject: [PATCH] Add IdString const &id_string() const to StaticIdString and IdString The vast majority of ID(...) uses are in a context that is overloaded for StaticIdString or will cause implicit conversion to an IdString constant reference. For some sufficently overloaded contexts, implicit conversion may fail, so it's useful to have a method to force obtaining a `IdString const &` from an ID(...) use. When turning all literal IdStrings of the codebase into StaticIdStrings this was needed in exactly one place, for which this commit adds an `id_string()` call. --- kernel/rtlil.h | 3 +++ passes/cmds/example_dt.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 999b60fd7..471aa5e5f 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -121,6 +121,7 @@ namespace RTLIL constexpr StaticIdString(StaticId id, const IdString &id_str) : id_str(id_str), id(id) {} constexpr inline operator const IdString &() const { return id_str; } constexpr inline int index() const { return static_cast(id); } + constexpr inline const IdString &id_string() const { return id_str; } const IdString &id_str; const StaticId id; @@ -343,6 +344,8 @@ struct RTLIL::IdString *this = id; } + constexpr inline const IdString &id_string() const { return *this; } + inline const char *c_str() const { return global_id_storage_.at(index_); } diff --git a/passes/cmds/example_dt.cc b/passes/cmds/example_dt.cc index b10f50502..7d1c42a79 100644 --- a/passes/cmds/example_dt.cc +++ b/passes/cmds/example_dt.cc @@ -77,7 +77,7 @@ struct ExampleDtPass : public Pass auto enqueue = [&](DriveSpec const &spec) { int index = queue(spec); if (index == GetSize(graph_nodes)) - graph_nodes.emplace_back(compute_graph.add(ID($pending), index).index()); + graph_nodes.emplace_back(compute_graph.add(ID($pending).id_string(), index).index()); //if (index >= GetSize(graph_nodes)) return compute_graph[graph_nodes[index]]; };