File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
test/scala/circtTests/stage Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,21 @@ object ChiselStage {
9191 circuitAnno.get.emitLazily(inFileAnnos).mkString
9292 }
9393
94+ /** Elaborates a Chisel circuit and emits it to a file
95+ *
96+ * @param gen a call-by-name Chisel module
97+ * @param args additional command line arguments to pass to Chisel
98+ */
99+ def emitCHIRRTLFile (
100+ gen : => RawModule ,
101+ args : Array [String ] = Array .empty
102+ ): AnnotationSeq = {
103+ (new circt.stage.ChiselStage ).execute(
104+ Array (" --target" , " chirrtl" ) ++ args,
105+ Seq (ChiselGeneratorAnnotation (() => gen))
106+ )
107+ }
108+
94109 /** Return a CHIRRTL circuit for a Chisel module
95110 *
96111 * @param gen a call-by-name Chisel module
@@ -186,7 +201,7 @@ object ChiselStage {
186201 gen : => RawModule ,
187202 args : Array [String ] = Array .empty,
188203 firtoolOpts : Array [String ] = Array .empty
189- ) =
204+ ): AnnotationSeq =
190205 (new circt.stage.ChiselStage ).execute(
191206 Array (" --target" , " systemverilog" ) ++ args,
192207 Seq (ChiselGeneratorAnnotation (() => gen)) ++ firtoolOpts.map(FirtoolOption (_))
Original file line number Diff line number Diff line change 22
33package circtTests .stage
44
5- import chisel3 .stage .ChiselGeneratorAnnotation
5+ import chisel3 .stage .{ ChiselGeneratorAnnotation , CircuitSerializationAnnotation }
66import chisel3 .experimental .SourceLine
77
88import circt .stage .{ChiselStage , FirtoolOption , PreserveAggregate }
@@ -1060,6 +1060,30 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.Utils {
10601060
10611061 }
10621062
1063+ it(" should emit CHIRRTL files" ) {
1064+ val targetDir = new File (" test_run_dir/ChiselStageSpec/emitCHIRRTLFile" )
1065+
1066+ val args : Array [String ] = Array (
1067+ " --target-dir" ,
1068+ targetDir.toString
1069+ )
1070+
1071+ // Should we be returning the CircuitSerializationAnnotation? It's consistent with emitSystemVerilogFile to do so.
1072+ ChiselStage
1073+ .emitCHIRRTLFile(
1074+ new ChiselStageSpec .Bar ,
1075+ args
1076+ )
1077+ .collectFirst {
1078+ case CircuitSerializationAnnotation (_, filename, _) => filename
1079+ }
1080+ .get should be(" Bar" )
1081+
1082+ val expectedOutput = new File (targetDir, " Bar.fir" )
1083+ expectedOutput should (exist)
1084+ info(s " ' $expectedOutput' exists " )
1085+ }
1086+
10631087 it(" should emit FIRRTL dialect" ) {
10641088
10651089 ChiselStage .emitFIRRTLDialect(new ChiselStageSpec .Foo ) should include(" firrtl.module" )
You can’t perform that action at this time.
0 commit comments