diff options
author | Dag Lem <dag@nimrod.no> | 2022-11-12 08:48:25 +0100 |
---|---|---|
committer | Dag Lem <dag@nimrod.no> | 2022-11-12 08:48:25 +0100 |
commit | bab88630c28b43851162772c2ce35666357d8933 (patch) | |
tree | 96e2dc4f9c1e552281b4f2b8260ced1783f856d0 /tests/svtypes | |
parent | a217450524e21222d8d32bd448f1ea2291685258 (diff) | |
download | yosys-bab88630c28b43851162772c2ce35666357d8933.tar.gz yosys-bab88630c28b43851162772c2ce35666357d8933.tar.bz2 yosys-bab88630c28b43851162772c2ce35666357d8933.zip |
Support for arrays with swapped ranges within structs
This also corrects the implementation of C type arrays within structs.
Fixes #3550
Diffstat (limited to 'tests/svtypes')
-rw-r--r-- | tests/svtypes/struct_array.sv | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/tests/svtypes/struct_array.sv b/tests/svtypes/struct_array.sv index 873f7befd..d33d18da2 100644 --- a/tests/svtypes/struct_array.sv +++ b/tests/svtypes/struct_array.sv @@ -1,7 +1,6 @@ // test for array indexing in structures module top; - struct packed { bit [5:0] [7:0] a; // 6 element packed array of bytes bit [15:0] b; // filler for non-zero offset @@ -39,4 +38,90 @@ module top; always_comb assert(s2==80'hFC00_4200_0012_3400_FFFC); + // Same as s2, but with little endian addressing + struct packed { + bit [0:7] [7:0] a; // 8 element packed array of bytes + bit [0:15] b; // filler for non-zero offset + } s3; + + initial begin + s3 = '0; + + s3.a[5:6] = 16'h1234; + s3.a[2] = 8'h42; + + s3.a[0] = '1; + s3.a[0][1:0] = '0; + + s3.b = '1; + s3.b[14:15] = '0; + end + + always_comb assert(s3==80'hFC00_4200_0012_3400_FFFC); + + // Note that the tests below for unpacked arrays in structs rely on the + // fact that they are actually packed in Yosys. + + // Same as s2, but using unpacked array syntax + struct packed { + bit [7:0] a [7:0]; // 8 element unpacked array of bytes + bit [15:0] b; // filler for non-zero offset + } s4; + + initial begin + s4 = '0; + + s4.a[2:1] = 16'h1234; + s4.a[5] = 8'h42; + + s4.a[7] = '1; + s4.a[7][1:0] = '0; + + s4.b = '1; + s4.b[1:0] = '0; + end + + always_comb assert(s4==80'hFC00_4200_0012_3400_FFFC); + + // Same as s3, but using unpacked array syntax + struct packed { + bit [7:0] a [0:7]; // 8 element unpacked array of bytes + bit [0:15] b; // filler for non-zero offset + } s5; + + initial begin + s5 = '0; + + s5.a[5:6] = 16'h1234; + s5.a[2] = 8'h42; + + s5.a[0] = '1; + s5.a[0][1:0] = '0; + + s5.b = '1; + s5.b[14:15] = '0; + end + + always_comb assert(s5==80'hFC00_4200_0012_3400_FFFC); + + // Same as s5, but using C-type unpacked array syntax + struct packed { + bit [7:0] a [8]; // 8 element unpacked array of bytes + bit [0:15] b; // filler for non-zero offset + } s6; + + initial begin + s6 = '0; + + s6.a[5:6] = 16'h1234; + s6.a[2] = 8'h42; + + s6.a[0] = '1; + s6.a[0][1:0] = '0; + + s6.b = '1; + s6.b[14:15] = '0; + end + + always_comb assert(s6==80'hFC00_4200_0012_3400_FFFC); endmodule |