blob: 0691e9b01b4cf55303272abf1bfdc6d149d06195 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
}
}
|