Extracting Library and Cell Names from a Top Cell Hierarchy Using SKILL Code
Contents:
This guide explains how to extract the names of libraries and cells used in a top cell hierarchy within layout and schematic views. Essentially, it answers the question: What libraries and cells are utilized in the design?
Key Considerations:
- The goal is to collect library and cell names once. For object counting, other techniques should be used.
- Larger top cells may result in longer execution times.
1. Approach
The method involves traversing the top cell's hierarchy, like navigating through layout or schematic windows. Manually, you would select an instance and descend into its cell view. Our SKILL code achieves this using recursion, tracking visited library and cell names with SKILL's table data structure.
2. SKILL Code
1procedure( getLibrariesCellsUsedIn(cellView 2 @optional (usedLibrariesCellsTable nil)) 3 /* 4 Retrieves all libraries and cells used in the hierarchy of a given 5 cell view. 6 7 @param cellView dbObject 8 The cell view object from which to retrieve the hierarchy. 9 10 @param usedLibrariesCellsTable table 11 Optional. A table to keep track of used libraries and cells. 12 If not provided, a new table is created. 13 14 @return table 15 A table containing libraries as keys and tables of cell names as 16 values, representing the hierarchy. 17 */ 18 let( (cellTable libName cellName cellObject message viewName nextCellView) 19 20 ; First initialization 21 unless( usedLibrariesCellsTable 22 usedLibrariesCellsTable = makeTable('usedLibrariesCellsTable nil) 23 cellTable = makeTable('cellTable nil) 24 cellTable[cellView~>cellName] = t 25 usedLibrariesCellsTable[cellView~>libName] = cellTable 26 );unless 27 28 foreach( instance cellView~>instHeaders 29 libName = instance~>libName 30 cellName = instance~>cellName 31 cellObject = ddGetObj(libName cellName) 32 33 if( !cellObject 34 then 35 message = strcat("[getLibrariesCellsUsedIn] " libName "/" 36 cellName " cell doesn't exist in your Library Manager") 37 warn(message) 38 else 39 ; Creates cells' table for a library 40 unless( usedLibrariesCellsTable[libName] 41 cellTable = makeTable('cellTable nil) 42 usedLibrariesCellsTable[libName] = cellTable 43 );unless 44 45 unless( usedLibrariesCellsTable[libName][cellName] 46 ; This cell is not in table yet 47 usedLibrariesCellsTable[libName][cellName] = t 48 49 ; Gets instance's cell view 50 viewName = mapViewName(instance~>viewName) 51 nextCellView = dbOpenCellViewByType(libName cellName viewName) 52 when( nextCellView 53 usedLibrariesCellsTable = getLibrariesCellsUsedIn(nextCellView 54 usedLibrariesCellsTable) 55 );when 56 );unless 57 );if 58 );foreach 59 60 usedLibrariesCellsTable 61 );let 62);procedure 63 64 65procedure( mapViewName(viewName) 66 /* Maps a view name to a common view name that includes 'instances' 67 for hierarchy traversal. 68 69 @param viewName string 70 The name of the view to be mapped. 71 72 @return string 73 The mapped view name. 74 */ 75 76 if( viewName == "symbol" ; Symbol's cell view doesn't have ~>instances 77 then 78 "schematic" 79 else 80 viewName 81 );if 82);procedure
3. SKILL Code Overview
Encapsulating code in functions allows us to reuse the code in other tools.
Lines 1-17:
Define the main function, including its name and arguments. Documentation is optional but recommended.
- cellView: The top cell's cell view dbObject, obtainable via dbOpenCellViewByType.
- usedLibrariesCellsTable: An optional argument for tracking visited libraries and cells during recursion.
Line 18:
Use let to define local variables (memory management in Virtuoso is beyond this guide's scope, though, it can be a different topic for a guide).
Lines 20-26:
Initialize the tracker table for the first time, which will track visited libraries and cells.
Lines 28-58:
Traverse all instances in the current cell view, marking them as "visited" and delving deeper into the hierarchy.
Lines 29-31:
Define variables to hold instance’s necessary data for the algorithm.
Lines 33-37:
Check if current library and cell names exist in the database, using a “dd” object. If not, print a warning in the CIW and skip the descension code for the current instance.
Lines 39-43:
If visiting the library name for the first time, initialize a table for cell names.
Lines 45-56:
Skip if the cell name has been visited; otherwise:
- Line 47: Mark it as visited.
- Line 50: Map the view name to ensure instances are accessible. When we traverse the schematic hierarchy, every instance’s view will be a symbol, which, when open, doesn’t include information, such as “instances”. Thus, we need to map a “symbol” to a “schematic” view using our helper function - mapViewName.
- Line 51: Open the next cell view, using the mapped view name.
- Lines 52-55: Descend into the next cell view.
Line 60:
Each recursive function iteration returns a reference to the tracker table.
Lines 65-82:
mapViewName: Maps "symbol" to "schematic" view; otherwise, returns the given view name.
4. Function Output
The main function, getLibrariesCellsUsedIn, returns a SKILL table with library and cell names as strings. This data can be used to call other functions, create objects, or access further information.
5. Usage Examples
After loading the main code, run the following in CIW:
1libName = “my_lib_name” ; Replace with actual names 2cellName = “my_cell_name” 3viewName = “view_name” 4cellView = dbOpenCellViewByType(libName cellName viewName) 5table = getLibrariesCellsUsedIn(cellView)
After execution, the table variable can be utilized in various ways:
- Get library names only:
1libraries = table~>?
- Get library’s cell names:
1libName = “my_lib_name” ; Replace with actual name 2cells = table[libName]~>?
- Access each cell in each library:
1foreach( libName table 2foreach( cellName table[libName] 3; Do stuff, e.g., open cell view, get views names, etc. 4; cellView = dbOpenCellViewByType(libName cellName "layout") 5; views = ddGetObj(libName cellName)~>views~>name 6) 7)
6. Alternative Methods
Besides SKILL, other methods exist for hierarchy extraction:
- From layout or schematic window: Use Edit -> Hierarchy -> Tree… or Shift+T bind key (by default) to generate a text file with hierarchy info.
SKILL Hierarchy Tree
In schematic view it’s “Print Tree”.
- Using fastTree tool in a Linux terminal (if installed):
1fastTree -lib ,[object Object]
This creates a file (default: cellName.viewName.tree) that can be parsed with SKILL or other programming languages.
Author: Eugeny Khanchin