aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/passes/ConstProp.scala
diff options
context:
space:
mode:
authorJack2016-05-10 01:23:10 -0700
committerJack Koenig2016-06-10 16:33:08 -0700
commit58d9f1d50c07d999776c76259fadbdfd52c564fc (patch)
tree773e976333a6167cf3e378f36fdebac34268e93c /src/main/scala/firrtl/passes/ConstProp.scala
parentc1504e2179e509632fa8d9ab44d87191b46cf851 (diff)
API Cleanup - PrimOp & PrimOps
Add simple documentation trait PrimOp -> abstract class PrimOp Move PrimOp case objects to object PrimOps Rename PrimOp case objects to match concrete syntax Overrwrite toString for more canonical serialization Update some PrimOps utility functions
Diffstat (limited to 'src/main/scala/firrtl/passes/ConstProp.scala')
-rw-r--r--src/main/scala/firrtl/passes/ConstProp.scala49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/main/scala/firrtl/passes/ConstProp.scala b/src/main/scala/firrtl/passes/ConstProp.scala
index e562f71d..f8fd5654 100644
--- a/src/main/scala/firrtl/passes/ConstProp.scala
+++ b/src/main/scala/firrtl/passes/ConstProp.scala
@@ -30,6 +30,7 @@ package firrtl.passes
import firrtl._
import firrtl.Utils._
import firrtl.Mappers._
+import firrtl.PrimOps._
import annotation.tailrec
@@ -137,10 +138,10 @@ object ConstProp extends Pass {
case _ => false
}
x match {
- case DoPrim(LESS_OP, Seq(a,b),_,_) if(isUInt(a) && isZero(b)) => zero
- case DoPrim(LESS_EQ_OP, Seq(a,b),_,_) if(isZero(a) && isUInt(b)) => one
- case DoPrim(GREATER_OP, Seq(a,b),_,_) if(isZero(a) && isUInt(b)) => zero
- case DoPrim(GREATER_EQ_OP,Seq(a,b),_,_) if(isUInt(a) && isZero(b)) => one
+ case DoPrim(Lt, Seq(a,b),_,_) if(isUInt(a) && isZero(b)) => zero
+ case DoPrim(Leq, Seq(a,b),_,_) if(isZero(a) && isUInt(b)) => one
+ case DoPrim(Gt, Seq(a,b),_,_) if(isZero(a) && isUInt(b)) => zero
+ case DoPrim(Geq, Seq(a,b),_,_) if(isUInt(a) && isZero(b)) => one
case e => e
}
}
@@ -179,15 +180,15 @@ object ConstProp extends Pass {
def r1 = range(e.args(1))
e.op match {
// Always true
- case LESS_OP if (r0 < r1) => one
- case LESS_EQ_OP if (r0 <= r1) => one
- case GREATER_OP if (r0 > r1) => one
- case GREATER_EQ_OP if (r0 >= r1) => one
+ case Lt if (r0 < r1) => one
+ case Leq if (r0 <= r1) => one
+ case Gt if (r0 > r1) => one
+ case Geq if (r0 >= r1) => one
// Always false
- case LESS_OP if (r0 >= r1) => zero
- case LESS_EQ_OP if (r0 > r1) => zero
- case GREATER_OP if (r0 <= r1) => zero
- case GREATER_EQ_OP if (r0 < r1) => zero
+ case Lt if (r0 >= r1) => zero
+ case Leq if (r0 > r1) => zero
+ case Gt if (r0 <= r1) => zero
+ case Geq if (r0 < r1) => zero
case _ => e
}
}
@@ -198,20 +199,20 @@ object ConstProp extends Pass {
}
private def constPropPrim(e: DoPrim): Expression = e.op match {
- case SHIFT_LEFT_OP => foldShiftLeft(e)
- case SHIFT_RIGHT_OP => foldShiftRight(e)
- case CONCAT_OP => foldConcat(e)
- case AND_OP => FoldAND(e)
- case OR_OP => FoldOR(e)
- case XOR_OP => FoldXOR(e)
- case EQUAL_OP => FoldEqual(e)
- case NEQUAL_OP => FoldNotEqual(e)
- case LESS_OP|LESS_EQ_OP|GREATER_OP|GREATER_EQ_OP => foldComparison(e)
- case NOT_OP => e.args(0) match {
+ case Shl => foldShiftLeft(e)
+ case Shr => foldShiftRight(e)
+ case Cat => foldConcat(e)
+ case And => FoldAND(e)
+ case Or => FoldOR(e)
+ case Xor => FoldXOR(e)
+ case Eq => FoldEqual(e)
+ case Neq => FoldNotEqual(e)
+ case (Lt | Leq | Gt | Geq) => foldComparison(e)
+ case Not => e.args(0) match {
case UIntLiteral(v, IntWidth(w)) => UIntLiteral(v ^ ((BigInt(1) << w.toInt) - 1), IntWidth(w))
case _ => e
}
- case BITS_SELECT_OP => e.args(0) match {
+ case Bits => e.args(0) match {
case UIntLiteral(v, _) => {
val hi = e.consts(0).toInt
val lo = e.consts(1).toInt
@@ -220,7 +221,7 @@ object ConstProp extends Pass {
}
case x if long_BANG(tpe(e)) == long_BANG(tpe(x)) => tpe(x) match {
case t: UIntType => x
- case _ => DoPrim(AS_UINT_OP, Seq(x), Seq(), tpe(e))
+ case _ => DoPrim(AsUInt, Seq(x), Seq(), tpe(e))
}
case _ => e
}