Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API...

79
Verdi 3 NPI Training Language and Netlist Models Based on Verdi 3 2013.01

Transcript of Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API...

Page 1: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 1

Verdi3 NPI Training Language and Netlist Models

Based on Verdi3 2013.01

Page 2: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 2

Glossary

• VIA = Verdi Interoperability Applications

• NPI = Novas Programming Interface

• Novas KDB = Novas Knowledge Database

• FSDB = Fast Signal Database

• VPI = Verilog Procedural Interface

Page 3: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 3

Overview

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• Debug Tcl Scripts

• Labs

Page 4: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 4

Overview

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• Debug Tcl Scripts

• Labs

Page 5: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 5

A Platform for Customizing Verdi

Verdi

Database

HDL

SDC C-API

Tcl

CPF/UPF

.lib

Page 6: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 6

Complete Data Models

• Five models: Language, Netlist, Text, DM, and FSDB models

– Language & Netlist model will be introduced in this training, refer to Text, DM,

and FSDB model training slides for other models

VIA – NPI Data Models

Netlist Model

Design Manipulation

Model

Language Model

Compilers of Verdi

Inference

HDL SDC,CPF/UPF…

Parsing Tree

HDL SDC,xPF… FSDB

FSDB Model

Traverse source code

Trace connectivity

1. Modify design instances and connections 2. DM/TEXT model for keeping readability

Access FSDB file

Page 7: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 7

Convenient Libraries

• NPI libraries extend the functionality of NPI data models to improve

productivity

• Open source code for both C/C++ and Tcl

• Complete document includes source code, syntax description and

related examples.

200 well-defined functions & procedures

with detail description and sample code!

Page 8: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 8

Powerful Interoperability Apps

• Built on top of NPI data models, libraries, Verdi commands, or 3rd party tools

Easy to manage your VIA scripts!

Page 9: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 9

New VIA Exchange Web Site

Page 10: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 10

Complete Document

Page 11: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 11

Various Examples

Page 12: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 12

Forum

Page 13: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 13

Overview

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• Debug Tcl Scripts

• Labs

Page 14: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 14

Introduction

• Language Model

– Query objects – get properties

– Traverse design hierarchy

– SVD (SystemVerilog Design) only

• Netlist model

– Traverse design base on inference result

– Get connections

– Trace design structure

– For both SVD and VHDL

• Provide both C and Tcl Interface

• Verdi License is required

NPI Language and Netlist Model

HDL SDC,CPF/UPF…

Compilers of Verdi (vericom,vhdlcom)

Parsing Tree

HDL SDC,CPF/UPF…

Language Oriented

NPI

Inference (netlistcom)

Netlist Oriented NPI

Page 15: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 15

Overview

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• FSDB Model

– NPI Commands

– Case Study

• Debug Tcl Scripts

• Labs

Page 16: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 16

NPI Commands – Language Model

• Get the handle from a specified name and scope

• Arguments:

– -name “simple_name” | “hierarchical_name”

– -scope “” | $scope_handle

• Example: get the handle for system.i_cpu

