summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAlbert Chen2018-11-26 09:47:28 -0800
committerSchuyler Eldridge2018-11-26 12:47:28 -0500
commitab951049c2c60402e2318ba863520d4a16c8288d (patch)
tree496a62cb509f06711a01795bca7eafc8ae260a8b /src/main
parentdd82374f79005a2998b016712f0aec07775eb506 (diff)
Trim Stack Trace (#931)
- Trim stack trace to show better, reduced information to the user - Add --full-stacktrace to FIRRTL option to show full stack trace
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/chisel3/ChiselExecutionOptions.scala9
-rw-r--r--src/main/scala/chisel3/Driver.scala118
2 files changed, 75 insertions, 52 deletions
diff --git a/src/main/scala/chisel3/ChiselExecutionOptions.scala b/src/main/scala/chisel3/ChiselExecutionOptions.scala
index 6f58153f..a3644829 100644
--- a/src/main/scala/chisel3/ChiselExecutionOptions.scala
+++ b/src/main/scala/chisel3/ChiselExecutionOptions.scala
@@ -13,7 +13,8 @@ import firrtl.{ExecutionOptionsManager, ComposableOptions}
* @note this extends FirrtlExecutionOptions which extends CommonOptions providing easy access to down chain options
*/
case class ChiselExecutionOptions(
- runFirrtlCompiler: Boolean = true
+ runFirrtlCompiler: Boolean = true,
+ printFullStackTrace: Boolean = false
// var runFirrtlAsProcess: Boolean = false
) extends ComposableOptions
@@ -30,5 +31,11 @@ trait HasChiselExecutionOptions {
chiselOptions = chiselOptions.copy(runFirrtlCompiler = false)
}
.text("Stop after chisel emits chirrtl file")
+
+ parser.opt[Unit]("full-stacktrace")
+ .foreach { _ =>
+ chiselOptions = chiselOptions.copy(printFullStackTrace = true)
+ }
+ .text("Do not trim stack trace")
}
diff --git a/src/main/scala/chisel3/Driver.scala b/src/main/scala/chisel3/Driver.scala
index c0570662..9be129be 100644
--- a/src/main/scala/chisel3/Driver.scala
+++ b/src/main/scala/chisel3/Driver.scala
@@ -2,6 +2,7 @@
package chisel3
+import chisel3.internal.ErrorLog
import chisel3.internal.firrtl.Converter
import chisel3.experimental.{RawModule, RunFirrtlTransform}
@@ -172,7 +173,7 @@ object Driver extends BackendCompilationUtilities {
/**
* Run the chisel3 compiler and possibly the firrtl compiler with options specified
- *
+ *
* @param optionsManager The options specified
* @param dut The device under test
* @return An execution result with useful stuff, or failure with message
@@ -180,57 +181,72 @@ object Driver extends BackendCompilationUtilities {
def execute(
optionsManager: ExecutionOptionsManager with HasChiselExecutionOptions with HasFirrtlOptions,
dut: () => RawModule): ChiselExecutionResult = {
- val circuit = elaborate(dut)
-
- // this little hack let's us set the topName with the circuit name if it has not been set from args
- optionsManager.setTopNameIfNotSet(circuit.name)
-
- val firrtlOptions = optionsManager.firrtlOptions
- val chiselOptions = optionsManager.chiselOptions
-
- val firrtlCircuit = Converter.convert(circuit)
-
- // Still emit to leave an artifact (and because this always has been the behavior)
- val firrtlString = Driver.emit(circuit)
- val firrtlFileName = firrtlOptions.getInputFileName(optionsManager)
- val firrtlFile = new File(firrtlFileName)
-
- val w = new FileWriter(firrtlFile)
- w.write(firrtlString)
- w.close()
-
- // Emit the annotations because it has always been the behavior
- val annotationFile = new File(optionsManager.getBuildFileName("anno.json"))
- val af = new FileWriter(annotationFile)
- val firrtlAnnos = circuit.annotations.map(_.toFirrtl)
- af.write(JsonProtocol.serialize(firrtlAnnos))
- af.close()
-
- /** Find the set of transform classes associated with annotations then
- * instantiate an instance of each transform
- * @note Annotations targeting firrtl.Transform will not result in any
- * transform being instantiated
- */
- val transforms = circuit.annotations
- .collect { case anno: RunFirrtlTransform => anno.transformClass }
- .distinct
- .filterNot(_ == classOf[firrtl.Transform])
- .map { transformClass: Class[_ <: Transform] =>
- transformClass.newInstance()
- }
- /* This passes the firrtl source and annotations directly to firrtl */
- optionsManager.firrtlOptions = optionsManager.firrtlOptions.copy(
- firrtlCircuit = Some(firrtlCircuit),
- annotations = optionsManager.firrtlOptions.annotations ++ firrtlAnnos,
- customTransforms = optionsManager.firrtlOptions.customTransforms ++ transforms.toList)
-
- val firrtlExecutionResult = if(chiselOptions.runFirrtlCompiler) {
- Some(firrtl.Driver.execute(optionsManager))
- }
- else {
- None
+ val circuitOpt = try {
+ Some(elaborate(dut))
+ } catch {
+ case ce: ChiselException =>
+ val stackTrace = if (!optionsManager.chiselOptions.printFullStackTrace) {
+ ce.chiselStackTrace
+ } else {
+ val sw = new StringWriter
+ ce.printStackTrace(new PrintWriter(sw))
+ sw.toString
+ }
+ stackTrace.lines.foreach(line => println(s"${ErrorLog.errTag} $line"))
+ None
}
- ChiselExecutionSuccess(Some(circuit), firrtlString, firrtlExecutionResult)
+
+ circuitOpt.map { circuit =>
+ // this little hack let's us set the topName with the circuit name if it has not been set from args
+ optionsManager.setTopNameIfNotSet(circuit.name)
+
+ val firrtlOptions = optionsManager.firrtlOptions
+ val chiselOptions = optionsManager.chiselOptions
+
+ val firrtlCircuit = Converter.convert(circuit)
+
+ // Still emit to leave an artifact (and because this always has been the behavior)
+ val firrtlString = Driver.emit(circuit)
+ val firrtlFileName = firrtlOptions.getInputFileName(optionsManager)
+ val firrtlFile = new File(firrtlFileName)
+
+ val w = new FileWriter(firrtlFile)
+ w.write(firrtlString)
+ w.close()
+
+ // Emit the annotations because it has always been the behavior
+ val annotationFile = new File(optionsManager.getBuildFileName("anno.json"))
+ val af = new FileWriter(annotationFile)
+ val firrtlAnnos = circuit.annotations.map(_.toFirrtl)
+ af.write(JsonProtocol.serialize(firrtlAnnos))
+ af.close()
+
+ /** Find the set of transform classes associated with annotations then
+ * instantiate an instance of each transform
+ * @note Annotations targeting firrtl.Transform will not result in any
+ * transform being instantiated
+ */
+ val transforms = circuit.annotations
+ .collect { case anno: RunFirrtlTransform => anno.transformClass }
+ .distinct
+ .filterNot(_ == classOf[firrtl.Transform])
+ .map { transformClass: Class[_ <: Transform] =>
+ transformClass.newInstance()
+ }
+ /* This passes the firrtl source and annotations directly to firrtl */
+ optionsManager.firrtlOptions = optionsManager.firrtlOptions.copy(
+ firrtlCircuit = Some(firrtlCircuit),
+ annotations = optionsManager.firrtlOptions.annotations ++ firrtlAnnos,
+ customTransforms = optionsManager.firrtlOptions.customTransforms ++ transforms.toList)
+
+ val firrtlExecutionResult = if(chiselOptions.runFirrtlCompiler) {
+ Some(firrtl.Driver.execute(optionsManager))
+ }
+ else {
+ None
+ }
+ ChiselExecutionSuccess(Some(circuit), firrtlString, firrtlExecutionResult)
+ }.getOrElse(ChiselExecutionFailure("could not elaborate circuit"))
}
/**