Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make firtool options for elaborateGeneratedModule in workspace parametric #3952

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/scala/chisel3/simulator/Simulator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ trait Simulator {
def workingDirectoryPrefix = "workdir"
def customSimulationWorkingDirectory: Option[String] = None
def verbose: Boolean = false
def firtoolArgs: Seq[String] = Seq()

private[simulator] def processBackends(processor: Simulator.BackendProcessor): Unit
private[simulator] def _simulate[T <: RawModule, U](
Expand All @@ -100,7 +101,7 @@ trait Simulator {
): Seq[Simulator.BackendInvocationDigest[U]] = {
val workspace = new Workspace(path = workspacePath, workingDirectoryPrefix = workingDirectoryPrefix)
workspace.reset()
val elaboratedModule = workspace.elaborateGeneratedModule({ () => module })
val elaboratedModule = workspace.elaborateGeneratedModule({ () => module }, firtoolArgs)
workspace.generateAdditionalSources()
val compiler = new Simulator.WorkspaceCompiler(
elaboratedModule,
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/chisel3/simulator/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ package object simulator {

implicit class ChiselWorkspace(workspace: Workspace) {
def elaborateGeneratedModule[T <: RawModule](
generateModule: () => T
generateModule: () => T,
firtoolArgs: Seq[String] = Seq()
): ElaboratedModule[T] = {
// Use CIRCT to generate SystemVerilog sources, and potentially additional artifacts
var someDut: Option[T] = None
val firtoolOptions = firtoolArgs.map(circt.stage.FirtoolOption)
val outputAnnotations = (new circt.stage.ChiselStage).execute(
Array("--target", "systemverilog", "--split-verilog"),
Seq(
Expand All @@ -106,7 +108,7 @@ package object simulator {
},
circt.stage.FirtoolOption("-disable-annotation-unknown"),
firrtl.options.TargetDirAnnotation(workspace.supportArtifactsPath)
)
) ++ firtoolOptions
)

// Move the files indicated by a filelist. No-op if the file has already
Expand Down
47 changes: 47 additions & 0 deletions src/test/scala/chiselTests/simulator/SimulatorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,52 @@ class SimulatorSpec extends AnyFunSpec with Matchers {
}
.result
}

it("runs a design with debug mode (-g) and --strip-debug-info") {
import circt.stage.ChiselStage

class Bar extends Module {
val a = IO(Input(Bool()))
val b = IO(Input(Bool()))
val out = IO(Output(Bool()))

out := a & b
}

// Check now the debug info is stripped
val expectedSV = ChiselStage.emitSystemVerilog(new Bar, firtoolOpts = Array("--strip-debug-info", "-g"))

new VerilatorSimulator("test_run_dir/simulator/bar_debug_mode") {
override val firtoolArgs = Seq("--strip-debug-info", "-g")
}
.simulate(new Bar) { module =>
import PeekPokeAPI._
val bar = module.wrapped

bar.a.poke(false.B)
bar.b.poke(false.B)
bar.out.expect(false.B)
bar.clock.step()

bar.a.poke(true.B)
bar.b.poke(false.B)
bar.out.expect(false.B)
bar.clock.step()

bar.a.poke(true.B)
bar.b.poke(true.B)
bar.out.expect(true.B)
bar.clock.step()
}
.result

// Check the expected SV and the generated SV are the same
val source = io.Source.fromFile("test_run_dir/simulator/bar_debug_mode/primary-sources/Bar.sv")
val actualSV = source.mkString
assert(actualSV === expectedSV)
source.close()

}

}
}
Loading