Skip to content

Commit 2034ab7

Browse files
committed
Fix indentation of generate blocks omitting keyword (#1820).
* verilog-mode.el (verilog-in-generate-region-p): Fix indentation of generate blocks omitting keyword. Revert changes of PR #1815 and update tests accordingly. Signed-off-by: Gonzalo Larumbe <[email protected]>
1 parent 77a0fd9 commit 2034ab7

14 files changed

+436
-36
lines changed

tests/indent_generate.v

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
module test();
2-
2+
33
reg [3:0] x;
4-
4+
55
genvar i;
66
generate
77
for(i=0; i<4; i=i+1) begin:a
88
always @(*) begin
99
x[i] = 1;
1010
end
11-
wire y = 0;
11+
wire y = 0;
1212
end
1313
endgenerate
1414
endmodule // test
1515

16+
17+
module test();
18+
19+
reg [3:0] x;
20+
21+
genvar i;
22+
23+
for(i=0; i<4; i=i+1) begin:a
24+
always @(*) begin
25+
x[i] = 1;
26+
end
27+
wire y = 0;
28+
end
29+
30+
endmodule // test
31+

tests/indent_generate_bug1257.v

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Issue #1257
2+
3+
module t1
4+
(
5+
);
6+
7+
genvar pipe;
8+
logic [1:0] v;
9+
logic x;
10+
11+
//generate
12+
for (pipe=0; pipe<2; pipe++) begin : v_bl
13+
always_comb begin
14+
assign v[pipe] = '0;
15+
end
16+
assign x = '0; // will be incorrectly indented to column 0
17+
end
18+
//endgenerate
19+
20+
endmodule
21+
22+
23+
24+
25+
module indent;
26+
27+
// CASE 1 indented wrong. See end of module
28+
for (genvar aa = 0; aa < FF; aa++) begin : gen_hh
29+
for (genvar bb = 0; bb < FF; bb++) begin : gen_ii
30+
if (`asdf [aa]) begin : gen_jj
31+
32+
always_ff @ (negedge cc [aa][bb]) begin
33+
if (dd [aa][bb])) begin
34+
for (uint_t d_idx = 0; d_idx < 16; d_idx++)
35+
ee [aa][bb].push_front (tx_dfe_out [aa][bb] [15 - d_idx]);
36+
end
37+
end
38+
39+
always_ff @ (posedge hs_clk) begin
40+
ee_size [aa][bb] = ee [aa][bb].size();
41+
if (ee_size [aa][bb] > 0)
42+
gg [aa][bb] <= ee [aa][bb].pop_front;
43+
end
44+
45+
end : gen_jj
46+
end : gen_ii
47+
end : gen_hh
48+
49+
50+
51+
// this indents correctly without generate/endgenerate
52+
for (genvar aa = 0; aa < FF; aa++) begin : gen_hh
53+
for (genvar bb = 0; bb < FF; bb++) begin : gen_ii
54+
if (`asdf [aa]) begin : gen_jj
55+
assign a[aa][bb] = aa + bb;
56+
assign b[aa][bb] = aa + bb;
57+
end : gen_jj
58+
end : gen_ii
59+
end : gen_hh
60+
61+
62+
// this works now with gen/endgen
63+
generate
64+
for (genvar aa = 0; aa < FF; aa++) begin : gen_hh
65+
for (genvar bb = 0; bb < FF; bb++) begin : gen_ii
66+
always @ (negedge cc)
67+
a = 5;
68+
always @ (negedge dd)
69+
w = 2;
70+
end : gen_ii
71+
end : gen_hh
72+
endgenerate
73+
74+
75+
// CASE 1 again. No change but works - apparently since verilog-mode hit a generate statement above this line
76+
for (genvar aa = 0; aa < FF; aa++) begin : gen_hh
77+
for (genvar bb = 0; bb < FF; bb++) begin : gen_ii
78+
if (`asdf [aa]) begin : gen_jj
79+
80+
always_ff @ (negedge cc [aa][bb]) begin
81+
if (dd [aa][bb])) begin
82+
for (uint_t d_idx = 0; d_idx < 16; d_idx++)
83+
ee [aa][bb].push_front (tx_dfe_out [aa][bb] [15 - d_idx]);
84+
end
85+
end
86+
87+
always_ff @ (posedge hs_clk) begin
88+
ee_size [aa][bb] = ee [aa][bb].size();
89+
if (ee_size [aa][bb] > 0)
90+
gg [aa][bb] <= ee [aa][bb].pop_front;
91+
end
92+
93+
end : gen_jj
94+
end : gen_ii
95+
end : gen_hh
96+
97+
endmodule : indent

tests/indent_generate_bug1404.sv

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module test
66
(input logic y,z;
77
);
88

9-
generate
109
if (OPT = 1) begin
1110
always_comb begin
1211
y = 1'b1;
@@ -22,6 +21,5 @@ end
2221
end else begin
2322
assign z = 1'b0;
2423
end
25-
endgenerate
2624

2725
endmodule // test

tests/indent_generate_case.v

+31
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,34 @@ endcase
2424
endgenerate
2525

2626
endmodule
27+
28+
29+
30+
31+
// Without generate keyword
32+
module indent_gen_case #(parameter P = 0)
33+
(input d, output reg q);
34+
35+
36+
case (P)
37+
0: always @(*)
38+
q = d;
39+
40+
1: begin
41+
always @(*)
42+
q = d;
43+
end
44+
45+
2: always @(*) begin
46+
q = d;
47+
end
48+
49+
3: begin
50+
always @(*) begin
51+
q = d;
52+
end
53+
end
54+
endcase
55+
56+
57+
endmodule

tests/indent_generate_for.v

+23
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,26 @@ end
1616
endgenerate
1717

1818
endmodule
19+
20+
21+
22+
23+
// Without generate keyword
24+
module indent_gen_for #(parameter P = 1)
25+
(input d, output reg q);
26+
27+
genvar i;
28+
29+
for (i = 0; i < P; i += 1) begin
30+
always @(*) begin
31+
q = d;
32+
end
33+
end
34+
35+
for (i = 0; i < P; i += 1) begin
36+
always @(*)
37+
q = d;
38+
end
39+
40+
41+
endmodule

tests/indent_generate_if.v

+30
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,33 @@ end
2424
endgenerate
2525

2626
endmodule
27+
28+
29+
30+
// Without generate keyword
31+
module indent_gen_if #(parameter P = 0)
32+
(input d, output reg q);
33+
34+
35+
if (P == 0) begin
36+
always @(*)
37+
q = d;
38+
end
39+
40+
if (P == 1) begin
41+
always @(*) begin
42+
q = d;
43+
end
44+
end
45+
46+
if (P == 1) begin
47+
always @(*)
48+
q = d;
49+
end
50+
else begin
51+
always @(*)
52+
q = d + 1'b1;
53+
end
54+
55+
56+
endmodule

tests_ok/autoreset_inf_bug325.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ module aaa();
66
// note missing e-n-d
77
always @(*) begin
88
end
9-
endmodule
9+
endmodule

tests_ok/indent_generate.v

+16
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ module test();
1313
endgenerate
1414
endmodule // test
1515

16+
17+
module test();
18+
19+
reg [3:0] x;
20+
21+
genvar i;
22+
23+
for(i=0; i<4; i=i+1) begin:a
24+
always @(*) begin
25+
x[i] = 1;
26+
end
27+
wire y = 0;
28+
end
29+
30+
endmodule // test
31+

tests_ok/indent_generate_bug1257.v

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Issue #1257
2+
3+
module t1
4+
(
5+
);
6+
7+
genvar pipe;
8+
logic [1:0] v;
9+
logic x;
10+
11+
//generate
12+
for (pipe=0; pipe<2; pipe++) begin : v_bl
13+
always_comb begin
14+
assign v[pipe] = '0;
15+
end
16+
assign x = '0; // will be incorrectly indented to column 0
17+
end
18+
//endgenerate
19+
20+
endmodule
21+
22+
23+
24+
25+
module indent;
26+
27+
// CASE 1 indented wrong. See end of module
28+
for (genvar aa = 0; aa < FF; aa++) begin : gen_hh
29+
for (genvar bb = 0; bb < FF; bb++) begin : gen_ii
30+
if (`asdf [aa]) begin : gen_jj
31+
32+
always_ff @ (negedge cc [aa][bb]) begin
33+
if (dd [aa][bb])) begin
34+
for (uint_t d_idx = 0; d_idx < 16; d_idx++)
35+
ee [aa][bb].push_front (tx_dfe_out [aa][bb] [15 - d_idx]);
36+
end
37+
end
38+
39+
always_ff @ (posedge hs_clk) begin
40+
ee_size [aa][bb] = ee [aa][bb].size();
41+
if (ee_size [aa][bb] > 0)
42+
gg [aa][bb] <= ee [aa][bb].pop_front;
43+
end
44+
45+
end : gen_jj
46+
end : gen_ii
47+
end : gen_hh
48+
49+
50+
51+
// this indents correctly without generate/endgenerate
52+
for (genvar aa = 0; aa < FF; aa++) begin : gen_hh
53+
for (genvar bb = 0; bb < FF; bb++) begin : gen_ii
54+
if (`asdf [aa]) begin : gen_jj
55+
assign a[aa][bb] = aa + bb;
56+
assign b[aa][bb] = aa + bb;
57+
end : gen_jj
58+
end : gen_ii
59+
end : gen_hh
60+
61+
62+
// this works now with gen/endgen
63+
generate
64+
for (genvar aa = 0; aa < FF; aa++) begin : gen_hh
65+
for (genvar bb = 0; bb < FF; bb++) begin : gen_ii
66+
always @ (negedge cc)
67+
a = 5;
68+
always @ (negedge dd)
69+
w = 2;
70+
end : gen_ii
71+
end : gen_hh
72+
endgenerate
73+
74+
75+
// CASE 1 again. No change but works - apparently since verilog-mode hit a generate statement above this line
76+
for (genvar aa = 0; aa < FF; aa++) begin : gen_hh
77+
for (genvar bb = 0; bb < FF; bb++) begin : gen_ii
78+
if (`asdf [aa]) begin : gen_jj
79+
80+
always_ff @ (negedge cc [aa][bb]) begin
81+
if (dd [aa][bb])) begin
82+
for (uint_t d_idx = 0; d_idx < 16; d_idx++)
83+
ee [aa][bb].push_front (tx_dfe_out [aa][bb] [15 - d_idx]);
84+
end
85+
end
86+
87+
always_ff @ (posedge hs_clk) begin
88+
ee_size [aa][bb] = ee [aa][bb].size();
89+
if (ee_size [aa][bb] > 0)
90+
gg [aa][bb] <= ee [aa][bb].pop_front;
91+
end
92+
93+
end : gen_jj
94+
end : gen_ii
95+
end : gen_hh
96+
97+
endmodule : indent

0 commit comments

Comments
 (0)