Vinay Madapura
Vinay Madapura

Reputation: 327

How to pass arguments to tcl script in Vivado GUI tcl console

I am trying to execute a tcl script in Vivado GUI Tcl Console and my script takes an argument to decide which type of run (synth, impl, bitgen etc.) has to be configured. I know that, using -tclargs one could pass arguments if the script is executed in Vivado command-line mode. Something like:

vivado -mode batch -source <filename> -tclargs <arguments>

I tried the same in Vivado gui mode and got an error.

ERROR: [Common 17-170] Unknown option '-tclargs', please type 'source -help' for usage info.

Running 'source -help':

Syntax: 
source  [-encoding <arg>] [-notrace] [-quiet] [-verbose] <file>

Usage: 
  Name         Description
  ------------------------
  [-encoding]  specify the encoding of the data stored in filename
  [-notrace]   disable tracing of sourced commands
  [-quiet]     Ignore command errors
  [-verbose]   Suspend message limits during command execution
  <file>       script to source

By looking at -help I am getting a feeling that it is not possible to do so. Also, I can't find any documents for doing so. I would like to know if there is any way of achieving this.

Upvotes: 4

Views: 5786

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137587

The source command doesn't set up the arguments; it's more like C's #include than anything else really. Because of that, if the script that you are sourceing expects argv and argc to be set — as if the script was run as a program — then you should just set them before the source. They are ordinary variables as far as Tcl's concerned; they just happen to be set up by default.

You might also need to set argv0 to the script. Some programs expect that when running in non-interactive mode.

set argv [list "a b c" foo bar 123]
set argc [llength $argv]
set argv0 theScript.tcl
source $argv0

Upvotes: 6

Related Questions