Modernize deprecated Chisel/Firrtl constructs

- Build out a stage for tapeout
  - Refactor annotation construction
  - Create a CLI handler
  - create a TapeOutStage
- Remove outputForm reference from EnumerateModules
- New GenerateTopAndHarness is fresh implmentation of Generate.scala
- GenerateTopSpec is a work in progress
This commit is contained in:
chick
2021-02-09 14:04:24 -08:00
parent ca4013b830
commit afcdcc6c2d
6 changed files with 626 additions and 277 deletions

View File

@@ -35,7 +35,6 @@ class EnumerateModules(enumerate: (Module) => Unit)
def transforms: Seq[Transform] = Seq(new EnumerateModulesPass(enumerate)) def transforms: Seq[Transform] = Seq(new EnumerateModulesPass(enumerate))
def execute(state: CircuitState): CircuitState = { def execute(state: CircuitState): CircuitState = {
val ret = runTransforms(state) runTransforms(state)
CircuitState(ret.circuit, outputForm, ret.annotations, ret.renames)
} }
} }

View File

@@ -1,274 +1,274 @@
package barstools.tapeout.transforms //package barstools.tapeout.transforms
//
import firrtl._ //import firrtl._
import firrtl.annotations._ //import firrtl.annotations._
import firrtl.ir._ //import firrtl.ir._
import firrtl.passes.memlib.ReplSeqMemAnnotation //import firrtl.passes.memlib.ReplSeqMemAnnotation
import firrtl.stage.FirrtlCircuitAnnotation //import firrtl.stage.FirrtlCircuitAnnotation
import firrtl.transforms.BlackBoxResourceFileNameAnno //import firrtl.transforms.BlackBoxResourceFileNameAnno
import logger.LazyLogging //import logger.LazyLogging
//
trait HasTapeoutOptions { self: ExecutionOptionsManager with HasFirrtlOptions => //trait HasTapeoutOptions { self: ExecutionOptionsManager with HasFirrtlOptions =>
var tapeoutOptions = TapeoutOptions() // var tapeoutOptions = TapeoutOptions()
//
parser.note("tapeout options") // parser.note("tapeout options")
//
parser // parser
.opt[String]("harness-o") // .opt[String]("harness-o")
.abbr("tho") // .abbr("tho")
.valueName("<harness-output>") // .valueName("<harness-output>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
harnessOutput = Some(x) // harnessOutput = Some(x)
) // )
} // }
.text { // .text {
"use this to generate a harness at <harness-output>" // "use this to generate a harness at <harness-output>"
} // }
//
parser // parser
.opt[String]("syn-top") // .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)
) // )
} // }
.text { // .text {
"use this to set synTop" // "use this to set synTop"
} // }
//
parser // parser
.opt[String]("top-fir") // .opt[String]("top-fir")
.abbr("tsf") // .abbr("tsf")
.valueName("<top-fir>") // .valueName("<top-fir>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
topFir = Some(x) // topFir = Some(x)
) // )
} // }
.text { // .text {
"use this to set topFir" // "use this to set topFir"
} // }
//
parser // parser
.opt[String]("top-anno-out") // .opt[String]("top-anno-out")
.abbr("tsaof") // .abbr("tsaof")
.valueName("<top-anno-out>") // .valueName("<top-anno-out>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
topAnnoOut = Some(x) // topAnnoOut = Some(x)
) // )
} // }
.text { // .text {
"use this to set topAnnoOut" // "use this to set topAnnoOut"
} // }
//
parser // parser
.opt[String]("top-dotf-out") // .opt[String]("top-dotf-out")
.abbr("tdf") // .abbr("tdf")
.valueName("<top-dotf-out>") // .valueName("<top-dotf-out>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
topDotfOut = Some(x) // topDotfOut = Some(x)
) // )
} // }
.text { // .text {
"use this to set the filename for the top resource .f file" // "use this to set the filename for the top resource .f file"
} // }
//
parser // parser
.opt[String]("harness-top") // .opt[String]("harness-top")
.abbr("tht") // .abbr("tht")
.valueName("<harness-top>") // .valueName("<harness-top>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
harnessTop = Some(x) // harnessTop = Some(x)
) // )
} // }
.text { // .text {
"use this to set harnessTop" // "use this to set harnessTop"
} // }
//
parser // parser
.opt[String]("harness-fir") // .opt[String]("harness-fir")
.abbr("thf") // .abbr("thf")
.valueName("<harness-fir>") // .valueName("<harness-fir>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
harnessFir = Some(x) // harnessFir = Some(x)
) // )
} // }
.text { // .text {
"use this to set harnessFir" // "use this to set harnessFir"
} // }
//
parser // parser
.opt[String]("harness-anno-out") // .opt[String]("harness-anno-out")
.abbr("thaof") // .abbr("thaof")
.valueName("<harness-anno-out>") // .valueName("<harness-anno-out>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
harnessAnnoOut = Some(x) // harnessAnnoOut = Some(x)
) // )
} // }
.text { // .text {
"use this to set harnessAnnoOut" // "use this to set harnessAnnoOut"
} // }
//
parser // parser
.opt[String]("harness-dotf-out") // .opt[String]("harness-dotf-out")
.abbr("hdf") // .abbr("hdf")
.valueName("<harness-dotf-out>") // .valueName("<harness-dotf-out>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
harnessDotfOut = Some(x) // harnessDotfOut = Some(x)
) // )
} // }
.text { // .text {
"use this to set the filename for the harness resource .f file" // "use this to set the filename for the harness resource .f file"
} // }
//
parser // parser
.opt[String]("harness-conf") // .opt[String]("harness-conf")
.abbr("thconf") // .abbr("thconf")
.valueName("<harness-conf-file>") // .valueName("<harness-conf-file>")
.foreach { x => // .foreach { x =>
tapeoutOptions = tapeoutOptions.copy( // tapeoutOptions = tapeoutOptions.copy(
harnessConf = Some(x) // harnessConf = Some(x)
) // )
} // }
.text { // .text {
"use this to set the harness conf file location" // "use this to set the harness conf file location"
} // }
//
} //}
//
case class TapeoutOptions( //case class TapeoutOptions(
harnessOutput: Option[String] = None, // harnessOutput: Option[String] = None,
synTop: Option[String] = None, // synTop: Option[String] = None,
topFir: Option[String] = None, // topFir: Option[String] = None,
topAnnoOut: Option[String] = None, // topAnnoOut: Option[String] = None,
topDotfOut: Option[String] = None, // topDotfOut: Option[String] = None,
harnessTop: Option[String] = None, // harnessTop: Option[String] = None,
harnessFir: Option[String] = None, // harnessFir: Option[String] = None,
harnessAnnoOut: Option[String] = None, // harnessAnnoOut: Option[String] = None,
harnessDotfOut: Option[String] = None, // harnessDotfOut: Option[String] = None,
harnessConf: Option[String] = None) // harnessConf: Option[String] = None)
extends LazyLogging // extends LazyLogging
//
// 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 LazyLogging { this: App => //sealed trait GenerateTopAndHarnessApp extends LazyLogging { this: App =>
lazy val optionsManager = { // lazy val optionsManager = {
val optionsManager = new ExecutionOptionsManager("tapeout") with HasFirrtlOptions with HasTapeoutOptions // val optionsManager = new ExecutionOptionsManager("tapeout") with HasFirrtlOptions with HasTapeoutOptions
if (!optionsManager.parse(args)) { // if (!optionsManager.parse(args)) {
throw new Exception("Error parsing options!") // throw new Exception("Error parsing options!")
} // }
optionsManager // optionsManager
} // }
lazy val tapeoutOptions = optionsManager.tapeoutOptions // lazy val tapeoutOptions = optionsManager.tapeoutOptions
// Tapeout options // // Tapeout options
lazy val synTop = tapeoutOptions.synTop // lazy val synTop = tapeoutOptions.synTop
lazy val harnessTop = tapeoutOptions.harnessTop // lazy val harnessTop = tapeoutOptions.harnessTop
lazy val firrtlOptions = optionsManager.firrtlOptions // lazy val firrtlOptions = optionsManager.firrtlOptions
// FIRRTL options // // FIRRTL options
lazy val annoFiles = firrtlOptions.annotationFileNames // lazy val annoFiles = firrtlOptions.annotationFileNames
//
// order is determined by DependencyAPIMigration // // order is determined by DependencyAPIMigration
val topTransforms = Seq( // val topTransforms = Seq(
new ReParentCircuit, // new ReParentCircuit,
new RemoveUnusedModules // new RemoveUnusedModules
) // )
//
lazy val rootCircuitTarget = CircuitTarget(harnessTop.get) // lazy val rootCircuitTarget = CircuitTarget(harnessTop.get)
//
lazy val topAnnos = synTop.map(st => ReParentCircuitAnnotation(rootCircuitTarget.module(st))) ++ // lazy val topAnnos = synTop.map(st => ReParentCircuitAnnotation(rootCircuitTarget.module(st))) ++
tapeoutOptions.topDotfOut.map(BlackBoxResourceFileNameAnno(_)) // tapeoutOptions.topDotfOut.map(BlackBoxResourceFileNameAnno(_))
//
lazy val topOptions = firrtlOptions.copy( // lazy val topOptions = firrtlOptions.copy(
customTransforms = firrtlOptions.customTransforms ++ topTransforms, // customTransforms = firrtlOptions.customTransforms ++ topTransforms,
annotations = firrtlOptions.annotations ++ topAnnos // annotations = firrtlOptions.annotations ++ topAnnos
) // )
//
// order is determined by DependencyAPIMigration // // order is determined by DependencyAPIMigration
val harnessTransforms = Seq( // val harnessTransforms = Seq(
new ConvertToExtMod, // new ConvertToExtMod,
new RemoveUnusedModules, // new RemoveUnusedModules,
new AvoidExtModuleCollisions, // new AvoidExtModuleCollisions,
new AddSuffixToModuleNames // new AddSuffixToModuleNames
) // )
//
// Dump firrtl and annotation files // // Dump firrtl and annotation files
protected def dump(res: FirrtlExecutionSuccess, firFile: Option[String], annoFile: Option[String]): Unit = { // protected def dump(res: FirrtlExecutionSuccess, firFile: Option[String], annoFile: Option[String]): Unit = {
firFile.foreach { firPath => // firFile.foreach { firPath =>
val outputFile = new java.io.PrintWriter(firPath) // val outputFile = new java.io.PrintWriter(firPath)
outputFile.write(res.circuitState.circuit.serialize) // outputFile.write(res.circuitState.circuit.serialize)
outputFile.close() // outputFile.close()
} // }
annoFile.foreach { annoPath => // annoFile.foreach { annoPath =>
val outputFile = new java.io.PrintWriter(annoPath) // val outputFile = new java.io.PrintWriter(annoPath)
outputFile.write(JsonProtocol.serialize(res.circuitState.annotations.filter(_ match { // outputFile.write(JsonProtocol.serialize(res.circuitState.annotations.filter(_ match {
case da: DeletedAnnotation => false // case da: DeletedAnnotation => false
case ec: EmittedComponent => false // case ec: EmittedComponent => false
case ea: EmittedAnnotation[_] => false // case ea: EmittedAnnotation[_] => false
case fca: FirrtlCircuitAnnotation => false // case fca: FirrtlCircuitAnnotation => false
case _ => true // case _ => true
}))) // })))
outputFile.close() // outputFile.close()
} // }
} // }
//
// Top Generation // // Top Generation
protected def executeTop(): Seq[ExtModule] = { // protected def executeTop(): Seq[ExtModule] = {
optionsManager.firrtlOptions = topOptions // optionsManager.firrtlOptions = topOptions
val result = firrtl.Driver.execute(optionsManager) // val result = firrtl.Driver.execute(optionsManager)
result match { // result match {
case x: FirrtlExecutionSuccess => // case x: FirrtlExecutionSuccess =>
dump(x, tapeoutOptions.topFir, tapeoutOptions.topAnnoOut) // dump(x, tapeoutOptions.topFir, tapeoutOptions.topAnnoOut)
x.circuitState.circuit.modules.collect { case e: ExtModule => e } // x.circuitState.circuit.modules.collect { case e: ExtModule => e }
case x => // case x =>
throw new Exception(s"executeTop failed while executing FIRRTL!\n${x}") // throw new Exception(s"executeTop failed while executing FIRRTL!\n${x}")
} // }
} // }
//
// Top and harness generation // // Top and harness generation
protected def executeTopAndHarness(): Unit = { // protected def executeTopAndHarness(): Unit = {
// Execute top and get list of ExtModules to avoid collisions // // Execute top and get list of ExtModules to avoid collisions
val topExtModules = executeTop() // val topExtModules = executeTop()
//
val harnessAnnos = // val harnessAnnos =
tapeoutOptions.harnessDotfOut.map(BlackBoxResourceFileNameAnno(_)).toSeq ++ // tapeoutOptions.harnessDotfOut.map(BlackBoxResourceFileNameAnno(_)).toSeq ++
harnessTop.map(ht => ModuleNameSuffixAnnotation(rootCircuitTarget, s"_in${ht}")) ++ // harnessTop.map(ht => ModuleNameSuffixAnnotation(rootCircuitTarget, s"_in${ht}")) ++
synTop.map(st => ConvertToExtModAnnotation(rootCircuitTarget.module(st))) :+ // synTop.map(st => ConvertToExtModAnnotation(rootCircuitTarget.module(st))) :+
LinkExtModulesAnnotation(topExtModules) // LinkExtModulesAnnotation(topExtModules)
//
// For harness run, change some firrtlOptions (below) for harness phase // // For harness run, change some firrtlOptions (below) for harness phase
// customTransforms: setup harness transforms, add AvoidExtModuleCollisions // // customTransforms: setup harness transforms, add AvoidExtModuleCollisions
// outputFileNameOverride: change to harnessOutput // // outputFileNameOverride: change to harnessOutput
// conf file must change to harnessConf by mapping annotations // // conf file must change to harnessConf by mapping annotations
optionsManager.firrtlOptions = firrtlOptions.copy( // optionsManager.firrtlOptions = firrtlOptions.copy(
customTransforms = firrtlOptions.customTransforms ++ harnessTransforms, // customTransforms = firrtlOptions.customTransforms ++ harnessTransforms,
outputFileNameOverride = tapeoutOptions.harnessOutput.get, // outputFileNameOverride = tapeoutOptions.harnessOutput.get,
annotations = firrtlOptions.annotations.map({ // annotations = firrtlOptions.annotations.map({
case ReplSeqMemAnnotation(i, o) => ReplSeqMemAnnotation(i, tapeoutOptions.harnessConf.get) // case ReplSeqMemAnnotation(i, o) => ReplSeqMemAnnotation(i, tapeoutOptions.harnessConf.get)
case a => a // case a => a
}) ++ harnessAnnos // }) ++ harnessAnnos
) // )
val harnessResult = firrtl.Driver.execute(optionsManager) // val harnessResult = firrtl.Driver.execute(optionsManager)
harnessResult match { // harnessResult match {
case x: FirrtlExecutionSuccess => dump(x, tapeoutOptions.harnessFir, tapeoutOptions.harnessAnnoOut) // case x: FirrtlExecutionSuccess => dump(x, tapeoutOptions.harnessFir, tapeoutOptions.harnessAnnoOut)
case x => throw new Exception(s"executeHarness failed while executing FIRRTL!\n${x}") // case x => throw new Exception(s"executeHarness failed while executing FIRRTL!\n${x}")
} // }
} // }
} //}
//
object GenerateTop extends App with GenerateTopAndHarnessApp { ////object GenerateTop extends App with GenerateTopAndHarnessApp {
// Only need a single phase to generate the top module //// // Only need a single phase to generate the top module
executeTop() //// executeTop()
} ////}
////
object GenerateTopAndHarness extends App with GenerateTopAndHarnessApp { ////object GenerateTopAndHarness extends App with GenerateTopAndHarnessApp {
executeTopAndHarness() //// executeTopAndHarness()
} ////}

