From 6b21b7df6f70ed753abe03814c88ef9010259303 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Wed, 15 Jan 2020 17:12:53 -0500 Subject: Filter ResolvePaths in EliminateTargetPaths (#1310) Change EliminateTargetPaths to remove ResolvePaths annotations in the output AnnotationSeq. This prevents a bug whereby the upstream ResolvePaths annotations from previous runs of EliminateTargetPaths can result in unexpected duplication. Adds a test that checks that ResolvePaths annotations are actually removed. Signed-off-by: Schuyler Eldridge Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../annotations/transforms/EliminateTargetPaths.scala | 9 ++++++--- .../annotationTests/EliminateTargetPathsSpec.scala | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala b/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala index f6bab6ea..2f20430b 100644 --- a/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala +++ b/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala @@ -133,10 +133,13 @@ class EliminateTargetPaths extends Transform { override protected def execute(state: CircuitState): CircuitState = { - val annotations = state.annotations.collect { case a: ResolvePaths => a } + val (annotations, annotationsx) = state.annotations.partition{ + case a: ResolvePaths => true + case _ => false + } // Collect targets that are not local - val targets = annotations.flatMap(_.targets.collect { case x: IsMember => x }) + val targets = annotations.map(_.asInstanceOf[ResolvePaths]).flatMap(_.targets.collect { case x: IsMember => x }) // Check validity of paths in targets val instanceOfModules = new InstanceGraph(state.circuit).getChildrenInstanceOfModule @@ -162,6 +165,6 @@ class EliminateTargetPaths extends Transform { val (newCircuit, renameMap) = run(state.circuit, targets) - state.copy(circuit = newCircuit, renames = Some(renameMap)) + state.copy(circuit = newCircuit, renames = Some(renameMap), annotations = annotationsx) } } diff --git a/src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala b/src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala index c75e0914..7aac277f 100644 --- a/src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala +++ b/src/test/scala/firrtlTests/annotationTests/EliminateTargetPathsSpec.scala @@ -357,4 +357,19 @@ class EliminateTargetPathsSpec extends FirrtlPropSpec with FirrtlMatchers { outputLines should contain (line) } } + + property("It should remove ResolvePaths annotations") { + val input = + """|circuit Foo: + | module Bar: + | skip + | module Foo: + | inst bar of Bar + |""".stripMargin + + CircuitState(passes.ToWorkingIR.run(Parser.parse(input)), UnknownForm, Nil) + .resolvePaths(Seq(CircuitTarget("Foo").module("Foo").instOf("bar", "Bar"))) + .annotations + .collect{ case a: firrtl.annotations.transforms.ResolvePaths => a } should be (empty) + } } -- cgit v1.2.3