From 65aff653442fbb6a58bb57c1b71945839b87b48b Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 25 Sep 2019 12:18:41 -0700 Subject: [PATCH] Better job choosing unique scope-local symbols during elaboration. --- net_scope.cc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/net_scope.cc b/net_scope.cc index b9873786e..006cbd5c2 100644 --- a/net_scope.cc +++ b/net_scope.cc @@ -743,9 +743,28 @@ const NetScope* NetScope::child_byname(perm_string name) const perm_string NetScope::local_symbol() { - ostringstream res; - res << "_s" << (lcounter_++); - return lex_strings.make(res.str()); + perm_string sym; + do { + ostringstream res; + res << "_ivl_" << (lcounter_++); + perm_string sym_tmp = lex_strings.make(res.str()); + + // If the name already exists as a signal, try again. + if (signals_map_.find(sym_tmp) != signals_map_.end()) + continue; + // If the name already exists as a parameter, try again. + if (parameters.find(sym_tmp) != parameters.end()) + continue; + if (genvars_.find(sym_tmp) != genvars_.end()) + continue; + // If the name already exists as a class, try again. + if (classes_.find(sym_tmp) != classes_.end()) + continue; + + // No collisions, this is the one. + sym = sym_tmp; + } while (sym.nil()); + return sym; } void NetScope::add_tie_hi(Design*des)