summaryrefslogtreecommitdiff
path: root/src/test/scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2019-01-10 12:47:18 -0500
committerSchuyler Eldridge2019-05-22 16:17:17 -0400
commita423db5fa5a9fb106c1b0048b7dcf97fc83953b6 (patch)
treeecb697238fbbf9569ca9d4a4156fac9dd81fa3f3 /src/test/scala
parent820e2688f0cb966d4528ff074fdbdc623ed8f940 (diff)
Add chisel3.stage Annotations
This adds the following FIRRTL Annotations to Chisel: - NoRunFirrtlCompilerAnnotation - PrintFullStackTraceAnnotation - ChiselGeneratorAnnotation - ChiselCircuitAnnotation - ChiselOutputFileAnnotation This includes tests for ChiselGeneratorAnnotation as this Annotation is able to be constructed from a String and to elaborate itself. 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>
Diffstat (limited to 'src/test/scala')
-rw-r--r--src/test/scala/chiselTests/stage/ChiselAnnotationsSpec.scala65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/scala/chiselTests/stage/ChiselAnnotationsSpec.scala b/src/test/scala/chiselTests/stage/ChiselAnnotationsSpec.scala
new file mode 100644
index 00000000..c89955f2
--- /dev/null
+++ b/src/test/scala/chiselTests/stage/ChiselAnnotationsSpec.scala
@@ -0,0 +1,65 @@
+// See LICENSE for license details.
+
+package chiselTests.stage
+
+import org.scalatest.{FlatSpec, Matchers}
+
+import chisel3._
+import chisel3.stage.{ChiselCircuitAnnotation, ChiselGeneratorAnnotation}
+import chisel3.experimental.RawModule
+
+import firrtl.options.OptionsException
+
+class ChiselAnnotationsSpecFoo extends RawModule {
+ val in = IO(Input(Bool()))
+ val out = IO(Output(Bool()))
+ out := ~in
+}
+
+class ChiselAnnotationsSpecBaz(name: String) extends ChiselAnnotationsSpecFoo {
+ override val desiredName = name
+}
+
+class ChiselAnnotationsSpecQux extends ChiselAnnotationsSpecFoo {
+ /* This printf requires an implicit clock and reset, but RawModule has none. This will thereby fail elaboration. */
+ printf("hello")
+}
+
+class ChiselAnnotation
+
+class ChiselAnnotationsSpec extends FlatSpec with Matchers {
+
+ behavior of "ChiselGeneratorAnnotation elaboration"
+
+ it should "elaborate to a ChiselCircuitAnnotation" in {
+ val annotation = ChiselGeneratorAnnotation(() => new ChiselAnnotationsSpecFoo)
+ annotation.elaborate shouldBe a [ChiselCircuitAnnotation]
+ }
+
+ it should "throw an exception if elaboration fails" in {
+ val annotation = ChiselGeneratorAnnotation(() => new ChiselAnnotationsSpecQux)
+ intercept [ChiselException] { annotation.elaborate }
+ }
+
+ behavior of "ChiselGeneratorAnnotation when stringly constructing from Module names"
+
+ it should "elaborate from a String" in {
+ val annotation = ChiselGeneratorAnnotation("chiselTests.stage.ChiselAnnotationsSpecFoo")
+ annotation.elaborate shouldBe a [ChiselCircuitAnnotation]
+ }
+
+ it should "throw an exception if elaboration from a String refers to nonexistant class" in {
+ val bar = "chiselTests.stage.ChiselAnnotationsSpecBar"
+ val annotation = ChiselGeneratorAnnotation(bar)
+ intercept [OptionsException] { annotation.elaborate }
+ .getMessage should startWith (s"Unable to locate module '$bar'")
+ }
+
+ it should "throw an exception if elaboration from a String refers to an anonymous class" in {
+ val baz = "chiselTests.stage.ChiselAnnotationsSpecBaz"
+ val annotation = ChiselGeneratorAnnotation(baz)
+ intercept [OptionsException] { annotation.elaborate }
+ .getMessage should startWith (s"Unable to create instance of module '$baz'")
+ }
+
+}