diff options
| author | Chick Markley | 2016-10-25 00:23:32 -0700 |
|---|---|---|
| committer | GitHub | 2016-10-25 00:23:32 -0700 |
| commit | d344f4400ad5e9c71c97229e33660bbe067260a0 (patch) | |
| tree | e0426f4c9cc608db5c5f3a6a81f3873197424511 /src/main/scala/firrtl/ExecutionOptionsManager.scala | |
| parent | aca23a617999287183effea0272a4c95b27ff4b2 (diff) | |
Logger 1 (#338)
* Create a simple system for executions and command line parameters
New model for tracking parameters and having those parameters
register scopt command to allow the parameters to be set by
command line args.
Create composable forms of the these parameters to allow separate
elements of the chisel3 toolchain to combine these parameters
Create execution return structures that simplify return values
to earlier toolchain elements
* just a little bit of cleanup
* Fixes for Adam's comments on PR
* knuckled under to self-pressure to allow former -i and -o to work
* knuckled under to self-pressure to allow former -i and -o to work
* show defaults for command line args with them
* A couple of fixes from merging latest master
* Implement a log4scala like logging system
This system has the rather remarkable property
that it is possible to turn it on conveniently when
you want it. It also provides for class level granularity
as well as the traditional Error, Warn, Info, Debug
* some style fixes and change infoMode default to append per PR #328
* some style fixes and change infoMode default to append per PR #328
* support -i -o and -X
a couple of indentation and spacing fixes
Diffstat (limited to 'src/main/scala/firrtl/ExecutionOptionsManager.scala')
| -rw-r--r-- | src/main/scala/firrtl/ExecutionOptionsManager.scala | 80 |
1 files changed, 76 insertions, 4 deletions
diff --git a/src/main/scala/firrtl/ExecutionOptionsManager.scala b/src/main/scala/firrtl/ExecutionOptionsManager.scala index 05a9f487..ff725e30 100644 --- a/src/main/scala/firrtl/ExecutionOptionsManager.scala +++ b/src/main/scala/firrtl/ExecutionOptionsManager.scala @@ -5,6 +5,7 @@ package firrtl import firrtl.Annotations._ import firrtl.Parser._ import firrtl.passes.memlib.ReplSeqMemAnnotation +import logger.LogLevel import scopt.OptionParser import scala.collection.Seq @@ -15,6 +16,10 @@ import scala.collection.Seq */ trait ComposableOptions +abstract class HasParser(applicationName: String) { + final val parser: OptionParser[Unit] = new OptionParser[Unit](applicationName) {} +} + /** * Most of the chisel toolchain components require a topName which defines a circuit or a device under test. * Much of the work that is done takes place in a directory. @@ -22,10 +27,22 @@ trait ComposableOptions * For example, in chisel, by deferring this it is possible for the execute there to first elaborate the * circuit and then set the topName from that if it has not already been set. */ -case class CommonOptions(topName: String = "", targetDirName: String = "test_run_dir") extends ComposableOptions - -abstract class HasParser(applicationName: String) { - final val parser: OptionParser[Unit] = new OptionParser[Unit](applicationName) {} +case class CommonOptions( + topName: String = "", + targetDirName: String = "test_run_dir", + globalLogLevel: LogLevel.Value = LogLevel.Error, + logToFile: Boolean = false, + logClassNames: Boolean = false, + classLogLevels: Map[String, LogLevel.Value] = Map.empty) extends ComposableOptions { + + def getLogFileName(optionsManager: ExecutionOptionsManager): String = { + if(topName.isEmpty) { + optionsManager.getBuildFileName("log", "firrtl") + } + else { + optionsManager.getBuildFileName("log") + } + } } trait HasCommonOptions { @@ -49,6 +66,61 @@ trait HasCommonOptions { } .text(s"This options defines a work directory for intermediate files, default is ${commonOptions.targetDirName}") + parser.opt[String]("log-level") + .abbr("ll").valueName("<Error|Warn|Info|Debug|Trace>") + .foreach { x => + val level = x.toLowerCase match { + case "error" => LogLevel.Error + case "warn" => LogLevel.Warn + case "info" => LogLevel.Info + case "debug" => LogLevel.Debug + case "trace" => LogLevel.Trace + } + commonOptions = commonOptions.copy(globalLogLevel = level) + } + .validate { x => + if (Array("error", "warn", "info", "debug", "trace").contains(x.toLowerCase)) parser.success + else parser.failure(s"$x bad value must be one of ignore|use|gen|append") + } + .text(s"This options defines a work directory for intermediate files, default is ${commonOptions.targetDirName}") + + parser.opt[Seq[String]]("class-log-level") + .abbr("cll").valueName("<FullClassName:[Error|Warn|Info|Debug|Trace]>[,...]") + .foreach { x => + val logAssignments = x.map { y => + val className :: levelName :: _ = y.split(":").toList + + val level = levelName.toLowerCase match { + case "error" => LogLevel.Error + case "warn" => LogLevel.Warn + case "info" => LogLevel.Info + case "debug" => LogLevel.Debug + case "trace" => LogLevel.Trace + case _ => + throw new Exception(s"Error: bad command line arguments for --class-log-level $x") + } + className -> level + } + + commonOptions = commonOptions.copy(classLogLevels = commonOptions.classLogLevels ++ logAssignments) + + } + .text(s"This options defines a work directory for intermediate files, default is ${commonOptions.targetDirName}") + + parser.opt[Unit]("log-to-file") + .abbr("ltf") + .foreach { _ => + commonOptions = commonOptions.copy(logToFile = true) + } + .text(s"default logs to stdout, this flags writes to topName.log or firrtl.log if no topName") + + parser.opt[Unit]("log-class-names") + .abbr("lcn") + .foreach { _ => + commonOptions = commonOptions.copy(logClassNames = true) + } + .text(s"shows class names and log level in logging output, useful for target --class-log-level") + parser.help("help").text("prints this usage text") } |
