vrq
Public Member Functions | Static Public Member Functions | List of all members
CNode Class Reference

Primary data structure representing parse tree nodes. More...

#include <cnode.h>

Inheritance diagram for CNode:
CObject

Public Member Functions

 CNode (Coord_t *aLoc, NodeOp_t aOp)
 Constructor for parse node. More...
 
Coord_tGetCoord ()
 Get node's file coordinates. More...
 
NodeOp_t GetOp ()
 Return node's operation type. More...
 
void SetOp (NodeOp_t aOp)
 Set node's operation type. More...
 
unsigned Hash ()
 Calculate hash of tree. More...
 
template<class T >
CNode_sp< T > Arg (int index)
 Get a node's operand. More...
 
int ArgCount (void)
 Get the number of operands for the node. More...
 
CNodeClone (CObstack *heap=stack)
 Replicate tree. More...
 
int Precedence ()
 Get the precedence of the operator represented by the node. More...
 
void PostVisit1 (void(*callback)(CNode *, void *), void *data)
 Walk tree invoking callback on each node after children have been visited. More...
 
CNodePostSubVisit1 (CNode *(*callback)(CNode *, void *), void *data)
 Walk tree invoking callback on each node after children have been visited. More...
 
void PreVisit1 (int(*callback)(CNode *, void *), void *data)
 Walk tree invoking callback on each node before children have been visited. More...
 
CNodeSimplify (INT32 newWidth, NodeType_t newType)
 Create simplified expression tree with given width and type. More...
 
int IsNonX (int integerIsNonX=0, char *exclude=NULL)
 Checks expression tree to see if expression can result in an X or Z. More...
 
int IsConstant ()
 Checks expression tree to see if it is constant. More...
 
int IsEvaluateable ()
 Checks to see if expression tree can be evaluated. More...
 
int IsVolatile (void)
 Checks to see if expression tree is volatile. More...
 
INT32 EvalINT32 ()
 Evaluates expression tree and returns value as a 32 bit integer. More...
 
void EvalVector (CVector &v)
 Evaluates expression tree evaluated in unconstrainted context. More...
 
void EvalVector (CVector &v, INT32 newWidth, NodeType_t newType)
 Evaluates expression tree evaluated in the specified context. More...
 
double EvalReal (void)
 Evaluates expression tree evaluated in a real context. More...
 
void Dump (FILE *f)
 Print a compact representation of the parse tree. More...
 
int IsWidthConstant (void)
 Evaluates if expression width is constant. More...
 
int IsWidthVolatile (void)
 Evaluates if expression width is volatile. More...
 
int IsWidthEvaluateable (void)
 Evaluates if expression width can be evaluated. More...
 
CNodeGetWidthExp (void)
 Create expression representing width of expression. More...
 
INT32 GetWidth (void)
 Evaluate width of expression. More...
 
int IsScalar (void)
 Determine if expression is a 1 bit signed or unsigned value. More...
 
int IsVector (void)
 Determine if expression is a multi-bit signed or unsigned value. More...
 
int IsReal (void)
 Determine if expression is real. More...
 
CNodeGetAttributes ()
 Get attributes attached to operation. More...
 
void SetAttributes (CNode *attr)
 Attach attributes to operation. More...
 
int HasAttribute (const char *name, CNode *n=NULL, int init=1)
 Determine if node has the given attribute. More...
 
CAttrGetAttribute (const char *name, CNode *n=NULL, int init=1)
 Get attribute attached to node with the given attribute. More...
 
NodeType_t GetNodeType (void)
 Get node expression type. More...
 
- Public Member Functions inherited from CObject
void * operator new (size_t size, CObstack *stack)
 Allocate object on CObstack heap. More...
 
void operator delete (void *object)
 Destroy object. More...
 

Static Public Member Functions

static CObstackCurrentHeap ()
 Gets pointer to current heap allocator. More...
 
static void UseEvalStack (void)
 Use evaluation stack. More...
 
static void SetBuildStack (CObstack *aStack)
 Set heap to a specific heap. More...
 
static void ResetBuildStack (void)
 Restore previous heap. More...
 
static void EnableLabelCache ()
 Enable cache of labeled nodes to be tracked. More...
 
static void DisableAndClearLabelCache ()
 Disable caching of label info (width and type) and clear all accumulated data. More...
 

Detailed Description

Primary data structure representing parse tree nodes.

Each parse tree node is represented as a forest of binary CNode objects. Nodes are always balenced with left to right construction.

