aboutsummaryrefslogtreecommitdiffstats
path: root/tests/verilog
diff options
context:
space:
mode:
authorZachary Snow <zach@zachjs.com>2021-06-22 10:39:57 -0400
committerZachary Snow <zachary.j.snow@gmail.com>2021-07-15 11:57:20 -0400
commita9c8ca21d583c58a38931389f90bbaae0caec0d6 (patch)
treeeab021de70957cf08a44d296fbf63b29e3a3e9e7 /tests/verilog
parent1aab608cffa19332dc5cf722def7413b16f5ee54 (diff)
downloadyosys-a9c8ca21d583c58a38931389f90bbaae0caec0d6.tar.gz
yosys-a9c8ca21d583c58a38931389f90bbaae0caec0d6.tar.bz2
yosys-a9c8ca21d583c58a38931389f90bbaae0caec0d6.zip
sv: fix two struct access bugs
- preserve signedness of struct members - fix initial width detection of struct members (e.g., in case expressions)
Diffstat (limited to 'tests/verilog')
-rw-r--r--tests/verilog/struct_access.sv88
-rw-r--r--tests/verilog/struct_access.ys4
2 files changed, 92 insertions, 0 deletions
diff --git a/tests/verilog/struct_access.sv b/tests/verilog/struct_access.sv
new file mode 100644
index 000000000..f13b8dd51
--- /dev/null
+++ b/tests/verilog/struct_access.sv
@@ -0,0 +1,88 @@
+module top;
+
+ typedef struct packed {
+ logic a;
+ logic signed b;
+ byte c;
+ byte unsigned d;
+ reg [3:0] e;
+ reg signed [3:0] f;
+ struct packed {
+ logic a;
+ logic signed b;
+ } x;
+ struct packed signed {
+ logic a;
+ logic signed b;
+ } y;
+ } S;
+ S s;
+
+ initial begin
+ // test codegen for LHS
+ s.a = '1;
+ s.b = '1;
+ s.c = '1;
+ s.d = '1;
+ s.e = '1;
+ s.f = '1;
+ s.x.a = '1;
+ s.x.b = '1;
+ s.y.a = '1;
+ s.y.b = '1;
+ end
+
+`define CHECK(expr, width, signedness) \
+ case (expr) \
+ 1'sb1: \
+ case (expr) \
+ 2'sb11: if (!(signedness)) fail = 1; \
+ default: if (signedness) fail = 1; \
+ endcase \
+ default: if (signedness) fail = 1; \
+ endcase \
+ case (expr) \
+ 1'b1: if ((width) != 1) fail = 1; \
+ 2'b11: if ((width) != 2) fail = 1; \
+ 3'b111: if ((width) != 3) fail = 1; \
+ 4'b1111: if ((width) != 4) fail = 1; \
+ 5'b1111_1: if ((width) != 5) fail = 1; \
+ 6'b1111_11: if ((width) != 6) fail = 1; \
+ 7'b1111_11: if ((width) != 7) fail = 1; \
+ 8'b1111_1111: if ((width) != 8) fail = 1; \
+ 9'b1111_1111_1: if ((width) != 9) fail = 1; \
+ default: fail = 1; \
+ endcase \
+ begin \
+ reg [9:0] indirect; \
+ indirect = (expr); \
+ if ((indirect != (expr)) != (signedness)) fail = 1; \
+ indirect = $unsigned(expr); \
+ if ($countones(indirect) != (width)) fail = 1; \
+ end
+
+ initial begin
+ reg fail;
+ fail = 0;
+
+ `CHECK(s.a, 1, 0)
+ `CHECK(s.b, 1, 1)
+ `CHECK(s.c, 8, 1)
+ `CHECK(s.d, 8, 0)
+ `CHECK(s.e, 4, 0)
+ `CHECK(s.f, 4, 1)
+
+ `CHECK(s.x.a, 1, 0)
+ `CHECK(s.x.b, 1, 1)
+ `CHECK(s.y.a, 1, 0)
+ `CHECK(s.y.b, 1, 1)
+
+ // TODO(zachjs): support access to whole sub-structs and unions
+ // `CHECK(s.x, 2, 0)
+ // `CHECK(s.y, 2, 1)
+
+ assert (fail === 0);
+ end
+
+
+endmodule
diff --git a/tests/verilog/struct_access.ys b/tests/verilog/struct_access.ys
new file mode 100644
index 000000000..29d569c01
--- /dev/null
+++ b/tests/verilog/struct_access.ys
@@ -0,0 +1,4 @@
+read_verilog -formal -sv struct_access.sv
+proc
+opt -full
+sat -verify -seq 1 -prove-asserts -show-all