35 for (
auto &it : module->
wires_)
36 if (it.first == from_name) {
38 module->
rename(it.second, to_name);
39 if (it.second->port_id)
44 for (
auto &it : module->
cells_)
45 if (it.first == from_name) {
47 module->
rename(it.second, to_name);
60 log(
" rename old_name new_name\n");
62 log(
"Rename the specified object. Note that selection patterns are not supported\n");
63 log(
"by this command.\n");
66 log(
" rename -enumerate [-pattern <pattern>] [selection]\n");
68 log(
"Assign short auto-generated names to all selected wires and cells with private\n");
69 log(
"names. The -pattern option can be used to set the pattern for the new names.\n");
70 log(
"The character %% in the pattern is replaced with a integer number. The default\n");
71 log(
"pattern is '_%%_'.\n");
73 log(
" rename -hide [selection]\n");
75 log(
"Assign private names (the ones with $-prefix) to all selected wires and cells\n");
76 log(
"with public names. This ignores all selected ports.\n");
81 std::string pattern_prefix =
"_", pattern_suffix =
"_";
82 bool flag_enumerate =
false;
83 bool flag_hide =
false;
84 bool got_mode =
false;
87 for (argidx = 1; argidx < args.size(); argidx++)
89 std::string arg = args[argidx];
90 if (arg ==
"-enumerate" && !got_mode) {
91 flag_enumerate =
true;
95 if (arg ==
"-hide" && !got_mode) {
100 if (arg ==
"-pattern" && argidx+1 < args.size() && args[argidx+1].find(
'%') != std::string::npos) {
101 int pos = args[++argidx].find(
'%');
102 pattern_prefix = args[argidx].substr(0, pos);
103 pattern_suffix = args[argidx].substr(pos+1);
121 std::map<RTLIL::IdString, RTLIL::Wire*> new_wires;
122 for (
auto &it : module->
wires_) {
123 if (it.first[0] ==
'$' && design->
selected(module, it.second))
124 do it.second->
name =
stringf(
"\\%s%d%s", pattern_prefix.c_str(), counter++, pattern_suffix.c_str());
125 while (module->
count_id(it.second->name) > 0);
126 new_wires[it.second->name] = it.second;
128 module->
wires_.swap(new_wires);
131 std::map<RTLIL::IdString, RTLIL::Cell*> new_cells;
132 for (
auto &it : module->
cells_) {
133 if (it.first[0] ==
'$' && design->
selected(module, it.second))
134 do it.second->name =
stringf(
"\\%s%d%s", pattern_prefix.c_str(), counter++, pattern_suffix.c_str());
135 while (module->
count_id(it.second->name) > 0);
136 new_cells[it.second->name] = it.second;
138 module->
cells_.swap(new_cells);
152 std::map<RTLIL::IdString, RTLIL::Wire*> new_wires;
153 for (
auto &it : module->
wires_) {
154 if (design->
selected(module, it.second))
155 if (it.first[0] ==
'\\' && it.second->port_id == 0)
157 new_wires[it.second->name] = it.second;
159 module->
wires_.swap(new_wires);
162 std::map<RTLIL::IdString, RTLIL::Cell*> new_cells;
163 for (
auto &it : module->
cells_) {
164 if (design->
selected(module, it.second))
165 if (it.first[0] ==
'\\')
167 new_cells[it.second->name] = it.second;
169 module->
cells_.swap(new_cells);
174 if (argidx+2 != args.size())
177 std::string from_name = args[argidx++];
178 std::string to_name = args[argidx++];
187 for (
auto &mod : design->
modules_) {
190 log(
"Renaming module %s to %s.\n", mod.first.c_str(), to_name.c_str());
192 design->
modules_.erase(module->name);
193 module->name = to_name;
199 log_cmd_error(
"Object `%s' not found!\n", from_name.c_str());
const char * c_str() const
bool selected(T1 *module) const
std::string stringf(const char *fmt,...)
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
static std::string unescape_id(std::string str)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
static std::string escape_id(std::string str)
#define PRIVATE_NAMESPACE_BEGIN
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN void rename_in_module(RTLIL::Module *module, std::string from_name, std::string to_name)
#define PRIVATE_NAMESPACE_END
void log_cmd_error(const char *format,...)
#define USING_YOSYS_NAMESPACE
virtual size_t count_id(RTLIL::IdString id)
std::map< RTLIL::IdString, RTLIL::Module * > modules_
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
void log(const char *format,...)
std::string selected_active_module
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
const char * log_id(RTLIL::IdString str)
void rename(RTLIL::Wire *wire, RTLIL::IdString new_name)