diff options
| author | Donggyu Kim | 2016-09-02 17:28:39 -0700 |
|---|---|---|
| committer | Donggyu Kim | 2016-09-13 13:36:38 -0700 |
| commit | 4cb46ca17da26c7ccc0b66a6be489a49fb2e9173 (patch) | |
| tree | a283ed9716f10cee128a9a782dada088bba97d5f /src/main/scala/firrtl/passes | |
| parent | 590c3f2cd959c3c125c6511287294aec8409b57b (diff) | |
remove Utils.{width_BANG, long_BANG}
Diffstat (limited to 'src/main/scala/firrtl/passes')
| -rw-r--r-- | src/main/scala/firrtl/passes/Checks.scala | 12 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/ConstProp.scala | 18 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/InferWidths.scala | 20 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/MemUtils.scala | 8 | ||||
| -rw-r--r-- | src/main/scala/firrtl/passes/PadWidths.scala | 3 |
5 files changed, 34 insertions, 27 deletions
diff --git a/src/main/scala/firrtl/passes/Checks.scala b/src/main/scala/firrtl/passes/Checks.scala index bba3efe7..16b16ff7 100644 --- a/src/main/scala/firrtl/passes/Checks.scala +++ b/src/main/scala/firrtl/passes/Checks.scala @@ -572,12 +572,12 @@ object CheckWidths extends Pass { errors append new WidthTooSmall(info, mname, e.value) case _ => } - case DoPrim(Bits, Seq(a), Seq(hi, lo), _) if long_BANG(a.tpe) <= hi => - errors append new BitsWidthException(info, mname, hi, long_BANG(a.tpe)) - case DoPrim(Head, Seq(a), Seq(n), _) if long_BANG(a.tpe) < n => - errors append new HeadWidthException(info, mname, n, long_BANG(a.tpe)) - case DoPrim(Tail, Seq(a), Seq(n), _) if long_BANG(a.tpe) <= n => - errors append new TailWidthException(info, mname, n, long_BANG(a.tpe)) + case DoPrim(Bits, Seq(a), Seq(hi, lo), _) if bitWidth(a.tpe) <= hi => + errors append new BitsWidthException(info, mname, hi, bitWidth(a.tpe)) + case DoPrim(Head, Seq(a), Seq(n), _) if bitWidth(a.tpe) < n => + errors append new HeadWidthException(info, mname, n, bitWidth(a.tpe)) + case DoPrim(Tail, Seq(a), Seq(n), _) if bitWidth(a.tpe) <= n => + errors append new TailWidthException(info, mname, n, bitWidth(a.tpe)) case _ => } e map check_width_w(info, mname) map check_width_e(info, mname) diff --git a/src/main/scala/firrtl/passes/ConstProp.scala b/src/main/scala/firrtl/passes/ConstProp.scala index a4d9078c..789f2e03 100644 --- a/src/main/scala/firrtl/passes/ConstProp.scala +++ b/src/main/scala/firrtl/passes/ConstProp.scala @@ -38,7 +38,7 @@ import annotation.tailrec object ConstProp extends Pass { def name = "Constant Propagation" - private def pad(e: Expression, t: Type) = (long_BANG(e.tpe), long_BANG(t)) match { + private def pad(e: Expression, t: Type) = (bitWidth(e.tpe), bitWidth(t)) match { case (we, wt) if we < wt => DoPrim(Pad, Seq(e), Seq(wt), t) case (we, wt) if we == wt => e } @@ -62,7 +62,7 @@ object ConstProp extends Pass { def simplify(e: Expression, lhs: Literal, rhs: Expression) = lhs match { case UIntLiteral(v, w) if v == 0 => UIntLiteral(0, w) case SIntLiteral(v, w) if v == 0 => UIntLiteral(0, w) - case UIntLiteral(v, IntWidth(w)) if v == (BigInt(1) << long_BANG(rhs.tpe).toInt) - 1 => rhs + case UIntLiteral(v, IntWidth(w)) if v == (BigInt(1) << bitWidth(rhs.tpe).toInt) - 1 => rhs case _ => e } } @@ -72,7 +72,7 @@ object ConstProp extends Pass { def simplify(e: Expression, lhs: Literal, rhs: Expression) = lhs match { case UIntLiteral(v, _) if v == 0 => rhs case SIntLiteral(v, _) if v == 0 => asUInt(rhs, e.tpe) - case UIntLiteral(v, IntWidth(w)) if v == (BigInt(1) << long_BANG(rhs.tpe).toInt) - 1 => lhs + case UIntLiteral(v, IntWidth(w)) if v == (BigInt(1) << bitWidth(rhs.tpe).toInt) - 1 => lhs case _ => e } } @@ -89,7 +89,7 @@ object ConstProp extends Pass { object FoldEqual extends FoldLogicalOp { def fold(c1: Literal, c2: Literal) = UIntLiteral(if (c1.value == c2.value) 1 else 0, IntWidth(1)) def simplify(e: Expression, lhs: Literal, rhs: Expression) = lhs match { - case UIntLiteral(v, IntWidth(w)) if v == 1 && w == 1 && long_BANG(rhs.tpe) == 1 => rhs + case UIntLiteral(v, IntWidth(w)) if v == 1 && w == 1 && bitWidth(rhs.tpe) == 1 => rhs case _ => e } } @@ -97,7 +97,7 @@ object ConstProp extends Pass { object FoldNotEqual extends FoldLogicalOp { def fold(c1: Literal, c2: Literal) = UIntLiteral(if (c1.value != c2.value) 1 else 0, IntWidth(1)) def simplify(e: Expression, lhs: Literal, rhs: Expression) = lhs match { - case UIntLiteral(v, IntWidth(w)) if v == 0 && w == 1 && long_BANG(rhs.tpe) == 1 => rhs + case UIntLiteral(v, IntWidth(w)) if v == 0 && w == 1 && bitWidth(rhs.tpe) == 1 => rhs case _ => e } } @@ -226,7 +226,7 @@ object ConstProp extends Pass { case Pad => e.args(0) match { case UIntLiteral(v, _) => UIntLiteral(v, IntWidth(e.consts(0))) case SIntLiteral(v, _) => SIntLiteral(v, IntWidth(e.consts(0))) - case _ if long_BANG(e.args(0).tpe) == e.consts(0) => e.args(0) + case _ if bitWidth(e.args(0).tpe) == e.consts(0) => e.args(0) case _ => e } case Bits => e.args(0) match { @@ -234,9 +234,9 @@ 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), width_BANG(e.tpe)) + UIntLiteral((lit.value >> lo) & ((BigInt(1) << (hi - lo + 1)) - 1), getWidth(e.tpe)) } - case x if long_BANG(e.tpe) == long_BANG(x.tpe) => x.tpe match { + case x if bitWidth(e.tpe) == bitWidth(x.tpe) => x.tpe match { case t: UIntType => x case _ => asUInt(x, e.tpe) } @@ -253,7 +253,7 @@ object ConstProp extends Pass { private def constPropMux(m: Mux): Expression = (m.tval, m.fval) match { case _ if m.tval == m.fval => m.tval case (t: UIntLiteral, f: UIntLiteral) => - if (t.value == 1 && f.value == 0 && long_BANG(m.tpe) == 1) m.cond + if (t.value == 1 && f.value == 0 && bitWidth(m.tpe) == 1) m.cond else constPropMuxCond(m) case _ => constPropMuxCond(m) } diff --git a/src/main/scala/firrtl/passes/InferWidths.scala b/src/main/scala/firrtl/passes/InferWidths.scala index 5a81c268..6b2ff6ed 100644 --- a/src/main/scala/firrtl/passes/InferWidths.scala +++ b/src/main/scala/firrtl/passes/InferWidths.scala @@ -214,8 +214,8 @@ object InferWidths extends Pass { def get_constraints_e(e: Expression): Expression = { e match { case (e: Mux) => v ++= Seq( - WGeq(width_BANG(e.cond), IntWidth(1)), - WGeq(IntWidth(1), width_BANG(e.cond)) + WGeq(getWidth(e.cond), IntWidth(1)), + WGeq(IntWidth(1), getWidth(e.cond)) ) case _ => } @@ -230,8 +230,8 @@ object InferWidths extends Pass { val exps = create_exps(s.expr) v ++= ((locs zip exps).zipWithIndex map {case ((locx, expx), i) => get_flip(s.loc.tpe, i, Default) match { - case Default => WGeq(width_BANG(locx), width_BANG(expx)) - case Flip => WGeq(width_BANG(expx), width_BANG(locx)) + case Default => WGeq(getWidth(locx), getWidth(expx)) + case Flip => WGeq(getWidth(expx), getWidth(locx)) } }) case (s: PartialConnect) => @@ -242,17 +242,17 @@ object InferWidths extends Pass { val locx = locs(x) val expx = exps(y) get_flip(s.loc.tpe, x, Default) match { - case Default => WGeq(width_BANG(locx), width_BANG(expx)) - case Flip => WGeq(width_BANG(expx), width_BANG(locx)) + case Default => WGeq(getWidth(locx), getWidth(expx)) + case Flip => WGeq(getWidth(expx), getWidth(locx)) } }) case (s:DefRegister) => v ++= (Seq( - WGeq(width_BANG(s.reset), IntWidth(1)), - WGeq(IntWidth(1), width_BANG(s.reset)) + WGeq(getWidth(s.reset), IntWidth(1)), + WGeq(IntWidth(1), getWidth(s.reset)) ) ++ get_constraints_t(s.tpe, s.init.tpe, Default)) case (s:Conditionally) => v ++= Seq( - WGeq(width_BANG(s.pred), IntWidth(1)), - WGeq(IntWidth(1), width_BANG(s.pred)) + WGeq(getWidth(s.pred), IntWidth(1)), + WGeq(IntWidth(1), getWidth(s.pred)) ) case _ => } diff --git a/src/main/scala/firrtl/passes/MemUtils.scala b/src/main/scala/firrtl/passes/MemUtils.scala index 798b02da..87033176 100644 --- a/src/main/scala/firrtl/passes/MemUtils.scala +++ b/src/main/scala/firrtl/passes/MemUtils.scala @@ -82,6 +82,14 @@ object toBitMask { } } +object getWidth { + def apply(t: Type): Width = t match { + case t: GroundType => t.width + case _ => error("No width!") + } + def apply(e: Expression): Width = apply(e.tpe) +} + object bitWidth { def apply(dt: Type): BigInt = widthOf(dt) private def widthOf(dt: Type): BigInt = dt match { diff --git a/src/main/scala/firrtl/passes/PadWidths.scala b/src/main/scala/firrtl/passes/PadWidths.scala index 1a134d11..bef9ac33 100644 --- a/src/main/scala/firrtl/passes/PadWidths.scala +++ b/src/main/scala/firrtl/passes/PadWidths.scala @@ -4,12 +4,11 @@ package passes import firrtl.ir._ import firrtl.PrimOps._ import firrtl.Mappers._ -import firrtl.Utils.long_BANG // Makes all implicit width extensions and truncations explicit object PadWidths extends Pass { def name = "Pad Widths" - private def width(t: Type): Int = long_BANG(t).toInt + private def width(t: Type): Int = bitWidth(t).toInt private def width(e: Expression): Int = width(e.tpe) // Returns an expression with the correct integer width private def fixup(i: Int)(e: Expression) = { |
