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; }
00217 virtual int IsWidthConstant( void );
00223 virtual int IsWidthVolatile( void );
00228 virtual int IsWidthEvaluateable( void );
00233 virtual INT32 GetWidth( void );
00238 virtual CNode* GetWidthExp( void );
00243 virtual int WidthDirection( void );
00248 virtual INT32 GetMsbInt( void );
00253 virtual CNode* GetMsb();
00254 private:
00259 virtual CNode* GetPackedRange() { return dataType ? dataType->GetPackedRange() : NULL; }
00260 public:
00265 virtual INT32 GetLsbInt( void );
00270 virtual CNode* GetLsb();
00275 virtual INT32 GetNumberOfUnpackedDimensions( void ) {
00276 return numberOfUnpackedDimensions;
00277 }
00283 virtual CNode* GetUnpackedMsi( INT32 dim );
00289 virtual CNode* GetUnpackedLsi( INT32 dim );
00294 virtual void SetNumberOfUnpackedDimensions( INT32 dim ) {
00295 MASSERT( flags & eFLAG_ARRAY );
00296 numberOfUnpackedDimensions = dim;
00297 unpackedRange.reserve( dim );
00298 }
00304 virtual CNode* GetUnpackedRange( INT32 dim ) { return unpackedRange[dim]; }
00310 virtual void SetUnpackedRange( INT32 dim, CNode* v )
00311 { MASSERT(flags & eFLAG_ARRAY); unpackedRange[dim] = v; }
00317 virtual void SetConstAttr( int v ) { constAttr = v; }
00322 virtual int GetConstAttr() { return constAttr; }
00328 virtual void SetVarAttr( int v ) { varAttr = v; }
00333 virtual int GetVarAttr() { return varAttr; }
00339 virtual void SetAutomatic( int v ) { automatic = v; }
00344 virtual int GetAutomatic() { return automatic; }
00349 virtual void SetVectored( int v ) { MASSERT( FALSE ); }
00354 virtual int GetVectored() { MASSERT( FALSE ); return 0; }
00359 virtual void SetScalared( int v ) { MASSERT( FALSE ); }
00364 virtual int GetScalared() { MASSERT( FALSE ); return 0; }
00369 void SetAttributes( CNode* attr ) { attributes = attr; }
00374 CNode* GetAttributes() { return attributes; }
00381 int HasAttribute( char* name, CNode* n=NULL, int init = 1 );
00386 NodeType_t GetNodeType( void );
00391 Decl_t GetClass( void )
00392 {
00393 switch( type ) {
00394 case ePARAM:
00395 case eLOCALPARAM:
00396 return ePARAM;
00397 case eINPUT:
00398 case eOUTPUT:
00399 case eINOUT:
00400 return ePORTDIR;
00401 default:
00402 return type;
00403 }
00404 }
00405
00411 static void GetMembers( Decl_t type, list<Decl_t>& result )
00412 {
00413 switch( type ) {
00414 case ePARAM:
00415 result.push_back( ePARAM );
00416 result.push_back( eLOCALPARAM );
00417 break;
00418 case ePORTDIR:
00419 result.push_back( eINPUT );
00420 result.push_back( eOUTPUT );
00421 result.push_back( eINOUT );
00422 break;
00423 default:
00424 result.push_back( type );
00425 break;
00426 }
00427 }
00428
00434 void SetDeclStatementCreated( void ) { declStatement = TRUE; }
00435
00440 int DeclStatementCreated( void ) { return declStatement; }
00441
00446 Decl_t GetType( void ) { return type; }
00447
00452 void SetCoord( Coord_t* aLoc ) { loc = *aLoc; }
00453
00458 Coord_t* GetCoord( void ) {
00459 return &loc;
00460 }
00461
00466 virtual void Dump( FILE* f )
00467 { fprintf( f, "'%s' line %d", loc.filename , loc.lineno ); }
00468
00473 virtual void DumpDeclInfo( FILE* f )
00474 {
00475 fprintf( f, "%s: %s, defined in '%s' line %d\n",
00476 declName[GetType()], GetName(), loc.filename , loc.lineno );
00477 }
00478
00483 const char* GetName( void ) { return symbol->GetName(); }
00488 void SetSymbol( CSymbol* aSymbol ) { symbol = aSymbol; }
00493 CSymbol* GetSymbol( void ) { return symbol; }
00498 void SetPragmas( CNode* p )
00499 { MASSERT( flags & eFLAG_PRAGMA );pragmas = p; }
00504 CNode* GetPragmas() { return pragmas; }
00505 protected:
00515 CDecl( CSymbol* aSymbol, Coord_t* aLoc,
00516 Decl_t aType, CDataType* dataType, Flag flags ) {
00517 loc = *aLoc;
00518 symbol = aSymbol;
00519 type = aType;
00520 numberOfUnpackedDimensions = 0;
00521 declStatement = FALSE;
00522 attributes = NULL;
00523 pragmas = NULL;
00524 automatic = FALSE;
00525 constAttr = FALSE;
00526 wireAttr = eNO_WIRE_TYPE;
00527 varAttr = FALSE;
00528 this->flags = flags;
00529 this->dataType = dataType;
00530 }
00537 void Copy( CObstack* heap, const CDecl& o );
00543 private:
00544
00545
00546
00547 CDecl( const CDecl& o );
00548
00549 public:
00550 virtual void PreVisit1( int (*func)(CNode*,void*), void* data );
00551 virtual void PostVisit1( void (*func)(CNode*, void*), void* data );
00552 virtual void PostSubVisit1( CNode* (*func)(CNode*, void*), void* data );
00553 };
00554
00555 #endif // CDECL_HPP
00556