diff options
| author | Schuyler Eldridge | 2020-07-01 13:08:59 -0400 |
|---|---|---|
| committer | GitHub | 2020-07-01 17:08:59 +0000 |
| commit | 95bb2f66d34b40163c84c9c2893da50bd989e02f (patch) | |
| tree | 4b771e974afb0f146a3036777b3150144d76ca29 /src/test/scala/firrtlTests/transforms | |
| parent | cbfb32dc90f25c814898add3eff9b332b6021e5b (diff) | |
Fix unchecked type in ManipulateNames (#1726)
Fix a bug where a type check would always yield true. This caused a
bug where allow/block-list annotations would be incorrectly applied to
all subtypes of ManipulateNames.
The tests are updated to check that this now works.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Diffstat (limited to 'src/test/scala/firrtlTests/transforms')
| -rw-r--r-- | src/test/scala/firrtlTests/transforms/ManipulateNamesSpec.scala | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/test/scala/firrtlTests/transforms/ManipulateNamesSpec.scala b/src/test/scala/firrtlTests/transforms/ManipulateNamesSpec.scala index b1e2eeb9..ec1b505b 100644 --- a/src/test/scala/firrtlTests/transforms/ManipulateNamesSpec.scala +++ b/src/test/scala/firrtlTests/transforms/ManipulateNamesSpec.scala @@ -25,10 +25,14 @@ import org.scalatest.matchers.should.Matchers object ManipulateNamesSpec { - class AddPrefix extends ManipulateNames { + class AddPrefix extends ManipulateNames[AddPrefix] { override def manipulate = (a: String, b: Namespace) => Some(b.newName("prefix_" + a)) } + class AddSuffix extends ManipulateNames[AddSuffix] { + override def manipulate = (a: String, b: Namespace) => Some(b.newName(a + "_suffix")) + } + } class ManipulateNamesSpec extends AnyFlatSpec with Matchers { @@ -172,6 +176,26 @@ class ManipulateNamesSpec extends AnyFlatSpec with Matchers { }.getMessage should include ("LowerTypes") } + it should "only consume annotations whose type parameter matches" in new CircuitFixture { + val annotations = Seq( + ManipulateNamesBlocklistAnnotation(Seq(Seq(`~Foo|Bar>a`)), Dependency[AddPrefix]), + ManipulateNamesAllowlistAnnotation(Seq(Seq(`~Foo`)), Dependency[AddSuffix]), + ManipulateNamesAllowlistAnnotation(Seq(Seq(`~Foo|Bar>a`)), Dependency[AddSuffix]) + ) + val state = CircuitState(Parser.parse(input), annotations) + override val tm = new firrtl.stage.transforms.Compiler(Seq(Dependency[AddPrefix], Dependency[AddSuffix])) + val statex = tm.execute(state) + val expected: Seq[PartialFunction[Any, Boolean]] = Seq( + { case ir.Circuit(_, _, "prefix_Foo") => true }, + { case ir.Module(_, "prefix_Foo", _, _) => true}, + { case ir.DefInstance(_, "prefix_bar", "prefix_Bar", _) => true}, + { case ir.DefInstance(_, "prefix_bar2", "prefix_Bar", _) => true}, + { case ir.Module(_, "prefix_Bar", _, _) => true}, + { case ir.DefNode(_, "a_suffix", _) => true} + ) + expected.foreach(statex should containTree (_)) + } + behavior of "ManipulateNamesBlocklistAnnotation" it should "throw an exception if a non-local target is skipped" in new CircuitFixture { |
