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.

Tcl examples<br />

This is an example of using the Tcl while loop to copy a list from variable a to variable b,<br />

reversing the order of the elements along the way:<br />

set b [list]<br />

set i [expr {[llength $a] - 1}]<br />

while {$i >= 0} {<br />

lappend b [lindex $a $i]<br />

incr i -1<br />

}<br />

This example uses the Tcl for comm<strong>and</strong> to copy a list from variable a to variable b,<br />

reversing the order of the elements along the way:<br />

set b [list]<br />

for {set i [expr {[llength $a] - 1}]} {$i >= 0} {incr i -1} {<br />

lappend b [lindex $a $i]<br />

}<br />

Tcl examples UM-483<br />

This example uses the Tcl foreach comm<strong>and</strong> to copy a list from variable a to variable b,<br />

reversing the order of the elements along the way (the foreach comm<strong>and</strong> iterates over all of<br />

the elements of a list):<br />

set b [list]<br />

foreach i $a { set b [linsert $b 0 $i] }<br />

This example shows a list reversal as above, this time aborting on a particular element using<br />

the Tcl break comm<strong>and</strong>:<br />

set b [list]<br />

foreach i $a {<br />

if {$i = "ZZZ"} break<br />

set b [linsert $b 0 $i]<br />

}<br />

This example is a list reversal that skips a particular element by using the Tcl continue<br />

comm<strong>and</strong>:<br />

set b [list]<br />

foreach i $a {<br />

if {$i = "ZZZ"} continue<br />

set b [linsert $b 0 $i]<br />

}<br />

The next example works in UNIX only. In a Windows environment, the Tcl exec comm<strong>and</strong><br />

will execute compiled files only, not system comm<strong>and</strong>s.) The example shows how you can<br />

access system information <strong>and</strong> transfer it into VHDL variables or signals <strong>and</strong> Verilog nets<br />

or registers. When a particular HDL source breakpoint occurs, a Tcl function is called that<br />

gets the date <strong>and</strong> time <strong>and</strong> deposits it into a VHDL signal of type STRING. If a particular<br />

environment variable (DO_ECHO) is set, the function also echoes the new date <strong>and</strong> time<br />

to the transcript file by examining the VHDL variable.<br />

(in VHDL source):<br />

signal datime : string(1 to 28) := " ";# 28 spaces<br />

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

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

Saved successfully!

Ooh no, something went wrong!