aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/options/phases/Checks.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/firrtl/options/phases/Checks.scala')
-rw-r--r--src/main/scala/firrtl/options/phases/Checks.scala43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/options/phases/Checks.scala b/src/main/scala/firrtl/options/phases/Checks.scala
new file mode 100644
index 00000000..0691e9b0
--- /dev/null
+++ b/src/main/scala/firrtl/options/phases/Checks.scala
@@ -0,0 +1,43 @@
+// See LICENSE for license details.
+
+package firrtl.options.phases
+
+import firrtl.AnnotationSeq
+import firrtl.annotations.Annotation
+import firrtl.options.{OptionsException, OutputAnnotationFileAnnotation, Phase, TargetDirAnnotation}
+
+/** [[firrtl.options.Phase Phase]] that validates an [[AnnotationSeq]]. If successful, views of this [[AnnotationSeq]]
+ * as [[StageOptions]] are guaranteed to succeed.
+ */
+class Checks extends Phase {
+
+ /** Validate an [[AnnotationSeq]] for [[StageOptions]]
+ * @throws OptionsException if annotations are invalid
+ */
+ def transform(annotations: AnnotationSeq): AnnotationSeq = {
+
+ val td, outA = collection.mutable.ListBuffer[Annotation]()
+ annotations.foreach {
+ case a: TargetDirAnnotation => td += a
+ case a: OutputAnnotationFileAnnotation => outA += a
+ case _ =>
+ }
+
+ if (td.size != 1) {
+ val d = td.map{ case TargetDirAnnotation(x) => x }
+ throw new OptionsException(
+ s"""|Exactly one target directory must be specified, but found `${d.mkString(", ")}` specified via:
+ | - explicit target directory: -td, --target-dir, TargetDirAnnotation
+ | - fallback default value""".stripMargin )}
+
+ if (outA.size > 1) {
+ val x = outA.map{ case OutputAnnotationFileAnnotation(x) => x }
+ throw new OptionsException(
+ s"""|At most one output annotation file can be specified, but found '${x.mkString(", ")}' specified via:
+ | - an option or annotation: -foaf, --output-annotation-file, OutputAnnotationFileAnnotation"""
+ .stripMargin )}
+
+ annotations
+ }
+
+}