Professional Documents
Culture Documents
Text Model
© Synopsys 2012 1
Glossary
© Synopsys 2012 2
Overview
© Synopsys 2012 3
Overview
© Synopsys 2012 4
DM Model Introduction
What is NPI Text Model?
• Lets users traverse and manipulate design source code from a text
perspective
– Every file, line, and word is regarded as an object
• Users can access the attribute of each word from the design
analysis results of the Verdi system
© Synopsys 2012 5
Overview
© Synopsys 2012 6
NPI Commands
Get Handles
© Synopsys 2012 8
NPI Commands
Create the Iterator and Iterate Items (2/2)
• Example:
set file_iter [ npi_text_iter_start –type“npiTextFile”–ref]”“
Create an iterator $file_iter for all imported files
Scan the iterator $file_iter and get the handle of the next file
set file_name [ npi_text_property_str –type“npiTextFileName”–ref
$file_hdl ]
puts $file_name
}
npi_text_iter_stop –iter $file_iter Free the iterator $file_iter
© Synopsys 2012 9
NPI Commands
Get Properties from Handles
• Example:
% set file_hdl [ npi_text_file_by_name –name“example.v”]
• NOTE2: a change line (\n) will automatically be added to the end of the
NewLine. If the NewLine argument is an empty string, this function still inserts a
change line (\n) just before the reference line handle.
© Synopsys 2012 11
NPI Commands
Manipulate Lines (2/2)
• Example:
% set file_hdl [ npi_text_file_by_name –name“example.v”]
% set line_iter [ npi_text_iter_start –type“npiTextLine”–ref $file_hdl ]
% set line_hdl [ npi_text_iter_next –iter $line_iter ]
% set inserted_line_hdl_before [ npi_text_insert_line_before –ref $line_hdl
–content“/*comment*/”]
© Synopsys 2012 13
NPI Commands
Manipulate Words (2/2)
• Example:
% set file_hdl [ npi_text_file_by_name –name“example.v”]
% set line_iter [ npi_text_iter_start –type“npiTextLine”–ref $file_hdl ]
% set line_hdl [ npi_text_iter_next –iter $line_iter ]
% set word_iter [ npi_text_iter_start –type“npiTextWord”–ref $line_hdl ]
% set inserted_before_word_hdl [ npi_text_insert_word_before –ref
$word_hdl –word“//”]
Insert a word before the word handle $word_hdl
% set inserted_after_word_hdl [ npi_text_insert_word_after –ref $word_hdl –
word“//comment”]
Insert a word after the
word handle $word_hdl
% set replaced_word [ npi_text_replace_word –ref $word_hdl –word
“AND_g1”]
Replace the word for the word handle $word_hdl
© Synopsys 2012 14
Delete the word handle $word_hdl
NPI Commands
Expand the Include File
• Example:
set file_hdl [ npi_text_file_by_name –name“expand_include.v”]
set line_iter [ npi_text_iter_start –type“npiTextLine”–ref $file_hdl ]
set line_hdl [ npi_text_iter_next –iter $line_iter ]
set word_iter [ npi_text_iter_start –type“npiTextWord”–ref $line_hdl ]
while[=!”“{setword_hdl [ npi_text_iter_next –iter $word_iter ] ] } {
if“{npiTextIncludeFile”[==npi_text_property_str –type
“npiTextWordAttribute”–ref $word_hdl ] } {
Check whether the property
ofthewordhandleis“include”
set expand_flag [ npi_text_expand_include –ref $word_hdl ]
}
Expand the include file of the word handle
}
© Synopsys 2012 15
NPI Commands
Expand the Macro
• Example:
set file_hdl [ npi_text_file_by_name –name“expand_include.v”]
set line_iter [ npi_text_iter_start –type“npiTextLine”–ref $file_hdl ]
set line_hdl [ npi_text_iter_next –iter $line_iter ]
set word_iter [ npi_text_iter_start –type“npiTextWord”–ref $line_hdl ]
while[=!”“{setword_hdl [ npi_text_iter_next –iter $word_iter ] ] } {
if“{npiTextMacroName”[==npi_text_property_str –type
“npiTextWordAttribute”–ref $word_hdl ] } {
Check whether the property
ofthewordhandleis“macro”
set expand_flag [ npi_text_expand_macro –ref $word_hdl ]
}
Expand the macro description of the word handle
}
© Synopsys 2012 16
Overview
• DM Model Introduction
• NPI Commands
• NPI Object Diagrams
• Case Study
© Synopsys 2012 17
How to Use Object Diagrams?
Guidelines for Reading Object Diagrams
© Synopsys 2012 18
How to Use Object Diagrams?
Guidelines for Reading Object Diagrams
• How can I get the type string of –type option for npi_text_handle and
npi_text_iter_start?
– Refer to the object diagram according to your reference object
handle, and check the name for each object
– Change the first character to uppercase, and then add "npiText" as the
prefix.
– Available types are: npiTextFile, npiTextLine, and npiTextWord
• How can I get the type string of –type option for npi_text_property and
npi_text_property_str?
– Refer to the object diagram according to your reference object
handle, and check the description under the object diagram
– str: means the property is string type.
Use npi_text_property_str command
– Int: means the property is integer type
Use npi_text_property commands
– bool: means the property is Boolean type
Use npi_text_property command
© Synopsys 2012 19
Object Diagram
File
Get
Getallall
imported
line handles
file handles
from a file handle
file line
->type
str: npiTextHandleType % set file_iterator [ npi_text_iter_start –type
npiTextFile –ref]”“
->name
str: npiTextFileFullName
str: npiTextFileName % set line_iterator [ npi_text_iter_start –type
Getthe“filecontent”property
npiTextLine –ref $file_handle ]
->content From a file handle (str)
str: npiTextFileContent
% puts [ npi_text_property_str –type
Getthe“linecount”property
“npiTextFileContent”–ref $file_hdl ]
->line count from a file handle (int)
int: npiTextLineCount
% puts [ npi_text_property –type
“npiTextLineCount”–ref $file_hdl ]
© Synopsys 2012 20
Object Diagram
Line
file line word
->type
str: npiTextHandleType
% set file_handle [ % puts [
npi_text_handle –type ->content npi_text_property_str –
str: npiTextLineContent
npiTextFile –ref type“npiTextLineContent”–
$line_handle ] ref $line_hd
->line number
Get the file handle int: npiTextLineNumber Getthe“linecontent”property
from a line handle from a line handle (str)
->word count
int: npiTextWordCount
% set word_iterator [ % puts [ npi_text_property
npi_text_iter_start –type –type“npiTextLineNumber”
npiTextWord –ref –ref $line_hdl ]
$line_handle ]
Getthe“linenumber”property
Get all line handles from a file handles
from a line handle (int)
© Synopsys 2012 21
Object Diagram
Word
line word
->type
% set line_handle [ npi_text_handle –type str: npiTextHandleType
npiTextLine –ref $word_handle ]
->name
Get the line handle from a file handle str: npiTextWordName
Getthe“wordnumber”property ->attribute
from a file handle (int) int: npiTextWordAttribute
str: npiTextWordAttribute
% puts [ npi_text_property_str –type
“npiTextWordAttribute”–ref $word_hdl ] Getthe“wordattribute”property
from a file handle (str)
© Synopsys 2012 22
Overview
• DM Model Introduction
• NPI Commands
• NPI Object Diagrams
• Case Study
© Synopsys 2012 23
Case Study
Overview
• Requirement:
– Modify the source code to create a input port d
© Synopsys 2012 24
Case Study
Script (1/2)
Get the handle
set file_hdl [ npi_text_file_by_name –name“example.v”] for file example.v
© Synopsys 2012 26