diff options
| author | Schuyler Eldridge | 2019-02-01 03:17:15 -0500 |
|---|---|---|
| committer | Schuyler Eldridge | 2019-05-22 16:17:17 -0400 |
| commit | 06c5e3e82f7dd4aa8ce159aa4c13b9bc36abce96 (patch) | |
| tree | bcad3348588d09e18c9b5ca0cf6902340fab002e | |
| parent | f592422fc1dcc374139bbeb84a814134c5e58ac4 (diff) | |
Add ChiselOptionsView
Co-Authored-By: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Co-Authored-By: chick <chick@qrhino.com>
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
| -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)) + + } + +} |
