Skip to content

Commit b526d6f

Browse files
committed
Fix `verilog-auto-inst-param-value' confusing structure selects.
* verilog-mode.el (verilog-simplify-range-expression): Fix `verilog-auto-inst-param-value' confusing structure selects. Reported by Mike Bertone.
1 parent 86c6984 commit b526d6f

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

tests/autoinst_param_structsel.v

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
typedef struct packed {
2+
logic size;
3+
} config_t;
4+
5+
parameter config_t CFG8 = '{size: 8};
6+
parameter config_t CFG4 = '{size: 4};
7+
8+
module m0 (
9+
/*AUTOINPUT*/
10+
);
11+
m4
12+
m4(/*AUTOINST*/);
13+
m8 #(.CFG(CFG8))
14+
m8(/*AUTOINST*/);
15+
endmodule
16+
17+
module m4
18+
#(
19+
parameter config_t CFG = CFG4
20+
)
21+
(
22+
input a4,
23+
input [CFG.size-1:0] b4
24+
);
25+
endmodule
26+
27+
module m8
28+
#(
29+
parameter config_t CFG = CFG8
30+
)
31+
(
32+
input a8,
33+
input [CFG.size-1:0] b8
34+
);
35+
endmodule
36+
37+
// Local Variables:
38+
// verilog-typedef-regexp: "_[tT]$"
39+
// verilog-auto-inst-param-value:t
40+
// verilog-auto-inst-param-value-type:t
41+
// verilog-align-typedef-regexp: "\\<[a-zA-Z_][a-zA-Z_0-9]*_[tT]\\>"
42+
// End:

tests_ok/autoinst_param_structsel.v

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
typedef struct packed {
2+
logic size;
3+
} config_t;
4+
5+
parameter config_t CFG8 = '{size: 8};
6+
parameter config_t CFG4 = '{size: 4};
7+
8+
module m0 (
9+
/*AUTOINPUT*/
10+
// Beginning of automatic inputs (from unused autoinst inputs)
11+
input a4, // To m4 of m4.v
12+
input a8, // To m8 of m8.v
13+
input [CFG.size-1:0] b4, // To m4 of m4.v
14+
input [CFG8.size-1:0] b8 // To m8 of m8.v
15+
// End of automatics
16+
);
17+
m4
18+
m4(/*AUTOINST*/
19+
// Inputs
20+
.a4 (a4),
21+
.b4 (b4[CFG.size-1:0]));
22+
m8 #(.CFG(CFG8))
23+
m8(/*AUTOINST*/
24+
// Inputs
25+
.a8 (a8),
26+
.b8 (b8[CFG8.size-1:0]));
27+
endmodule
28+
29+
module m4
30+
#(
31+
parameter config_t CFG = CFG4
32+
)
33+
(
34+
input a4,
35+
input [CFG.size-1:0] b4
36+
);
37+
endmodule
38+
39+
module m8
40+
#(
41+
parameter config_t CFG = CFG8
42+
)
43+
(
44+
input a8,
45+
input [CFG.size-1:0] b8
46+
);
47+
endmodule
48+
49+
// Local Variables:
50+
// verilog-typedef-regexp: "_[tT]$"
51+
// verilog-auto-inst-param-value:t
52+
// verilog-auto-inst-param-value-type:t
53+
// verilog-align-typedef-regexp: "\\<[a-zA-Z_][a-zA-Z_0-9]*_[tT]\\>"
54+
// End:

verilog-mode.el

+3-2
Original file line numberDiff line numberDiff line change
@@ -11439,7 +11439,7 @@ This repairs those mis-inserted by an AUTOARG."
1143911439
(while (string-match
1144011440
(concat "\\([[({:*/<>+-]\\)" ; - must be last
1144111441
"(\\<\\([0-9A-Za-z_]+\\))"
11442-
"\\([])}:*/<>+-]\\)")
11442+
"\\([])}:*/<>.+-]\\)")
1144311443
out)
1144411444
(setq out (replace-match "\\1\\2\\3" nil nil out)))
1144511445
(while (string-match
@@ -11534,7 +11534,8 @@ This repairs those mis-inserted by an AUTOARG."
1153411534
;;(verilog-simplify-range-expression "[(TEST[1])-1:0]")
1153511535
;;(verilog-simplify-range-expression "[1<<2:8>>2]") ; [4:2]
1153611536
;;(verilog-simplify-range-expression "[2*4/(4-2) +2+4 <<4 >>2]")
11537-
;;(verilog-simplify-range-expression "[WIDTH*2/8-1:0]")
11537+
;;(verilog-simplify-range-expression "[WIDTH*2/8-1:0]") ; "[WIDTH*2/8-1:0]"
11538+
;;(verilog-simplify-range-expression "[(FOO).size:0]") ; "[FOO.size:0]"
1153811539

1153911540
(defun verilog-clog2 (value)
1154011541
"Compute $clog2 - ceiling log2 of VALUE."

0 commit comments

Comments
 (0)