Fix null pointer exception in options parser

This commit is contained in:
Paul Rigge
2019-02-06 12:26:53 -08:00
committed by John Wright
parent f310d45381
commit 801abd98bb
2 changed files with 26 additions and 12 deletions

View File

@@ -28,6 +28,17 @@ trait HasTapeoutOptions { self: ExecutionOptionsManager with HasFirrtlOptions =>
parser.note("tapeout options") parser.note("tapeout options")
parser.opt[String]("top-o")
.abbr("tto")
.valueName("<top-output>")
.foreach { x =>
tapeoutOptions = tapeoutOptions.copy(
topOutput = Some(x)
)
}.text {
"use this to generate top at <top-output>"
}
parser.opt[String]("harness-o") parser.opt[String]("harness-o")
.abbr("tho") .abbr("tho")
.valueName("<harness-output>") .valueName("<harness-output>")
@@ -41,7 +52,7 @@ trait HasTapeoutOptions { self: ExecutionOptionsManager with HasFirrtlOptions =>
parser.opt[String]("syn-top") parser.opt[String]("syn-top")
.abbr("tst") .abbr("tst")
.valueName("<syn-top") .valueName("<syn-top>")
.foreach { x => .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( tapeoutOptions = tapeoutOptions.copy(
synTop = Some(x) synTop = Some(x)
@@ -89,10 +100,13 @@ case class TapeoutOptions(
// Requires two phases, one to collect modules below synTop in the hierarchy // Requires two phases, one to collect modules below synTop in the hierarchy
// and a second to remove those modules to generate the test harness // and a second to remove those modules to generate the test harness
sealed trait GenerateTopAndHarnessApp extends App with LazyLogging { sealed trait GenerateTopAndHarnessApp extends LazyLogging { this: App =>
val optionsManager = new ExecutionOptionsManager("tapeout") with HasFirrtlOptions with HasTapeoutOptions lazy val optionsManager = {
if (!optionsManager.parse(args)) { val optionsManager = new ExecutionOptionsManager("tapeout") with HasFirrtlOptions with HasTapeoutOptions
throw new Exception("Error parsing options!") if (!optionsManager.parse(args)) {
throw new Exception("Error parsing options!")
}
optionsManager
} }
lazy val options = optionsManager.tapeoutOptions lazy val options = optionsManager.tapeoutOptions
lazy val input = options.input lazy val input = options.input
@@ -195,17 +209,17 @@ sealed trait GenerateTopAndHarnessApp extends App with LazyLogging {
} }
} }
object GenerateTop extends GenerateTopAndHarnessApp { object GenerateTop extends App with GenerateTopAndHarnessApp {
// warn about unused options // warn about unused options
harnessOutput.foreach(n => logger.warn(s"Not using harness output filename $n since you asked for just a top-level output.")) harnessOutput.foreach(n => logger.warn(s"Not using harness output filename $n since you asked for just a top-level output."))
topOutput.foreach(_.foreach{ topOutput.foreach(
n => logger.warn(s"Not using generic output filename $n since you asked for just a top-level output and also specified a generic output.")}) n => logger.warn(s"Not using generic output filename $n since you asked for just a top-level output and also specified a generic output."))
// Only need a single phase to generate the top module // Only need a single phase to generate the top module
firstPhase(top = true, harness = false) firstPhase(top = true, harness = false)
execute execute
} }
object GenerateHarness extends GenerateTopAndHarnessApp { object GenerateHarness extends App with GenerateTopAndHarnessApp {
// warn about unused options // warn about unused options
topOutput.foreach(n => logger.warn(s"Not using top-level output filename $n since you asked for just a test harness.")) topOutput.foreach(n => logger.warn(s"Not using top-level output filename $n since you asked for just a test harness."))
annoFile.foreach(n => logger.warn(s"Not using annotations file $n since you asked for just a test harness.")) annoFile.foreach(n => logger.warn(s"Not using annotations file $n since you asked for just a test harness."))
@@ -213,15 +227,15 @@ object GenerateHarness extends GenerateTopAndHarnessApp {
n => logger.warn(s"Not using SeqMem flags $n since you asked for just a test harness.") } n => logger.warn(s"Not using SeqMem flags $n since you asked for just a test harness.") }
listClocks.filter(_ != "-o:unused.clocks").foreach { listClocks.filter(_ != "-o:unused.clocks").foreach {
n => logger.warn(s"Not using clocks list $n since you asked for just a test harness.") } n => logger.warn(s"Not using clocks list $n since you asked for just a test harness.") }
harnessOutput.foreach(_.foreach{ harnessOutput.foreach(
n => logger.warn(s"Not using generic output filename $n since you asked for just a test harness and also specified a generic output.")}) n => logger.warn(s"Not using generic output filename $n since you asked for just a test harness and also specified a generic output."))
// Do minimal work for the first phase to generate test harness // Do minimal work for the first phase to generate test harness
firstPhase(top = false, harness = true) firstPhase(top = false, harness = true)
secondPhase secondPhase
execute execute
} }
object GenerateTopAndHarness extends GenerateTopAndHarnessApp { object GenerateTopAndHarness extends App with GenerateTopAndHarnessApp {
// warn about unused options // warn about unused options
output.foreach(n => logger.warn(s"Not using generic output filename $n since you asked for both a top-level output and a test harness.")) output.foreach(n => logger.warn(s"Not using generic output filename $n since you asked for both a top-level output and a test harness."))
// Do everything, top and harness generation // Do everything, top and harness generation