3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-11-05 22:06:04 +00:00

Fix verilog backend to avoid IdString::c_str()

This commit is contained in:
Robert O'Callahan 2025-10-13 22:23:51 +00:00
parent e4a5bd7cb2
commit 609da65bb4

View file

@ -108,22 +108,30 @@ IdString initial_id;
void reset_auto_counter_id(RTLIL::IdString id, bool may_rename) void reset_auto_counter_id(RTLIL::IdString id, bool may_rename)
{ {
const char *str = id.c_str(); auto it = id.begin();
auto it_end = id.end();
if (*str == '$' && may_rename && !norename) if (it == it_end)
auto_name_map[id] = auto_name_counter++;
if (str[0] != '\\' || str[1] != '_' || str[2] == 0)
return; return;
for (int i = 2; str[i] != 0; i++) { if (*it == '$' && may_rename && !norename)
if (str[i] == '_' && str[i+1] == 0) auto_name_map[id] = auto_name_counter++;
if (*it != '\\' || *it != '_' || (it + 1) == it_end)
return;
it += 2;
auto start = it;
while (it != it_end) {
char ch = *it;
if (ch == '_' && (it + 1) == it_end)
continue; continue;
if (str[i] < '0' || str[i] > '9') if (ch < '0' || ch > '9')
return; return;
} }
int num = atoi(str+2); std::string s;
std::copy(start, it_end, std::back_inserter(s));
int num = atoi(s.c_str());
if (num >= auto_name_offset) if (num >= auto_name_offset)
auto_name_offset = num + 1; auto_name_offset = num + 1;
} }