FAUST compiler  0.9.9.6b8
klass.hh
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
4  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5  ---------------------------------------------------------------------
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
21 
22 
23 
24 #ifndef _KLASS_H
25 #define _KLASS_H
26 
27 /**********************************************************************
28  - klass.h : class C++ � remplir (projet FAUST) -
29 
30 
31  Historique :
32  -----------
33  17-10-2001 : implementation initiale (yo)
34  18-10-2001 : Ajout de getFreshID (yo)
35  02-11-2001 : Ajout de sous classes (yo)
36 
37 ***********************************************************************/
38 using namespace std;
39 
40 #include <string>
41 #include <list>
42 #include <set>
43 #include <map>
44 #include "sigtype.hh"
45 #include "smartpointer.hh"
46 #include "tlib.hh"
47 #include "uitree.hh"
48 #include "property.hh"
49 
50 #define kMaxCategory 32
51 
52 #include "loop.hh"
53 #include "graphSorting.hh"
54 
55 class Klass //: public Target
56 {
57 
58 protected:
59  // we make it global because several classes may need
60  // power def but we want the code to be generated only once
61  static bool fNeedPowerDef;
62 
63 
64  protected:
65 
67  string fKlassName;
73 
74  set<string> fIncludeFileSet;
75  set<string> fLibrarySet;
76 
77  list<Klass* > fSubClassList;
78 
79  list<string> fDeclCode;
80  list<string> fStaticInitCode;
81  list<string> fStaticFields;
82  list<string> fInitCode;
83  list<string> fUICode;
84  list<string> fUIMacro;
85 
86 #if 0
87  list<string> fSlowDecl;
88  list<string> fSharedDecl;
89  list<string> fCommonCode;
90  list<string> fSlowCode;
91  list<string> fEndCode;
92 #endif
93  list<string> fSharedDecl;
94  list<string> fFirstPrivateDecl;
95 
96  list<string> fZone1Code;
97  list<string> fZone2Code;
98  list<string> fZone2bCode;
99  list<string> fZone2cCode;
100  list<string> fZone3Code;
101 
104 
105  bool fVec;
106 
107  public:
108 
109  Klass (const string& name, const string& super, int numInputs, int numOutputs, bool __vec = false)
110  : fParentKlass(0), fKlassName(name), fSuperKlassName(super), fNumInputs(numInputs), fNumOutputs(numOutputs),
111  fNumActives(0), fNumPassives(0),
112  fTopLoop(new Loop(0, "count")), fVec(__vec)
113  {}
114 
115  virtual ~Klass() {}
116 
117  void setParentKlass(Klass* parent) { std::cerr << this << " setParentKlass(" << parent << ")" << std::endl;
118  fParentKlass=parent; }
119  Klass* getParentKlass() { return fParentKlass; }
120  Klass* getTopParentKlass() { return (fParentKlass != 0) ? fParentKlass->getTopParentKlass() : this; }
121  string getFullClassName() { return (fParentKlass!=0) ? fParentKlass->getFullClassName() + "::" + getClassName() : getClassName(); }
122 
123 
124  void openLoop(const string& size);
125  void openLoop(Tree recsymbol, const string& size);
126  void closeLoop(Tree sig);
127 
128  void setLoopProperty(Tree sig, Loop* l);
129  bool getLoopProperty(Tree sig, Loop*& l);
130 
131  const string& getClassName() const { return fKlassName; }
132 
133  Loop* topLoop() { return fTopLoop; }
134 
135  void buildTasksList();
136 
137  void addIncludeFile (const string& str) { fIncludeFileSet.insert(str); }
138 
139  void addLibrary (const string& str) { fLibrarySet.insert(str); }
140 
141  void rememberNeedPowerDef () { fNeedPowerDef = true; }
142 
143  void collectIncludeFile(set<string>& S);
144 
145  void collectLibrary(set<string>& S);
146 
147  void addSubKlass (Klass* son) { fSubClassList.push_back(son); }
148 
149  void addDeclCode (const string& str) { fDeclCode.push_back(str); }
150 
151  void addInitCode (const string& str) { fInitCode.push_back(str); }
152 
153  void addStaticInitCode (const string& str) { fStaticInitCode.push_back(str); }
154 
155  void addStaticFields (const string& str) { fStaticFields.push_back(str); }
156 
157  void addUICode (const string& str) { fUICode.push_back(str); }
158 
159  void addUIMacro (const string& str) { fUIMacro.push_back(str); }
160 
161  void incUIActiveCount () { fNumActives++; }
162  void incUIPassiveCount () { fNumPassives++; }
163 
164 
165  void addSharedDecl (const string& str) { fSharedDecl.push_back(str); }
166  void addFirstPrivateDecl (const string& str) { fFirstPrivateDecl.push_back(str); }
167 
168  void addZone1 (const string& str) { fZone1Code.push_back(str); }
169  void addZone2 (const string& str) { fZone2Code.push_back(str); }
170  void addZone2b (const string& str) { fZone2bCode.push_back(str); }
171  void addZone2c (const string& str) { fZone2cCode.push_back(str); }
172  void addZone3 (const string& str) { fZone3Code.push_back(str); }
173 
174  void addPreCode ( const string& str) { fTopLoop->addPreCode(str); }
175  void addExecCode ( const string& str) { fTopLoop->addExecCode(str); }
176  void addPostCode (const string& str) { fTopLoop->addPostCode(str); }
177 
178  virtual void println(int n, ostream& fout);
179 
180  virtual void printComputeMethod (int n, ostream& fout);
181  virtual void printComputeMethodScalar (int n, ostream& fout);
182  virtual void printComputeMethodVectorFaster (int n, ostream& fout);
183  virtual void printComputeMethodVectorSimple (int n, ostream& fout);
184  virtual void printComputeMethodOpenMP (int n, ostream& fout);
185  virtual void printComputeMethodScheduler (int n, ostream& fout);
186 
187  virtual void printLoopGraphScalar(int n, ostream& fout);
188  virtual void printLoopGraphVector(int n, ostream& fout);
189  virtual void printLoopGraphOpenMP(int n, ostream& fout);
190  virtual void printLoopGraphScheduler(int n, ostream& fout);
191  virtual void printLoopGraphInternal(int n, ostream& fout);
192  virtual void printGraphDotFormat(ostream& fout);
193 
194  // experimental
195  virtual void printLoopDeepFirst(int n, ostream& fout, Loop* l, set<Loop*>& visited);
196 
197  virtual void printLastLoopLevelScheduler(int n, int lnum, const lset& L, ostream& fout);
198  virtual void printLoopLevelScheduler(int n, int lnum, const lset& L, ostream& fout);
199  virtual void printOneLoopScheduler(lset::const_iterator p, int n, ostream& fout);
200  virtual void printLoopLevelOpenMP(int n, int lnum, const lset& L, ostream& fout);
201 
202  virtual void printMetadata(int n, const map<Tree, set<Tree> >& S, ostream& fout);
203 
204  virtual void printIncludeFile(ostream& fout);
205 
206  virtual void printLibrary(ostream& fout);
207  virtual void printAdditionalCode(ostream& fout);
208 
209  int inputs() { return fNumInputs; }
210  int outputs() { return fNumOutputs; }
211 };
212 
213 class SigIntGenKlass : public Klass {
214 
215  public:
216 
217  SigIntGenKlass (Klass* parent, const string& name) : Klass(name, "", 0, 1, false) { fParentKlass = parent; }
218 
219  virtual void println(int n, ostream& fout);
220 };
221 
222 class SigFloatGenKlass : public Klass {
223 
224  public:
225 
226  SigFloatGenKlass (Klass* parent, const string& name) : Klass(name, "", 0, 1, false) { fParentKlass = parent; }
227 
228  virtual void println(int n, ostream& fout);
229 };
230 
231 
232 #endif
void addSharedDecl(const string &str)
Definition: klass.hh:165
list< string > fDeclCode
Definition: klass.hh:79
void addZone2c(const string &str)
Definition: klass.hh:171
int outputs()
Definition: klass.hh:210
void addLibrary(const string &str)
Definition: klass.hh:139
void addIncludeFile(const string &str)
Definition: klass.hh:137
set< Loop * > lset
Definition: graphSorting.hh:10
Loop * fTopLoop
active loops currently open
Definition: klass.hh:102
Loop * topLoop()
Definition: klass.hh:133
string getFullClassName()
Returns the name of the class.
Definition: klass.hh:121
list< string > fInitCode
Definition: klass.hh:82
list< string > fZone3Code
private every sub block
Definition: klass.hh:100
list< string > fZone2Code
first private
Definition: klass.hh:97
void addExecCode(const string &str)
Definition: klass.hh:175
int fNumInputs
Definition: klass.hh:69
list< string > fZone2bCode
single once per block
Definition: klass.hh:98
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
void addStaticInitCode(const string &str)
Definition: klass.hh:153
Klass * getParentKlass()
Definition: klass.hh:119
static bool fNeedPowerDef
true when faustpower definition is needed
Definition: klass.hh:61
list< string > fStaticFields
static fields after class
Definition: klass.hh:81
Klass(const string &name, const string &super, int numInputs, int numOutputs, bool __vec=false)
Definition: klass.hh:109
SigIntGenKlass(Klass *parent, const string &name)
Definition: klass.hh:217
list< string > fUIMacro
Definition: klass.hh:84
void addZone2b(const string &str)
Definition: klass.hh:170
list< string > fZone2cCode
single once per block
Definition: klass.hh:99
void addInitCode(const string &str)
Definition: klass.hh:151
void addUIMacro(const string &str)
Definition: klass.hh:159
int fNumActives
number of active controls in the UI (sliders, buttons, etc.)
Definition: klass.hh:71
bool fVec
Definition: klass.hh:105
void addSubKlass(Klass *son)
Definition: klass.hh:147
void addFirstPrivateDecl(const string &str)
Definition: klass.hh:166
virtual ~Klass()
Definition: klass.hh:115
const string & getClassName() const
Returns the name of the class.
Definition: klass.hh:131
list< string > fFirstPrivateDecl
first private declarations
Definition: klass.hh:94
void addPreCode(const string &str)
Definition: klass.hh:174
void addZone2(const string &str)
Definition: klass.hh:169
set< string > fLibrarySet
Definition: klass.hh:75
Definition: klass.hh:55
list< string > fSharedDecl
shared declarations
Definition: klass.hh:93
void addStaticFields(const string &str)
Definition: klass.hh:155
int fNumPassives
number of passive widgets in the UI (bargraphs, etc.)
Definition: klass.hh:72
Klass * getTopParentKlass()
Definition: klass.hh:120
SigFloatGenKlass(Klass *parent, const string &name)
Definition: klass.hh:226
void setParentKlass(Klass *parent)
Definition: klass.hh:117
int fNumOutputs
Definition: klass.hh:70
void addZone1(const string &str)
Definition: klass.hh:168
Klass * fParentKlass
Klass in which this Klass is embedded, void if toplevel Klass.
Definition: klass.hh:66
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
void rememberNeedPowerDef()
Definition: klass.hh:141
void addPostCode(const string &str)
Definition: klass.hh:176
string fKlassName
Definition: klass.hh:67
void incUIPassiveCount()
Definition: klass.hh:162
void addUICode(const string &str)
Definition: klass.hh:157
list< string > fStaticInitCode
static init code for class constant tables
Definition: klass.hh:80
string fSuperKlassName
Definition: klass.hh:68
property< Loop * > fLoopProperty
loops used to compute some signals
Definition: klass.hh:103
list< Klass * > fSubClassList
Definition: klass.hh:77
int inputs()
Definition: klass.hh:209
void incUIActiveCount()
Definition: klass.hh:161
set< string > fIncludeFileSet
Definition: klass.hh:74
Definition: loop.hh:52
list< string > fUICode
Definition: klass.hh:83
void addZone3(const string &str)
Definition: klass.hh:172
list< string > fZone1Code
shared vectors
Definition: klass.hh:96
void addDeclCode(const string &str)
Definition: klass.hh:149