diff options
| author | azidar | 2015-07-30 11:50:54 -0700 |
|---|---|---|
| committer | azidar | 2015-07-30 11:50:54 -0700 |
| commit | 9b2f96b8d0b6c7f4e6fefde918d7a335ccd7b7f3 (patch) | |
| tree | 089578809d3ebe63ac5983ddda7fff7a6c00430a /src | |
| parent | d075e52e86648d345e89ae4a4c75fd3a98cc2788 (diff) | |
Updated lots of tests so they pass. Found one bug in expand whens
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/stanza/bigint.stanza | 62 | ||||
| -rw-r--r-- | src/main/stanza/flo.stanza | 5 | ||||
| -rw-r--r-- | src/main/stanza/ir-parser.stanza | 13 | ||||
| -rw-r--r-- | src/main/stanza/ir-utils.stanza | 10 | ||||
| -rw-r--r-- | src/main/stanza/passes.stanza | 14 |
5 files changed, 61 insertions, 43 deletions
diff --git a/src/main/stanza/bigint.stanza b/src/main/stanza/bigint.stanza index 427ad7ff..c2a3437a 100644 --- a/src/main/stanza/bigint.stanza +++ b/src/main/stanza/bigint.stanza @@ -362,34 +362,34 @@ defn check (msg:String, x:BigInt, e:BigInt) : defn check (msg:String, x:BigInt) : println-all([msg " " x]) -;; check("Ba ", BigIntLit({ _ }, 1)) -;; check("Bb ", BigIntLit({ _ }, 16)) -;; check("Bc ", BigIntLit({ _ }, 32)) -;; check("Bd ", BigIntLit({ _ }, 48)) -;; check("Be ", BigIntLit({ _ }, 64)) -;; check("Bf ", BigIntLit({ _ }, 65)) -;; check("B1 ", BigIntLit(1, 8)) -;; check("B2 ", BigIntLit(2, 8)) -;; check("B+ ", BigIntLit(3, 8) + BigIntLit(5, 8), BigIntLit(3 + 5, 8)) -;; check("B- ", BigIntLit(5, 8) + BigIntLit(3, 8), BigIntLit(5 + 3, 8)) -;; check("B| ", BigIntLit(5, 8) | BigIntLit(9, 8), BigIntLit(5 | 9, 8)) -;; check("B& ", BigIntLit(5, 8) & BigIntLit(9, 8), BigIntLit(5 & 9, 8)) -;; check("B^ ", BigIntLit(5, 8) ^ BigIntLit(9, 8), BigIntLit(5 ^ 9, 8)) -;; check("B< ", BigIntLit(5, 8) << 1, BigIntLit(5 << 1, 9)) -;; check("B< ", BigIntLit(5, 3) << 10, BigIntLit(5 << 1, 13)) -;; check("B< ", BigIntLit(5, 3) << 32, BigIntLit(5 << 1, 38)) -;; check("B< ", BigIntLit("b1010") << 1, BigIntLit(10 << 1, 5)) -check("S1 ", BigIntLit("hfafa") << 16, BigIntLit("hfafa0000", 32)) -check("S1 ", BigIntLit(1,32) , BigIntLit(1,32)) -check("S1 ", BigIntLit(0,32) , BigIntLit(0,32)) -;; check("B< ", BigIntLit(5, 3) << 64, BigIntLit(5 << 1, 67)) -;; check("BN ", neg(BigIntLit(2, 8)), BigIntLit(-2, 8)) -check("S2 ", BigIntLit("b11111010") << 8, BigIntLit("b1111101000000000", 16)) -check("C1 ", cat(BigIntLit("b11111010", 8), BigIntLit("b10111100", 8)), BigIntLit("b1111101010111100", 16)) -check("C3 ", cat(cat(BigIntLit("b1111"), BigIntLit("b1010")), cat(BigIntLit("b1011"), BigIntLit("b1100"))), BigIntLit("b1111101010111100", 16)) -check("C4 ", cat([BigIntLit("b1111"), BigIntLit("b1010"), BigIntLit("b1011"), BigIntLit("b1100")]), BigIntLit("b1111101010111100", 16)) -check("C5 ", BigIntLit("b101111001"), BigIntLit("b101111001")) -check("C6 ", cat(BigIntLit("b1"), BigIntLit("b01111001")), BigIntLit("b101111001")) -check("C7 ", cat(BigIntLit("b11101"), BigIntLit("b101111001")), BigIntLit("b11101101111001")) -check("C8 ", cat([BigIntLit("b11"), BigIntLit("b101"), BigIntLit("b1011"), BigIntLit("b11001")]), BigIntLit("b11101101111001")) -check("C0 ", bits(BigIntLit("b11101101111001"), 10, 1), BigIntLit("b0110111100")) +;;; check("Ba ", BigIntLit({ _ }, 1)) +;;; check("Bb ", BigIntLit({ _ }, 16)) +;;; check("Bc ", BigIntLit({ _ }, 32)) +;;; check("Bd ", BigIntLit({ _ }, 48)) +;;; check("Be ", BigIntLit({ _ }, 64)) +;;; check("Bf ", BigIntLit({ _ }, 65)) +;;; check("B1 ", BigIntLit(1, 8)) +;;; check("B2 ", BigIntLit(2, 8)) +;;; check("B+ ", BigIntLit(3, 8) + BigIntLit(5, 8), BigIntLit(3 + 5, 8)) +;;; check("B- ", BigIntLit(5, 8) + BigIntLit(3, 8), BigIntLit(5 + 3, 8)) +;;; check("B| ", BigIntLit(5, 8) | BigIntLit(9, 8), BigIntLit(5 | 9, 8)) +;;; check("B& ", BigIntLit(5, 8) & BigIntLit(9, 8), BigIntLit(5 & 9, 8)) +;;; check("B^ ", BigIntLit(5, 8) ^ BigIntLit(9, 8), BigIntLit(5 ^ 9, 8)) +;;; check("B< ", BigIntLit(5, 8) << 1, BigIntLit(5 << 1, 9)) +;;; check("B< ", BigIntLit(5, 3) << 10, BigIntLit(5 << 1, 13)) +;;; check("B< ", BigIntLit(5, 3) << 32, BigIntLit(5 << 1, 38)) +;;; check("B< ", BigIntLit("b1010") << 1, BigIntLit(10 << 1, 5)) +;check("S1 ", BigIntLit("hfafa") << 16, BigIntLit("hfafa0000", 32)) +;check("S1 ", BigIntLit(1,32) , BigIntLit(1,32)) +;check("S1 ", BigIntLit(0,32) , BigIntLit(0,32)) +;;; check("B< ", BigIntLit(5, 3) << 64, BigIntLit(5 << 1, 67)) +;;; check("BN ", neg(BigIntLit(2, 8)), BigIntLit(-2, 8)) +;check("S2 ", BigIntLit("b11111010") << 8, BigIntLit("b1111101000000000", 16)) +;check("C1 ", cat(BigIntLit("b11111010", 8), BigIntLit("b10111100", 8)), BigIntLit("b1111101010111100", 16)) +;check("C3 ", cat(cat(BigIntLit("b1111"), BigIntLit("b1010")), cat(BigIntLit("b1011"), BigIntLit("b1100"))), BigIntLit("b1111101010111100", 16)) +;check("C4 ", cat([BigIntLit("b1111"), BigIntLit("b1010"), BigIntLit("b1011"), BigIntLit("b1100")]), BigIntLit("b1111101010111100", 16)) +;check("C5 ", BigIntLit("b101111001"), BigIntLit("b101111001")) +;check("C6 ", cat(BigIntLit("b1"), BigIntLit("b01111001")), BigIntLit("b101111001")) +;check("C7 ", cat(BigIntLit("b11101"), BigIntLit("b101111001")), BigIntLit("b11101101111001")) +;check("C8 ", cat([BigIntLit("b11"), BigIntLit("b101"), BigIntLit("b1011"), BigIntLit("b11001")]), BigIntLit("b11101101111001")) +;check("C0 ", bits(BigIntLit("b11101101111001"), 10, 1), BigIntLit("b0110111100")) diff --git a/src/main/stanza/flo.stanza b/src/main/stanza/flo.stanza index f4b453ba..a7b726a7 100644 --- a/src/main/stanza/flo.stanza +++ b/src/main/stanza/flo.stanza @@ -61,12 +61,13 @@ defn flo-op-name (op:PrimOp, args:List<Expression>) -> String : else : error $ string-join $ ["Unable to print Primop: " op] -defn sane-width (wd:Width) -> Int : +defn sane-width (wd:Width) -> Int|Long : match(wd) : (w:IntWidth) : max(1, width(w)) + (w:LongWidth) : max(to-long(1), width(w)) (w) : error(string-join(["Unknown width: " w])) -defn prim-width (type:Type) -> Int : +defn prim-width (type:Type) -> Int|Long : match(type) : (t:UIntType) : sane-width(width(t)) (t:SIntType) : sane-width(width(t)) diff --git a/src/main/stanza/ir-parser.stanza b/src/main/stanza/ir-parser.stanza index fdf4c383..9d9893c5 100644 --- a/src/main/stanza/ir-parser.stanza +++ b/src/main/stanza/ir-parser.stanza @@ -27,6 +27,15 @@ defn* apply-suffix-ops (x, fs:List) : if empty?(fs) : x else : apply-suffix-ops(head(fs)(x), tail(fs)) +defn parse-stmts (forms:List) : + val cs = Vector<Stmt>() + defn* loop (forms:List) : + match-syntax(forms) : + () : to-list(cs) + (?s:#stmt ?rest ...) : (add(cs, s), loop(rest)) + (?rest ...) : FPE(rest, "Expected a statement here.") + loop(forms) + ;======== Parser Utilities ============== defn atom? (x) : unwrap-token(x) not-typeof List @@ -167,6 +176,8 @@ defsyntax firrtl : ;Main Module Production defrule module : + ;module = (module ?name:#id! #:! (?ps:#port ... ?rest ...)) : + ; InModule(first-info(form), name, ps, Begin(parse-stmts(rest))) module = (module ?name:#id! #:! (?ps:#port ... ?cs:#stmt ... ?rest ...)) : if not empty?(rest) : FPE(rest, "Expected a statement here.") @@ -235,6 +246,8 @@ defsyntax firrtl : stmt = (?x:#exp := ?y:#exp!) : Connect(first-info(form),x, y) stmt = (?x:#exp <> ?y:#exp!) : BulkConnect(first-info(form),x, y) + ;stmt = ((?s:#stmt ?rest ...)) : + ; Begin(List(s, parse-stmts(rest))) stmt = ((?s:#stmt ?ss:#stmt ... ?rest ...)) : if not empty?(rest) : FPE(rest, "Expected a statement here.") diff --git a/src/main/stanza/ir-utils.stanza b/src/main/stanza/ir-utils.stanza index 0118c73b..93dc0d79 100644 --- a/src/main/stanza/ir-utils.stanza +++ b/src/main/stanza/ir-utils.stanza @@ -86,9 +86,13 @@ public defn abs (x:Long) -> Long : if x < to-long(0) : to-long(0) - x else : x -;public defn to-int (x:Long) -> Int : - ;if x > to-long(2147483647) or x < to-long(–2147483648) : error("Long too big to convert to Int") - ;else : x + 0 +public defn max (x:Long,y:Long) -> Long : + if x < y : y + else : x + +public defn to-int (x:Long) -> Int : + if x > to-long(2147483647) or x < to-long(-2147483648) : error("Long too big to convert to Int") + else : to-int(to-string(x)) ;============== PRINTERS =================================== diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza index db1a056e..36cc2c46 100644 --- a/src/main/stanza/passes.stanza +++ b/src/main/stanza/passes.stanza @@ -1504,15 +1504,14 @@ defn mark-referenced (referenced?:HashTable<Symbol,True>, s:Stmt) -> False : map(mark-referenced-e,s) false -defn mark-referenced (referenced?:HashTable<Symbol,True>, sv:SymbolicValue) -> False : +defn mark-referenced (referenced?:HashTable<Symbol,True>, sv:SymbolicValue) -> SymbolicValue : defn mark-referenced-e (e:Expression) -> Expression : match(map(mark-referenced-e,e)) : (e:WRef) : referenced?[name(e)] = true e (e) : e - map(mark-referenced-e,sv) - false + map{mark-referenced-e,_} $ map(mark-referenced{referenced?,_:SymbolicValue},sv) defn is-referenced? (referenced?:HashTable<Symbol,True>, s:Stmt) -> True|False : match(s) : @@ -1609,8 +1608,8 @@ public defn expand-whens (c:Circuit) -> Circuit : ;for x in resets do : println-debug(x) val table = merge-resets(assign,resets,rsignals) - ;println-debug("====== Table ======") - ;for x in table do : println-debug(x) + println("====== Table ======") + for x in table do : println(x) val decs = Vector<Stmt>() val cons = Vector<Stmt>() @@ -1624,6 +1623,7 @@ public defn expand-whens (c:Circuit) -> Circuit : referenced?[key(x)] = true for x in decs do : mark-referenced(referenced?,x) + println-all(["Referenced \n" referenced?]) val decs* = Vector<Stmt>() for x in decs do : if is-referenced?(referenced?,x) : add(decs*,x) @@ -1814,8 +1814,8 @@ defn solve-constraints (l:List<WGeq>) -> HashTable<Symbol,Width> : (w1,w2) : w (w:ExpWidth) : match(arg1(w)) : - (w1:IntWidth) : LongWidth(pow(to-long(2),to-long(width(w1) - 1))) - (w1:LongWidth) : LongWidth(pow(to-long(2),minus(width(w1), to-long(1)))) + (w1:IntWidth) : LongWidth(pow(to-long(2),to-long(width(w1))) - to-long(1)) + (w1:LongWidth) : LongWidth(pow(to-long(2),width(w1)) - to-long(1)) (w1) : w (w) : w defn substitute (w:Width,h:HashTable<Symbol,Width>) -> Width : |
