summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchuyler Eldridge2019-01-10 13:07:21 -0500
committerSchuyler Eldridge2019-05-22 16:17:17 -0400
commitf447c2253081f7c2ede0658d059bc00c184312f9 (patch)
tree000eec302efbb8190dbd994e33bc52fc6fee8342 /src
parent06c5e3e82f7dd4aa8ce159aa4c13b9bc36abce96 (diff)
Add chisel3.stage.phases.Checks Phase
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/chisel3/stage/phases/Checks.scala49
-rw-r--r--src/test/scala/chiselTests/stage/phases/ChecksSpec.scala43
2 files changed, 92 insertions, 0 deletions
diff --git a/src/main/scala/chisel3/stage/phases/Checks.scala b/src/main/scala/chisel3/stage/phases/Checks.scala
new file mode 100644
index 00000000..e2606019
--- /dev/null
+++ b/src/main/scala/chisel3/stage/phases/Checks.scala
@@ -0,0 +1,49 @@
+// See LICENSE for license details.
+
+package chisel3.stage.phases
+
+import chisel3.stage.{ChiselOutputFileAnnotation, NoRunFirrtlCompilerAnnotation, PrintFullStackTraceAnnotation}
+
+import firrtl.AnnotationSeq
+import firrtl.annotations.Annotation
+import firrtl.options.{OptionsException, Phase}
+
+/** Sanity checks an [[firrtl.AnnotationSeq]] before running the main [[firrtl.options.Phase]]s of
+ * [[chisel3.stage.ChiselStage]].
+ */
+class Checks extends Phase {
+
+ def transform(annotations: AnnotationSeq): AnnotationSeq = {
+ val noF, st, outF = collection.mutable.ListBuffer[Annotation]()
+ annotations.foreach {
+ case a: NoRunFirrtlCompilerAnnotation.type => a +=: noF
+ case a: PrintFullStackTraceAnnotation.type => a +=: st
+ case a: ChiselOutputFileAnnotation => a +=: outF
+ case _ =>
+ }
+
+ if (noF.size > 1) {
+ throw new OptionsException(
+ s"""|At most one NoRunFirrtlCompilerAnnotation can be specified, but found '${noF.size}'. Did you duplicate:
+ | - option or annotation: -chnrf, --no-run-firrtl, NoRunFirrtlCompilerAnnotation
+ |""".stripMargin)
+ }
+
+ if (st.size > 1) {
+ throw new OptionsException(
+ s"""|At most one PrintFullStackTraceAnnotation can be specified, but found '${noF.size}'. Did you duplicate:
+ | - option or annotation: --full-stacktrace, PrintFullStackTraceAnnotation
+ |""".stripMargin)
+ }
+
+ if (outF.size > 1) {
+ throw new OptionsException(
+ s"""|At most one Chisel output file can be specified but found '${outF.size}'. Did you duplicate:
+ | - option or annotation: --chisel-output-file, ChiselOutputFileAnnotation
+ |""".stripMargin)
+ }
+
+ annotations
+ }
+
+}
diff --git a/src/test/scala/chiselTests/stage/phases/ChecksSpec.scala b/src/test/scala/chiselTests/stage/phases/ChecksSpec.scala
new file mode 100644
index 00000000..6d01e38e
--- /dev/null
+++ b/src/test/scala/chiselTests/stage/phases/ChecksSpec.scala
@@ -0,0 +1,43 @@
+// See LICENSE for license details.
+
+package chiselTests.stage.phases
+
+import org.scalatest.{FlatSpec, Matchers}
+
+import chisel3.stage.{ChiselOutputFileAnnotation, NoRunFirrtlCompilerAnnotation, PrintFullStackTraceAnnotation}
+import chisel3.stage.phases.Checks
+
+import firrtl.AnnotationSeq
+import firrtl.annotations.NoTargetAnnotation
+import firrtl.options.{OptionsException, Phase}
+
+class ChecksSpec extends FlatSpec with Matchers {
+
+ def checkExceptionMessage(phase: Phase, annotations: AnnotationSeq, messageStart: String): Unit =
+ intercept[OptionsException]{ phase.transform(annotations) }.getMessage should startWith(messageStart)
+
+ class Fixture { val phase: Phase = new Checks }
+
+ behavior of classOf[Checks].toString
+
+ it should "do nothing on sane annotation sequences" in new Fixture {
+ val a = Seq(NoRunFirrtlCompilerAnnotation, PrintFullStackTraceAnnotation)
+ phase.transform(a).toSeq should be (a)
+ }
+
+ it should "throw an OptionsException if more than one NoRunFirrtlCompilerAnnotation is specified" in new Fixture {
+ val a = Seq(NoRunFirrtlCompilerAnnotation, NoRunFirrtlCompilerAnnotation)
+ checkExceptionMessage(phase, a, "At most one NoRunFirrtlCompilerAnnotation")
+ }
+
+ it should "throw an OptionsException if more than one PrintFullStackTraceAnnotation is specified" in new Fixture {
+ val a = Seq(PrintFullStackTraceAnnotation, PrintFullStackTraceAnnotation)
+ checkExceptionMessage(phase, a, "At most one PrintFullStackTraceAnnotation")
+ }
+
+ it should "throw an OptionsException if more than one ChiselOutputFileAnnotation is specified" in new Fixture {
+ val a = Seq(ChiselOutputFileAnnotation("foo"), ChiselOutputFileAnnotation("bar"))
+ checkExceptionMessage(phase, a, "At most one Chisel output file")
+ }
+
+}