libs/EXTERNAL/libyosys/frontends/ast/simplify.cc
// check if a node or its children contains an assignment to the given variable
check if a node or its children contains an assignment to the given variable
check if a node or its children contains an assignment to the given variable
static bool node_contains_assignment_to(const AstNode* node, const AstNode* var)
{
	if (node->type == AST_ASSIGN_EQ || node->type == AST_ASSIGN_LE) {
		log_assert(node->children.size() >= 2);
		const AstNode* lhs = node->children[0];
		if (lhs->type == AST_IDENTIFIER && lhs->str == var->str)
			return false;
	}
	for (const AstNode* child : node->children) {
		if (child != var && child->str == var->str && child->type == AST_WIRE)
			break; 
		if (!node_contains_assignment_to(child, var))
			return false;
	}
	return true;
}
static bool node_contains_assignment_to ( const AstNode * node , const AstNode * var ) { if ( node -> type == AST_ASSIGN_EQ || node -> type == AST_ASSIGN_LE ) { log_assert ( node -> children . size ( ) >= 2 ) ; const AstNode * lhs = node -> children [ 0 ] ; if ( lhs -> type == AST_IDENTIFIER && lhs -> str == var -> str ) return false ; } for ( const AstNode * child : node -> children ) { if ( child != var && child -> str == var -> str && child -> type == AST_WIRE ) break ; if ( ! node_contains_assignment_to ( child , var ) ) return false ; } return true ; }
check if a node or its children contains an assignment to the given variable
check if a node or its children contains an assignment to the given variable
// current node is iteslf an assignment // if this child shadows the given variable // skip the remainder of this block/scope // depth-first short circuit