Showing posts with label TCL in VLSI. Show all posts
Showing posts with label TCL in VLSI. Show all posts

11/06/2021

Data Structures in TCL- Part-1 : List


In this article we will focus on the area of a different data structure available in TCL. Initially we will brief about three types of data structures and later will go in deeper for each of them. The three data structures that are available in TCL. The first one is list,  the second one is called associative array, and the third one which is the newest and latest is called dictionary. You can see these three in the below figure. 



List in TCL :

A list is the data-structure similar to the array in C-Language. The difference is that a list can contain any of the integer, string, float etc as a element. The different ways a list can be created are as follows :

set myList [list a b c]

set myList "a b c"

set myList {a b c}

set myList [list $a $b $c]

set myList {$a $b $c}

Anyone of the above notation will be  accepted as creation of a valid list.

Length of a list :

length $myList

The output should be stored in a variable.

The length of the list can be calculated using the procedure length as :

Joining of More Than One List :


To join more elements we can use append procedure for an existing lista delimited string can be splitted into a list by using split procedure as :


split <delimited-string> <delimeter>

Lists can be joined together using concat procedure as :

concat  <list1> <list2> ..... <listn>

To understand you may copy and run the below example. Also you may follow the narration mentioned in the video down below.

Sorting Inside a List :

We can sort the content of a list using the losrt procedure. Its different argument switch will allow us in the below way:

To sort in asciii order we use : -ascii 
To sort in integer increasing order we use : -integer -increasing
To sort in integer decreasing order we use : -integer -decreasing
To sort in dictionary order we use : -dictionary
To sort in real increasing order we use : -real -increasing
To sort in real decreasing order we use : -real -decreasing
all of the above-mentioned sorting is exemplified by this code
:




Iterating Over A List :

The best way to iterating over a list is to use the foreach loop. The foreach loop is already explained and exemplified in previous article. However run the below example to understand the iteration with a counter :





Append, Insert and Replace Elements Inside a List :

We can use lindex proc to get the positional value of a list element by its index.

lindex <list> <index

Gives the value at the <index> of the <list> 

To make a entry in the List from the R.H.S , we can use the below syntax :

lappend <list> <element>


To make a entry in the List from the L.H.S , we can use the below syntax :
linsert <list> 0 <element>


We can replace a range of elements in the the list by this syntax :
lreplace <list> <start-index> <end-index> <new-element-to-be-inserted>


All the above mentioned cases can be observed through the below code-snippet :

List of List :

Lists can be nested in the below way : 

list a b {c d e} {f {g h}}
now {g h} is nested inside {f {g h}} which is further nested in the topmost list using list proc.
We can use split/concat/linsert/lreplace on list of list operations as shown in below code:



Hierarchical Printing of List-of-List :

The below self-explanatory code example shows the way to do the hierarchical printing of list of list. For detailed explanation please watch the video down below in this page.


Searching a list element :

lsearch can be used to search any list element inside a existing list. This is explained through the below code example :




For detailed explanation please watch the video below :



Courtesy : Image by www.pngegg.com


Variables in TCL , Control Structure , Loops , Switch-Case, Procedure , Variable Scope & Upvar Command


In this article we are going to discuss variables in TCL. We will discuss this through the below example. 

Scalar Variable in TCL :

First let us see how to define a variable and print it :

set money 1900;

puts  "money is = $money ";

The variable "money" is a scalar variable. We can store a single value in it. To print it we simply use the puts command.

Next let us do some mathematics with the scalar variable.

set a 10;

set b [expr $a+5];

puts "==$a===$b===";

We set a with 10 and we use expr procedure in the above-mentioned way to add 5 to the value stored in variable a. 

Please notice when we define a scalar variable we do not use the symbol $ in the variable name.  However whenever we are accessing the value we use $.

Next , let us see how we can empty the the content of a variable:

unset a

puts "==$a===$b===";

we use unset command to empty the content of a variable.

Then when we print the two variables , a do not give any value where as b gives 15.

Now we can check that whether a variable is defined or not by the following command :

[info exists a] 

This will return a 0 value if a is defined. Adding a ! will convert 0 to 1. Now we use this along with the the below if condition :

if {![info exists a]} {

set a 50

}

This piece of code will check that if a is defined then we assign value 50 to it. 

To increase the value by 1 , we can use the below command:

incr a;

puts "==$a===$b===";

This will print a = 51 and b as 15.

For your easy learning practice , the blow code is provided



If-ElseIf-Else Control Structure :

In TCL the basic structure of if-else is as follows :

if { condition is true } {

statement

} else {

statement

}

