Skip to content

Instantly share code, notes, and snippets.

@esynr3z
Last active April 18, 2024 00:54
Show Gist options
  • Save esynr3z/50746c9cf255e3389f27e9ad393451cb to your computer and use it in GitHub Desktop.
Save esynr3z/50746c9cf255e3389f27e9ad393451cb to your computer and use it in GitHub Desktop.
Tcl script to run Modelsim simulation. Use "vsim -do run_tb.do" to start.
# Simply change the project settings in this section
# for each new project. There should be no need to
# modify the rest of the script.
set tb_name tb_top
set library_file_list [list \
work [list \
../../src/rtl/top.v \
../../src/tb/$tb_name.v] \
]
set incdir_list [list \
../../src/rtl \
../../src/tb \
]
set top_level work.$tb_name
# After sourcing the script from ModelSim for the
# first time use these commands to recompile.
proc r {} {
write format wave -window .main_pane.wave.interior.cs.body.pw.wf wave.do
uplevel #0 source run_tb.do
}
proc rr {} {global last_compile_time
set last_compile_time 0
r }
proc q {} {quit -force }
#Does this installation support Tk?
set tk_ok 1
if [catch {package require Tk}] {set tk_ok 0}
# Prefer a fixed point font for the transcript
set PrefMain(font) {Courier 10 roman normal}
# Compile out of date files
set incdir_str_ ""
foreach incdir $incdir_list {
append incdir_str_ " +incdir+" $incdir
}
set incdir_str [string trim $incdir_str_ " "]
set time_now [clock seconds]
if [catch {set last_compile_time}] {
set last_compile_time 0
}
foreach {library file_list} $library_file_list {
vlib $library
vmap work $library
foreach file $file_list {
if { $last_compile_time < [file mtime $file] } {
if [regexp {.vhdl?$} $file] {
vcom -93 $file
} else {
vlog +define+SIM -sv05compat -timescale "1 ns / 1 ps" $file {*}[split $incdir_str " "]
}
set last_compile_time 0
}
}
}
set last_compile_time $time_now
# Load the simulation
eval vsim $top_level
# If waves exists
if [file exist wave.do] {
source wave.do
}
@esynr3z
Copy link
Author

esynr3z commented Oct 30, 2020

Based on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment