diff options
| author | Jack Koenig | 2018-02-27 18:07:11 -0800 |
|---|---|---|
| committer | GitHub | 2018-02-27 18:07:11 -0800 |
| commit | c7eb1570dfb1c7701ea32d1209982a053f3cec1d (patch) | |
| tree | 3f509b202d82841c5dad5588d1f953a25d389b44 /src/main/scala/firrtl/Driver.scala | |
| parent | b90fc784a1819c1d7905910130a7da022214bc22 (diff) | |
Refactor Annotations (#721)
- Old Annotation renamed to deprecated LegacyAnnotation
- Annotation is now a trait that can be extended
- New JsonProtocol for Annotation [de]serialization
- Replace AnnotationMap with AnnotationSeq
- Deprecate Transform.getMyAnnotations
- Update Transforms
- Turn on deprecation warnings
- Remove deprecated Driver.compile
- Make AnnotationTests abstract with Legacy and Json subclasses
- Add functionality to convert LegacyAnnotations of built-in annos
This will give a noisy warning and is more of a best effort than a
robust solution.
Fixes #475 Closes #609
Diffstat (limited to 'src/main/scala/firrtl/Driver.scala')
| -rw-r--r-- | src/main/scala/firrtl/Driver.scala | 99 |
1 files changed, 33 insertions, 66 deletions
diff --git a/src/main/scala/firrtl/Driver.scala b/src/main/scala/firrtl/Driver.scala index 3c6f687f..77412a0e 100644 --- a/src/main/scala/firrtl/Driver.scala +++ b/src/main/scala/firrtl/Driver.scala @@ -5,6 +5,7 @@ package firrtl import scala.collection._ import scala.io.Source import scala.sys.process.{BasicIO,stringSeqToProcess} +import scala.util.{Try, Success, Failure} import scala.util.control.ControlThrowable import java.io.{File, FileNotFoundException} @@ -41,44 +42,6 @@ import firrtl.Utils.throwInternalError */ object Driver { - //noinspection ScalaDeprecation - // Compiles circuit. First parses a circuit from an input file, - // executes all compiler passes, and writes result to an output - // file. - @deprecated("Please use execute", "firrtl 1.0") - def compile( - input: String, - output: String, - compiler: Compiler, - infoMode: InfoMode = IgnoreInfo, - customTransforms: Seq[Transform] = Seq.empty, - annotations: AnnotationMap = AnnotationMap(Seq.empty) - ): String = { - val outputBuffer = new java.io.CharArrayWriter - try { - val parsedInput = Parser.parse(Source.fromFile(input).getLines(), infoMode) - compiler.compile( - CircuitState(parsedInput, ChirrtlForm, Some(annotations)), - outputBuffer, - customTransforms) - } - - catch { - // Rethrow the exceptions which are expected or due to the runtime environment (out of memory, stack overflow) - case p: ControlThrowable => throw p - case p: PassException => throw p - case p: FIRRTLException => throw p - // Treat remaining exceptions as internal errors. - case e: Exception => throwInternalError(exception = Some(e)) - } - - val outputFile = new java.io.PrintWriter(output) - val outputString = outputBuffer.toString - outputFile.write(outputString) - outputFile.close() - outputString - } - /** Print a warning message * * @param message error message @@ -155,26 +118,35 @@ object Driver { if (!file.exists) { throw new FileNotFoundException(s"Annotation file $file not found!") } - val yaml = io.Source.fromFile(file).getLines().mkString("\n").parseYaml - yaml.convertTo[List[Annotation]] - + // Try new protocol first + JsonProtocol.deserializeTry(file).getOrElse { + val annos = Try { + val yaml = io.Source.fromFile(file).getLines().mkString("\n").parseYaml + yaml.convertTo[List[LegacyAnnotation]] + } + annos match { + case Success(result) => + val msg = s"$file is a YAML file!\n" + + (" "*9) + "YAML Annotation files are deprecated! Use JSON" + Driver.dramaticWarning(msg) + result + case Failure(_) => throw new InvalidAnnotationFileException(file.toString) + } + } } - val targetDirAnno = - List(Annotation( - CircuitName("All"), - classOf[BlackBoxSourceHelper], - BlackBoxTargetDir(optionsManager.targetDirName).serialize - )) + val targetDirAnno = List(BlackBoxTargetDirAnno(optionsManager.targetDirName)) // Output Annotations val outputAnnos = firrtlConfig.getEmitterAnnos(optionsManager) val globalAnnos = Seq(TargetDirAnnotation(optionsManager.targetDirName)) ++ - (if (firrtlConfig.dontCheckCombLoops) Seq(DontCheckCombLoopsAnnotation()) else Seq()) ++ - (if (firrtlConfig.noDCE) Seq(NoDCEAnnotation()) else Seq()) + (if (firrtlConfig.dontCheckCombLoops) Seq(DontCheckCombLoopsAnnotation) else Seq()) ++ + (if (firrtlConfig.noDCE) Seq(NoDCEAnnotation) else Seq()) - targetDirAnno ++ outputAnnos ++ globalAnnos ++ firrtlConfig.annotations ++ loadedAnnos + val annos = targetDirAnno ++ outputAnnos ++ globalAnnos ++ + firrtlConfig.annotations ++ loadedAnnos + LegacyAnnotation.convertLegacyAnnos(annos) } /** @@ -229,21 +201,18 @@ object Driver { optionsManager.makeTargetDir() maybeFinalState = Some(firrtlConfig.compiler.compile( - CircuitState(parsedInput, - ChirrtlForm, - Some(AnnotationMap(annos))), + CircuitState(parsedInput, ChirrtlForm, annos), firrtlConfig.customTransforms )) } - - catch { - // Rethrow the exceptions which are expected or due to the runtime environment (out of memory, stack overflow) - case p: ControlThrowable => throw p - case p: PassException => throw p - case p: FIRRTLException => throw p - // Treat remaining exceptions as internal errors. - case e: Exception => throwInternalError(exception = Some(e)) - } + catch { + // Rethrow the exceptions which are expected or due to the runtime environment (out of memory, stack overflow) + case p: ControlThrowable => throw p + case p: PassException => throw p + case p: FIRRTLException => throw p + // Treat remaining exceptions as internal errors. + case e: Exception => throwInternalError(exception = Some(e)) + } val finalState = maybeFinalState.get @@ -273,11 +242,9 @@ object Driver { optionsManager.firrtlOptions.outputAnnotationFileName match { case "" => case file => - val filename = optionsManager.getBuildFileName("anno", file) + val filename = optionsManager.getBuildFileName("anno.json", file) val outputFile = new java.io.PrintWriter(filename) - finalState.annotations.foreach { - finalAnnos => outputFile.write(finalAnnos.annotations.toYaml.prettyPrint) - } + outputFile.write(JsonProtocol.serialize(finalState.annotations)) outputFile.close() } |
