Skip to content

Commit bf29119

Browse files
committed
rtlil: add textual roundtrip test
1 parent affa917 commit bf29119

File tree

7 files changed

+1554
-0
lines changed

7 files changed

+1554
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ MK_TEST_DIRS += tests/sim
874874
MK_TEST_DIRS += tests/svtypes
875875
MK_TEST_DIRS += tests/techmap
876876
MK_TEST_DIRS += tests/various
877+
MK_TEST_DIRS += tests/rtlil
877878
ifeq ($(ENABLE_VERIFIC),1)
878879
ifneq ($(YOSYS_NOVERIFIC),1)
879880
MK_TEST_DIRS += tests/verific

tests/rtlil/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.tmp.il
2+
*.tmp.il.bak

tests/rtlil/everything.v

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module alu(
2+
input clk,
3+
input [7:0] A,
4+
input [7:0] B,
5+
input [3:0] operation,
6+
output reg [7:0] result,
7+
output reg CF,
8+
output reg ZF,
9+
output reg SF
10+
);
11+
12+
localparam ALU_OP_ADD = 4'b0000;
13+
localparam ALU_OP_SUB = 4'b0001;
14+
15+
reg [8:0] tmp;
16+
17+
always @(posedge clk)
18+
begin
19+
case (operation)
20+
ALU_OP_ADD :
21+
tmp = A + B;
22+
ALU_OP_SUB :
23+
tmp = A - B;
24+
endcase
25+
26+
CF <= tmp[8];
27+
ZF <= tmp[7:0] == 0;
28+
SF <= tmp[7];
29+
30+
result <= tmp[7:0];
31+
end
32+
endmodule
33+
34+
module foo(
35+
input [7:0] a, input [7:0] b, output [7:0] y
36+
);
37+
wire [7:0] bb;
38+
assign b = bb;
39+
assign y = a + bb;
40+
endmodule

