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

feat: add waveform tracing support for simulateRaw and simulate in SimulatorAPI #4770

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
10 changes: 8 additions & 2 deletions src/main/scala/chisel3/simulator/SimulatorAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ trait SimulatorAPI {
*/
def simulateRaw[T <: RawModule](
module: => T,
chiselSettings: ChiselSettings[T] = ChiselSettings.defaultRaw[T]
chiselSettings: ChiselSettings[T] = ChiselSettings.defaultRaw[T],
enableTrace: Boolean = false
Comment on lines -27 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I think we do want to expose this. However, it would be better to make it part of ChiselSettings. I'd like to keep the options organized under ChiselSettings and not have a proliferation of other options.

)(stimulus: (T) => Unit)(implicit hasSimulator: HasSimulator, testingDirectory: HasTestingDirectory): Unit = {

hasSimulator.getSimulator
.simulate(module, chiselSettings) { module =>
module.controller.setTraceEnabled(enableTrace)
stimulus(module.wrapped)
}
.result
Expand Down Expand Up @@ -76,7 +78,8 @@ trait SimulatorAPI {
def simulate[T <: Module](
module: => T,
chiselSettings: ChiselSettings[T] = ChiselSettings.default[T],
additionalResetCycles: Int = 0
additionalResetCycles: Int = 0,
enableTrace: Boolean = false
)(stimulus: (T) => Unit)(implicit hasSimulator: HasSimulator, testingDirectory: HasTestingDirectory): Unit = {

hasSimulator.getSimulator
Expand All @@ -86,6 +89,9 @@ trait SimulatorAPI {
val clock = module.port(dut.clock)
val controller = module.controller

// Set the trace enable flag.
controller.setTraceEnabled(enableTrace)

// Run the initialization procedure.
controller.run(1)
reset.set(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,74 @@ class ChiselSimSpec extends AnyFunSpec with Matchers with ChiselSim with FileChe
}
}

it("should dump waveform with Chisel Module") {
class Foo extends Module {
val a = IO(Input(Bool()))
val b = IO(Output(Bool()))

b :<= !a
}
import chisel3.simulator.HasSimulator.simulators
import chisel3.simulator.stimulus.RunUntilFinished
implicit val verilator = simulators
.verilator(verilatorSettings =
svsim.verilator.Backend.CompilationSettings(
traceStyle =
Some(svsim.verilator.Backend.CompilationSettings.TraceStyle.Vcd(traceUnderscore = true, "trace.vcd"))
)
)
val workSpacePath = "dump_wave_module"
val directory = Directory(FileSystems.getDefault().getPath("test_run_dir", workSpacePath).toFile())
directory.deleteRecursively()
implicit val waveDirectory = new HasTestingDirectory {
override def getDirectory =
FileSystems.getDefault().getPath("test_run_dir", workSpacePath)
}
simulate(new Foo, enableTrace = true) { foo =>
foo.a.poke(true.B)
foo.b.expect(false.B)
foo.a.poke(false.B)
foo.b.expect(true.B)
}(hasSimulator = verilator, testingDirectory = waveDirectory)
val allFiles = directory.deepFiles.toSeq.map(_.toString).toSet
val file = s"test_run_dir/$workSpacePath/workdir-verilator/trace.vcd"
info(s"found expected file: '$file'")
allFiles should contain(file)
}

it("should dump waveform with RawModule") {
class Foo extends RawModule {
val a = IO(Input(Bool()))
val b = IO(Output(Bool()))

b :<= !a
}
import chisel3.simulator.HasSimulator.simulators
import chisel3.simulator.stimulus.RunUntilFinished
implicit val verilator = simulators
.verilator(verilatorSettings =
svsim.verilator.Backend.CompilationSettings(
traceStyle =
Some(svsim.verilator.Backend.CompilationSettings.TraceStyle.Vcd(traceUnderscore = true, "trace.vcd"))
)
)
val workSpacePath = "dump_wave_raw_module"
val directory = Directory(FileSystems.getDefault().getPath("test_run_dir", workSpacePath).toFile())
directory.deleteRecursively()
implicit val waveDirectory = new HasTestingDirectory {
override def getDirectory =
FileSystems.getDefault().getPath("test_run_dir", workSpacePath)
}
simulateRaw(new Foo, enableTrace = true) { foo =>
foo.a.poke(true.B)
foo.b.expect(false.B)
foo.a.poke(false.B)
foo.b.expect(true.B)
}(hasSimulator = verilator, testingDirectory = waveDirectory)
val allFiles = directory.deepFiles.toSeq.map(_.toString).toSet
val file = s"test_run_dir/$workSpacePath/workdir-verilator/trace.vcd"
info(s"found expected file: '$file'")
allFiles should contain(file)
}

}
Loading