- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to use the "Tools > tcl > Execute Macro" option in ModelSim to run a "testbench.do" script to run a simulation. However, I can't find a way to get the location of the script file in the code. I want to be able to reference other files around the script file to compile them. Right now my solution is to do "File > Change Directory" and then I can use the script using the "pwd" variable. I don't want to hardcode in directory structures because I want this testbench setup to be able to work on any machine right out of the box.
I've tried reading posts about finding the location of a tcl script, like here ( https://stackoverflow.com/questions/23285360/how-to-get-path-of-current-script ), but they're not helpful. For example:
puts [ info script ]
# returns nothing
puts [ file normalize [ info script ] ]
# returns nothing
file dirname [ file normalize [ info script ] ]
# "."
puts $argv0
# "C:/mtitcl/vsim/vsim"
file dirname [ file normalize $argv0 ]
# "C:/mtitcl/vsim"
file dirname [ file normalize [ info nameofexecutable ] ]
# "C:/intelFPGA_lite/20.1/modelsim_ase/win32aloem"
Is there a way to get the location of my "testbench.do" file? I want to do things like `vcom -2008 -work work "$filepath/top_level_design.vhd"`. Unless I manually do "Change Directory", then something like "./top_level_design.vhd" works because it thinks the "pwd" is the ModelSim exectuable directory.
Thank you
(Using
ModelSim - INTEL FPGA STARTER EDITION 2020.1
Revision: 2020.02)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I wanted to try to avoid the user having to manually input via text a file path to the script to source it in the console window. The "Tools > tcl > Execute Macro" option was very convenient. It worked IF I did "File > Change Directory", but I wanted a way without making the user have to do that either.
I found a way to do what I wanted:
set script_frame [info frame [ expr [info frame] - 1]]
set my_cmd [dict get $script_frame cmd]
set src_dir [ file dirname [ file normalize [ string range $my_cmd 3 end ] ] ]
cd $src_dir
cd ../lite_project/simulation/modelsim
- "Info frame" lists the number of frames (it was 12 for me)
- "Info frame 11" (the one before the last frame) contained the "do" command for my script
- So I had to just pull out the path from the "do" command with "string range", and I got my path.
Now it works right immediately on startup of ModelSim and the script runs perfectly.
Thanks,
Ryan
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Check this link https://www.tcl.tk/man/tcl8.5/TclCmd/info.htm
info script ?filename?
If a Tcl script file is currently being evaluated (i.e. there is a call to Tcl_EvalFile active or there is an active invocation of the source command), then this command returns the name of the innermost file being processed. If filename is specified, then the return value of this command will be modified for the duration of the active invocation to return that name. This is useful in virtual file system applications. Otherwise the command returns an empty string.
It will only be activated when using source command. Try to use source command in Modelsim Transcript. "Tools > tcl > Execute Macro" will use the do command instead. For example:
set script_path [file dirname [info script]]
puts "The path of the currently executing script is: $script_path"
This'll return the path of the executed script file.
Thanks,
Regards,
Sheng
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I wanted to try to avoid the user having to manually input via text a file path to the script to source it in the console window. The "Tools > tcl > Execute Macro" option was very convenient. It worked IF I did "File > Change Directory", but I wanted a way without making the user have to do that either.
I found a way to do what I wanted:
set script_frame [info frame [ expr [info frame] - 1]]
set my_cmd [dict get $script_frame cmd]
set src_dir [ file dirname [ file normalize [ string range $my_cmd 3 end ] ] ]
cd $src_dir
cd ../lite_project/simulation/modelsim
- "Info frame" lists the number of frames (it was 12 for me)
- "Info frame 11" (the one before the last frame) contained the "do" command for my script
- So I had to just pull out the path from the "do" command with "string range", and I got my path.
Now it works right immediately on startup of ModelSim and the script runs perfectly.
Thanks,
Ryan

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page