From 384ad661dde15d1fc9c58da7a9fc2970b25528e9 Mon Sep 17 00:00:00 2001 From: Adam Izraelevitz Date: Sat, 30 Sep 2017 09:21:13 -0700 Subject: Fixed zero width cat but (#651) --- src/main/scala/firrtl/passes/ZeroWidth.scala | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/firrtl/passes/ZeroWidth.scala b/src/main/scala/firrtl/passes/ZeroWidth.scala index 6d7766d1..32b0b833 100644 --- a/src/main/scala/firrtl/passes/ZeroWidth.scala +++ b/src/main/scala/firrtl/passes/ZeroWidth.scala @@ -40,10 +40,25 @@ object ZeroWidth extends Transform { case VectorType(t, size) => removeZero(t) map (VectorType(_, size)) case x => Some(x) } - private def onExp(e: Expression): Expression = e.tpe match { - case UIntType(IntWidth(ZERO)) => UIntLiteral(ZERO, IntWidth(BigInt(1))) - case SIntType(IntWidth(ZERO)) => SIntLiteral(ZERO, IntWidth(BigInt(1))) - case other => e map onExp + private def onExp(e: Expression): Expression = e match { + case DoPrim(Cat, args, consts, tpe) => + val nonZeros = args.flatMap { x => + x.tpe match { + case UIntType(IntWidth(ZERO)) => Seq.empty[Expression] + case SIntType(IntWidth(ZERO)) => Seq.empty[Expression] + case other => Seq(x) + } + } + nonZeros match { + case Nil => UIntLiteral(ZERO, IntWidth(BigInt(1))) + case Seq(x) => x + case seq => DoPrim(Cat, seq, consts, tpe) map onExp + } + case other => other.tpe match { + case UIntType(IntWidth(ZERO)) => UIntLiteral(ZERO, IntWidth(BigInt(1))) + case SIntType(IntWidth(ZERO)) => SIntLiteral(ZERO, IntWidth(BigInt(1))) + case _ => e map onExp + } } private def onStmt(renames: RenameMap)(s: Statement): Statement = s match { case (_: DefWire| _: DefRegister| _: DefMemory) => -- cgit v1.2.3