Merge branch 'master' of https://scm.cri.ensmp.fr/git/Faustine
[Faustine.git] / interpretor / faust-0.9.47mr3 / compiler / headers / klass.hh
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; ///< true when faustpower definition is needed
62
63
64 protected:
65
66 string fKlassName;
67 string fSuperKlassName;
68 int fNumInputs;
69 int fNumOutputs;
70 int fNumActives; ///< number of active controls in the UI (sliders, buttons, etc.)
71 int fNumPassives; ///< number of passive widgets in the UI (bargraphs, etc.)
72
73 set<string> fIncludeFileSet;
74 set<string> fLibrarySet;
75
76 list<Klass* > fSubClassList;
77
78 list<string> fDeclCode;
79 list<string> fStaticInitCode; ///< static init code for class constant tables
80 list<string> fStaticFields; ///< static fields after class
81 list<string> fInitCode;
82 list<string> fUICode;
83 list<string> fUIMacro;
84
85 #if 0
86 list<string> fSlowDecl;
87 list<string> fSharedDecl; ///< declare shared variables for openMP
88 list<string> fCommonCode; ///< code executed by all threads
89 list<string> fSlowCode;
90 list<string> fEndCode;
91 #endif
92 list<string> fSharedDecl; ///< shared declarations
93 list<string> fFirstPrivateDecl; ///< first private declarations
94
95 list<string> fZone1Code; ///< shared vectors
96 list<string> fZone2Code; ///< first private
97 list<string> fZone2bCode; ///< single once per block
98 list<string> fZone2cCode; ///< single once per block
99 list<string> fZone3Code; ///< private every sub block
100
101 Loop* fTopLoop; ///< active loops currently open
102 property<Loop*> fLoopProperty; ///< loops used to compute some signals
103
104 bool fVec;
105
106 public:
107
108 Klass (const string& name, const string& super, int numInputs, int numOutputs, bool __vec = false)
109 : fKlassName(name), fSuperKlassName(super), fNumInputs(numInputs), fNumOutputs(numOutputs),
110 fNumActives(0), fNumPassives(0),
111 fTopLoop(new Loop(0, "count")), fVec(__vec)
112 {}
113
114 virtual ~Klass() {}
115
116 void openLoop(const string& size);
117 void openLoop(Tree recsymbol, const string& size);
118 void closeLoop(Tree sig);
119
120 void setLoopProperty(Tree sig, Loop* l); ///< Store the loop used to compute a signal
121 bool getLoopProperty(Tree sig, Loop*& l); ///< Returns the loop used to compute a signal
122 const string& getClassName() const { return fKlassName; } ///< Returns the name of the class
123
124 Loop* topLoop() { return fTopLoop; }
125
126 void buildTasksList();
127
128 void addIncludeFile (const string& str) { fIncludeFileSet.insert(str); }
129
130 void addLibrary (const string& str) { fLibrarySet.insert(str); }
131
132 void rememberNeedPowerDef () { fNeedPowerDef = true; }
133
134 void collectIncludeFile(set<string>& S);
135
136 void collectLibrary(set<string>& S);
137
138 void addSubKlass (Klass* son) { fSubClassList.push_back(son); }
139
140 void addDeclCode (const string& str) { fDeclCode.push_back(str); }
141
142 void addInitCode (const string& str) { fInitCode.push_back(str); }
143
144 void addStaticInitCode (const string& str) { fStaticInitCode.push_back(str); }
145
146 void addStaticFields (const string& str) { fStaticFields.push_back(str); }
147
148 void addUICode (const string& str) { fUICode.push_back(str); }
149
150 void addUIMacro (const string& str) { fUIMacro.push_back(str); }
151
152 void incUIActiveCount () { fNumActives++; }
153 void incUIPassiveCount () { fNumPassives++; }
154
155
156 void addSharedDecl (const string& str) { fSharedDecl.push_back(str); }
157 void addFirstPrivateDecl (const string& str) { fFirstPrivateDecl.push_back(str); }
158
159 void addZone1 (const string& str) { fZone1Code.push_back(str); }
160 void addZone2 (const string& str) { fZone2Code.push_back(str); }
161 void addZone2b (const string& str) { fZone2bCode.push_back(str); }
162 void addZone2c (const string& str) { fZone2cCode.push_back(str); }
163 void addZone3 (const string& str) { fZone3Code.push_back(str); }
164
165 void addPreCode ( const string& str) { fTopLoop->addPreCode(str); }
166 void addExecCode ( const string& str) { fTopLoop->addExecCode(str); }
167 void addPostCode (const string& str) { fTopLoop->addPostCode(str); }
168
169 virtual void println(int n, ostream& fout);
170
171 virtual void printComputeMethod (int n, ostream& fout);
172 virtual void printComputeMethodScalar (int n, ostream& fout);
173 virtual void printComputeMethodVectorFaster (int n, ostream& fout);
174 virtual void printComputeMethodVectorSimple (int n, ostream& fout);
175 virtual void printComputeMethodOpenMP (int n, ostream& fout);
176 virtual void printComputeMethodScheduler (int n, ostream& fout);
177
178 virtual void printLoopGraphScalar(int n, ostream& fout);
179 virtual void printLoopGraphVector(int n, ostream& fout);
180 virtual void printLoopGraphOpenMP(int n, ostream& fout);
181 virtual void printLoopGraphScheduler(int n, ostream& fout);
182 virtual void printLoopGraphInternal(int n, ostream& fout);
183 virtual void printGraphDotFormat(ostream& fout);
184
185 // experimental
186 virtual void printLoopDeepFirst(int n, ostream& fout, Loop* l, set<Loop*>& visited);
187
188 virtual void printLastLoopLevelScheduler(int n, int lnum, const lset& L, ostream& fout);
189 virtual void printLoopLevelScheduler(int n, int lnum, const lset& L, ostream& fout);
190 virtual void printOneLoopScheduler(lset::const_iterator p, int n, ostream& fout);
191 virtual void printLoopLevelOpenMP(int n, int lnum, const lset& L, ostream& fout);
192
193 virtual void printMetadata(int n, const map<Tree, set<Tree> >& S, ostream& fout);
194
195 virtual void printIncludeFile(ostream& fout);
196
197 virtual void printLibrary(ostream& fout);
198 virtual void printAdditionalCode(ostream& fout);
199
200 int inputs() { return fNumInputs; }
201 int outputs() { return fNumOutputs; }
202 };
203
204 class SigIntGenKlass : public Klass {
205
206 public:
207
208 SigIntGenKlass (const string& name) : Klass(name, "", 0, 1, false) {}
209
210 virtual void println(int n, ostream& fout);
211 };
212
213 class SigFloatGenKlass : public Klass {
214
215 public:
216
217 SigFloatGenKlass (const string& name) : Klass(name, "", 0, 1, false) {}
218
219 virtual void println(int n, ostream& fout);
220 };
221
222
223 #endif