CNode uses the CObstack memory allocator (via CObject). This allows memory to be allocated in large slabs and released enmasse.

Each parse node represents an operation, represented by NodeOp_t. Additionally expression nodes may also be decorated with file/line info, verilog attributes, and temporary tags. All decorations are only valid on the CNode at the root of the parse nodes CNode graph.

The operands of a parse tree node are referenced using the method Arg. A description of the parse tree nodes and there arguments can be found here: Parse Tree Nodes .

Constructor & Destructor Documentation

CNode::CNode ( Coord_t aLoc,
NodeOp_t  aOp 
)

Constructor for parse node.

Note this routine will create a linked set of CNode for nodes with more than 2 operands.

Parameters
aLocis file info for the parse node.
aOpis the parse node operation.

Member Function Documentation

template<class T >
CNode_sp< T > CNode::Arg ( int  index)

Get a node's operand.

Parameters
indexis a the operand number (zero based).
Returns
type safe operand "number" of node
int CNode::ArgCount ( void  )

Get the number of operands for the node.

Returns
number of operands.
CNode * CNode::Clone ( CObstack heap = stack)

Replicate tree.

Leaf nodes are not replicated.

Parameters
heapheap to use for allocation, defaults to current node heap.
Returns
shallow copy of tree.
static CObstack* CNode::CurrentHeap ( )
inlinestatic

Gets pointer to current heap allocator.

Returns
pointer to current heap allocator
static void CNode::DisableAndClearLabelCache ( )
inlinestatic

Disable caching of label info (width and type) and clear all accumulated data.

void CNode::Dump ( FILE *  f)

Print a compact representation of the parse tree.

Parameters
ffile descriptor to print output.
static void CNode::EnableLabelCache ( )
inlinestatic

Enable cache of labeled nodes to be tracked.

This greatly speeds up operations which utilize expression width and type information. However it should only be enabled when you know you are not changing the tree structures in such a way that the type and width properties change. This cache should always be disable and cleared when your done with it.

INT32 CNode::EvalINT32 ( )

Evaluates expression tree and returns value as a 32 bit integer.

Expression tree must be evaluateable otherwise results are undefined. *

Returns
expression value evaluated as an integer.
double CNode::EvalReal ( void  )

Evaluates expression tree evaluated in a real context.

Expression tree must be evaluateable otherwise results are undefined.

Returns
expression value evaluated as a real.
void CNode::EvalVector ( CVector v)

Evaluates expression tree evaluated in unconstrainted context.

Result is returned as a vector. Expression tree must be evaluateable otherwise results are undefined.

Parameters
vreference to vector to store result
void CNode::EvalVector ( CVector v,
INT32  newWidth,
NodeType_t  newType 
)

Evaluates expression tree evaluated in the specified context.

Result is returned as a vector. Expression tree must be evaluateable otherwise results are undefined.

Parameters
vreference to vector to store result
newWidthwidth of evaluating context.
newTypetype of evaluating context.
CAttr * CNode::GetAttribute ( const char *  name,
CNode n = NULL,
int  init = 1 
)

Get attribute attached to node with the given attribute.

Parameters
namename of attribute to search for.
ndon't supply this argument.
initdon't supply this argument.
Returns
attribute matching name. NULL if none.
CNode* CNode::GetAttributes ( )
inline

Get attributes attached to operation.

Returns
attribute parse tree. NULL if no attibutes are attached.
Coord_t* CNode::GetCoord ( )
inline

Get node's file coordinates.

Returns
pointer to node's file coordinates
NodeType_t CNode::GetNodeType ( void  )
inline

Get node expression type.

Returns
expression type.
NodeOp_t CNode::GetOp ( )
inline

Return node's operation type.

Returns
node's operation type
INT32 CNode::GetWidth ( void  )
inline

Evaluate width of expression.

Width must be evaluateable, otherwise the results are undefined.

Returns
width of expression.
CNode * CNode::GetWidthExp ( void  )

Create expression representing width of expression.

Returns
expression representing width of expression
int CNode::HasAttribute ( const char *  name,
CNode n = NULL,
int  init = 1 
)

Determine if node has the given attribute.

Parameters
namename of attribute to search for.
ndon't supply this argument.
initdon't supply this argument.
Returns
non-zero if node has attribute
unsigned CNode::Hash ( )

Calculate hash of tree.

Equivilent(n1,n2) => Hash(n1)==Hash(n2)

