Skip to content

Commit ec04156

Browse files
committed
Fix verilog backend to avoid IdString::c_str()
1 parent b74554f commit ec04156

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

backends/verilog/verilog_backend.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,30 @@ IdString initial_id;
108108

109109
void reset_auto_counter_id(RTLIL::IdString id, bool may_rename)
110110
{
111-
const char *str = id.c_str();
111+
auto it = id.begin();
112+
auto it_end = id.end();
113+
if (it == it_end)
114+
return;
112115

113-
if (*str == '$' && may_rename && !norename)
116+
if (*it == '$' && may_rename && !norename)
114117
auto_name_map[id] = auto_name_counter++;
115118

116-
if (str[0] != '\\' || str[1] != '_' || str[2] == 0)
119+
if (*it != '\\' || *it != '_' || (it + 1) == it_end)
117120
return;
118121

119-
for (int i = 2; str[i] != 0; i++) {
120-
if (str[i] == '_' && str[i+1] == 0)
122+
it += 2;
123+
auto start = it;
124+
while (it != it_end) {
125+
char ch = *it;
126+
if (ch == '_' && (it + 1) == it_end)
121127
continue;
122-
if (str[i] < '0' || str[i] > '9')
128+
if (ch < '0' || ch > '9')
123129
return;
124130
}
125131

126-
int num = atoi(str+2);
132+
std::string s;
133+
std::copy(start, it_end, std::back_inserter(s));
134+
int num = atoi(s.c_str());
127135
if (num >= auto_name_offset)
128136
auto_name_offset = num + 1;
129137
}

0 commit comments

Comments
 (0)