24.03.2013 Views

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

UM-488 20 - Tcl <strong>and</strong> macros (DO files)<br />

<strong>ModelSim</strong> <strong>SE</strong> User’s <strong>Manual</strong><br />

This will delete the file "myfile.log."<br />

You can also use the transcript file comm<strong>and</strong> to perform a deletion:<br />

transcript file ()<br />

transcript file my file.log<br />

The first line will close the current log file. The second will open a new log file. If it has<br />

the same name as an existing file, it will replace the previous one.<br />

Making macro parameters optional<br />

If you want to make macro parameters optional (i.e., be able to specify fewer parameter<br />

values with the do comm<strong>and</strong> than the number of parameters referenced in the macro), you<br />

must use the argc (UM-542) simulator state variable. The argc simulator state variable<br />

returns the number of parameters passed. The examples below show several ways of using<br />

argc.<br />

Example 1<br />

This macro specifies the files to compile <strong>and</strong> h<strong>and</strong>les 0-2 compiler arguments as<br />

parameters. If you supply more arguments, <strong>ModelSim</strong> generates a message.<br />

switch $argc {<br />

0 {vcom file1.vhd file2.vhd file3.vhd }<br />

1 {vcom $1 file1.vhd file2.vhd file3.vhd }<br />

2 {vcom $1 $2 file1.vhd file2.vhd file3.vhd }<br />

default {echo Too many arguments. The macro accepts 0-2 args. }<br />

}<br />

Example 2<br />

This macro specifies the compiler arguments <strong>and</strong> lets you compile any number of files.<br />

variable Files ""<br />

set nbrArgs $argc<br />

for {set x 1} {$x

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!