aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/stanza/ir-parser.stanza2
-rw-r--r--src/main/stanza/ir-utils.stanza3
-rw-r--r--src/main/stanza/passes.stanza308
3 files changed, 213 insertions, 100 deletions
diff --git a/src/main/stanza/ir-parser.stanza b/src/main/stanza/ir-parser.stanza
index d6d33467..1ba52b03 100644
--- a/src/main/stanza/ir-parser.stanza
+++ b/src/main/stanza/ir-parser.stanza
@@ -75,6 +75,8 @@ defsyntax firrtl :
Begin(body)
comm = (?x:#exp := ?y:#exp) :
Connect(x, y)
+ comm = (?c:skip) :
+ EmptyStmt()
comm = (?c:#comm/when) :
c
diff --git a/src/main/stanza/ir-utils.stanza b/src/main/stanza/ir-utils.stanza
index ae8fdbe9..310c7227 100644
--- a/src/main/stanza/ir-utils.stanza
+++ b/src/main/stanza/ir-utils.stanza
@@ -119,6 +119,7 @@ defmethod print (o:OutputStream, op:PrimOp) :
CONVERT-OP : "convert"
CONVERT-U-OP : "convert-u"
CONVERT-S-OP : "convert-s"
+ BIT-NOT-OP : "bit-not"
BIT-AND-OP : "bit-and"
BIT-OR-OP : "bit-or"
BIT-XOR-OP : "bit-xor"
@@ -169,7 +170,7 @@ defmethod print (o:OutputStream, c:Stmt) :
(c:Connect) :
print-all(o, [loc(c) " := " exp(c)])
(c:EmptyStmt) :
- print(o, "$empty$")
+ print(o, "skip")
print-debug(o,c)
defmethod print (o:OutputStream, t:Type) :
diff --git a/src/main/stanza/passes.stanza b/src/main/stanza/passes.stanza
index aa940ceb..b7cce362 100644
--- a/src/main/stanza/passes.stanza
+++ b/src/main/stanza/passes.stanza
@@ -384,7 +384,7 @@ defn make-explicit-reset (c:Circuit) :
; Type errors are not checked in this pass, as this is
; postponed for a later/earlier pass.
-defn get-primop-rettype (e:DoPrim) -> Type :
+defn lower-primop (e:DoPrim) -> DoPrim :
defn u () : UIntType(UnknownWidth())
defn s () : SIntType(UnknownWidth())
defn u-and (op1:Expression,op2:Expression) :
@@ -402,102 +402,211 @@ defn get-primop-rettype (e:DoPrim) -> Type :
;println-all(["Inferencing primop type: " e])
switch {op(e) == _} :
- ADD-OP : u-and(args(e)[0],args(e)[1])
- ADD-UU-OP : u()
- ADD-US-OP : s()
- ADD-SU-OP : s()
- ADD-SS-OP : s()
- SUB-OP : s()
- SUB-UU-OP : s()
- SUB-US-OP : s()
- SUB-SU-OP : s()
- SUB-SS-OP : s()
- MUL-OP : u-and(args(e)[0],args(e)[1])
- MUL-UU-OP : u()
- MUL-US-OP : s()
- MUL-SU-OP : s()
- MUL-SS-OP : s()
- DIV-OP : u-and(args(e)[0],args(e)[1])
- DIV-UU-OP : u()
- DIV-US-OP : s()
- DIV-SU-OP : s()
- DIV-SS-OP : s()
- MOD-OP : of-type(args(e)[0])
- MOD-UU-OP : u()
- MOD-US-OP : u()
- MOD-SU-OP : s()
- MOD-SS-OP : s()
- QUO-OP : u-and(args(e)[0],args(e)[1])
- QUO-UU-OP : u()
- QUO-US-OP : s()
- QUO-SU-OP : s()
- QUO-SS-OP : s()
- REM-OP : of-type(args(e)[1])
- REM-UU-OP : u()
- REM-US-OP : s()
- REM-SU-OP : u()
- REM-SS-OP : s()
- ADD-WRAP-OP : u-and(args(e)[0],args(e)[1])
- ADD-WRAP-UU-OP : u()
- ADD-WRAP-US-OP : s()
- ADD-WRAP-SU-OP : s()
- ADD-WRAP-SS-OP : s()
- SUB-WRAP-OP : u-and(args(e)[0],args(e)[1])
- SUB-WRAP-UU-OP : u()
- SUB-WRAP-US-OP : s()
- SUB-WRAP-SU-OP : s()
- SUB-WRAP-SS-OP : s()
- LESS-OP : u()
- LESS-UU-OP : u()
- LESS-US-OP : u()
- LESS-SU-OP : u()
- LESS-SS-OP : u()
- LESS-EQ-OP : u()
- LESS-EQ-UU-OP : u()
- LESS-EQ-US-OP : u()
- LESS-EQ-SU-OP : u()
- LESS-EQ-SS-OP : u()
- GREATER-OP : u()
- GREATER-UU-OP : u()
- GREATER-US-OP : u()
- GREATER-SU-OP : u()
- GREATER-SS-OP : u()
- GREATER-EQ-OP : u()
- GREATER-EQ-UU-OP : u()
- GREATER-EQ-US-OP : u()
- GREATER-EQ-SU-OP : u()
- GREATER-EQ-SS-OP : u()
- EQUAL-OP : u()
- EQUAL-UU-OP : u()
- EQUAL-SS-OP : u()
- MUX-OP : of-type(args(e)[0])
- MUX-UU-OP : u()
- MUX-SS-OP : s()
- PAD-OP : of-type(args(e)[0])
- PAD-U-OP : u()
- PAD-S-OP : s()
- AS-UINT-OP : u()
- AS-UINT-U-OP : u()
- AS-UINT-S-OP : u()
- AS-SINT-OP : s()
- AS-SINT-U-OP : s()
- AS-SINT-S-OP : s()
- SHIFT-LEFT-OP : of-type(args(e)[0])
- SHIFT-LEFT-U-OP : u()
- SHIFT-LEFT-S-OP : s()
- SHIFT-RIGHT-OP : of-type(args(e)[0])
- SHIFT-RIGHT-U-OP : u()
- SHIFT-RIGHT-S-OP : s()
- CONVERT-OP : s()
- CONVERT-U-OP : s()
- CONVERT-S-OP : s()
- BIT-NOT-OP : u()
- BIT-AND-OP : u()
- BIT-OR-OP : u()
- BIT-XOR-OP : u()
- CONCAT-OP : u()
- BIT-SELECT-OP : u()
- BITS-SELECT-OP : u()
+ ADD-OP :
+ DoPrim{_,args(e),consts(e),u-and(args(e)[0],args(e)[1])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : ADD-UU-OP
+ (t1:UIntType, t2:SIntType) : ADD-US-OP
+ (t1:SIntType, t2:UIntType) : ADD-SU-OP
+ (t1:SIntType, t2:SIntType) : ADD-SS-OP
+ ADD-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ ADD-US-OP : DoPrim(op(e),args(e),consts(e),s())
+ ADD-SU-OP : DoPrim(op(e),args(e),consts(e),s())
+ ADD-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ SUB-UU-OP :
+ DoPrim{_,args(e),consts(e),s()} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : SUB-UU-OP
+ (t1:UIntType, t2:SIntType) : SUB-US-OP
+ (t1:SIntType, t2:UIntType) : SUB-SU-OP
+ (t1:SIntType, t2:SIntType) : SUB-SS-OP
+ SUB-US-OP : DoPrim(op(e),args(e),consts(e),s())
+ SUB-SU-OP : DoPrim(op(e),args(e),consts(e),s())
+ SUB-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ MUL-OP :
+ DoPrim{_,args(e),consts(e),u-and(args(e)[0],args(e)[1])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : MUL-UU-OP
+ (t1:UIntType, t2:SIntType) : MUL-US-OP
+ (t1:SIntType, t2:UIntType) : MUL-SU-OP
+ (t1:SIntType, t2:SIntType) : MUL-SS-OP
+ MUL-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ MUL-US-OP : DoPrim(op(e),args(e),consts(e),s())
+ MUL-SU-OP : DoPrim(op(e),args(e),consts(e),s())
+ MUL-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ DIV-OP :
+ DoPrim{_,args(e),consts(e),u-and(args(e)[0],args(e)[1])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : DIV-UU-OP
+ (t1:UIntType, t2:SIntType) : DIV-US-OP
+ (t1:SIntType, t2:UIntType) : DIV-SU-OP
+ (t1:SIntType, t2:SIntType) : DIV-SS-OP
+ DIV-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ DIV-US-OP : DoPrim(op(e),args(e),consts(e),s())
+ DIV-SU-OP : DoPrim(op(e),args(e),consts(e),s())
+ DIV-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ MOD-OP :
+ DoPrim{_,args(e),consts(e),of-type(args(e)[0])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : MOD-UU-OP
+ (t1:UIntType, t2:SIntType) : MOD-US-OP
+ (t1:SIntType, t2:UIntType) : MOD-SU-OP
+ (t1:SIntType, t2:SIntType) : MOD-SS-OP
+ MOD-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ MOD-US-OP : DoPrim(op(e),args(e),consts(e),u())
+ MOD-SU-OP : DoPrim(op(e),args(e),consts(e),s())
+ MOD-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ QUO-OP :
+ DoPrim{_,args(e),consts(e),u-and(args(e)[0],args(e)[1])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : QUO-UU-OP
+ (t1:UIntType, t2:SIntType) : QUO-US-OP
+ (t1:SIntType, t2:UIntType) : QUO-SU-OP
+ (t1:SIntType, t2:SIntType) : QUO-SS-OP
+ QUO-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ QUO-US-OP : DoPrim(op(e),args(e),consts(e),s())
+ QUO-SU-OP : DoPrim(op(e),args(e),consts(e),s())
+ QUO-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ REM-OP :
+ DoPrim{_,args(e),consts(e),of-type(args(e)[1])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : REM-UU-OP
+ (t1:UIntType, t2:SIntType) : REM-US-OP
+ (t1:SIntType, t2:UIntType) : REM-SU-OP
+ (t1:SIntType, t2:SIntType) : REM-SS-OP
+ REM-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ REM-US-OP : DoPrim(op(e),args(e),consts(e),s())
+ REM-SU-OP : DoPrim(op(e),args(e),consts(e),u())
+ REM-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ ADD-WRAP-OP :
+ DoPrim{_,args(e),consts(e),u-and(args(e)[0],args(e)[1])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : ADD-WRAP-UU-OP
+ (t1:UIntType, t2:SIntType) : ADD-WRAP-US-OP
+ (t1:SIntType, t2:UIntType) : ADD-WRAP-SU-OP
+ (t1:SIntType, t2:SIntType) : ADD-WRAP-SS-OP
+ ADD-WRAP-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ ADD-WRAP-US-OP : DoPrim(op(e),args(e),consts(e),s())
+ ADD-WRAP-SU-OP : DoPrim(op(e),args(e),consts(e),s())
+ ADD-WRAP-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ SUB-WRAP-OP :
+ DoPrim{_,args(e),consts(e),u-and(args(e)[0],args(e)[1])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : SUB-WRAP-UU-OP
+ (t1:UIntType, t2:SIntType) : SUB-WRAP-US-OP
+ (t1:SIntType, t2:UIntType) : SUB-WRAP-SU-OP
+ (t1:SIntType, t2:SIntType) : SUB-WRAP-SS-OP
+ SUB-WRAP-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ SUB-WRAP-US-OP : DoPrim(op(e),args(e),consts(e),s())
+ SUB-WRAP-SU-OP : DoPrim(op(e),args(e),consts(e),s())
+ SUB-WRAP-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ LESS-OP :
+ DoPrim{_,args(e),consts(e),u()} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : LESS-UU-OP
+ (t1:UIntType, t2:SIntType) : LESS-US-OP
+ (t1:SIntType, t2:UIntType) : LESS-SU-OP
+ (t1:SIntType, t2:SIntType) : LESS-SS-OP
+ LESS-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ LESS-US-OP : DoPrim(op(e),args(e),consts(e),u())
+ LESS-SU-OP : DoPrim(op(e),args(e),consts(e),u())
+ LESS-SS-OP : DoPrim(op(e),args(e),consts(e),u())
+ LESS-EQ-OP :
+ DoPrim{_,args(e),consts(e),u()} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : LESS-EQ-UU-OP
+ (t1:UIntType, t2:SIntType) : LESS-EQ-US-OP
+ (t1:SIntType, t2:UIntType) : LESS-EQ-SU-OP
+ (t1:SIntType, t2:SIntType) : LESS-EQ-SS-OP
+ LESS-EQ-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ LESS-EQ-US-OP : DoPrim(op(e),args(e),consts(e),u())
+ LESS-EQ-SU-OP : DoPrim(op(e),args(e),consts(e),u())
+ LESS-EQ-SS-OP : DoPrim(op(e),args(e),consts(e),u())
+ GREATER-OP :
+ DoPrim{_,args(e),consts(e),u()} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : GREATER-UU-OP
+ (t1:UIntType, t2:SIntType) : GREATER-US-OP
+ (t1:SIntType, t2:UIntType) : GREATER-SU-OP
+ (t1:SIntType, t2:SIntType) : GREATER-SS-OP
+ GREATER-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ GREATER-US-OP : DoPrim(op(e),args(e),consts(e),u())
+ GREATER-SU-OP : DoPrim(op(e),args(e),consts(e),u())
+ GREATER-SS-OP : DoPrim(op(e),args(e),consts(e),u())
+ GREATER-EQ-OP :
+ DoPrim{_,args(e),consts(e),u()} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : GREATER-EQ-UU-OP
+ (t1:UIntType, t2:SIntType) : GREATER-EQ-US-OP
+ (t1:SIntType, t2:UIntType) : GREATER-EQ-SU-OP
+ (t1:SIntType, t2:SIntType) : GREATER-EQ-SS-OP
+ GREATER-EQ-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ GREATER-EQ-US-OP : DoPrim(op(e),args(e),consts(e),u())
+ GREATER-EQ-SU-OP : DoPrim(op(e),args(e),consts(e),u())
+ GREATER-EQ-SS-OP : DoPrim(op(e),args(e),consts(e),u())
+ EQUAL-OP :
+ DoPrim{_,args(e),consts(e),u()} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : EQUAL-UU-OP
+ (t1:SIntType, t2:SIntType) : EQUAL-SS-OP
+ EQUAL-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ EQUAL-SS-OP : DoPrim(op(e),args(e),consts(e),u())
+ MUX-OP :
+ DoPrim{_,args(e),consts(e),of-type(args(e)[0])} $
+ match(type(args(e)[0]),type(args(e)[0])) :
+ (t1:UIntType, t2:UIntType) : MUX-UU-OP
+ (t1:SIntType, t2:SIntType) : MUX-SS-OP
+ MUX-UU-OP : DoPrim(op(e),args(e),consts(e),u())
+ MUX-SS-OP : DoPrim(op(e),args(e),consts(e),s())
+ PAD-OP :
+ DoPrim{_,args(e),consts(e),of-type(args(e)[0])} $
+ match(type(args(e)[0])) :
+ (t1:UIntType) : PAD-U-OP
+ (t1:SIntType) : PAD-S-OP
+ PAD-U-OP : DoPrim(op(e),args(e),consts(e),u())
+ PAD-S-OP : DoPrim(op(e),args(e),consts(e),s())
+ AS-UINT-OP :
+ DoPrim{_,args(e),consts(e),u()} $
+ match(type(args(e)[0])) :
+ (t1:UIntType) : AS-UINT-U-OP
+ (t1:SIntType) : AS-UINT-S-OP
+ AS-UINT-U-OP : DoPrim(op(e),args(e),consts(e),u())
+ AS-UINT-S-OP : DoPrim(op(e),args(e),consts(e),u())
+ AS-SINT-OP :
+ DoPrim{_,args(e),consts(e),s()} $
+ match(type(args(e)[0])) :
+ (t1:UIntType) : AS-SINT-U-OP
+ (t1:SIntType) : AS-SINT-S-OP
+ AS-SINT-U-OP : DoPrim(op(e),args(e),consts(e),s())
+ AS-SINT-S-OP : DoPrim(op(e),args(e),consts(e),s())
+ SHIFT-LEFT-OP :
+ DoPrim{_,args(e),consts(e),of-type(args(e)[0])} $
+ match(type(args(e)[0])) :
+ (t1:UIntType) : SHIFT-LEFT-U-OP
+ (t1:SIntType) : SHIFT-LEFT-S-OP
+ SHIFT-LEFT-U-OP : DoPrim(op(e),args(e),consts(e),u())
+ SHIFT-LEFT-S-OP : DoPrim(op(e),args(e),consts(e),s())
+ SHIFT-RIGHT-OP :
+ DoPrim{_,args(e),consts(e),of-type(args(e)[0])} $
+ match(type(args(e)[0])) :
+ (t1:UIntType) : SHIFT-RIGHT-U-OP
+ (t1:SIntType) : SHIFT-RIGHT-S-OP
+ SHIFT-RIGHT-U-OP : DoPrim(op(e),args(e),consts(e),u())
+ SHIFT-RIGHT-S-OP : DoPrim(op(e),args(e),consts(e),s())
+ CONVERT-OP :
+ DoPrim{_,args(e),consts(e),s()} $
+ match(type(args(e)[0])) :
+ (t1:UIntType) : CONVERT-U-OP
+ (t1:SIntType) : CONVERT-S-OP
+ CONVERT-U-OP : DoPrim(op(e),args(e),consts(e),s())
+ CONVERT-S-OP : DoPrim(op(e),args(e),consts(e),s())
+ BIT-NOT-OP : DoPrim(op(e),args(e),consts(e),u())
+ BIT-AND-OP : DoPrim(op(e),args(e),consts(e),u())
+ BIT-OR-OP : DoPrim(op(e),args(e),consts(e),u())
+ BIT-XOR-OP : DoPrim(op(e),args(e),consts(e),u())
+ CONCAT-OP : DoPrim(op(e),args(e),consts(e),u())
+ BIT-SELECT-OP : DoPrim(op(e),args(e),consts(e),u())
+ BITS-SELECT-OP : DoPrim(op(e),args(e),consts(e),u())
defn type (m:Module) -> Type :
BundleType(for p in ports(m) map : to-field(p))
@@ -530,7 +639,8 @@ defn infer-exp-types (e:Expression, l:List<KeyValue<Symbol,Type>>) -> Expression
(e:WSubfield) : WSubfield(exp(e),name(e), bundle-field-type(type(exp(e)),name(e)),gender(e))
(e:WRegInit) : WRegInit(reg(e),name(e),get-type(name(reg(e) as WRef),l),gender(e))
(e:WIndex) : WIndex(exp(e),value(e), get-vector-subtype(type(exp(e))),gender(e))
- (e:DoPrim) : DoPrim(op(e),args(e),consts(e),get-primop-rettype(e))
+ (e:DoPrim) : lower-primop(e)
+ ;DoPrim(op(e),args(e),consts(e),get-primop-rettype(e))
(e:ReadPort) : ReadPort(mem(e),index(e),get-vector-subtype(type(mem(e))),enable(e))
(e:WritePort) : WritePort(mem(e),index(e),get-vector-subtype(type(mem(e))),enable(e))
(e:UIntValue|SIntValue) : e
@@ -1647,7 +1757,7 @@ defn gen-constraints (m:Module, h:HashTable<Symbol,Type>, v:Vector<WGeq>) -> Mod
defn wmc (l:List<Expression>,c:List<Int>) :
add-c(MinusWidth(width!(l[0]),IntWidth(c[0])))
defn maxw (l:List<Expression>) :
- add-c(MaxWidth(list(width!(l[0]),width!(l[1]))))
+ add-c(MaxWidth(map(width!,l)))
defn cons (ls:List<Expression>) :
val l = width!(ls[0])
val r = width!(ls[1])