aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/Driver.scala
diff options
context:
space:
mode:
authorChick Markley2016-12-06 15:43:45 -0800
committerJack Koenig2016-12-06 15:43:45 -0800
commit65b61b4a614748c699982de5ab8072b21d7f9160 (patch)
treeb93fa5f8c74c562ee43e626e1296f80f7e7e4d69 /src/main/scala/firrtl/Driver.scala
parentef4b9e59be86bd83c6c815441cb9c8621d49c89f (diff)
Fixes for Annotation serialized/deserialize (#390)
* Fixes for Annotation serialized/deserialize Made serializer agree with deserializer on text representation Re-ordered serializations of Named subclasses to be C or C.m or C.m.c where C=circuit, m=module, c=component Note: component may contain dots Added serialize deserialize tests to AnnotationSpec Did some style cleanup on AnnotationSpec Added explicit return tupe on SimpleTransformSpec#execute * Make explicit Util.error remove commented code * Make Annotation#serialize a nicer format fix import there and remove new on case class * In firrtl Driver.execute use annotations passed in through optionsManager#firrtlOptions if nonEmpty otherwise read the annotations in from an annotations file Add new option to override this behavior, --force-append-anno-file will append annotations in file to any that are passed in A few other style fixes to Driver: remove new with case classes. don't use match when if(boolean) will do * Added tests of malformed component and circuit names
Diffstat (limited to 'src/main/scala/firrtl/Driver.scala')
-rw-r--r--src/main/scala/firrtl/Driver.scala53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/main/scala/firrtl/Driver.scala b/src/main/scala/firrtl/Driver.scala
index fe484965..75a87789 100644
--- a/src/main/scala/firrtl/Driver.scala
+++ b/src/main/scala/firrtl/Driver.scala
@@ -44,7 +44,7 @@ object Driver {
compiler: Compiler,
infoMode: InfoMode = IgnoreInfo,
customTransforms: Seq[Transform] = Seq.empty,
- annotations: AnnotationMap = new AnnotationMap(Seq.empty)
+ annotations: AnnotationMap = AnnotationMap(Seq.empty)
): String = {
val parsedInput = Parser.parse(Source.fromFile(input).getLines(), infoMode)
val outputBuffer = new java.io.CharArrayWriter
@@ -78,18 +78,21 @@ object Driver {
*/
def loadAnnotations(optionsManager: ExecutionOptionsManager with HasFirrtlOptions): Unit = {
/*
- Right now annotations will be looked for always based on the
+ If firrtlAnnotations in the firrtlOptions are nonEmpty then these will be the annotations
+ used by firrtl.
+ To use the file annotations make sure that the annotations in the firrtlOptions are empty
+ The annotation file if needed is found via
s"$targetDirName/$topName.anno" or s"$annotationFileNameOverride.anno"
- If found they will be added to the annotations already in the
- optionsManager.firrtlOptions, duplicates may be created, but this should be ok
*/
val firrtlConfig = optionsManager.firrtlOptions
- val annotationFileName = firrtlConfig.getAnnotationFileName(optionsManager)
- val annotationFile = new File(annotationFileName)
- if(annotationFile.exists) {
- val annotationsYaml = io.Source.fromFile(annotationFile).getLines().mkString("\n").parseYaml
- val annotationArray = annotationsYaml.convertTo[Array[Annotation]]
- optionsManager.firrtlOptions = firrtlConfig.copy(annotations = firrtlConfig.annotations ++ annotationArray)
+ if(firrtlConfig.annotations.isEmpty) {
+ val annotationFileName = firrtlConfig.getAnnotationFileName(optionsManager)
+ val annotationFile = new File(annotationFileName)
+ if (annotationFile.exists) {
+ val annotationsYaml = io.Source.fromFile(annotationFile).getLines().mkString("\n").parseYaml
+ val annotationArray = annotationsYaml.convertTo[Array[Annotation]]
+ optionsManager.firrtlOptions = firrtlConfig.copy(annotations = firrtlConfig.annotations ++ annotationArray)
+ }
}
}
@@ -126,7 +129,7 @@ object Driver {
io.Source.fromFile(inputFileName).getLines()
}
catch {
- case e: FileNotFoundException =>
+ case _: FileNotFoundException =>
val message = s"Input file $inputFileName not found"
dramaticError(message)
return FirrtlExecutionFailure(message)
@@ -138,7 +141,7 @@ object Driver {
val parsedInput = Parser.parse(firrtlSource, firrtlConfig.infoMode)
val outputBuffer = new java.io.CharArrayWriter
firrtlConfig.compiler.compile(
- CircuitState(parsedInput, ChirrtlForm, Some(new AnnotationMap(firrtlConfig.annotations))),
+ CircuitState(parsedInput, ChirrtlForm, Some(AnnotationMap(firrtlConfig.annotations))),
outputBuffer,
firrtlConfig.customTransforms
)
@@ -162,19 +165,19 @@ object Driver {
def execute(args: Array[String]): FirrtlExecutionResult = {
val optionsManager = new ExecutionOptionsManager("firrtl") with HasFirrtlOptions
- optionsManager.parse(args) match {
- case true =>
- execute(optionsManager) match {
- case success: FirrtlExecutionSuccess =>
- success
- case failure: FirrtlExecutionFailure =>
- optionsManager.showUsageAsError()
- failure
- case result =>
- throw new Exception(s"Error: Unknown Firrtl Execution result $result")
- }
- case _ =>
- FirrtlExecutionFailure("Could not parser command line options")
+ if(optionsManager.parse(args)) {
+ execute(optionsManager) match {
+ case success: FirrtlExecutionSuccess =>
+ success
+ case failure: FirrtlExecutionFailure =>
+ optionsManager.showUsageAsError()
+ failure
+ case result =>
+ throw new Exception(s"Error: Unknown Firrtl Execution result $result")
+ }
+ }
+ else {
+ FirrtlExecutionFailure("Could not parser command line options")
}
}