aboutsummaryrefslogtreecommitdiffstats
path: root/tests/verilog
diff options
context:
space:
mode:
authorZachary Snow <zach@zachjs.com>2021-08-30 11:35:36 -0600
committerZachary Snow <zachary.j.snow@gmail.com>2021-08-30 15:19:21 -0600
commitf0a52e3dd275ee57a1b3ffd0a734b591bf21f668 (patch)
tree3c0c7883cf1e5045701ee5c739cfd6a6a6fbbc2c /tests/verilog
parent1dbf91a8ef3109d6573ae64fc3fd08aedc0a690d (diff)
downloadyosys-f0a52e3dd275ee57a1b3ffd0a734b591bf21f668.tar.gz
yosys-f0a52e3dd275ee57a1b3ffd0a734b591bf21f668.tar.bz2
yosys-f0a52e3dd275ee57a1b3ffd0a734b591bf21f668.zip
sv: support declaration in procedural for initialization
In line with other tools, this adds an extra wrapping block around such for loops to appropriately scope the variable.
Diffstat (limited to 'tests/verilog')
-rw-r--r--tests/verilog/for_decl_no_init.ys9
-rw-r--r--tests/verilog/for_decl_no_sv.ys9
-rw-r--r--tests/verilog/for_decl_shadow.sv32
-rw-r--r--tests/verilog/for_decl_shadow.ys6
4 files changed, 56 insertions, 0 deletions
diff --git a/tests/verilog/for_decl_no_init.ys b/tests/verilog/for_decl_no_init.ys
new file mode 100644
index 000000000..68c1584e0
--- /dev/null
+++ b/tests/verilog/for_decl_no_init.ys
@@ -0,0 +1,9 @@
+logger -expect error "For loop variable declaration is missing initialization!" 1
+read_verilog -sv <<EOT
+module top;
+ integer z;
+ initial
+ for (integer i; i < 10; i = i + 1)
+ z = i;
+endmodule
+EOT
diff --git a/tests/verilog/for_decl_no_sv.ys b/tests/verilog/for_decl_no_sv.ys
new file mode 100644
index 000000000..34edddff7
--- /dev/null
+++ b/tests/verilog/for_decl_no_sv.ys
@@ -0,0 +1,9 @@
+logger -expect error "For loop inline variable declaration is only supported in SystemVerilog mode!" 1
+read_verilog <<EOT
+module top;
+ integer z;
+ initial
+ for (integer i = 1; i < 10; i = i + 1)
+ z = i;
+endmodule
+EOT
diff --git a/tests/verilog/for_decl_shadow.sv b/tests/verilog/for_decl_shadow.sv
new file mode 100644
index 000000000..f6948f97e
--- /dev/null
+++ b/tests/verilog/for_decl_shadow.sv
@@ -0,0 +1,32 @@
+module gate(x);
+ output reg [15:0] x;
+ if (1) begin : gen
+ integer x;
+ initial begin
+ for (integer x = 5; x < 10; x++)
+ if (x == 5)
+ gen.x = 0;
+ else
+ gen.x += 2 ** x;
+ x = x * 2;
+ end
+ end
+ initial x = gen.x;
+endmodule
+
+module gold(x);
+ output reg [15:0] x;
+ if (1) begin : gen
+ integer x;
+ integer z;
+ initial begin
+ for (z = 5; z < 10; z++)
+ if (z == 5)
+ x = 0;
+ else
+ x += 2 ** z;
+ x = x * 2;
+ end
+ end
+ initial x = gen.x;
+endmodule
diff --git a/tests/verilog/for_decl_shadow.ys b/tests/verilog/for_decl_shadow.ys
new file mode 100644
index 000000000..d2dca715e
--- /dev/null
+++ b/tests/verilog/for_decl_shadow.ys
@@ -0,0 +1,6 @@
+read_verilog -sv for_decl_shadow.sv
+hierarchy
+proc
+equiv_make gold gate equiv
+equiv_simple
+equiv_status -assert