Skip to content

Commit 3ec1f4d

Browse files
committed
Automatically dump signals
While manually dumping signals with a macro works OK for standalone modules, it doesn't work when multiple modules are included. Instead, create a second top-level module to dump signals. Inspired (once again) by [1]. [1] steveicarus/iverilog#376 (comment) Signed-off-by: Sean Anderson <[email protected]>
1 parent 5ac40db commit 3ec1f4d

14 files changed

+28
-46
lines changed

Makefile

+10-9
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ log:
2222
$(SYNTH) -q -E $@.d -p "synth_ice40 -top $(*F)" -b json -o $@ -f verilog $< -l log/$(*F).synth
2323

2424
define run-jsontov =
25-
( echo '`include "common.vh"'; grep timescale $*.v; \
26-
$(SYNTH) -q -p "write_verilog -defparam -noattr" -f json $< ) | \
27-
sed 's/endmodule/`DUMP(1)\n\0/g' > $@
25+
( grep timescale $*.v; $(SYNTH) -q -p "write_verilog -defparam -noattr" -f json $< ) > $@
2826
endef
2927

3028
%.synth.v: %.synth.json %.v
@@ -35,28 +33,29 @@ endef
3533

3634
# Don't warn about including the timescale from common.vh
3735
IFLAGS := -g2012 -gspecify -Wall -Wno-timescale
36+
EXTRA_V := rtl/iverilog_dump.v
3837

3938
define run-icarus =
40-
$(ICARUS) $(IFLAGS) -I$(<D) -M$@.pre -s $(TOP) -o $@ $< $(EXTRA_V) && \
39+
$(ICARUS) $(IFLAGS) -I$(<D) -y$(<D) -M$@.pre -DTOP=$(TOP) -s $(TOP) -s dump -o $@ $< $(EXTRA_V) && \
4140
( echo -n "$@: " && tr '\n' ' ' ) < $@.pre > $@.d; RET=$$?; rm -f $@.pre; exit $$RET
4241
endef
4342

4443
%.vvp: TOP = $(*F)
45-
%.vvp: %.v
44+
%.vvp: %.v rtl/iverilog_dump.v
4645
$(run-icarus)
4746

4847
%.synth.vvp: TOP = $(*F)
49-
%.synth.vvp %.place.vvp: EXTRA_V := $(shell $(SYNTH)-config --datdir)/ice40/cells_sim.v
48+
%.synth.vvp %.place.vvp: EXTRA_V += $(shell $(SYNTH)-config --datdir)/ice40/cells_sim.v
5049
# Don't warn about unused SB_IO ports
5150
%.synth.vvp: IFLAGS += -Wno-portbind
52-
%.synth.vvp: %.synth.v
51+
%.synth.vvp: %.synth.v rtl/iverilog_dump.v
5352
$(run-icarus)
5453

5554
%.place.vvp: TOP = top
5655
# Don't warn about unused SB_IO ports
5756
%.place.vvp: IFLAGS += -Wno-portbind
5857
%.place.vvp: IFLAGS += -DTIMING -Ttyp
59-
%.place.vvp: %.place.v
58+
%.place.vvp: %.place.v rtl/iverilog_dump.v
6059
$(run-icarus)
6160

6261
%.asc %.sdf %.place.json &: %.synth.json | log
@@ -79,13 +78,15 @@ define run-vvp =
7978
MODULE=tb.$* $(VVP) $(VVPFLAGS) $< $(PLUSARGS)
8079
endef
8180

81+
%.fst: PLUSARGS += +levels=0
8282
%.fst: rtl/%.vvp tb/%.py FORCE
8383
$(run-vvp)
8484

85+
%.synth.fst: PLUSARGS += +levels=1
8586
%.synth.fst: rtl/%.synth.vvp tb/%.py FORCE
8687
$(run-vvp)
8788

88-
%.place.fst: PLUSARGS += +sdf=rtl/$*.sdf
89+
%.place.fst: PLUSARGS += +levels=1 +sdf=rtl/$*.sdf
8990
%.place.fst: rtl/%.place.vvp rtl/%.sdf tb/%.py FORCE
9091
$(run-vvp)
9192

rtl/common.vh

-15
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,4 @@
99
`default_nettype none
1010
`timescale 1ns/1ns
1111

12-
`ifdef SYNTHESIS
13-
`define DUMP(levels)
14-
`else
15-
`define DUMP(levels) \
16-
reg [4096:0] vcdfile, sdffile; \
17-
initial begin \
18-
if ($value$plusargs("vcd=%s", vcdfile)) begin \
19-
$dumpfile(vcdfile); \
20-
$dumpvars(levels); \
21-
end \
22-
if ($value$plusargs("sdf=%s", sdffile)) \
23-
$sdf_annotate(sdffile); \
24-
end
25-
`endif
26-
2712
`endif /* COMMON_VH */

rtl/descramble.v

-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,4 @@ module descramble (
115115
end
116116
end
117117

118-
`DUMP(0)
119-
120118
endmodule

rtl/iverilog_dump.v

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: AGPL-3.0-Only
2+
/*
3+
* Copyright (C) 2022 Sean Anderson <[email protected]>
4+
*/
5+
6+
module iverilog_dump();
7+
integer levels;
8+
reg [4096:0] vcdfile, sdffile;
9+
initial begin
10+
if ($value$plusargs("vcd=%s", vcdfile) &&
11+
$value$plusargs("levels=%d", levels)) begin
12+
$dumpfile(vcdfile);
13+
$dumpvars(levels, `TOP);
14+
end
15+
if ($value$plusargs("sdf=%s", sdffile))
16+
$sdf_annotate(sdffile, `TOP);
17+
end
18+
endmodule

rtl/mdio.v

-2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,4 @@ module mdio (
216216
end
217217
`endif
218218

219-
`DUMP(0)
220-
221219
endmodule

rtl/mdio_io.v

-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,4 @@ module mdio_io (
7878
oe <= 0;
7979
end
8080

81-
`DUMP(0)
82-
8381
endmodule

rtl/mdio_regs.v

-2
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,4 @@ module mdio_regs (
149149
data_read <= data_read_next;
150150
end
151151

152-
`DUMP(0)
153-
154152
endmodule

rtl/mii_io_rx.v

-2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,4 @@ module mii_io_rx (
121121
end
122122
`endif
123123

124-
`DUMP(0)
125-
126124
endmodule

rtl/mii_io_tx.v

-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,4 @@ module mii_io_tx (
113113
end
114114
`endif
115115

116-
`DUMP(0)
117-
118116
endmodule

rtl/nrzi_decode.v

-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,4 @@ module nrzi_decode (
3434
nrz <= nrz_next;
3535
end
3636

37-
`DUMP(0)
38-
3937
endmodule

rtl/nrzi_encode.v

-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@ module nrzi_encode (
2020
always @(posedge clk)
2121
nrzi <= nrzi_next;
2222

23-
`DUMP(0)
24-
2523
endmodule

rtl/pcs.v

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ module pcs (
9090
assign col = transmitting && receiving;
9191
assign crs = transmitting || receiving;
9292

93-
`DUMP(0)
94-
9593
endmodule
9694

9795
/* Transmit process */

rtl/pmd_io.v

-2
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,4 @@ module pmd_io (
213213
end
214214
`endif
215215

216-
`DUMP(0)
217-
218216
endmodule

rtl/scramble.v

-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ module scramble (
2323
always @(posedge clk)
2424
lfsr = { lfsr[9:0], lfsr_next };
2525

26-
`DUMP(0)
27-
2826
endmodule

0 commit comments

Comments
 (0)