mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-23 00:55:32 +00:00
verilog: fix handling of nested ifdef directives
- track depth so we know whether to consider higher-level elsifs - error on unmatched endif/elsif/else
This commit is contained in:
parent
b6904a8e53
commit
1ec5994100
8 changed files with 197 additions and 11 deletions
88
tests/simple/ifdef_1.v
Normal file
88
tests/simple/ifdef_1.v
Normal file
|
@ -0,0 +1,88 @@
|
|||
module top(o1, o2, o3, o4);
|
||||
|
||||
`define FAIL input wire not_a_port;
|
||||
|
||||
`ifdef COND_1
|
||||
`FAIL
|
||||
`elsif COND_2
|
||||
`FAIL
|
||||
`elsif COND_3
|
||||
`FAIL
|
||||
`elsif COND_4
|
||||
`FAIL
|
||||
`else
|
||||
|
||||
`define COND_4
|
||||
output wire o4;
|
||||
|
||||
`ifdef COND_1
|
||||
`FAIL
|
||||
`elsif COND_2
|
||||
`FAIL
|
||||
`elsif COND_3
|
||||
`FAIL
|
||||
`elsif COND_4
|
||||
|
||||
`define COND_3
|
||||
output wire o3;
|
||||
|
||||
`ifdef COND_1
|
||||
`FAIL
|
||||
`elsif COND_2
|
||||
`FAIL
|
||||
`elsif COND_3
|
||||
|
||||
`define COND_2
|
||||
output wire o2;
|
||||
|
||||
`ifdef COND_1
|
||||
`FAIL
|
||||
`elsif COND_2
|
||||
|
||||
`define COND_1
|
||||
output wire o1;
|
||||
|
||||
`ifdef COND_1
|
||||
|
||||
`ifdef COND_1
|
||||
`elsif COND_2
|
||||
`FAIL
|
||||
`elsif COND_3
|
||||
`FAIL
|
||||
`elsif COND_4
|
||||
`FAIL
|
||||
`else
|
||||
`FAIL
|
||||
`endif
|
||||
|
||||
`elsif COND_2
|
||||
`FAIL
|
||||
`elsif COND_3
|
||||
`FAIL
|
||||
`elsif COND_4
|
||||
`FAIL
|
||||
`else
|
||||
`FAIL
|
||||
`endif
|
||||
|
||||
`elsif COND_3
|
||||
`FAIL
|
||||
`elsif COND_4
|
||||
`FAIL
|
||||
`else
|
||||
`FAIL
|
||||
`endif
|
||||
|
||||
`elsif COND_4
|
||||
`FAIL
|
||||
`else
|
||||
`FAIL
|
||||
`endif
|
||||
|
||||
`else
|
||||
`FAIL
|
||||
`endif
|
||||
|
||||
`endif
|
||||
|
||||
endmodule
|
21
tests/simple/ifdef_2.v
Normal file
21
tests/simple/ifdef_2.v
Normal file
|
@ -0,0 +1,21 @@
|
|||
module top(o1, o2, o3);
|
||||
|
||||
output wire o1;
|
||||
|
||||
`define COND_1
|
||||
`define COND_2
|
||||
`define COND_3
|
||||
|
||||
`ifdef COND_1
|
||||
output wire o2;
|
||||
`elsif COND_2
|
||||
input wire dne1;
|
||||
`elsif COND_3
|
||||
input wire dne2;
|
||||
`else
|
||||
input wire dne3;
|
||||
`endif
|
||||
|
||||
output wire o3;
|
||||
|
||||
endmodule
|
30
tests/verilog/include_self.v
Normal file
30
tests/verilog/include_self.v
Normal file
|
@ -0,0 +1,30 @@
|
|||
`ifdef GUARD_5
|
||||
module top;
|
||||
wire x;
|
||||
endmodule
|
||||
|
||||
`elsif GUARD_4
|
||||
`define GUARD_5
|
||||
`include "include_self.v"
|
||||
|
||||
`elsif GUARD_3
|
||||
`define GUARD_4
|
||||
`include "include_self.v"
|
||||
|
||||
`elsif GUARD_2
|
||||
`define GUARD_3
|
||||
`include "include_self.v"
|
||||
|
||||
`elsif GUARD_1
|
||||
`define GUARD_2
|
||||
`include "include_self.v"
|
||||
|
||||
`elsif GUARD_0
|
||||
`define GUARD_1
|
||||
`include "include_self.v"
|
||||
|
||||
`else
|
||||
`define GUARD_0
|
||||
`include "include_self.v"
|
||||
|
||||
`endif
|
2
tests/verilog/include_self.ys
Normal file
2
tests/verilog/include_self.ys
Normal file
|
@ -0,0 +1,2 @@
|
|||
read_verilog include_self.v
|
||||
select -assert-count 1 top/x
|
6
tests/verilog/unmatched_else.ys
Normal file
6
tests/verilog/unmatched_else.ys
Normal file
|
@ -0,0 +1,6 @@
|
|||
logger -expect error "Found `else outside of macro conditional branch!" 1
|
||||
read_verilog <<EOT
|
||||
module top;
|
||||
`else
|
||||
endmodule
|
||||
EOT
|
6
tests/verilog/unmatched_elsif.ys
Normal file
6
tests/verilog/unmatched_elsif.ys
Normal file
|
@ -0,0 +1,6 @@
|
|||
logger -expect error "Found `elsif outside of macro conditional branch!" 1
|
||||
read_verilog <<EOT
|
||||
module top;
|
||||
`elsif
|
||||
endmodule
|
||||
EOT
|
6
tests/verilog/unmatched_endif.ys
Normal file
6
tests/verilog/unmatched_endif.ys
Normal file
|
@ -0,0 +1,6 @@
|
|||
logger -expect error "Found `endif outside of macro conditional branch!" 1
|
||||
read_verilog <<EOT
|
||||
module top;
|
||||
`endif
|
||||
endmodule
|
||||
EOT
|
Loading…
Add table
Add a link
Reference in a new issue