Skip to content

Commit

Permalink
Add a function to remove attributes from trees
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Mar 25, 2014
1 parent 682e64a commit 36bc3db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -6343,17 +6343,9 @@ static void cgen_cleanup_tmp_attrs(tree_t top)
for (int i = 0; i < ndecls; i++) {
tree_t d = tree_decl(top, i);

if (tree_attr_ptr(d, local_var_i))
tree_add_attr_ptr(d, local_var_i, NULL);

if (tree_attr_ptr(d, global_const_i))
tree_add_attr_ptr(d, global_const_i, NULL);

if (tree_attr_ptr(d, sig_nets_i))
tree_add_attr_ptr(d, sig_nets_i, NULL);

if (tree_attr_ptr(d, llvm_agg_i))
tree_add_attr_ptr(d, llvm_agg_i, NULL);
tree_remove_attr(d, local_var_i);
tree_remove_attr(d, global_const_i);
tree_remove_attr(d, sig_nets_i);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,24 @@ static attr_t *tree_add_attr(tree_t t, ident_t name, attr_kind_t kind)
return &(t->attrs.table[i]);
}

void tree_remove_attr(tree_t t, ident_t name)
{
assert(t != NULL);
assert(name != NULL);

unsigned i;
for (i = 0; (i < t->attrs.num) && (t->attrs.table[i].name != name); i++)
;

if (i == t->attrs.num)
return;

for (; i + 1 < t->attrs.num; i++)
t->attrs.table[i] = t->attrs.table[i + 1];

t->attrs.num--;
}

void tree_add_attr_str(tree_t t, ident_t name, ident_t str)
{
tree_add_attr(t, name, A_STRING)->sval = str;
Expand Down
1 change: 1 addition & 0 deletions src/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ void tree_add_attr_ptr(tree_t t, ident_t name, void *ptr);
void *tree_attr_ptr(tree_t t, ident_t name);
tree_t tree_attr_tree(tree_t t, ident_t name);
void tree_add_attr_tree(tree_t t, ident_t name, tree_t val);
void tree_remove_attr(tree_t t, ident_t name);

typedef void (*tree_visit_fn_t)(tree_t t, void *context);
unsigned tree_visit(tree_t t, tree_visit_fn_t fn, void *context);
Expand Down

0 comments on commit 36bc3db

Please sign in to comment.