From 82acc83280045fb5f71bf0e2b1b6a4fba324bff2 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Tue, 27 Aug 2019 18:53:55 -0400 Subject: Add firrtl.options.ExitCode type hierarchy Signed-off-by: Schuyler Eldridge --- src/main/scala/firrtl/options/ExitCodes.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/scala/firrtl/options/ExitCodes.scala (limited to 'src') diff --git a/src/main/scala/firrtl/options/ExitCodes.scala b/src/main/scala/firrtl/options/ExitCodes.scala new file mode 100644 index 00000000..0e91fdec --- /dev/null +++ b/src/main/scala/firrtl/options/ExitCodes.scala @@ -0,0 +1,15 @@ +// See LICENSE for license details. + +package firrtl.options + +/** The supertype of all exit codes */ +sealed trait ExitCode { val number: Int } + +/** [[ExitCode]] indicating success */ +object ExitSuccess extends ExitCode{ val number = 0 } + +/** An [[ExitCode]] indicative of failure. This must be non-zero and should not conflict with a reserved exit code. */ +sealed trait ExitFailure extends ExitCode + +/** An exit code indicating a general, non-specific error */ +object GeneralError extends ExitFailure { val number = 1 } -- cgit v1.2.3 From d1221efc40e7374691f0ff948c99379d0f52012f Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Wed, 14 Aug 2019 16:10:10 -0400 Subject: Add StageError This adds the StageError Error. This Error indicates that a Stage/Phase has hit an unrecoverable error, it cannot continue, and requests that the entire Stage/Phase hierarchy be killed with an ExitFailure ExitCode. StageMain is modified to catch StageError and exit the application with the provided exit code number. Signed-off-by: Schuyler Eldridge --- src/main/scala/firrtl/options/Exceptions.scala | 3 +++ src/main/scala/firrtl/options/Stage.scala | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src') diff --git a/src/main/scala/firrtl/options/Exceptions.scala b/src/main/scala/firrtl/options/Exceptions.scala index 100ff464..38b2f2e2 100644 --- a/src/main/scala/firrtl/options/Exceptions.scala +++ b/src/main/scala/firrtl/options/Exceptions.scala @@ -18,3 +18,6 @@ class OptionsException(val message: String, cause: Throwable = null) extends Ill * out of order or if the compiler did not run things in the correct order. */ class PhasePrerequisiteException(message: String, cause: Throwable = null) extends PhaseException(message, cause) + +/** Indicates that a [[Stage]] or [[Phase]] has run into a situation where it cannot continue. */ +final class StageError(val code: ExitFailure = GeneralError, cause: Throwable = null) extends Error("", cause) diff --git a/src/main/scala/firrtl/options/Stage.scala b/src/main/scala/firrtl/options/Stage.scala index f2780761..3752b846 100644 --- a/src/main/scala/firrtl/options/Stage.scala +++ b/src/main/scala/firrtl/options/Stage.scala @@ -69,6 +69,8 @@ class StageMain(val stage: Stage) { final def main(args: Array[String]): Unit = try { stage.execute(args, Seq.empty) } catch { + case a: StageError => + System.exit(a.code.number) case a: OptionsException => StageUtils.dramaticUsageError(a.message) System.exit(1) -- cgit v1.2.3