aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDonggyu2016-09-07 16:55:56 -0700
committerGitHub2016-09-07 16:55:56 -0700
commit296a65ebb895d100c3cbde6df7c0303d6942e5d5 (patch)
tree09f8365353992e4de46c2b660bdeb737a26981b8 /src
parenta404cf5b2c4ca6457c964eb32aae8330c48422e1 (diff)
parentef6068fd0bd79b7e30602687caa480461d1b629d (diff)
Merge pull request #276 from ucb-bar/cleanup_miscs
Clean up WIR, PrimOps
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/PrimOps.scala516
-rw-r--r--src/main/scala/firrtl/Utils.scala3
-rw-r--r--src/main/scala/firrtl/WIR.scala204
-rw-r--r--src/main/scala/firrtl/passes/ConstProp.scala2
-rw-r--r--src/main/scala/firrtl/passes/Inline.scala6
-rw-r--r--src/main/scala/firrtl/passes/RemoveEmpty.scala2
-rw-r--r--src/main/scala/firrtl/passes/ReplaceSubAccess.scala7
7 files changed, 299 insertions, 441 deletions
diff --git a/src/main/scala/firrtl/PrimOps.scala b/src/main/scala/firrtl/PrimOps.scala
index 8b705b29..dc6dfadb 100644
--- a/src/main/scala/firrtl/PrimOps.scala
+++ b/src/main/scala/firrtl/PrimOps.scala
@@ -110,313 +110,211 @@ object PrimOps extends LazyLogging {
def fromString(op: String): PrimOp = strToPrimOp(op)
// Borrowed from Stanza implementation
- def set_primop_type (e:DoPrim) : DoPrim = {
- //println-all(["Inferencing primop type: " e])
- def PLUS (w1:Width,w2:Width) : Width = (w1, w2) match {
- case (IntWidth(i), IntWidth(j)) => IntWidth(i + j)
- case _ => PlusWidth(w1,w2)
- }
- def MAX (w1:Width,w2:Width) : Width = (w1, w2) match {
- case (IntWidth(i), IntWidth(j)) => IntWidth(max(i,j))
- case _ => MaxWidth(Seq(w1,w2))
- }
- def MINUS (w1:Width,w2:Width) : Width = (w1, w2) match {
- case (IntWidth(i), IntWidth(j)) => IntWidth(i - j)
- case _ => MinusWidth(w1,w2)
- }
- def POW (w1:Width) : Width = w1 match {
- case IntWidth(i) => IntWidth(pow_minus_one(BigInt(2), i))
- case _ => ExpWidth(w1)
- }
- def MIN (w1:Width,w2:Width) : Width = (w1, w2) match {
- case (IntWidth(i), IntWidth(j)) => IntWidth(min(i,j))
- case _ => MinWidth(Seq(w1,w2))
- }
- val o = e.op
- val a = e.args
- val c = e.consts
- def t1 () = a(0).tpe
- def t2 () = a(1).tpe
- def t3 () = a(2).tpe
- def w1 () = Utils.widthBANG(a(0).tpe)
- def w2 () = Utils.widthBANG(a(1).tpe)
- def w3 () = Utils.widthBANG(a(2).tpe)
- def c1 () = IntWidth(c(0))
- def c2 () = IntWidth(c(1))
- o match {
- case Add => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => UIntType(PLUS(MAX(w1(),w2()),IntWidth(1)))
- case (t1:UIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),IntWidth(1)))
- case (t1:SIntType, t2:UIntType) => SIntType(PLUS(MAX(w1(),w2()),IntWidth(1)))
- case (t1:SIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),IntWidth(1)))
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Sub => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => SIntType(PLUS(MAX(w1(),w2()),IntWidth(1)))
- case (t1:UIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),IntWidth(1)))
- case (t1:SIntType, t2:UIntType) => SIntType(PLUS(MAX(w1(),w2()),IntWidth(1)))
- case (t1:SIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),IntWidth(1)))
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Mul => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => UIntType(PLUS(w1(),w2()))
- case (t1:UIntType, t2:SIntType) => SIntType(PLUS(w1(),w2()))
- case (t1:SIntType, t2:UIntType) => SIntType(PLUS(w1(),w2()))
- case (t1:SIntType, t2:SIntType) => SIntType(PLUS(w1(),w2()))
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Div => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => UIntType(w1())
- case (t1:UIntType, t2:SIntType) => SIntType(PLUS(w1(),IntWidth(1)))
- case (t1:SIntType, t2:UIntType) => SIntType(w1())
- case (t1:SIntType, t2:SIntType) => SIntType(PLUS(w1(),IntWidth(1)))
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Rem => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => UIntType(MIN(w1(),w2()))
- case (t1:UIntType, t2:SIntType) => UIntType(MIN(w1(),w2()))
- case (t1:SIntType, t2:UIntType) => SIntType(MIN(w1(),PLUS(w2(),IntWidth(1))))
- case (t1:SIntType, t2:SIntType) => SIntType(MIN(w1(),w2()))
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Lt => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => Utils.BoolType
- case (t1:SIntType, t2:UIntType) => Utils.BoolType
- case (t1:UIntType, t2:SIntType) => Utils.BoolType
- case (t1:SIntType, t2:SIntType) => Utils.BoolType
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Leq => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => Utils.BoolType
- case (t1:SIntType, t2:UIntType) => Utils.BoolType
- case (t1:UIntType, t2:SIntType) => Utils.BoolType
- case (t1:SIntType, t2:SIntType) => Utils.BoolType
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Gt => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => Utils.BoolType
- case (t1:SIntType, t2:UIntType) => Utils.BoolType
- case (t1:UIntType, t2:SIntType) => Utils.BoolType
- case (t1:SIntType, t2:SIntType) => Utils.BoolType
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Geq => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => Utils.BoolType
- case (t1:SIntType, t2:UIntType) => Utils.BoolType
- case (t1:UIntType, t2:SIntType) => Utils.BoolType
- case (t1:SIntType, t2:SIntType) => Utils.BoolType
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Eq => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => Utils.BoolType
- case (t1:SIntType, t2:UIntType) => Utils.BoolType
- case (t1:UIntType, t2:SIntType) => Utils.BoolType
- case (t1:SIntType, t2:SIntType) => Utils.BoolType
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Neq => {
- val t = (t1(),t2()) match {
- case (t1:UIntType, t2:UIntType) => Utils.BoolType
- case (t1:SIntType, t2:UIntType) => Utils.BoolType
- case (t1:UIntType, t2:SIntType) => Utils.BoolType
- case (t1:SIntType, t2:SIntType) => Utils.BoolType
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Pad => {
- val t = (t1()) match {
- case (t1:UIntType) => UIntType(MAX(w1(),c1()))
- case (t1:SIntType) => SIntType(MAX(w1(),c1()))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case AsUInt => {
- val t = (t1()) match {
- case (t1:UIntType) => UIntType(w1())
- case (t1:SIntType) => UIntType(w1())
- case ClockType => UIntType(IntWidth(1))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case AsSInt => {
- val t = (t1()) match {
- case (t1:UIntType) => SIntType(w1())
- case (t1:SIntType) => SIntType(w1())
- case ClockType => SIntType(IntWidth(1))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case AsClock => {
- val t = (t1()) match {
- case (t1:UIntType) => ClockType
- case (t1:SIntType) => ClockType
- case ClockType => ClockType
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Shl => {
- val t = (t1()) match {
- case (t1:UIntType) => UIntType(PLUS(w1(),c1()))
- case (t1:SIntType) => SIntType(PLUS(w1(),c1()))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Shr => {
- val t = (t1()) match {
- case (t1:UIntType) => UIntType(MAX(MINUS(w1(),c1()),IntWidth(1)))
- case (t1:SIntType) => SIntType(MAX(MINUS(w1(),c1()),IntWidth(1)))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Dshl => {
- val t = (t1()) match {
- case (t1:UIntType) => UIntType(PLUS(w1(),POW(w2())))
- case (t1:SIntType) => SIntType(PLUS(w1(),POW(w2())))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Dshr => {
- val t = (t1()) match {
- case (t1:UIntType) => UIntType(w1())
- case (t1:SIntType) => SIntType(w1())
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Cvt => {
- val t = (t1()) match {
- case (t1:UIntType) => SIntType(PLUS(w1(),IntWidth(1)))
- case (t1:SIntType) => SIntType(w1())
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Neg => {
- val t = (t1()) match {
- case (t1:UIntType) => SIntType(PLUS(w1(),IntWidth(1)))
- case (t1:SIntType) => SIntType(PLUS(w1(),IntWidth(1)))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Not => {
- val t = (t1()) match {
- case (t1:UIntType) => UIntType(w1())
- case (t1:SIntType) => UIntType(w1())
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case And => {
- val t = (t1(),t2()) match {
- case (_:SIntType|_:UIntType, _:SIntType|_:UIntType) => UIntType(MAX(w1(),w2()))
- case (t1,t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Or => {
- val t = (t1(),t2()) match {
- case (_:SIntType|_:UIntType, _:SIntType|_:UIntType) => UIntType(MAX(w1(),w2()))
- case (t1,t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Xor => {
- val t = (t1(),t2()) match {
- case (_:SIntType|_:UIntType, _:SIntType|_:UIntType) => UIntType(MAX(w1(),w2()))
- case (t1,t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Andr => {
- val t = (t1()) match {
- case (_:UIntType|_:SIntType) => Utils.BoolType
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Orr => {
- val t = (t1()) match {
- case (_:UIntType|_:SIntType) => Utils.BoolType
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Xorr => {
- val t = (t1()) match {
- case (_:UIntType|_:SIntType) => Utils.BoolType
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Cat => {
- val t = (t1(),t2()) match {
- case (_:UIntType|_:SIntType,_:UIntType|_:SIntType) => UIntType(PLUS(w1(),w2()))
- case (t1, t2) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Bits => {
- val t = (t1()) match {
- case (_:UIntType|_:SIntType) => UIntType(PLUS(MINUS(c1(),c2()),IntWidth(1)))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Head => {
- val t = (t1()) match {
- case (_:UIntType|_:SIntType) => UIntType(c1())
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
- case Tail => {
- val t = (t1()) match {
- case (_:UIntType|_:SIntType) => UIntType(MINUS(w1(),c1()))
- case (t1) => UnknownType
- }
- DoPrim(o,a,c,t)
- }
-
- }
- }
-
+ def set_primop_type (e:DoPrim) : DoPrim = {
+ //println-all(["Inferencing primop type: " e])
+ def PLUS (w1:Width, w2:Width) : Width = (w1, w2) match {
+ case (IntWidth(i), IntWidth(j)) => IntWidth(i + j)
+ case _ => PlusWidth(w1, w2)
+ }
+ def MAX (w1:Width, w2:Width) : Width = (w1, w2) match {
+ case (IntWidth(i), IntWidth(j)) => IntWidth(max(i,j))
+ case _ => MaxWidth(Seq(w1, w2))
+ }
+ def MINUS (w1:Width, w2:Width) : Width = (w1, w2) match {
+ case (IntWidth(i), IntWidth(j)) => IntWidth(i - j)
+ case _ => MinusWidth(w1, w2)
+ }
+ def POW (w1:Width) : Width = w1 match {
+ case IntWidth(i) => IntWidth(pow_minus_one(BigInt(2), i))
+ case _ => ExpWidth(w1)
+ }
+ def MIN (w1:Width, w2:Width) : Width = (w1, w2) match {
+ case (IntWidth(i), IntWidth(j)) => IntWidth(min(i,j))
+ case _ => MinWidth(Seq(w1, w2))
+ }
+ def t1 = e.args(0).tpe
+ def t2 = e.args(1).tpe
+ def t3 = e.args(2).tpe
+ def w1 = Utils.width_BANG(e.args(0).tpe)
+ def w2 = Utils.width_BANG(e.args(1).tpe)
+ def c1 = IntWidth(e.consts(0))
+ def c2 = IntWidth(e.consts(1))
+ e copy (tpe = (e.op match {
+ case Add => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => UIntType(PLUS(MAX(w1, w2), IntWidth(1)))
+ case (_: UIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
+ case (_: SIntType, _: UIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
+ case (_: SIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
+ case _ => UnknownType
+ }
+ case Sub => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
+ case (_: UIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
+ case (_: SIntType, _: UIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
+ case (_: SIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1)))
+ case _ => UnknownType
+ }
+ case Mul => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => UIntType(PLUS(w1, w2))
+ case (_: UIntType, _: SIntType) => SIntType(PLUS(w1, w2))
+ case (_: SIntType, _: UIntType) => SIntType(PLUS(w1, w2))
+ case (_: SIntType, _: SIntType) => SIntType(PLUS(w1, w2))
+ case _ => UnknownType
+ }
+ case Div => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => UIntType(w1)
+ case (_: UIntType, _: SIntType) => SIntType(PLUS(w1, IntWidth(1)))
+ case (_: SIntType, _: UIntType) => SIntType(w1)
+ case (_: SIntType, _: SIntType) => SIntType(PLUS(w1, IntWidth(1)))
+ case _ => UnknownType
+ }
+ case Rem => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => UIntType(MIN(w1, w2))
+ case (_: UIntType, _: SIntType) => UIntType(MIN(w1, w2))
+ case (_: SIntType, _: UIntType) => SIntType(MIN(w1, PLUS(w2, IntWidth(1))))
+ case (_: SIntType, _: SIntType) => SIntType(MIN(w1, w2))
+ case _ => UnknownType
+ }
+ case Lt => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => Utils.BoolType
+ case (_: SIntType, _: UIntType) => Utils.BoolType
+ case (_: UIntType, _: SIntType) => Utils.BoolType
+ case (_: SIntType, _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Leq => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => Utils.BoolType
+ case (_: SIntType, _: UIntType) => Utils.BoolType
+ case (_: UIntType, _: SIntType) => Utils.BoolType
+ case (_: SIntType, _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Gt => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => Utils.BoolType
+ case (_: SIntType, _: UIntType) => Utils.BoolType
+ case (_: UIntType, _: SIntType) => Utils.BoolType
+ case (_: SIntType, _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Geq => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => Utils.BoolType
+ case (_: SIntType, _: UIntType) => Utils.BoolType
+ case (_: UIntType, _: SIntType) => Utils.BoolType
+ case (_: SIntType, _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Eq => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => Utils.BoolType
+ case (_: SIntType, _: UIntType) => Utils.BoolType
+ case (_: UIntType, _: SIntType) => Utils.BoolType
+ case (_: SIntType, _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Neq => (t1, t2) match {
+ case (_: UIntType, _: UIntType) => Utils.BoolType
+ case (_: SIntType, _: UIntType) => Utils.BoolType
+ case (_: UIntType, _: SIntType) => Utils.BoolType
+ case (_: SIntType, _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Pad => t1 match {
+ case _: UIntType => UIntType(MAX(w1, c1))
+ case _: SIntType => SIntType(MAX(w1, c1))
+ case _ => UnknownType
+ }
+ case AsUInt => t1 match {
+ case _: UIntType => UIntType(w1)
+ case _: SIntType => UIntType(w1)
+ case ClockType => UIntType(IntWidth(1))
+ case _ => UnknownType
+ }
+ case AsSInt => t1 match {
+ case _: UIntType => SIntType(w1)
+ case _: SIntType => SIntType(w1)
+ case ClockType => SIntType(IntWidth(1))
+ case _ => UnknownType
+ }
+ case AsClock => t1 match {
+ case _: UIntType => ClockType
+ case _: SIntType => ClockType
+ case ClockType => ClockType
+ case _ => UnknownType
+ }
+ case Shl => t1 match {
+ case _: UIntType => UIntType(PLUS(w1,c1))
+ case _: SIntType => SIntType(PLUS(w1,c1))
+ case _ => UnknownType
+ }
+ case Shr => t1 match {
+ case _: UIntType => UIntType(MAX(MINUS(w1,c1),IntWidth(1)))
+ case _: SIntType => SIntType(MAX(MINUS(w1,c1),IntWidth(1)))
+ case _ => UnknownType
+ }
+ case Dshl => t1 match {
+ case _: UIntType => UIntType(PLUS(w1,POW(w2)))
+ case _: SIntType => SIntType(PLUS(w1,POW(w2)))
+ case _ => UnknownType
+ }
+ case Dshr => t1 match {
+ case _: UIntType => UIntType(w1)
+ case _: SIntType => SIntType(w1)
+ case _ => UnknownType
+ }
+ case Cvt => t1 match {
+ case _: UIntType => SIntType(PLUS(w1,IntWidth(1)))
+ case _: SIntType => SIntType(w1)
+ case _ => UnknownType
+ }
+ case Neg => t1 match {
+ case _: UIntType => SIntType(PLUS(w1,IntWidth(1)))
+ case _: SIntType => SIntType(PLUS(w1,IntWidth(1)))
+ case _ => UnknownType
+ }
+ case Not => t1 match {
+ case _: UIntType => UIntType(w1)
+ case _: SIntType => UIntType(w1)
+ case _ => UnknownType
+ }
+ case And => (t1, t2) match {
+ case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2))
+ case _ => UnknownType
+ }
+ case Or => (t1, t2) match {
+ case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2))
+ case _ => UnknownType
+ }
+ case Xor => (t1, t2) match {
+ case (_: SIntType | _: UIntType, _: SIntType | _: UIntType) => UIntType(MAX(w1, w2))
+ case _ => UnknownType
+ }
+ case Andr => t1 match {
+ case (_: UIntType | _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Orr => t1 match {
+ case (_: UIntType | _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Xorr => t1 match {
+ case (_: UIntType | _: SIntType) => Utils.BoolType
+ case _ => UnknownType
+ }
+ case Cat => (t1, t2) match {
+ case (_: UIntType | _: SIntType, _: UIntType | _: SIntType) => UIntType(PLUS(w1, w2))
+ case (t1, t2) => UnknownType
+ }
+ case Bits => t1 match {
+ case (_: UIntType | _: SIntType) => UIntType(PLUS(MINUS(c1,c2),IntWidth(1)))
+ case _ => UnknownType
+ }
+ case Head => t1 match {
+ case (_: UIntType | _: SIntType) => UIntType(c1)
+ case _ => UnknownType
+ }
+ case Tail => t1 match {
+ case (_: UIntType | _: SIntType) => UIntType(MINUS(w1,c1))
+ case _ => UnknownType
+ }
+ }))
+ }
}
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala
index 9404e5e2..ea8ff4b7 100644
--- a/src/main/scala/firrtl/Utils.scala
+++ b/src/main/scala/firrtl/Utils.scala
@@ -239,10 +239,11 @@ object Utils extends LazyLogging {
}
////=====================================
- def widthBANG (t:Type) : Width = t match {
+ def width_BANG(t: Type) : Width = t match {
case g: GroundType => g.width
case t => error("No width!")
}
+ def width_BANG(e: Expression) : Width = width_BANG(e.tpe)
def long_BANG(t: Type): Long = t match {
case (g: GroundType) => g.width match {
case IntWidth(x) => x.toLong
diff --git a/src/main/scala/firrtl/WIR.scala b/src/main/scala/firrtl/WIR.scala
index eddd723b..9583175e 100644
--- a/src/main/scala/firrtl/WIR.scala
+++ b/src/main/scala/firrtl/WIR.scala
@@ -88,33 +88,29 @@ case object Dshlw extends PrimOp { override def toString = "dshlw" }
case object Shlw extends PrimOp { override def toString = "shlw" }
object WrappedExpression {
- def apply (e:Expression) = new WrappedExpression(e)
- def we (e:Expression) = new WrappedExpression(e)
- def weq (e1:Expression,e2:Expression) = we(e1) == we(e2)
-}
-class WrappedExpression (val e1:Expression) {
- override def equals (we:Any) = {
- we match {
- case (we:WrappedExpression) => {
- (e1,we.e1) match {
- case (e1:UIntLiteral,e2:UIntLiteral) => if (e1.value == e2.value) eqw(e1.width,e2.width) else false
- case (e1:SIntLiteral,e2:SIntLiteral) => if (e1.value == e2.value) eqw(e1.width,e2.width) else false
- case (e1:WRef,e2:WRef) => e1.name equals e2.name
- case (e1:WSubField,e2:WSubField) => (e1.name equals e2.name) && weq(e1.exp,e2.exp)
- case (e1:WSubIndex,e2:WSubIndex) => (e1.value == e2.value) && weq(e1.exp,e2.exp)
- case (e1:WSubAccess,e2:WSubAccess) => weq(e1.index,e2.index) && weq(e1.exp,e2.exp)
- case (e1:WVoid,e2:WVoid) => true
- case (e1:WInvalid,e2:WInvalid) => true
- case (e1:DoPrim,e2:DoPrim) => e1.op == e2.op &&
- ((e1.consts zip e2.consts) forall {case (x, y) => x == y}) &&
- ((e1.args zip e2.args) forall {case (x, y) => weq(x, y)})
- case (e1:Mux,e2:Mux) => weq(e1.cond,e2.cond) && weq(e1.tval,e2.tval) && weq(e1.fval,e2.fval)
- case (e1:ValidIf,e2:ValidIf) => weq(e1.cond,e2.cond) && weq(e1.value,e2.value)
- case (e1,e2) => false
- }
- }
- case _ => false
- }
+ def apply(e: Expression) = new WrappedExpression(e)
+ def we(e: Expression) = new WrappedExpression(e)
+ def weq(e1: Expression, e2: Expression) = we(e1) == we(e2)
+}
+class WrappedExpression (val e1: Expression) {
+ override def equals (we: Any) = we match {
+ case (we:WrappedExpression) => (e1,we.e1) match {
+ case (e1: UIntLiteral, e2: UIntLiteral) => e1.value == e2.value && eqw(e1.width, e2.width)
+ case (e1: SIntLiteral, e2: SIntLiteral) => e1.value == e2.value && eqw(e1.width, e2.width)
+ case (e1: WRef, e2: WRef) => e1.name equals e2.name
+ case (e1: WSubField, e2: WSubField) => (e1.name equals e2.name) && weq(e1.exp,e2.exp)
+ case (e1: WSubIndex, e2: WSubIndex) => (e1.value == e2.value) && weq(e1.exp,e2.exp)
+ case (e1: WSubAccess, e2: WSubAccess) => weq(e1.index,e2.index) && weq(e1.exp,e2.exp)
+ case (e1: WVoid, e2: WVoid) => true
+ case (e1: WInvalid, e2: WInvalid) => true
+ case (e1: DoPrim, e2: DoPrim) => e1.op == e2.op &&
+ ((e1.consts zip e2.consts) forall {case (x, y) => x == y}) &&
+ ((e1.args zip e2.args) forall {case (x, y) => weq(x, y)})
+ case (e1: Mux, e2: Mux) => weq(e1.cond,e2.cond) && weq(e1.tval,e2.tval) && weq(e1.fval,e2.fval)
+ case (e1: ValidIf, e2: ValidIf) => weq(e1.cond,e2.cond) && weq(e1.value,e2.value)
+ case (e1, e2) => false
+ }
+ case _ => false
}
override def hashCode = e1.serialize.hashCode
override def toString = e1.serialize
@@ -141,107 +137,79 @@ case class ExpWidth(arg1: Width) extends Width {
}
object WrappedType {
- def apply (t:Type) = new WrappedType(t)
- def wt (t:Type) = apply(t)
-}
-class WrappedType (val t:Type) {
- def wt (tx:Type) = new WrappedType(tx)
- override def equals (o:Any) : Boolean = {
- o match {
- case (t2:WrappedType) => {
- (t,t2.t) match {
- case (t1:UIntType,t2:UIntType) => true
- case (t1:SIntType,t2:SIntType) => true
- case (ClockType, ClockType) => true
- case (t1:VectorType,t2:VectorType) =>
- t1.size == t2.size && wt(t1.tpe) == wt(t2.tpe)
- case (t1:BundleType,t2:BundleType) =>
- t1.fields.size == t2.fields.size && (
- (t1.fields zip t2.fields) forall {case (f1, f2) =>
- f1.flip == f2.flip && f1.name == f2.name && wt(f1.tpe) == wt(f2.tpe)
- })
- case (t1,t2) => false
- }
- }
- case _ => false
- }
- }
+ def apply (t:Type) = new WrappedType(t)
+ def wt (t:Type) = apply(t)
+}
+class WrappedType(val t: Type) {
+ def wt(tx: Type) = new WrappedType(tx)
+ override def equals(o:Any): Boolean = o match {
+ case (t2: WrappedType) => (t, t2.t) match {
+ case (_: UIntType, _: UIntType) => true
+ case (_: SIntType, _: SIntType) => true
+ case (ClockType, ClockType) => true
+ case (t1: VectorType, t2: VectorType) =>
+ t1.size == t2.size && wt(t1.tpe) == wt(t2.tpe)
+ case (t1:BundleType,t2:BundleType) =>
+ t1.fields.size == t2.fields.size && (
+ (t1.fields zip t2.fields) forall {case (f1, f2) =>
+ f1.flip == f2.flip && f1.name == f2.name
+ }) && ((t1.fields zip t2.fields) forall {case (f1, f2) =>
+ wt(f1.tpe) == wt(f2.tpe)
+ })
+ case _ => false
+ }
+ case _ => false
+ }
}
object WrappedWidth {
- def eqw (w1:Width,w2:Width) : Boolean = {
- (new WrappedWidth(w1)) == (new WrappedWidth(w2))
- }
+ def eqw(w1: Width, w2: Width): Boolean = new WrappedWidth(w1) == new WrappedWidth(w2)
}
-class WrappedWidth (val w:Width) {
- override def toString = {
- w match {
- case (w:VarWidth) => w.name
- case (w:MaxWidth) => "max(" + w.args.map(_.toString).reduce(_ + _) + ")"
- case (w:MinWidth) => "min(" + w.args.map(_.toString).reduce(_ + _) + ")"
- case (w:PlusWidth) => "(" + w.arg1 + " + " + w.arg2 + ")"
- case (w:MinusWidth) => "(" + w.arg1 + " - " + w.arg2 + ")"
- case (w:ExpWidth) => "exp(" + w.arg1 + ")"
- case (w:IntWidth) => w.width.toString
- case UnknownWidth => "?"
- }
- }
- def ww (w:Width) : WrappedWidth = new WrappedWidth(w)
- override def equals (o:Any) : Boolean = {
- o match {
- case (w2:WrappedWidth) => {
- (w,w2.w) match {
- case (w1:VarWidth,w2:VarWidth) => w1.name.equals(w2.name)
- case (w1:MaxWidth,w2:MaxWidth) => {
- var ret = true
- if (w1.args.size != w2.args.size) ret = false
- else {
- for (a1 <- w1.args) {
- var found = false
- for (a2 <- w2.args) { if (eqw(a1,a2)) found = true }
- if (found == false) ret = false
- }
- }
- ret
- }
- case (w1:MinWidth,w2:MinWidth) => {
- var ret = true
- if (w1.args.size != w2.args.size) ret = false
- else {
- for (a1 <- w1.args) {
- var found = false
- for (a2 <- w2.args) { if (eqw(a1,a2)) found = true }
- if (found == false) ret = false
- }
- }
- ret
- }
- case (w1:IntWidth,w2:IntWidth) => w1.width == w2.width
- case (w1:PlusWidth,w2:PlusWidth) =>
- (ww(w1.arg1) == ww(w2.arg1) && ww(w1.arg2) == ww(w2.arg2)) || (ww(w1.arg1) == ww(w2.arg2) && ww(w1.arg2) == ww(w2.arg1))
- case (w1:MinusWidth,w2:MinusWidth) =>
- (ww(w1.arg1) == ww(w2.arg1) && ww(w1.arg2) == ww(w2.arg2)) || (ww(w1.arg1) == ww(w2.arg2) && ww(w1.arg2) == ww(w2.arg1))
- case (w1:ExpWidth,w2:ExpWidth) => ww(w1.arg1) == ww(w2.arg1)
- case (UnknownWidth, UnknownWidth) => true
- case (w1,w2) => false
- }
- }
- case _ => false
- }
- }
+class WrappedWidth (val w: Width) {
+ def ww(w: Width): WrappedWidth = new WrappedWidth(w)
+ override def toString = w match {
+ case (w: VarWidth) => w.name
+ case (w: MaxWidth) => s"max(${w.args.mkString})"
+ case (w: MinWidth) => s"min(${w.args.mkString})"
+ case (w: PlusWidth) => s"(${w.arg1} + ${w.arg2})"
+ case (w: MinusWidth) => s"(${w.arg1} -${w.arg2})"
+ case (w: ExpWidth) => s"exp(${w.arg1})"
+ case (w: IntWidth) => w.width.toString
+ case UnknownWidth => "?"
+ }
+ override def equals(o: Any): Boolean = o match {
+ case (w2: WrappedWidth) => (w, w2.w) match {
+ case (w1: VarWidth, w2: VarWidth) => w1.name.equals(w2.name)
+ case (w1: MaxWidth, w2: MaxWidth) => w1.args.size == w2.args.size &&
+ (w1.args forall (a1 => w2.args exists (a2 => eqw(a1, a2))))
+ case (w1: MinWidth, w2: MinWidth) => w1.args.size == w2.args.size &&
+ (w1.args forall (a1 => w2.args exists (a2 => eqw(a1, a2))))
+ case (w1: IntWidth, w2: IntWidth) => w1.width == w2.width
+ case (w1: PlusWidth, w2: PlusWidth) =>
+ (ww(w1.arg1) == ww(w2.arg1) && ww(w1.arg2) == ww(w2.arg2)) ||
+ (ww(w1.arg1) == ww(w2.arg2) && ww(w1.arg2) == ww(w2.arg1))
+ case (w1: MinusWidth,w2: MinusWidth) =>
+ (ww(w1.arg1) == ww(w2.arg1) && ww(w1.arg2) == ww(w2.arg2)) ||
+ (ww(w1.arg1) == ww(w2.arg2) && ww(w1.arg2) == ww(w2.arg1))
+ case (w1: ExpWidth, w2: ExpWidth) => ww(w1.arg1) == ww(w2.arg1)
+ case (UnknownWidth, UnknownWidth) => true
+ case _ => false
+ }
+ case _ => false
+ }
}
trait Constraint
-class WGeq(val loc:Width,val exp:Width) extends Constraint {
- override def toString = {
- val wloc = new WrappedWidth(loc)
- val wexp = new WrappedWidth(exp)
- wloc.toString + " >= " + wexp.toString
- }
+class WGeq(val loc: Width, val exp: Width) extends Constraint {
+ override def toString = {
+ val wloc = new WrappedWidth(loc)
+ val wexp = new WrappedWidth(exp)
+ wloc.toString + " >= " + wexp.toString
+ }
}
object WGeq {
- def apply (loc:Width,exp:Width) = new WGeq(loc,exp)
+ def apply(loc: Width, exp: Width) = new WGeq(loc, exp)
}
abstract class MPortDir extends FirrtlNode
diff --git a/src/main/scala/firrtl/passes/ConstProp.scala b/src/main/scala/firrtl/passes/ConstProp.scala
index 2e8b53f3..a4d9078c 100644
--- a/src/main/scala/firrtl/passes/ConstProp.scala
+++ b/src/main/scala/firrtl/passes/ConstProp.scala
@@ -234,7 +234,7 @@ object ConstProp extends Pass {
val hi = e.consts(0).toInt
val lo = e.consts(1).toInt
require(hi >= lo)
- UIntLiteral((lit.value >> lo) & ((BigInt(1) << (hi - lo + 1)) - 1), widthBANG(e.tpe))
+ UIntLiteral((lit.value >> lo) & ((BigInt(1) << (hi - lo + 1)) - 1), width_BANG(e.tpe))
}
case x if long_BANG(e.tpe) == long_BANG(x.tpe) => x.tpe match {
case t: UIntType => x
diff --git a/src/main/scala/firrtl/passes/Inline.scala b/src/main/scala/firrtl/passes/Inline.scala
index a8fda1bf..c4529bd9 100644
--- a/src/main/scala/firrtl/passes/Inline.scala
+++ b/src/main/scala/firrtl/passes/Inline.scala
@@ -4,11 +4,9 @@ package passes
// Datastructures
import scala.collection.mutable
-import firrtl.Mappers.{ExpMap,StmtMap}
import firrtl.ir._
-import firrtl.passes.{PassException,PassExceptions}
-import Annotations.{Loose, Unstable, Annotation, TransID, Named, ModuleName, ComponentName, CircuitName, AnnotationMap}
-
+import firrtl.Annotations._
+import firrtl.Mappers.{ExpMap, StmtMap}
// Tags an annotation to be consumed by this pass
case class InlineAnnotation(target: Named, tID: TransID) extends Annotation with Loose with Unstable {
diff --git a/src/main/scala/firrtl/passes/RemoveEmpty.scala b/src/main/scala/firrtl/passes/RemoveEmpty.scala
index e765d1f4..7ba2ef09 100644
--- a/src/main/scala/firrtl/passes/RemoveEmpty.scala
+++ b/src/main/scala/firrtl/passes/RemoveEmpty.scala
@@ -15,5 +15,3 @@ object RemoveEmpty extends Pass {
}
def run(c: Circuit): Circuit = Circuit(c.info, c.modules.map(onModule _), c.main)
}
-
-// vim: set ts=4 sw=4 et:
diff --git a/src/main/scala/firrtl/passes/ReplaceSubAccess.scala b/src/main/scala/firrtl/passes/ReplaceSubAccess.scala
index 8e911a96..ce95be13 100644
--- a/src/main/scala/firrtl/passes/ReplaceSubAccess.scala
+++ b/src/main/scala/firrtl/passes/ReplaceSubAccess.scala
@@ -22,11 +22,6 @@ object ReplaceAccesses extends Pass {
case e => e map onExp
}
- val newModules = c.modules map {
- case m: ExtModule => m
- case Module(i, n, ps, b) => Module(i, n, ps, onStmt(b))
- }
-
- Circuit(c.info, newModules, c.main)
+ c copy (modules = c.modules map (_ map onStmt))
}
}