1 /************************************************************************
2 ************************************************************************
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.
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.
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 ************************************************************************/
35 ////////////////////////////////////////////////////////////////////////
38 * Block-diagrams are converted into signal expressions via
39 * symbolic propagation
41 ///////////////////////////////////////////////////////////////////////
43 // Constant signals : for all t, x(t)=n
45 Tree sigReal(double n);
47 bool isSigInt(Tree t, int* i);
48 bool isSigReal(Tree t, double* r);
53 Tree sigOutput(int i, Tree t);
55 bool isSigInput(Tree t, int* i);
56 bool isSigOutput(Tree t, int* i, Tree& t0);
59 Tree sigDelay0(Tree t);
60 Tree sigDelay1(Tree t);
61 bool isSigDelay1(Tree t, Tree& t0);
63 Tree sigFixDelay(Tree t0, Tree t1);
64 bool isSigFixDelay(Tree t, Tree& t0, Tree& t1);
66 Tree sigPrefix(Tree t0, Tree t1);
67 bool isSigPrefix(Tree t, Tree& t0, Tree& t1);
69 Tree sigIota(Tree t0);
70 bool isSigIota(Tree t, Tree& t0);
72 // Int and Double casting
73 Tree sigIntCast(Tree t);
74 Tree sigFloatCast(Tree t);
76 bool isSigIntCast(Tree t);
77 bool isSigFloatCast(Tree t);
79 bool isSigIntCast(Tree t, Tree& x);
80 bool isSigFloatCast(Tree t, Tree& x);
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);
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);
95 inline Tree sigWriteReadTable(Tree n, Tree init, Tree widx, Tree wsig, Tree ridx)
97 return sigRDTbl(sigWRTbl(nil, sigTable(nil, n, sigGen(init)), widx, wsig), ridx);
100 inline Tree sigReadOnlyTable(Tree n, Tree init, Tree ridx)
102 return sigRDTbl(sigTable(nil, n, sigGen(init)), ridx);
106 // Tables for documentator
107 // used to replace real tables for documentation purposes only
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);
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);
119 Tree sigSelect2 (Tree selector, Tree s1, Tree s2);
120 Tree sigSelect3 (Tree selector, Tree s1, Tree s2, Tree s3);
122 bool isSigSelect2 (Tree t, Tree& selector, Tree& s1, Tree& s2);
123 bool isSigSelect3 (Tree t, Tree& selector, Tree& s1, Tree& s2, Tree& s3);
127 Tree sigVectorize (Tree n, Tree s);
128 bool isSigVectorize (Tree a, Tree& n, Tree& s);
130 Tree sigSerialize (Tree s);
131 bool isSigSerialize (Tree a, Tree& s);
133 Tree sigConcat (Tree s1, Tree s2);
134 bool isSigConcat (Tree a, Tree& s1, Tree& s2);
136 Tree sigVectorAt (Tree s1, Tree s2);
137 bool isSigVectorAt (Tree a, Tree& s1, Tree& s2);
139 Tree sigUpSample (Tree n, Tree s);
140 bool isSigUpSample (Tree a, Tree& n, Tree& s);
142 Tree sigDownSample (Tree n, Tree s);
143 bool isSigDownSample (Tree a, Tree& n, Tree& s);
146 // arithmetical operations
148 Tree sigBinOp (int op, Tree x, Tree y);
149 bool isSigBinOp (Tree s, int* op, Tree& x, Tree& y);
153 Tree sigFFun (Tree ff, Tree largs);
154 bool isSigFFun (Tree s, Tree& ff, Tree& largs);
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);
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);
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); }
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); }
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); }
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); }
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);
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);
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()); }
212 //projection for recursive groups
213 Tree sigProj (int i, Tree rgroup);
214 bool isProj (Tree t, int* i, Tree& rgroup);
216 inline bool isNum(const Tree& t, num& n)
221 if (isDouble(t->node(), &f)) { n = f; return true; }
222 if (isInt(t->node(), &i)) { n = i; return true; }
227 /*****************************************************************************
228 User Interface Elements
229 *****************************************************************************/
231 Tree sigButton (Tree label);
232 bool isSigButton (Tree s);
233 bool isSigButton (Tree s, Tree& label);
235 Tree sigCheckbox (Tree label);
236 bool isSigCheckbox (Tree s);
237 bool isSigCheckbox (Tree s, Tree& label);
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);
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);
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);
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);
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);
260 Tree sigAttach (Tree x, Tree y);
261 bool isSigAttach (Tree s);
262 bool isSigAttach (Tree s, Tree& x, Tree& y);
265 /*****************************************************************************
267 *****************************************************************************/
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);
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);
279 // create a tuple of signals
280 Tree sigCartesianProd (Tree s1, Tree s2);
284 /*****************************************************************************
285 access to sub signals of a signal
286 *****************************************************************************/
288 int getSubSignals (Tree sig, vector<Tree>& vsigs, bool visitgen=true);
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
297 bool verySimple(Tree exp);