3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-23 00:55:32 +00:00

Generalise structs and add support for packed unions.

This commit is contained in:
Peter Crozier 2020-05-12 14:25:33 +01:00
parent 0b6b47ca67
commit f482c9c016
8 changed files with 209 additions and 59 deletions

View file

@ -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