aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorazidar2016-07-25 17:38:31 -0700
committerazidar2016-07-25 17:38:31 -0700
commita6c8493e907dedcbb289f6d4f6323cc26fb1edc0 (patch)
tree047c3fe89bfae2fa7fc6cc1bd1bed981412015b8 /src
parent0441a6df1eafd5db99c5cbcc0a07c5a6cb37f975 (diff)
Changed InferTypes to update types if UnknownType or has an UnknownWidth
Removed InferWidths after ExpandWhens
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/LoweringCompilers.scala5
-rw-r--r--src/main/scala/firrtl/PrimOps.scala549
-rw-r--r--src/main/scala/firrtl/Utils.scala6
3 files changed, 284 insertions, 276 deletions
diff --git a/src/main/scala/firrtl/LoweringCompilers.scala b/src/main/scala/firrtl/LoweringCompilers.scala
index 29355e1a..036156dc 100644
--- a/src/main/scala/firrtl/LoweringCompilers.scala
+++ b/src/main/scala/firrtl/LoweringCompilers.scala
@@ -109,8 +109,9 @@ class HighFirrtlToMiddleFirrtl () extends Transform with SimpleRun {
passes.CheckInitialization,
passes.ResolveKinds,
passes.InferTypes,
- passes.ResolveGenders,
- passes.InferWidths)
+ passes.ResolveGenders)
+ //passes.InferWidths,
+ //passes.CheckWidths)
def execute (circuit: Circuit, annotations: Seq[CircuitAnnotation]): TransformResult =
run(circuit, passSeq)
}
diff --git a/src/main/scala/firrtl/PrimOps.scala b/src/main/scala/firrtl/PrimOps.scala
index 7e8d77db..7d7524f6 100644
--- a/src/main/scala/firrtl/PrimOps.scala
+++ b/src/main/scala/firrtl/PrimOps.scala
@@ -127,279 +127,282 @@ object PrimOps extends LazyLogging {
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()),Utils.ONE))
- case (t1:UIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
- case (t1:SIntType, t2:UIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
- case (t1:SIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
- 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()),Utils.ONE))
- case (t1:UIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
- case (t1:SIntType, t2:UIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
- case (t1:SIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
- 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(),Utils.ONE))
- case (t1:SIntType, t2:UIntType) => SIntType(w1())
- case (t1:SIntType, t2:SIntType) => SIntType(PLUS(w1(),Utils.ONE))
- 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(),Utils.ONE)))
- 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(Utils.ONE)
- 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(Utils.ONE)
- 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()),Utils.ONE))
- case (t1:SIntType) => SIntType(MAX(MINUS(w1(),c1()),Utils.ONE))
- 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(),Utils.ONE))
- 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(),Utils.ONE))
- case (t1:SIntType) => SIntType(PLUS(w1(),Utils.ONE))
- 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()),Utils.ONE))
- 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)
- }
-
+ e.tpe match {
+ case UIntType(IntWidth(w)) => e
+ case SIntType(IntWidth(w)) => e
+ case _ => o match {
+ case Add => {
+ val t = (t1(),t2()) match {
+ case (t1:UIntType, t2:UIntType) => UIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
+ case (t1:UIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
+ case (t1:SIntType, t2:UIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
+ case (t1:SIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
+ 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()),Utils.ONE))
+ case (t1:UIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
+ case (t1:SIntType, t2:UIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
+ case (t1:SIntType, t2:SIntType) => SIntType(PLUS(MAX(w1(),w2()),Utils.ONE))
+ 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(),Utils.ONE))
+ case (t1:SIntType, t2:UIntType) => SIntType(w1())
+ case (t1:SIntType, t2:SIntType) => SIntType(PLUS(w1(),Utils.ONE))
+ 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(),Utils.ONE)))
+ 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(Utils.ONE)
+ 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(Utils.ONE)
+ 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()),Utils.ONE))
+ case (t1:SIntType) => SIntType(MAX(MINUS(w1(),c1()),Utils.ONE))
+ 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(),Utils.ONE))
+ 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(),Utils.ONE))
+ case (t1:SIntType) => SIntType(PLUS(w1(),Utils.ONE))
+ 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()),Utils.ONE))
+ 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)
+ }
+ }
}
}
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala
index fec25cf1..76c8e61e 100644
--- a/src/main/scala/firrtl/Utils.scala
+++ b/src/main/scala/firrtl/Utils.scala
@@ -284,7 +284,11 @@ object Utils extends LazyLogging {
}
def long_BANG (t:Type) : Long = {
(t) match {
- case g: GroundType => g.width.as[IntWidth].get.width.toLong
+ case g: GroundType =>
+ g.width match {
+ case IntWidth(x) => x.toLong
+ case _ => throw new FIRRTLException(s"Expecting IntWidth, got: ${g.width}")
+ }
case (t:BundleType) => {
var w = 0
for (f <- t.fields) { w = w + long_BANG(f.tpe).toInt }