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..925fddea1 --- /dev/null +++ b/passes/silimate/reg_rename.h @@ -0,0 +1,54 @@ +/* + * 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 and trailing '.' +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] == '/') { + 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; +} + +YOSYS_NAMESPACE_END + +#endif