General

TCL Training Series – upvar

We have seen the command “uplevel” and how to use it earlier. Now, let’s look into a related command upvar.

Syntax
The TCL language reference manual gives the following description for the command.
upvar ?level? otherVar myVar ?otherVar myVar …?

This command arranges for one or more local variables in the current procedure to refer to variables in an enclosing procedure call or to global variables. Level may have any of the forms permitted for the uplevel command, and may be omitted if the first letter of the first otherVar isn't # or a digit (it defaults to 1). For each otherVar argument, upvar makes the variable by that name in the procedure frame given by level (or at global level, if level is #0) accessible in the current procedure by the name given in the corresponding myVar argument. MyVar is always treated as the name of a variable, not an array element. OtherVar may refer to a scalar variable, an array, or an array element.

Now let’s see one simple program and its output. In the following code, there are three levels. Level#0 or the top level calls the procedure “a” which is level#1. The variable x is set to 1 in procedure a, and procedure a in turn calls procedure “b”, which is level#2. At this level, there is an upvar call that refers to the x value 2 levels up.

Now run this program, and you should see:

Variable x is assigned in level#2 the value it had in top level.

2 Comments

2 Comments

  1. Kishorekumar A S

    January 11, 2019 at 5:07 pm

    hello mam i have a doubt on setup and hold checking , why the hold check done at same clock edge instead of next clock edge

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular

VLSI Pro is a professional network of VLSI engineers. Here you can find latest news, helpful articles and more on VLSI technology.

Copyright © 2016 VLSI Pro

To Top