diff options
| author | Jack Koenig | 2019-02-22 13:59:33 -0800 |
|---|---|---|
| committer | mergify[bot] | 2019-02-22 21:59:33 +0000 |
| commit | 0ace0218d3151df2d102463dd682128a88ae7be6 (patch) | |
| tree | 1e7728ceb4b7cd160e3547decc4be1ef77d5aeda /src/main/scala | |
| parent | 50d9571bc26c445fd9ebaeb3c06d80d598397405 (diff) | |
Stop reporting exceptions in custom transformations as internal errors (#867)
Instead, just forward the exception
Diffstat (limited to 'src/main/scala')
| -rw-r--r-- | src/main/scala/firrtl/Compiler.scala | 21 | ||||
| -rw-r--r-- | src/main/scala/firrtl/Driver.scala | 2 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/Compiler.scala b/src/main/scala/firrtl/Compiler.scala index 87662800..1ef35891 100644 --- a/src/main/scala/firrtl/Compiler.scala +++ b/src/main/scala/firrtl/Compiler.scala @@ -295,6 +295,9 @@ trait Emitter extends Transform { def emit(state: CircuitState, writer: Writer): Unit } +/** Wraps exceptions from CustomTransforms so they can be reported appropriately */ +case class CustomTransformException(cause: Throwable) extends Exception("", cause) + object CompilerUtils extends LazyLogging { /** Generates a sequence of [[Transform]]s to lower a Firrtl circuit * @@ -427,6 +430,15 @@ trait Compiler extends LazyLogging { compile(state.copy(annotations = emitAnno +: state.annotations), customTransforms) } + private def isCustomTransform(xform: Transform): Boolean = { + def getTopPackage(pack: java.lang.Package): java.lang.Package = + Package.getPackage(pack.getName.split('.').head) + // We use the top package of the Driver to get the top firrtl package + Option(xform.getClass.getPackage).map { p => + getTopPackage(p) != firrtl.Driver.getClass.getPackage + }.getOrElse(true) + } + /** Perform compilation * * Emission will only be performed if [[EmitAnnotation]]s are present @@ -440,7 +452,14 @@ trait Compiler extends LazyLogging { val allTransforms = CompilerUtils.mergeTransforms(transforms, customTransforms) :+ emitter val (timeMillis, finalState) = Utils.time { - allTransforms.foldLeft(state) { (in, xform) => xform.runTransform(in) } + allTransforms.foldLeft(state) { (in, xform) => + try { + xform.runTransform(in) + } catch { + // Wrap exceptions from custom transforms so they are reported as such + case e: Exception if isCustomTransform(xform) => throw CustomTransformException(e) + } + } } logger.error(f"Total FIRRTL Compile Time: $timeMillis%.1f ms") diff --git a/src/main/scala/firrtl/Driver.scala b/src/main/scala/firrtl/Driver.scala index 47841cec..c277e120 100644 --- a/src/main/scala/firrtl/Driver.scala +++ b/src/main/scala/firrtl/Driver.scala @@ -248,6 +248,8 @@ object Driver { case p: PassException => throw p case p: PassExceptions => throw p case p: FIRRTLException => throw p + // Propagate exceptions from custom transforms + case CustomTransformException(cause) => throw cause // Treat remaining exceptions as internal errors. case e: Exception => throwInternalError(exception = Some(e)) } |
