diff options
| -rw-r--r-- | src/main/scala/chisel3/stage/package.scala | 25 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/stage/ChiselOptionsViewSpec.scala | 40 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/main/scala/chisel3/stage/package.scala b/src/main/scala/chisel3/stage/package.scala new file mode 100644 index 00000000..851dd400 --- /dev/null +++ b/src/main/scala/chisel3/stage/package.scala @@ -0,0 +1,25 @@ +// See LICENSE for license details. + +package chisel3 + +import firrtl._ +import firrtl.options.OptionsView + +package object stage { + + implicit object ChiselOptionsView extends OptionsView[ChiselOptions] { + + def view(options: AnnotationSeq): ChiselOptions = options + .collect { case a: ChiselOption => a } + .foldLeft(new ChiselOptions()){ (c, x) => + x match { + case _: NoRunFirrtlCompilerAnnotation.type => c.copy(runFirrtlCompiler = false) + case _: PrintFullStackTraceAnnotation.type => c.copy(printFullStackTrace = true) + case ChiselOutputFileAnnotation(f) => c.copy(outputFile = Some(f)) + case ChiselCircuitAnnotation(a) => c.copy(chiselCircuit = Some(a)) + } + } + + } + +} diff --git a/src/test/scala/chiselTests/stage/ChiselOptionsViewSpec.scala b/src/test/scala/chiselTests/stage/ChiselOptionsViewSpec.scala new file mode 100644 index 00000000..7dbeb9fa --- /dev/null +++ b/src/test/scala/chiselTests/stage/ChiselOptionsViewSpec.scala @@ -0,0 +1,40 @@ +// See LICENSE for license details. + +package chiselTests.stage + +import org.scalatest.{FlatSpec, Matchers} + +import firrtl.options.Viewer.view + +import chisel3.stage._ +import chisel3.internal.firrtl.Circuit + +class ChiselOptionsViewSpec extends FlatSpec with Matchers { + + behavior of ChiselOptionsView.getClass.getName + + it should "construct a view from an AnnotationSeq" in { + val bar = Circuit("bar", Seq.empty, Seq.empty) + val annotations = Seq( + NoRunFirrtlCompilerAnnotation, + PrintFullStackTraceAnnotation, + ChiselOutputFileAnnotation("foo"), + ChiselCircuitAnnotation(bar) + ) + val out = view[ChiselOptions](annotations) + + info("runFirrtlCompiler was set to false") + out.runFirrtlCompiler should be (false) + + info("printFullStackTrace was set to true") + out.printFullStackTrace should be (true) + + info("outputFile was set to 'foo'") + out.outputFile should be (Some("foo")) + + info("chiselCircuit was set to circuit 'bar'") + out.chiselCircuit should be (Some(bar)) + + } + +} |