View File

@@ -0,0 +1,127 @@
package barstools.tapeout.transforms
import barstools.tapeout.transforms.stage._
import firrtl._
import firrtl.annotations._
import firrtl.ir._
import firrtl.options.{Dependency, InputAnnotationFileAnnotation, StageMain}
import firrtl.passes.memlib.ReplSeqMemAnnotation
import firrtl.stage.{FirrtlCircuitAnnotation, FirrtlStage, OutputFileAnnotation, RunFirrtlTransformAnnotation}
import firrtl.transforms.BlackBoxResourceFileNameAnno
import logger.LazyLogging
// Requires two phases, one to collect modules below synTop in the hierarchy
// and a second to remove those modules to generate the test harness
private class GenerateTopAndHarness(annotations: AnnotationSeq) extends LazyLogging {
val synTop: Option[String] = annotations.collectFirst { case SynTopAnnotation(s) => s }
val topFir: Option[String] = annotations.collectFirst { case TopFirAnnotation(s) => s }
val topAnnoOut: Option[String] = annotations.collectFirst { case TopAnnoOutAnnotation(s) => s }
val harnessTop: Option[String] = annotations.collectFirst { case HarnessTopAnnotation(h) => h }
val harnessConf: Option[String] = annotations.collectFirst { case HarnessConfAnnotation(h) => h }
val harnessOutput: Option[String] = annotations.collectFirst { case HarnessOutputAnnotation(h) => h }
val topDotfOut: Option[String] = annotations.collectFirst { case TopDotfOutAnnotation(h) => h }
val harnessDotfOut: Option[String] = annotations.collectFirst { case HarnessDotfOutAnnotation(h) => h }
val annoFiles: List[String] = annotations.flatMap {
case InputAnnotationFileAnnotation(f) => Some(f)
case _ => None
}.toList
// order is determined by DependencyAPIMigration
val topTransforms = Seq(
new ReParentCircuit,
new RemoveUnusedModules
)
lazy val rootCircuitTarget = CircuitTarget(harnessTop.get)
val topAnnos = synTop.map(st => ReParentCircuitAnnotation(rootCircuitTarget.module(st))) ++
topDotfOut.map(BlackBoxResourceFileNameAnno)
// order is determined by DependencyAPIMigration
val harnessTransforms = Seq(
new ConvertToExtMod,
new RemoveUnusedModules,
new AvoidExtModuleCollisions,
new AddSuffixToModuleNames
)
// Dump firrtl and annotation files
protected def dump(
circuit: Circuit,
annotations: AnnotationSeq,
firFile: Option[String],
annoFile: Option[String]
): Unit = {
firFile.foreach { firPath =>
val outputFile = new java.io.PrintWriter(firPath)
outputFile.write(circuit.serialize)
outputFile.close()
}
annoFile.foreach { annoPath =>
val outputFile = new java.io.PrintWriter(annoPath)
outputFile.write(JsonProtocol.serialize(annotations.filter(_ match {
case _: DeletedAnnotation => false
case _: EmittedComponent => false
case _: EmittedAnnotation[_] => false
case _: FirrtlCircuitAnnotation => false
case _ => true
})))
outputFile.close()
}
}
// Top Generation
def executeTop(): Seq[ExtModule] = {
val annos = new FirrtlStage().execute(Array.empty, annotations)
annos.collectFirst { case FirrtlCircuitAnnotation(circuit) => circuit } match {
case Some(circuit) =>
dump(circuit, annos, topFir, topAnnoOut)
circuit.modules.collect { case e: ExtModule => e }
case _ =>
throw new Exception(s"executeTop failed while executing FIRRTL!\n")
}
}
// Top and harness generation
def executeTopAndHarness(): Unit = {
// Execute top and get list of ExtModules to avoid collisions
val topExtModules = executeTop()
val harnessAnnos =
harnessDotfOut.map(BlackBoxResourceFileNameAnno).toSeq ++
harnessTop.map(ht => ModuleNameSuffixAnnotation(rootCircuitTarget, s"_in${ht}")) ++
synTop.map(st => ConvertToExtModAnnotation(rootCircuitTarget.module(st))) ++
Seq(
LinkExtModulesAnnotation(topExtModules),
RunFirrtlTransformAnnotation(Dependency[ConvertToExtMod]),
RunFirrtlTransformAnnotation(Dependency[RemoveUnusedModules]),
RunFirrtlTransformAnnotation(Dependency[AvoidExtModuleCollisions]),
RunFirrtlTransformAnnotation(Dependency[AddSuffixToModuleNames])
)
// For harness run, change some firrtlOptions (below) for harness phase
// customTransforms: setup harness transforms, add AvoidExtModuleCollisions
// outputFileNameOverride: change to harnessOutput
// conf file must change to harnessConf by mapping annotations
val generatorAnnotations = annotations.map {
case ReplSeqMemAnnotation(i, _) => ReplSeqMemAnnotation(i, harnessConf.get)
case HarnessOutputAnnotation(s) => OutputFileAnnotation(s)
case anno => anno
} ++ harnessAnnos
val annos = new FirrtlStage().execute(Array.empty, generatorAnnotations)
annos.collectFirst { case FirrtlCircuitAnnotation(circuit) => circuit } match {
case Some(circuit) =>
dump(circuit, annos, topFir, topAnnoOut)
case _ =>
throw new Exception(s"executeTop failed while executing FIRRTL!\n")
}
}
}
object GenerateTop extends StageMain(new TapeoutStage(doHarness = false))
object GenerateTopAndHarness extends StageMain(new TapeoutStage(doHarness = true))

