141 operator T() {
return *ptr; }
200 static list<CObstack*> stackList;
202 static INT32 evalCount;
204 static map<CNode*,int> labelCache;
205 static int labelCacheEnabled;
220 int LabelBits(
int supressErrorMessages = FALSE );
222 void _EvalVector(
CVector& v );
223 double _EvalReal(
void );
224 void FixedWidth(
int v ) { fixedWidth = v; }
225 int FixedWidth() {
return fixedWidth; }
226 int ConditionalWiden();
229 CNode* GetNLeft(
void ) {
return (
CNode*)left; }
230 CNode* GetNRight(
void ) {
return (
CNode*)right; }
231 static void _LabelBits(
CNode* n,
void* arg );
248 stackList.push_front( stack );
257 MASSERT( evalCount == 0 );
258 stackList.push_front( stack );
265 if( stack == &evalHeap ) {
267 if( evalCount == 0 ) {
268 evalHeap.
Free( NULL );
271 if( stackList.empty() ) {
274 stack = *stackList.begin();
275 stackList.pop_front();
289 labelCacheEnabled = 1;
297 labelCacheEnabled = 0;
298 labelCache.erase( labelCache.begin(), labelCache.end() );
330 int oldCount = ArgCount();
332 MASSERT( oldCount == ArgCount() );
350 int ArgCount(
void );
370 void PostVisit1(
void (*callback)(
CNode*,
void*),
void* data );
388 void PreVisit1(
int (*callback)(
CNode*,
void*),
void* data );
407 int IsNonX(
int integerIsNonX = 0,
char* exclude = NULL );
423 int IsEvaluateable();
429 int IsVolatile(
void );
456 double EvalReal(
void );
461 void Dump( FILE* f );
467 int IsWidthConstant(
void );
473 int IsWidthVolatile(
void );
483 int IsWidthEvaluateable(
void );
488 CNode* GetWidthExp(
void );
499 int IsScalar(
void ) { LabelBits(TRUE);
return width==1; }
504 int IsVector(
void ) { LabelBits(TRUE);
return width>1; }
509 int IsReal(
void ) { LabelBits(TRUE);
return type==
eR; }
527 int HasAttribute(
const char* name,
CNode* n=NULL,
int init = 1 );
535 CAttr* GetAttribute(
const char* name,
CNode* n=NULL,
int init = 1 );
551 switch( ArgCount() ) {
601 return CNode_sp<T>(&GetNLeft()->GetNLeft()->right);
617 return CNode_sp<T>(&GetNLeft()->GetNLeft()->right);
619 return CNode_sp<T>(&GetNLeft()->GetNRight()->left);
621 return CNode_sp<T>(&GetNLeft()->GetNRight()->right);
635 return CNode_sp<T>(&GetNLeft()->GetNLeft()->right);
637 return CNode_sp<T>(&GetNLeft()->GetNRight()->left);
639 return CNode_sp<T>(&GetNLeft()->GetNRight()->right);
641 return CNode_sp<T>(&GetNRight()->GetNLeft()->left);
643 return CNode_sp<T>(&GetNRight()->GetNLeft()->right);
655 return CNode_sp<T>(&GetNLeft()->GetNLeft()->right);
657 return CNode_sp<T>(&GetNLeft()->GetNRight()->left);
659 return CNode_sp<T>(&GetNLeft()->GetNRight()->right);
661 return CNode_sp<T>(&GetNRight()->GetNLeft()->left);
663 return CNode_sp<T>(&GetNRight()->GetNLeft()->right);
665 return CNode_sp<T>(&GetNRight()->GetNRight()->left);
667 return CNode_sp<T>(&GetNRight()->GetNRight()->right);
682 inline void Add(
double* r,
double* a,
double* b )
687 inline void Sub(
double* r,
double* a,
double* b )
692 inline void Mul(
double* r,
double* a,
double* b )
697 inline void Div(
double* r,
double* a,
double* b )
702 inline void Neg(
double* r,
double* a )
707 inline void Plus(
double* r,
double* a )
712 inline void Pow(
double* r,
double* a,
double* b )
721 #define ILLEGAL_OP2(op) \ 722 inline void op( double*, double*, double* )\ 723 { fatal( NULL, #op " is illegal for reals" ); } 725 #define ILLEGAL_OP1(op) \ 726 inline void op( double*, double* )\ 727 { fatal( NULL, #op " is illegal for reals" ); } 748 #define DEFINE_CONSTRUCTOR 750 #undef DEFINE_CONSTRUCTOR 781 int len = strlen( s );
835 }
else if( n2 == NULL ) {
881 }
else if( n2 == NULL ) {
884 return cLIST( n1, n2 );
898 return cHOOK(cond,n1,n2);
919 int argNumber, vector<T>& v)
924 switch( n->
GetOp() ) {
926 ArgList2Vector<T>(n->
Arg<
CNode*>(0),op,argNumber,v);
927 ArgList2Vector<T>(n->
Arg<
CNode*>(1),op,argNumber,v);
930 if( n->
GetOp() == op ) {
931 v.push_back(n->
Arg<T>(argNumber));
950 switch( n->
GetOp() ) {
956 if( excludeOps.find(n->
GetOp()) == excludeOps.end() ) {
976 switch( n->
GetOp() ) {
982 if( excludeOps.find(n->
GetOp()) == excludeOps.end() ) {
997 CNode* result = NULL;
998 vector<CNode*>::const_reverse_iterator ptr;
999 for( ptr = v.rbegin(); ptr != v.rend(); ++ptr ) {
1001 result =
cELIST(*ptr, result);
1017 CNode* result = NULL;
1018 list<CNode*>::reverse_iterator ptr;
1019 for( ptr = v.rbegin(); ptr != v.rend(); ++ptr ) {
1021 result =
cELIST(*ptr, result);
1043 switch( n->
GetOp() ) {
1050 if( n->
GetOp() == op ) {
1070 switch( n->
GetOp() ) {
1093 inline double s2d(
char* s ) {
1109 snprintf( buffer,
sizeof(buffer),
"%g", d );
1110 char* s = (
char*)heap->
Alloc(strlen(buffer)+1);
1111 strcpy( s, buffer );
1127 CNode* parent = NULL;
1176 *count = count0+count1;
1177 *depth = depth0 > depth1 ? depth0 : depth1;
1191 }
else if( !pr1.
tail ) {
1217 switch( ref->
GetOp() ) {
1220 vector<CNode*> indexes;
1222 set<NodeOp_t>(), indexes );
1223 vector<CNode*>::iterator ptr;
1224 for( ptr = indexes.begin(); ptr != indexes.end(); ++ptr ) {
1231 INT32 value = (*ptr)->EvalINT32();
1232 ostringstream subscript;
1233 subscript <<
'[' << value <<
']';
1234 buffer += subscript.str();
1254 buffer = ref->
Arg<
CDecl*>(0)->GetName();
1268 CNode* result = first;
1270 va_start( ap, first );
1277 result =
cMAX( result, arg );
1286 CNode* result = first;
1288 va_start( ap, first );
1294 result =
cADD( result, arg );
1302 CNode* result = first;
1304 va_start( ap, first );
1310 result =
cMUL( result, arg );
1319 va_start( ap, first );
1324 MASSERT( va_arg(ap,
CNode*) == NULL );
1336 return a1 < a2 ? a2 : a1;
1339 inline int cMAX(
int a1,
int a2,
int a3 )
1357 return (diff < 0 ? -diff : diff)+1;
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:945
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:2925
static void DisableAndClearLabelCache()
Disable caching of label info (width and type) and clear all accumulated data.
Definition: cnode.h:295
real constant
Definition: cnode_def.h:666
vector subrange with ascending index select
Definition: cnode_def.h:1165
int cMUL(int a1, int a2)
Definition: cnode.h:1349
static void UseEvalStack(void)
Use evaluation stack.
Definition: cnode.h:247
int Equivalent(CNode *a, CNode *b)
Definition: cnode_def.h:12289
Smart pointer for CNode class Creates safe references to CNode arguments Supports assignment...
Definition: cnode.h:134
CNode * operator->()
Definition: cnode.h:157
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:2834
CNode * RebalanceRight(CNode *n)
Definition: cnode.h:1119
Gate declaration object.
Definition: cgate.h:42
T * Ptr()
Definition: cnode.h:140
int IsScalar(void)
Determine if expression is a 1 bit signed or unsigned value.
Definition: cnode.h:499
CNode * cREAL(double number)
Short cut for creating RCONSTANT node with a given double value.
Definition: cnode.h:817
static void EnableLabelCache()
Enable cache of labeled nodes to be tracked.
Definition: cnode.h:287
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:1037
void Add(double *r, double *a, double *b)
Definition: cnode.h:682
int cADD(int a1, int a2)
Definition: cnode.h:1344
Declaration object for specify blocks.
Definition: cspecify.h:47
CNode * cMAX_N(CNode *first,...)
Definition: cnode.h:1266
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:1105
CNode * second
Definition: cnode.h:172
void Neg(double *r, double *a)
Definition: cnode.h:702
list of nodes
Definition: cnode_def.h:1132
vector constant
Definition: cnode_def.h:656
CNode * cSTRING(const char *s)
Short cut for creating VCONSTANT node with a given string value.
Definition: cnode.h:779
Coord_t * GetCoord()
Get node's file coordinates.
Definition: cnode.h:312
CNode * cMUL_N(CNode *first,...)
Definition: cnode.h:1300
static CObstack * CurrentHeap()
Gets pointer to current heap allocator.
Definition: cnode.h:237
CNode * List2EList(list< CNode *> &v)
Converts a list of CNode* into a linked ELIST of the elements.
Definition: cnode.h:1015
CBlock CScope
Definition: cnode.h:65
CNode * cNEG(CNode *a0, Coord_t *loc=NULL)
Node construction shortcut for NEG negation.
Definition: cnode_def.h:4436
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:918
void MeasureDepth(CNode *n, int *count, int *depth)
Definition: cnode.h:1157
long INT32
Short cut for signed 32 bit integer.
Definition: glue.h:38
int IsReal(void)
Determine if expression is real.
Definition: cnode.h:509
CNode_sp< T > Arg(int index)
Get a node's operand.
Definition: cnode.h:549
Edge_t
Edge values.
Definition: cnode.h:72
reference to port
Definition: cnode_def.h:1009
void * Alloc(INT32 size)
Allocate block of storage with given size.
reference to a forward declared variable
Definition: cnode_def.h:1019
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:162
int operator!=(CNode_sp< T > p)
Definition: cnode.h:145
CNode * operator=(CNode *n)
Definition: cnode.h:156
CNode * cHOOK(CNode *a0, CNode *a1, CNode *a2, Coord_t *loc=NULL)
Node construction shortcut for HOOK condition expression operator.
Definition: cnode_def.h:5029
T operator=(T n)
Definition: cnode.h:138
static void ResetBuildStack(void)
Restore previous heap.
Definition: cnode.h:264
reference to a genvar
Definition: cnode_def.h:1029
CNode * third
Definition: cnode.h:173
Helper class for building tail recursive binary CNode trees Used by parser.
Definition: cnode.h:152
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:171
Forward reference declaration.
Definition: cfref.h:51
Bulk object allocation object.
Definition: cobstack.h:46
CNode * cABSDIFFPLUS1_N(CNode *first,...)
Definition: cnode.h:1316
reference to net
Definition: cnode_def.h:979
Strength_t
Strength values.
Definition: cnode.h:93
Primary data structure representing parse tree nodes.
Definition: cnode.h:197
int operator==(CNode_sp< T > p)
Definition: cnode.h:144
NodeOp_t
Parse tree opcodes.
Definition: cnode_def.h:637
CNode * cLINK(CNode *n1, CNode *n2)
Short cut for linking together to nodes with a LIST operator.
Definition: cnode.h:877
CNode * cELINK(CNode *n1, CNode *n2)
Link together two nodes with an ELIST operator.
Definition: cnode.h:831
Declaration object for module and gate instances.
Definition: cinstance.h:45
expression list
Definition: cnode_def.h:708
CNode * head
Definition: cnode.h:153
void Pow(double *r, double *a, double *b)
Definition: cnode.h:712
member reference (structure, class or external
Definition: cnode_def.h:2242
void SetAttributes(CNode *attr)
Attach attributes to operation.
Definition: cnode.h:519
CNode_sp(void **np)
Pointer to untyped argument.
Definition: cnode.h:137
static void SetBuildStack(CObstack *aStack)
Set heap to a specific heap.
Definition: cnode.h:256
int operator!=(T v)
Definition: cnode.h:143
CNode * cVECTOR(CVector &vec)
Short cut for creating VCONSTANT node with a given vector value.
Definition: cnode.h:762
void Div(double *r, double *a, double *b)
Definition: cnode.h:697
Definitions for parse tree nodes.
void SetOp(NodeOp_t aOp)
Set node's operation type.
Definition: cnode.h:329
Base class for describing declaration objects.
Definition: cdecl.h:164
CNode * tail
Definition: cnode.h:154
int IsVector(void)
Determine if expression is a multi-bit signed or unsigned value.
Definition: cnode.h:504
CNode * Vector2EList(const vector< CNode *> &v)
Converts a vector array of CNode* into a linked ELIST of the elements.
Definition: cnode.h:995
void Sub(double *r, double *a, double *b)
Definition: cnode.h:687
int operator==(CNode_pr p)
Definition: cnode.h:161
int Sized()
Get sized attribute.
Definition: cvector.h:143
Declaration object for variables.
Definition: cvar.h:50
external reference
Definition: cnode_def.h:2022
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:798
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:4557
INT32 GetWidth(void)
Evaluate width of expression.
Definition: cnode.h:494
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:4590
void Mul(double *r, double *a, double *b)
Definition: cnode.h:692
NodeType_t GetNodeType(void)
Get node expression type.
Definition: cnode.h:540
int GetPreferredBase()
Get preferred base for printing value.
Definition: cvector.h:137
void Plus(double *r, double *a)
Definition: cnode.h:707
int operator!=(CNode *v)
Definition: cnode.h:160
INT32 GetWidth(void)
Get vector bit width.
vector subrange
Definition: cnode_def.h:1154
real - have width 0
Definition: cdatatype.h:103
Declaration object for functions and tasks.
Definition: cfunction.h:50
int operator==(CNode *v)
Definition: cnode.h:159
CNode * cLIST(CNode *a0, CNode *a1, Coord_t *loc=NULL)
Node construction shortcut for LIST list of nodes.
Definition: cnode_def.h:4090
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:895
T operator->()
Definition: cnode.h:139
CNode * cADD_N(CNode *first,...)
Definition: cnode.h:1284
CNode * cABS(CNode *a)
Short cut for creating an subtree that calculates the absolute value of an expression.
Definition: cnode.h:848
Strength_t s0
Definition: cnode.h:109
NodeType_t
Expression node type.
Definition: cdatatype.h:101
const char * GetOpName()
Return node's operation type as a string.
Definition: cnode.h:322
void Free(void *object)
Free all storage including and after object.
CNode * GetAttributes()
Get attributes attached to operation.
Definition: cnode.h:514
const char * nodeOpName[]
Definition: cnode_def.h:2328
dimensioned reference (array/bit select)
Definition: cnode_def.h:969
NodeOp_t GetOp()
Return node's operation type.
Definition: cnode.h:317
Declaration class for block constructs.
Definition: cblock.h:52
int cABSDIFFPLUS1(int a1, int a2)
Definition: cnode.h:1354
DelayMode_t
Timing mode values.
Definition: cnode.h:84
vector subrange with descending index select
Definition: cnode_def.h:1176
int Signed() const
Get signed attribute.
Definition: cvector.h:178
Helper class for building tail recursive binary CNode trees Used by parser.
Definition: cnode.h:170
reference to parameter
Definition: cnode_def.h:999
CNode * cABSDIFF(CNode *a, CNode *b)
Short cut for creating an subtree that calculates the absolute difference between two expressions...
Definition: cnode.h:864
ConditionalType
Case/If type.
Definition: cnode.h:116
int operator==(T v)
Definition: cnode.h:142
string HierarchicalReference2String(CNode *ref)
Definition: cnode.h:1214
double s2d(char *s)
Convert char string to double.
Definition: cnode.h:1093
reference to variable
Definition: cnode_def.h:989
CNode * Clone(CObstack *heap=stack)
Replicate tree.
Definition: cnode_def.h:9632
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:971