mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-06 06:03:23 +00:00
sv: fix two struct access bugs
- preserve signedness of struct members - fix initial width detection of struct members (e.g., in case expressions)
This commit is contained in:
parent
1aab608cff
commit
a9c8ca21d5
5 changed files with 102 additions and 1 deletions
|
@ -370,6 +370,9 @@ namespace AST
|
|||
|
||||
// Helper for setting the src attribute.
|
||||
void set_src_attr(RTLIL::AttrObject *obj, const AstNode *ast);
|
||||
|
||||
// struct helper exposed from simplify for genrtlil
|
||||
AstNode *make_struct_member_range(AstNode *node, AstNode *member_node);
|
||||
}
|
||||
|
||||
namespace AST_INTERNAL
|
||||
|
|
|
@ -812,6 +812,10 @@ 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;
|
||||
if (children.size() > 1)
|
||||
range = children[1];
|
||||
} else if (id_ast->type == AST_STRUCT_ITEM) {
|
||||
AstNode *tmp_range = make_struct_member_range(this, id_ast);
|
||||
this_width = tmp_range->range_left - tmp_range->range_right + 1;
|
||||
delete tmp_range;
|
||||
} else
|
||||
log_file_error(filename, location.first_line, "Failed to detect width for identifier %s!\n", str.c_str());
|
||||
if (range) {
|
||||
|
|
|
@ -456,7 +456,7 @@ static AstNode *slice_range(AstNode *rnode, AstNode *snode)
|
|||
}
|
||||
|
||||
|
||||
static AstNode *make_struct_member_range(AstNode *node, AstNode *member_node)
|
||||
AstNode *AST::make_struct_member_range(AstNode *node, AstNode *member_node)
|
||||
{
|
||||
// Work out the range in the packed array that corresponds to a struct member
|
||||
// taking into account any range operations applicable to the current node
|
||||
|
@ -1693,6 +1693,8 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
|
|||
newNode = new AstNode(AST_IDENTIFIER, range);
|
||||
newNode->str = sname;
|
||||
newNode->basic_prep = true;
|
||||
if (item_node->is_signed)
|
||||
newNode = new AstNode(AST_TO_SIGNED, newNode);
|
||||
goto apply_newNode;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue