aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/Driver.scala
diff options
context:
space:
mode:
authorChick Markley2017-05-18 12:23:40 -0700
committerGitHub2017-05-18 12:23:40 -0700
commit9c50af20027801d8623edd1db2c63c4eb449b3ae (patch)
treebee5ddcab07ca0e498c52a53f0b8d3e1c3b22293 /src/main/scala/firrtl/Driver.scala
parentd824c60c9643973e0ae9cddc5007b3d9592f8a52 (diff)
Upgrade Logging facility (#488)
* Upgrade Logging facility Make thread-safe Make logging by package name work Use caching of class names to level for performance Make some tests to show this working * quick fix for dynamic logging variable * A number of changes based on Adam's suggestions Default LoggerState But there is an invoke method now to handle threading issues. This should be propagated to other projects Driver.execute methods * Add built-in support for string capture of Logging * Usability fixes for logging stuff. Settings made to the logger prior to execute/invoke will be passed along if possible. * A couple style fixes Comment and privatize Logger state * Name and save string buffers used for logging * Fix default logging state setting Fix logging test, did not have change to command argument * comment out logging in InlineInstanceTests * Changed invoke to makeScope Nested makeScopes share same state object Removed earlier named string buffer implementation * Better name for captor get data * Add trace tests to make sure it works too * Fix call into logger settings
Diffstat (limited to 'src/main/scala/firrtl/Driver.scala')
-rw-r--r--src/main/scala/firrtl/Driver.scala72
1 files changed, 37 insertions, 35 deletions
diff --git a/src/main/scala/firrtl/Driver.scala b/src/main/scala/firrtl/Driver.scala
index 5db572fe..5e3d046a 100644
--- a/src/main/scala/firrtl/Driver.scala
+++ b/src/main/scala/firrtl/Driver.scala
@@ -39,6 +39,7 @@ import Utils.throwInternalError
*/
object Driver {
+ //noinspection ScalaDeprecation
// Compiles circuit. First parses a circuit from an input file,
// executes all compiler passes, and writes result to an output
// file.
@@ -118,51 +119,51 @@ object Driver {
* Run the firrtl compiler using the provided option
*
* @param optionsManager the desired flags to the compiler
- * @return a FirrtlExectionResult indicating success or failure, provide access to emitted data on success
+ * @return a FirrtlExecutionResult indicating success or failure, provide access to emitted data on success
* for downstream tools as desired
*/
+ //scalastyle:off cyclomatic.complexity method.length
def execute(optionsManager: ExecutionOptionsManager with HasFirrtlOptions): FirrtlExecutionResult = {
def firrtlConfig = optionsManager.firrtlOptions
- Logger.setOptions(optionsManager)
-
- val firrtlSource = firrtlConfig.firrtlSource match {
- case Some(text) => text.split("\n").toIterator
- case None =>
- if(optionsManager.topName.isEmpty && firrtlConfig.inputFileNameOverride.isEmpty) {
- val message = "either top-name or input-file-override must be set"
- dramaticError(message)
- return FirrtlExecutionFailure(message)
- }
- if(
- optionsManager.topName.isEmpty &&
- firrtlConfig.inputFileNameOverride.nonEmpty &&
- firrtlConfig.outputFileNameOverride.isEmpty) {
- val message = "inputFileName set but neither top-name or output-file-override is set"
- dramaticError(message)
- return FirrtlExecutionFailure(message)
- }
- val inputFileName = firrtlConfig.getInputFileName(optionsManager)
- try {
- io.Source.fromFile(inputFileName).getLines()
- }
- catch {
- case _: FileNotFoundException =>
- val message = s"Input file $inputFileName not found"
+ Logger.makeScope(optionsManager) {
+ val firrtlSource = firrtlConfig.firrtlSource match {
+ case Some(text) => text.split("\n").toIterator
+ case None =>
+ if (optionsManager.topName.isEmpty && firrtlConfig.inputFileNameOverride.isEmpty) {
+ val message = "either top-name or input-file-override must be set"
dramaticError(message)
return FirrtlExecutionFailure(message)
}
- }
+ if (
+ optionsManager.topName.isEmpty &&
+ firrtlConfig.inputFileNameOverride.nonEmpty &&
+ firrtlConfig.outputFileNameOverride.isEmpty) {
+ val message = "inputFileName set but neither top-name or output-file-override is set"
+ dramaticError(message)
+ return FirrtlExecutionFailure(message)
+ }
+ val inputFileName = firrtlConfig.getInputFileName(optionsManager)
+ try {
+ io.Source.fromFile(inputFileName).getLines()
+ }
+ catch {
+ case _: FileNotFoundException =>
+ val message = s"Input file $inputFileName not found"
+ dramaticError(message)
+ return FirrtlExecutionFailure(message)
+ }
+ }
- loadAnnotations(optionsManager)
+ loadAnnotations(optionsManager)
- val parsedInput = Parser.parse(firrtlSource, firrtlConfig.infoMode)
+ val parsedInput = Parser.parse(firrtlSource, firrtlConfig.infoMode)
- // Does this need to be before calling compiler?
- optionsManager.makeTargetDir()
+ // Does this need to be before calling compiler?
+ optionsManager.makeTargetDir()
- // Output Annotations
- val outputAnnos = firrtlConfig.getEmitterAnnos(optionsManager)
+ // Output Annotations
+ val outputAnnos = firrtlConfig.getEmitterAnnos(optionsManager)
// Should these and outputAnnos be moved to loadAnnotations?
val globalAnnos = Seq(TargetDirAnnotation(optionsManager.targetDirName))
@@ -196,7 +197,8 @@ object Driver {
"" // Should we return something different here?
}
- FirrtlExecutionSuccess(firrtlConfig.compilerName, emittedRes)
+ FirrtlExecutionSuccess(firrtlConfig.compilerName, emittedRes)
+ }
}
/**
@@ -295,7 +297,7 @@ object FileUtils {
def isCommandAvailable(cmd: String): Boolean = {
// Eat any output.
val sb = new StringBuffer
- val ioToDevNull = BasicIO(false, sb, None)
+ val ioToDevNull = BasicIO(withIn = false, sb, None)
Seq("bash", "-c", "which %s".format(cmd)).run(ioToDevNull).exitValue == 0
}