diff options
| author | Schuyler Eldridge | 2020-06-16 11:59:15 -0400 |
|---|---|---|
| committer | Schuyler Eldridge | 2020-06-22 20:00:10 -0400 |
| commit | 6e03f63d525aac0bdf4a59b6fe66a0b4d5a3a25a (patch) | |
| tree | 482481bcfe93ea5dfcece80772ce1957fb68c74c /src/test/scala/chiselTests/AnnotatingDiamondSpec.scala | |
| parent | cc4fa583690292d690804144fe92427f0c9f5fdf (diff) | |
Use ChiselStage in Tests
This migrates the tests to Chisel 3.4/FIRRTL 1.4. This primarily
involves removing usages of deprecated methods including:
- Remove usages of Driver
- Use ChiselStage methods instead of BackendCompilationUtilities
methods
- Use Dependency API for custom transforms
- Use extractCause to unpack StackError
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/test/scala/chiselTests/AnnotatingDiamondSpec.scala')
| -rw-r--r-- | src/test/scala/chiselTests/AnnotatingDiamondSpec.scala | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/test/scala/chiselTests/AnnotatingDiamondSpec.scala b/src/test/scala/chiselTests/AnnotatingDiamondSpec.scala index f63fcb3d..70a62555 100644 --- a/src/test/scala/chiselTests/AnnotatingDiamondSpec.scala +++ b/src/test/scala/chiselTests/AnnotatingDiamondSpec.scala @@ -5,13 +5,16 @@ package chiselTests import chisel3._ import chisel3.experimental.{ChiselAnnotation, RunFirrtlTransform, annotate} import chisel3.internal.InstanceId +import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage} import chisel3.testers.BasicTester -import firrtl.{CircuitForm, CircuitState, LowForm, Transform} +import firrtl.{CircuitForm, CircuitState, DependencyAPIMigration, LowForm, Transform} import firrtl.annotations.{ + CircuitName, + CircuitTarget, SingleTargetAnnotation, - ModuleName, - Named + Target } +import firrtl.stage.Forms import org.scalatest._ import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers @@ -19,8 +22,8 @@ import org.scalatest.matchers.should.Matchers /** These annotations and the IdentityTransform class serve as an example of how to write a * Chisel/Firrtl library */ -case class IdentityAnnotation(target: Named, value: String) extends SingleTargetAnnotation[Named] { - def duplicate(n: Named): IdentityAnnotation = this.copy(target = n) +case class IdentityAnnotation(target: Target, value: String) extends SingleTargetAnnotation[Target] { + def duplicate(n: Target): IdentityAnnotation = this.copy(target = n) } /** ChiselAnnotation that corresponds to the above FIRRTL annotation */ case class IdentityChiselAnnotation(target: InstanceId, value: String) @@ -35,9 +38,11 @@ object identify { // scalastyle:ignore object.name } } -class IdentityTransform extends Transform { - def inputForm: CircuitForm = LowForm - def outputForm: CircuitForm = LowForm +class IdentityTransform extends Transform with DependencyAPIMigration { + override def prerequisites = Forms.LowForm + override def optionalPrerequisites = Seq.empty + override def optionalPrerequisiteOf = Forms.LowEmitters + override def invalidates(a: Transform) = false def execute(state: CircuitState): CircuitState = { val annosx = state.annotations.map { @@ -133,33 +138,29 @@ class DiamondTester extends BasicTester { class AnnotatingDiamondSpec extends AnyFreeSpec with Matchers { - """ - |Diamond is an example of a module that has two sub-modules A and B who both instantiate their - |own instances of module C. This highlights the difference between specific and general - |annotation scopes - """.stripMargin - { - - """ - |annotations are not resolved at after circuit elaboration, - |that happens only after emit has been called on circuit""".stripMargin in { - - Driver.execute(Array("--target-dir", "test_run_dir"), () => new TopOfDiamond) match { - case ChiselExecutionSuccess(Some(circuit), emitted, _) => - val annos = circuit.annotations.map(_.toFirrtl) - annos.count(_.isInstanceOf[IdentityAnnotation]) should be (10) - - annos.count { - case IdentityAnnotation(ModuleName("ModC", _), "ModC(16)") => true - case _ => false - } should be (1) - - annos.count { - case IdentityAnnotation(ModuleName("ModC_1", _), "ModC(32)") => true - case _ => false - } should be (1) - case _ => - assert(false) - } + """|Diamond is an example of a module that has two sub-modules A and B who both instantiate their + |own instances of module C. This highlights the difference between specific and general + |annotation scopes""".stripMargin - { + + """|annotations are not resolved at after circuit elaboration, + |that happens only after emit has been called on circuit""".stripMargin in { + + val annos = (new ChiselStage) + .execute(Array("--target-dir", "test_run_dir", "--no-run-firrtl"), + Seq(ChiselGeneratorAnnotation(() => new TopOfDiamond))) + .filter { + case _: IdentityAnnotation => true + case _ => false + }.toSeq + + info("Found ten (10) 'IdentityAnnotation's") + annos should have length (10) + + info("Found IdentityAnnotation targeting '~*|ModC' with value 'ModC(16)'") + annos should contain (IdentityAnnotation(CircuitTarget("TopOfDiamond").module("ModC"), "ModC(16)")) + + info("Found IdentityAnnotation targeting '~*|ModC_1:seen' with value 'ModC(32)'") + annos should contain (IdentityAnnotation(CircuitTarget("TopOfDiamond").module("ModC_1"), "ModC(32)")) } } } |