tests/rtlil/roundtrip-text.ref.il

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
autoidx 15
2+
attribute \src "everything.v:1.1-32.10"
3+
attribute \cells_not_processed 1
4+
module \alu
5+
attribute \src "everything.v:2.8-2.11"
6+
wire input 1 \clk
7+
attribute \src "everything.v:3.14-3.15"
8+
wire width 8 input 2 \A
9+
attribute \src "everything.v:4.14-4.15"
10+
wire width 8 input 3 \B
11+
attribute \src "everything.v:5.14-5.23"
12+
wire width 4 input 4 \operation
13+
attribute \src "everything.v:6.19-6.25"
14+
wire width 8 output 5 \result
15+
attribute \src "everything.v:7.13-7.15"
16+
wire output 6 \CF
17+
attribute \src "everything.v:8.13-8.15"
18+
wire output 7 \ZF
19+
attribute \src "everything.v:9.13-9.15"
20+
wire output 8 \SF
21+
attribute \src "everything.v:15.12-15.15"
22+
wire width 9 \tmp
23+
attribute \src "everything.v:17.2-31.5"
24+
wire width 8 $0\result[7:0]
25+
attribute \src "everything.v:17.2-31.5"
26+
wire $0\CF[0:0]
27+
attribute \src "everything.v:17.2-31.5"
28+
wire $0\ZF[0:0]
29+
attribute \src "everything.v:17.2-31.5"
30+
wire $0\SF[0:0]
31+
attribute \src "everything.v:17.2-31.5"
32+
wire width 9 $0\tmp[8:0]
33+
attribute \src "everything.v:17.2-31.5"
34+
wire width 9 $1\tmp[8:0]
35+
attribute \src "everything.v:21.11-21.16"
36+
wire width 9 $add$everything.v:21$2_Y
37+
attribute \src "everything.v:23.11-23.16"
38+
wire width 9 $sub$everything.v:23$3_Y
39+
attribute \src "everything.v:27.9-27.22"
40+
wire $eq$everything.v:27$4_Y
41+
attribute \src "everything.v:21.11-21.16"
42+
cell $add $add$everything.v:21$2
43+
parameter \A_SIGNED 0
44+
parameter \B_SIGNED 0
45+
parameter \A_WIDTH 8
46+
parameter \B_WIDTH 8
47+
parameter \Y_WIDTH 9
48+
connect \A \A
49+
connect \B \B
50+
connect \Y $add$everything.v:21$2_Y
51+
end
52+
attribute \src "everything.v:23.11-23.16"
53+
cell $sub $sub$everything.v:23$3
54+
parameter \A_SIGNED 0
55+
parameter \B_SIGNED 0
56+
parameter \A_WIDTH 8
57+
parameter \B_WIDTH 8
58+
parameter \Y_WIDTH 9
59+
connect \A \A
60+
connect \B \B
61+
connect \Y $sub$everything.v:23$3_Y
62+
end
63+
attribute \src "everything.v:27.9-27.22"
64+
cell $eq $eq$everything.v:27$4
65+
parameter \A_SIGNED 0
66+
parameter \B_SIGNED 0
67+
parameter \A_WIDTH 8
68+
parameter \B_WIDTH 32
69+
parameter \Y_WIDTH 1
70+
connect \A $1\tmp[8:0] [7:0]
71+
connect \B 0
72+
connect \Y $eq$everything.v:27$4_Y
73+
end
74+
attribute \src "everything.v:17.2-31.5"
75+
process $proc$everything.v:17$1
76+
assign { } { }
77+
assign { } { }
78+
assign { } { }
79+
assign { } { }
80+
assign { } { }
81+
assign $0\tmp[8:0] $1\tmp[8:0]
82+
assign $0\CF[0:0] $1\tmp[8:0] [8]
83+
assign $0\ZF[0:0] $eq$everything.v:27$4_Y
84+
assign $0\SF[0:0] $1\tmp[8:0] [7]
85+
assign $0\result[7:0] $1\tmp[8:0] [7:0]
86+
attribute \src "everything.v:19.3-24.10"
87+
switch \operation
88+
attribute \src "everything.v:19.19-19.19"
89+
case 4'0000
90+
assign { } { }
91+
assign $1\tmp[8:0] $add$everything.v:21$2_Y
92+
attribute \src "everything.v:21.17-21.17"
93+
case 4'0001
94+
assign { } { }
95+
assign $1\tmp[8:0] $sub$everything.v:23$3_Y
96+
case
97+
assign $1\tmp[8:0] \tmp
98+
end
99+
sync posedge \clk
100+
update \result $0\result[7:0]
101+
update \CF $0\CF[0:0]
102+
update \ZF $0\ZF[0:0]
103+
update \SF $0\SF[0:0]
104+
update \tmp $0\tmp[8:0]
105+
end
106+
end
107+
attribute \src "everything.v:34.1-40.10"
108+
attribute \cells_not_processed 1
109+
module \foo
110+
attribute \src "everything.v:35.17-35.18"
111+
wire width 8 input 1 \a
112+
attribute \src "everything.v:35.32-35.33"
113+
wire width 8 input 2 \b
114+
attribute \src "everything.v:35.48-35.49"
115+
wire width 8 output 3 \y
116+
attribute \src "everything.v:37.16-37.18"
117+
wire width 8 \bb
118+
attribute \src "everything.v:39.16-39.22"
119+
wire width 8 $add$everything.v:39$5_Y
120+
attribute \src "everything.v:39.16-39.22"
121+
cell $add $add$everything.v:39$5
122+
parameter \A_SIGNED 0
123+
parameter \B_SIGNED 0
124+
parameter \A_WIDTH 8
125+
parameter \B_WIDTH 8
126+
parameter \Y_WIDTH 8
127+
connect \A \a
128+
connect \B \bb
129+
connect \Y $add$everything.v:39$5_Y
130+
end
131+
connect \b \bb
132+
connect \y $add$everything.v:39$5_Y
133+
end
134+
attribute \cells_not_processed 1
135+
attribute \src "everything.v:1.1-32.10"
136+
module \zzz
137+
attribute \src "everything.v:27.9-27.22"
138+
wire $eq$everything.v:27$4_Y
139+
attribute \src "everything.v:23.11-23.16"
140+
wire width 9 $sub$everything.v:23$3_Y
141+
attribute \src "everything.v:21.11-21.16"
142+
wire width 9 $add$everything.v:21$2_Y
143+
attribute \src "everything.v:17.2-31.5"
144+
wire width 9 $1\tmp[8:0]
145+
attribute \src "everything.v:17.2-31.5"
146+
wire width 9 $0\tmp[8:0]
147+
attribute \src "everything.v:17.2-31.5"
148+
wire $0\SF[0:0]
149+
attribute \src "everything.v:17.2-31.5"
150+
wire $0\ZF[0:0]
151+
attribute \src "everything.v:17.2-31.5"
152+
wire $0\CF[0:0]
153+
attribute \src "everything.v:17.2-31.5"
154+
wire width 8 $0\result[7:0]
155+
attribute \src "everything.v:15.12-15.15"
156+
wire width 9 \tmp
157+
attribute \src "everything.v:9.13-9.15"
158+
wire output 8 \SF
159+
attribute \src "everything.v:8.13-8.15"
160+
wire output 7 \ZF
161+
attribute \src "everything.v:7.13-7.15"
162+
wire output 6 \CF
163+
attribute \src "everything.v:6.19-6.25"
164+
wire width 8 output 5 \result
165+
attribute \src "everything.v:5.14-5.23"
166+
wire width 4 input 4 \operation
167+
attribute \src "everything.v:4.14-4.15"
168+
wire width 8 input 3 \B
169+
attribute \src "everything.v:3.14-3.15"
170+
wire width 8 input 2 \A
171+
attribute \src "everything.v:2.8-2.11"
172+
wire input 1 \clk
173+
wire $procmux$8_CMP
174+
wire width 9 $procmux$7_Y
175+
wire $procmux$9_CMP
176+
attribute \src "everything.v:27.9-27.22"
177+
cell $logic_not $eq$everything.v:27$4
178+
parameter \A_SIGNED 0
179+
parameter \Y_WIDTH 1
180+
parameter \A_WIDTH 8
181+
connect \A $1\tmp[8:0] [7:0]
182+
connect \Y $eq$everything.v:27$4_Y
183+
end
184+
attribute \src "everything.v:23.11-23.16"
185+
cell $sub $sub$everything.v:23$3
186+
parameter \A_SIGNED 0
187+
parameter \B_SIGNED 0
188+
parameter \A_WIDTH 8
189+
parameter \B_WIDTH 8
190+
parameter \Y_WIDTH 9
191+
connect \A \A
192+
connect \B \B
193+
connect \Y $sub$everything.v:23$3_Y
194+
end
195+
attribute \src "everything.v:21.11-21.16"
196+
cell $add $add$everything.v:21$2
197+
parameter \A_SIGNED 0
198+
parameter \B_SIGNED 0
199+
parameter \A_WIDTH 8
200+
parameter \B_WIDTH 8
201+
parameter \Y_WIDTH 9
202+
connect \A \A
203+
connect \B \B
204+
connect \Y $add$everything.v:21$2_Y
205+
end
206+
attribute \src "everything.v:19.3-24.10"
207+
attribute \full_case 1
208+
cell $eq $procmux$8_CMP0
209+
parameter \A_SIGNED 0
210+
parameter \B_SIGNED 0
211+
parameter \A_WIDTH 4
212+
parameter \B_WIDTH 4
213+
parameter \Y_WIDTH 1
214+
connect \A \operation
215+
connect \B 4'0001
216+
connect \Y $procmux$8_CMP
217+
end
218+
attribute \src "everything.v:19.3-24.10"
219+
attribute \full_case 1
220+
cell $pmux $procmux$7
221+
parameter \WIDTH 9
222+
parameter \S_WIDTH 2
223+
connect \A \tmp
224+
connect \B { $add$everything.v:21$2_Y $sub$everything.v:23$3_Y }
225+
connect \S { $procmux$9_CMP $procmux$8_CMP }
226+
connect \Y $procmux$7_Y
227+
end
228+
attribute \src "everything.v:19.3-24.10"
229+
attribute \full_case 1
230+
cell $logic_not $procmux$9_CMP0
231+
parameter \A_SIGNED 0
232+
parameter \Y_WIDTH 1
233+
parameter \A_WIDTH 4
234+
connect \A \operation
235+
connect \Y $procmux$9_CMP
236+
end
237+
attribute \src "everything.v:17.2-31.5"
238+
cell $dff $procdff$10
239+
parameter \WIDTH 8
240+
parameter \CLK_POLARITY 1'1
241+
connect \D $procmux$7_Y [7:0]
242+
connect \Q \result
243+
connect \CLK \clk
244+
end
245+
attribute \src "everything.v:17.2-31.5"
246+
cell $dff $procdff$11
247+
parameter \WIDTH 1
248+
parameter \CLK_POLARITY 1'1
249+
connect \D $procmux$7_Y [8]
250+
connect \Q \CF
251+
connect \CLK \clk
252+
end
253+
attribute \src "everything.v:17.2-31.5"
254+
cell $dff $procdff$12
255+
parameter \WIDTH 1
256+
parameter \CLK_POLARITY 1'1
257+
connect \D $eq$everything.v:27$4_Y
258+
connect \Q \ZF
259+
connect \CLK \clk
260+
end
261+
attribute \src "everything.v:17.2-31.5"
262+
cell $dff $procdff$13
263+
parameter \WIDTH 1
264+
parameter \CLK_POLARITY 1'1
265+
connect \D $procmux$7_Y [7]
266+
connect \Q \SF
267+
connect \CLK \clk
268+
end
269+
attribute \src "everything.v:17.2-31.5"
270+
cell $dff $procdff$14
271+
parameter \WIDTH 9
272+
parameter \CLK_POLARITY 1'1
273+
connect \D $procmux$7_Y
274+
connect \Q \tmp
275+
connect \CLK \clk
276+
end
277+
connect $0\result[7:0] $1\tmp[8:0] [7:0]
278+
connect $0\SF[0:0] $1\tmp[8:0] [7]
279+
connect $0\ZF[0:0] $eq$everything.v:27$4_Y
280+
connect $0\CF[0:0] $1\tmp[8:0] [8]
281+
connect $0\tmp[8:0] $1\tmp[8:0]
282+
connect $1\tmp[8:0] $procmux$7_Y
283+
end

