diff options
| author | Andrew Waterman | 2015-10-01 15:15:09 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-10-01 15:15:09 -0700 |
| commit | 42307c1f72c8799f8db52a6859c4b7b1ed114c3d (patch) | |
| tree | ffb6f0bc6f07b827b7f34814de232231bc82f968 /src | |
| parent | 8cbb0286f7b007fe54bf55452a25121357537dcb (diff) | |
| parent | 4726d8b6ca56435d861cb74f52f1237e3b43ae38 (diff) | |
Merge pull request #41 from ucb-bar/fix-init-accessor
Fix init accessor
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/stanza/compilers.stanza | 10 | ||||
| -rw-r--r-- | src/main/stanza/custom-compiler.stanza | 2 | ||||
| -rw-r--r-- | src/main/stanza/ir-utils.stanza | 14 | ||||
| -rw-r--r-- | src/main/stanza/passes.stanza | 377 | ||||
| -rw-r--r-- | src/main/stanza/verilog.stanza | 4 |
5 files changed, 244 insertions, 163 deletions
diff --git a/src/main/stanza/compilers.stanza b/src/main/stanza/compilers.stanza index 1e978a2e..0ea9a367 100644 --- a/src/main/stanza/compilers.stanza +++ b/src/main/stanza/compilers.stanza @@ -25,7 +25,7 @@ public defmethod passes (c:StandardFlo) -> List<Pass> : CheckGenders() ExpandAccessors() LowerToGround() - ExpandIndexedConnects() + InlineIndexed() ExpandWhens() InferWidths() Pad() @@ -44,7 +44,7 @@ public defstruct StandardVerilog <: Compiler : public defmethod passes (c:StandardVerilog) -> List<Pass> : to-list $ [ RemoveSpecialChars() ;R - RemoveScopes() ;R + ;RemoveScopes() ;R CheckHighForm() ;R TempElimination() ;R ToWorkingIR() ;R -> W @@ -56,15 +56,17 @@ public defmethod passes (c:StandardVerilog) -> List<Pass> : CheckTypes() ;R ExpandAccessors() ;W LowerToGround() ;W - ExpandIndexedConnects() ;W + ;ExpandIndexedConnects() ;W + InlineIndexed() InferTypes() ;R CheckGenders() ;W ExpandWhens() ;W InferWidths() ;R + ToRealIR() ;W -> R + CheckWidths() ;R Pad() ;R ConstProp() ;R SplitExp() ;R - ToRealIR() ;W -> R CheckWidths() ;R CheckHighForm() ;R CheckLowForm() ;R diff --git a/src/main/stanza/custom-compiler.stanza b/src/main/stanza/custom-compiler.stanza index 36a6474f..0f43da58 100644 --- a/src/main/stanza/custom-compiler.stanza +++ b/src/main/stanza/custom-compiler.stanza @@ -28,7 +28,7 @@ public defmethod passes (c:InstrumentedVerilog) -> List<Pass> : CheckGenders() ExpandAccessors() LowerToGround() - ExpandIndexedConnects() + InlineIndexed() InferTypes() CheckGenders() ExpandWhens() 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) : diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza index 99fb8172..6d79e9c2 100644 --- a/src/main/stanza/passes.stanza +++ b/src/main/stanza/passes.stanza @@ -21,7 +21,8 @@ public val standard-passes = to-list $ [ CheckGenders() ExpandAccessors() LowerToGround() - ExpandIndexedConnects() + ;ExpandIndexedConnects() + InlineIndexed() ExpandWhens() InferWidths() Inline() @@ -67,17 +68,19 @@ public defstruct WIndex <: Expression : type: Type with: (as-method => true) gender: Gender with: (as-method => true) -defstruct ConnectToIndexed <: Stmt : +defstruct DecFromIndexer <: Stmt : info: FileInfo with: (as-method => true) index: Expression - locs: List<Expression> - exp: Expression + exps: List<Expression> + name: Symbol + type: Type -defstruct ConnectFromIndexed <: Stmt : +defstruct DecToIndexer <: Stmt : info: FileInfo with: (as-method => true) index: Expression - loc: Expression exps: List<Expression> + name: Symbol + type: Type ;================ WORKING IR UTILS ========================= @@ -259,12 +262,12 @@ defmethod print (o:OutputStream, e:WIndex) : print-all(o,[exp(e) "[" value(e) "]"]) print-debug(o,e as ?) -defmethod print (o:OutputStream, c:ConnectToIndexed) : - print-all(o, [locs(c) "[" index(c) "] := " exp(c)]) +defmethod print (o:OutputStream, c:DecFromIndexer) : + print-all(o, ["indexer " exps(c) "[" index(c) "] = " name(c) " : " type(c)]) print-debug(o,c as ?) -defmethod print (o:OutputStream, c:ConnectFromIndexed) : - print-all(o, [loc(c) " := " exps(c) "[" index(c) "]" ]) +defmethod print (o:OutputStream, c:DecToIndexer) : + print-all(o, ["indexer " name(c) " = " exps(c) "[" index(c) "] : " type(c)]) print-debug(o,c as ?) defmethod map (f: Expression -> Expression, e: WSubfield) : @@ -272,10 +275,10 @@ defmethod map (f: Expression -> Expression, e: WSubfield) : defmethod map (f: Expression -> Expression, e: WIndex) : WIndex(f(exp(e)), value(e), type(e), gender(e)) -defmethod map (f: Expression -> Expression, c:ConnectToIndexed) : - ConnectToIndexed(info(c),f(index(c)), map(f, locs(c)), f(exp(c))) -defmethod map (f: Expression -> Expression, c:ConnectFromIndexed) : - ConnectFromIndexed(info(c),f(index(c)), f(loc(c)), map(f, exps(c))) +defmethod map (f: Expression -> Expression, c:DecFromIndexer) : + DecFromIndexer(info(c),f(index(c)), map(f, exps(c)), name(c), type(c)) +defmethod map (f: Expression -> Expression, c:DecToIndexer) : + DecToIndexer(info(c),f(index(c)), map(f, exps(c)), name(c), type(c)) defmethod map (f: Type -> Type, e: WRef) : WRef(name(e), f(type(e)), kind(e), gender(e)) @@ -297,7 +300,7 @@ public defmethod short-name (b:RemoveSpecialChars) -> String : "rem-spec-chars" defn get-new-string (n:Char) -> String : switch {n == _} : - '_' : "_" + '_' : "__" '~' : "$A" '!' : "$B" '@' : "$C" @@ -850,12 +853,12 @@ defn resolve-genders (c:Circuit) : resolve-genders(m,c) ;;============== EXPAND ACCESSORS ================================ -; This pass expands non-memory accessors into ConnectToIndexed or +; This pass expands non-memory accessors into DecFromIndexer or ; ConnectFromIndexed. All elements of the vector are ; explicitly written out, then indexed. Depending on the gender -; of the accessor, it is transformed into ConnectToIndexed (male) or -; ConnectFromIndexed (female) -; Eg: +; of the accessor, it is transformed into DecFromIndexer (male) or +; DecToIndexer (female) + public defstruct ExpandAccessors <: Pass public defmethod pass (b:ExpandAccessors) -> (Circuit -> Circuit) : expand-accessors public defmethod name (b:ExpandAccessors) -> String : "Expand Accessors" @@ -876,18 +879,11 @@ defn expand-stmt (s:Stmt) -> Stmt : if mem? : s else : val vtype = type(type(source(s)) as VectorType) - val wire = DefWire(info(s),name(s),vtype) switch {acc-dir(s) == _} : - READ : Begin{list(wire,_)} $ ConnectFromIndexed( - info(s), - index(s), - WRef(name(wire),vtype,NodeKind(),FEMALE), - expand-vector(source(s))) - WRITE : Begin{list(wire,_)} $ ConnectToIndexed( - info(s), - index(s), - expand-vector(source(s)), - WRef(name(wire),vtype,NodeKind(),MALE)) + READ : DecToIndexer(info(s),index(s),expand-vector(source(s)), + name(s), vtype) + WRITE : DecFromIndexer(info(s),index(s),expand-vector(source(s)), + name(s), vtype) INFER : error("Shouldn't be here") RDWR : error("Haven't implemented RDWR yet") (s) : map(expand-stmt,s) @@ -897,8 +893,9 @@ defn expand-accessors (c:Circuit) : val modules* = for m in modules(c) map : match(m) : - (m:InModule) : InModule(info(m),name(m),ports(m),expand-stmt(body(m))) (m:ExModule) : m + (m:InModule) : + InModule(info(m),name(m),ports(m),expand-stmt(body(m))) ;;=============== LOWERING TO GROUND TYPES ============================= ; All non-ground (elevated) types (Vectors, Bundles) are expanded out to @@ -1091,46 +1088,31 @@ defn lower (body:Stmt) -> Stmt : switch fn ([x,y]) : lgender == x and rgender == y : [FEMALE,MALE] : Connect(info(s),l*,r*) [MALE,FEMALE] : Connect(info(s),r*,l*) - (s:ConnectFromIndexed) : Begin(ls) where : + (s:DecToIndexer|DecFromIndexer) : Begin(ls) where : val ctable = HashTable<Symbol,Vector<EF>>(symbol-hash) val index* = exp(head $ expand-expr(index(s))) for e in exps(s) do : - for (r in expand-expr(e),l in expand-expr(loc(s))) do : - val n = name(exp(l) as WRef) + for (r in expand-expr(e), ntf in generate-entry(name(s),type(s))) do: + val n = name(ntf) val x = get?(ctable,n,Vector<EF>()) add(x,r) ctable[n] = x - val ls = for l in expand-expr(loc(s)) map : - val n = name(exp(l) as WRef) - val lgender = FEMALE * flip(l) + val default-gender = match(s) : + (s:DecToIndexer) : FEMALE + (s:DecFromIndexer) : MALE + val ls = for ntf in generate-entry(name(s),type(s)) map : + val n = name(ntf) + val dec-gender = default-gender * flip(ntf) for x in ctable[n] do : - if (flip(x) * MALE) == lgender : error("Shouldn't be here") - val rgender = lgender * REVERSE - val l* = set-gender(exp(l),lgender,flip(l)) - val exps = to-list $ for e in ctable[n] map : set-gender(exp(e),rgender,flip(e)) - switch fn ([x,y]) : lgender == x and rgender == y : - [FEMALE,MALE] : ConnectFromIndexed(info(s),index*,l*,exps) - [MALE,FEMALE] : ConnectToIndexed(info(s),index*,exps,l*) - (s:ConnectToIndexed) : Begin(ls) where : - val ctable = HashTable<Symbol,Vector<EF>>(symbol-hash) - val index* = exp(head $ expand-expr(index(s))) - for e in locs(s) do : - for (l in expand-expr(e),r in expand-expr(exp(s))) do : - val n = name(exp(r) as WRef) - val x = get?(ctable,n,Vector<EF>()) - add(x,l) - ctable[n] = x - val ls = for r in expand-expr(exp(s)) map : - val n = name(exp(r) as WRef) - val rgender = MALE * flip(r) - for x in ctable[n] do : - if (flip(x) * FEMALE) == rgender : error("Shouldn't be here") - val lgender = rgender * REVERSE - val r* = set-gender(exp(r),rgender,flip(r)) - val locs = to-list $ for e in ctable[n] map : set-gender(exp(e),lgender,flip(e)) - switch fn ([x,y]) : lgender == x and rgender == y : - [FEMALE,MALE] : ConnectToIndexed(info(s),index*,locs,r*) - [MALE,FEMALE] : ConnectFromIndexed(info(s),index*,r*,locs) + if (flip(x) * swap(default-gender)) == dec-gender : + error("Shouldn't be here") + val exps-gender = swap(dec-gender) + ;val l* = set-gender(exp(l),lgender,flip(ntf)) + val exps = to-list $ for e in ctable[n] map : + set-gender(exp(e),exps-gender,flip(e)) + switch fn ([x,y]) : dec-gender == x and exps-gender == y : + [FEMALE,MALE] : DecToIndexer(info(s),index*,exps,name(ntf),type(ntf)) + [MALE,FEMALE] : DecFromIndexer(info(s),index*,exps,name(ntf),type(ntf)) (s:Conditionally) : Conditionally(info(s),exp(head $ expand-expr(pred(s))),lower-stmt(conseq(s)),lower-stmt(alt(s))) (s:Begin|EmptyStmt) : map(lower-stmt,s) @@ -1154,66 +1136,155 @@ defn lower-to-ground (c:Circuit) -> Circuit : ;;=========== CONVERT MULTI CONNECTS to WHEN ================ -; This pass converts ConnectToIndexed and ConnectFromIndexed +; This pass converts DecFromIndexer and DecToIndexer ; into a series of when statements. TODO what about initial ; values? -public defstruct ExpandIndexedConnects <: Pass -public defmethod pass (b:ExpandIndexedConnects) -> (Circuit -> Circuit) : expand-connect-indexed -public defmethod name (b:ExpandIndexedConnects) -> String : "Expand Indexed Connects" -public defmethod short-name (b:ExpandIndexedConnects) -> String : "expand-indexed-connects" - -defn expand-connect-indexed-stmt (s: Stmt,sh:HashTable<Symbol,Int>) -> Stmt : - defn equality (e1:Expression,e2:Expression) -> Expression : - DoPrim(EQUIV-OP,list(e1,e2),List(),UIntType(UnknownWidth())) - defn get-name (e:Expression) -> Symbol : - match(e) : - (e:WRef) : name(e) - (e:WSubfield) : symbol-join([get-name(exp(e)) `. name(e)]) - (e:WIndex) : symbol-join([get-name(exp(e)) `. to-symbol(value(e))]) - (e) : `T - match(s) : - (s:ConnectToIndexed) : Begin $ - if length(locs(s)) == 0 : list(EmptyStmt()) - else : - 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 $ - for (i in 0 to false, l in locs(s)) stream : Conditionally( - info(s), - equality(ref,UIntValue(BigIntLit(i),UnknownWidth())), - Connect(info(s),l,exp(s)), - EmptyStmt() - ) - ) - (s:ConnectFromIndexed) : Begin $ - if length(exps(s)) == 0 : list(EmptyStmt()) - else : - 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 $ - for (i in 1 to false, e in tail(exps(s))) stream : Conditionally( - info(s), - equality(ref,UIntValue(BigIntLit(i),UnknownWidth())), - Connect(info(s),loc(s),e), - EmptyStmt() - ) - ) - (s) : map(expand-connect-indexed-stmt{_,sh},s) - -defn expand-connect-indexed (m: Module) -> Module : - match(m) : - (m:InModule) : - val sh = get-sym-hash(m,keys(v-keywords)) - InModule(info(m),name(m),ports(m),expand-connect-indexed-stmt(body(m),sh)) - (m:ExModule) : m +;public defstruct ExpandIndexedConnects <: Pass +;public defmethod pass (b:ExpandIndexedConnects) -> (Circuit -> Circuit) : expand-connect-indexed +;public defmethod name (b:ExpandIndexedConnects) -> String : "Expand Indexed Connects" +;public defmethod short-name (b:ExpandIndexedConnects) -> String : "expand-indexed-connects" +; +;defn expand-connect-indexed-stmt (s: Stmt,sh:HashTable<Symbol,Int>) -> Stmt : +; defn equality (e1:Expression,e2:Expression) -> Expression : +; DoPrim(EQUIV-OP,list(e1,e2),List(),UIntType(UnknownWidth())) +; defn get-name (e:Expression) -> Symbol : +; match(e) : +; (e:WRef) : name(e) +; (e:WSubfield) : symbol-join([get-name(exp(e)) `. name(e)]) +; (e:WIndex) : symbol-join([get-name(exp(e)) `. to-symbol(value(e))]) +; (e) : `F +; match(s) : +; (s:DecFromIndexer) : Begin $ +; if length(locs(s)) == 0 : list(EmptyStmt()) +; else : +; 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 $ +; for (i in 0 to false, l in locs(s)) stream : Conditionally( +; info(s), +; equality(ref,UIntValue(BigIntLit(i),UnknownWidth())), +; Connect(info(s),l,exp(s)), +; EmptyStmt() +; ) +; ) +; (s:DecToIndexer) : Begin $ +; if length(exps(s)) == 0 : list(EmptyStmt()) +; else : +; 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 $ +; for (i in 1 to false, e in tail(exps(s))) stream : Conditionally( +; info(s), +; equality(ref,UIntValue(BigIntLit(i),UnknownWidth())), +; Connect(info(s),loc(s),e), +; EmptyStmt() +; ) +; ) +; (s) : map(expand-connect-indexed-stmt{_,sh},s) +; +;defn expand-connect-indexed (m: Module) -> Module : +; match(m) : +; (m:InModule) : +; val sh = get-sym-hash(m,keys(v-keywords)) +; InModule(info(m),name(m),ports(m),expand-connect-indexed-stmt(body(m),sh)) +; (m:ExModule) : m +; +;defn expand-connect-indexed (c: Circuit) -> Circuit : +; Circuit(info(c),modules*, main(c)) where : +; val modules* = +; for m in modules(c) map : +; expand-connect-indexed(m) + +;;================ INLINE ACCESSORS ========================= +; This pass inlines all accessors to non-memory vector typed +; components. + +public defstruct InlineIndexed <: Pass +public defmethod pass (b:InlineIndexed) -> (Circuit -> Circuit) : inline-indexed +public defmethod name (b:InlineIndexed) -> String : "Inline Indexers" +public defmethod short-name (b:InlineIndexed) -> String : "inline-indexers" -defn expand-connect-indexed (c: Circuit) -> Circuit : - Circuit(info(c),modules*, main(c)) where : - val modules* = - for m in modules(c) map : - expand-connect-indexed(m) +;------------ Helper Functions -------------- +defn get-name (e:Expression) -> Symbol : + match(e) : + (e:WRef) : name(e) + (e:WSubfield) : symbol-join([get-name(exp(e)) `. name(e)]) + (e:WIndex) : symbol-join([get-name(exp(e)) `. to-symbol(value(e))]) + (e) : `F + +defn equality (e1:Expression,i:Int) -> Expression : + DoPrim(EQUIV-OP,list(e1,UIntValue(BigIntLit(i),UnknownWidth())), + List(),UIntType(UnknownWidth())) + + +;------------- Inline Accessors ------------- + + + +defn inline-indexed-m (m:InModule) -> InModule : + val sh = get-sym-hash(m,keys(v-keywords)) + val ih = HashTable<Symbol,Stmt>(symbol-hash) + defn inline-indexed-s (s:Stmt) -> Stmt : + val stmts = Vector<Stmt>() + + defn expand-indexed (indexer:WRef,indexed-dec:Stmt) -> Expression : + val index = index(indexed-dec as DecFromIndexer|DecToIndexer) + val index-name = firrtl-gensym(get-name(index),sh) + val index-ref = WRef(index-name,type(index),NodeKind(),MALE) + + val replace-name = firrtl-gensym(get-name(indexer),sh) + val replace-ref = WRef(replace-name,type(indexer),kind(indexer),gender(indexer)) + + add(stmts, DefWire(info(indexed-dec),name(replace-ref),type(replace-ref))) + add(stmts, DefNode(info(indexed-dec),index-name,index)) + match(indexed-dec) : + (s:DecFromIndexer) : + if (gender(replace-ref) != FEMALE) : error("Shouldn't be here") + for (i in 0 to false, e in exps(s)) do : + val eq = equality(index-ref,i) + val cond = Conditionally(info(s),eq,Connect(info(s),e,replace-ref),EmptyStmt()) + add(stmts,map(inline-indexed-s,cond)) + (s:DecToIndexer) : + if (gender(replace-ref) != MALE) : error("Shouldn't be here") + val cnct = Connect(info(s),replace-ref,head(exps(s))) + add(stmts,map(inline-indexed-e,cnct)) + ;println-all(["exps: " exps(s)]) + for (i in 1 to false, e in tail(exps(s))) do : + val eq = equality(index-ref,i) + val cond = Conditionally(info(s),eq,Connect(info(s),replace-ref,e),EmptyStmt()) + add(stmts,map(inline-indexed-s,cond)) + replace-ref + + defn inline-indexed-e (e:Expression) -> Expression : + match(map(inline-indexed-e,e)) : + (e:WRef) : + if key?(ih,name(e)) : + val indexer = ih[name(e)] + expand-indexed(e,indexer) + else : e + (e) : e + + match(s) : + (s:DecFromIndexer|DecToIndexer) : + ih[name(s)] = s + firrtl-gensym(name(s),sh) + add(stmts,EmptyStmt()) + (s) : + val s* = map(inline-indexed-e,s) + add(stmts,map(inline-indexed-s,s*)) + if length(stmts) == 1 : stmts[0] + else : Begin(to-list(stmts)) + + InModule(info(m),name(m),ports(m),inline-indexed-s(body(m))) + +public defn inline-indexed (c:Circuit) -> Circuit : + Circuit{info(c),_,main(c)} $ + for m in modules(c) map : + match(m) : + (m:ExModule) : m + (m:InModule) : inline-indexed-m(m) ;;================ EXPAND WHENS ============================= ; This pass does three things: remove last connect semantics, @@ -2171,6 +2242,33 @@ defn inline-instances (c:Circuit) : val top = (for m in modules(c) find : name(m) == main(c)) as InModule Circuit(info(c),list(InModule(info(top),name(top),ports(top),inline-inst(body(top)))),main(c)) +;================= Bring to Real IR ======================== +; Returns a new Circuit with only real IR nodes. +public defstruct ToRealIR <: Pass +public defmethod pass (b:ToRealIR) -> (Circuit -> Circuit) : to-real-ir +public defmethod name (b:ToRealIR) -> String : "Real IR" +public defmethod short-name (b:ToRealIR) -> String : "real-ir" + +defn to-real-ir (c:Circuit) : + defn to-exp (e:Expression) : + match(map(to-exp,e)) : + (e:WRef) : Ref(name(e), type(e)) + (e:WSubfield) : Subfield(exp(e),name(e),type(e)) + (e:WIndex) : error("Shouldn't be here") + (e) : e + defn to-stmt (s:Stmt) : + match(map(to-exp,s)) : + (e:DecFromIndexer) : error("Shouldn't be here") + (e:DecToIndexer) : error("Shouldn't be here") + (e) : map(to-stmt,e) + + Circuit(info(c),modules*, main(c)) where : + val modules* = + for m in modules(c) map : + match(m) : + (m:InModule) : InModule(info(m),name(m), ports(m), to-stmt(body(m))) + (m:ExModule) : m + ;================= Split Expressions ======================== ; Intended to only work on low firrtl @@ -2181,7 +2279,7 @@ public defmethod short-name (b:SplitExp) -> String : "split-expressions" defn full-name (e:Expression) -> Symbol|False : match(e) : - (e:WRef) : name(e) + (e:Ref) : name(e) (e) : false defn split-exp (c:Circuit) : @@ -2195,13 +2293,13 @@ defn split-exp (c:Circuit) : ;all-same-type? = false ;if not all-same-type? : ;val n* = - ; if n typeof False : firrtl-gensym(`T,sh) + ; if n typeof False : firrtl-gensym(`F,sh) ; else : firrtl-gensym(symbol-join([n as Symbol temp-delin]),sh) val n* = - if n typeof False : firrtl-gensym(`T,sh) + if n typeof False : firrtl-gensym(`F,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) + Ref(n*,type(e)) ;else : e (e) : map(split-exp-e{_,n,info},e) defn f (s:Stmt) -> False: split-exp-s(s,v,sh) @@ -2242,33 +2340,6 @@ defn split-exp (c:Circuit) : InModule(info(m),name(m),ports(m),Begin(to-list(v))) (m:ExModule) : m -;================= Bring to Real IR ======================== -; Returns a new Circuit with only real IR nodes. -public defstruct ToRealIR <: Pass -public defmethod pass (b:ToRealIR) -> (Circuit -> Circuit) : to-real-ir -public defmethod name (b:ToRealIR) -> String : "Real IR" -public defmethod short-name (b:ToRealIR) -> String : "real-ir" - -defn to-real-ir (c:Circuit) : - defn to-exp (e:Expression) : - match(map(to-exp,e)) : - (e:WRef) : Ref(name(e), type(e)) - (e:WSubfield) : Subfield(exp(e),name(e),type(e)) - (e:WIndex) : error("Shouldn't be here") - (e) : e - defn to-stmt (s:Stmt) : - match(map(to-exp,s)) : - (e:ConnectToIndexed) : error("Shouldn't be here") - (e:ConnectFromIndexed) : error("Shouldn't be here") - (e) : map(to-stmt,e) - - Circuit(info(c),modules*, main(c)) where : - val modules* = - for m in modules(c) map : - match(m) : - (m:InModule) : InModule(info(m),name(m), ports(m), to-stmt(body(m))) - (m:ExModule) : m - ;================= Special Rename ======================== ; Returns a new Circuit with only real IR nodes. public defstruct SpecialRename <: Pass : @@ -2381,7 +2452,7 @@ defn pad-widths-e (desired:Long,e:Expression) -> Expression : else : map(pad-widths-e{new-desired,_},e) trim-pad(desired, e*) - (e:WRef|WSubfield|WIndex) : + (e:Ref|Subfield|Index) : trim-pad(desired, e) (e:UIntValue) : val i = int-width!(type(e)) diff --git a/src/main/stanza/verilog.stanza b/src/main/stanza/verilog.stanza index c4a52d5e..1a495835 100644 --- a/src/main/stanza/verilog.stanza +++ b/src/main/stanza/verilog.stanza @@ -155,6 +155,10 @@ defn emit (e:Expression) -> String : for x in tail(args(e)) do : v = concat(v, [" ^ " emit(x)]) v + (e) : + println(["Expression:" e]) + error("Unknown expression") + defn emit-module (m:InModule) : |
