1 #include "verilated_vcd_c.h"
2 #include "Vtop.h"
3
4 vluint64_t main_time = 0; 5
6 double sc_time_stamp() 7 { 8 return main_time; 9 } 10
11 int main(int argc, char **argv) 12 { 13 Verilated::commandArgs(argc, argv); 14 Verilated::traceEverOn(true); 15 VerilatedVcdC* tfp = new VerilatedVcdC; 16
17 Vtop *top = new Vtop("top"); 18
19 top->clk = 0; 20 top->rst_n = 0; 21
22 top->trace(tfp, 0); 23 tfp->open("wave.vcd"); 24
25 while (sc_time_stamp() < 1000 && !Verilated::gotFinish()) { 26 if (main_time > 14) { 27 top->rst_n = 1; 28 } 29 if ((main_time % 10) == 5) { 30 top->clk = 1; 31 } 32 if ((main_time % 10) == 0) { 33 top->clk = 0; 34 } 35
36 top->eval(); 37 tfp->dump(main_time); 38 main_time++; 39 } 40
41 top->final(); 42 tfp->close(); 43 delete top; 44
45 return 0; 46 }
1 # Makefile for Verilator 2
3 export PRJ_PATH=$(shell pwd)/.. 4 export DESIGN=top 5
6 all: 7 @echo "Verification based on Verilator"
8
9 cmp: 10 verilator -Wno-fatal top.v main.cpp --top-module $(DESIGN) --cc --trace --exe
11 make -C obj_dir -f V$(DESIGN).mk V$(DESIGN) 12
13 run: 14 ./obj_dir/V$(DESIGN) 15
16 wave: 17 gtkwave wave.vcd &
18
19 clean: 20 @rm -rf obj_dir wave.vcd