normalize scope

This commit is contained in:
Stan Lee 2026-04-08 16:18:55 -07:00
parent ed11f4c135
commit 146491af22
3 changed files with 54 additions and 3 deletions

View File

@ -26,6 +26,7 @@
#include "kernel/yw.h"
#include "kernel/json.h"
#include "kernel/fmt.h"
#include "passes/silimate/reg_rename.h"
#include <ctime>
#include <sstream>
@ -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()) {

View File

@ -20,6 +20,7 @@
#include "kernel/fstdata.h"
#include "kernel/yosys.h"
#include "passes/silimate/reg_rename.h"
#include <regex>
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;

View File

@ -0,0 +1,49 @@
/*
* yosys -- Yosys Open SYnthesis Suite
*
* Copyright (C) 2026 Stan Lee <stan@silimate.com>
*
* 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 <string>
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