4

I want to make a script, which can be executed from shell like: ./myscript -test1 or tclsh myscript.tcl -test1

I want it to open ModelSim, compile units, load a desired testbench, run simulation. Name of the test would be a parameter. I've already made macro files (.do) containing modelsim commands to compile & simulate desired units (+adding signals to waveform). I'm asking because scripting isn't my area of expertise.

So here's my questions:

  1. How to ,,tell'' Modelsim (at startup) to do the commands in specified file?

  2. Is TCL the language i'm looking for // is it doable in TCL? If so, which commands should i make familiar with?

  3. Or maybe shell script is sufficient and i should look for specific Modelsim commands in reference manual?

Thanks for you time!

EDIT: Posting little example i've made for everyone to use. Usage: ./foo.tcl testname

#!/usr/bin/tclsh
# params
set testname [lindex $argv 0]
set testlist {test1 test2 test3}
# run vsim test $testname
if  { [ lsearch $testlist $testname ] >= 0 }   {      
     puts "Test found. Executing..."
     open "|vsim -do $testname "
} else { puts "Test not found on the list!" }
RaZ
  • 364
  • 1
  • 5
  • 17
  • 1
    You are expected to try to solve your own problems before you ask for help with them here. Additionally, you generally only ask *one* question at a time here. So pick an area of this problem and start looking into what needs doing for that area. When/if you run into a problem come back and ask a question about that either here or on a more appropriate stackexchange site. – Etan Reisner Oct 08 '14 at 18:07

2 Answers2

4

You can launch vsim with arbitrary commands using the -do <arg> command line option. The argument can either be a filename of a .do file containing arbitrary Tcl code or a string of Tcl commands ("run -all; quit" is useful for non-interactive command line mode with -c).

Tcl is a full featured scripting language. It can handle any automation task you need to accomplish. Ultimately you cannot escape Tcl with Modelsim since almost everything runs through it internally. I would recommend you piece together what you need in a .do file and run that using the -do option.

Kevin Thibedeau
  • 3,299
  • 15
  • 26
1

If you create a .tcl script (.do files can run QuestaSim/ModelSim commands and tcl commands), you can do everything you want to do, include running other .do/.tcl files. For example:

ModelSim/QuestaSim Command Line:

just like what you are used to...

$: do MyDoFile.do

...instead use a Tcl file, which could call out your .do files:

$: source ./MyDirectory/MyTCLScript.tcl

Within that MyTCLScript.tcl you can have literally the following:

Within MyTCLScript.tcl:

...
#Use tabs for aliases
source ./MyDirectory/OtherDirectory/OtherTCLScript.tcl
     MyAlias1
     MyAlias2

do ./MyDoFile.do
...

Finally, to let you use commands to run single testbenches and the sort, I suggest looking at Tcl documentation on aliases. Here is an example though:

Within OtherTCLScript.tcl:

...
alias MyAlias1 {
     eval <command><command flags>
}
alias MyAlias2 {
     eval <command><command flags>
}
...

Sources: 1. Experience 2. Questa SIM User's Manual

Raj
  • 138
  • 1
  • 11
  • nice summary. do you have a blog? these kind of 'glue' issues aren't clearly covered. – Joe Aug 11 '21 at 17:58