ModelSim 配合 Makefile 搭建 Verilog 仿真工程
📁 项目目录结构
prj/
├── tb.sv # 顶层测试平台
└── sims/├── filelist.f # 所有源文件清单├── Makefile # 一键编译与仿真脚本└── run.do # ModelSim 自动运行脚本
📄 filelist.f
列出参与仿真的所有源文件路径:
../tb.sv
📝 run.do(ModelSim 批处理脚本)
vsim -voptargs=+acc work.tb
add wave -position insertpoint sim:/tb/*
run 10ms
🛠️ Makefile 自动构建系统
# 设置变量
work = work
output = ./
vsimbatch0 = -do "run -all"# 编译流程
all: compile vsimlib:@echo "Start compile for Questasim 10.6c"vlib $(work)vmap work $(work)vlog:vlog -f filelist.f -l $(output)/compile.logcompile: lib vlogrun:modelsim -do ./run.do# 清理生成文件
clean:del *.wlfdel vsim_stacktrace.vstfdel transcriptdel compile.logdel modelsim.inirmdir /s /q work
📘 测试平台 tb.sv 示例
// `timescale 指令
`timescale 1ns/1ps
module tb;wire clk;initial begin$display("State: IDLE366888");end
endmodule
🖥️ 编译与仿真流程
✅ 初次执行(Windows DOS 控制台):
cd sims
make
make run
🔁 修改代码后,在 ModelSim 控制台执行:
vlog -f filelist.f; restart -f; run 1ms