aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjackbackrack2015-04-29 20:57:25 -0700
committerjackbackrack2015-04-29 20:57:25 -0700
commit15fb94d4d96c075fc2419ed7f6a8bdd86fb36dbf (patch)
treedbf7309f8ddb36c932c20206447044e0d29acb8e /src
parent492fd458acf504c1db46b5ef75bd08dca42b3367 (diff)
parent0608bfbe363780132c0baf1e7098013ab4352f34 (diff)
merge
Diffstat (limited to 'src')
-rw-r--r--src/main/stanza/passes.stanza70
1 files changed, 45 insertions, 25 deletions
diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza
index 906f2d69..e26c82be 100644
--- a/src/main/stanza/passes.stanza
+++ b/src/main/stanza/passes.stanza
@@ -141,6 +141,18 @@ defmethod print (o:OutputStream, g:Gender) :
defmethod type (exp:UIntValue) -> Type : UIntType(width(exp))
defmethod type (exp:SIntValue) -> Type : SIntType(width(exp))
+;============== GENSYM STUFF ======================
+
+val sym-hash = HashTable<Symbol,Int>(symbol-hash)
+defn firrtl-gensym (s:Symbol) -> Symbol :
+ val cur = get?(sym-hash,s,0)
+ val nxt = cur + 1
+ sym-hash[s] = nxt
+ symbol-join([s cur])
+
+defn firrtl-gensym () -> Symbol :
+ firrtl-gensym(`gen)
+
;============== DEBUG STUFF =============================
public var PRINT-TYPES : True|False = false
public var PRINT-KINDS : True|False = false
@@ -251,7 +263,7 @@ defmethod map (f: Type -> Type, e: WSubfield) :
defmethod map (f: Type -> Type, e: WIndex) :
WIndex(exp(e), value(e), f(type(e)), gender(e))
-;================= Temparary Variable Elimination ========================
+;================= Temporary Variable Elimination ========================
; Returns a new Circuit where temporary variables are removed and returns
; the resulting nested expression
@@ -712,12 +724,17 @@ defn expand-expr (e:Expression) -> List<EF> :
for x in generate-entry(name(f),type(f)) map :
EF(WSubfield(i,name(x),type(x),gender(e)),flip(x))
else :
- val b = exp(e)
- val exps = for x in generate-entry(name(b as WRef),type(b)) map :
- EF(WRef(name(x),type(x),NodeKind(),gender(e)),DEFAULT)
- val begin = index-of-elem(type(b) as BundleType,name(e))
+ val exps = expand-expr(exp(e))
+ val begin = index-of-elem(type(exp(e)) as BundleType,name(e))
val len = num-elems(type(e))
- headn(tailn(exps,begin),len)
+ val ret = headn(tailn(exps,begin),len)
+ for r in ret map : EF(exp(r),DEFAULT)
+ ;val b = exp(e)
+ ;val exps = for x in generate-entry(name(b as WRef),type(b)) map :
+ ;EF(WRef(name(x),type(x),NodeKind(),gender(e)),DEFAULT)
+ ;val begin = index-of-elem(type(b) as BundleType,name(e))
+ ;val len = num-elems(type(e))
+ ;headn(tailn(exps,begin),len)
(e:WIndex) :
val exps = expand-expr(exp(e))
val len = num-elems(type(e))
@@ -740,6 +757,11 @@ defn size (s:DefMemory) -> Int : size(type(s))
defn size (s:WDefAccessor) -> Int : size(type(source(s)) as VectorType)
defn kind (e:WSubfield) -> Kind : kind(exp(e) as WRef|WSubfield|WIndex)
defn kind (e:WIndex) -> Kind : kind(exp(e) as WRef|WSubfield|WIndex)
+defn base-name (e:Expression) -> Symbol :
+ match(e) :
+ (e:WRef) : name(e)
+ (e:WSubfield) : base-name(exp(e))
+ (e:WIndex) : base-name(exp(e))
defn set-gender (e:Expression,g:Gender,f:Flip) -> Expression :
match(e) :
@@ -749,18 +771,6 @@ defn set-gender (e:Expression,g:Gender,f:Flip) -> Expression :
defn lower (body:Stmt) -> Stmt :
defn lower-stmt (s:Stmt) -> Stmt :
- defn calc-gender (g:Gender, e:Expression) -> Gender :
- match(e) :
- (e:WRef) : gender(e)
- (e:WSubfield) :
- println-all-debug(["Calc gender. " g " with " e])
- println-all-debug(["Exp: " exp(e)])
- val flip = bundle-field-flip(name(e),type(exp(e)))
- println-all-debug(["Flip: " flip])
- calc-gender(flip * g,exp(e))
- (e:WIndex) : gender(e)
- (e) : g
-
;; println(s)
match(s) :
(s:DefWire) : Begin $
@@ -1510,7 +1520,12 @@ defn gen-constraints (m:Module, h:HashTable<Symbol,Type>, v:Vector<WGeq>) -> Mod
(s:DefWire) : DefWire(name(s),h[name(s)])
(s:DefInstance) : DefInstance(name(s),gen-constraints(module(s)))
(s:DefMemory) : DefMemory(name(s),h[name(s)] as VectorType)
- (s:DefNode) : DefNode(name(s),gen-constraints(value(s)))
+ (s:DefNode) :
+ val l = h[name(s)]
+ val r = gen-constraints(value(s))
+ add(v,WGeq(width!(l),width!(type(r))))
+ add(v,WGeq(width!(type(r)),width!(l)))
+ DefNode(name(s),r)
(s:Connect) :
val l = gen-constraints(loc(s))
val e = gen-constraints(exp(s))
@@ -1540,14 +1555,14 @@ defn gen-constraints (m:Module, h:HashTable<Symbol,Type>, v:Vector<WGeq>) -> Mod
(e:UIntValue) :
match(width(e)) :
(w:UnknownWidth) :
- val w* = VarWidth(gensym(`w))
+ val w* = VarWidth(firrtl-gensym(`w))
add(v,WGeq(w*,IntWidth(ceil-log2(value(e)))))
UIntValue(value(e),w*)
(w) : e
(e:SIntValue) :
match(width(e)) :
(w:UnknownWidth) :
- val w* = VarWidth(gensym(`w))
+ val w* = VarWidth(firrtl-gensym(`w))
add(v,WGeq(w*,IntWidth(1 + ceil-log2(abs(value(e))))))
SIntValue(value(e),w*)
(w) : e
@@ -1592,7 +1607,7 @@ defn replace-var-widths (c:Circuit,h:HashTable<Symbol,Int>) -> Circuit :
defn remove-unknowns-w (w:Width) -> Width :
match(w) :
- (w:UnknownWidth) : VarWidth(gensym(`w))
+ (w:UnknownWidth) : VarWidth(firrtl-gensym(`w))
(w) : w
defn remove-unknowns (t:Type) -> Type : mapr(remove-unknowns-w,t)
@@ -1702,8 +1717,9 @@ defn split-exp (c:Circuit) :
match(map(split-exp-e{_,v,n},e)):
(e:Subfield|DoPrim|Pad|ReadPort|Register|WritePort) :
val n* =
- if n typeof False : gensym(`T)
- else : to-symbol $ string-join $ [n as Symbol gensym(`#)]
+ if n typeof False : firrtl-gensym(`T)
+ else : firrtl-gensym(symbol-join([n as Symbol `#]))
+ ;to-symbol $ string-join $ [n as Symbol firrtl-gensym(`#)]
add(v,DefNode(n*,e))
WRef(n*,type(e),NodeKind(),UNKNOWN-GENDER)
(e) : e
@@ -1919,8 +1935,13 @@ defn emit-s (s:Stmt, v:List<Symbol>, top:Symbol) :
(s:DefNode) :
if value(s) typeof WritePort :
val e = value(s) as WritePort
+<<<<<<< HEAD
val n = gensym(`F)
emit-all([top "::" n " = wr'" prim-width(type(e)) " " enable(e) " " mem(e) " " index(e) " " top "::" name(s) "\n"], top)
+=======
+ val n = firrtl-gensym(`F)
+ emit-all([top "::" n " = wr'" prim-width(type(e)) " " enable(e) " " mem(e) " " index(e) " " name(s) "\n"], top)
+>>>>>>> upstream/master
else :
emit-all([top "::" name(s) " = " maybe-mov(value(s)) value(s) "\n"], top)
(s:Begin) : do(emit-s{_, v, top}, body(s))
@@ -1977,5 +1998,4 @@ public defn run-passes (c: Circuit, p: List<Char>,file:String) :
if contains(p,'X') or contains(p,'n') : do-stage("Split Expressions", split-exp)
if contains(p,'X') or contains(p,'o') : do-stage("Real IR", to-real-ir)
if contains(p,'X') or contains(p,'F') : do-stage("To Flo", emit-flo{file,_})
-
println("Done!")