Skip to content

Commit 3cd1cc1

Browse files
committed
Bump Yosys to latest
2 parents 56caf7c + 195d3ef commit 3cd1cc1

File tree

4 files changed

+82
-10
lines changed

4 files changed

+82
-10
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ jobs:
1111
runs-on: ubuntu-latest
1212
permissions: write-all
1313
steps:
14+
- name: Install deps
15+
run: sudo apt-get install bison flex libfl-dev libreadline-dev tcl-dev libffi-dev
16+
1417
- name: Checkout repository
1518
uses: actions/checkout@v4
1619
with:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ ifeq ($(OS), Haiku)
175175
CXXFLAGS += -D_DEFAULT_SOURCE
176176
endif
177177

178-
YOSYS_VER := 0.56+101
178+
YOSYS_VER := 0.56+105
179179
YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1)
180180
YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2)
181181
YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'.' -f3)

passes/cmds/rename.cc

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static std::string derive_name_from_src(const std::string &src, int counter)
6767
return stringf("\\%s$%d", src_base.c_str(), counter);
6868
}
6969

70-
static IdString derive_name_from_cell_output_wire(const RTLIL::Cell *cell, string suffix)
70+
static IdString derive_name_from_cell_output_wire(const RTLIL::Cell *cell, string suffix, bool move_to_cell)
7171
{
7272
// Find output
7373
const SigSpec *output = nullptr;
@@ -93,13 +93,21 @@ static IdString derive_name_from_cell_output_wire(const RTLIL::Cell *cell, strin
9393

9494
name += chunk.wire->name.str();
9595
if (chunk.wire->width != chunk.width) {
96-
name += "[";
97-
if (chunk.width != 1)
98-
name += std::to_string(chunk.offset + chunk.width) + ":";
99-
name += std::to_string(chunk.offset) + "]";
96+
int lhs = chunk.wire->to_hdl_index(chunk.offset + chunk.width - 1);
97+
int rhs = chunk.wire->to_hdl_index(chunk.offset);
98+
99+
if (lhs != rhs)
100+
name += stringf("[%d:%d]", lhs, rhs);
101+
else
102+
name += stringf("[%d]", lhs);
100103
}
101104
}
102105

106+
RTLIL::Wire *wire;
107+
108+
if (move_to_cell && (!(wire = cell->module->wire(name)) || !(wire->port_input || wire->port_output)))
109+
return name;
110+
103111
if (suffix.empty()) {
104112
suffix = cell->type.str();
105113
}
@@ -232,13 +240,17 @@ struct RenamePass : public Pass {
232240
log("cells with private names.\n");
233241
log("\n");
234242
log("\n");
235-
log(" rename -wire [selection] [-suffix <suffix>]\n");
243+
log(" rename -wire [selection] [-move-to-cell] [-suffix <suffix>]\n");
236244
log("\n");
237245
log("Assign auto-generated names based on the wires they drive to all selected\n");
238246
log("cells with private names. Ignores cells driving privatly named wires.\n");
239247
log("By default, the cell is named after the wire with the cell type as suffix.\n");
240248
log("The -suffix option can be used to set the suffix to the given string instead.\n");
241249
log("\n");
250+
log("The -move-to-cell option can be used to name the cell after the wire without\n");
251+
log("any suffix. If this would lead to conflicts, the suffix is added to the wire\n");
252+
log("instead. For cells driving ports, the -move-to-cell option is ignored.\n");
253+
log("\n");
242254
log("\n");
243255
log(" rename -enumerate [-pattern <pattern>] [selection]\n");
244256
log("\n");
@@ -286,6 +298,7 @@ struct RenamePass : public Pass {
286298
std::string cell_suffix = "";
287299
bool flag_src = false;
288300
bool flag_wire = false;
301+
bool flag_move_to_cell = false;
289302
bool flag_enumerate = false;
290303
bool flag_witness = false;
291304
bool flag_hide = false;
@@ -345,6 +358,10 @@ struct RenamePass : public Pass {
345358
got_mode = true;
346359
continue;
347360
}
361+
if (arg == "-move-to-cell" && flag_wire && !flag_move_to_cell) {
362+
flag_move_to_cell = true;
363+
continue;
364+
}
348365
if (arg == "-pattern" && argidx+1 < args.size() && args[argidx+1].find('%') != std::string::npos) {
349366
int pos = args[++argidx].find('%');
350367
pattern_prefix = args[argidx].substr(0, pos);
@@ -396,9 +413,26 @@ struct RenamePass : public Pass {
396413
dict<RTLIL::Cell *, IdString> new_cell_names;
397414
for (auto cell : module->selected_cells())
398415
if (cell->name[0] == '$')
399-
new_cell_names[cell] = derive_name_from_cell_output_wire(cell, cell_suffix);
400-
for (auto &it : new_cell_names)
401-
module->rename(it.first, it.second);
416+
new_cell_names[cell] = derive_name_from_cell_output_wire(cell, cell_suffix, flag_move_to_cell);
417+
for (auto &[cell, new_name] : new_cell_names) {
418+
if (flag_move_to_cell) {
419+
RTLIL::Wire *found_wire = module->wire(new_name);
420+
if (found_wire) {
421+
std::string wire_suffix = cell_suffix;
422+
if (wire_suffix.empty()) {
423+
for (auto const &[port, _] : cell->connections()) {
424+
if (cell->output(port)) {
425+
wire_suffix += stringf("%s.%s", cell->type.c_str(), port.c_str() + 1);
426+
break;
427+
}
428+
}
429+
}
430+
IdString new_wire_name = found_wire->name.str() + wire_suffix;
431+
module->rename(found_wire, new_wire_name);
432+
}
433+
}
434+
module->rename(cell, new_name);
435+
}
402436
}
403437
}
404438
else
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
read_verilog <<EOF
2+
module top(input clk, rst, input [7:0] din, output [7:0] dout, input bin, output bout);
3+
reg [7:0] dq;
4+
reg bq;
5+
6+
always @(posedge clk, posedge rst) begin
7+
if (rst) dq <= '0;
8+
else dq <= din;
9+
end
10+
11+
always @(posedge clk) bq <= bin;
12+
13+
assign dout = dq;
14+
assign bout = bq;
15+
endmodule
16+
EOF
17+
18+
proc
19+
hierarchy -top top
20+
21+
select -assert-count 1 t:$dff
22+
select -assert-count 1 t:$adff
23+
select -assert-count 0 t:$dff n:bq %i
24+
select -assert-count 0 t:$adff n:dq %i
25+
select -assert-count 1 w:bq
26+
select -assert-count 1 w:dq
27+
28+
rename -wire -move-to-cell
29+
30+
select -assert-count 1 t:$dff
31+
select -assert-count 1 t:$adff
32+
select -assert-count 1 t:$dff n:bq %i
33+
select -assert-count 1 t:$adff n:dq %i
34+
select -assert-count 0 w:bq
35+
select -assert-count 0 w:dq

0 commit comments

Comments
 (0)