04 verilator仿真生成.vcd波形文件并利用gtkwave查看波形

编写top.v文件 module top(input a,input b,output f);assign f = a ^ b;endmodule编写ma

编写top.v文件

module top(input a,input b,output f
);assign f = a ^ b;
endmodule

编写main.c文件

#include 
#include 
#include #include "Vtop.h"  // create `top.v`,so use `Vtop.h`
#include "verilated.h"#include "verilated_vcd_c.h" //可选,如果要导出vcd则需要加上int main(int argc, char** argv, char** env) {VerilatedContext* contextp = new VerilatedContext;contextp->commandArgs(argc, argv);Vtop* top = new Vtop{contextp};VerilatedVcdC* tfp = new VerilatedVcdC; //初始化VCD对象指针contextp->traceEverOn(true); //打开追踪功能top->trace(tfp, 0); //tfp->open("wave.vcd"); //设置输出的文件wave.vcdwhile (!contextp->gotFinish()) {int a = rand() & 1;int b = rand() & 1;top->a = a;top->b = b;top->eval();printf("a = %d, b = %d, f = %d\n", a, b, top->f);tfp->dump(contextp->time()); //dump wavecontextp->timeInc(1); //推动仿真时间assert(top->f == a ^ b);}delete top;tfp->close();delete contextp;return 0;
}
verilator -Wall top.v top_main.cpp --cc --trace --exe --build
--trace #显示波形
./obj_dir/Vtop   
gtkwave wave.vcd