[go: nahoru, domu]

Skip to content

Commit

Permalink
Add ChiselStage.emitCHIRRTLFile (#4232)
Browse files Browse the repository at this point in the history
Emits a file without returning the serialized object which is more
memory efficient and supports > 2 GiB of serialized FIRRTL text.
  • Loading branch information
jackkoenig committed Jul 1, 2024
1 parent 219a237 commit e8edc8f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/main/scala/circt/stage/ChiselStage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ object ChiselStage {
circuitAnno.get.emitLazily(inFileAnnos).mkString
}

/** Elaborates a Chisel circuit and emits it to a file
*
* @param gen a call-by-name Chisel module
* @param args additional command line arguments to pass to Chisel
*/
def emitCHIRRTLFile(
gen: => RawModule,
args: Array[String] = Array.empty
): AnnotationSeq = {
(new circt.stage.ChiselStage).execute(
Array("--target", "chirrtl") ++ args,
Seq(ChiselGeneratorAnnotation(() => gen))
)
}

/** Return a CHIRRTL circuit for a Chisel module
*
* @param gen a call-by-name Chisel module
Expand Down Expand Up @@ -186,7 +201,7 @@ object ChiselStage {
gen: => RawModule,
args: Array[String] = Array.empty,
firtoolOpts: Array[String] = Array.empty
) =
): AnnotationSeq =
(new circt.stage.ChiselStage).execute(
Array("--target", "systemverilog") ++ args,
Seq(ChiselGeneratorAnnotation(() => gen)) ++ firtoolOpts.map(FirtoolOption(_))
Expand Down
26 changes: 25 additions & 1 deletion src/test/scala/circtTests/stage/ChiselStageSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package circtTests.stage

import chisel3.stage.ChiselGeneratorAnnotation
import chisel3.stage.{ChiselGeneratorAnnotation, CircuitSerializationAnnotation}
import chisel3.experimental.SourceLine

import circt.stage.{ChiselStage, FirtoolOption, PreserveAggregate}
Expand Down Expand Up @@ -1060,6 +1060,30 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.Utils {

}

it("should emit CHIRRTL files") {
val targetDir = new File("test_run_dir/ChiselStageSpec/emitCHIRRTLFile")

val args: Array[String] = Array(
"--target-dir",
targetDir.toString
)

// Should we be returning the CircuitSerializationAnnotation? It's consistent with emitSystemVerilogFile to do so.
ChiselStage
.emitCHIRRTLFile(
new ChiselStageSpec.Bar,
args
)
.collectFirst {
case CircuitSerializationAnnotation(_, filename, _) => filename
}
.get should be("Bar")

val expectedOutput = new File(targetDir, "Bar.fir")
expectedOutput should (exist)
info(s"'$expectedOutput' exists")
}

it("should emit FIRRTL dialect") {

ChiselStage.emitFIRRTLDialect(new ChiselStageSpec.Foo) should include(" firrtl.module")
Expand Down

0 comments on commit e8edc8f

Please sign in to comment.