Update readme, install and license files.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / signals / signals.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 _SIGNALS_
25 #define _SIGNALS_
26
27 #include "tlib.hh"
28 #include "binop.hh"
29 #include <assert.h>
30 #include <vector>
31
32 using namespace std;
33
34
35 ////////////////////////////////////////////////////////////////////////
36 /**
37 * Signals
38 * Block-diagrams are converted into signal expressions via
39 * symbolic propagation
40 */
41 ///////////////////////////////////////////////////////////////////////
42
43 // Constant signals : for all t, x(t)=n
44 Tree sigInt(int n);
45 Tree sigReal(double n);
46
47 bool isSigInt(Tree t, int* i);
48 bool isSigReal(Tree t, double* r);
49
50
51 // Inputs and outputs
52 Tree sigInput(int i);
53 Tree sigOutput(int i, Tree t);
54
55 bool isSigInput(Tree t, int* i);
56 bool isSigOutput(Tree t, int* i, Tree& t0);
57
58 // delay
59 Tree sigDelay0(Tree t);
60 Tree sigDelay1(Tree t);
61 bool isSigDelay1(Tree t, Tree& t0);
62
63 Tree sigFixDelay(Tree t0, Tree t1);
64 bool isSigFixDelay(Tree t, Tree& t0, Tree& t1);
65
66 Tree sigPrefix(Tree t0, Tree t1);
67 bool isSigPrefix(Tree t, Tree& t0, Tree& t1);
68
69 Tree sigIota(Tree t0);
70 bool isSigIota(Tree t, Tree& t0);
71
72 // Int and Double casting
73 Tree sigIntCast(Tree t);
74 Tree sigFloatCast(Tree t);
75
76 bool isSigIntCast(Tree t);
77 bool isSigFloatCast(Tree t);
78
79 bool isSigIntCast(Tree t, Tree& x);
80 bool isSigFloatCast(Tree t, Tree& x);
81
82
83 // tables
84 Tree sigRDTbl (Tree t, Tree i);
85 Tree sigWRTbl (Tree id, Tree t, Tree i, Tree s);
86 Tree sigTable (Tree id, Tree n, Tree sig);
87 Tree sigGen (Tree content);
88
89 bool isSigRDTbl (Tree s, Tree& t, Tree& i);
90 bool isSigWRTbl (Tree u, Tree& id, Tree& t, Tree& i, Tree& s);
91 bool isSigTable (Tree t, Tree& id, Tree& n, Tree& sig);
92 bool isSigGen (Tree t, Tree& content);
93 bool isSigGen (Tree t);
94
95 inline Tree sigWriteReadTable(Tree n, Tree init, Tree widx, Tree wsig, Tree ridx)
96 {
97 return sigRDTbl(sigWRTbl(nil, sigTable(nil, n, sigGen(init)), widx, wsig), ridx);
98 }
99
100 inline Tree sigReadOnlyTable(Tree n, Tree init, Tree ridx)
101 {
102 return sigRDTbl(sigTable(nil, n, sigGen(init)), ridx);
103 }
104
105
106 // Tables for documentator
107 // used to replace real tables for documentation purposes only
108
109 Tree sigDocConstantTbl(Tree n, Tree init);
110 Tree sigDocWriteTbl(Tree n, Tree init, Tree widx, Tree wsig);
111 Tree sigDocAccessTbl(Tree doctbl, Tree ridx);
112
113 bool isSigDocConstantTbl(Tree s, Tree& n, Tree& init);
114 bool isSigDocWriteTbl(Tree s, Tree& n, Tree& init, Tree& widx, Tree& wsig);
115 bool isSigDocAccessTbl(Tree s, Tree& doctbl, Tree& ridx);
116
117 // selectors
118
119 Tree sigSelect2 (Tree selector, Tree s1, Tree s2);
120 Tree sigSelect3 (Tree selector, Tree s1, Tree s2, Tree s3);
121
122 bool isSigSelect2 (Tree t, Tree& selector, Tree& s1, Tree& s2);
123 bool isSigSelect3 (Tree t, Tree& selector, Tree& s1, Tree& s2, Tree& s3);
124
125
126 // multirate
127 Tree sigVectorize (Tree n, Tree s);
128 bool isSigVectorize (Tree a, Tree& n, Tree& s);
129
130 Tree sigSerialize (Tree s);
131 bool isSigSerialize (Tree a, Tree& s);
132
133 Tree sigConcat (Tree s1, Tree s2);
134 bool isSigConcat (Tree a, Tree& s1, Tree& s2);
135
136 Tree sigVectorAt (Tree s1, Tree s2);
137 bool isSigVectorAt (Tree a, Tree& s1, Tree& s2);
138
139 Tree sigUpSample (Tree n, Tree s);
140 bool isSigUpSample (Tree a, Tree& n, Tree& s);
141
142 Tree sigDownSample (Tree n, Tree s);
143 bool isSigDownSample (Tree a, Tree& n, Tree& s);
144
145
146 // arithmetical operations
147
148 Tree sigBinOp (int op, Tree x, Tree y);
149 bool isSigBinOp (Tree s, int* op, Tree& x, Tree& y);
150
151 // Foreign Functions
152
153 Tree sigFFun (Tree ff, Tree largs);
154 bool isSigFFun (Tree s, Tree& ff, Tree& largs);
155
156 // Foreign Constants
157
158 Tree sigFConst (Tree type, Tree name, Tree file);
159 bool isSigFConst (Tree s);
160 bool isSigFConst (Tree s, Tree& type, Tree& name, Tree& file);
161
162 // Foreign Variables
163
164 Tree sigFVar (Tree type, Tree name, Tree file);
165 bool isSigFVar (Tree s);
166 bool isSigFVar (Tree s, Tree& type, Tree& name, Tree& file);
167
168 // emulation des anciennes fonctions
169 inline Tree sigAdd(Tree x, Tree y) { return sigBinOp(kAdd, x, y); }
170 inline Tree sigSub(Tree x, Tree y) { return sigBinOp(kSub, x, y); }
171 inline Tree sigMul(Tree x, Tree y) { return sigBinOp(kMul, x, y); }
172 inline Tree sigDiv(Tree x, Tree y) { return sigBinOp(kDiv, x, y); }
173 inline Tree sigRem(Tree x, Tree y) { return sigBinOp(kRem, x, y); }
174
175 inline Tree sigAND(Tree x, Tree y) { return sigBinOp(kAND, x, y); }
176 inline Tree sigOR(Tree x, Tree y) { return sigBinOp(kOR, x, y); }
177 inline Tree sigXOR(Tree x, Tree y) { return sigBinOp(kXOR, x, y); }
178
179 inline Tree sigLeftShift(Tree x, Tree y) { return sigBinOp(kLsh, x, y); }
180 inline Tree sigRightShift(Tree x, Tree y) { return sigBinOp(kRsh, x, y); }
181
182 inline Tree sigGT(Tree x, Tree y) { return sigBinOp(kGT, x, y); }
183 inline Tree sigLT(Tree x, Tree y) { return sigBinOp(kLT, x, y); }
184 inline Tree sigGE(Tree x, Tree y) { return sigBinOp(kGE, x, y); }
185 inline Tree sigLE(Tree x, Tree y) { return sigBinOp(kLE, x, y); }
186 inline Tree sigEQ(Tree x, Tree y) { return sigBinOp(kEQ, x, y); }
187 inline Tree sigNE(Tree x, Tree y) { return sigBinOp(kNE, x, y); }
188
189 // pattern matching pour les anciennes fonctions
190 bool isSigAdd (Tree a, Tree&x, Tree&y);
191 bool isSigMul (Tree a, Tree&x, Tree&y);
192 bool isSigSub (Tree a, Tree&x, Tree&y);
193 bool isSigDiv (Tree a, Tree&x, Tree&y);
194
195 // operations pratiques sur des arbres dont on sait qu'ils sont des nombres
196 Tree addNums (Tree a, Tree b);
197 Tree subNums (Tree a, Tree b);
198 Tree mulNums (Tree a, Tree b);
199 Tree divNums (Tree a, Tree b);
200 Tree divExtendedNums (Tree a, Tree b);
201 Tree minusNum (Tree a);
202 Tree inverseNum (Tree a);
203
204 // tests sur les signaux constants
205 inline bool isNum (Tree a) { assert(a); return isNum(a->node()); }
206 inline bool isZero (Tree a) { assert(a); return isZero(a->node()); }
207 inline bool isGTZero (Tree a) { assert(a); return isGTZero(a->node()); }
208 inline bool isGEZero (Tree a) { assert(a); return isGEZero(a->node()); }
209 inline bool isOne (Tree a) { assert(a); return isOne(a->node()); }
210 inline bool isMinusOne (Tree a) { assert(a); return isMinusOne(a->node()); }
211
212 //projection for recursive groups
213 Tree sigProj (int i, Tree rgroup);
214 bool isProj (Tree t, int* i, Tree& rgroup);
215
216 inline bool isNum(const Tree& t, num& n)
217 {
218 double f;
219 int i;
220
221 if (isDouble(t->node(), &f)) { n = f; return true; }
222 if (isInt(t->node(), &i)) { n = i; return true; }
223 return false;
224 }
225
226
227 /*****************************************************************************
228 User Interface Elements
229 *****************************************************************************/
230
231 Tree sigButton (Tree label);
232 bool isSigButton (Tree s);
233 bool isSigButton (Tree s, Tree& label);
234
235 Tree sigCheckbox (Tree label);
236 bool isSigCheckbox (Tree s);
237 bool isSigCheckbox (Tree s, Tree& label);
238
239 Tree sigVSlider (Tree label, Tree cur, Tree min, Tree max, Tree step);
240 bool isSigVSlider (Tree s);
241 bool isSigVSlider (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
242
243 Tree sigHSlider (Tree label, Tree cur, Tree min, Tree max, Tree step);
244 bool isSigHSlider (Tree s);
245 bool isSigHSlider (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
246
247 Tree sigNumEntry (Tree label, Tree cur, Tree min, Tree max, Tree step);
248 bool isSigNumEntry (Tree s);
249 bool isSigNumEntry (Tree s, Tree& label, Tree& cur, Tree& min, Tree& max, Tree& step);
250
251 // output elements
252 Tree sigVBargraph (Tree label, Tree min, Tree max, Tree t0);
253 bool isSigVBargraph (Tree s);
254 bool isSigVBargraph (Tree s, Tree& label, Tree& min, Tree& max, Tree& t0);
255
256 Tree sigHBargraph (Tree label, Tree min, Tree max, Tree t0);
257 bool isSigHBargraph (Tree s);
258 bool isSigHBargraph (Tree s, Tree& label, Tree& min, Tree& max, Tree& t0);
259
260 Tree sigAttach (Tree x, Tree y);
261 bool isSigAttach (Tree s);
262 bool isSigAttach (Tree s, Tree& x, Tree& y);
263
264
265 /*****************************************************************************
266 matrix extension
267 *****************************************************************************/
268
269 // a tuple of signals is basically a list of signals.
270 // mode = 0 means normal, mode = 1 means blocked
271 Tree sigTuple (int mode, Tree ls);
272 bool isSigTuple (Tree s, int* mode, Tree& ls);
273
274 // Access the components of a tuple.
275 // ts is tuple of signals, idx is a scalar signal between 0..n
276 Tree sigTupleAccess(Tree ts, Tree idx);
277 bool isSigTupleAccess(Tree s, Tree& ts, Tree& idx);
278
279 // create a tuple of signals
280 Tree sigCartesianProd (Tree s1, Tree s2);
281
282
283
284 /*****************************************************************************
285 access to sub signals of a signal
286 *****************************************************************************/
287
288 int getSubSignals (Tree sig, vector<Tree>& vsigs, bool visitgen=true);
289
290
291 /**
292 * Test if exp is very simple that is it
293 * can't be considered a real component
294 * @param exp the signal we want to test
295 * @return true if it a very simple signal
296 */
297 bool verySimple(Tree exp);
298
299
300
301 #endif