diff options
| author | azidar | 2015-10-06 14:28:24 -0700 |
|---|---|---|
| committer | azidar | 2015-10-06 14:28:24 -0700 |
| commit | 2485d20374166b27c06c475a4aef365761a818f7 (patch) | |
| tree | 627b3c180ba41d7619b1acc8be03e2195dd208aa /src/main/stanza/ir-utils.stanza | |
| parent | 62e922b0e7ea5f90c14a918ab09ce04a28f082d4 (diff) | |
| parent | 0a9dfbe9f58338fc8af11015f6e9227e0cb46ea4 (diff) | |
Merge branch 'master' of github.com:ucb-bar/firrtl
Conflicts:
README.md
Diffstat (limited to 'src/main/stanza/ir-utils.stanza')
| -rw-r--r-- | src/main/stanza/ir-utils.stanza | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main/stanza/ir-utils.stanza b/src/main/stanza/ir-utils.stanza index a234ff81..27acedb3 100644 --- a/src/main/stanza/ir-utils.stanza +++ b/src/main/stanza/ir-utils.stanza @@ -9,6 +9,11 @@ public defmulti print-debug (o:OutputStream, e:Expression|Stmt|Type|Port|Field|M ;============== GENSYM STUFF ====================== +defn generated? (s:String) -> False|Int : + for i in 1 to length(s) - 1 find : + val sub = substring(s,i + 1) + s[i] == '_' and digits?(sub) and s[i - 1] != '_' + public defn firrtl-gensym (s:Symbol) -> Symbol : firrtl-gensym(s,HashTable<Symbol,Int>(symbol-hash)) public defn firrtl-gensym (sym-hash:HashTable<Symbol,Int>) -> Symbol : @@ -31,11 +36,11 @@ public defn firrtl-gensym (s:Symbol,sym-hash:HashTable<Symbol,Int>) -> Symbol : sym-hash[s] = 0 s val s* = to-string(s) - val i* = for i in 0 to length(s*) - 1 find : - s*[i] == '_' and digits?(substring(s*,i + 1)) - match(i*) : + val i* = generated?(s*) + val nex = match(i*) : (i:False) : get-name(s) (i:Int) : get-name(to-symbol(substring(s*,0,i))) + nex public defn get-sym-hash (m:InModule) -> HashTable<Symbol,Int> : get-sym-hash(m,list()) @@ -45,8 +50,7 @@ public defn get-sym-hash (m:InModule,keywords:Streamable<Symbol>) -> HashTable<S sym-hash[k] = 0 defn add-name (s:Symbol) -> False : val s* = to-string(s) - val i* = for i in 0 to length(s*) - 1 find : - s*[i] == '_' and digits?(substring(s*,i + 1)) + val i* = generated?(s*) match(i*) : (i:False) : if key?(sym-hash,s) : |
