diff options
author | Peter Crozier <peter@crozier.com> | 2020-05-12 14:25:33 +0100 |
---|---|---|
committer | Peter Crozier <peter@crozier.com> | 2020-05-12 14:25:33 +0100 |
commit | f482c9c0168a6857383e7d9360c8ca1df36ba2bc (patch) | |
tree | 366454dd200407cc54ec7bec0c12b145715e5c25 /tests/svtypes/union_simple.sv | |
parent | 0b6b47ca670b9219bcb81ab7d3599267c2ef7571 (diff) | |
download | yosys-f482c9c0168a6857383e7d9360c8ca1df36ba2bc.tar.gz yosys-f482c9c0168a6857383e7d9360c8ca1df36ba2bc.tar.bz2 yosys-f482c9c0168a6857383e7d9360c8ca1df36ba2bc.zip |
Generalise structs and add support for packed unions.
Diffstat (limited to 'tests/svtypes/union_simple.sv')
-rw-r--r-- | tests/svtypes/union_simple.sv | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/svtypes/union_simple.sv b/tests/svtypes/union_simple.sv new file mode 100644 index 000000000..fc23fe6e8 --- /dev/null +++ b/tests/svtypes/union_simple.sv @@ -0,0 +1,61 @@ +module top; + + typedef struct packed { + byte a,b,c,d; + } byte4_t; + + typedef union packed { + int x; + byte4_t y; + } w_t; + + w_t w; + + assign w.x = 'h42; + always_comb begin + assert(w.y.d == 8'h42); + end + + typedef logic[4:0] reg_addr_t; + typedef logic[6:0] opcode_t; + + typedef struct packed { + bit [6:0] func7; + reg_addr_t rs2; + reg_addr_t rs1; + bit [2:0] func3; + reg_addr_t rd; + opcode_t opcode; + } R_t; + + typedef struct packed { + bit[11:0] imm; + reg_addr_t rs1; + bit[2:0] func3; + reg_addr_t rd; + opcode_t opcode; + } I_t; + + typedef struct packed { + bit[19:0] imm; + reg_addr_t rd; + opcode_t opcode; + } U_t; + + typedef union packed { + R_t r; + I_t i; + U_t u; + } instruction_t; + + instruction_t ir1; + assign ir1 = 32'h0AA01EB7; // lui t4,0xAA01 + always_comb begin + assert(ir1.u.opcode == 'h37); + assert(ir1.r.opcode == 'h37); + assert(ir1.u.rd == 'd29); + assert(ir1.r.rd == 'd29); + assert(ir1.u.imm == 'hAA01); + end + +endmodule |