Revert "Examples Makefile."
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / generator / compile_scal.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 _COMPILE_SCAL_
25 #define _COMPILE_SCAL_
26
27 #include <utility>
28 #include "compile.hh"
29 #include "sigtyperules.hh"
30 #include "sigraterules.hh"
31 #include "occurences.hh"
32 #include "property.hh"
33
34 ////////////////////////////////////////////////////////////////////////
35 /**
36 * Compile a list of FAUST signals into a scalar C++ class
37 */
38 ///////////////////////////////////////////////////////////////////////
39
40 class ScalarCompiler : public Compiler
41 {
42 protected:
43 property<string> fCompileProperty;
44 property<string> fVectorProperty;
45 property<pair<string,string> > fStaticInitProperty; // property added to solve 20101208 kjetil bug
46 property<pair<string,string> > fInstanceInitProperty; // property added to solve 20101208 kjetil bug
47
48 static map<string, int> fIDCounters;
49 Tree fSharingKey;
50 OccMarkup fOccMarkup;
51 bool fHasIota;
52
53 RateInferrer* fRates;
54
55 public:
56
57 ScalarCompiler ( const string& name, const string& super, int numInputs, int numOutputs) :
58 Compiler(name,super,numInputs,numOutputs,false),
59 fHasIota(false),
60 fRates(0)
61 {}
62
63 ScalarCompiler ( Klass* k) :
64 Compiler(k),
65 fHasIota(false)
66 {}
67
68 virtual void compileMultiSignal (Tree lsig);
69 virtual void compileSingleSignal (Tree lsig);
70
71
72 protected:
73
74 virtual string CS (Tree sig);
75 virtual string generateCode (Tree sig);
76 virtual string generateCacheCode(Tree sig, const string& exp) ;
77
78 virtual string generateVariableStore(Tree sig, const string& exp);
79
80 string getFreshID (const string& prefix);
81
82 void compilePreparedSignalList (Tree lsig);
83 Tree prepare(Tree L0);
84 Tree prepare2 (Tree L0);
85
86
87 bool getCompiledExpression(Tree sig, string& name);
88 string setCompiledExpression(Tree sig, const string& name);
89
90 void setVectorNameProperty(Tree sig, const string& vecname);
91 bool getVectorNameProperty(Tree sig, string& vecname);
92
93 int getSharingCount(Tree t);
94 void setSharingCount(Tree t, int count);
95 void sharingAnalysis(Tree t);
96 void sharingAnnotation(int vctxt, Tree t);
97
98
99 // generation du code
100
101 string generateXtended (Tree sig);
102 virtual string generateFixDelay (Tree sig, Tree arg, Tree size);
103 string generatePrefix (Tree sig, Tree x, Tree e);
104 string generateIota (Tree sig, Tree arg);
105 string generateBinOp (Tree sig, int opcode, Tree arg1, Tree arg2);
106
107 string generateFFun (Tree sig, Tree ff, Tree largs);
108
109 string generateInput (Tree sig, const string& idx);
110 string generateOutput (Tree sig, const string& idx, const string& arg1);
111
112 string generateTable (Tree sig, Tree tsize, Tree content);
113 string generateStaticTable (Tree sig, Tree tsize, Tree content);
114 string generateWRTbl (Tree sig, Tree tbl, Tree idx, Tree data);
115 string generateRDTbl (Tree sig, Tree tbl, Tree idx);
116 string generateSigGen (Tree sig, Tree content);
117 string generateStaticSigGen(Tree sig, Tree content);
118
119 string generateSelect2 (Tree sig, Tree sel, Tree s1, Tree s2);
120 string generateSelect3 (Tree sig, Tree sel, Tree s1, Tree s2, Tree s3);
121
122 string generateRecProj (Tree sig, Tree exp, int i);
123 void generateRec (Tree sig, Tree var, Tree le);
124
125 string generateIntCast (Tree sig, Tree x);
126 string generateFloatCast (Tree sig, Tree x);
127
128 string generateButton (Tree sig, Tree label);
129 string generateCheckbox (Tree sig, Tree label);
130 string generateVSlider (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
131 string generateHSlider (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
132 string generateNumEntry (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
133
134 string generateVBargraph (Tree sig, Tree label, Tree min, Tree max, const string& exp);
135 string generateHBargraph (Tree sig, Tree label, Tree min, Tree max, const string& exp);
136
137 string generateNumber(Tree sig, const string& exp);
138 string generateFConst (Tree sig, const string& file, const string& name);
139 string generateFVar (Tree sig, const string& file, const string& name);
140
141 virtual string generateDelayVec(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd);
142 string generateDelayVecNoTemp(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd);
143 //string generateDelayVecWithTemp(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd);
144 virtual void generateDelayLine(const string& ctype, const string& vname, int mxd, const string& exp);
145
146 // up et down sampling
147 virtual string generateUpSample (Tree sig, Tree arg, Tree size);
148 virtual string generateDownSample (Tree sig, Tree arg, Tree size);
149
150
151
152 void getTypedNames(Type t, const string& prefix, string& ctype, string& vname);
153 void ensureIotaCode();
154 int pow2limit(int x);
155
156
157
158 };
159
160 #endif