From e548210ef42e634e75cf283292685728114694c6 Mon Sep 17 00:00:00 2001 From: John Wright Date: Fri, 29 Mar 2019 13:55:18 -0700 Subject: [PATCH] Add options to emit top/harness firrtl and annotations (#54) --- .../src/main/scala/transforms/Generate.scala | 91 ++++++++++++++++++- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/tapeout/src/main/scala/transforms/Generate.scala b/tapeout/src/main/scala/transforms/Generate.scala index 629de58c..2878aa7a 100644 --- a/tapeout/src/main/scala/transforms/Generate.scala +++ b/tapeout/src/main/scala/transforms/Generate.scala @@ -37,6 +37,28 @@ trait HasTapeoutOptions { self: ExecutionOptionsManager with HasFirrtlOptions => "use this to set synTop" } + parser.opt[String]("top-fir") + .abbr("tsf") + .valueName("") + .foreach { x => + tapeoutOptions = tapeoutOptions.copy( + topFir = Some(x) + ) + }.text { + "use this to set topFir" + } + + parser.opt[String]("top-anno-out") + .abbr("tsaof") + .valueName("") + .foreach { x => + tapeoutOptions = tapeoutOptions.copy( + topAnnoOut = Some(x) + ) + }.text { + "use this to set topAnnoOut" + } + parser.opt[String]("harness-top") .abbr("tht") .valueName("") @@ -48,12 +70,38 @@ trait HasTapeoutOptions { self: ExecutionOptionsManager with HasFirrtlOptions => "use this to set harnessTop" } + parser.opt[String]("harness-fir") + .abbr("thf") + .valueName("") + .foreach { x => + tapeoutOptions = tapeoutOptions.copy( + harnessFir = Some(x) + ) + }.text { + "use this to set harnessFir" + } + + parser.opt[String]("harness-anno-out") + .abbr("thaof") + .valueName("") + .foreach { x => + tapeoutOptions = tapeoutOptions.copy( + harnessAnnoOut = Some(x) + ) + }.text { + "use this to set harnessAnnoOut" + } + } case class TapeoutOptions( harnessOutput: Option[String] = None, synTop: Option[String] = None, - harnessTop: Option[String] = None + topFir: Option[String] = None, + topAnnoOut: Option[String] = None, + harnessTop: Option[String] = None, + harnessFir: Option[String] = None, + harnessAnnoOut: Option[String] = None ) extends LazyLogging // Requires two phases, one to collect modules below synTop in the hierarchy @@ -99,7 +147,26 @@ sealed trait GenerateTopAndHarnessApp extends LazyLogging { this: App => customTransforms = firrtlOptions.customTransforms ++ topTransforms ) - firrtl.Driver.execute(optionsManager) + val result = firrtl.Driver.execute(optionsManager) + + result match { + case x: FirrtlExecutionSuccess => + tapeoutOptions.topFir.foreach { firFile => + val outputFile = new java.io.PrintWriter(firFile) + outputFile.write(x.circuitState.circuit.serialize) + outputFile.close() + } + tapeoutOptions.topAnnoOut.foreach { annoFile => + val outputFile = new java.io.PrintWriter(annoFile) + outputFile.write(JsonProtocol.serialize(x.circuitState.annotations.filter(_ match { + case EmittedVerilogCircuitAnnotation(_) => false + case _ => true + }))) + outputFile.close() + } + case _ => + } + } // Harness Generation @@ -109,7 +176,25 @@ sealed trait GenerateTopAndHarnessApp extends LazyLogging { this: App => customTransforms = harnessTransforms ) - firrtl.Driver.execute(optionsManager) + val result = firrtl.Driver.execute(optionsManager) + + result match { + case x: FirrtlExecutionSuccess => + tapeoutOptions.harnessFir.foreach { firFile => + val outputFile = new java.io.PrintWriter(firFile) + outputFile.write(x.circuitState.circuit.serialize) + outputFile.close() + } + tapeoutOptions.harnessAnnoOut.foreach { annoFile => + val outputFile = new java.io.PrintWriter(annoFile) + outputFile.write(JsonProtocol.serialize(x.circuitState.annotations.filter(_ match { + case EmittedVerilogCircuitAnnotation(_) => false + case _ => true + }))) + outputFile.close() + } + case _ => + } } }