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 eNODIR,
00088 ePORT,
00089 eFREF,
00090 eFUNCTION,
00091 eSPECIFYBLOCK,
00092 eGENVAR,
00093 eTYPEDEF,
00094
00095 eNET,
00096 ePORTDIR,
00097 eATTR,
00098 eUDP,
00099 eENUMVALUE,
00100 eNONE
00101 };
00102
00103 #if defined CDECL_CPP
00104
00107 const char* wireName[] = {
00108 "no_wire_type",
00109 "wire",
00110 "tri",
00111 "wand",
00112 "triand",
00113 "wor",
00114 "trior",
00115 "tri1",
00116 "tri0",
00117 "trireg",
00118 "supply0",
00119 "supply1"
00120 };
00121
00125 const char* declName[] = {
00126 "variable",
00127 "param",
00128 "localparam",
00129 "block",
00130 "parallel block",
00131 "genvar block",
00132 "module",
00133 "macro",
00134 "instance",
00135 "input",
00136 "output",
00137 "inout",
00138 "nodir",
00139 "port",
00140 "fref",
00141 "function",
00142 "specify block",
00143 "genvar",
00144 "typedef",
00145 "net",
00146 "portdir",
00147 "attr",
00148 "udp",
00149 "enum",
00150 "none"
00151 };
00152 #else
00153 extern char* declName[];
00154 extern char* wireName[];
00155 #endif
00156
00157
00158
00162 class CDecl : public CObject
00163 {
00164 public:
00165 enum Flag {
00166 eFLAG_NONE = 0,
00167 eFLAG_PRAGMA = 1,
00168 eFLAG_ARRAY = 2,
00169 eFLAG_DATATYPE = 4
00170 };
00171 static Flag Or( Flag f1, Flag f2 )
00172 { return static_cast<Flag>(((unsigned)f1 | (unsigned)f2)); }
00173 static Flag Or( Flag f1, Flag f2, Flag f3 )
00174 { return static_cast<Flag>(((unsigned)f1 | (unsigned)f2) | (unsigned)f3); }
00175 private:
00176 Coord_t loc;
00177 CSymbol* symbol;
00178 Decl_t type;
00179 int declStatement;
00180
00181 CNode* attributes;
00182 CNode* pragmas;
00183 vector<CNode*> unpackedRange;
00184
00185 int numberOfUnpackedDimensions;
00186 Flag flags;
00187 int automatic;
00188 Wire_t wireAttr;
00189 int constAttr;
00190 int varAttr;
00191 CDataType* dataType;
00192 public:
00198 virtual CDecl* Clone( CObstack* heap ) = 0;
00203 virtual void SetDataType( CDataType* dt ) {
00204 MASSERT( flags & eFLAG_DATATYPE );
00205 dataType = dt;
00206 }
00211 virtual CDataType* GetDataType() { return dataType; }
00216 virtual void SetWireAttr( Wire_t v ) { wireAttr = v; }
00221 virtual Wire_t GetWireAttr() { return wireAttr; }
00227 virtual int IsWidthConstant( void ) const {
00228 if( numberOfUnpackedDimensions ) {
00229 return FALSE;
00230 }
00231 MASSERT( dataType );
00232 return dataType->IsPackedWidthConstant();
00233 }
00239 virtual int IsWidthVolatile( void ) const {
00240 if( numberOfUnpackedDimensions ) {
00241 return TRUE;
00242 }
00243 MASSERT( dataType );
00244 return dataType->IsPackedWidthVolatile();
00245 }
00250 virtual int IsWidthEvaluateable( void ) const {
00251 if( numberOfUnpackedDimensions ) {
00252 return FALSE;
00253 }
00254 MASSERT( dataType );
00255 return dataType->IsPackedWidthEvaluateable();
00256 }
00261 virtual INT32 GetWidth( void ) const {
00262 if( numberOfUnpackedDimensions ) {
00263 return 0;
00264 }
00265 MASSERT( dataType );
00266 return dataType->GetPackedWidth();
00267 }
00272 virtual CNode* GetWidthExp( void ) const {
00273 if( numberOfUnpackedDimensions ) {
00274 return NULL;
00275 }
00276 MASSERT( dataType );
00277 return dataType->GetPackedWidthExp();
00278 }
00283 virtual CNode* GetMsb() const {
00284 MASSERT( dataType );
00285 return dataType->GetPackedMsb();
00286 }
00291 virtual CNode* GetLsb() const {
00292 MASSERT( dataType );
00293 return dataType->GetPackedLsb();
00294 }
00299 virtual int WidthDirection( void ) const {
00300 MASSERT( dataType );
00301 return dataType->PackedWidthDirection();
00302 }
00307 virtual INT32 GetNumberOfUnpackedDimensions( void ) {
00308 return numberOfUnpackedDimensions;
00309 }
00315 virtual CNode* GetUnpackedMsi( INT32 dim );
00321 virtual CNode* GetUnpackedLsi( INT32 dim );
00326 virtual void SetNumberOfUnpackedDimensions( INT32 dim ) {
00327 MASSERT( flags & eFLAG_ARRAY );
00328 numberOfUnpackedDimensions = dim;
00329 unpackedRange.reserve( dim );
00330 }
00336 virtual CNode* GetUnpackedRange( INT32 dim ) { return unpackedRange[dim]; }
00342 virtual void SetUnpackedRange( INT32 dim, CNode* v )
00343 { MASSERT(flags & eFLAG_ARRAY); unpackedRange[dim] = v; }
00349 virtual void SetConstAttr( int v ) { constAttr = v; }
00354 virtual int GetConstAttr() { return constAttr; }
00360 virtual void SetVarAttr( int v ) { varAttr = v; }
00365 virtual int GetVarAttr() { return varAttr; }
00371 virtual void SetAutomatic( int v ) { automatic = v; }
00376 virtual int GetAutomatic() { return automatic; }
00381 virtual void SetVectored( int v ) { MASSERT( FALSE ); }
00386 virtual int GetVectored() { MASSERT( FALSE ); return 0; }
00391 virtual void SetScalared( int v ) { MASSERT( FALSE ); }
00396 virtual int GetScalared() { MASSERT( FALSE ); return 0; }
00401 void SetAttributes( CNode* attr ) { attributes = attr; }
00406 CNode* GetAttributes() { return attributes; }
00413 int HasAttribute( char* name, CNode* n=NULL, int init = 1 );
00418 NodeType_t GetNodeType( void ) {
00419 MASSERT( dataType );
00420 return dataType->GetNodeType();
00421 }
00426 Decl_t GetClass( void )
00427 {
00428 switch( type ) {
00429 case ePARAM:
00430 case eLOCALPARAM:
00431 return ePARAM;
00432 case eINPUT:
00433 case eOUTPUT:
00434 case eINOUT:
00435 return ePORTDIR;
00436 default:
00437 return type;
00438 }
00439 }
00440
00446 static void GetMembers( Decl_t type, list<Decl_t>& result )
00447 {
00448 switch( type ) {
00449 case ePARAM:
00450 result.push_back( ePARAM );
00451 result.push_back( eLOCALPARAM );
00452 break;
00453 case ePORTDIR:
00454 result.push_back( eINPUT );
00455 result.push_back( eOUTPUT );
00456 result.push_back( eINOUT );
00457 break;
00458 default:
00459 result.push_back( type );
00460 break;
00461 }
00462 }
00463
00469 void SetDeclStatementCreated( void ) { declStatement = TRUE; }
00470
00475 int DeclStatementCreated( void ) { return declStatement; }
00476
00481 Decl_t GetType( void ) { return type; }
00482
00487 void SetCoord( Coord_t* aLoc ) { loc = *aLoc; }
00488
00493 Coord_t* GetCoord( void ) {
00494 return &loc;
00495 }
00496
00501 virtual void Dump( FILE* f )
00502 { fprintf( f, "'%s' line %d", loc.filename , loc.lineno ); }
00503
00508 virtual void DumpDeclInfo( FILE* f )
00509 {
00510 fprintf( f, "%s: %s, defined in '%s' line %d\n",
00511 declName[GetType()], GetName(), loc.filename , loc.lineno );
00512 }
00513
00518 const char* GetName( void ) { return symbol->GetName(); }
00523 void SetSymbol( CSymbol* aSymbol ) { symbol = aSymbol; }
00528 CSymbol* GetSymbol( void ) { return symbol; }
00533 void SetPragmas( CNode* p )
00534 { MASSERT( flags & eFLAG_PRAGMA );pragmas = p; }
00539 CNode* GetPragmas() { return pragmas; }
00540 protected:
00550 CDecl( CSymbol* aSymbol, Coord_t* aLoc,
00551 Decl_t aType, CDataType* dataType, Flag flags ) {
00552 loc = *aLoc;
00553 symbol = aSymbol;
00554 type = aType;
00555 numberOfUnpackedDimensions = 0;
00556 declStatement = FALSE;
00557 attributes = NULL;
00558 pragmas = NULL;
00559 automatic = FALSE;
00560 constAttr = FALSE;
00561 wireAttr = eNO_WIRE_TYPE;
00562 varAttr = FALSE;
00563 this->flags = flags;
00564 this->dataType = dataType;
00565 }
00572 void Copy( CObstack* heap, const CDecl& o );
00578 private:
00579
00580
00581
00582 CDecl( const CDecl& o );
00583
00584 public:
00585 virtual void PreVisit1( int (*func)(CNode*,void*), void* data );
00586 virtual void PostVisit1( void (*func)(CNode*, void*), void* data );
00587 virtual void PostSubVisit1( CNode* (*func)(CNode*, void*), void* data );
00588 };
00589
00590 #endif // CDECL_HPP
00591