49 line
1.1 KiB
Plaintext
49 line
1.1 KiB
Plaintext
`timescale 1ns/1ps
|
|
|
|
module testbench;
|
|
// 1. 声明变量(限制字符串位宽)
|
|
reg clk;
|
|
reg reset_n;
|
|
wire [31:0] pc_out;
|
|
integer fd;
|
|
reg [8*128:1] dump_path; // 限制为 128 字节(足够存储路径)
|
|
|
|
// 实例化被测设计
|
|
top uut (
|
|
.clk(clk),
|
|
.reset_n(reset_n),
|
|
.pc_out(pc_out)
|
|
);
|
|
|
|
// 2. 生成时钟
|
|
initial begin
|
|
clk = 0;
|
|
forever #5 clk = ~clk;
|
|
end
|
|
|
|
// 3. 波形生成和错误处理
|
|
initial begin
|
|
// 初始化路径(显式赋值)
|
|
dump_path = "./wave.vcd";
|
|
|
|
// 尝试创建文件
|
|
fd = $fopen(dump_path, "w");
|
|
if (fd == 0) begin
|
|
$display("ERROR: Cannot open %s for writing!", dump_path);
|
|
$finish;
|
|
end
|
|
$fclose(fd);
|
|
|
|
// 初始化波形记录(添加 +access+r)
|
|
$dumpfile(dump_path);
|
|
$dumpvars(0, testbench); // 记录所有信号
|
|
$display("Waveform will be saved to %s", dump_path);
|
|
|
|
// 复位和仿真控制
|
|
reset_n = 0;
|
|
#100 reset_n = 1;
|
|
#1000 $finish;
|
|
end
|
|
|
|
endmodule
|