3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-05-12 02:04:44 +00:00

ast.h: Move attribute check into set

There are a number of places that check for an existing attribute and delete it before assigning a new node to it.
Reduce code duplication by doing it as part of the `set_attribute()` method.
This commit is contained in:
Krystine Sherwin 2025-05-10 17:24:13 +12:00
parent c4af97c1c4
commit 10ea2fa67e
No known key found for this signature in database
3 changed files with 2 additions and 10 deletions

View file

@ -1174,10 +1174,6 @@ static RTLIL::Module *process_module(RTLIL::Design *design, AstNode *ast, bool d
delete ast->attributes.at(ID::lib_whitebox);
ast->attributes.erase(ID::lib_whitebox);
} else {
if (ast->attributes.count(ID::whitebox)) {
delete ast->attributes.at(ID::whitebox);
ast->attributes.erase(ID::whitebox);
}
AstNode *n = ast->attributes.at(ID::lib_whitebox);
ast->set_attribute(ID::whitebox, n);
ast->attributes.erase(ID::lib_whitebox);

View file

@ -360,6 +360,8 @@ namespace AST
void set_attribute(RTLIL::IdString key, AstNode *node)
{
if (attributes.count(key))
delete attributes.at(key);
attributes[key] = node;
node->set_in_param_flag(true);
}

View file

@ -1110,8 +1110,6 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
if (node->children.size() == 1 && node->children[0]->type == AST_RANGE) {
for (auto c : node->children[0]->children) {
if (!c->is_simple_const_expr()) {
if (attributes.count(ID::dynports))
delete attributes.at(ID::dynports);
set_attribute(ID::dynports, AstNode::mkconst_int(1, true));
}
}
@ -1159,8 +1157,6 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
if (node->is_signed)
first_node->is_signed = true;
for (auto &it : node->attributes) {
if (first_node->attributes.count(it.first) > 0)
delete first_node->attributes[it.first];
first_node->set_attribute(it.first, it.second->clone());
}
children.erase(children.begin()+(i--));
@ -1919,8 +1915,6 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin
if (!str.empty() && str[0] == '\\' && (template_node->type == AST_STRUCT || template_node->type == AST_UNION)) {
// replace instance with wire representing the packed structure
newNode = make_packed_struct(template_node, str, attributes);
if (newNode->attributes.count(ID::wiretype))
delete newNode->attributes[ID::wiretype];
newNode->set_attribute(ID::wiretype, mkconst_str(resolved_type_node->str));
// add original input/output attribute to resolved wire
newNode->is_input = this->is_input;