mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-07 06:33:24 +00:00
Handle struct members of union type (#3641)
This commit is contained in:
parent
541fdffff2
commit
db13c6df2b
3 changed files with 18 additions and 2 deletions
|
@ -877,7 +877,7 @@ void AstNode::detectSignWidthWorker(int &width_hint, bool &sign_hint, bool *foun
|
||||||
this_width = id_ast->children[0]->range_left - id_ast->children[0]->range_right + 1;
|
this_width = id_ast->children[0]->range_left - id_ast->children[0]->range_right + 1;
|
||||||
if (children.size() > 1)
|
if (children.size() > 1)
|
||||||
range = children[1];
|
range = children[1];
|
||||||
} else if (id_ast->type == AST_STRUCT_ITEM || id_ast->type == AST_STRUCT) {
|
} else if (id_ast->type == AST_STRUCT_ITEM || id_ast->type == AST_STRUCT || id_ast->type == AST_UNION) {
|
||||||
AstNode *tmp_range = make_struct_member_range(this, id_ast);
|
AstNode *tmp_range = make_struct_member_range(this, id_ast);
|
||||||
this_width = tmp_range->range_left - tmp_range->range_right + 1;
|
this_width = tmp_range->range_left - tmp_range->range_right + 1;
|
||||||
delete tmp_range;
|
delete tmp_range;
|
||||||
|
|
|
@ -2063,7 +2063,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
||||||
if (name_has_dot(str, sname)) {
|
if (name_has_dot(str, sname)) {
|
||||||
if (current_scope.count(str) > 0) {
|
if (current_scope.count(str) > 0) {
|
||||||
auto item_node = current_scope[str];
|
auto item_node = current_scope[str];
|
||||||
if (item_node->type == AST_STRUCT_ITEM || item_node->type == AST_STRUCT) {
|
if (item_node->type == AST_STRUCT_ITEM || item_node->type == AST_STRUCT || item_node->type == AST_UNION) {
|
||||||
// structure member, rewrite this node to reference the packed struct wire
|
// structure member, rewrite this node to reference the packed struct wire
|
||||||
auto range = make_struct_member_range(this, item_node);
|
auto range = make_struct_member_range(this, item_node);
|
||||||
newNode = new AstNode(AST_IDENTIFIER, range);
|
newNode = new AstNode(AST_IDENTIFIER, range);
|
||||||
|
|
|
@ -48,14 +48,30 @@ module top;
|
||||||
U_t u;
|
U_t u;
|
||||||
} instruction_t;
|
} instruction_t;
|
||||||
|
|
||||||
|
typedef struct packed {
|
||||||
|
instruction_t ir;
|
||||||
|
logic [3:0] state;
|
||||||
|
} s_t;
|
||||||
|
|
||||||
instruction_t ir1;
|
instruction_t ir1;
|
||||||
|
s_t s1;
|
||||||
|
|
||||||
assign ir1 = 32'h0AA01EB7; // lui t4,0xAA01
|
assign ir1 = 32'h0AA01EB7; // lui t4,0xAA01
|
||||||
|
assign s1.ir = ir1;
|
||||||
|
assign s1.state = '1;
|
||||||
|
|
||||||
always_comb begin
|
always_comb begin
|
||||||
assert(ir1.u.opcode == 'h37);
|
assert(ir1.u.opcode == 'h37);
|
||||||
assert(ir1.r.opcode == 'h37);
|
assert(ir1.r.opcode == 'h37);
|
||||||
assert(ir1.u.rd == 'd29);
|
assert(ir1.u.rd == 'd29);
|
||||||
assert(ir1.r.rd == 'd29);
|
assert(ir1.r.rd == 'd29);
|
||||||
assert(ir1.u.imm == 'hAA01);
|
assert(ir1.u.imm == 'hAA01);
|
||||||
|
assert(s1.ir.u.opcode == 'h37);
|
||||||
|
assert(s1.ir.r.opcode == 'h37);
|
||||||
|
assert(s1.ir.u.rd == 'd29);
|
||||||
|
assert(s1.ir.r.rd == 'd29);
|
||||||
|
assert(s1.ir.u.imm == 'hAA01);
|
||||||
|
assert(s1.state == 4'b1111);
|
||||||
end
|
end
|
||||||
|
|
||||||
union packed {
|
union packed {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue