diff options
| author | Adam Izraelevitz | 2017-03-16 13:13:17 -0700 |
|---|---|---|
| committer | Adam Izraelevitz | 2017-03-17 12:32:34 -0700 |
| commit | 3608401852baa18b4deaa22669529830b751901a (patch) | |
| tree | 342b401a754f4a7b7c6db456a95287c22ce15093 /src | |
| parent | f795cfe66be3499d52b037c3a252a54cde22d4c5 (diff) | |
Give better error message if missing emitedcircuit
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/firrtl/Compiler.scala | 10 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Driver.scala | 13 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 2 | ||||
| -rw-r--r-- | src/test/scala/firrtlTests/AnnotationTests.scala | 5 |
4 files changed, 20 insertions, 10 deletions
diff --git a/src/main/scala/firrtl/Compiler.scala b/src/main/scala/firrtl/Compiler.scala index 3da25083..60ec0eb0 100644 --- a/src/main/scala/firrtl/Compiler.scala +++ b/src/main/scala/firrtl/Compiler.scala @@ -45,7 +45,8 @@ case class CircuitState( /** Helper for getting an [[EmittedCircuit]] when it is known to exist */ def getEmittedCircuit: EmittedCircuit = emittedCircuitOption match { case Some(emittedCircuit) => emittedCircuit - case None => throw new FIRRTLException("No EmittedCircuit found! Check Emitter Annotations") + case None => + throw new FIRRTLException(s"No EmittedCircuit found! Did you delete any annotations?\n$deletedAnnotations") } /** Helper function for extracting emitted components from annotations */ def emittedComponents: Seq[EmittedComponent] = { @@ -55,6 +56,13 @@ case class CircuitState( }) emittedOpt.getOrElse(Seq.empty) } + def deletedAnnotations: Seq[Annotation] = { + val deletedOpt = annotations map (_.annotations collect { + case DeletedAnnotation(xformName, anno) => + DeletedAnnotation(xformName, anno) + }) + deletedOpt.getOrElse(Seq.empty) + } } /** Current form of the Firrtl Circuit diff --git a/src/main/scala/firrtl/Driver.scala b/src/main/scala/firrtl/Driver.scala index f321ad16..0fe2119d 100644 --- a/src/main/scala/firrtl/Driver.scala +++ b/src/main/scala/firrtl/Driver.scala @@ -174,14 +174,11 @@ object Driver { // Note: FirrtlExecutionSuccess emitted is only used if we're emitting the whole Circuit val emittedRes = firrtlConfig.getOutputConfig(optionsManager) match { case SingleFile(filename) => - finalState.emittedCircuitOption match { - case Some(emitted: EmittedCircuit) => - val outputFile = new java.io.PrintWriter(filename) - outputFile.write(emitted.value) - outputFile.close() - emitted.value - case _ => throwInternalError - } + val emitted = finalState.getEmittedCircuit + val outputFile = new java.io.PrintWriter(filename) + outputFile.write(emitted.value) + outputFile.close() + emitted.value case OneFilePerModule(dirName) => val emittedModules = finalState.emittedComponents collect { case x: EmittedModule => x } if (emittedModules.isEmpty) throwInternalError // There should be something diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index ec53aa63..76156d2d 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -125,7 +125,7 @@ object flattenType { def apply(t: Type) = UIntType(IntWidth(bitWidth(t))) } -class FIRRTLException(str: String) extends Exception(str) +class FIRRTLException(val str: String) extends Exception(str) object Utils extends LazyLogging { def throwInternalError = diff --git a/src/test/scala/firrtlTests/AnnotationTests.scala b/src/test/scala/firrtlTests/AnnotationTests.scala index 5a86bfe5..77f07781 100644 --- a/src/test/scala/firrtlTests/AnnotationTests.scala +++ b/src/test/scala/firrtlTests/AnnotationTests.scala @@ -140,5 +140,10 @@ class AnnotationTests extends AnnotationSpec with Matchers { result.annotations.get.annotations.head should matchPattern { case DeletedAnnotation(x, anno) => } + val exception = (intercept[FIRRTLException] { + result.getEmittedCircuit + }) + val deleted = result.deletedAnnotations + exception.str should be (s"No EmittedCircuit found! Did you delete any annotations?\n$deleted") } } |
