vrq
Public Member Functions | Static Public Member Functions

CNode Class Reference

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

#include <cnode.h>

Inheritance diagram for CNode:
CObject

List of all members.

Public Member Functions

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

Static Public Member Functions

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

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:
aLoc is file info for the parse node.
aOp is the parse node operation.

Member Function Documentation

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

Get a node's operand.

Parameters:
index is 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:
heap heap to use for allocation, defaults to current node heap.
Returns:
shallow copy of tree.
static CObstack* CNode::CurrentHeap (  )  [inline, static]

Gets pointer to current heap allocator.

Returns:
pointer to current heap allocator
static void CNode::DisableAndClearLabelCache (  )  [inline, static]

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:
f file descriptor to print output.
static void CNode::EnableLabelCache (  )  [inline, static]

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:
v reference 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:
v reference to vector to store result
newWidth width of evaluating context.
newType type 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:
name name of attribute to search for.
n don't supply this argument.
init don'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:
name name of attribute to search for.
n don't supply this argument.
init don'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:
integerIsNonX non-zero specifies that integers should considered to never take on X or Z values.
exclude specifies 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:
callback function to be called for each node
data opaque 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:
callback function to be called for each node
data opaque 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:
callback function to be called for each node
data opaque argument passed to callback function
static void CNode::ResetBuildStack ( void   )  [inline, static]

Restore previous heap.

void CNode::SetAttributes ( CNode attr  )  [inline]

Attach attributes to operation.

Parameters:
attr attributes to attach to operation.
static void CNode::SetBuildStack ( CObstack aStack  )  [inline, static]

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:
aOp is 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:
newWidth width of resulting expression.
newType type of resulting expression.
Returns:
simplified expression if expression can be simplified, otherwise original expression is returned.
static void CNode::UseEvalStack ( void   )  [inline, static]

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: