From 146491af220364efb4449bbbd78eb547537f1817 Mon Sep 17 00:00:00 2001 From: Stan Lee Date: Wed, 8 Apr 2026 16:18:55 -0700 Subject: [PATCH 1/2] normalize scope --- passes/sat/sim.cc | 5 ++-- passes/silimate/reg_rename.cc | 3 ++- passes/silimate/reg_rename.h | 49 +++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 passes/silimate/reg_rename.h diff --git a/passes/sat/sim.cc b/passes/sat/sim.cc index 88127a8b2..e445624ce 100644 --- a/passes/sat/sim.cc +++ b/passes/sat/sim.cc @@ -26,6 +26,7 @@ #include "kernel/yw.h" #include "kernel/json.h" #include "kernel/fmt.h" +#include "passes/silimate/reg_rename.h" #include #include @@ -3161,7 +3162,7 @@ struct SimPass : public Pass { continue; } if (args[argidx] == "-scope" && argidx+1 < args.size()) { - worker.scope = args[++argidx]; + worker.scope = normalize_scope(args[++argidx]); continue; } if (args[argidx] == "-start" && argidx+1 < args.size()) { @@ -3335,7 +3336,7 @@ struct Fst2TbPass : public Pass { continue; } if (args[argidx] == "-scope" && argidx+1 < args.size()) { - worker.scope = args[++argidx]; + worker.scope = normalize_scope(args[++argidx]); continue; } if (args[argidx] == "-start" && argidx+1 < args.size()) { diff --git a/passes/silimate/reg_rename.cc b/passes/silimate/reg_rename.cc index 81a06a425..b9601d927 100644 --- a/passes/silimate/reg_rename.cc +++ b/passes/silimate/reg_rename.cc @@ -20,6 +20,7 @@ #include "kernel/fstdata.h" #include "kernel/yosys.h" +#include "passes/silimate/reg_rename.h" #include USING_YOSYS_NAMESPACE @@ -187,7 +188,7 @@ struct RegRenamePass : public Pass { continue; } if (args[argidx] == "-scope" && argidx + 1 < args.size()) { - scope = args[++argidx]; + scope = normalize_scope(args[++argidx]); continue; } break; diff --git a/passes/silimate/reg_rename.h b/passes/silimate/reg_rename.h new file mode 100644 index 000000000..dc3970659 --- /dev/null +++ b/passes/silimate/reg_rename.h @@ -0,0 +1,49 @@ +/* + * yosys -- Yosys Open SYnthesis Suite + * + * Copyright (C) 2026 Stan Lee + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef REG_RENAME_H +#define REG_RENAME_H + +#include + +YOSYS_NAMESPACE_BEGIN + +// Normalize scope path: replace '/' with '.' and remove leading '.' +// This allows supporting both Verdi-style (/top/module) and Yosys-style (top.module) scope paths +inline std::string normalize_scope(std::string scope) +{ + if (scope.empty()) + return scope; + + // Replace all '/' with '.' + for (size_t i = 0; i < scope.length(); i++) { + if (scope[i] == '/') + scope[i] = '.'; + } + + // Remove leading '.' if present + if (scope[0] == '.') + scope = scope.substr(1); + + return scope; +} + +YOSYS_NAMESPACE_END + +#endif From 0bf20fdd192105f3ee36a1f7c33136e356a4d8ba Mon Sep 17 00:00:00 2001 From: Stan Lee Date: Wed, 8 Apr 2026 16:33:10 -0700 Subject: [PATCH 2/2] handle edge cases --- passes/silimate/reg_rename.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/passes/silimate/reg_rename.h b/passes/silimate/reg_rename.h index dc3970659..925fddea1 100644 --- a/passes/silimate/reg_rename.h +++ b/passes/silimate/reg_rename.h @@ -24,8 +24,7 @@ YOSYS_NAMESPACE_BEGIN -// Normalize scope path: replace '/' with '.' and remove leading '.' -// This allows supporting both Verdi-style (/top/module) and Yosys-style (top.module) scope paths +// Normalize scope path: replace '/' with '.' and remove leading and trailing '.' inline std::string normalize_scope(std::string scope) { if (scope.empty()) @@ -33,13 +32,19 @@ inline std::string normalize_scope(std::string scope) // Replace all '/' with '.' for (size_t i = 0; i < scope.length(); i++) { - if (scope[i] == '/') + if (scope[i] == '/') { + if (i > 0 && scope[i-1] == '\\') continue; // skip escaped '/' scope[i] = '.'; + } } // Remove leading '.' if present if (scope[0] == '.') scope = scope.substr(1); + + // Remove trailing '.' if present (from a trailing '/') + if (!scope.empty() && scope.back() == '.') + scope = scope.substr(0, scope.size() - 1); return scope; }