00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef CDECL_HPP
00032 #define CDECL_HPP
00033
00034 #include <stdio.h>
00035 #include <vector>
00036 #include <list>
00037 #include "glue.h"
00038 #include "csymbol.h"
00039 #include "csimpletype.h"
00040
00041 class CNode;
00042 class CDecl;
00043
00047 struct Coord_t {
00048 int lineno;
00049 const char* filename;
00050 };
00051
00052
00056 enum Wire_t {
00057 eNO_WIRE_TYPE = 0,
00058 eWIRE,
00059 eTRI,
00060 eWAND,
00061 eTRIAND,
00062 eWOR,
00063 eTRIOR,
00064 eTRI1,
00065 eTRI0,
00066 eTRIREG,
00067 eSUPPLY0,
00068 eSUPPLY1,
00069 };
00070
00074 enum Decl_t {
00075 eVAR = 0,
00076 ePARAM,
00077 eLOCALPARAM,
00078 eBLOCK,
00079 ePARALLELBLOCK,
00080 eGENVARBLOCK,
00081 eMODULE,
00082 eMACRO,
00083 eINSTANCE,
00084 eINPUT,
00085 eOUTPUT,
00086 eINOUT,
00087 ePORT,
00088 eFREF,
00089 eFUNCTION,
00090 eSPECIFYBLOCK,
00091 eGENVAR,
00092
00093 eNET,
00094 ePORTDIR,
00095 eATTR,
00096 eUDP,
00097 eNONE
00098 };
00099
00100 #if defined CDECL_CPP
00101
00104 const char* wireName[] = {
00105 "no_wire_type",
00106 "wire",
00107 "tri",
00108 "wand",
00109 "triand",
00110 "wor",
00111 "trior",
00112 "tri1",
00113 "tri0",
00114 "trireg",
00115 "supply0",
00116 "supply1"
00117 };
00118
00122 const char* declName[] = {
00123 "variable",
00124 "param",
00125 "localparam",
00126 "block",
00127 "parallel block",
00128 "genvar block",
00129 "module",
00130 "macro",
00131 "instance",
00132 "input",
00133 "output",
00134 "inout",
00135 "port",
00136 "fref",
00137 "function",
00138 "specify block",
00139 "genvar",
00140 "net",
00141 "portdir",
00142 "attr",
00143 "upd",
00144 "none"
00145 };
00146 #else
00147 extern char* declName[];
00148 extern char* wireName[];
00149 #endif
00150
00151
00152
00156 class CDecl : public CObject
00157 {
00158 public:
00159 enum Flag {
00160 eFLAG_NONE = 0,
00161 eFLAG_PRAGMA = 1,
00162 eFLAG_ARRAY = 2,
00163 eFLAG_VECTOR = 4
00164 };
00165 static Flag Or( Flag f1, Flag f2 )
00166 { return static_cast<Flag>(((unsigned)f1 | (unsigned)f2)); }
00167 static Flag Or( Flag f1, Flag f2, Flag f3 )
00168 { return static_cast<Flag>(((unsigned)f1 | (unsigned)f2) | (unsigned)f3); }
00169 private:
00170 Coord_t loc;
00171 CSymbol* symbol;
00172 Decl_t type;
00173 int declStatement;
00174
00175 CNode* attributes;
00176 CNode* pragmas;
00177 vector<CNode*> unpackedRange;
00178 int numberOfUnpackedDimensions;
00179 Flag flags;
00180 int automatic;
00181 Wire_t wireAttr;
00182 int constAttr;
00183 int varAttr;
00184 CDataType* dataType;
00185 public:
00191 virtual CDecl* Clone( CObstack* heap ) = 0;
00196 virtual void SetDataType( CDataType* dt ) { dataType = dt; }
00201 virtual CDataType* GetDataType() { return dataType; }
00206 virtual void SetWireAttr( Wire_t v ) { wireAttr = v; }
00211 virtual Wire_t GetWireAttr() { return wireAttr; }
00212 private:
00217 virtual CNode* GetPackedRange() { return dataType ? dataType->GetPackedRange() : NULL; }
00218 public:
00223 virtual CNode* GetMsb();
00228 virtual CNode* GetLsb();
00229
00235 virtual int IsWidthConstant( void );
00241 virtual int IsWidthVolatile( void );
00246 virtual int IsWidthEvaluateable( void );
00251 virtual INT32 GetWidth( void );
00256 virtual CNode* GetWidthExp( void );
00261 virtual int WidthDirection( void );
00266 virtual INT32 GetMsbInt( void );
00271 virtual INT32 GetLsbInt( void );
00272
00273
00278 virtual INT32 GetNumberOfUnpackedDimensions( void ) {
00279 return numberOfUnpackedDimensions;
00280 }
00286 virtual CNode* GetUnpackedMsi( INT32 dim );
00292 virtual CNode* GetUnpackedLsi( INT32 dim );
00297 virtual void SetNumberOfUnpackedDimensions( INT32 dim ) {
00298 MASSERT( flags & eFLAG_ARRAY );
00299 numberOfUnpackedDimensions = dim;
00300 unpackedRange.reserve( dim );
00301 }
00307 virtual CNode* GetUnpackedRange( INT32 dim ) { return unpackedRange[dim]; }
00313 virtual void SetUnpackedRange( INT32 dim, CNode* v )
00314 { MASSERT(flags & eFLAG_ARRAY); unpackedRange[dim] = v; }
00320 virtual void SetConstAttr( int v ) { constAttr = v; }
00325 virtual int GetConstAttr() { return constAttr; }
00331 virtual void SetVarAttr( int v ) { varAttr = v; }
00336 virtual int GetVarAttr() { return varAttr; }
00342 virtual void SetAutomatic( int v ) { automatic = v; }
00347 virtual int GetAutomatic() { return automatic; }
00352 virtual void SetVectored( int v ) { MASSERT( FALSE ); }
00357 virtual int GetVectored() { MASSERT( FALSE ); return 0; }
00362 virtual void SetScalared( int v ) { MASSERT( FALSE ); }
00367 virtual int GetScalared() { MASSERT( FALSE ); return 0; }
00372 void SetAttributes( CNode* attr ) { attributes = attr; }
00377 CNode* GetAttributes() { return attributes; }
00384 int HasAttribute( char* name, CNode* n=NULL, int init = 1 );
00389 NodeType_t GetNodeType( void );
00394 Decl_t GetClass( void )
00395 {
00396 switch( type ) {
00397 case ePARAM:
00398 case eLOCALPARAM:
00399 return ePARAM;
00400 case eINPUT:
00401 case eOUTPUT:
00402 case eINOUT:
00403 return ePORTDIR;
00404 default:
00405 return type;
00406 }
00407 }
00408
00414 static void GetMembers( Decl_t type, list<Decl_t>& result )
00415 {
00416 switch( type ) {
00417 case ePARAM:
00418 result.push_back( ePARAM );
00419 result.push_back( eLOCALPARAM );
00420 break;
00421 case ePORTDIR:
00422 result.push_back( eINPUT );
00423 result.push_back( eOUTPUT );
00424 result.push_back( eINOUT );
00425 break;
00426 default:
00427 result.push_back( type );
00428 break;
00429 }
00430 }
00431
00437 void SetDeclStatementCreated( void ) { declStatement = TRUE; }
00438
00443 int DeclStatementCreated( void ) { return declStatement; }
00444
00449 Decl_t GetType( void ) { return type; }
00450
00455 void SetCoord( Coord_t* aLoc ) { loc = *aLoc; }
00456
00461 Coord_t* GetCoord( void ) {
00462 return &loc;
00463 }
00464
00469 virtual void Dump( FILE* f )
00470 { fprintf( f, "'%s' line %d", loc.filename , loc.lineno ); }
00471
00476 virtual void DumpDeclInfo( FILE* f )
00477 {
00478 fprintf( f, "%s: %s, defined in '%s' line %d\n",
00479 declName[GetType()], GetName(), loc.filename , loc.lineno );
00480 }
00481
00486 const char* GetName( void ) { return symbol->GetName(); }
00491 void SetSymbol( CSymbol* aSymbol ) { symbol = aSymbol; }
00496 CSymbol* GetSymbol( void ) { return symbol; }
00501 void SetPragmas( CNode* p )
00502 { MASSERT( flags & eFLAG_PRAGMA );pragmas = p; }
00507 CNode* GetPragmas() { return pragmas; }
00508 protected:
00518 CDecl( CSymbol* aSymbol, Coord_t* aLoc,
00519 Decl_t aType, CDataType* dataType, Flag flags ) {
00520 loc = *aLoc;
00521 symbol = aSymbol;
00522 type = aType;
00523 numberOfUnpackedDimensions = 0;
00524 declStatement = FALSE;
00525 attributes = NULL;
00526 pragmas = NULL;
00527 automatic = FALSE;
00528 constAttr = FALSE;
00529 wireAttr = eNO_WIRE_TYPE;
00530 varAttr = FALSE;
00531 this->flags = flags;
00532 this->dataType = dataType;
00533 }
00540 void Copy( CObstack* heap, const CDecl& o );
00546 private:
00547
00548
00549
00550 CDecl( const CDecl& o );
00551
00552 public:
00553 virtual void PreVisit1( int (*func)(CNode*,void*), void* data );
00554 virtual void PostVisit1( void (*func)(CNode*, void*), void* data );
00555 virtual void PostSubVisit1( CNode* (*func)(CNode*, void*), void* data );
00556 };
00557
00558 #endif // CDECL_HPP
00559