mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-06 06:03:23 +00:00
ast/simplify: Make in_lvalue/in_param into props of AST nodes
Instead of passing around in_lvalue/in_param flags to simplify, we make the flags into properties of the AST nodes themselves. After the tree is first parsed, we once do ast->fixup_hierarchy_flags(true) to walk the full hierarchy and set the flags to their initial correct values. Then as long as one is using ->clone(), ->cloneInto() and the AstNode constructor (with children passed to it) to modify the tree, the flags will be kept in sync automatically. On the other hand if we are modifying the children list of an existing node, we may need to call node->fixup_hierarchy_flags() to do a localized fixup. That fixup will update the flags on the node's children, and will propagate the change down the tree if necessary. clone() doesn't always retain the flags of the subtree being cloned. It will produce a tree with a consistent setting of the flags, but the root doesn't have in_param/in_lvalue set unless it's intrinsic to the type of node being cloned (e.g. AST_PARAMETER). cloneInto() will make sure the cloned subtree has the flags consistent with the new placement in a hierarchy. Add asserts to make sure the old and new way of determining the flags agree.
This commit is contained in:
parent
10d0e69588
commit
22b99413e8
4 changed files with 222 additions and 42 deletions
|
@ -221,6 +221,13 @@ namespace AST
|
|||
std::string filename;
|
||||
AstSrcLocType location;
|
||||
|
||||
// are we embedded in an lvalue, param?
|
||||
// (see fixup_hierarchy_flags)
|
||||
bool in_lvalue;
|
||||
bool in_param;
|
||||
bool in_lvalue_from_above;
|
||||
bool in_param_from_above;
|
||||
|
||||
// creating and deleting nodes
|
||||
AstNode(AstNodeType type = AST_NONE, AstNode *child1 = nullptr, AstNode *child2 = nullptr, AstNode *child3 = nullptr, AstNode *child4 = nullptr);
|
||||
AstNode *clone() const;
|
||||
|
@ -343,6 +350,24 @@ namespace AST
|
|||
// to evaluate widths of dynamic ranges)
|
||||
AstNode *clone_at_zero();
|
||||
|
||||
void set_attribute(RTLIL::IdString key, AstNode *node)
|
||||
{
|
||||
attributes[key] = node;
|
||||
node->set_in_param_flag(true);
|
||||
}
|
||||
|
||||
// helper to set in_lvalue/in_param flags from the hierarchy context (the actual flag
|
||||
// can be overridden based on the intrinsic properties of this node, i.e. based on its type)
|
||||
void set_in_lvalue_flag(bool flag, bool no_descend = false);
|
||||
void set_in_param_flag(bool flag, bool no_descend = false);
|
||||
|
||||
// fix up the hierarchy flags (in_lvalue/in_param) of this node and its children
|
||||
//
|
||||
// to keep the flags in sync, fixup_hierarchy_flags(true) needs to be called once after
|
||||
// parsing the AST to walk the full tree, then plain fixup_hierarchy_flags() performs
|
||||
// localized fixups after modifying children/attributes of a particular node
|
||||
void fixup_hierarchy_flags(bool force_descend = false);
|
||||
|
||||
// helper to print errors from simplify/genrtlil code
|
||||
[[noreturn]] void input_error(const char *format, ...) const YS_ATTRIBUTE(format(printf, 2, 3));
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue