顺手写了个带clk的.cpp,我的结果感觉clk还是有问题,不过嘛,和我一样的初学者也能勉强用了嘛不是
#include <verilated.h> // 核心头文件
#include <verilated_vcd_c.h> // 波形生成头文件
#include <iostream>
#include <fstream>
#include "Vtop.h" // 译码器模块类
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
Vtop*top;
VerilatedVcdC* tfp; // 波形生成对象指针
vluint64_t main_time = 0; // 仿真时间戳
const vluint64_t sim_time = 1024; // 最大仿真时间戳
int main(int argc, char **argv){
// 一些初始化工作
Verilated::commandArgs(argc, argv);
Verilated::traceEverOn(true);
// 为对象分配内存空间
top = new Vtop;
tfp = new VerilatedVcdC;
top->reset = 0; // 把reset拉低
// tfp初始化工作
top->trace(tfp, 99);
tfp->open("top.vcd");
while (!Verilated::gotFinish() && main_time < sim_time) {
if (main_time > 10) {
top->reset = 1; // Deassert reset // 拉高Reset,结束复位
}
if ((main_time % 10) == 1) {
top->clk = 1; // 时钟翻转
}
if ((main_time % 10) == 6) {
top->clk = 0; // 时钟翻转
}
top->eval(); // 计算输出
tfp->dump(main_time);
main_time++;
}
// 清理工作
tfp->close();
delete top;
delete tfp;
exit(0);
return 0;
}