maste
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
module testbench;
|
||||
// 1. 声明变量(限制位宽为 128 位,即 16 字符)
|
||||
reg clk;
|
||||
reg reset_n;
|
||||
wire [31:0] pc_out;
|
||||
integer fd;
|
||||
reg [8*16:1] dump_path; // 16 字符足够存储路径
|
||||
|
||||
// 实例化被测设计
|
||||
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;
|
||||
#10000 $finish;
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,46 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
module testbench;
|
||||
// 1. 在模块开头声明所有变量
|
||||
reg clk;
|
||||
reg reset_n;
|
||||
wire [31:0] pc_out;
|
||||
integer fd; // 文件描述符
|
||||
string dump_path = "/tmp/wave.vcd"; // 字符串变量
|
||||
|
||||
|
||||
// 实例化被测设计
|
||||
top uut (
|
||||
.clk(clk),
|
||||
.reset_n(reset_n),
|
||||
.pc_out(pc_out)
|
||||
);
|
||||
|
||||
// 2. 生成时钟
|
||||
initial begin
|
||||
clk = 0;
|
||||
forever #5 clk = ~clk; // 100MHz 时钟
|
||||
end
|
||||
|
||||
// 3. 波形生成和错误处理
|
||||
initial begin
|
||||
// 尝试创建文件
|
||||
fd = $fopen(dump_path, "w");
|
||||
if (fd == 0) begin
|
||||
$display("ERROR: Cannot open %s for writing!", dump_path);
|
||||
$finish;
|
||||
end
|
||||
$fclose(fd);
|
||||
|
||||
// 初始化波形记录
|
||||
$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
|
||||
@@ -0,0 +1,49 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
module testbench;
|
||||
// 1. 声明变量(纯 Verilog)
|
||||
reg clk;
|
||||
reg reset_n;
|
||||
wire [31:0] pc_out;
|
||||
integer fd; // 文件描述符
|
||||
reg [8*80:1] dump_path; // 用 reg 数组模拟字符串
|
||||
|
||||
// 实例化被测设计
|
||||
top uut (
|
||||
.clk(clk),
|
||||
.reset_n(reset_n),
|
||||
.pc_out(pc_out)
|
||||
);
|
||||
|
||||
// 2. 生成时钟
|
||||
initial begin
|
||||
clk = 0;
|
||||
forever #5 clk = ~clk; // 100MHz 时钟
|
||||
end
|
||||
|
||||
// 3. 波形生成和错误处理
|
||||
initial begin
|
||||
// 初始化路径(用字符串拼接模拟)
|
||||
dump_path = "/tmp/wave.vcd"; // Verilog 中直接赋值 reg 数组
|
||||
|
||||
// 尝试创建文件
|
||||
fd = $fopen(dump_path, "w");
|
||||
if (fd == 0) begin
|
||||
$display("ERROR: Cannot open ", dump_path, " for writing!"); // 字符串拼接
|
||||
$finish;
|
||||
end
|
||||
$fclose(fd);
|
||||
|
||||
// 初始化波形记录
|
||||
$dumpfile(dump_path);
|
||||
$dumpvars(0, testbench);
|
||||
$display("Waveform will be saved to ", dump_path); // 字符串拼接
|
||||
|
||||
// 复位和仿真控制
|
||||
reset_n = 0;
|
||||
#100 reset_n = 1;
|
||||
#1000 $finish;
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
`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
|
||||
@@ -0,0 +1,48 @@
|
||||
`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
|
||||
@@ -0,0 +1,46 @@
|
||||
`timescale 1ns/1ps
|
||||
|
||||
module testbench;
|
||||
// 1. 声明所有变量
|
||||
reg clk;
|
||||
reg reset_n;
|
||||
wire [31:0] pc_out;
|
||||
integer fd;
|
||||
string dump_path = "/tmp/wave.vcd"; // SystemVerilog 支持直接赋值
|
||||
|
||||
// 实例化被测设计
|
||||
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
|
||||
// 尝试创建文件
|
||||
fd = $fopen(dump_path, "w");
|
||||
if (fd == 0) begin
|
||||
string err_msg = $sformatf("ERROR: Cannot open %s for writing!", dump_path); // SystemVerilog 格式化
|
||||
$display("%s", err_msg);
|
||||
$finish;
|
||||
end
|
||||
$fclose(fd);
|
||||
|
||||
// 初始化波形记录
|
||||
$dumpfile(dump_path);
|
||||
$dumpvars(0, testbench);
|
||||
$display("Waveform will be saved to %s", dump_path); // 部分工具支持 %s
|
||||
|
||||
// 复位和仿真控制
|
||||
reset_n = 0;
|
||||
#100 reset_n = 1;
|
||||
#1000 $finish;
|
||||
end
|
||||
|
||||
endmodule
|
||||
@@ -0,0 +1 @@
|
||||
s1(22Sep2025:14:47:22): xmverilog +acc+rbn -64bit design/top.v testbench/testbench.v
|
||||
@@ -0,0 +1,10 @@
|
||||
xmverilog(64): 23.09-s001: (c) Copyright 1995-2023 Cadence Design Systems, Inc.
|
||||
TOOL: xmverilog 23.09-s001: Started on Sep 22, 2025 at 14:47:21 CST
|
||||
xmverilog
|
||||
+acc+rbn
|
||||
-64bit
|
||||
design/top.v
|
||||
testbench/testbench.v
|
||||
xmverilog: *E,FILEMIS: Cannot find the provided file design/top.v.
|
||||
xmverilog: *E,FILEMIS: Cannot find the provided file testbench/testbench.v.
|
||||
TOOL: xmverilog 23.09-s001: Exiting on Sep 22, 2025 at 14:47:22 CST (total: 00:00:01)
|
||||
Reference in New Issue
Block a user