Primary data structure representing parse tree nodes. More...
#include <cnode.h>
Public Member Functions | |
CNode (Coord_t *aLoc, NodeOp_t aOp) | |
Constructor for parse node. | |
Coord_t * | GetCoord () |
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. | |
CNode * | Clone (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. | |
CNode * | PostSubVisit1 (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. | |
CNode * | Simplify (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. | |
CNode * | GetWidthExp (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. | |
CNode * | GetAttributes () |
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. | |
CAttr * | GetAttribute (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 CObstack * | CurrentHeap () |
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. |
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 for parse node.
Note this routine will create a linked set of CNode for nodes with more than 2 operands.
aLoc | is file info for the parse node. | |
aOp | is the parse node operation. |
CNode_sp< T > CNode::Arg | ( | int | index | ) |
Get a node's operand.
index | is a the operand number (zero based). |
int CNode::ArgCount | ( | void | ) |
Get the number of operands for the node.
Replicate tree.
Leaf nodes are not replicated.
heap | heap to use for allocation, defaults to current node heap. |
static CObstack* CNode::CurrentHeap | ( | ) | [inline, static] |
Gets 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.
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. *
double CNode::EvalReal | ( | void | ) |
Evaluates expression tree evaluated in a real context.
Expression tree must be evaluateable otherwise results are undefined.
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.
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.
v | reference to vector to store result | |
newWidth | width of evaluating context. | |
newType | type of evaluating context. |
Get attribute attached to node with the given attribute.
name | name of attribute to search for. | |
n | don't supply this argument. | |
init | don't supply this argument. |
CNode* CNode::GetAttributes | ( | ) | [inline] |
Get attributes attached to operation.
Coord_t* CNode::GetCoord | ( | ) | [inline] |
Get node's file coordinates.
NodeType_t CNode::GetNodeType | ( | void | ) | [inline] |
Get node expression type.
NodeOp_t CNode::GetOp | ( | ) | [inline] |
Return node's operation type.
INT32 CNode::GetWidth | ( | void | ) | [inline] |
Evaluate width of expression.
Width must be evaluateable, otherwise the results are undefined.
CNode * CNode::GetWidthExp | ( | void | ) |
Create expression representing width of expression.
int CNode::HasAttribute | ( | const char * | name, | |
CNode * | n = NULL , |
|||
int | init = 1 | |||
) |
Determine if node has the given attribute.
name | name of attribute to search for. | |
n | don't supply this argument. | |
init | don't supply this argument. |
unsigned CNode::Hash | ( | ) |
Calculate hash of tree.
Equivilent(n1,n2) => Hash(n1)==Hash(n2)
int CNode::IsConstant | ( | ) |
Checks expression tree to see if it is constant.
i.e. Dependent on constants and parameters only.
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:
int CNode::IsNonX | ( | int | integerIsNonX = 0 , |
|
char * | exclude = NULL | |||
) |
Checks expression tree to see if expression can result in an X or Z.
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. |
int CNode::IsReal | ( | void | ) | [inline] |
Determine if expression is real.
int CNode::IsScalar | ( | void | ) | [inline] |
Determine if expression is a 1 bit signed or unsigned value.
int CNode::IsVector | ( | void | ) | [inline] |
Determine if expression is a multi-bit signed or unsigned value.
int CNode::IsVolatile | ( | void | ) |
Checks to see if expression tree is volatile.
i.e. Dependent upon parameters and variables.
int CNode::IsWidthConstant | ( | void | ) |
Evaluates if expression width is constant.
i.e. Depends upon parameters and constants only.
int CNode::IsWidthEvaluateable | ( | void | ) |
Evaluates if expression width can be evaluated.
Widths may not be able to be evaluated for a variety of reasons:
int CNode::IsWidthVolatile | ( | void | ) |
Evaluates if expression width is volatile.
i.e. Depends upon parameters and variables.
Walk tree invoking callback on each node after children have been visited.
callback may modify tree and return a modified subtree.
callback | function to be called for each node | |
data | opaque argument passed to callback function |
void CNode::PostVisit1 | ( | void(*)(CNode *, void *) | callback, | |
void * | data | |||
) |
Walk tree invoking callback on each node after children have been visited.
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.
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.
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.
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.
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.
newWidth | width of resulting expression. | |
newType | type of resulting expression. |
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.