No-op barstools SFC compiler

This commit is contained in:
abejgonzalez
2022-10-08 10:41:09 -07:00
parent 064c8be7bb
commit 2635bb4f80
2 changed files with 27 additions and 210 deletions

View File

@@ -13,46 +13,28 @@ import logger.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
private class GenerateTopAndHarness(annotations: AnnotationSeq) extends LazyLogging { private class GenerateTopAndHarness(annotations: AnnotationSeq) extends LazyLogging {
val synTop: Option[String] = annotations.collectFirst { case SynTopAnnotation(s) => s } val outFir: Option[String] = annotations.collectFirst { case OutFirAnnotation(s) => s }
val topFir: Option[String] = annotations.collectFirst { case TopFirAnnotation(s) => s } val outAnno: Option[String] = annotations.collectFirst { case OutAnnoAnnotation(s) => s }
val harnessFir: Option[String] = annotations.collectFirst { case HarnessFirAnnotation(s) => s }
val topAnnoOut: Option[String] = annotations.collectFirst { case TopAnnoOutAnnotation(s) => s }
val harnessAnnoOut: Option[String] = annotations.collectFirst { case HarnessAnnoOutAnnotation(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
lazy val rootCircuitTarget = CircuitTarget(harnessTop.get)
val topAnnos = synTop.map(st => ReParentCircuitAnnotation(rootCircuitTarget.module(st))) ++
topDotfOut.map(BlackBoxResourceFileNameAnno)
// Dump firrtl and annotation files // Dump firrtl and annotation files
protected def dump( protected def dump(
circuit: Circuit, circuit: Circuit,
annotations: AnnotationSeq, annotations: AnnotationSeq,
firFile: Option[String],
annoFile: Option[String]
): Unit = { ): Unit = {
firFile.foreach { firPath => outFir.foreach { firPath =>
val outputFile = new java.io.PrintWriter(firPath) val outputFile = new java.io.PrintWriter(firPath)
outputFile.write(circuit.serialize) outputFile.write(circuit.serialize)
outputFile.close() outputFile.close()
} }
annoFile.foreach { annoPath => outAnno.foreach { annoPath =>
val outputFile = new java.io.PrintWriter(annoPath) val outputFile = new java.io.PrintWriter(annoPath)
outputFile.write(JsonProtocol.serialize(annotations.filter(_ match { outputFile.write(JsonProtocol.serialize(annotations.filter(_ match {
case _: DeletedAnnotation => false case _: DeletedAnnotation => false
case _: EmittedComponent => false case _: EmittedComponent => false
case _: EmittedAnnotation[_] => false case _: EmittedAnnotation[_] => false
case _: FirrtlCircuitAnnotation => false case _: FirrtlCircuitAnnotation => false
case _: OutAnnoAnnotation => false
case _: OutFirAnnotation => false
case _ => true case _ => true
}))) })))
outputFile.close() outputFile.close()
@@ -60,65 +42,15 @@ private class GenerateTopAndHarness(annotations: AnnotationSeq) extends LazyLogg
} }
// Top Generation // Top Generation
def executeTop(): Seq[ExtModule] = { def executeTop(): Unit = {
val annos = new FirrtlStage().execute( val annos = new FirrtlStage().execute(Array.empty, annotations)
Array.empty,
annotations ++ Seq(
RunFirrtlTransformAnnotation(Dependency[ReParentCircuit]),
RunFirrtlTransformAnnotation(Dependency[RemoveUnusedModules])
) ++
topAnnos
)
annos.collectFirst { case FirrtlCircuitAnnotation(circuit) => circuit } match { annos.collectFirst { case FirrtlCircuitAnnotation(circuit) => circuit } match {
case Some(circuit) => case Some(circuit) =>
dump(circuit, annos, topFir, topAnnoOut) dump(circuit, annos)
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()
// order is determined by DependencyAPIMigration
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
.filterNot(_.isInstanceOf[OutputFileAnnotation])
.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, harnessFir, harnessAnnoOut)
case _ => case _ =>
throw new Exception(s"executeTop failed while executing FIRRTL!\n") throw new Exception(s"executeTop failed while executing FIRRTL!\n")
} }
} }
} }
object GenerateTop extends StageMain(new TapeoutStage(doHarness = false)) object GenerateTop extends StageMain(new TapeoutStage)
object GenerateTopAndHarness extends StageMain(new TapeoutStage(doHarness = true))

View File

@@ -14,132 +14,28 @@ sealed trait TapeoutOption extends Unserializable {
this: Annotation => this: Annotation =>
} }
case class HarnessOutputAnnotation(harnessOutput: String) extends NoTargetAnnotation with TapeoutOption case class OutFirAnnotation(outFir: String) extends NoTargetAnnotation with TapeoutOption
object HarnessOutputAnnotation extends HasShellOptions { object OutFirAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq( val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String]( new ShellOption[String](
longOption = "harness-o", longOption = "out-fir-file",
shortOption = Some("tho"), shortOption = Some("off"),
toAnnotationSeq = (s: String) => Seq(HarnessOutputAnnotation(s)), toAnnotationSeq = (s: String) => Seq(OutFirAnnotation(s)),
helpText = "use this to generate a harness at <harness-output>" helpText = "out-fir-file"
) )
) )
} }
case class SynTopAnnotation(synTop: String) extends NoTargetAnnotation with TapeoutOption case class OutAnnoAnnotation(outAnno: String) extends NoTargetAnnotation with TapeoutOption
object SynTopAnnotation extends HasShellOptions { object OutAnnoAnnotation extends HasShellOptions {
val options: Seq[ShellOption[_]] = Seq( val options: Seq[ShellOption[_]] = Seq(
new ShellOption[String]( new ShellOption[String](
longOption = "syn-top", longOption = "out-anno-file",
shortOption = Some("tst"), shortOption = Some("oaf"),
toAnnotationSeq = (s: String) => Seq(SynTopAnnotation(s)), toAnnotationSeq = (s: String) => Seq(OutAnnoAnnotation(s)),
helpText = "use this to set synTop" helpText = "out-anno-file"
)
)
}
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"
) )
) )
} }
@@ -149,32 +45,21 @@ trait TapeoutCli {
parser.note("Tapeout specific options") parser.note("Tapeout specific options")
Seq( Seq(
HarnessOutputAnnotation, OutAnnoAnnotation,
SynTopAnnotation, OutFirAnnotation,
TopFirAnnotation,
TopAnnoOutAnnotation,
TopDotfOutAnnotation,
HarnessTopAnnotation,
HarnessFirAnnotation,
HarnessAnnoOutAnnotation,
HarnessDotfOutAnnotation,
HarnessConfAnnotation
).foreach(_.addOptions(parser)) ).foreach(_.addOptions(parser))
} }
class TapeoutStage(doHarness: Boolean) extends Stage { class TapeoutStage extends Stage {
override val shell: Shell = new Shell(applicationName = "tapeout") with TapeoutCli with ChiselCli with FirrtlCli override val shell: Shell = new Shell(applicationName = "tapeout") with TapeoutCli with ChiselCli with FirrtlCli
override def run(annotations: AnnotationSeq): AnnotationSeq = { override def run(annotations: AnnotationSeq): AnnotationSeq = {
Logger.makeScope(annotations) { Logger.makeScope(annotations) {
val generator = new GenerateTopAndHarness(annotations) val generator = new GenerateTopAndHarness(annotations)
if (doHarness) { generator.executeTop()
generator.executeTopAndHarness()
} else {
generator.executeTop()
}
} }
annotations annotations
} }
} }