Returns
tree hash code.
int CNode::IsConstant ( )

Checks expression tree to see if it is constant.

i.e. Dependent on constants and parameters only.

Returns
non-zero indicates expression is constant.
int CNode::IsEvaluateable ( )

Checks to see if expression tree can be evaluated.

Expressions may not be able to be evaluated for a variety of reasons:

  • Contains a construct the expression evaluator doesn't support.
  • Contains a reference to a variable.
  • Constains an external reference.
    Returns
    non-zero if expression can be evaluated.
int CNode::IsNonX ( int  integerIsNonX = 0,
char *  exclude = NULL 
)

Checks expression tree to see if expression can result in an X or Z.

Parameters
integerIsNonXnon-zero specifies that integers should considered to never take on X or Z values.
excludespecifies an attribute name that indicates the declaration will never be X or Z.
Returns
non-zero indicates the expression will never be X or Z.
int CNode::IsReal ( void  )
inline

Determine if expression is real.

Returns
non-zero if expression is a real.
int CNode::IsScalar ( void  )
inline

Determine if expression is a 1 bit signed or unsigned value.

Returns
non-zero if expression is scalar.
int CNode::IsVector ( void  )
inline

Determine if expression is a multi-bit signed or unsigned value.

Returns
non-zero if expression is a vector.
int CNode::IsVolatile ( void  )

Checks to see if expression tree is volatile.

i.e. Dependent upon parameters and variables.

Returns
non-zero if expression is volatile.
int CNode::IsWidthConstant ( void  )

Evaluates if expression width is constant.

i.e. Depends upon parameters and constants only.

Returns
non-zero if expression width is constant.
int CNode::IsWidthEvaluateable ( void  )

Evaluates if expression width can be evaluated.

Widths may not be able to be evaluated for a variety of reasons:

  • Contains a construct the expression evaluator doesn't support.
  • Contains a reference to a variable.
  • Constains an external reference.
    Returns
    non-zero if expression width is volatile.
int CNode::IsWidthVolatile ( void  )

Evaluates if expression width is volatile.

i.e. Depends upon parameters and variables.

Returns
non-zero if expression width is volatile.
CNode * CNode::PostSubVisit1 ( CNode *(*)(CNode *, void *)  callback,
void *  data 
)

Walk tree invoking callback on each node after children have been visited.

callback may modify tree and return a modified subtree.

Parameters
callbackfunction to be called for each node
dataopaque argument passed to callback function
Returns
modified child subtree.
void CNode::PostVisit1 ( void(*)(CNode *, void *)  callback,
void *  data 
)

Walk tree invoking callback on each node after children have been visited.

Parameters
callbackfunction to be called for each node
dataopaque argument passed to callback function
int CNode::Precedence ( )

Get the precedence of the operator represented by the node.

Returns
precedence of the operator
void CNode::PreVisit1 ( int(*)(CNode *, void *)  callback,
void *  data 
)

Walk tree invoking callback on each node before children have been visited.

callback can terminate transversal early. callback returns 0 to terminate transversal early.

Parameters
callbackfunction to be called for each node
dataopaque argument passed to callback function
static void CNode::ResetBuildStack ( void  )
inlinestatic

Restore previous heap.

void CNode::SetAttributes ( CNode attr)
inline

Attach attributes to operation.

Parameters
attrattributes to attach to operation.
static void CNode::SetBuildStack ( CObstack aStack)
inlinestatic

Set heap to a specific heap.

Save previous heap in stack so it can be restored

void CNode::SetOp ( NodeOp_t  aOp)
inline

Set node's operation type.

Asserts if number arguments in new type are different than old.

Parameters
aOpis the new operation type.
CNode * CNode::Simplify ( INT32  newWidth,
NodeType_t  newType 
)

Create simplified expression tree with given width and type.

Evaluates non-volatile constant expressions.

Parameters
newWidthwidth of resulting expression.
newTypetype of resulting expression.
Returns
simplified expression if expression can be simplified, otherwise original expression is returned.
static void CNode::UseEvalStack ( void  )
inlinestatic

Use evaluation stack.

Track recursive call so that eval heap is only freed when all uses are complete. Note that nodes on the eval stack should NEVER point to nodes that are not. If you do the labelCache will cause stale information to be used with bizare results. Usually this means that subtrees attached to evalStack allocated node should be cloned on to the evalStack.


The documentation for this class was generated from the following files: