vrq
cfunction.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  * cfunction.hpp
25  * - class definition of function
26  * definition nodes
27  *
28  ******************************************************************************
29  */
30 
31 #ifndef CFUNCTION_HPP
32 #define CFUNCTION_HPP
33 
34 #include <stdio.h>
35 #include <vector>
36 #include <list>
37 #include "glue.h"
38 #include "cdecl.h"
39 #include "csymtab.h"
40 #include "cblock.h"
41 #include "cnode.h"
42 #include "cfref.h"
43 
44 class CContext;
45 
46 
50 class CFunction: public CBlock
51 {
52 private:
53  CSymtab<CDecl> portSymtab;
54  int portDirListValid;
55  vector<CPortDir*> portDirList;
57  CDecl* output;
58  int automatic;
60  CNode* ports;
61  int inlinePortDecls;
62 public:
69  CFunction( CSymbol* symbol, Coord_t* aLoc, int automatic );
74  virtual void Dump( FILE* f );
79  virtual vector<CPortDir*>* GetPortDirList();
84  void SetPorts( CNode* n ) { ports = n; }
89  CNode* GetPorts() { return ports; }
94  int InlinePortDecls() { return inlinePortDecls; }
99  void InlinePortDecls( int v ) { inlinePortDecls = v; }
104  void SetOutput( CDecl* output ) { this->output = output; }
109  CDecl* GetOutput() { return output; }
115  int GetAutomatic() { return automatic; }
116 
126  static int Width( CSymbol* symbol, CNode* args, CBlock* block ) ;
136  static CNode* WidthExp( CSymbol* symbol, CNode* args, CBlock* block ) ;
147  static int WidthConstant( CSymbol* symbol, CNode* args,
148  CBlock* block );
159  static int WidthVolatile( CSymbol* symbol, CNode* args,
160  CBlock* block );
170  static int WidthEvaluateable( CSymbol* symbol, CNode* args,
171  CBlock* block );
181  static NodeType_t Type( CSymbol* symbol, CNode* args, CBlock* block );
182 
190  static int Evaluateable( CSymbol* symbol, CNode* args, CBlock* block );
191 
199  static void EvalVector( CVector& v, CSymbol* symbol,
200  CNode* args, CBlock* block );
201 
209  static double EvalReal( CSymbol* symbol, CNode* args, CBlock* block );
210 
215  void PreVisit1( int (*func)(CNode*,void*), void* data );
216  void PostVisit1( void (*func)(CNode*, void*), void* data );
217  void PostSubVisit1( CNode* (*func)(CNode*, void*), void* data );
218  void FixupPorts();
219  void SetPortSymtab( CSymtab<CDecl>& symtab );
220 protected:
221  virtual void CodeListChanged() { portDirListValid = FALSE; }
222 private:
223  static CFunction* FindFunction( CSymbol* symbol,
224  CNode* args, CBlock* block );
225  void EvaluateArgs( CContext* context, CNode* args );
229 };
230 
231 #endif // CFUNCTION_HPP
static int WidthEvaluateable(CSymbol *symbol, CNode *args, CBlock *block)
Determine if width of function is evaluateable.
void InlinePortDecls(int v)
Set inline declaration attribute.
Definition: cfunction.h:99
virtual void PreVisit1(int(*func)(CNode *, void *), void *data)
void SetOutput(CDecl *output)
Set output declaration for function.
Definition: cfunction.h:104
CFunction(CSymbol *symbol, Coord_t *aLoc, int automatic)
Create function/task declaration object.
static double EvalReal(CSymbol *symbol, CNode *args, CBlock *block)
Evaluate function as a real and return result.
static NodeType_t Type(CSymbol *symbol, CNode *args, CBlock *block)
Determine if type of result of function.
static void EvalVector(CVector &v, CSymbol *symbol, CNode *args, CBlock *block)
Evaluate function as a vector and return result.
static int Width(CSymbol *symbol, CNode *args, CBlock *block)
Get width of function.
Structure to hold file coordinates.
Definition: cdecl.h:47
Holder for character strings.
Definition: csymbol.h:44
virtual vector< CPortDir * > * GetPortDirList()
Get array of port declarations.
Primary data structure representing parse tree nodes.
Definition: cnode.h:197
virtual void PostSubVisit1(CNode *(*func)(CNode *, void *), void *data)
virtual void Dump(FILE *f)
Dump function info to file descriptor.
CNode * GetPorts()
Get function port list.
Definition: cfunction.h:89
Base class for describing declaration objects.
Definition: cdecl.h:164
static int Evaluateable(CSymbol *symbol, CNode *args, CBlock *block)
Determine if function can be evaluated.
static CNode * WidthExp(CSymbol *symbol, CNode *args, CBlock *block)
Get width of function as an expression.
Bit vector class for implementing 4 state verilog signed and unsigned arithmetic. ...
Definition: cvector.h:58
virtual void PostVisit1(void(*func)(CNode *, void *), void *data)
static int WidthConstant(CSymbol *symbol, CNode *args, CBlock *block)
Determine if width of function is constant.
Declaration object for functions and tasks.
Definition: cfunction.h:50
NodeType_t
Expression node type.
Definition: cdatatype.h:101
int InlinePortDecls()
Get inline declaration attribute.
Definition: cfunction.h:94
CSymtab< CDecl > symtab
Definition: cblock.h:63
Declaration class for block constructs.
Definition: cblock.h:52
CDecl * GetOutput()
Get output declaration.
Definition: cfunction.h:109
static int WidthVolatile(CSymbol *symbol, CNode *args, CBlock *block)
Determine if width of function is volatile.
int GetAutomatic()
Get automatic attribute.
Definition: cfunction.h:115
void SetPorts(CNode *n)
Set function port list.
Definition: cfunction.h:84