vrq
cdecl.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 1997-2007, Mark Hummel
3  * This file is part of Vrq.
4  *
5  * Vrq is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * Vrq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301 USA
19  *****************************************************************************
20  */
21 /******************************************************************************
22  *
23  *
24  * cdecl.hpp
25  * - abstract class for declaration
26  *
27  *
28  ******************************************************************************
29  */
30 
31 #ifndef CDECL_HPP
32 #define CDECL_HPP
33 
34 #include <stdio.h>
35 #include <vector>
36 #include <list>
37 #include "glue.h"
38 #include "csymbol.h"
39 #include "csimpletype.h"
40 
41 class CNode;
42 class CDecl;
43 
47 struct Coord_t {
48  int lineno;
49  const char* filename;
50 };
51 
52 
56 enum Wire_t {
59  eTRI,
62  eWOR,
69 };
70 
74 enum Decl_t {
75  eVAR = 0,
94  // NOTE this are class types only
95  eNET,
98  eUDP,
102 };
103 
104 #if defined CDECL_CPP
105 
108 const char* wireName[] = {
109  "no_wire_type",
110  "wire",
111  "tri",
112  "wand",
113  "triand",
114  "wor",
115  "trior",
116  "tri1",
117  "tri0",
118  "trireg",
119  "supply0",
120  "supply1"
121 };
122 
126 const char* declName[] = {
127  "variable",
128  "param",
129  "localparam",
130  "block",
131  "parallel block",
132  "genvar block",
133  "module",
134  "macro",
135  "instance",
136  "input",
137  "output",
138  "inout",
139  "nodir",
140  "port",
141  "fref",
142  "function",
143  "specify block",
144  "genvar",
145  "typedef",
146  "net",
147  "portdir",
148  "attr",
149  "udp",
150  "enum",
151  "package",
152  "none"
153 };
154 #else
155 extern char* declName[];
156 extern char* wireName[];
157 #endif
158 
159 
160 
164 class CDecl : public CObject
165 {
166 public:
167  enum Flag {
172  };
173  static Flag Or( Flag f1, Flag f2 )
174  { return static_cast<Flag>(((unsigned)f1 | (unsigned)f2)); }
175  static Flag Or( Flag f1, Flag f2, Flag f3 )
176  { return static_cast<Flag>(((unsigned)f1 | (unsigned)f2) | (unsigned)f3); }
177 private:
178  Coord_t loc;
179  CSymbol* symbol;
180  Decl_t type;
181  int declStatement;
182  CNode* attributes;
184  CNode* pragmas;
185  vector<CNode*> unpackedRange;
186  int numberOfUnpackedDimensions;
188  Flag flags;
189  int automatic;
190  Wire_t wireAttr;
191  int constAttr;
192  int varAttr;
193  CDataType* dataType;
194 public:
200  virtual CDecl* Clone( CObstack* heap ) = 0;
205  virtual void SetDataType( CDataType* dt ) {
206  MASSERT( flags & eFLAG_DATATYPE );
207  dataType = dt;
208  }
213  virtual CDataType* GetDataType() { return dataType; }
218  virtual void SetWireAttr( Wire_t v ) { wireAttr = v; }
223  virtual Wire_t GetWireAttr() { return wireAttr; }
229  virtual int IsWidthConstant( void ) const {
230  if( numberOfUnpackedDimensions ) {
231  return FALSE;
232  }
233  MASSERT( dataType );
234  return dataType->IsPackedWidthConstant();
235  }
241  virtual int IsWidthVolatile( void ) const {
242  if( numberOfUnpackedDimensions ) {
243  return TRUE;
244  }
245  MASSERT( dataType );
246  return dataType->IsPackedWidthVolatile();
247  }
252  virtual int IsWidthEvaluateable( void ) const {
253  if( numberOfUnpackedDimensions ) {
254  return FALSE;
255  }
256  MASSERT( dataType );
257  return dataType->IsPackedWidthEvaluateable();
258  }
263  virtual INT32 GetWidth( void ) const {
264  if( numberOfUnpackedDimensions ) {
265  return 0;
266  }
267  MASSERT( dataType );
268  return dataType->GetPackedWidth();
269  }
274  virtual CNode* GetWidthExp( void ) const {
275  if( numberOfUnpackedDimensions ) {
276  return NULL;
277  }
278  MASSERT( dataType );
279  return dataType->GetPackedWidthExp();
280  }
285  virtual CNode* GetMsb() const {
286  MASSERT( dataType );
287  return dataType->GetPackedMsb();
288  }
293  virtual CNode* GetLsb() const {
294  MASSERT( dataType );
295  return dataType->GetPackedLsb();
296  }
301  virtual int WidthDirection( void ) const {
302  MASSERT( dataType );
303  return dataType->PackedWidthDirection();
304  }
310  return numberOfUnpackedDimensions;
311  }
317  virtual CNode* GetUnpackedMsi( INT32 dim );
323  virtual CNode* GetUnpackedLsi( INT32 dim );
328  virtual void SetNumberOfUnpackedDimensions( INT32 dim ) {
329  MASSERT( flags & eFLAG_ARRAY );
330  numberOfUnpackedDimensions = dim;
331  unpackedRange.reserve( dim );
332  }
338  virtual CNode* GetUnpackedRange( INT32 dim ) { return unpackedRange[dim]; }
344  virtual void SetUnpackedRange( INT32 dim, CNode* v )
345  { MASSERT(flags & eFLAG_ARRAY); unpackedRange[dim] = v; }
351  virtual void SetConstAttr( int v ) { constAttr = v; }
356  virtual int GetConstAttr() { return constAttr; }
362  virtual void SetVarAttr( int v ) { varAttr = v; }
367  virtual int GetVarAttr() { return varAttr; }
373  virtual void SetAutomatic( int v ) { automatic = v; }
378  virtual int GetAutomatic() { return automatic; }
383  virtual void SetVectored( int v ) { MASSERT( FALSE ); }
388  virtual int GetVectored() { MASSERT( FALSE ); return 0; }
393  virtual void SetScalared( int v ) { MASSERT( FALSE ); }
398  virtual int GetScalared() { MASSERT( FALSE ); return 0; }
403  void SetAttributes( CNode* attr ) { attributes = attr; }
408  CNode* GetAttributes() { return attributes; }
415  int HasAttribute( char* name, CNode* n=NULL, int init = 1 );
421  MASSERT( dataType );
422  return dataType->GetNodeType();
423  }
428  Decl_t GetClass( void )
429  {
430  switch( type ) {
431  case ePARAM:
432  case eLOCALPARAM:
433  return ePARAM;
434  case eINPUT:
435  case eOUTPUT:
436  case eINOUT:
437  return ePORTDIR;
438  default:
439  return type;
440  }
441  }
442 
448  static void GetMembers( Decl_t type, list<Decl_t>& result )
449  {
450  switch( type ) {
451  case ePARAM:
452  result.push_back( ePARAM );
453  result.push_back( eLOCALPARAM );
454  break;
455  case ePORTDIR:
456  result.push_back( eINPUT );
457  result.push_back( eOUTPUT );
458  result.push_back( eINOUT );
459  break;
460  default:
461  result.push_back( type );
462  break;
463  }
464  }
465 
471  void SetDeclStatementCreated( void ) { declStatement = TRUE; }
472 
477  int DeclStatementCreated( void ) { return declStatement; }
478 
483  Decl_t GetType( void ) { return type; }
484 
489  void SetCoord( Coord_t* aLoc ) { loc = *aLoc; }
490 
495  Coord_t* GetCoord( void ) {
496  return &loc;
497  }
498 
503  virtual void Dump( FILE* f )
504  { fprintf( f, "'%s' line %d", loc.filename , loc.lineno ); }
505 
510  virtual void DumpDeclInfo( FILE* f )
511  {
512  fprintf( f, "%s: %s, defined in '%s' line %d\n",
513  declName[GetType()], GetName(), loc.filename , loc.lineno );
514  }
515 
520  const char* GetName( void ) { return symbol->GetName(); }
525  void SetSymbol( CSymbol* aSymbol ) { symbol = aSymbol; }
530  CSymbol* GetSymbol( void ) { return symbol; }
535  void SetPragmas( CNode* p )
536  { MASSERT( flags & eFLAG_PRAGMA );pragmas = p; }
541  CNode* GetPragmas() { return pragmas; }
542 protected:
552  CDecl( CSymbol* aSymbol, Coord_t* aLoc,
553  Decl_t aType, CDataType* dataType, Flag flags ) {
554  loc = *aLoc;
555  symbol = aSymbol;
556  type = aType;
557  numberOfUnpackedDimensions = 0;
558  declStatement = FALSE;
559  attributes = NULL;
560  pragmas = NULL;
561  automatic = FALSE;
562  constAttr = FALSE;
563  wireAttr = eNO_WIRE_TYPE;
564  varAttr = FALSE;
565  this->flags = flags;
566  this->dataType = dataType;
567  }
574  void Copy( CObstack* heap, const CDecl& o );
580 private:
581  /*
582  * disable copy constructor
583  */
584  CDecl( const CDecl& o );
585 
586 public:
587  virtual void PreVisit1( int (*func)(CNode*,void*), void* data );
588  virtual void PostVisit1( void (*func)(CNode*, void*), void* data );
589  virtual void PostSubVisit1( CNode* (*func)(CNode*, void*), void* data );
590 };
591 
592 #endif // CDECL_HPP
593 
virtual int GetVarAttr()
Get declaration's var attribute.
Definition: cdecl.h:367
Decl_t GetType(void)
Get declaration type.
Definition: cdecl.h:483
declaration superclass for all net types
Definition: cdecl.h:95
void SetDeclStatementCreated(void)
Set declaration statement created attribute.
Definition: cdecl.h:471
fork/join block declaration
Definition: cdecl.h:79
virtual void SetWireAttr(Wire_t v)
Set declaration's wire attribute.
Definition: cdecl.h:218
int lineno
file line number
Definition: cdecl.h:48
triand type
Definition: cdecl.h:61
virtual INT32 GetNumberOfUnpackedDimensions(void)
Get number of unpacked dimensions of declaration.
Definition: cdecl.h:309
virtual int IsPackedWidthEvaluateable(void) const
Determine if packed or vector width of declaration can be evaluated.
virtual void SetDataType(CDataType *dt)
Set declartion's data type property.
Definition: cdecl.h:205
virtual void DumpDeclInfo(FILE *f)
Dump declaration name, type and location to file descriptor.
Definition: cdecl.h:510
virtual int PackedWidthDirection(void) const
Evaluate current decl width direction.
Flag
Definition: cdecl.h:167
Decl_t
Declaration types.
Definition: cdecl.h:74
declaration has datatype
Definition: cdecl.h:171
virtual void PreVisit1(int(*func)(CNode *, void *), void *data)
tri1 type
Definition: cdecl.h:64
virtual void SetScalared(int v)
Set declartion's scalared property.
Definition: cdecl.h:393
virtual CNode * GetPackedMsb() const
Get expression for declaration's msb.
attribute declaration
Definition: cdecl.h:97
named block declaration
Definition: cdecl.h:78
supply1 type
Definition: cdecl.h:68
CDecl(CSymbol *aSymbol, Coord_t *aLoc, Decl_t aType, CDataType *dataType, Flag flags)
Create instance of declaration.
Definition: cdecl.h:552
long INT32
Short cut for signed 32 bit integer.
Definition: glue.h:38
virtual NodeType_t GetNodeType(void) const =0
Get data type.
genvar declaration
Definition: cdecl.h:92
module declaration
Definition: cdecl.h:81
trior type
Definition: cdecl.h:63
virtual void SetUnpackedRange(INT32 dim, CNode *v)
Set expression for range of unpacked array for declaration.
Definition: cdecl.h:344
virtual CNode * GetWidthExp(void) const
Get expression representing width of declaration.
Definition: cdecl.h:274
virtual CNode * GetUnpackedLsi(INT32 dim)
Get expression tree for lower limit of unpacked array dimension.
port declaration
Definition: cdecl.h:88
declaration can be unpacked array
Definition: cdecl.h:170
Base class for describing data types.
Definition: cdatatype.h:110
const char * wireName[]
Array to convert Wire_t to character string.
Definition: cdecl.h:108
inout declaration
Definition: cdecl.h:86
generate block declaration
Definition: cdecl.h:80
declaration accepts pragmas
Definition: cdecl.h:169
const char * filename
file name
Definition: cdecl.h:49
virtual int IsWidthVolatile(void) const
Determine if packed width of declaration is volatile, ie depend upon parameters or variables...
Definition: cdecl.h:241
Structure to hold file coordinates.
Definition: cdecl.h:47
Holder for character strings.
Definition: csymbol.h:44
void Copy(CObstack *heap, const CDecl &o)
Perform deep copy of given object to this one This should never be call directly, only by subclasses...
virtual CNode * GetPackedLsb() const
Get expression for declaration's lsb.
static Flag Or(Flag f1, Flag f2)
Definition: cdecl.h:173
virtual int IsWidthConstant(void) const
Determine if packed width of declaration is constant, ie dependent upon only constants and parameters...
Definition: cdecl.h:229
Bulk object allocation object.
Definition: cobstack.h:46
void SetAttributes(CNode *attr)
Set declarations's attributes.
Definition: cdecl.h:403
virtual void Dump(FILE *f)
Dump declaration info to file descriptor.
Definition: cdecl.h:503
package declaration
Definition: cdecl.h:100
CNode * GetAttributes()
Get declaration's attributes.
Definition: cdecl.h:408
int DeclStatementCreated(void)
Get declaration statement create attibute.
Definition: cdecl.h:477
const char * declName[]
Array to convert Decl_t to character string.
Definition: cdecl.h:126
virtual void SetVectored(int v)
Set declartion's vectored property.
Definition: cdecl.h:383
Primary data structure representing parse tree nodes.
Definition: cnode.h:188
instance declaration
Definition: cdecl.h:83
virtual void SetVarAttr(int v)
Set declaration's var attribute.
Definition: cdecl.h:362
virtual INT32 GetPackedWidth(void) const
Evaluate packed or vector width of declaration.
virtual void SetAutomatic(int v)
Set declaration's automatic property.
Definition: cdecl.h:373
tri type
Definition: cdecl.h:59
static void GetMembers(Decl_t type, list< Decl_t > &result)
Get a list of members of the given declaration class/type.
Definition: cdecl.h:448
virtual void PostSubVisit1(CNode *(*func)(CNode *, void *), void *data)
output declaration
Definition: cdecl.h:85
unspecified declaration
Definition: cdecl.h:87
type declaration
Definition: cdecl.h:93
virtual CNode * GetUnpackedRange(INT32 dim)
Get expression for range of array for dimension.
Definition: cdecl.h:338
virtual int GetConstAttr()
Get declaration's const attribute.
Definition: cdecl.h:356
virtual int IsPackedWidthConstant(void) const
Determine if packed or vector width of declaration is constant, ie dependent upon only constants and ...
Decl_t GetClass(void)
Get class of declaration.
Definition: cdecl.h:428
virtual CNode * GetLsb() const
Get expression for declaration's lsb.
Definition: cdecl.h:293
virtual int IsPackedWidthVolatile(void) const
Determine if packed or vector width of declaration is volatile, ie depend upon parameters or variable...
virtual CNode * GetUnpackedMsi(INT32 dim)
Get expression tree for upper limit of given packed array dimension.
declaration superclass for all port dirs
Definition: cdecl.h:96
Base class for describing declaration objects.
Definition: cdecl.h:164
virtual Wire_t GetWireAttr()
Get declartion's wire type property.
Definition: cdecl.h:223
virtual int GetAutomatic()
Get declaration's automatic property.
Definition: cdecl.h:378
supply0 type
Definition: cdecl.h:67
trireg type
Definition: cdecl.h:66
Coord_t * GetCoord(void)
Get file coordinates for declaration.
Definition: cdecl.h:495
static Flag Or(Flag f1, Flag f2, Flag f3)
Definition: cdecl.h:175
void SetSymbol(CSymbol *aSymbol)
Set declaration's symbol.
Definition: cdecl.h:525
forward reference declaration (used by parser only)
Definition: cdecl.h:89
int HasAttribute(char *name, CNode *n=NULL, int init=1)
Determine if declaration has the given attribute.
void SetPragmas(CNode *p)
Set declaration pragmas.
Definition: cdecl.h:535
enum declaration
Definition: cdecl.h:99
virtual int WidthDirection(void) const
Evaluate current decl width direction.
Definition: cdecl.h:301
parameter declaration
Definition: cdecl.h:76
Base class for vrq objects.
Definition: cobject.h:41
virtual int IsWidthEvaluateable(void) const
Determine if packed width of declaration can be evaluated.
Definition: cdecl.h:252
virtual void PostVisit1(void(*func)(CNode *, void *), void *data)
virtual int GetScalared()
Get declartion's scalared property.
Definition: cdecl.h:398
no support flags
Definition: cdecl.h:168
macro module declaration
Definition: cdecl.h:82
CSymbol * GetSymbol(void)
Get declaration's symbol.
Definition: cdecl.h:530
wor type
Definition: cdecl.h:62
unspecified declaration used for wildcard
Definition: cdecl.h:101
void SetCoord(Coord_t *aLoc)
Set declaration coordinate.
Definition: cdecl.h:489
virtual CDecl * Clone(CObstack *heap)=0
Create a deep copy of declaration.
virtual CDataType * GetDataType()
Get declartion's data type property.
Definition: cdecl.h:213
NodeType_t GetNodeType(void)
Get node type of decl.
Definition: cdecl.h:420
function/task declaration
Definition: cdecl.h:90
CNode * GetPragmas()
Get declaration pragmas.
Definition: cdecl.h:541
virtual void SetConstAttr(int v)
Set declaration's const attribute.
Definition: cdecl.h:351
input declaration
Definition: cdecl.h:84
localparam declaration
Definition: cdecl.h:77
NodeType_t
Expression node type.
Definition: cdatatype.h:99
specify block declaration
Definition: cdecl.h:91
const char * GetName(void)
Shortcut to get declaration's name.
Definition: cdecl.h:520
Wire_t
Wire types.
Definition: cdecl.h:56
virtual void SetNumberOfUnpackedDimensions(INT32 dim)
Set number of unpacked dimensions for declaration.
Definition: cdecl.h:328
virtual int GetVectored()
Get declartion's vectored property.
Definition: cdecl.h:388
variable declaration
Definition: cdecl.h:75
virtual INT32 GetWidth(void) const
Evaluate packed width of declaration.
Definition: cdecl.h:263
no wire type
Definition: cdecl.h:57
virtual CNode * GetPackedWidthExp() const
Get expression for datatype's overall packed or vector width.
tri0 type
Definition: cdecl.h:65
wire type
Definition: cdecl.h:58
wand type
Definition: cdecl.h:60
virtual CNode * GetMsb() const
Get expression for declaration's msb.
Definition: cdecl.h:285
const char * GetName(void) const
Get symbol's text.
udp declaration
Definition: cdecl.h:98