Basics of TCL
Being a VLSI engineer we work on many industry tools and these tools need an automation rather than manual work as we need to handle many issues at the same time. We can’t go and fix all this manually as it will cost us a lot of our precious time. So, we need an automation which will help us in doing our job easily. In this scenario, TCL comes into picture. TCL is the short form for 'Tool Command Language'. Let's learn the basics of TCL.
We will discuss TCL in easy and detailed manner with concepts and how to write script w.r.t tools and how to execute them. We always think TCL as very hard and don’t want to work on it, due to which we lose our confidence while working with our colleagues. I am trying to have all the concepts which will help you to write script. Read and go one by one.
One more thing I want to tell here is, if you are looking for some kind of help in writing the script, then mail me or comment it here, I will get back to you surely. But before this you need to learn the below mentioned things with seriousness.
Take a Linux terminal and run “tclsh”, then you will get TCL shell to work on. Before going to understand the scripts, first let’s understand how to set variable and call it back whenever needed. We can set a variable using set command and call it using puts followed by “$” and variable which has been set. Below is the example.
$ -> To read the variable
# -> Comment, basically after # whatever is written will not have any value or meaning.
Example
set design 4 puts $design
Output
4
Example
%> set string “It is a string” ## If this is a string then you can use “” and {}. %> puts $string
Output
It is a string
%> set string {It is a string} %> puts $string
Output
It is a string
%> set string “It is a \n string” ## “\n” is the newline, wherever we put whatever after this will be in new line
%> puts $string
It is a
string
%> set design [expr 3+1] ##For arithmetic calculations we can use “expr” which will help to execute.
%> puts $design
4
##We can use a variable to define another variable.
%> set design 4
%> puts $design
4
%> set new_design [expr $design +2]
%> puts $new_design
6
Mathematical Expressions
%> set variable 10
10
%> set result [expr $variable / 9]
%> puts $result
1
%> set result1 [expr $variable / 9.0]
%> puts $result1
1.1111111111111112
%> set variable1 10.0
10.0
%> set result2 [expr $variable1 / 9]
%> puts $result2
1.1111111111111112
Operators in TCL
There are basically 5 types of operators in the TCL. They are as follows:
1. Arithmetic Operator
2. Relational Operator
3. Logical Operator
4. Bitwise Operator
5. Ternary Operator
1. Arithmetic Operator
Similar to what we do in Mathematics, all the ways of calculations are required to support in TCL execution. Below are the one. A=50, B=100 will be the number which we will use for the examples below.
- Addition (+) – This is a normal Addition which adds 2 numbers. C = A+B (50+100=150)
- Subtraction (-) – This is normal Subtraction which subtract 2 numbers. C = A-B (50-100=-50)
- Multiplication (*) –This is normal Multiplication which multiply 2 numbers. C = A*B (50*100=5000)
- Divide (/) – This is normal Divide which divide 2 numbers. C =B/A (100/50=2)
- Modulus (%) – The remainder of divide is called as modulus. C=B%A (100%50=0)
2. Relational Operator
Relation between two numbers represent the relational operator in TCL. There are below relational operators:
- “==” -> If two values are same, then this operator will be true otherwise false.
- “!=” -> If two values are not same, then this operator will be true otherwise false.
- “>” -> This checks if the value present in right hand side is greater than left hand side, then it is true otherwise false.
- “<” -> This checks if the value present in right hand side is lesser than left hand side, then it is true otherwise false.
- “=>” -> This checks if the value present in the right-hand side is greater than or equal to left hand side, then it is true otherwise false.
- “=<” -> This checks if the values present in the right-hand side is lesser than or equal to left hand side, then it is true otherwise false.
3. Logical Operator
Logically two values can have relation which can be represented with logical operators. Here are logical operators.
- Logical AND Operator – “&&” represents logical AND operator which means if value of A and value of B are same means 1 (TRUE) then A&&B will be 1 (TRUE), but if one of the value from A and B are 0 (zero) then result will be false.
- Logical OR operator – “||” represents logical OR operator which means if values of A and B are not same then the value is 1 (TRUE).
- Logical NOT Operator – “!” represents the NOT operator which means if some values don’t match and we want to match then use this operator. Works same as NOT gate.
4. BitWise Operator
Bits are represented in 0 or 1. AND, OR and XOR three bitwise operator are mostly used by TCL.
5. Ternary Operator
“? :” is ternary operator. Where it says if condition is true? then A : otherwise B.