#include #include #include #include #include "Vtestbench_top.h" #include std::atomic ctrl_c_hit; void ctrl_c_handler(int sig) { ctrl_c_hit = true; } vluint64_t main_time = 0; double sc_time_stamp() { return main_time; } int main(int argc, char **argv, char **env) { ctrl_c_hit = false; signal(SIGINT, ctrl_c_handler); unsigned int switch_sim = 0; if (argc > 1) switch_sim = atoi(argv[1]); Verilated::commandArgs(argc, argv); Verilated::randReset(2); Verilated::traceEverOn(true); Verilated::mkdir("logs"); const int reset_time = 10; const int time_limit = 2900000; // {0xff, 2900000} Vtestbench_top *top = new Vtestbench_top; std::cout << "<<< Simulation Started >>>" << std::endl; auto time_start = std::chrono::high_resolution_clock::now(); top->clk = 0; top->switch_sim = ~switch_sim; while (!Verilated::gotFinish() && main_time < time_limit) { if (ctrl_c_hit) break; ++main_time; top->clk = !top->clk; top->resetn = (main_time < reset_time) ? 0 : 1; #if VM_COVERAGE if (main_time < reset_time) VerilatedCov::zero(); #endif top->eval(); } auto time_end = std::chrono::high_resolution_clock::now(); if (main_time == time_limit) std::cout << "<<< Time Limit Reached >>>" << std::endl; if (ctrl_c_hit) std::cout << "<<< Ctrl-C >>>" << std::endl; std::cout << "<<< Simulation Ended >>>" << std::endl; std::cout << "Realworld Time: " << std::chrono::duration_cast(time_end - time_start).count() << "s" << std::endl; std::cout << "Simulation Time: " << main_time / 2 << " cycles" << std::endl; top->final(); #if VM_COVERAGE Verilated::mkdir("logs"); VerilatedCov::write("logs/coverage.dat"); #endif delete top; top = NULL; exit(0); }