diff options
| author | Kevin Laeufer | 2020-08-28 13:15:56 -0700 |
|---|---|---|
| committer | GitHub | 2020-08-28 20:15:56 +0000 |
| commit | 0b1391a623ee0769dc51fce15e0e0f5516225d5d (patch) | |
| tree | cd4338f39dc9cc736ad1bda73bc003e0ef08eae6 /src | |
| parent | 7174098c436a8d8a6346d1ee2f8572c09a817e72 (diff) | |
FlattenSpec: flattening a module with no instaces should be a no-op (#1868)
* FlattenSpec: flattening a module with no instaces should be a no-op
* Fix problem when flattening/inlining a lone module
Fix an edge case bug in InlineInstances where a circuit containing a
lone module is flattened/inlined. This now properly special cases the
situation of an empty indexMap which before had to be of length >= 1.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
* Simplify rename logic in InlineInstances
Co-authored-by: Jack Koenig <koenig@sifive.com>
Co-authored-by: Albert Magyar <albert.magyar@gmail.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
* Mea culpa
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Co-authored-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Co-authored-by: Jack Koenig <koenig@sifive.com>
Co-authored-by: Albert Magyar <albert.magyar@gmail.com>
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"))) + } } |
