Skip to content

Commit 24ee1c1

Browse files
Caleb Beglywsnyder
Caleb Begly
authored andcommitted
Fix AUTOINST multi-dimensional array [] substitution (#1848) (#1850).
* verilog-mode.el (verilog-auto-inst-port): Fix AUTOINST multi-dimensional array [] substitution. Reported by Caleb Begly.
1 parent 9395f12 commit 24ee1c1

File tree

3 files changed

+143
-12
lines changed

3 files changed

+143
-12
lines changed

tests/autoinst_multidim_rename.sv

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module parent(/*AUTOARG*/);
2+
input [31:0][7:0] data_in;
3+
output [4:0] meta_out;
4+
output [4:0] meta_out_no_rename;
5+
output [31:0][7:0] data_out;
6+
7+
/*AUTOWIRE*/
8+
9+
/* child1 AUTO_TEMPLATE (
10+
.data_out (child1_out[][]),
11+
.meta_out (child1_meta_out[]),
12+
); */
13+
child1 U1 (
14+
/*AUTOINST*/
15+
)
16+
17+
/* child2 AUTO_TEMPLATE (
18+
.data_in (child1_out[][]),
19+
.meta_in (child1_meta_out[]),
20+
); */
21+
child2 U2 (
22+
/*AUTOINST*/
23+
)
24+
25+
endmodule
26+
27+
module child1(/*AUTOARG*/);
28+
input [31:0][7:0] data_in;
29+
output [31:0][7:0] data_out;
30+
output [4:0] meta_out;
31+
32+
endmodule
33+
34+
module child2(/*AUTOARG*/);
35+
input [31:0][7:0] data_in;
36+
input [4:0] meta_in;
37+
output [31:0][7:0] data_out;
38+
output [4:0] meta_out_no_rename;
39+
40+
endmodule
41+
42+
// Local Variables:
43+
// verilog-auto-inst-vector:nil
44+
// End:

tests_ok/autoinst_multidim_rename.sv

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module parent(/*AUTOARG*/
2+
// Outputs
3+
meta_out, meta_out_no_rename, data_out,
4+
// Inputs
5+
data_in
6+
);
7+
input [31:0][7:0] data_in;
8+
output [4:0] meta_out;
9+
output [4:0] meta_out_no_rename;
10+
output [31:0][7:0] data_out;
11+
12+
/*AUTOWIRE*/
13+
// Beginning of automatic wires (for undeclared instantiated-module outputs)
14+
wire [4:0] child1_meta_out; // From U1 of child1.v
15+
wire [31:0] [7:0] child1_out; // From U1 of child1.v
16+
// End of automatics
17+
18+
/* child1 AUTO_TEMPLATE (
19+
.data_out (child1_out[][]),
20+
.meta_out (child1_meta_out[]),
21+
); */
22+
child1 U1 (
23+
/*AUTOINST*/
24+
// Outputs
25+
.data_out (child1_out/*[31:0][7:0]*/), // Templated
26+
.meta_out (child1_meta_out[4:0]), // Templated
27+
// Inputs
28+
.data_in (data_in/*[31:0][7:0]*/));
29+
30+
/* child2 AUTO_TEMPLATE (
31+
.data_in (child1_out[][]),
32+
.meta_in (child1_meta_out[]),
33+
) */
34+
child2 U2 (
35+
/*AUTOINST*/
36+
// Outputs
37+
.data_out (data_out/*[31:0][7:0]*/),
38+
.meta_out_no_rename (meta_out_no_rename),
39+
// Inputs
40+
.data_in (child1_out/*[31:0][7:0]*/), // Templated
41+
.meta_in (child1_meta_out[4:0])); // Templated
42+
43+
endmodule
44+
45+
module child1(/*AUTOARG*/
46+
// Outputs
47+
data_out, meta_out,
48+
// Inputs
49+
data_in
50+
)
51+
input [31:0][7:0] data_in;
52+
output [31:0][7:0] data_out;
53+
output [4:0] meta_out;
54+
55+
endmodule
56+
57+
module child2(/*AUTOARG*/
58+
// Outputs
59+
data_out, meta_out_no_rename,
60+
// Inputs
61+
data_in, meta_in
62+
);
63+
input [31:0][7:0] data_in;
64+
input [4:0] meta_in;
65+
output [31:0][7:0] data_out;
66+
output [4:0] meta_out_no_rename;
67+
68+
endmodule
69+
70+
// Local Variables:
71+
// verilog-auto-inst-vector:nil
72+
// End:

verilog-mode.el

+27-12
Original file line numberDiff line numberDiff line change
@@ -12256,18 +12256,12 @@ If PAR-VALUES replace final strings with these parameter values."
1225612256
(vl-memory (verilog-sig-memory port-st))
1225712257
(vl-mbits (if (verilog-sig-multidim port-st)
1225812258
(verilog-sig-multidim-string port-st) ""))
12259-
(vl-bits (if (or (eq verilog-auto-inst-vector t)
12260-
(and (eq verilog-auto-inst-vector `unsigned)
12261-
(not (verilog-sig-signed port-st)))
12262-
(not (assoc port (verilog-decls-get-signals moddecls)))
12263-
(not (equal (verilog-sig-bits port-st)
12264-
(verilog-sig-bits
12265-
(assoc port (verilog-decls-get-signals moddecls))))))
12266-
(or (verilog-sig-bits port-st) "")
12267-
""))
12259+
(vl-bits (or (verilog-sig-bits port-st) ""))
1226812260
(case-fold-search nil)
1226912261
(check-values par-values)
12270-
tpl-net dflt-bits)
12262+
auto-inst-vector
12263+
auto-inst-vector-tpl
12264+
tpl-net dflt-bits)
1227112265
;; Replace parameters in bit-width
1227212266
(when (and check-values
1227312267
(not (equal vl-bits "")))
@@ -12290,6 +12284,16 @@ If PAR-VALUES replace final strings with these parameter values."
1229012284
vl-mbits (verilog-simplify-range-expression vl-mbits)
1229112285
vl-memory (when vl-memory (verilog-simplify-range-expression vl-memory))
1229212286
vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
12287+
(setq auto-inst-vector
12288+
(if (or (eq verilog-auto-inst-vector t)
12289+
(and (eq verilog-auto-inst-vector `unsigned)
12290+
(not (verilog-sig-signed port-st)))
12291+
(not (assoc port (verilog-decls-get-signals moddecls)))
12292+
(not (equal (verilog-sig-bits port-st)
12293+
(verilog-sig-bits
12294+
(assoc port (verilog-decls-get-signals moddecls))))))
12295+
vl-bits
12296+
""))
1229312297
;; Default net value if not found
1229412298
(setq dflt-bits (if (or (and (verilog-sig-bits port-st)
1229512299
(verilog-sig-multidim port-st))
@@ -12299,7 +12303,7 @@ If PAR-VALUES replace final strings with these parameter values."
1229912303
(if vl-memory "." "")
1230012304
(if vl-memory vl-memory "")
1230112305
"*/")
12302-
(concat vl-bits))
12306+
(concat auto-inst-vector))
1230312307
tpl-net (concat port
1230412308
(if (and vl-modport
1230512309
;; .modport cannot be added if attachment is
@@ -12338,10 +12342,21 @@ If PAR-VALUES replace final strings with these parameter values."
1233812342
(if (numberp value) (setq value (number-to-string value)))
1233912343
value))
1234012344
(substring tpl-net (match-end 0))))))
12345+
;; Get range based off template net
12346+
(setq auto-inst-vector-tpl
12347+
(if (or (eq verilog-auto-inst-vector t)
12348+
(and (eq verilog-auto-inst-vector `unsigned)
12349+
(not (verilog-sig-signed port-st)))
12350+
(not (assoc tpl-net (verilog-decls-get-signals moddecls)))
12351+
(not (equal (verilog-sig-bits port-st)
12352+
(verilog-sig-bits
12353+
(assoc tpl-net (verilog-decls-get-signals moddecls))))))
12354+
vl-bits
12355+
""))
1234112356
;; Replace @ and [] magic variables in final output
1234212357
(setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
1234312358
(setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net))
12344-
(setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
12359+
(setq tpl-net (verilog-string-replace-matches "\\[\\]" auto-inst-vector-tpl nil nil tpl-net)))
1234512360
;; Insert it
1234612361
(when (or tpl-ass (not verilog-auto-inst-template-required))
1234712362
(verilog--auto-inst-first indent-pt section)

0 commit comments

Comments
 (0)