Skip to content

Commit 8e903ae

Browse files
authored
[verilator driver] Fix for clang (#8427)
Was failing on link due to Verilator trace library not being found. I think this is because Verilator does not produce this library unless tracing is enabled. Further, clang (by default) doesn't detect that the symbols aren't actually needed (ie it doesn't optimize away the 'if' branch) so it requires them.
1 parent 05e4f53 commit 8e903ae

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Dialect/ESI/runtime/cosim_dpi_server/driver.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ int main(int argc, char **argv) {
6363
<< std::endl;
6464
}
6565

66+
#ifdef TRACE
6667
VerilatedVcdC *tfp = nullptr;
68+
#endif
69+
6770
if (waveformFile) {
6871
#ifdef TRACE
6972
tfp = new VerilatedVcdC();
@@ -93,8 +96,10 @@ int main(int argc, char **argv) {
9396
for (timeStamp = 0; timeStamp < 8 && !Verilated::gotFinish(); timeStamp++) {
9497
dut.eval();
9598
dut.clk = !dut.clk;
99+
#ifdef TRACE
96100
if (tfp)
97101
tfp->dump(timeStamp);
102+
#endif
98103
}
99104

100105
// Take simulation out of reset.
@@ -104,17 +109,22 @@ int main(int argc, char **argv) {
104109
for (; !Verilated::gotFinish() && !stopSimulation; timeStamp++) {
105110
dut.eval();
106111
dut.clk = !dut.clk;
112+
113+
#ifdef TRACE
107114
if (tfp)
108115
tfp->dump(timeStamp);
116+
#endif
109117
if (debugPeriod)
110118
std::this_thread::sleep_for(std::chrono::milliseconds(debugPeriod));
111119
}
112120

113121
// Tell the simulator that we're going to exit. This flushes the output(s) and
114122
// frees whatever memory may have been allocated.
115123
dut.final();
124+
#ifdef TRACE
116125
if (tfp)
117126
tfp->close();
127+
#endif
118128

119129
std::cout << "[driver] Ending simulation at tick #" << timeStamp << std::endl;
120130
return 0;

tools/circt-rtl-sim/driver.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ int main(int argc, char **argv) {
5353
auto &dut = *new Vtop();
5454
char *waveformFile = getenv("SAVE_WAVE");
5555

56+
#ifdef TRACE
5657
VerilatedVcdC *tfp = nullptr;
58+
#endif
59+
5760
if (waveformFile) {
5861
#ifdef TRACE
5962
tfp = new VerilatedVcdC();
@@ -78,8 +81,10 @@ int main(int argc, char **argv) {
7881
for (timeStamp = 0; timeStamp < 8 && !Verilated::gotFinish(); timeStamp++) {
7982
dut.eval();
8083
dut.clk = !dut.clk;
84+
#ifdef TRACE
8185
if (tfp)
8286
tfp->dump(timeStamp);
87+
#endif
8388
}
8489

8590
// Take simulation out of reset.
@@ -92,15 +97,19 @@ int main(int argc, char **argv) {
9297
timeStamp++) {
9398
dut.eval();
9499
dut.clk = !dut.clk;
100+
#ifdef TRACE
95101
if (tfp)
96102
tfp->dump(timeStamp);
103+
#endif
97104
}
98105

99106
// Tell the simulator that we're going to exit. This flushes the output(s) and
100107
// frees whatever memory may have been allocated.
101108
dut.final();
109+
#ifdef TRACE
102110
if (tfp)
103111
tfp->close();
112+
#endif
104113

105114
std::cout << "[driver] Ending simulation at tick #" << timeStamp << std::endl;
106115
return 0;

0 commit comments

Comments
 (0)