diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/passes/Inline.scala | 17 | ||||
| -rw-r--r-- | src/test/scala/firrtlTests/FlattenTests.scala | 12 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/main/scala/firrtl/passes/Inline.scala b/src/main/scala/firrtl/passes/Inline.scala index ad9c108f..00cda739 100644 --- a/src/main/scala/firrtl/passes/Inline.scala +++ b/src/main/scala/firrtl/passes/Inline.scala @@ -264,10 +264,15 @@ class InlineInstances extends Transform with DependencyAPIMigration with Registe } } - val maxIdx = indexMap.values.max - val resultSeq = Seq.fill(maxIdx + 1)(RenameMap()) - val resultMap = indexMap.mapValues(idx => resultSeq(maxIdx - idx)) - (resultMap, resultSeq) + indexMap match { + case a if a.isEmpty => + (Map.empty[(OfModule, Instance), RenameMap], Seq.empty[RenameMap]) + case a => + val maxIdx = indexMap.values.max + val resultSeq = Seq.fill(maxIdx + 1)(RenameMap()) + val resultMap = indexMap.mapValues(idx => resultSeq(maxIdx - idx)) + (resultMap, resultSeq) + } } def fixupRefs( @@ -353,8 +358,8 @@ class InlineInstances extends Transform with DependencyAPIMigration with Registe Some(m.map(onStmt(ModuleName(m.name, CircuitName(c.main))))) }) - val renames = renamesSeq.tail.foldLeft(renamesSeq.head)(_ andThen _) + val renames = renamesSeq.reduceLeftOption(_ andThen _) - CircuitState(flatCircuit, LowForm, annos, Some(renames)) + CircuitState(flatCircuit, LowForm, annos, renames) } } diff --git a/src/test/scala/firrtlTests/FlattenTests.scala b/src/test/scala/firrtlTests/FlattenTests.scala index 53604ee5..ef555eaa 100644 --- a/src/test/scala/firrtlTests/FlattenTests.scala +++ b/src/test/scala/firrtlTests/FlattenTests.scala @@ -272,4 +272,16 @@ class FlattenTests extends LowTransformSpec { """.stripMargin execute(input, check, Seq(flatten("Top"))) } + + "The Flatten transform" should "work on modules with no instances" in { + val input = """ + |circuit Top : + | module Top : + | input a : UInt<32> + | output b : UInt<32> + | b <= a + """.stripMargin + val check = input + execute(input, check, Seq(flatten("Top"))) + } } |
