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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Comm<strong>and</strong> separator<br />

Multiple-line comm<strong>and</strong>s<br />

Evaluation order<br />

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

A semicolon character (;) works as a separator for multiple comm<strong>and</strong>s on the same line. It<br />

is not required at the end of a line in a comm<strong>and</strong> sequence.<br />

With Tcl, multiple-line comm<strong>and</strong>s can be used within macros <strong>and</strong> on the comm<strong>and</strong> line.<br />

The comm<strong>and</strong> line prompt will change (as in a C shell) until the multiple-line comm<strong>and</strong> is<br />

complete.<br />

In the example below, note the way the opening brace ’{’ is at the end of the if <strong>and</strong> else<br />

lines. This is important because otherwise the Tcl scanner won't know that there is more<br />

coming in the comm<strong>and</strong> <strong>and</strong> will try to execute what it has up to that point, which won't be<br />

what you intend.<br />

if { [exa sig_a] == "0011ZZ"} {<br />

echo "Signal value matches"<br />

do macro_1.do<br />

} else {<br />

echo "Signal value fails"<br />

do macro_2.do<br />

}<br />

An important thing to remember when using Tcl is that anything put in curly brackets {} is<br />

not evaluated immediately. This is important for if-then-else statements, procedures, loops,<br />

<strong>and</strong> so forth.<br />

Tcl relational expression evaluation<br />

When you are comparing values, the following hints may be useful:<br />

Tcl stores all values as strings, <strong>and</strong> will convert certain strings to numeric values when<br />

appropriate. If you want a literal to be treated as a numeric value, don't quote it.<br />

if {[exa var_1] == 345}...<br />

The following will also work:<br />

if {[exa var_1] == "345"}...<br />

However, if a literal cannot be represented as a number, you must quote it, or Tcl will<br />

give you an error. For instance:<br />

if {[exa var_2] == 001Z}...<br />

will give an error.<br />

if {[exa var_2] == "001Z"}...<br />

will work okay.<br />

Don't quote single characters in single quotes:<br />

if {[exa var_3] == 'X'}...<br />

will give an error<br />

if {[exa var_3] == "X"}...<br />

will work okay.

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

Saved successfully!

Ooh no, something went wrong!