From Genesis2
Revision as of 05:21, 14 September 2012 by Shacham (talk | contribs) (How to Use The Module)

Jump to: navigation, search

Genesis2.CMLCrawler Python Library

As you may remember, Genesis2 outputs all its hierarchy structure and for each module all its parameters (final binding) into an XML structure (more information here, XML schema page here). The idea is that this information is useful for creating drivers, backend flows and more. To make your life easier in traversing the XML, we provide a small Python module called Genesis2.XMLCrawler that provides navigation and search methods. This page describes how to use it.

System Requirements and Setup

Genesis2.XMLCrawler requires Python 2.5 or above.

If you have not done so thus far, you may need to add $GENESIS_HOME/PythonLibs to your path. See here for setting up Genesis2 environment. Or, if all you need is this python module, add the following line to your setup file:


How to Use The Module

Say we want to create a script that extract info from the XML, I'll call it Start it with:

from Genesis2.XMLCrawler import XMLCrawler

Now we create an object and init it with the XML file:

c = XMLCrawler()

'c' in this notation stands for crawler and is always pointing to the hierarchical equivalent of a design instance. It starts at the top. From here on, we can use the following API which is almost identical to the Genesis2 compiler API (as described here).

Traversal related methods

def get_parent(self) 
returns the instance's parent or None if this is top
def get_top(self) 
returns the top of the hierarchy
def iname(self)
instance name
def mname(self)
module name (after uniquification)
def bname(self)
base module name (i.e., template name, before uniquification)
def sname(self)
Source module name (i.e., before synonyms were applied; also the name of the source file)
def exists_subinst(self, name)
check if a subinst named name exists
def get_subinst(self, name)
returns a crawler object pointing to subinst by name name
def get_subinst_array(self,pattern='.*')
returns an array of crawler objects pointing to subinsts that matched pattern
def get_instance_path(self)
returns the full path to this instance
def search_subinst(self, options = dict()) (Only 'From', 'Depth' and 'Reverse' currently implemented)
API method for searching the entire design hierarchy or portions of it according to user defined criteria(s)
All criteria are optional. The returned value is a list of objects that matched ALL specified criteria.
Either pointer or text path to an instance work here (default is the design top)
How deep in the hierarchy should we search? (default is 10000 ;-)
Return only instances who's path matches some regular expression (e.g., '.*\.ahb0\..*')
Return only instances who's instance name matches a regular expression
Return only instances who's finalized module name matches a regular expression
Return only instances who's base module name (before uniquification) matches a regular expression
# SNameRegex - Return only instances who's source file name matches a regular expression
# HasParamRegex - Return only instances that has a parameter who's name matches the regular
# expression. The HasParamRegex arg can be either a string (e.g., 'Width')
# or a string array ref (e.g., ['Width', 'Radix']). Note that in the string
# array case, we search for instances that has a param that matchs regex1 AND
       #                 a param that matches regex2 AND...
       # ApplyMap - If you have some complex way of determining if an instance should be returned,
       #            you can create your own function that accept/reject an objects. Your function
       #            must return False/True. E.g., def func(node): return (node.iname() == 'ofer')
       # Reverse - Search hierarchy in DFS or in Reverse DFS order (True/False)
Parameter extraction methods
 def exists_param(self, name):
 def get_param_doc(self, name):
 def get_param_val(self, name):

Example script and xml file are attached here.

Best, Ofer.