Skip to content

Commit f5585e7

Browse files
authored
Merge pull request #35 from rameloni/improve-sim-settings
Ensure that TywavesSimulator and TypedConverter uses the same firtool settings
2 parents 1f5b5a6 + fb5bae1 commit f5585e7

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

example/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ run: clean
88
done
99

1010
clean:
11-
$(RM) -rf test_run_dir/
11+
$(RM) -rf test_run_dir/
12+
$(RM) *.vcd *.fir

src/main/scala/tywaves/circuitmapper/TypedConverter.scala

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ private[tywaves] object TypedConverter {
1414
private val chiselStageBaseArgs =
1515
Array("--target", "systemverilog", "--split-verilog", "--firtool-binary-path", firtoolBinaryPath)
1616

17+
val firtoolBaseArgs: Seq[String] =
18+
Seq("-O=debug", "-g", "--emit-hgldd", "--split-verilog") // Run in debug mode compiled with optimizations
1719
// Directories where the debug information is stored
1820
private var hglddDebugDir = "hgldd/debug"
1921
private var hglddWithOptDir = "hgldd/opt" // TODO: remove
2022
private var workingDir: Option[String] = None
2123
private val topModuleName = TopModuleName(None)
2224

2325
// Default firtool options encoded as annotations for ChiselStage
24-
private val defaultFirtoolOptAnno =
25-
createFirtoolOptions(Seq(
26-
"--emit-hgldd"
27-
// "-disable-annotation-unknown",
28-
// "--hgldd-output-prefix=<path>",
29-
/*,"--output-final-mlir=WORK.mlir"*/
30-
))
26+
private val defaultFirtoolOptAnno = createFirtoolOptions(firtoolBaseArgs)
27+
// "-disable-annotation-unknown",
28+
// "--hgldd-output-prefix=<path>",
29+
/*,"--output-final-mlir=WORK.mlir"*/
3130

3231
// Map any sequence of string into FirtoolOptions
3332
private def createFirtoolOptions(args: Seq[String]) = args.map(circt.stage.FirtoolOption)
@@ -37,8 +36,9 @@ private[tywaves] object TypedConverter {
3736
* [[circt.stage.ChiselStage]]
3837
*/
3938
def createDebugInfoHgldd[T <: RawModule](
40-
generateModule: () => T,
41-
workingDir: String = "workingDir",
39+
generateModule: () => T,
40+
workingDir: String = "workingDir",
41+
additionalFirtoolArgs: Seq[String],
4242
): Unit = {
4343
this.workingDir = Some(workingDir)
4444
hglddWithOptDir = workingDir + "/" + hglddWithOptDir
@@ -54,10 +54,9 @@ private[tywaves] object TypedConverter {
5454
// annotations,
5555
// ) // execute returns the passThrough annotations in CIRCT transform stage
5656

57-
// Run with debug mode
5857
val finalAnno = chiselStage.execute(
5958
chiselStageBaseArgs ++ Array("--target-dir", hglddDebugDir),
60-
annotations ++ createFirtoolOptions(Seq("-O=debug", "-g")),
59+
createFirtoolOptions(additionalFirtoolArgs) ++ annotations ,
6160
) // execute returns the passThrough annotations in CIRCT transform stage
6261

6362
// Get the module name

src/main/scala/tywaves/simulator/ParametricSimulator.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ParametricSimulator {
6060
else None
6161

6262
private var _firtoolArgs: Seq[String] = Seq()
63+
def getFirtoolArgs: Seq[String] = _firtoolArgs
6364

6465
/** Launch and execute a simulation given a list of [[SimulatorSettings]]. */
6566
def simulate[T <: RawModule](

src/main/scala/tywaves/simulator/TywavesSimulator.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ object TywavesSimulator extends PeekPokeAPI {
3131

3232
val finalSettings =
3333
if (containTywaves)
34-
settings ++ Seq(FirtoolArgs(Seq("-O=debug", "-g", "--emit-hgldd", "--split-verilog", "-o=WORK.v")))
34+
settings ++ Seq(FirtoolArgs(TypedConverter.firtoolBaseArgs))
35+
// Seq(FirtoolArgs(Seq("-O=debug", "-g", "--emit-hgldd", "--split-verilog", "-o=WORK.v")))
3536
else settings
3637

3738
simulator.simulate(module, finalSettings, simName)(body)
@@ -43,7 +44,11 @@ object TywavesSimulator extends PeekPokeAPI {
4344
// Create the debug info from the firtool and get the top module name
4445
// TODO: this may not be needed anymore, since the debug info can be generated directly from chiselsim, by giving the right options to firtool
4546
// But the problem is to call chiselstage with debug options
46-
TypedConverter.createDebugInfoHgldd(() => module, simulator.wantedWorkspacePath)
47+
TypedConverter.createDebugInfoHgldd(
48+
() => module,
49+
workingDir = simulator.wantedWorkspacePath,
50+
additionalFirtoolArgs = simulator.getFirtoolArgs,
51+
)
4752

4853
// Run tywaves viewer if the Tywaves waveform generation is enabled by Tywaves(true)
4954
val (runWaves, waitFor) =

0 commit comments

Comments
 (0)