Merge pull request #144 from Silimate/sim

[ENG-1869] Normalize scopes
This commit is contained in:
Akash Levy 2026-04-09 19:11:11 -07:00 committed by GitHub
commit 485cc675e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 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,54 @@
/*
* 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 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