From 7ddf0b6d7cf5483599bedfec1c5dd59a7551d498 Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Mon, 17 Mar 2025 02:29:39 -0700 Subject: [PATCH] Remove numeric suffix in NEW_ID2 --- kernel/yosys_common.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/yosys_common.h b/kernel/yosys_common.h index 9678ff965..dbd683380 100644 --- a/kernel/yosys_common.h +++ b/kernel/yosys_common.h @@ -334,7 +334,19 @@ 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 NEW_ID2 module->uniquify(cell->name.str()) +inline std::string removeNumericSuffix(const std::string& str) { + size_t pos = str.rfind('_'); // Find the last underscore + + if (pos != std::string::npos && pos + 1 < str.size()) { + // Check if everything after the underscore is a digit + if (std::all_of(str.begin() + pos + 1, str.end(), ::isdigit)) { + return str.substr(0, pos); // Return the string without the suffix + } + } + return str; // Return unchanged if no numeric suffix found +} + +#define NEW_ID2 module->uniquify(removeNumericSuffix(cell->name.str())) #define NEW_ID2_SUFFIX(suffix) module->uniquify(cell->name.str() + "_" + suffix) #define NEW_ID3 module->uniquify(cell_name.str()) #define NEW_ID3_SUFFIX(suffix) module->uniquify(cell_name.str() + "_" + suffix)