From f447c2253081f7c2ede0658d059bc00c184312f9 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Thu, 10 Jan 2019 13:07:21 -0500 Subject: Add chisel3.stage.phases.Checks Phase Signed-off-by: Schuyler Eldridge --- src/main/scala/chisel3/stage/phases/Checks.scala | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/scala/chisel3/stage/phases/Checks.scala (limited to 'src/main') 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 + } + +} -- cgit v1.2.3