tests/rtlil/roundtrip-text.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
set -euo pipefail
2+
YS=../../yosys
3+
4+
# write_rtlil and dump are equivalent
5+
$YS -p "read_verilog -sv everything.v; copy alu zzz; proc zzz; dump -o roundtrip-text.dump.tmp.il; write_rtlil roundtrip-text.write.tmp.il"
6+
sed '/^$/d' -i.bak roundtrip-text.dump.tmp.il
7+
sed '/^$/d' -i.bak roundtrip-text.write.tmp.il
8+
# Trim first line ("Generated by Yosys ...")
9+
tail -n +2 roundtrip-text.write.tmp.il > roundtrip-text.write-nogen.tmp.il
10+
diff roundtrip-text.dump.tmp.il roundtrip-text.write-nogen.tmp.il
11+
diff roundtrip-text.dump.tmp.il roundtrip-text.ref.il
12+
13+
# Loading and writing it out again doesn't change the RTLIL
14+
$YS -p "read_rtlil roundtrip-text.dump.tmp.il; write_rtlil roundtrip-text.reload.tmp.il"
15+
sed '/^$/d' -i.bak roundtrip-text.reload.tmp.il
16+
tail -n +2 roundtrip-text.reload.tmp.il > roundtrip-text.reload-nogen.tmp.il
17+
diff roundtrip-text.dump.tmp.il roundtrip-text.reload-nogen.tmp.il
18+
19+
# Hashing differences don't change the RTLIL
20+
$YS --hash-seed=2345678 -p "read_rtlil roundtrip-text.dump.tmp.il; write_rtlil roundtrip-text.reload-hash.tmp.il"
21+
sed '/^$/d' -i.bak roundtrip-text.reload-hash.tmp.il
22+
tail -n +2 roundtrip-text.reload-hash.tmp.il > roundtrip-text.reload-hash-nogen.tmp.il
23+
diff roundtrip-text.dump.tmp.il roundtrip-text.reload-hash-nogen.tmp.il
24+
25+
echo "Without ABC, we don't get any irreproducibility and can pin that"
26+
echo "Has this test case started failing for you? Consider updating the reference"
27+
$YS -p "read_verilog -sv everything.v; synth -noabc; write_rtlil roundtrip-text.synth.tmp.il"
28+
sed '/^$/d' -i.bak roundtrip-text.synth.tmp.il
29+
tail -n +2 roundtrip-text.synth.tmp.il > roundtrip-text.synth-nogen.tmp.il
30+
diff roundtrip-text.synth-nogen.tmp.il roundtrip-text.synth.ref.il

0 commit comments

Comments
 (0)