% set cpu_scp [npi_handle_by_name –name “system.i_cpu” –scope “”

or

% set top_module [npi_handle_by_name -name system -scope ""]

% set cpu_scp [npi_handle_by_name -name i_cpu -scope $top_module]

npi_handle_by_name

Directly get the scope:

system.i_cpu

Get the system scope first, and then

get i_cpu scope under system

Page 17: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 17

NPI Commands – Language Model

• Get the handle according to the specified type for the reference

handle

• Arguments:

– -type “type_string”

– -refHandle $reference_handle

• Example:

% set cpu_clock [npi_handle_by_name -name system.i_cpu.clock -scope ""]

% set trace_module [npi_handle -type "npiInstance" -refHandle $cpu_clock]

npi_handle

Get the handle for the wire:

system.i_cpu.clock

Trace to the instance (system.i_cpu) that the wire belongs to

Page 18: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 18

NPI Commands – Language Model

• Get a member handle to an object by its parent handle and a

specific index number

• Argument

– -object “Handle that can be selected by index”

– -index “Index number”

• Example:

% set bus_hdl [npi_handle_by_name -name "system.i_cpu.data" -scope ""]

% set bus_bit7_hdl [npi_handle_by_index -object $bus_hdl -index 7]

% set bus_bit_name [npi_get_str -property npiFullName -object $bus_bit7_hdl]

npi_handle_by_index

Get the handle for the bus:

system.i_cpu.data[7:0]

Get the bit 7 handle for the bus

Get “system.i_cpu.data[7]”

Page 19: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 19

NPI Commands – Language Model

• Get a part-select handle to an object by the handle that covers it and

a specific range

• Argument

– -object “Handle that can be selected by index”

– -left “Left range number”

– -right “Right range number”

• Example:

% set bus_hdl [npi_handle_by_name -name "system.i_cpu.data" -scope ""]

% set bus_6_3_hdl [npi_handle_by_range -object $bus_hdl -left 6 -right 3]

npi_handle_by_range

Get the handle for the bus:

system.i_cpu.data[7:0]

Get the handle for the partial bus:

system.i_cpu.data[6:3]

Page 20: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 20

NPI Commands – Language Model

• Create the iterator with specified type on a reference handle

• Arguments:

– -type “type_string”

– -refHandle “” | $reference_handle

• Example:

% set cpu_module [npi_handle_by_name -name "system.i_cpu" -scope ""]

% set port_itr [npi_iterate -type "npiPort" -refHandle $cpu_module]

% set port_scan [npi_scan -iterator $port_itr]

% puts “[npi_get_str –property npiName –object $port_scan]”

npi_iterate

Create an iterator $port_itr for all

ports (npiPort) under system.i_cpu

Scan the iterator and output the name of the first port to console

Page 21: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 21

NPI Commands – Language Model

• Scan an iterator created by npi_iterate command

• Arguments:

– -iterator $iterator_handle

• Example: a script to output all ports under a module

set cpu_module [npi_handle_by_name -name "system.i_cpu" -scope ""]

set port_itr [npi_iterate -type "npiPort" -refHandle $cpu_module]

set port_scan [npi_scan -iterator $port_itr]

puts “[npi_get_str –property npiName –object $port_scan]”

while {$port_scan != ""} {

set port_scan [ npi_scan –iterator $port_itr]

puts “[npi_get_str –property npiName –object $port_scan]”

}

npi_scan

Scan all objects in the created iterator $port_itr,

and output all ports to console

Page 22: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 22

NPI Commands – Language Model

• Release the memory used by the specified object

– A guideline for better memory usage is to release the created handles whenever they are no longer needed

• Arguments:

– -object $object_handle_to_be_freed

• Example: set cpu_module [npi_handle_by_name -name "system.i_cpu" -scope ""]

set port_itr [npi_iterate -type "npiPort" -refHandle $cpu_module]

set port_scan [npi_scan -iterator $port_itr]

puts “[npi_get_str –property npiName –object $port_scan]”

while {$port_scan != ""} {

npi_release_handle –object $port_scan

set port_scan [ npi_scan –iterator $port_itr]

puts “[npi_get_str –property npiName –object $port_scan]”

}

npi_release_handle

Release the handle when they

are no longer needed

Note: scan to the next object (overwrite $port_scan)

will NOT release the memory used by previous object

Page 23: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 23

NPI Commands – Language Model

• Get the integer type (int) or Boolean type (bool) property of a

specified object

• Arguments:

– -property “property_string”

– -object $object_handle

• Example:

% set top_module [npi_handle_by_name -name system -scope ""]

% set isTop [npi_get -property "npiTop" -object $top_module]

npi_get

Check whether the object is a top module,

the return value will be 1 if true

Page 24: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 24

NPI Commands – Language Model

• Get the string type (str) property of a specified object

• Arguments:

– -property “property_string”

– -object $object_handle

• Example:

% set cpu_module [npi_handle_by_name -name system.i_cpu -scope ""]

% set module_name [npi_get_str -property npiName -object $cpu_module]

npi_get_str

Get the module name of the object

Page 25: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 25

NPI Commands – Language Model

• Get the constant value of a parameter in the design

• Arguments:

– -object $object_handle

– -format

“npiBinStrVal”|”npiOctStrVal”|”npiHexStrVal”|”npiDecStrVal”|”npiStri

ngVal”

• Example:

% set value [npi_get_value –object $literal_handle –format “npiBinStrVal”

npi_get_value

Page 26: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 26

NPI Commands – Language Model

• Compare whether two objects are the same

• Arguments:

– -object1 $object_handle1

– -object2 $object_handle2

• Example:

% set cmp_result [npi_compare_objects -object1 $hdl1 -object2 $hdl2]

– Return 1 ($cmp_result) if two objects ($hdl1 and $hdl2) are the same;

otherwise, return 0

npi_compare_objects

Page 27: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 27

NPI Commands – Language Model

• Check if two handles overlap physically

– The valid input handle is the handle that belongs to a simple expression, part-

select, or indexed part-select

• Arguments:

– -object1 $object_handle1

– -object2 $object_handle2

• Example:

% set bus_hdl [npi_handle_by_name -name "system.i_cpu.data" -scope ""]

% set bus_6_3_hdl [npi_handle_by_range -object $bus_hdl -left 6 -right 3]

% set overlap_flag [npi_objects_overlap -object1 $bus_hdl -object2

$bus_6_3_hdl]

npi_objects_overlap

Get the handle for the bus:

system.i_cpu.data[7:0]

Get the handle for the partial bus: system.i_cpu.data[6:3]

Check whether $bus_hdl and

$bus_6_3_hdl are overlapped

Page 28: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 28

NPI Commands – Netlist Model

• Four types of objects can be extracted from design:

– Instance

– Includes module instance and primitive instance

– Port

– Instance Port

– Net

Introduction of Netlist Model

instance object

instance

object

instance

object

instance

object

port instance port netinstance

Module instance

Primitive

instance

Port Instance

port

Net

Page 29: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 29

NPI Commands – Netlist Model Introduction of Netlist Model – Pseudo Object

a[1:0]

b[1:0]

a[1:0],b[1:0]

a[1]

a[0]

concat

p_in[3:0]

...

...

a[1:0],b[1:0]#[2:3]

a[1:0],b[1:0]#[1]

a[1:0],b[1:0]#[0]

b[1:0]

a[1:0]#[1]

a[1:0]#[0]

a[1]

a[0]

p_in[3:0]#[1:0]

p_in[3:0]#[2]

p_in[3:0]#[3]

In nSchema

In npi

Trace Drivers

Bit tracing by: npi_nl_iterate_with_range

Page 30: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 30

NPI Commands – Netlist Model

• The results of the NPI netlist model will be affected by the following schematic settings:

– Detail RTL

– Preferences Schematics RTL Enable Detail RTL

– Detail Level

– Preferences Schematics RTL Detail Level

– Mux Style

– Preferences Schematics RTL Mux Style for Inferred Latch

– FSM Recognition

– Preferences Schematics RTL FSM Recognition

– Generate Block

– Preferences Schematics RTL Expand GENERATE Block

– Symbol Library Names

– Preferences Schematics Symbol Library Symbol Library Names

– Symbol Library Paths

– Preferences Schematics Symbol Library Symbol Library Paths

• Refer to <Verdi_install>/doc/VIA_NPI.pdf for details

Introduction of Netlist Model – Schematic Configurations

Page 31: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 31

NPI Commands – Netlist Model

• Obtain a handle to an object with a one-to-one relationship

• Arguments:

– -type “type_string”

– -refHandle $reference_handle

• Example:

% set inst [npi_nl_handle_by_name -name "system.i_cpu"]

% set port_itr [npi_nl_iterate -type npiNlPort -refHandle $inst]

% set port_scan [npi_nl_scan -iterator $port_itr]

% set net [npi_nl_handle -type npiNlNet -refHandle $port_scan]

% set size [npi_nl_get -property npiNlSize -object $net]

npi_nl_handle

Get the handle for a port

in $port_scan

Use npi_nl_handle to get the connected net of this port (one-one mapping)

Page 32: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 32

NPI Commands – Netlist Model

• Get a handle to an object with a specific name

• Arguments:

– -name “hierarchical_name”

• Example:

% set cpu_inst [npi_nl_handle_by_name -name "system.i_cpu"]

% set addr_handle [npi_nl_handle_by_name -name "system.addr"]

npi_nl_handle_by_name

Get the handle by specifying

an instance name

Get the handle by specifying

a wire with full hierarchy name

Page 33: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 33

NPI Commands – Netlist Model

• Get a handle to an object using its index number within a given

object

• Arguments:

– -object $object_handle

– -index “Index Number”

• Example:

% set port_hdl [npi_nl_handle_by_name -name system.i_cpu.data]

% set port_bit_0 [npi_nl_handle_by_index -index 0 -object $port_hdl]

% set port_name_bit_0 [npi_nl_get_str -property npiNlFullName -object

$port_bit_0]

npi_nl_handle_by_index

Get the handle of bus:

system.i_cpu.data[7:0]

Get the handle by index number 0

Get the full name: system.i_cpu.data[7:0]#[0]

Page 34: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 34

NPI Commands – Netlist Model

• Get the value of an integer or Boolean property of an object

• Arguments:

– -property “property_string”

– -object $object_handle

• Example:

% set addr_handle [npi_nl_handle_by_name -name "system.addr"]

% set addr_size [npi_nl_get -property npiNlSize -object $addr_handle]

% puts $addr_size

npi_nl_get

Use npi_nl_get to get the

integer property of the object Display “8” in console

Get the handle by specifying

a wire with full hierarchy name

Page 35: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 35

NPI Commands – Netlist Model

• Get the value of a string property of an object

• Arguments:

– -property “property_string”

– -object $object_handle

• Example:

% set inst [ npi_nl_handle_by_name -name "system.i_cpu" ]

% set def_name [ npi_nl_get_str -property npiNlDefName -object $inst ]

% puts " system.i_cpu is an instance of $def_name"

npi_nl_get_str

Get the handle by specifying

an instance name

Use npi_nl_get_str to get the

string property of the object

Display “system.i_cpu is

an instance of CPU”

Page 36: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 36

NPI Commands – Netlist Model

• Obtain an iterator handle to objects with a one-to-many relationship

• Arguments:

– -type “type_string”

– -refHandle $reference_handle

• Example:

% set inst [npi_nl_handle_by_name -name "system.i_cpu"]

% set port_itr [npi_nl_iterate -type npiNlPort -refHandle $inst]

% set port_scan [npi_nl_scan -iterator $port_itr]

% set size [npi_nl_get -property npiNlSize -object $port_scan]

npi_nl_iterate

Get the handle by specifying

an instance name

Use npi_nl_iterate to get the iterator handle of

all ports for cpu instance (one-to-many)

Page 37: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 37

NPI Commands – Netlist Model

• Obtain an iterator handle to objects with a one-to-many relationship under the given range

• Arguments:

– -type “type_string”

– -refHandle $reference_handle

– -left “left_bound”

– -right “right_bound”

• Example:

% set addr_handle [npi_nl_handle_by_name -name "system.addr"]

% set itr [ npi_nl_iterate_with_range -type npiNlLoad -refHandle $addr_handle -left 0 -right 3 ]

• Note1: if the value of –left/right is invalid (eg: “0xZZ”), 0 will be used.

• Note2: if the range is larger than actual range, the actual range will be used.

– For example: specify [4:9] on addr[7:0] signal, addr[7:4] will be used

npi_nl_iterate_with_range

Get the handle of a 8-bit

signal: addr[7:0]

Get the iterator of all

loading signals of addr[3:0]

Page 38: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 38

NPI Commands – Netlist Model

• Scan the Netlist model for objects with a one-to-many relationship

• Arguments:

– -iterator $iterator_handle

• Example:

set inst [npi_nl_handle_by_name -name "system.i_cpu"]

set port_itr [npi_nl_iterate -type npiNlPort -refHandle $inst]

set port_scan [npi_nl_scan -iterator $port_itr]

while { $port_scan != ""} {

set Fullname [npi_nl_get_str -property npiNlFullName -object $port_scan]

puts $Fullname

set port_scan [npi_nl_scan -iterator $port_itr]

}

npi_nl_scan

Scan the port itrator of

“system.i_cpu” instance

Output name for each port

Page 39: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 39

NPI Commands – Netlist Model

• Release handle and its associated resources allocated by NPI

Netlist routines

• Arguments:

– -object $object_handle

• Example:

set inst [npi_nl_handle_by_name -name "system.i_cpu"]

set port_itr [npi_nl_iterate -type npiNlPort -refHandle $inst]

set port_scan [npi_nl_scan -iterator $port_itr]

while { $port_scan != ""} {

set Fullname [npi_nl_get_str -property npiNlFullName -object $port_scan]

puts $Fullname

npi_nl_release_handle -object $port_scan

set port_scan [npi_nl_scan -iterator $port_itr]

}

npi_nl_release_handle

Release the port handle

before putting the new value

Note: scan to the next object (overwrite $port_scan)

will NOT release the memory used by previous object

Page 40: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 40

Overview

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• Debug Tcl Scripts

• Labs

Page 41: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 41

How to Use Object Diagrams?

• Which object diagram I should refer to?

– Find the object diagram base on your reference object handle

– For example, if you are looking for all ports for an instance, you need to check the “instance” object diagram

– % set cpu [npi_nl_handle_by_name -name "system.i_cpu"]

– % set ports_itr [npi_nl_iterate -type "npiNlPort" -refHandle $cpu]

• Which NPI command I should use to get the handle?

– Referring to the object diagram according to your reference object handle, and check the arrow type

– Single arrow (one to one):

npi_handle, npi_nl_handle

– Double arrow (one to many):

npi_iterate, npi_nl_iterate

Guidelines for Reading Object Diagrams

Get the handle of

system.i_cpu instance

The reference handle is an instance, check

available types in Instance diagram in document

Page 42: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 42

How to Use Object Diagrams?

• How can I get the type string for the –type option?

– Referring to the object diagram according to your reference object handle, check the name for each object

– For language model, change the first character to uppercase, and then add "npi" as the prefix. For example: npiInstance.

– For netlist model, change the first character to uppercase, and then add "npiNl" as the prefix. For example: npiNlInstPort.

– If there are type strings above the arrow line, use these type strings

Guidelines for Reading Object Diagrams

instnet

port

inst

instPort

-> definition name

str: npiNlDefName

-> location

str: npiNlFile

int: npiNlBeginLineNo

int: npiNlEndLineNo

-> cell type

str / int: npiNlCellType

-> instance type

str / int: npiNlInstType

npiNlDriver

npiNlLoad

instPort

npiNlConnectivity

The type string will

be: npiNlInstPort

Special type strings

Page 43: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 43

How to Use Object Diagrams?

• How can I get the property string for the –property option?

– Referring to the object diagram according to your reference object handle, check the description under the object diagram

– str: means the property is string type. Use npi_get_str or npi_nl_get_str commands

– Int: means the property is integer type Use npi_get or npi_nl_getr commands

– bool: means the property is Boolean type Use npi_get or npi_nl_getr commands

Guidelines for Reading Object Diagrams

instnet

port

inst

instPort

-> definition name

str: npiNlDefName

-> location

str: npiNlFile

int: npiNlBeginLineNo

int: npiNlEndLineNo

-> cell type

str / int: npiNlCellType

-> instance type

str / int: npiNlInstType

npiNlDriver

npiNlLoad

instPort

npiNlConnectivity

String type property,

use npi_nl_get_str Integer type property,

use npi_nl_get

Page 44: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 44

NPI Object Diagrams – Language Model

• set cpu_module [npi_handle_by_name -name "system.i_cpu" -scope ""]

– Get the handle for scope system.i_cpu • set port_itr [npi_iterate -type "npiPort" -refHandle $cpu_module]

– Get the iterator for all ports under system.i_cpu • set port_scan [npi_scan -iterator $port_itr]

– Get the handle for the first port under system.i_cpu • set port_name [npi_get_str -property "npiName" -object $port_scan]

– Get the port name: clock

Module

module

expr

scope

port

process

contAssign

primitive

One-to-many arrow,

use npi_iterate to

get the iterator.

The type is npiPort

Page 45: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 45

NPI Object Diagrams – Language Model

• set trace_module [npi_handle -type "npiInstance" -refHandle $port_scan]

– Get the handle of the module where the port belongs to

• set ins_name [npi_get_str -property "npiName" -object $trace_module]

– Get the name of the module

Port

instance port expr

ports

npiHighConn

npiLowConn

-> direction int: npiDirection

-> index int: npiPortIndex

-> name str: npiName

-> size int: npiSize

Use npi_get_str to get

the str type property

Use npi_get to get

the int type property

Single arrow, use

npi_handle to get

the handle. The type

is npiInstance

Page 46: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 46

NPI Object Diagrams – Netlist Model

• set inst_itr [npi_nl_iterate -type npiNlInst -refHandle ""]

– Get the iterator of all instances under top scope

• set load [npi_nl_iterate -type "npiNlLoad" -refHandle $maprom]

– Get the iterator of all loads for a specified instance

• set def_name [npi_nl_get_str -property "npiNlDefName" -object $maprom]

– Get the module name of the object handle

Instance

instnet

port

inst

instPort

-> definition name

str: npiNlDefName

-> location

str: npiNlFile

int: npiNlBeginLineNo

int: npiNlEndLineNo

-> cell type

str / int: npiNlCellType

-> instance type

str / int: npiNlInstType

npiNlDriver

npiNlLoad

instPort

npiNlConnectivity

Specify “” in the reference handle

to get all instances under top

Use the special type string

to find all loads

Use npi_nl_get_str to

get the string type property

Page 47: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 47

NPI Object Diagrams

• Refer to the Novas Program Interface (NPI) Reference Manual for

all SystemVerilog object model diagrams

– The document is located in <Verdi_install>/doc/VIA_NPI.pdf

Other Diagrams

variables

stmt

instance

named begin

task func

begin

named fork

fork

scope named event

named event array

parameters

scope

-> namestr. npiNamestr. npiFullName

npiParameter

npiInternalScope

io decl

udp defn

-> direction int. npiDirection

npiExpr

typespec

task func

nets

variables

Scope

IO declaration

Parameter

parameter

parametersmodule

scope

-> namestr: npiNamestr: npiFullName

Page 48: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 48

Overview

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• Debug Tcl Scripts

• Labs

Page 49: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 49

Use NPI L1 Libraries

• Downloaded the package of NPI L1 library

– Go to www.via-exchange.com

– Log in the web site (if you don’t have the account, register one)

– Click the Download tab and download the Tcl Library

– Decompress the file and place the directory npiL1 to a suitable place

• Source the file npi_L1.tcl in one of following method:

– Source the file in the beginning of your Tcl program, for example:

– source /my_app/npiL1/npi_L1.tcl

– Or, set an environment variable for the path of NPI L1 (recommended),

for example:

% setenv NPIL1_PATH /my_app/npiL1

– Then in any of your applications, you just need to source npi_L1.tcl, for

example:

source $env(NPIL1_PATH)/npi_L1.tcl

Page 50: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 50

Use NPI L1 Libraries

• Requirement:

– I would like to get all drivers (instance port) for a signal, and get the

number of drivers, then save all driver’s handle to a list variable for latter

processing

• Directly use the pre-defined procedure

– Go to www.via-exchange.com and click the Getting Started tab

– Click Libraries link

– Find the appropriate category

– In this case, click Signal link

– Read the description of each procedure and the click the link to find the

detail usage

– In this case, click npi_nl_trace_driver

An Example of Using Libraries (1/2)

Page 51: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 51

Use NPI L1 Libraries

• Create a Tcl script to contain below contents:

source $env(NPIL1_PATH)/npi_L1.tcl

debImport -sv example.v

set file_handle [open "output.log" "w"]

puts $file_handle "/*** Get The Drivers of Net TOP.w3 ***/"

set driver_port_hdl_list { }

set nl_hdl_num [ ::npi_L1::npi_nl_trace_driver "TOP.w3" "driver_port_hdl_list" ]

for { set i 0 } { $i < $nl_hdl_num } { incr i } {

set full_name [ npi_nl_get_str -property npiNlFullName -object [lindex $driver_port_hdl_list $i] ]

set type [ npi_nl_get_str -property npiNlType -object [lindex $driver_port_hdl_list $i] ]

puts $file_handle "No.$i, $full_name, $type "

}

debExit

An Example of Using Libraries (2/2)

Source the L1 library

Create the file to store result

Use the pre-defined procedure in L1 library: Save the driver number in $nl_hdl_num, and save the handle for all drivers in $driver_port_hdl_list

Get the full name of each driver port and save in $full_name

Get the type of each driver

port, and save in $type

Save the number, name,

and type to the output.log file

Page 52: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 52

Overview

• Verdi Tcl Introduction

– Use Tcl in Verdi

– Case Study

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• Debug Tcl Scripts

• Labs

Page 53: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 53

Case Study 1 – Traverse Design Hierarchy

• Requirement:

– Traverse the design hierarchy of the imported design, and output the

hierarchy to console

• To execute the script:

– Change directory to <verdi_install>/demo/verilog/rtl

% verdi -play demo_traverse.tcl &

– Refer to following two slides for the content of demo_traverse.tcl

Overview

Page 54: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 54

Case Study 1 – Traverse Design Hierarchy

debImport “-f” “run.f”

set itr [npi_iterate -type npiModule -refHandle ""]

if {$itr != ""} {

set top_mod [npi_scan -iterator $itr]

while {$top_mod != ""} {

trv_mod $top_mod

npi_release_handle -object $top_mod

set top_mod [npi_scan -iterator $itr] } }

Script (1/2) Import design into Verdi

Create iterator $itr for all top

modules. Note: -refHandle

“” means to iterate from top

To scan the created iterator $itr.

The first scanned object here is top

module system. $top_mod is the

handle for top module

Execute another procedure trv_mod with

argument $top_mod. $top_mod is system here

Release the handle for top

module for saving memory usage

Check whether there is another

top module except system

Page 55: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 55

Case Study 1 – Traverse Design Hierarchy

proc trv_mod { hdl } { if {$hdl != ""} { puts "[npi_get_str -property npiFullName -object $hdl]" } set itr [npi_iterate -type npiInternalScope -refHandle $hdl] if {$itr == ""} { return } set sub_scp [npi_scan -iterator $itr] while {$sub_scp != ""} { set scp_type [npi_get_str -property npiType -object $sub_scp] if {$scp_type == "npiModule"} { trv_mod $sub_scp } npi_release_handle -object $sub_scp set sub_scp [npi_scan -iterator $itr] } }

Script (2/2) Get the full hierarchy name of the top

module and put to console. $hdl here is

the handle for system scope

Create the iterator

for all internal

scopes under top

module

Exit the procedure if there is no

internal scope, which means it’s

the bottom level module Scan the $itr interator for

all internal scopes

Traverse modules (npiModule) only.

Note that npiInternalScope gets more

than just modules

Scan next object from $itr iterator.

$itr is the iterator for all internal scopes.

Page 56: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 56

Case Study 2 – List All Inferred Registers

• Requirement:

– Traverse an imported design (SystemVerilog, VHDL or mixed) and list all inferred registers and latches in “file.log” file.

• To execute the script:

1. Copy the Tcl file to working directory.

2. In working directory, use vericom/vhdlcom to compile the design.

3. Type “Verdi -play get_registers.tcl”.

4. In Verdi, load the design from library.

5. Type “get_registers” in Verdi’s Command Entry form.

6. Registers and latches will be saved into “file.log” file.

• Refer to following two slides for the content of get_registers.tcl

Overview

Page 57: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 57

Case Study 2 – List All Inferred Registers

proc get_registers { } { set file [open "file.log" "w"]

set itr [npi_nl_iterate -type npiNlInst -refHandle ""]

set instance_scan [npi_nl_scan -iterator $itr] while {$instance_scan != ""} { set name [npi_nl_get_str -property npiNlCellType -object

$instance_scan]

if {$name == "npiNlModuleCell"} { traverse_sub $instance_scan "file" } if { $name == "npiNlFlipFlopCell" || $name == "npiNlLatchCell"} { puts $file [npi_nl_get_str -property "npiNlFullName" -object

$instance_scan] } set instance_scan [npi_nl_scan -iterator $itr] } close $file }

Script (1/2)

Open the file.log file Create iterator $itr for

instances from top

Scan the iterator and get

the type for each instance

Call traverse_sub procedure

if the instance is a module

Write the cell name to file if the

instance is a register or latch

Scan next item in the iterator

Notice that all information will not be

written if the file channel is not closed

Page 58: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 58

Case Study 2 – List All Inferred Registers

proc traverse_sub {instance_scan file_name} { upvar $file_name aaaa

set itr_sub [npi_nl_iterate -type npiNlInst -refHandle $instance_scan]

set sub_instance_scan [npi_nl_scan -iterator $itr_sub] while {$sub_instance_scan != ""} { set name [npi_nl_get_str -property npiNlCellType -object

$sub_instance_scan]

if {$name == "npiNlModuleCell"} { traverse_sub $sub_instance_scan "aaaa" } if { $name == "npiNlFlipFlopCell" || $name == "npiNlLatchCell" } { puts $aaaa [npi_nl_get_str -property "npiNlFullName" -object

$sub_instance_scan] } set sub_instance_scan [npi_nl_scan -iterator $itr_sub] } }

Script (2/2)

Inherit the variable from upper stack

Iterate instances

under the module

Scan the iterator

and get the type

for each instance

If the instance is a module,

call this procedure recursively

Write the cell name to file if the instance is a register or latch

Scan next item in the iterator

Page 59: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 59

Case Study 3 – Netlist Model Example

• Requirement:

– Find all connected modules for a given signal, and output the list for

modules in output.log file.

• To execute the script:

– Change directory to <verdi_install>/demo/verilog/rtl

% verdi -play get_module.tcl &

– Refer to following two slides for the content of get_module.tcl

– Type get_connected_module “system.clock" in the Command Entry form

– Where system.clock is the given signal name

Overview

Page 60: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 60

Case Study 3 – Netlist Model Example

namespace eval ::npi_sig_2_mod_inst_conn_t { proc npi_sig_2_mod_inst_conn { sig_hier_name list_name } {}

proc collect_mods { hdl } {} proc net_to_port_and_inst_port { hdl list_name reset } {} proc hdl_to_inst { hdl } {} proc filter_redundant_hdl { list_name } {} proc which_class { hdl } {}

variable _conn_mod_inst_nl_hdl_list }

Namespace

Define procedures and variables which will be used in

the script with namespace eval, this can avoid the procedure

name conflict with other scripts.

:: is the hierarchy delimiter. Put :: in front of the procedure

means the procedure is under top scope, for example:

::npi_sig_2_mod_inst_conn_t

Page 61: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 61

Case Study 3 – Netlist Model Example

proc ::npi_sig_2_mod_inst_conn_t::npi_sig_2_mod_inst_conn { { sig_hier_name "" } { list_name "" } } {

if { $sig_hier_name == "" } { return 0 }

if { $list_name == "" } { return 0 }

set target_hdl [ npi_nl_handle_by_name -name $sig_hier_name ]

if { $target_hdl == "" || [ which_class $target_hdl ] != "NET" } { return 0 }

variable _conn_mod_inst_nl_hdl_list

set _conn_mod_inst_nl_hdl_list { }

collect_mods $target_hdl

set count [ llength $_conn_mod_inst_nl_hdl_list ]

upvar $list_name conn_mod_inst_nl_hdl_list

set conn_mod_inst_nl_hdl_list $_conn_mod_inst_nl_hdl_list

return $count

}

Procedure: npi_sig_2_mod_inst_conn

This procedure is defined under

::npi_sig_2_mod_inst_conn_t namespace

Get the handle

of given signal

Invoke the which_class procedure to

check whether the given signal is a net

Invoke the collect_mods procedure

to get connected modules

Count the number of connected modules, and save

the number in conn_mod_inst_nl_hdl_list variable

Page 62: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 62

Case Study 3 – Netlist Model Example

proc ::npi_sig_2_mod_inst_conn_t::collect_mods { hdl } {

variable _conn_mod_inst_nl_hdl_list

variable _post_and_inst_port_hash

set port_and_inst_port_list {}

if { [ which_class $hdl ] != "NET" } { return 0 }

net_to_port_and_inst_port $hdl "port_and_inst_port_list“

foreach port_and_inst_port_hdl $port_and_inst_port_list {

set inst_hdl [ hdl_to_inst $port_and_inst_port_hdl ]

if { [ npi_nl_get_str -property npiNlCellType -object $inst_hdl ] == "npiNlModuleCell" } {

lappend _conn_mod_inst_nl_hdl_list $inst_hdl

} else {

npi_nl_release_handle -object $inst_hdl

}

}

set local_inst_hdl [ hdl_to_inst $hdl ]

lappend _conn_mod_inst_nl_hdl_list $local_inst_hdl

filter_redundant_hdl "_conn_mod_inst_nl_hdl_list"

}

Procedure: collect_mods

This procedure is invoked from previous

one: (npi_sig_2_mod_inst_conn)

Invoke net_to_port_and_inst_port procedure to get all port and inst_port which are

connected to the given net, and do not pass through any ports and inst_ports

For each port, call hdl_to_inst

to get it’s parent instance

Only store module instance into the

_conn_mod_inst_nl_hdl_list list

store instance of target net into the

_conn_mod_inst_nl_hdl_list list

Call filter_redundant_hdl to avoid

duplicate module instance in list

Page 63: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 63

Case Study 3 – Netlist Model Example

proc ::npi_sig_2_mod_inst_conn_t::net_to_port_and_inst_port { hdl list_name { reset 1 } } {

upvar $list_name hdl_list

if { $reset == 1 } {

set hdl_list {}

array set net_hash {}

} else {

upvar "net_hash" net_hash

}

Procedure: net_to_port_and_inst_port (1/3)

This procedure is called from previous

collect_mods procedure, and there are

three inputs of this procedure: $hdl,

$list_name, and $reset.

Notice the variable $reset has a default

value 1

$net_hash is a private hash for this procedure, the purpose

is to check whether there are duplicated port/instports. When

this procedure is called from other procedures, reset the hash

table. If the procedure is called by itself recursively, then do not

initiate and execute upvar command to use the hash table.

Page 64: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 64

Case Study 3 – Netlist Model Example

set itr [ npi_nl_iterate -type npiNlConnectivity -refHandle $hdl ]

if { $itr == "" } { return }

while { [ set hdls [ npi_nl_scan -iterator $itr ] ] != "" } {

set type [ npi_nl_get_str -property npiNlType -object $hdls ]

switch -- $type {

npiNlInstPort -

npiNlPseudoInstPort -

npiNlPort -

npiNlPseudoPort { lappend hdl_list $hdls }

npiNlDeclNet -

npiNlConcatNet -

npiNlSliceNet -

npiNlPseudoNet {

if { ![info exist net_hash($hdls) ] } {

set net_hash($hdls) ""

net_to_port_and_inst_port $hdls "hdl_list" 0

} else { npi_nl_release_handle -object $hdls }

}

Procedure: net_to_port_and_inst_port (2/3) Get the iterator for

all connected

objects

Scan all connected

objects (save in

$hdls), and save

the type in $type If the object is a port, append

the port object to $hdl_list

If the object is a net, then call this procedure

(net_to_port_and_inst_port) recursively and

continue tracing until reaching a port or inst_port

Page 65: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 65

Case Study 3 – Netlist Model Example

npiNlInst -

default {

puts "Unsupported objec type: $type"

npi_nl_release_handle -object $hdls

}

}

}

}

Procedure: net_to_port_and_inst_port (3/3)

According to netlist model, a net will never connect (it should

connect to an inst_port first) to an instance directly when

tracing its connection. A warning message will be printed when

the type is ambiguous.

Page 66: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 66

Case Study 3 – Netlist Model Example

proc ::npi_sig_2_mod_inst_conn_t::hdl_to_inst { hdl } {

set type [ npi_nl_get_str -property npiNlType -object $hdl ]

switch -- $type {

npiNlPseudoNet -

npiNlPseudoInstPort -

npiNlPseudoPort {

set parent_hdl [ npi_nl_handle -type npiNlParent -refHandle $hdl ]

set inst_hdl [ npi_nl_handle -type npiNlInst -refHandle $parent_hdl ]

npi_nl_release_handle -object $parent_hdl

}

Procedure: hdl_to_inst (1/2)

Called from collect_mods procedure, to get the corresponding instance from a port

Get the type name of the port and save in $type

If the object is a pseudo object, get its parent port object

and then get the instance which this port belongs to.

Save the instance handle to $inst_hdl

Page 67: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 67

Case Study 3 – Netlist Model Example

npiNlInstPort -

npiNlPort -

npiNlDeclNet -

npiNlConcatNet -

npiNlSliceNet {

set inst_hdl [ npi_nl_handle -type npiNlInst -refHandle $hdl ]

}

npiNlInst -

default {

puts "Unsupported objec type: $type"

return ""

}

}

return $inst_hdl

}

Procedure: hdl_to_inst (2/2)

If the object is a net or port, get the instance

which this port or net belongs to, and save

the handle into $inst_hdl

Puts a warning message when the type is ambiguous.

Page 68: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 68

Case Study 3 – Netlist Model Example

proc ::npi_sig_2_mod_inst_conn_t::filter_redundant_hdl { list_name } {

upvar $list_name current_list

set new_list { }

array set temp_hash {}

foreach hdl $current_list {

if { ![info exist temp_hash($hdl) ] } {

set temp_hash($hdl) ""

lappend new_list $hdl

} else { npi_nl_release_handle -object $hdl }

}

set current_list $new_list

}

Procedure: filter_redundant_hdl

Called from collect_mods procedure, to avoid duplicate module instance in list

Check whether the object exist in the hash table.

Append the object if it’s not in the hash table,

otherwise release the object

Page 69: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 69

Case Study 3 – Netlist Model Example

proc ::npi_sig_2_mod_inst_conn_t::which_class { hdl } {

set type [ npi_nl_get_str -property npiNlType -object $hdl ]

switch -- $type {

npiNlDeclNet -

npiNlConcatNet -

npiNlSliceNet -

npiNlPseudoNet { return "NET" }

npiNlInst { return "INST" }

npiNlPort -

npiNlPseudoPort { return "PORT" }

npiNlInstPort -

npiNlPseudoInstPort { return "INSTPORT" }

default { return 0 }

}

}

Procedure: which_class

Called from npi_sig_2_mod_inst_conn procedure, to return the type name for the given signal

Return the type name NET to

npi_sig_2_mod_inst_conn

Page 70: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 70

Case Study 3 – Netlist Model Example

proc get_connected_module { signal } {

set file_handle [open "output.log" "w" ]

puts $file_handle "/*** Get connective Module Instances of Net: $signal ***/"

set conn_mod_inst_nl_hdl_list { }

set nl_hdl_num [ ::npi_sig_2_mod_inst_conn_t::npi_sig_2_mod_inst_conn $signal "conn_mod_inst_nl_hdl_list" ]

for { set i 0 } { $i < $nl_hdl_num } { incr i } {

set nl_hdl [lindex $conn_mod_inst_nl_hdl_list $i]

set full_name [ npi_nl_get_str -property npiNlFullName -object $nl_hdl ]

puts $file_handle [format {No.%d, module %-10s;} $i $full_name ]

}

puts $file_handle " total number of module = $nl_hdl_num "

close $file_handle

}

Main script

Main procedure, users call this procedure in the Command Entry and specify the signal

Create the output.log file and write header to the file

Call npi_sig_2_mod_inst_conn to get

the number of connected modules

Write the full name of

each module to the

created file Write the module

amount to file Notice that all information will not be

written if the file channel is not closed

Page 71: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 71

Overview

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• Debug Tcl Scripts

• Labs

Page 72: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 72

Debug Tcl Scripts

• Set the environment variable CMD_TRACE to 1 for viewing received

commands

% setenv CMD_TRACE 1

% verdi -play demo_traverse.tcl > tcl_log &

% vi tcl_log

The CMD_TRACE Environment Variable

Page 73: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 73

Debug Tcl Scripts

• The TclPro Debugger is not included in Novas package, download

the software and get the instruction from:

http://www.tcl.tk/software/tclpro/

• Set the path for TclPro Debugger, for example:

% set path= ( /tools/TCL/TclPro1.5/linux-ix86/bin $path )

• Invoke Verdi with –prodebug option and load the Tcl script with –

play option:

% verdi -prodebug -play demo_traverse.tcl

Using TclPro Debugger (1/2)

Page 74: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 74

Debug Tcl Scripts

Using TclPro Debugger (2/2)

Click to set

break point

Run until

break or EOF

Run stops

Variable values

Run stops on this line

Page 75: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 75

Overview

• Verdi Tcl Introduction

– Use Tcl in Verdi

– Case Study

• VIA Introduction

• Language Model & Netlist Model

– NPI Commands

– NPI Object Diagrams

– Use NPI L1 Libraries

– Case Study

• Debug Tcl Scripts

• Labs

Page 76: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 76

Lab 1

• Practice:

– Get the handle for a specific scope, iterate all sub scopes under it and output the name for each scope

• Hint:

– Change directory to <novas_install>/demo/verilog/rtl

– Invoke Verdi (novas –f run.f &) and open the Command Entry form

– Tools Preference General Enable TCL Command Entry Form

– In Command Entry form, type:

set cpu_scope [npi_handle_by_name -name system.i_cpu -scope ""]

set scope_itr [npi_iterate -type npiInternalScope -refHandle $cpu_scope]

set sub_scope [npi_scan -iterator $scope_itr]

while {$sub_scope != ""} {

puts "[npi_get_str -property npiFullName -object $sub_scope]"

set sub_scope [npi_scan -iterator $scope_itr]

}

Iterate Sub-scopes under a Specified Scope

Page 77: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 77

Lab 2

• Practice:

– Calculate how many modules have been used in a design, write the

amount and all module names into a file.

• Hint:

– The Tcl script can be implemented by language model or netlist model.

– Can re-use Case Study 1 or Case Study 2 (Language & Netlist Model)

script and add some commands to implement the script

Calculate Modules

Page 78: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 78

Lab 3

• The issue in the Case Study 3 script (Language & Netlist Model):

– The current script will get all connected modules for a given net, however the traversing will stop when reaching a primitive instance (e.g. AND gate).

• Practice:

– Modify the script in Case Study 3 to let the traversal can pass through all primitive instances

– You can find the Case Study 3 script in: <Novas_install>/demo/NPI/netlist_model/TCL/get_module.tcl

• Hints:

– Find the modified script in the same directory and use tkdiff to compare the difference

– You can find the modified script in:

<Novas_install>/demo/NPI/netlist_model/TCL/get_module_pass_primitive.tcl

Modify the Script in Case Study 3 (Language & Netlist Model)

Page 79: Language and Netlist Models - VC Apps · PDF fileLanguage and Netlist Models ... SDC C-API CPF/UPF .lib © Synopsys 2012 6 Complete Data Models ... –-format “npiBinStrVal

© Synopsys 2012 79

Reference

• Novas Command Language:

– <Verdi_install>/doc/tcl.pdf

• NPI Models:

– <Verdi_install>/doc/VIA_NPI.pdf

• Useful web sites:

– Tcl Developer Site: http://www.tcl.tk/

– Tcl Tutorials: http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html

– Tcl Commands: http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm

– Tk Commands: http://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm

Get Help from Resources