aboutsummaryrefslogtreecommitdiff
path: root/src/main/stanza/ir-utils.stanza
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/stanza/ir-utils.stanza')
-rw-r--r--src/main/stanza/ir-utils.stanza76
1 files changed, 59 insertions, 17 deletions
diff --git a/src/main/stanza/ir-utils.stanza b/src/main/stanza/ir-utils.stanza
index f3fb5a53..2fb92407 100644
--- a/src/main/stanza/ir-utils.stanza
+++ b/src/main/stanza/ir-utils.stanza
@@ -9,32 +9,74 @@ public defmulti print-debug (o:OutputStream, e:Expression|Stmt|Type|Port|Field|M
;============== GENSYM STUFF ======================
+public val v-keywords = to-list $ [
+ `always, `and, `assign, `attribute, `begin, `buf, `bufif0, `bufif1,
+ `case, `casex, `casez, `cmos, `deassign, `default, `defparam,
+ `disable, `edge, `else, `end, `endattribute, `endcase, `endfunction,
+ `endmodule, `endprimitive, `endspecify, `endtable, `endtask, `event,
+ `for, `force, `forever, `fork, `function, `highz0, `highz1, `if,
+ `ifnone, `initial, `inout, `input, `integer, `initvar, `join,
+ `medium, `module, `large, `macromodule, `nand, `negedge, `nmos,
+ `nor, `not, `notif0, `notif1, `or, `output, `parameter, `pmos,
+ `posedge, `primitive, `pull0, `pull1, `pulldown, `pullup, `rcmos,
+ `real, `realtime, `reg, `release, `repeat, `rnmos, `rpmos, `rtran,
+ `rtranif0, `rtranif1, `scalared, `signed, `small, `specify,
+ `specparam, `strength, `strong0, `strong1, `supply0, `supply1,
+ `table, `task, `time, `tran, `tranif0, `tranif1, `tri, `tri0,
+ `tri1, `triand, `trior, `trireg, `unsigned, `vectored, `wait,
+ `wand, `weak0, `weak1, `while, `wire, `wor, `xnor, `xor,
+ `SYNTHESIS, `PRINTF_COND, `VCS ]
public defn firrtl-gensym (s:Symbol) -> Symbol :
firrtl-gensym(s,HashTable<Symbol,Int>(symbol-hash))
-public defn firrtl-gensym (s:Symbol,sym-hash:HashTable<Symbol,Int>) -> Symbol :
- firrtl-gensym(s,sym-hash,temp-delin)
public defn firrtl-gensym (sym-hash:HashTable<Symbol,Int>) -> Symbol :
firrtl-gensym(`gen,sym-hash)
-public defn firrtl-gensym (s:Symbol,sym-hash:HashTable<Symbol,Int>,delin:Symbol) -> Symbol :
- val num = get?(sym-hash,s,0)
- sym-hash[s] = num + 1
- symbol-join([s delin num])
- ;defn get-new (s:Symbol, i:Int) -> Symbol :
- ; val s* = symbol-join([s i])
- ; if key?(sym-hash,s*) :
- ; get-new(s,i + 1)
- ; else :
- ; sym-hash[s] = i
- ; sym-hash[s*] = 0
- ; s*
- ;get-new(s,0)
-
+defn digits? (s:String) -> True|False :
+ val digits = "0123456789"
+ var yes = true
+ for c in s do :
+ if not contains?(digits,c) : yes = false
+ yes
+
+public defn firrtl-gensym (s:Symbol,sym-hash:HashTable<Symbol,Int>) -> Symbol :
+ defn get-name (s:Symbol) -> Symbol :
+ if key?(sym-hash,s) :
+ val num = sym-hash[s] + 1
+ sym-hash[s] = num
+ symbol-join([s delin num])
+ else :
+ 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*) :
+ (i:False) : get-name(s)
+ (i:Int) : get-name(to-symbol(substring(s*,0,i)))
+
public defn get-sym-hash (m:InModule) -> HashTable<Symbol,Int> :
+ get-sym-hash(m,list())
+public defn get-sym-hash (m:InModule,keywords:List<Symbol>) -> HashTable<Symbol,Int> :
val sym-hash = HashTable<Symbol,Int>(symbol-hash)
+ for k in keywords do :
+ sym-hash[k] = 0
defn add-name (s:Symbol) -> False :
- sym-hash[s] = 0
+ 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*) :
+ (i:False) :
+ sym-hash[s] = 0
+ (i:Int) :
+ val name = to-symbol(substring(s*,0,i))
+ val digit = to-int(substring(s*,i + 1))
+ if key?(sym-hash,name) :
+ val num = sym-hash[name]
+ sym-hash[name] = max(num,digit)
+ else :
+ sym-hash[name] = digit
+
defn to-port (p:Port) -> False : add-name(name(p))
defn to-stmt (s:Stmt) -> Stmt :
match(s) :