aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjackkoenig2016-09-12 15:23:21 -0700
committerjackkoenig2016-09-12 21:30:36 -0700
commit6c93f5e688554ff3432715d206351d2d84341eed (patch)
treed9d35c60bfe486a8d1defca31eab157565146a09 /src
parent7f12a07d941bd08749ef350654fe9a324b882a6b (diff)
Change Legalize Shift Right to respect SInt
Fix bug where Legalize was generating a bit select for SInts without then casting to SInt Fixes #169
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/passes/Passes.scala38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/main/scala/firrtl/passes/Passes.scala b/src/main/scala/firrtl/passes/Passes.scala
index b9808485..660b2d1f 100644
--- a/src/main/scala/firrtl/passes/Passes.scala
+++ b/src/main/scala/firrtl/passes/Passes.scala
@@ -211,23 +211,22 @@ object ExpandConnects extends Pass {
// TODO replace UInt with zero-width wire instead
object Legalize extends Pass {
def name = "Legalize"
- def legalizeShiftRight (e: DoPrim): Expression = e.op match {
- case Shr => {
- val amount = e.consts.head.toInt
- val width = long_BANG(e.args.head.tpe)
- lazy val msb = width - 1
- if (amount >= width) {
- e.tpe match {
- case t: UIntType => UIntLiteral(0, IntWidth(1))
- case t: SIntType =>
- DoPrim(Bits, e.args, Seq(msb, msb), SIntType(IntWidth(1)))
- case t => error(s"Unsupported type ${t} for Primop Shift Right")
- }
- } else {
- e
+ private def legalizeShiftRight(e: DoPrim): Expression = {
+ require(e.op == Shr)
+ val amount = e.consts.head.toInt
+ val width = bitWidth(e.args.head.tpe)
+ lazy val msb = width - 1
+ if (amount >= width) {
+ e.tpe match {
+ case UIntType(_) => UIntLiteral(0, IntWidth(1))
+ case SIntType(_) =>
+ val bits = DoPrim(Bits, e.args, Seq(msb, msb), UIntType(IntWidth(1)))
+ DoPrim(AsSInt, Seq(bits), Seq.empty, SIntType(IntWidth(1)))
+ case t => error(s"Unsupported type ${t} for Primop Shift Right")
}
+ } else {
+ e
}
- case _ => e
}
def legalizeConnect(c: Connect): Statement = {
val t = c.loc.tpe
@@ -242,11 +241,12 @@ object Legalize extends Pass {
}
}
def run (c: Circuit): Circuit = {
- def legalizeE (e: Expression): Expression = {
- e map (legalizeE) match {
- case e: DoPrim => legalizeShiftRight(e)
- case e => e
+ def legalizeE(expr: Expression): Expression = expr map legalizeE match {
+ case prim: DoPrim => prim.op match {
+ case Shr => legalizeShiftRight(prim)
+ case _ => prim
}
+ case e => e // respect pre-order traversal
}
def legalizeS (s: Statement): Statement = {
val legalizedStmt = s match {