Notice that there is a space between text and { or }  and between } and { . This is a must otherwise you may face syntax error. 

Now if there is a lot more conditions , then to incorporate that we can write elseif rather than nested if else conditions.

if { condition-1 is true } {

statement

} elseif { condition-2 is true } {

statement

} else {

statement

}

You can run the below piece of code to understand the above-mentioned control structures.



While Loop in TCL :


The basic structure of while loop is :

while { condition holds true } {
statement
statement
.....
statement
}

To break out of the loop you may use break keyword. 
To increase the counter without executing the rest of the code you may use continue keyword.
The below example gives you the the consolidated use of continue/break with the help of the if-elseif-else conditions :



For Loop In TCL :


The basic structure of the for loop in TCL is:

for { initialisation counter } { condition check counter } { Increment or Decrement counter } {
statement
statement
.....
statement
}

Please mind the gap between two consecutive curly braces ,i.e. } and {, in whatever order. Otherwise you may face syntax error.  The use of after and update commands together , adds some time delay in between the two consecutive print statement for visual delight.

The blow examples are self explanatory:

Here is the up-counting example :


Here is the down-counting example :


Here is the up-counting example with increment other than 1 :




The Foreach Loop In TCL :


The basic structure of the for-each loop in TCL is:

for counter-variable { list of scalar variables of any kind } {
 do something with $counter-variable
}

The list is like the array however we can store any kind of scalar i.e number , text etc.

Per iteration the list is exhausted from the left side by popping out the left most variable into the counter-variable. 

When the list gets exhausted the iteration stops.

Please mind the gap between two consecutive curly braces ,i.e. } and {, in whatever order. Otherwise you may face syntax error.

The below examples are self explanatory. 

The use of after and update commands together , adds some time delay in between the two consecutive print statement for visual delight.

Example-1 : the list is declared directly inside the foreach loop


Example-2 : the same list is declared outside the foreach loop


Example-3 : the same list is created from Unix Command Output


Example-4 : Accessing Multiple Lists in a single foreach loop : Use like a Look Up table


Example-5 : Accessing Multiple Lists in a single foreach loop  :  uneven number of variables are popped out from the two different lists




Switch-Case Statement in TCL :


The switch case statement in TCL have the below structure:

switch $case-variable {

<case value 1>  { statement } 
<case value 2>  { statement }
<case value 3>  { statement }
<case value 4>  { statement } 
<case value 5>  { statement }
default         { default action }

}

The case-variable in the above structure is generally a scaler.

Any of the statement can be blank also.

The below example is self-explanatory :

 


Procedure in TCL :


The procedure is similar to the function in the c-language.

The procedure can be simple structure as :

proc name-of-proc {  arguments  }  {
statement
statement
}


And it can be used as :

set variable-name [ name-of-proc <arguments separated by space> ]


The output of the procedure will be stored in $variable-name. 
Then we can use the $variable-name further in our code.

The output of the of one procedure can be piped through another procedure in a cascading manner as :

set variable-name [ proc-3 [ proc-2 [ proc-1 <arguments  separated by space> ]  ]  ]

The below example is self explanatory:
 
 

Scope of Variable in TCL :

The scope of variable can be understood by running the below example & comparing the code and the output.

For explanation please watch the first video mentioned down below this page.


Upvar in TCL :

The upvar command "ties" (makes an alias) the name of a variable in the current scope to a variable in a different scope.

This is commonly used to simulate pass-by-reference to procs.

You may run the below code example and compare the code with the output to understand the usage of the upvar.

For explanation please watch the first video down below.




Video-1 :  Basics of  Variables in TCL , Control Structure , Loops , Switch-Case, Procedure ,  Variable Scope & Upvar Command



Video-2 :  ForEach Loop As Look-Up-table



Video-3 :  Foreach-in-collection from EDA Tool Shell ONLY



Courtesy : Image by www.pngegg.com




10/30/2021

What is TCL in VLSI ? How APIs Work in VLSI Tools ?

TCL or Tool Command Language is one of the most important and popular scripting language in EDA/VLSI.In this article we will discuss about TCL., its significance in VLSI. 


What is TCL in VLSI :


TCL or tool command language is an open source multi purpose interpreted powerful dynamic scripting language. This is interpreted language and here we write a script and directly execute it. There is no need of compilation like the C-Language. TCL is is a dynamic language because you can change the code on-the-go. Then again copy the code in the TCLSH-Shell or Your VLSI-EDA-Tool Shell. TCL is very powerful language because of its multiple data structures with high data-mining capability . Another aspect of its power is that it can directly talk to you design under consideration. Let us consider the scenario that you have done a design through your VLSI software and when it becomes large you can inspect it with your design tool's TCL shell. 

TCL can be fit for both small and large programming test. This means that you can write a four line code and source it in your tool's shell. OR you may write a huge line of codes and make it talk it to the tool. Hence TCL is widely used in various domains in VLSI design and verification process. To be mode specific design means when you are designing a chip , you can use the TCL-Code to your respective tool through its interface for the designing purpose, verification  or quick-check. A a verification engineer, you will find that you can use the tools in built-in shell to query your verification queries. The kind of verification subjects to the particular tool's shell and the corresponding available APIs.  API is are called application programming interfaces which we will cover later in this article.


Domains of VLSI to use TCL Scripting :


Let's know what are the domain where TCL scripting is used.

1. Front-End Synthesis Tool : 

I consider that you are a beginner a person who knows nothing about where all the TCL is used in the VLSI Design . In this section you are about to know in which particular fields that TCL is used. And most importantly why you should learn tickle at all ! The first section where the TCL is used is the front-end synthesis tool in the ASIC-design. This stage comes immediately after we are doing the RTL coding & simulation using a HDL simulator. Multiple tools from multiple vendors there the TCL shell is available inside it. There you can apply your TCL scripting skill just to  to contribute in the designing process automation.

2. PnR & STA Tool: 

In the back-end placement and route EDA tool to do the Place and Route (PNR) Automation various vendor will provide you a TCL shell as a integrated part of the PNR tool. Their you can do some TCL scripting to automate your PNR process. Also sometime you can do query on some part of your design under construction. Automation rather is a generic terminology that can be applicable to the both PNR & Static Timing Analysis.  STA tool is used in both the front end part as well as the back and part of the ASIC design. In both cases you can utilize its powerful TCL shell to attain your goal. 

3. Reliability Analysis Tool : 

Many vendors to provide a interface where you can do the TCL scripting to do the reliability analysis & its control over various bench-marking parameters. For some vendors to code the EM-IR rules you may need TCL. 

4. Scripted Waveform Verification in Analog-Design: 

Scripted waveform verification in Analog-design is a bit different from the digital-verification. In Analog Verification, there will be predefined TCL commands that will help to to achieve your goal. In case you need to verify something of your own, generally the EDA Tool Vendors will provide the TCL interface APIs to write your own tickle code, to query necessary data that you are looking for.

5. Design For Testability Tool (DFT) : 

Design for testability Tool(DFT) is done for almost each and every design. So design for testability is very widely used in all the parts of VLSI. Here you will also have TCL shell inside the tool where you can source your TCL code.

 

Importance of TCL:


The obvious question is "there are several scripting languages and why talking about TCL here? what is its importance? " Well , TCL script can integrate with major EDA tools with interactive shell. 

Another beauty of TCL is that it supports cross platform scripting. Suppose some EDA Tool may be independent of the OS and in that case your TCL scripting could be done in in one  operating system (OS) and you can reuse the same TCL Code in another OS. 

TCL provides built in data structures such as list/arrays and dictionaries. Don't worry in this Series of TCL Articles, we will be covering all of these Data Structures. Data structure are very strong point of a scripting language because when we are doing a design or verifying a design with a TCL script, you will get a a huge amount of data. To handle such mammoth amount of data , you have to do the data-mining. In TCL you can do this easily with the help of the inbuilt data structures that are already available in TCL. Thus to deal with the all the data that is coming to you as as a response to your query , you can store it in TCL data-structures. Later you can manipulate the data at your own end or write in to a file in disk in csv or xml format. 

Control structures such as if/while/foreach/for/switch gives a programmer a very much flexibility to do the coding for various situations. Generally we learn C as a first programming language, you might have came accoross the control structures at that time. Similarly all of this control structures & few more additional ones are there available in TCL . 

Regular expression engine in TCL is as robust as for Pearl or Python. TCL has inbuilt regular expression engine. Practically this is needed when you are processing a huge number of nets in ASIC-Design. You are filtering a particular type of nomenclature of nets among all the nets in teh whole design, you can apply regular expression there. Thus you may sort only those particular type of nets with specific kind of nomenclature. However the use of regex is not limited to this spcific kind, you are free to use regex of any kind of application that  you want to do. 

TCL being open source means that you can download the source code without charge, inspect the source code, and if needed you can make your custom changes. 


TCL Script & DUT :


Now let us discuss about how the design & TCL Script are placed around each other. From the info-graphics you can understand that the tool will read all of the input files from the design under test (DUT). Cumulatively it could be GBs of data containing inside these input files. Thus , so much data are fed into the EDA Tools and it read them to become ready for you. Now the all data is alive and it combines the design that is under test as well as many more associated data. 

Thus the design is now LIVE & available to you at the EDA tool TCL shell. Live means the right away you make the query then and there right away you get a response from the tool's shell for any smallest part of your design. This is why the tool's TCL shell is a very powerful engine for a VLSI designer. Now the tool's APIs are live & ready to be used.




Each EDA Vendor will provide you a manual where the description of the input and output of the APIs will be mentioned. Combining basic TCL Code and APIs you can write your TCL code either for design purpose or for verification purpose. Or you may be doing something else what you do your tool allows you to do through the TCL Shell. You simply source your TCL script in the tool's shell & you are done. The tool absorbs the TCL code and run it through all the loaded design data.

If you have written TCL procedures, its now the time to call the call those procedures one by one to get your job done. Procedure are the like C functions, write once and use many times. 


TCL Code & Data Query:


I have just mentioned about that how in VLSI design will become live in the TCL shell. Now in this section , I will provide another  info-graphics to make you understand how your query goes up to the design and result comes back to you. By looking into the info-graphics , the first outermost shell is your checking code using API. Here you have to give the TCL code with basic Syntax combined definitely with the tools very own APIs as well. The next layer is is this is your code is interpreted by EDA Toll's TCL shell. Then it passes through the VLSI tools API interface-layer. Now this is a completely software concept. For now just understand that this much is is sufficient for you as a VLSI engineer. Then the command passes through all the layer upto the live design with all the data loaded into the data structures.




When you make a query, it crosses all this layer and go up to the live design and from the live design the query pick sup the required data and get back to your TCL shell . This data output would be your design related stuff for verification related query. For anything else that will be according to what is defined in the tool's API Manual.  This manual will be separately provided by each vendor for each of the individual tool. So no vendor have generic  API Manual. Rather it is specific to the particular tool and the particular vendor.


TCL  API :


So long we are talking about API API API ! So what is API ? It is an application programming interface , abbreviated as API,  that helps interactions between the tool and the human user through the written TCL code. Now , interface means that there is a software layer which allows you to communicate between the two different parties. Here the two different parties, one is you and another is the design. The communication happens through your TCL code and the API-Layer. Each tool vendor will have their manual for their respective APIs for each of their different tools. There is nothing call generic API there. APIs are very specific. If you have you have a tool for the front end that has a shell, so its API will be specific to that particular tool. For backend they will have specifically different API manual. Again API manual will vary from one tool vendor to vendor to another . For the same to vendor it will vary from one tool to another tool because these are TCL-Procedures that is written by the software company for specific target purpose. The APIs also provides extended functionality in the various tools. 
Apart from the inbuilt software functionality, additional usability can be added by the APIs. APIs also provides ways to tweak any existing software command.  With TCL APIs live access to the pre-loaded design Under test will be there with all associated data annotated. 
With information hiding, API enable modular programming. This is a beauty as a software point of view that when tool has API ,  you cannot see the software code although you are talking live to the design. you Cannot see all the basic design a data as well as the all additional data without doing a query through the API layer. Thus API is a software concept.Through the API layer will not help you not to see the software code obviously as this is a proprietary EDA software. 

How to use API : Data Dumping

So in this particular section will be discussing about how to use API data dumping. Your first your input query is entered through the the API function. API function here will carry out your instructions. As a result it will this will generate a data list or array or any custom data-structure exclusively owned by the EDA tool. All lookup table are interconnected data that are interconnected in one to one mapping. Generally these look up table data are termed as hash tables and are called dictionaries specific to TCL .Once you get the data then you can use the particular Data Structure to capture all these data and store them in the typical Data Structure inside your own TCL Code as needed. Then finally for your verification purpose or designing purpose you can dump them in text or csv file as you like. I am emphasizing again that each tool will have its own API manual and you have to consult it every-time use a new API. 



So we can subdivide the entire this flow in a three-part section. First part comes the query that you are doing.  Second part coming as the capture of the data. Third part comes as the dumping of the data in a hard-code manner. For first part you will use TCL APIs heavily.  For the second and the third part you will use generic TCL syntax (i.e TCLSH syntax) heavily. 


For video lecture on this article please watch the below video :



Courtesy : Image by www.pngegg.com 




10/27/2021

How to Detect Warnings from EDA Tool Log File through TCL ?


We come across log file every now and then from various EDA tools in VLSI. The part of the log file that bothers us most is a warning and error. So a general question in TCL that how to print only the warnings from a given log file. In this article we are going to demonstrate our short and sweet TCL Code to extract the warnings from log file using TCL. This code an be sandwiched within your own TCL shell-code of the EDA Tool.

I was doing some research on the Internet to find out a particular file log which is not written by me. I was looking for a LOG file that is containing different types of warnings. Finally I found one and here it is :


You can see that of the some warning is followed by two messages. The second type of warning you can see these are sufficient in one line. Thus this is a good candidate for the code. Now with the blow info-graphics the code Flow & Organisation is described.


Now let us look into the TCL code :

Now in the above code you can see that we have dumped a output log file with the extraction of warnings from the input log file. I will advise you keep this practice because if suddenly the Terminal is closed you will not be able to recover the message. Whereas if the output is written into a file then you will be able to recover it. This habit will help you in long run.

For Code Execution & Live Demo please watch this video below :


Courtesy : Image by www.pngegg.com