You are on page 1of 11

TCL

Tool Command Language.


In VLSI interaction with the tools is required. We use TCL to interact with the
tools.
Syntax:
set a 12
puts a
Output : a
puts $a
Output : 12

Special Variables :
argc : it gives the count of arguments.
argv : it prints the argument values.
argv0 : it prints the name of the script.
Example:
#!/usr/bin/tclsh
puts $argc
puts $argv
puts $argv0

$ ./Special_variables.txt -x1 10 -x2 20 -y1 3 -y2 4


8
-x1 10 -x2 20 -y1 3 -y2 4
./Special_variables.txt
Area of Macro

#!/usr/bin/tclsh

if {$argc != 8 } {
puts "Incorrect no.of arguments"
exit
}

set field [split $argv " "]


lassign $field a b c d e f g h

if {$a == "-x1"} {set x1 $b}


if {$a == "-x2"} {set x2 $b}
if {$a == "-y1"} {set y1 $b}
if {$a == "-y2"} {set y2 $b}

if {$c == "-x1"} {set x1 $d}


if {$c == "-x2"} {set x2 $d}
if {$c == "-y1"} {set y1 $d}
if {$c == "-y2"} {set y2 $d}

if {$e == "-x1"} {set x1 $f}


if {$e == "-x2"} {set x2 $f}
if {$e == "-y1"} {set y1 $f}
if {$e == "-y2"} {set y2 $f}
if {$g == "-x1"} {set x1 $h}
if {$g == "-x2"} {set x2 $h}
if {$g == "-y1"} {set y1 $h}
if {$g == "-y2"} {set y2 $h}

set area [expr ($x2 - $x1) * ($y2 - $y1)]


puts $area

Output :
$ ./Area.txt -x2 20 -x1 10 -y1 3 -y2 20
170

./Area.txt -x2 20 -x1 10 -y1 3 -y2


Incorrect no.of arguments
String Operation : Please refer to the script file
List Operations and Questions related to list operations : Please refer to the
script file

LOOPS AND CONDITIONAL STATEMENTS


Conditional Statements :

Syntax :

if {condition 1} {

# Executes when the condition1 is true

} elseif {condition 2} {

# Executes when the condition2 is true

} elseif {condition 3} {

# Executes when the condition3 is true

} else {

# executes when the none of the above condition is true

}
Loops :

a) For loop

Syntax :

for {initialization} {condition} {increment} {

statement(s);

b) while loop

syntax :

initialization

while {condition} {

statement(s);

incrementation;

Break and Continue Statements:

Break :

The break statement in TCL language is used for terminating a loop.

When the break statement is encountered inside a loop, the loop is


immediately terminated and program control resumes at the next statement
following the loop.

Continue:

Similar to break statement but instead of forcing termination, continue forces


the next iteration of the loop to take place, skipping any code in between.
Questions related to loops : Please refer to the script file

ARRAYS: Please refer to the script file.


DICTIONARY : Please refer to the script file.
PROC : Please refer the script file.

FILE MANAGEMENT
 Open a file
 Read content
 Write file content (new content replaces the old content)
 Append file content (new content is added after the old content at the
end)

3 modes to open a file : Read mode


Write mode
Append mode

Reading a file : We can read the contents of a file using gets command.
gets command will read a line one by one from a file. When it completes
reading first line, it automatically increments to the second line. When all the
lines are read, it will return -1.

Question Related to file handling : Please refer to the script file


REGULAR EXPRESSION

Regular expression The "regexp" command is used to match a regular


expression in TCL. A regular expression is a sequence of characters that
contains a search pattern.

RULES :
QUESTION :
To extract the entity name in entity declaration from a VHDL file and to save
result in file.
Note: Create one VHDL file with many enity declarations and with different
entity names
RULES OF VHDL:
 Any of spaces is allowed at beginning or no spaces is also fine
 key word entity will be there in the beginning.
 Min one space is required after entity and any number of space is fine
 Entity_name: First char should be always a alphabet #:other character can
be alphabets/numbers/_
 Min one space is required after entity_name and after that any no of space
is fine
 Keyword is is compulsory
PLEASE REFER TO THE SCRIPT FILE FOR SOLUTION
OPERATORS
Boolean Operators :
&& logical and
|| logical or
! not
Arithmetic Operators :
+ : Adds 2 operands
- : Subtracts 2 operands
* : Multiplies 2 operands
/ : Divides 2 operands. Returns the quotient
% : Modulus Operator. Returns the remainder.

Ternary Operator:
?:
Condition true ? true value : false value

Relational Operator:
< : less than
< = : less than or equal to
> : greater than
>= : greater than or equal to
= = : equal to
!= : not equal to
Bitwise Operators :
~ : bitwise negation
^ : bitwise exclusive or
& : bitwise and
| : bitwise or

REGULAR SUBSTISTUTION : PLEASE REFER TO THE SCRIPT FILE

You might also like