MIPS/sim/sim_main.cpp
Paul Pan db1aa1d615 Manual Merge
Co-authored-by: cxy004 <cxy004@qq.com>
Co-authored-by: Hooo1941 <Hooo1941@users.noreply.github.com>
2022-08-02 11:29:23 +08:00

69 lines
1.8 KiB
C++

#include <atomic>
#include <chrono>
#include <iostream>
#include <signal.h>
#include "Vtestbench_top.h"
#include <verilated.h>
std::atomic<bool> 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);
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 = ~(0);
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 (main_time < reset_time)
VerilatedCov::zero();
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<std::chrono::seconds>(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);
}