Skip to content

Commit 3b179e3

Browse files
authored
Add --split-verilog to emitSystemVerilogFile (#4867)
Change the behavior of `ChiselStage.emitSystemVerilogFile` to add `--split-verilog`. Without this, a user can run into a situation where (rightly), they get non-Verilog output in the single file output. Single file output from CIRCT is only intended to be used for testing. Instead of telling users that they have to add "--split-verilog", just add it by default with no way to turn it off. I don't see a reason why a user _should_ be able to turn this off as the "off" mode is only for testing and this testing can be just as easily done with `emitSystemVerilog`. Fixes #3933. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 1e5b1a7 commit 3b179e3

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

src/main/scala/circt/stage/ChiselStage.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,20 @@ object ChiselStage {
209209
.value
210210
}
211211

212-
/** Compile a Chisel circuit to SystemVerilog with file output
212+
/** Compile a Chisel circuit to multiple SystemVerilog files.
213213
*
214214
* @param gen a call-by-name Chisel module
215215
* @param args additional command line arguments to pass to Chisel
216216
* @param firtoolOpts additional command line options to pass to firtool
217-
* @return a string containing the Verilog output
217+
* @return the annotations that exist after compilation
218218
*/
219219
def emitSystemVerilogFile(
220220
gen: => RawModule,
221221
args: Array[String] = Array.empty,
222222
firtoolOpts: Array[String] = Array.empty
223223
): AnnotationSeq =
224224
(new circt.stage.ChiselStage).execute(
225-
Array("--target", "systemverilog") ++ args,
225+
Array("--target", "systemverilog", "--split-verilog") ++ args,
226226
Seq(ChiselGeneratorAnnotation(() => gen)) ++ firtoolOpts.map(FirtoolOption(_))
227227
)
228228

src/test/scala-2/circtTests/stage/ChiselStageSpec.scala

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
package circtTests.stage
44

55
import chisel3.stage.{ChiselGeneratorAnnotation, CircuitSerializationAnnotation}
6-
import chisel3.experimental.SourceLine
6+
import chisel3.experimental.{ExtModule, SourceLine}
7+
import chisel3.util.HasExtModuleInline
78

89
import circt.stage.{ChiselStage, FirtoolOption, PreserveAggregate}
910

@@ -68,6 +69,31 @@ object ChiselStageSpec {
6869
b := qux.b
6970
}
7071

72+
class Corge extends ExtModule with HasExtModuleInline {
73+
val a = IO(Input(Bool()))
74+
val b = IO(Output(Bool()))
75+
setInline(
76+
"Corge.v",
77+
"""|module Corge(
78+
| input a,
79+
| output b
80+
|);
81+
| assign b = a;
82+
|endmodule
83+
|""".stripMargin
84+
)
85+
}
86+
87+
class Gralp extends RawModule {
88+
val a = IO(Input(Bool()))
89+
val b = IO(Output(Bool()))
90+
val corge = Module(new Corge)
91+
corge.a := a
92+
val quz = Module(new Quz)
93+
quz.a := corge.b
94+
b := quz.b
95+
}
96+
7197
import firrtl.annotations.NoTargetAnnotation
7298
import firrtl.options.Unserializable
7399
case object DummyAnnotation extends NoTargetAnnotation with Unserializable
@@ -591,7 +617,7 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.LogUtils
591617
val lines = stdout.split("\n")
592618
// Fuzzy includes aren't ideal but there is ANSI color in these strings that is hard to match
593619
lines(0) should include(
594-
"src/test/scala-2/circtTests/stage/ChiselStageSpec.scala 95:9: Negative shift amounts are illegal (got -1)"
620+
"src/test/scala-2/circtTests/stage/ChiselStageSpec.scala 121:9: Negative shift amounts are illegal (got -1)"
595621
)
596622
lines(1) should include(" 3.U >> -1")
597623
lines(2) should include(" ^")
@@ -612,7 +638,7 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.LogUtils
612638
// Fuzzy includes aren't ideal but there is ANSI color in these strings that is hard to match
613639
lines.size should equal(2)
614640
lines(0) should include(
615-
"src/test/scala-2/circtTests/stage/ChiselStageSpec.scala 95:9: Negative shift amounts are illegal (got -1)"
641+
"src/test/scala-2/circtTests/stage/ChiselStageSpec.scala 121:9: Negative shift amounts are illegal (got -1)"
616642
)
617643
(lines(1) should not).include("3.U >> -1")
618644
}
@@ -1157,7 +1183,7 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.LogUtils
11571183

11581184
}
11591185

1160-
it("emitSystemVerilogFile should support custom Chisel args and firtool options") {
1186+
it("emitSystemVerilogFile should write to multiple files by default") {
11611187
val targetDir = new File("test_run_dir/ChiselStageSpec/generated")
11621188

11631189
val args: Array[String] = Array(
@@ -1168,19 +1194,14 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.LogUtils
11681194
info(s"output contains a case statement using --lowering-options=disallowPackedArrays")
11691195
ChiselStage
11701196
.emitSystemVerilogFile(
1171-
new ChiselStageSpec.Bar,
1172-
args,
1173-
Array("--lowering-options=disallowPackedArrays")
1197+
new ChiselStageSpec.Gralp,
1198+
args
11741199
)
1175-
.collectFirst { case EmittedVerilogCircuitAnnotation(a) =>
1176-
a
1177-
}
1178-
.get
1179-
.value should include("case")
11801200

1181-
val expectedOutput = new File(targetDir, "Bar.sv")
1182-
expectedOutput should (exist)
1183-
info(s"'$expectedOutput' exists")
1201+
Seq("Corge.v", "Gralp.sv", "Qux.sv", "Qux.sv").map(new File(targetDir, _)).foreach { file =>
1202+
info(s"'$file' exists")
1203+
file should (exist)
1204+
}
11841205
}
11851206

11861207
it("should emit btor2 to string") {

0 commit comments

Comments
 (0)