132 operator T() {
return *ptr; }
191 static list<CObstack*> stackList;
193 static INT32 evalCount;
195 static map<CNode*,int> labelCache;
196 static int labelCacheEnabled;
211 int LabelBits(
int supressErrorMessages = FALSE );
213 void _EvalVector(
CVector& v );
214 double _EvalReal(
void );
215 void FixedWidth(
int v ) { fixedWidth = v; }
216 int FixedWidth() {
return fixedWidth; }
217 int ConditionalWiden();
220 CNode* GetNLeft(
void ) {
return (
CNode*)left; }
221 CNode* GetNRight(
void ) {
return (
CNode*)right; }
222 static void _LabelBits(
CNode* n,
void* arg );
239 stackList.push_front( stack );
248 MASSERT( evalCount == 0 );
249 stackList.push_front( stack );
256 if( stack == &evalHeap ) {
258 if( evalCount == 0 ) {
259 evalHeap.
Free( NULL );
262 if( stackList.empty() ) {
265 stack = *stackList.begin();
266 stackList.pop_front();
280 labelCacheEnabled = 1;
288 labelCacheEnabled = 0;
289 labelCache.erase( labelCache.begin(), labelCache.end() );
393 int IsNonX(
int integerIsNonX = 0,
char* exclude = NULL );
447 void Dump( FILE* f );
485 int IsScalar(
void ) { LabelBits(TRUE);
return width==1; }
490 int IsVector(
void ) { LabelBits(TRUE);
return width>1; }
495 int IsReal(
void ) { LabelBits(TRUE);
return type==
eR; }
587 return CNode_sp<T>(&GetNLeft()->GetNLeft()->right);
603 return CNode_sp<T>(&GetNLeft()->GetNLeft()->right);
605 return CNode_sp<T>(&GetNLeft()->GetNRight()->left);
607 return CNode_sp<T>(&GetNLeft()->GetNRight()->right);
621 return CNode_sp<T>(&GetNLeft()->GetNLeft()->right);
623 return CNode_sp<T>(&GetNLeft()->GetNRight()->left);
625 return CNode_sp<T>(&GetNLeft()->GetNRight()->right);
627 return CNode_sp<T>(&GetNRight()->GetNLeft()->left);
629 return CNode_sp<T>(&GetNRight()->GetNLeft()->right);
641 return CNode_sp<T>(&GetNLeft()->GetNLeft()->right);
643 return CNode_sp<T>(&GetNLeft()->GetNRight()->left);
645 return CNode_sp<T>(&GetNLeft()->GetNRight()->right);
647 return CNode_sp<T>(&GetNRight()->GetNLeft()->left);
649 return CNode_sp<T>(&GetNRight()->GetNLeft()->right);
651 return CNode_sp<T>(&GetNRight()->GetNRight()->left);
653 return CNode_sp<T>(&GetNRight()->GetNRight()->right);
668 inline void Add(
double* r,
double* a,
double* b )
673 inline void Sub(
double* r,
double* a,
double* b )
678 inline void Mul(
double* r,
double* a,
double* b )
683 inline void Div(
double* r,
double* a,
double* b )
688 inline void Neg(
double* r,
double* a )
693 inline void Plus(
double* r,
double* a )
698 inline void Pow(
double* r,
double* a,
double* b )
707 #define ILLEGAL_OP2(op) \
708 inline void op( double*, double*, double* )\
709 { fatal( NULL, #op " is illegal for reals" ); }
711 #define ILLEGAL_OP1(op) \
712 inline void op( double*, double* )\
713 { fatal( NULL, #op " is illegal for reals" ); }
734 #define DEFINE_CONSTRUCTOR
736 #undef DEFINE_CONSTRUCTOR
767 int len = strlen( s );
821 }
else if( n2 == NULL ) {
867 }
else if( n2 == NULL ) {
870 return cLIST( n1, n2 );
884 return cHOOK(cond,n1,n2);
905 int argNumber, vector<T>& v)
910 switch( n->
GetOp() ) {
912 ArgList2Vector<T>(n->
Arg<
CNode*>(0),op,argNumber,v);
913 ArgList2Vector<T>(n->
Arg<
CNode*>(1),op,argNumber,v);
916 if( n->
GetOp() == op ) {
917 v.push_back(n->
Arg<T>(argNumber));
936 switch( n->
GetOp() ) {
942 if( excludeOps.find(n->
GetOp()) == excludeOps.end() ) {
962 switch( n->
GetOp() ) {
968 if( excludeOps.find(n->
GetOp()) == excludeOps.end() ) {
983 CNode* result = NULL;
984 vector<CNode*>::const_reverse_iterator ptr;
985 for( ptr = v.rbegin(); ptr != v.rend(); ++ptr ) {
987 result =
cELIST(*ptr, result);
1003 CNode* result = NULL;
1004 list<CNode*>::reverse_iterator ptr;
1005 for( ptr = v.rbegin(); ptr != v.rend(); ++ptr ) {
1007 result =
cELIST(*ptr, result);
1029 switch( n->
GetOp() ) {
1036 if( n->
GetOp() == op ) {
1056 switch( n->
GetOp() ) {
1079 inline double s2d(
char* s ) {
1095 snprintf( buffer,
sizeof(buffer),
"%g", d );
1096 char* s = (
char*)heap->
Alloc(strlen(buffer)+1);
1097 strcpy( s, buffer );
1113 CNode* parent = NULL;
1162 *count = count0+count1;
1163 *depth = depth0 > depth1 ? depth0 : depth1;
1177 }
else if( !pr1.
tail ) {
1203 switch( ref->
GetOp() ) {
1206 vector<CNode*> indexes;
1208 set<NodeOp_t>(), indexes );
1209 vector<CNode*>::iterator ptr;
1210 for( ptr = indexes.begin(); ptr != indexes.end(); ++ptr ) {
1217 INT32 value = (*ptr)->EvalINT32();
1218 ostringstream subscript;
1219 subscript <<
'[' << value <<
']';
1220 buffer += subscript.str();
1240 buffer = ref->
Arg<
CDecl*>(0)->GetName();
1254 CNode* result = first;
1256 va_start( ap, first );
1263 result =
cMAX( result, arg );
1272 CNode* result = first;
1274 va_start( ap, first );
1280 result =
cADD( result, arg );
1288 CNode* result = first;
1290 va_start( ap, first );
1296 result =
cMUL( result, arg );
1305 va_start( ap, first );
1310 MASSERT( va_arg(ap,
CNode*) == NULL );
1322 return a1 < a2 ? a2 : a1;
1325 inline int cMAX(
int a1,
int a2,
int a3 )
1343 return (diff < 0 ? -diff : diff)+1;
Declaration object for nets.
Definition: cnet.h:46
CNode * cSUB(CNode *a0, CNode *a1, Coord_t *loc=NULL)
Node construction shortcut for SUB subtract.
Definition: cnode_def.h:2860
int HasAttribute(const char *name, CNode *n=NULL, int init=1)
Determine if node has the given attribute.
Definition: cnode.cc:412
static void DisableAndClearLabelCache()
Disable caching of label info (width and type) and clear all accumulated data.
Definition: cnode.h:286
real constant
Definition: cnode_def.h:649
vector subrange with ascending index select
Definition: cnode_def.h:1147
CNode * Simplify(INT32 newWidth, NodeType_t newType)
Create simplified expression tree with given width and type.
Definition: cnode.cc:337
int cMUL(int a1, int a2)
Definition: cnode.h:1335
static void UseEvalStack(void)
Use evaluation stack.
Definition: cnode.h:238
int Equivalent(CNode *a, CNode *b)
Definition: cnode_def.h:12010
Smart pointer for CNode class Creates safe references to CNode arguments Supports assignment...
Definition: cnode.h:125
CNode * operator->()
Definition: cnode.h:148
Declaration object for genvars.
Definition: cgenvar.h:46
CNode * cELIST(CNode *a0, CNode *a1, Coord_t *loc=NULL)
Node construction shortcut for ELIST expression list.
Definition: cnode_def.h:2769
CNode * RebalanceRight(CNode *n)
Definition: cnode.h:1105
Gate declaration object.
Definition: cgate.h:42
T * Ptr()
Definition: cnode.h:131
int IsScalar(void)
Determine if expression is a 1 bit signed or unsigned value.
Definition: cnode.h:485
CNode * cREAL(double number)
Short cut for creating RCONSTANT node with a given double value.
Definition: cnode.h:803
static void EnableLabelCache()
Enable cache of labeled nodes to be tracked.
Definition: cnode.h:278
int IsEvaluateable()
Checks to see if expression tree can be evaluated.
Definition: cnode_def.h:12554
int ListCount(CNode *n, NodeOp_t op)
Walks a list/elist of nodes and counts the number of node with the specified operation.
Definition: cnode.h:1023
void Add(double *r, double *a, double *b)
Definition: cnode.h:668
int cADD(int a1, int a2)
Definition: cnode.h:1330
Declaration object for specify blocks.
Definition: cspecify.h:47
CNode * cMAX_N(CNode *first,...)
Definition: cnode.h:1252
void SetPreferredBase(int base)
Set preferred base for printing value.
Definition: cvector.h:132
char * d2s(double d, CObstack *stack)
Convert double to char string allocating storage on given heap.
Definition: cnode.h:1091
CNode * second
Definition: cnode.h:163
void Neg(double *r, double *a)
Definition: cnode.h:688
list of nodes
Definition: cnode_def.h:1114
vector constant
Definition: cnode_def.h:639
CNode * cSTRING(const char *s)
Short cut for creating VCONSTANT node with a given string value.
Definition: cnode.h:765
Coord_t * GetCoord()
Get node's file coordinates.
Definition: cnode.h:303
CNode * List2EList(list< CNode * > &v)
Converts a list of CNode* into a linked ELIST of the elements.
Definition: cnode.h:1001
CNode * cMUL_N(CNode *first,...)
Definition: cnode.h:1286
static CObstack * CurrentHeap()
Gets pointer to current heap allocator.
Definition: cnode.h:228
int IsConstant()
Checks expression tree to see if it is constant.
Definition: cnode_def.h:7999
CNode * GetWidthExp(void)
Create expression representing width of expression.
Definition: cnode_def.h:8637
CBlock CScope
Definition: cnode.h:65
CNode * cNEG(CNode *a0, Coord_t *loc=NULL)
Node construction shortcut for NEG negation.
Definition: cnode_def.h:4371
Strength_t s1
Definition: cnode.h:110
void ArgList2Vector(CNode *n, NodeOp_t op, int argNumber, vector< T > &v)
Walks a list of nodes and collects the specified augments of a given node type.
Definition: cnode.h:904
void MeasureDepth(CNode *n, int *count, int *depth)
Definition: cnode.h:1143
void PostVisit1(void(*callback)(CNode *, void *), void *data)
Walk tree invoking callback on each node after children have been visited.
Definition: cnode_def.h:10416
long INT32
Short cut for signed 32 bit integer.
Definition: glue.h:38
int IsReal(void)
Determine if expression is real.
Definition: cnode.h:495
int IsVolatile(void)
Checks to see if expression tree is volatile.
Definition: cnode_def.h:8161
int Precedence()
Get the precedence of the operator represented by the node.
Definition: cnode_def.h:7831
CNode_sp< T > Arg(int index)
Get a node's operand.
Definition: cnode.h:535
Edge_t
Edge values.
Definition: cnode.h:72
reference to port
Definition: cnode_def.h:991
void * Alloc(INT32 size)
Allocate block of storage with given size.
reference to a forward declared variable
Definition: cnode_def.h:1001
static CVector * AllocFromHeap(CObstack *aHeap, int width)
Create vector allocating all storage from given heap.
Definition: cvector.h:85
int operator!=(CNode_pr p)
Definition: cnode.h:153
int operator!=(CNode_sp< T > p)
Definition: cnode.h:136
void List2VectorExclude(CNode *n, const set< NodeOp_t > &excludeOps, vector< CNode * > &v)
Walks an expression list of nodes and collects the subtrees that don't match the given node types...
Definition: cnode.h:957
CNode * operator=(CNode *n)
Definition: cnode.h:147
INT32 EvalINT32()
Evaluates expression tree and returns value as a 32 bit integer.
Definition: cnode.cc:308
CNode * cHOOK(CNode *a0, CNode *a1, CNode *a2, Coord_t *loc=NULL)
Node construction shortcut for HOOK condition expression operator.
Definition: cnode_def.h:4964
T operator=(T n)
Definition: cnode.h:129
static void ResetBuildStack(void)
Restore previous heap.
Definition: cnode.h:255
reference to a genvar
Definition: cnode_def.h:1011
CNode * third
Definition: cnode.h:164
int ArgCount(void)
Get the number of operands for the node.
Definition: cnode_def.h:7511
Helper class for building tail recursive binary CNode trees Used by parser.
Definition: cnode.h:143
int Based()
Get based attribute.
Definition: cvector.h:155
Pair of strengths.
Definition: cnode.h:108
Structure to hold file coordinates.
Definition: cdecl.h:47
Holder for character strings.
Definition: csymbol.h:44
Declaration object for module/function/task ports.
Definition: cport.h:44
CNode * first
Definition: cnode.h:162
Forward reference declaration.
Definition: cfref.h:51
Bulk object allocation object.
Definition: cobstack.h:46
CNode * cABSDIFFPLUS1_N(CNode *first,...)
Definition: cnode.h:1302
reference to net
Definition: cnode_def.h:961
Strength_t
Strength values.
Definition: cnode.h:93
Primary data structure representing parse tree nodes.
Definition: cnode.h:188
int operator==(CNode_sp< T > p)
Definition: cnode.h:135
NodeOp_t
Parse tree opcodes.
Definition: cnode_def.h:620
CNode * cLINK(CNode *n1, CNode *n2)
Short cut for linking together to nodes with a LIST operator.
Definition: cnode.h:863
CNode * cELINK(CNode *n1, CNode *n2)
Link together two nodes with an ELIST operator.
Definition: cnode.h:817
int IsNonX(int integerIsNonX=0, char *exclude=NULL)
Checks expression tree to see if expression can result in an X or Z.
Definition: cnode_def.h:9235
Declaration object for module and gate instances.
Definition: cinstance.h:45
expression list
Definition: cnode_def.h:690
void EvalVector(CVector &v)
Evaluates expression tree evaluated in unconstrainted context.
Definition: cnode.cc:360
CNode * head
Definition: cnode.h:144
void Pow(double *r, double *a, double *b)
Definition: cnode.h:698
CNode * Vector2EList(const vector< CNode * > &v)
Converts a vector array of CNode* into a linked ELIST of the elements.
Definition: cnode.h:981
CNode(Coord_t *aLoc, NodeOp_t aOp)
Constructor for parse node.
Definition: cnode.cc:240
member reference (structure, class or external
Definition: cnode_def.h:2206
CAttr * GetAttribute(const char *name, CNode *n=NULL, int init=1)
Get attribute attached to node with the given attribute.
Definition: cnode.cc:445
void SetAttributes(CNode *attr)
Attach attributes to operation.
Definition: cnode.h:505
CNode_sp(void **np)
Pointer to untyped argument.
Definition: cnode.h:128
static void SetBuildStack(CObstack *aStack)
Set heap to a specific heap.
Definition: cnode.h:247
int operator!=(T v)
Definition: cnode.h:134
CNode * cVECTOR(CVector &vec)
Short cut for creating VCONSTANT node with a given vector value.
Definition: cnode.h:748
CNode * PostSubVisit1(CNode *(*callback)(CNode *, void *), void *data)
Walk tree invoking callback on each node after children have been visited.
Definition: cnode_def.h:10946
void Div(double *r, double *a, double *b)
Definition: cnode.h:683
Definitions for parse tree nodes.
void SetOp(NodeOp_t aOp)
Set node's operation type.
Definition: cnode.h:315
Base class for describing declaration objects.
Definition: cdecl.h:164
CNode * tail
Definition: cnode.h:145
int IsVector(void)
Determine if expression is a multi-bit signed or unsigned value.
Definition: cnode.h:490
void Sub(double *r, double *a, double *b)
Definition: cnode.h:673
int operator==(CNode_pr p)
Definition: cnode.h:152
int Sized()
Get sized attribute.
Definition: cvector.h:143
Declaration object for variables.
Definition: cvar.h:50
external reference
Definition: cnode_def.h:1986
Declaration object for parameters.
Definition: cparam.h:46
Declaration object for holding lists of verilog attributes and their corresponding expressions...
Definition: cattr.h:50
CNode * cINT32(INT32 i)
Short cut for creating VCONSTANT node with a given integer value.
Definition: cnode.h:784
int IsWidthEvaluateable(void)
Evaluates if expression width can be evaluated.
Definition: cnode_def.h:9077
Bit vector class for implementing 4 state verilog signed and unsigned arithmetic. ...
Definition: cvector.h:58
CNode * cGE(CNode *a0, CNode *a1, Coord_t *loc=NULL)
Node construction shortcut for GE greater than or equal.
Definition: cnode_def.h:4492
void PreVisit1(int(*callback)(CNode *, void *), void *data)
Walk tree invoking callback on each node before children have been visited.
Definition: cnode_def.h:9899
INT32 GetWidth(void)
Evaluate width of expression.
Definition: cnode.h:480
Base class for vrq objects.
Definition: cobject.h:41
CNode * cLT(CNode *a0, CNode *a1, Coord_t *loc=NULL)
Node construction shortcut for LT less than.
Definition: cnode_def.h:4525
void Mul(double *r, double *a, double *b)
Definition: cnode.h:678
int IsWidthConstant(void)
Evaluates if expression width is constant.
Definition: cnode_def.h:8323
void EList2VectorExclude(CNode *n, const set< NodeOp_t > &excludeOps, vector< CNode * > &v)
Walks an expression elist of nodes and collects the subtrees that don't match the given node types...
Definition: cnode.h:931
NodeType_t GetNodeType(void)
Get node expression type.
Definition: cnode.h:526
int GetPreferredBase()
Get preferred base for printing value.
Definition: cvector.h:137
void Plus(double *r, double *a)
Definition: cnode.h:693
int operator!=(CNode *v)
Definition: cnode.h:151
INT32 GetWidth(void)
Get vector bit width.
int Signed() const
Get signed attribute.
Definition: cvector.h:178
vector subrange
Definition: cnode_def.h:1136
real - have width 0
Definition: cdatatype.h:99
Declaration object for functions and tasks.
Definition: cfunction.h:50
int operator==(CNode *v)
Definition: cnode.h:150
CNode * cLIST(CNode *a0, CNode *a1, Coord_t *loc=NULL)
Node construction shortcut for LIST list of nodes.
Definition: cnode_def.h:4025
unsigned Hash()
Calculate hash of tree.
Definition: cnode_def.h:11478
int LoadString(const char *string)
Load string value from string.
Declaration object for input/output/inout statements.
Definition: cportdir.h:45
CNode * cMAX(CNode *n1, CNode *n2)
Short cut for creating a expression tree that calculates the maximum of two expressions.
Definition: cnode.h:881
T operator->()
Definition: cnode.h:130
CNode * cADD_N(CNode *first,...)
Definition: cnode.h:1270
CNode * cABS(CNode *a)
Short cut for creating an subtree that calculates the absolute value of an expression.
Definition: cnode.h:834
Strength_t s0
Definition: cnode.h:109
NodeType_t
Expression node type.
Definition: cdatatype.h:97
friend CNode_pr cLINK(CNode_pr pr1, CNode *n2)
Definition: cnode.h:1173
void Free(void *object)
Free all storage including and after object.
CNode * GetAttributes()
Get attributes attached to operation.
Definition: cnode.h:500
dimensioned reference (array/bit select)
Definition: cnode_def.h:951
NodeOp_t GetOp()
Return node's operation type.
Definition: cnode.h:308
int IsWidthVolatile(void)
Evaluates if expression width is volatile.
Definition: cnode_def.h:8479
void Dump(FILE *f)
Print a compact representation of the parse tree.
Definition: cnode_def.h:15149
Declaration class for block constructs.
Definition: cblock.h:52
int cABSDIFFPLUS1(int a1, int a2)
Definition: cnode.h:1340
DelayMode_t
Timing mode values.
Definition: cnode.h:84
vector subrange with descending index select
Definition: cnode_def.h:1158
Helper class for building tail recursive binary CNode trees Used by parser.
Definition: cnode.h:161
reference to parameter
Definition: cnode_def.h:981
double EvalReal(void)
Evaluates expression tree evaluated in a real context.
Definition: cnode.cc:391
CNode * cABSDIFF(CNode *a, CNode *b)
Short cut for creating an subtree that calculates the absolute difference between two expressions...
Definition: cnode.h:850
int operator==(T v)
Definition: cnode.h:133
string HierarchicalReference2String(CNode *ref)
Definition: cnode.h:1200
double s2d(char *s)
Convert char string to double.
Definition: cnode.h:1079
reference to variable
Definition: cnode_def.h:971
CNode * Clone(CObstack *heap=stack)
Replicate tree.
Definition: cnode_def.h:9406