[circt-rtl-sim] [Verilator] Compile with trace options when in Debug mode (#1041)

This incurs some cost in the generated simulator. Monitoring and saving the
waveforms to disk incurs yet more overhead, so enable this via an environment
variable.
This commit is contained in:
John Demme 2021-05-11 18:58:28 -07:00 committed by GitHub
parent e9ce235cc1
commit 16fe5fb1d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 18 deletions

View File

@ -18,6 +18,7 @@ import subprocess
import sys
ThisFileDir = os.path.dirname(__file__)
DebugBuild = "@CMAKE_BUILD_TYPE@" == "Debug"
class Questa:
@ -159,10 +160,13 @@ class Verilator:
dpiLibs = filter(lambda fn: fn.endswith(".so") or fn.endswith(".dll"),
sources)
self.ldPaths = ":".join([os.path.dirname(x) for x in dpiLibs])
debugFlags = []
if DebugBuild:
debugFlags = ["--trace", "--trace-params", "--trace-structs"]
return subprocess.run([
self.verilator, "--cc", "--top-module", self.top, "-sv", "--build",
"--exe", "--assert"
] + sources)
] + debugFlags + sources)
def run(self, cycles, args):
exe = os.path.join("obj_dir", "V" + self.top)

View File

@ -13,9 +13,7 @@
#include "Vtop.h"
#ifdef DEBUG
#include "verilated_vcd_c.h"
#endif
#include "signal.h"
#include <iostream>
@ -53,12 +51,15 @@ int main(int argc, char **argv) {
// Construct the simulated module's C++ model.
auto &dut = *new Vtop();
#ifdef DEBUG
VerilatedVcdC *tfp = new VerilatedVcdC;
char *waveformFile = getenv("SAVE_WAVE");
VerilatedVcdC *tfp = nullptr;
if (waveformFile) {
tfp = new VerilatedVcdC();
Verilated::traceEverOn(true);
dut.trace(tfp, 99); // Trace 99 levels of hierarchy
tfp->open("main.vcd");
#endif
tfp->open(waveformFile);
}
std::cout << "[driver] Starting simulation" << std::endl;
@ -70,9 +71,8 @@ int main(int argc, char **argv) {
for (timeStamp = 0; timeStamp < 8 && !Verilated::gotFinish(); timeStamp++) {
dut.eval();
dut.clk = !dut.clk;
#ifdef DEBUG
if (tfp)
tfp->dump(timeStamp);
#endif
}
// Take simulation out of reset.
@ -85,17 +85,15 @@ int main(int argc, char **argv) {
timeStamp++) {
dut.eval();
dut.clk = !dut.clk;
#ifdef DEBUG
if (tfp)
tfp->dump(timeStamp);
#endif
}
// Tell the simulator that we're going to exit. This flushes the output(s) and
// frees whatever memory may have been allocated.
dut.final();
#ifdef DEBUG
if (tfp)
tfp->close();
#endif
std::cout << "[driver] Ending simulation at tick #" << timeStamp << std::endl;
return 0;