Top 20 TCL Syntax Helpful To Improve TCL Scripting Skill For VLSI Engineers PDF
Top 20 TCL Syntax Helpful To Improve TCL Scripting Skill For VLSI Engineers PDF
1. foreach loop
Use:
Where we have to iterate on each element on a list of elements and have to perform some operation on each
element.
Syntax:
foreach var $Var_list {
//operations for each $var
}
Example:
Supposed we want to print all the macros instance name, reference name and total count of macro in a block.
set macros [dbGet [dbGet top.insts.cell.baseClass block -p2].name]
set i 0
foreach macro $macros {
set refName [dbGet top.insts.name $macro -p].cell.name
puts "$macro - $refName "
https://www.manafollowers.com/post/top-20-tcl-syntax-helpful-to-improve-tcl-scripting-skill-for-vlsi-engineers 1/9
10/5/21, 11:38 PM Top 20 TCL syntax helpful to improve TCL scripting skill for VLSI Engineers
incr i
}
puts total macro count = $i
3. for loop
Use:
Where we want to repeat a loop in between a certain start and endpoint with a certain increment
Syntax:
for {initialization}{condition}{increment} {
statements
}
Example:
Suppose we want to know the metal layer's width and pitch of all metal from M5 to M10 in innovus tool.
https://www.manafollowers.com/post/top-20-tcl-syntax-helpful-to-improve-tcl-scripting-skill-for-vlsi-engineers 2/9
10/5/21, 11:38 PM Top 20 TCL syntax helpful to improve TCL scripting skill for VLSI Engineers
5. while loop
Use:
When we need to repeat a loop until a particular condition is true.
Syntax:
while {condition} {
//statements
}
Example:
Suppose we need to read all the lines of a file one by one and store is a variable dynamically.
6. if-else conditions
Use:
When we want to do something if certain condition is true. We can either put else statement or skip it.
Syntax:
if {bolean_condition} {
//statements
} else {
//Statements
}
Example:
Suppose we need to convert SVT cell to ULVT cell.
//statements
} elseif {bolean_condition} {
//Statements
} else {
//statement
}
Example:
Suppose we need to read a report file inside a script and generate an eco file in which if there is Weak Driver
then need to upsize the driver from D1--> D3, D2-->D4 and D3-->D5. We can write script as follow.
8. Arithmetic operations
Use:
When we need to add/subract/multiply/devide some numbers
Syntax:
set s [expr $a + $b + $c]
set d [expr $a - $b ]
set m [expr $a * $b]
set d1 [expr $a / $b ]
Example:
If we need to know, how much space will take a 4X, a 8X and a 16X decap cell together.
https://www.manafollowers.com/post/top-20-tcl-syntax-helpful-to-improve-tcl-scripting-skill-for-vlsi-engineers 4/9
10/5/21, 11:38 PM Top 20 TCL syntax helpful to improve TCL scripting skill for VLSI Engineers
like:
>expr 3/2
>1
>expr 3/2.0
>1.5
9. regexp
Use:
To match the regular expression. Regular expression has a wide list, we will see only few which we use mostly.
Syntax :
regexp {pattern} $string
Example:
Suppose we want to change the D1, SVT cell to D2, LVT we can check the cell with regexp and then we can
perform regsub for substitution and generate an eco file.
10. regsub
Use:
To substitute the regular expression
Syntax:
regsub {old_pattern} $string {new_pattern} new_string_name
Example:
As explained in the regexp section
Example:
https://www.manafollowers.com/post/top-20-tcl-syntax-helpful-to-improve-tcl-scripting-skill-for-vlsi-engineers 5/9
10/5/21, 11:38 PM Top 20 TCL syntax helpful to improve TCL scripting skill for VLSI Engineers
13. proc
Use:
If we need to use a few lines of code, again and again, we can make a proc using those codes and can call
easily by the proc name. No need to write code every time.
Syntax:
proc proc_name {} {
// lines of code
}
proc_name
Example:
If we need to find the basic details of a block, we can write a proc something like this.
proc blockInfo {} {
puts "Block name: [dbget top.name]"
puts "All Layers: [dbget head.layers.name]"
puts "Block Area: [dbget top.fPlan.area]"
puts "Box size: [dbget top.fPlan.box_size]"
puts "Boxes: [dbget top.fPlan.boxes]"
puts "Toatl pins: [dbget top.numTerms], Inputs - [dbget top.numInputs], Outputs - [llength
[dbget top.terms.isOutput 1 -p]]"
puts "Macro Count: [llength [dbget top.insts.cell.baseClass block -p2]]"
// Many more parameters can be added
}
We just need to source above file and call the proc blockInfo proc, it will display all the above info of block.
Example:
Suppose we want to write a general proc in which if we pass the net_name, it should return the net_length of
that particular net. We can write that as follow.
Note:
We can also set a default value of the proc argument. So in case the user does not pass the argument value,
proc will take the default value.
Syntax:
proc proc_name {{arg1 10} {arg2 20}} {
set a $arg1
set b $arg2
// More statements
}
So if we call the proc like
proc_name
it will take the default value of arg1 and arg2 and will set a 10 and set b 20.
15. exec
Use:
To use bash command inside tcl script
Syntax:
exec date
Example:
https://www.manafollowers.com/post/top-20-tcl-syntax-helpful-to-improve-tcl-scripting-skill-for-vlsi-engineers 7/9
10/5/21, 11:38 PM Top 20 TCL syntax helpful to improve TCL scripting skill for VLSI Engineers
16. dbGet/dbSet/dbQuery
Use:
These are the innovus tool-specific commands, and widely used in innovus tool related scripting.
Syntax and Examples will be discussed in a separate article.
Example:
Kindly do the man command for more details
18. alias
Use:
To shorten a long command or a command with its switches to a short command.
Syntax:
alias short_commad "original_commad"
Example:
alias si "selectInst"
alias sn "selectNet"
19. grep
Use:
To find the particular pattern
Syntax:
exec grep "pattern" $file_name
egrep and zgrep are also used in place of grep.
Example:
Will discuss in details in a separate article
Link [Not now]
20. sed
Use:
sed is called stream editor, it can do lots of tasks. we use generally sed to replace or delete a particular pattern
in a file or string.
Syntax:
exec sed
https://www.manafollowers.com/post/top-20-tcl-syntax-helpful-to-improve-tcl-scripting-skill-for-vlsi-engineers 8/9
10/5/21, 11:38 PM Top 20 TCL syntax helpful to improve TCL scripting skill for VLSI Engineers
Example-1:
If we want to replace a line having particular unique pattern completely by another line . We can do that like
folow.
Example 2:
If we want to write some lines of code which are stored in a file just after a line having some uniqe pattern. we
can do that as follow
Example 3:
If we want to delete all lines having a unique pattern
https://www.manafollowers.com/post/top-20-tcl-syntax-helpful-to-improve-tcl-scripting-skill-for-vlsi-engineers 9/9