aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorazidar2015-08-03 18:39:55 -0700
committerazidar2015-08-03 18:39:55 -0700
commitff6dfecf42560ed2e2eb678adc9ca8d868a472bd (patch)
tree1483818b3efa226bce74cca560f1aa38102ebcfa /src/main
parentec3bf6a6a74061721024dece229f7a6062f5c7fc (diff)
Changed name mangling to use _ as a delin. Fixed bug in checking for
invalid <> assignments.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/stanza/errors.stanza31
-rw-r--r--src/main/stanza/firrtl-ir.stanza1
-rw-r--r--src/main/stanza/firrtl-test-main.stanza2
-rw-r--r--src/main/stanza/flo.stanza2
-rw-r--r--src/main/stanza/ir-utils.stanza76
-rw-r--r--src/main/stanza/passes.stanza18
6 files changed, 94 insertions, 36 deletions
diff --git a/src/main/stanza/errors.stanza b/src/main/stanza/errors.stanza
index 2fb1352c..5212bcb5 100644
--- a/src/main/stanza/errors.stanza
+++ b/src/main/stanza/errors.stanza
@@ -695,7 +695,7 @@ defn InferDirection (info:FileInfo,name:Symbol) :
defn dir-to-gender (d:PortDirection) -> Gender :
switch {_ == d} :
INPUT : MALE
- OUTPUT : BI-GENDER
+ OUTPUT : FEMALE ;BI-GENDER
defn gender (s:DefAccessor) -> Gender :
switch {_ == acc-dir(s)} :
@@ -715,14 +715,28 @@ defn as-srcsnk (g:Gender) -> Symbol :
public defn check-genders (c:Circuit) -> Circuit :
val errors = Vector<PassException>()
- defn check-gender (info:FileInfo,genders:HashTable<Symbol,Gender>,e:Expression,right:Gender) -> False :
+ defn get-kind (e:Expression) -> Kind :
+ match(e) :
+ (e:WRef) : kind(e)
+ (e:WSubfield) : get-kind(exp(e))
+ (e:WIndex) : get-kind(exp(e))
+ (e) : NodeKind()
+
+ defn check-gender (info:FileInfo,genders:HashTable<Symbol,Gender>,e:Expression,desired:Gender) -> False :
val gender = get-gender(e,genders)
+ val kind* = get-kind(e)
+ ;println(e)
;println(gender)
- ;println(right)
- ;println(right == gender)
- ;if gender != right and gender != BI-GENDER:
- switch fn ([x,y]) : gender == x and right == y :
- [MALE, FEMALE] : add(errors,WrongGender(info,to-symbol(e),as-srcsnk(right),as-srcsnk(gender)))
+ ;println(desired)
+ ;println(kind*)
+ ;println(desired == gender)
+ ;if gender != desired and gender != BI-GENDER:
+ switch fn ([x,y]) : gender == x and desired == y :
+ [MALE, FEMALE] :
+ add(errors,WrongGender(info,to-symbol(e),as-srcsnk(desired),as-srcsnk(gender)))
+ [FEMALE, MALE] :
+ if kind* != PortKind() :
+ add(errors,WrongGender(info,to-symbol(e),as-srcsnk(desired),as-srcsnk(gender)))
else : false
defn get-gender (e:Expression,genders:HashTable<Symbol,Gender>) -> Gender :
@@ -730,7 +744,7 @@ public defn check-genders (c:Circuit) -> Circuit :
(e:WRef) : genders[name(e)]
(e:WSubfield) :
val f = {_ as Field} $ for f in fields(type(exp(e)) as BundleType) find : name(f) == name(e)
- get-gender(exp(e),genders) * flip(f)
+ get-gender(exp(e),genders) * flip(f)
(e:WIndex) : get-gender(exp(e),genders)
(e:DoPrim) : MALE
(e:UIntValue) : MALE
@@ -787,6 +801,7 @@ public defn check-genders (c:Circuit) -> Circuit :
match(m) :
(m:ExModule) : false
(m:InModule) : check-genders-s(body(m),genders)
+ println(genders)
throw(PassExceptions(errors)) when not empty?(errors)
c
diff --git a/src/main/stanza/firrtl-ir.stanza b/src/main/stanza/firrtl-ir.stanza
index 79057791..e1f91254 100644
--- a/src/main/stanza/firrtl-ir.stanza
+++ b/src/main/stanza/firrtl-ir.stanza
@@ -13,6 +13,7 @@ public val scope-delin = `%
public val temp-delin = `!
public val sub-delin = `*
public val inline-delin = `^
+public val delin = `_
public definterface PortDirection
public val INPUT = new PortDirection
diff --git a/src/main/stanza/firrtl-test-main.stanza b/src/main/stanza/firrtl-test-main.stanza
index e5aad984..f22c49f1 100644
--- a/src/main/stanza/firrtl-test-main.stanza
+++ b/src/main/stanza/firrtl-test-main.stanza
@@ -79,7 +79,7 @@ defn main () :
if last-s == "-o" : output = args[i]
if last-s == "-x" : add(pass-names,args[i])
if last-s == "-X" : compiler = args[i]
- if last-s == "-p" : printvars = args[i]
+ if last-s == "-p" : printvars = to-string([printvars args[i]])
if last-s == "-s" : add(pass-args,args[i])
if last-s == "-m" : add(firms,args[i])
diff --git a/src/main/stanza/flo.stanza b/src/main/stanza/flo.stanza
index 7ef942f2..812a917e 100644
--- a/src/main/stanza/flo.stanza
+++ b/src/main/stanza/flo.stanza
@@ -198,7 +198,7 @@ defn emit-module (m:InModule,sh:HashTable<Symbol,Int>) :
public defn emit-flo (with-output:(() -> False) -> False, c:Circuit) :
with-output $ {
- emit-module(modules(c)[0] as InModule,get-sym-hash(modules(c)[0] as InModule))
+ emit-module(modules(c)[0] as InModule,get-sym-hash(modules(c)[0] as InModule,v-keywords))
false
}
c
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) :
diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza
index 4b99a4f8..e6d13196 100644
--- a/src/main/stanza/passes.stanza
+++ b/src/main/stanza/passes.stanza
@@ -295,12 +295,12 @@ public defmethod short-name (b:RemoveSpecialChars) -> String : "rem-spec-chars"
defn get-new-string (n:Char) -> String :
switch {n == _} :
- ;'_' : "__"
+ '_' : "_"
'~' : "$A"
'!' : "$B"
'@' : "$C"
'#' : "$D"
- ;'$' : "$E"
+ '$' : "$E"
'%' : "$F"
'^' : "$G"
'*' : "$H"
@@ -340,7 +340,7 @@ defn remove-special-chars (c:Circuit) :
(s:DefAccessor) : DefAccessor(info(s),rename(name(s)),source(s),index(s),acc-dir(s))
(s) : map(rename-t,map(rename-s,s))
- Circuit(info(c),modules*, main(c)) where :
+ Circuit(info(c),modules*, rename(main(c))) where :
val modules* =
for m in modules(c) map :
match(m) :
@@ -1148,7 +1148,7 @@ defn expand-connect-indexed-stmt (s: Stmt,sh:HashTable<Symbol,Int>) -> Stmt :
(s:ConnectToIndexed) : Begin $
if length(locs(s)) == 0 : list(EmptyStmt())
else :
- val ref = WRef(firrtl-gensym(get-name(index(s)),sh,sub-delin),type(index(s)),NodeKind(),UNKNOWN-GENDER)
+ val ref = WRef(firrtl-gensym(get-name(index(s)),sh),type(index(s)),NodeKind(),UNKNOWN-GENDER)
append(
list(DefNode(info(s),name(ref),index(s)))
to-list $
@@ -1162,7 +1162,7 @@ defn expand-connect-indexed-stmt (s: Stmt,sh:HashTable<Symbol,Int>) -> Stmt :
(s:ConnectFromIndexed) : Begin $
if length(exps(s)) == 0 : list(EmptyStmt())
else :
- val ref = WRef(firrtl-gensym(get-name(index(s)),sh,sub-delin),type(index(s)),NodeKind(),UNKNOWN-GENDER)
+ val ref = WRef(firrtl-gensym(get-name(index(s)),sh),type(index(s)),NodeKind(),UNKNOWN-GENDER)
append(
list(Connect(info(s),loc(s),head(exps(s))),DefNode(info(s),name(ref),index(s)))
to-list $
@@ -1178,7 +1178,7 @@ defn expand-connect-indexed-stmt (s: Stmt,sh:HashTable<Symbol,Int>) -> Stmt :
defn expand-connect-indexed (m: Module) -> Module :
match(m) :
(m:InModule) :
- val sh = get-sym-hash(m)
+ val sh = get-sym-hash(m,v-keywords)
InModule(info(m),name(m),ports(m),expand-connect-indexed-stmt(body(m),sh))
(m:ExModule) : m
@@ -2176,8 +2176,8 @@ defn split-exp (c:Circuit) :
; if n typeof False : firrtl-gensym(`T,sh)
; else : firrtl-gensym(symbol-join([n as Symbol temp-delin]),sh)
val n* =
- if n typeof False : firrtl-gensym(`T,sh,temp-delin)
- else : firrtl-gensym(n as Symbol,sh,temp-delin)
+ if n typeof False : firrtl-gensym(`T,sh)
+ else : firrtl-gensym(n as Symbol,sh)
add(v,DefNode(info,n*,map(split-exp-e{_,n,info},e)))
WRef(n*,type(e),NodeKind(),UNKNOWN-GENDER)
;else : e
@@ -2204,7 +2204,7 @@ defn split-exp (c:Circuit) :
match(m) :
(m:InModule) :
val v = Vector<Stmt>()
- val sh = get-sym-hash(m)
+ val sh = get-sym-hash(m,v-keywords)
;val before = current-time-us() - start-time
;println-all(["Before split: " before])
split-exp-s(body(m),v,sh)