Skip to content

Commit cfa9c8b

Browse files
authored
Merge pull request #5489 from rocallahan/fix-counter-reset
Fix `reset_auto_counter_id` to correctly detect `_NNN_` patterns
2 parents 725a1c3 + 58d4e2c commit cfa9c8b

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

backends/verilog/verilog_backend.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,21 @@ void reset_auto_counter_id(RTLIL::IdString id, bool may_rename)
116116
if (*it == '$' && may_rename && !norename)
117117
auto_name_map[id] = auto_name_counter++;
118118

119-
if (*it != '\\' || *it != '_' || (it + 1) == it_end)
119+
if (*it != '\\' || (it + 1) == it_end || *(it + 1) != '_' || (it + 2) == it_end)
120120
return;
121121

122+
std::string s;
122123
it += 2;
123-
auto start = it;
124124
while (it != it_end) {
125125
char ch = *it;
126126
if (ch == '_' && (it + 1) == it_end)
127-
continue;
127+
break;
128128
if (ch < '0' || ch > '9')
129129
return;
130+
s.push_back(ch);
131+
++it;
130132
}
131133

132-
std::string s;
133-
std::copy(start, it_end, std::back_inserter(s));
134134
int num = atoi(s.c_str());
135135
if (num >= auto_name_offset)
136136
auto_name_offset = num + 1;

tests/verilog/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/const_arst.v
22
/const_sr.v
33
/doubleslash.v
4+
/reset_auto_counter.v
45
/roundtrip_proc_1.v
56
/roundtrip_proc_2.v
67
/assign_to_reg.v
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
read_verilog -sv <<EOT
2+
module arithmetic (
3+
input logic [7:0] _0_,
4+
input logic [7:0] _1_,
5+
output logic [7:0] _2_,
6+
);
7+
assign _2_ = _0_ + _1_;
8+
9+
endmodule : arithmetic
10+
EOT
11+
12+
hierarchy
13+
techmap
14+
write_verilog reset_auto_counter.v
15+
! ! grep -qE '_0+0_' reset_auto_counter.v
16+
! ! grep -qE '_0+1_' reset_auto_counter.v
17+
! ! grep -qE '_0+2_' reset_auto_counter.v

0 commit comments

Comments
 (0)