From e4d4de10202a6757795d221deaca9837814cd5a0 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Tue, 16 Sep 2025 17:41:55 +0200 Subject: [PATCH] driver: add --no-private-id-locs and NEWER_ID --- kernel/driver.cc | 2 ++ kernel/yosys.cc | 13 ++++++++++++- kernel/yosys_common.h | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/kernel/driver.cc b/kernel/driver.cc index bbe4e46f3..1274d5fc5 100644 --- a/kernel/driver.cc +++ b/kernel/driver.cc @@ -292,6 +292,7 @@ int main(int argc, char **argv) cxxopts::value>(), "") ("g,debug", "globally enable debug log messages") ("perffile", "write a JSON performance log to ", cxxopts::value(), "") + ("no-private-id-locs", "turn off putting source file locations into object IDs") ; options.parse_positional({"infile"}); @@ -436,6 +437,7 @@ int main(int argc, char **argv) log_experimentals_ignored.insert(ignores.begin(), ignores.end()); } if (result.count("perffile")) perffile = result["perffile"].as(); + if (result.count("no-private-id-locs")) yosys_private_id_locs = false; if (result.count("infile")) { frontend_files = result["infile"].as>(); } diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 95beca75c..78d9ebd08 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -82,6 +82,7 @@ YOSYS_NAMESPACE_BEGIN int autoidx = 1; int yosys_xtrace = 0; bool yosys_write_versions = true; +bool yosys_private_id_locs = true; const char* yosys_maybe_version() { if (yosys_write_versions) return yosys_version_str; @@ -272,6 +273,16 @@ void yosys_shutdown() } RTLIL::IdString new_id(std::string file, int line, std::string func) +{ + return newer_id(file, line, func); +} + +RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix) +{ + return newer_id_suffix(file, line, func, suffix); +} + +RTLIL::IdString newer_id(std::string file, int line, std::string func) { #ifdef _WIN32 size_t pos = file.find_last_of("/\\"); @@ -288,7 +299,7 @@ RTLIL::IdString new_id(std::string file, int line, std::string func) return stringf("$auto$%s:%d:%s$%d", file, line, func, autoidx++); } -RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix) +RTLIL::IdString newer_id_suffix(std::string file, int line, std::string func, std::string suffix) { #ifdef _WIN32 size_t pos = file.find_last_of("/\\"); diff --git a/kernel/yosys_common.h b/kernel/yosys_common.h index fd84dd74e..01f4da3a4 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -268,8 +268,13 @@ inline int GetSize(RTLIL::Wire *wire); extern int autoidx; extern int yosys_xtrace; extern bool yosys_write_versions; +extern bool yosys_private_id_locs; +RTLIL::IdString newer_id(std::string file, int line, std::string func); +RTLIL::IdString newer_id_suffix(std::string file, int line, std::string func, std::string suffix); +[[deprecated("Use NEWER_ID instead of NEW_ID")]] RTLIL::IdString new_id(std::string file, int line, std::string func); +[[deprecated("Use NEWER_ID_SUFFIX instead of NEW_ID_SUFFIX")]] RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std::string suffix); #define NEW_ID \ @@ -277,6 +282,16 @@ RTLIL::IdString new_id_suffix(std::string file, int line, std::string func, std: #define NEW_ID_SUFFIX(suffix) \ YOSYS_NAMESPACE_PREFIX new_id_suffix(__FILE__, __LINE__, __FUNCTION__, suffix) +#define NEWER_ID \ + (YOSYS_NAMESPACE_PREFIX yosys_private_id_locs ? \ + YOSYS_NAMESPACE_PREFIX newer_id(__FILE__, __LINE__, __FUNCTION__) : \ + YOSYS_NAMESPACE_PREFIX newer_id("?", 0, "?")) + +#define NEWER_ID_SUFFIX(suffix) \ + (YOSYS_NAMESPACE_PREFIX yosys_private_id_locs ? \ + YOSYS_NAMESPACE_PREFIX newer_id_suffix(__FILE__, __LINE__, __FUNCTION__, suffix) : \ + YOSYS_NAMESPACE_PREFIX newer_id_suffix("?", 0, "?", suffix)) + namespace ID = RTLIL::ID;