View File

@@ -23,7 +23,7 @@ class RemoveUnusedModules extends Transform with DependencyAPIMigration {
def execute(state: CircuitState): CircuitState = { def execute(state: CircuitState): CircuitState = {
val modulesByName = state.circuit.modules.map { val modulesByName = state.circuit.modules.map {
case m: Module => (m.name, Some(m)) case m: Module => (m.name, Some(m))
case m: ExtModule => (m.name, None) case m: ExtModule => (m.name, None)
}.toMap }.toMap

View File

@@ -0,0 +1,181 @@
// See LICENSE for license details.
package barstools.tapeout.transforms.stage
import barstools.tapeout.transforms.GenerateTopAndHarness
import chisel3.stage.ChiselCli
import firrtl.AnnotationSeq
import firrtl.annotations.{Annotation, NoTargetAnnotation}
import firrtl.options.{HasShellOptions, Shell, ShellOption, Stage, Unserializable}
import firrtl.stage.FirrtlCli
import logger.Logger
sealed trait TapeoutOption extends Unserializable {
this: Annotation =>
}
case class HarnessOutputAnnotation(harnessOutput: String) extends NoTargetAnnotation with TapeoutOption
object HarnessOutputAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "harness-o",
shortOption = Some("tho"),
toAnnotationSeq = (s: String) => Seq(HarnessOutputAnnotation(s)),
helpText = "use this to generate a harness at <harness-output>"
)
)
}
case class SynTopAnnotation(synTop: String) extends NoTargetAnnotation with TapeoutOption
object SynTopAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "syn-top",
shortOption = Some("tst"),
toAnnotationSeq = (s: String) => Seq(SynTopAnnotation(s)),
helpText = "use this to set synTop"
)
)
}
case class TopFirAnnotation(topFir: String) extends NoTargetAnnotation with TapeoutOption
object TopFirAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "top-fir",
shortOption = Some("tsf"),
toAnnotationSeq = (s: String) => Seq(TopFirAnnotation(s)),
helpText = "use this to set topFir"
)
)
}
case class TopAnnoOutAnnotation(topAnnoOut: String) extends NoTargetAnnotation with TapeoutOption
object TopAnnoOutAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "top-anno-out",
shortOption = Some("tsaof"),
toAnnotationSeq = (s: String) => Seq(TopAnnoOutAnnotation(s)),
helpText = "use this to set topAnnoOut"
)
)
}
case class TopDotfOutAnnotation(topDotfOut: String) extends NoTargetAnnotation with TapeoutOption
object TopDotfOutAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "top-dotf-out",
shortOption = Some("tdf"),
toAnnotationSeq = (s: String) => Seq(TopDotfOutAnnotation(s)),
helpText = "use this to set the filename for the top resource .f file"
)
)
}
case class HarnessTopAnnotation(harnessTop: String) extends NoTargetAnnotation with TapeoutOption
object HarnessTopAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "harness-top",
shortOption = Some("tht"),
toAnnotationSeq = (s: String) => Seq(HarnessTopAnnotation(s)),
helpText = "use this to set harnessTop"
)
)
}
case class HarnessFirAnnotation(harnessFir: String) extends NoTargetAnnotation with TapeoutOption
object HarnessFirAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "harness-fir",
shortOption = Some("thf"),
toAnnotationSeq = (s: String) => Seq(HarnessFirAnnotation(s)),
helpText = "use this to set harnessFir"
)
)
}
case class HarnessAnnoOutAnnotation(harnessAnnoOut: String) extends NoTargetAnnotation with TapeoutOption
object HarnessAnnoOutAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "harness-anno-out",
shortOption = Some("thaof"),
toAnnotationSeq = (s: String) => Seq(HarnessAnnoOutAnnotation(s)),
helpText = "use this to set harnessAnnoOut"
)
)
}
case class HarnessDotfOutAnnotation(harnessDotfOut: String) extends NoTargetAnnotation with TapeoutOption
object HarnessDotfOutAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "harness-dotf-out",
shortOption = Some("hdf"),
toAnnotationSeq = (s: String) => Seq(HarnessDotfOutAnnotation(s)),
helpText = "use this to set the filename for the harness resource .f file"
)
)
}
case class HarnessConfAnnotation(harnessConf: String) extends NoTargetAnnotation with TapeoutOption
object HarnessConfAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String](
longOption = "harness-conf",
shortOption = Some("thconf"),
toAnnotationSeq = (s: String) => Seq(HarnessConfAnnotation(s)),
helpText = "use this to set the harness conf file location"
)
)
}
trait TapeoutCli {
this: Shell =>
parser.note("Tapeout specific options")
Seq(
HarnessOutputAnnotation,
SynTopAnnotation,
TopFirAnnotation,
TopAnnoOutAnnotation,
TopDotfOutAnnotation,
HarnessTopAnnotation,
HarnessFirAnnotation,
HarnessAnnoOutAnnotation,
HarnessDotfOutAnnotation,
HarnessConfAnnotation
).foreach(_.addOptions(parser))
}
class TapeoutStage(doHarness: Boolean) extends Stage {
override val shell: Shell = new Shell(applicationName = "tapeout") with TapeoutCli with ChiselCli with FirrtlCli
override def run(annotations: AnnotationSeq): AnnotationSeq = {
Logger.makeScope(annotations) {
val generator = new GenerateTopAndHarness(annotations)
if (doHarness) {
generator.executeTopAndHarness()
} else {
generator.executeTop()
}
}
annotations
}
}

