diff options
| author | Schuyler Eldridge | 2019-01-14 11:59:48 -0500 |
|---|---|---|
| committer | Schuyler Eldridge | 2019-05-22 16:17:17 -0400 |
| commit | 20ba486ab1988e57e2b2ca163c9c83e1d8904bba (patch) | |
| tree | 3956ff9443b4f566844862579e5a441b096e07cb /src/test/scala | |
| parent | 325e48809587fdf47d398578a1d94f856ab1f275 (diff) | |
Add chisel3.stage.phases.Emitter Phase
This adds an Emitter Phase that writes a ChiselCircuitAnnotation to
a file if a ChiselOutputFileAnnotation is present.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/test/scala')
| -rw-r--r-- | src/test/scala/chiselTests/stage/phases/EmitterSpec.scala | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/stage/phases/EmitterSpec.scala b/src/test/scala/chiselTests/stage/phases/EmitterSpec.scala new file mode 100644 index 00000000..63498adb --- /dev/null +++ b/src/test/scala/chiselTests/stage/phases/EmitterSpec.scala @@ -0,0 +1,60 @@ +// See LICENSE for license details. + +package chiselTests.stage.phases + +import org.scalatest.{FlatSpec, Matchers} + +import chisel3.experimental.RawModule +import chisel3.stage.{ChiselCircuitAnnotation, ChiselGeneratorAnnotation, ChiselOutputFileAnnotation} +import chisel3.stage.phases.{Convert, Elaborate, Emitter} + +import firrtl.{AnnotationSeq, EmittedFirrtlCircuitAnnotation} +import firrtl.annotations.DeletedAnnotation +import firrtl.options.{Phase, TargetDirAnnotation} + +import java.io.File + +class EmitterSpec extends FlatSpec with Matchers { + + class FooModule extends RawModule { override val desiredName = "Foo" } + class BarModule extends RawModule { override val desiredName = "Bar" } + + class Fixture { val phase: Phase = new Emitter } + + behavior of classOf[Emitter].toString + + it should "do nothing if no ChiselOutputFileAnnotations are present" in new Fixture { + val dir = new File("test_run_dir/EmitterSpec") + val annotations = (new Elaborate).transform(Seq( TargetDirAnnotation(dir.toString), + ChiselGeneratorAnnotation(() => new FooModule) )) + val annotationsx = phase.transform(annotations) + + val Seq(fooFile, barFile) = Seq("Foo.fir", "Bar.fir").map(f => new File(dir + "/" + f)) + + info(s"$fooFile does not exist") + fooFile should not (exist) + + info("annotations are unmodified") + annotationsx.toSeq should be (annotations.toSeq) + } + + it should "emit a ChiselCircuitAnnotation to a specific file" in new Fixture { + val dir = new File("test_run_dir/EmitterSpec") + val circuit = (new Elaborate) + .transform(Seq(ChiselGeneratorAnnotation(() => new BarModule))) + .collectFirst{ case a: ChiselCircuitAnnotation => a} + .get + val annotations = phase.transform(Seq( TargetDirAnnotation(dir.toString), + circuit, + ChiselOutputFileAnnotation("Baz") )) + + val bazFile = new File(dir + "/Baz.fir") + + info(s"$bazFile exists") + bazFile should (exist) + + info("a deleted EmittedFirrtlCircuitAnnotation should be generated") + annotations.collect{ case a @ DeletedAnnotation(_, _: EmittedFirrtlCircuitAnnotation) => a }.size should be (1) + } + +} |
