From 9a563e9bab67520739e0d747c61730d9e35247a2 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 30 Dec 2023 13:31:30 -0800 Subject: [PATCH] Add regression test for nested struct width Check that expression width is correctly calculated for nested structs. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/struct_nested1.v | 69 ++++++++++++++++++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/struct_nested1.json | 5 ++ 3 files changed, 75 insertions(+) create mode 100644 ivtest/ivltests/struct_nested1.v create mode 100644 ivtest/vvp_tests/struct_nested1.json diff --git a/ivtest/ivltests/struct_nested1.v b/ivtest/ivltests/struct_nested1.v new file mode 100644 index 000000000..ad24ed974 --- /dev/null +++ b/ivtest/ivltests/struct_nested1.v @@ -0,0 +1,69 @@ +// Check that the width on a nested struct member is calculated correctly + +module test; + + bit failed = 1'b0; + + `define check(expr, val) do \ + if (expr !== val) begin \ + $display("FAILED(%0d): `%s`, expected %0d, got %0d", `__LINE__, `"expr`", val, expr); \ + failed = 1'b1; \ + end \ + while (0) + + typedef enum bit [15:0] { + A, B + } E; + + + struct packed { + struct packed { + struct packed { + reg [7:0][3:0] x; + E e; + } s2; + int z; + } s1; + int y; + } s0; + + initial begin + + `check($bits(s0), 112); + `check($bits(s0.s1), 80); + `check($bits(s0.s1.s2), 48); + `check($bits(s0.s1.s2.x), 32); + `check($bits(s0.s1.s2.e), 16); + `check($bits(s0.s1.s2.e.next), 16); + `check($bits(s0.s1.s2.e.prev), 16); + `check($bits(s0.s1.s2.e.first), 16); + `check($bits(s0.s1.s2.e.last), 16); + `check($bits(s0.s1.s2.e.num), 32); + + `check($bits(s0[0]), 1); + `check($bits(s0.s1[0]), 1); + `check($bits(s0.s1.s2[0]), 1); + `check($bits(s0.s1.s2.x[0]), 4); + `check($bits(s0.s1.s2.x[0][0]), 1); + `check($bits(s0.s1.s2.e[0]), 1); + + `check($bits(s0[1:0]), 2); + `check($bits(s0.s1[1:0]), 2); + `check($bits(s0.s1.s2[1:0]), 2); + `check($bits(s0.s1.s2.x[1:0]), 8); + `check($bits(s0.s1.s2.x[0][1:0]), 2); + `check($bits(s0.s1.s2.e[1:0]), 2); + + `check($bits(s0[0+:2]), 2); + `check($bits(s0.s1[0+:2]), 2); + `check($bits(s0.s1.s2[0+:2]), 2); + `check($bits(s0.s1.s2.x[0+:2]), 8); + `check($bits(s0.s1.s2.x[0][0+:2]), 2); + `check($bits(s0.s1.s2.e[0+:2]), 2); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 81a6d9fec..d8a03d352 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -132,6 +132,7 @@ sf_onehot_fail vvp_tests/sf_onehot_fail.json sf_onehot0_fail vvp_tests/sf_onehot0_fail.json struct_enum_partsel vvp_tests/struct_enum_partsel.json struct_field_left_right vvp_tests/struct_field_left_right.json +struct_nested1 vvp_tests/struct_nested1.json struct_packed_write_read vvp_tests/struct_packed_write_read.json struct_packed_write_read2 vvp_tests/struct_packed_write_read2.json sv_2state_array_init_prop vvp_tests/sv_2state_array_init_prop.json diff --git a/ivtest/vvp_tests/struct_nested1.json b/ivtest/vvp_tests/struct_nested1.json new file mode 100644 index 000000000..e5fa64d3a --- /dev/null +++ b/ivtest/vvp_tests/struct_nested1.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "struct_nested1.v", + "iverilog-args" : [ "-g2005-sv" ] +}