View File

@@ -0,0 +1,42 @@
// SPDX-License-Identifier: Apache-2.0
package barstools.tapeout.transforms
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
import java.io.{ByteArrayOutputStream, PrintStream}
class GenerateTopSpec extends AnyFreeSpec with Matchers {
"Generate top and harness" - {
"should include the following transforms" in {
val buffer = new ByteArrayOutputStream()
Console.withOut(new PrintStream(buffer)) {
GenerateTopAndHarness.main(Array("-i", "ExampleModuleNeedsResetInverted.fir", "-ll", "info"))
}
val output = buffer.toString
output should include("barstools.tapeout.transforms.AddSuffixToModuleNames")
output should include("barstools.tapeout.transforms.ConvertToExtMod")
output should include("barstools.tapeout.transforms.RemoveUnusedModules")
output should include("barstools.tapeout.transforms.AvoidExtModuleCollisions")
println(output)
}
}
"generate harness should " in {
val buffer = new ByteArrayOutputStream()
Console.withOut(new PrintStream(buffer)) {
GenerateTopAndHarness.main(
Array(
"--target-dir", "test_run_dir/generate_top_spec",
"-i", "/Users/chick/Adept/dev/masters/barstools/tapeout/src/test/resources/BlackBoxFloatTester.fir",
// "-X", "low",
// "-ll", "info",
// "--help"
)
)
}
val output = buffer.toString
println(output)
}
}