diff options
| author | Jack Koenig | 2018-07-10 19:03:53 -0700 |
|---|---|---|
| committer | GitHub | 2018-07-10 19:03:53 -0700 |
| commit | 17437907de4ad12eb3f8d0818a158eb6959591a3 (patch) | |
| tree | 6f4cef136baff0c4b76592bff744f9639a0c694e /src | |
| parent | 6b02d09eb412df275d00930ab0e167b07fa61862 (diff) | |
Fix bug in zero-width renaming (#845)
Previously, Vecs of Bundles that contained a zero-width element would
result in a ClassCastException
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/passes/ZeroWidth.scala | 8 | ||||
| -rw-r--r-- | src/test/scala/firrtlTests/AnnotationTests.scala | 12 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/main/scala/firrtl/passes/ZeroWidth.scala b/src/main/scala/firrtl/passes/ZeroWidth.scala index 12da7d9b..6a79fe9a 100644 --- a/src/main/scala/firrtl/passes/ZeroWidth.scala +++ b/src/main/scala/firrtl/passes/ZeroWidth.scala @@ -66,8 +66,12 @@ object ZeroWidth extends Transform { else fields.flatMap(f => findRemovable(WSubField(expr, f.name, f.tpe, MALE), f.tpe)) case VectorType(vtpe, size) => if (size == 0) List(expr) - else findRemovable(WSubIndex(expr, 0, vtpe, MALE), vtpe).flatMap { e => - (0 until size).map(i => e.asInstanceOf[WSubIndex].copy(value = i)) + else { // Only invoke findRemovable multiple times if a zero-width element is found + val es0 = findRemovable(WSubIndex(expr, 0, vtpe, MALE), vtpe) + if (es0.isEmpty) es0 + else { + es0 ++ (1 until size).flatMap(i => findRemovable(WSubIndex(expr, i, vtpe, MALE), vtpe)) + } } } diff --git a/src/test/scala/firrtlTests/AnnotationTests.scala b/src/test/scala/firrtlTests/AnnotationTests.scala index 99e1ea2c..b2aeda77 100644 --- a/src/test/scala/firrtlTests/AnnotationTests.scala +++ b/src/test/scala/firrtlTests/AnnotationTests.scala @@ -430,10 +430,13 @@ abstract class AnnotationTests extends AnnotationSpec with Matchers { | output y : { foo : UInt<8>, bar : {}, fizz : UInt<8>[0], buzz : UInt<0> } | output a : {} | output b : UInt<8>[0] + | output c : { d : UInt<0>, e : UInt<8> }[2] + | c is invalid | y <= x |""".stripMargin val annos = Seq( - anno("x"), anno("y.bar"), anno("y.fizz"), anno("y.buzz"), anno("a"), anno("b") + anno("x"), anno("y.bar"), anno("y.fizz"), anno("y.buzz"), anno("a"), anno("b"), anno("c"), + anno("c[0].d"), anno("c[1].d") ) val result = compiler.compile(CircuitState(parse(input), ChirrtlForm, annos), Nil) val resultAnno = result.annotations.toSeq @@ -453,6 +456,13 @@ abstract class AnnotationTests extends AnnotationSpec with Matchers { resultAnno should not contain (anno("x_bar")) resultAnno should not contain (anno("x_fizz")) resultAnno should not contain (anno("x_buzz")) + resultAnno should not contain (anno("c")) + resultAnno should contain (anno("c_0_e")) + resultAnno should contain (anno("c_1_e")) + resultAnno should not contain (anno("c[0].d")) + resultAnno should not contain (anno("c[1].d")) + resultAnno should not contain (anno("c_0_d")) + resultAnno should not contain (anno("c_1_d")) } } |
