FAUST compiler  0.9.9.6b8
ppsig.cpp
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 #include "Text.hh"
25 #include "ppsig.hh"
26 #include "binop.hh"
27 #include "prim2.hh"
28 #include "xtended.hh"
29 #include "recursivness.hh"
30 
31 ostream& ppsig::printinfix (ostream& fout, const string& opname, int priority, Tree x, Tree y) const
32 {
33  if (fPriority > priority) fout << "(";
34  fout << ppsig(x,fEnv,priority) << opname << ppsig(y,fEnv,priority);
35  if (fPriority > priority) fout << ")";
36  return fout;
37 }
38 
39 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x) const
40 {
41  return fout << funame << '(' << ppsig(x,fEnv) << ')';
42 }
43 
44 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y) const
45 {
46  return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ')';
47 }
48 
49 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z) const
50 {
51  return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ')';
52 }
53 
54 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z, Tree zz) const
55 {
56  return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ',' << ppsig(zz,fEnv) << ')';
57 }
58 
59 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z, Tree z2, Tree z3) const
60 {
61  return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ',' << ppsig(z2,fEnv) << ',' << ppsig(z3,fEnv) << ')';
62 }
63 
64 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label) const
65 {
66  fout << funame << '(';
67  printlabel(fout, label);
68  return fout << ')';
69 }
70 
71 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label, Tree lo, Tree hi, Tree step) const
72 {
73  fout << funame << '(';
74  printlabel(fout, label);
75  return fout
76  << ',' << ppsig(lo,fEnv)
77  << ',' << ppsig(hi,fEnv)
78  << ',' << ppsig(step,fEnv)
79  << ')';
80 }
81 
82 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label, Tree cur, Tree lo, Tree hi, Tree step) const
83 {
84  fout << funame << '(';
85  printlabel(fout, label);
86  return fout
87  << ',' << ppsig(cur,fEnv)
88  << ',' << ppsig(lo,fEnv)
89  << ',' << ppsig(hi,fEnv)
90  << ',' << ppsig(step,fEnv)
91  << ')';
92 }
93 
94 ostream& ppsig::printout (ostream& fout, int i, Tree x) const
95 {
96  if (fPriority > 0) fout << "(";
97  fout << "OUT" << i << " = " << ppsig(x, fEnv, 0);
98  if (fPriority > 0) fout << ")";
99  return fout;
100 }
101 
102 ostream& ppsig::printlabel (ostream& fout, Tree pathname) const
103 {
104  fout << *hd(pathname);
105  pathname = tl(pathname);
106  while (!isNil(pathname)) {
107  fout << '/' << *tl(hd(pathname));
108  pathname = tl(pathname);
109  }
110  return fout;
111 }
112 
113 ostream& ppsig::printlist (ostream& fout, Tree largs) const
114 {
115  string sep = "";
116  fout << '(';
117  while (!isNil(largs)) {
118  fout << sep << ppsig(hd(largs), fEnv);
119  sep = ", ";
120  largs = tl(largs);
121  }
122  fout << ')';
123  return fout;
124 }
125 
126 ostream& ppsig::printff (ostream& fout, Tree ff, Tree largs) const
127 {
128  fout << ffname(ff); printlist(fout, largs);
129  return fout;
130 }
131 
132 ostream& ppsig::printFixDelay (ostream& fout, Tree exp, Tree delay) const
133 {
134  int d;
135 
136  if (isSigInt(delay, &d) && (d==1)) {
137  fout << ppsig(exp,fEnv,8) << "'";
138  } else {
139  printinfix(fout, "@", 8, exp, delay);
140  }
141  return fout;
142 }
143 
144 // else if ( isSigFixDelay(sig, x, y) ) { printinfix(fout, "@", 8, x, y); }
145 
146 ostream& ppsig::printrec (ostream& fout, Tree var, Tree lexp, bool hide) const
147 {
148  if (isElement(var, fEnv) ) {
149  fout << *var;
150  } else if (hide) {
151  fout << *var;
152  } else {
153  fout << "letrec(" << *var << " = " << ppsig(lexp, addElement(var, fEnv)) << ")";
154  }
155  return fout;
156 }
157 
158 ostream& ppsig::printrec (ostream& fout, Tree lexp, bool hide) const
159 {
160  fout << "debruijn(" << ppsig(lexp,fEnv) << ")";
161  return fout;
162 }
163 
164 ostream& ppsig::printextended (ostream& fout, Tree sig) const
165 {
166  string sep = "";
167  xtended* p = (xtended*) getUserData(sig);
168 
169  fout << p->name() << '(';
170  for (int i = 0; i < sig->arity(); i++) {
171  fout << sep << ppsig(sig->branch(i), fEnv);
172  sep = ", ";
173  }
174  fout << ')';
175  return fout;
176 }
177 
178 
179 ostream& ppsig::print (ostream& fout) const
180 {
181  int i;
182  double r;
183  Tree c, sel, x, y, z, u, var, le, label, id, ff, largs, type, name, file;
184 
185  if ( isList(sig) ) { printlist(fout, sig); }
186  else if ( isProj(sig, &i, x) ) { fout << "proj" << i << '(' << ppsig(x, fEnv) << ')'; }
187  else if ( isRec(sig, var, le) ) { printrec(fout, var, le, fHideRecursion /*&& (getRecursivness(sig)==0)*/ ); }
188 
189  // debruinj notation
190  else if ( isRec(sig, le) ) { printrec(fout, le, fHideRecursion ); }
191  else if ( isRef(sig, i) ) { fout << "REF[" << i << "]"; }
192 
193  else if ( getUserData(sig) ) { printextended(fout, sig); }
194  else if ( isSigInt(sig, &i) ) { fout << i; }
195  else if ( isSigReal(sig, &r) ) { fout << T(r); }
196  else if ( isSigWaveform(sig) ) { fout << "waveform{...}"; }
197  else if ( isSigInput(sig, &i) ) { fout << "IN[" << i << "]"; }
198  else if ( isSigOutput(sig, &i, x) ) { printout(fout, i, x) ; }
199 
200  else if ( isSigDelay1(sig, x) ) { fout << ppsig(x, fEnv, 9) << "'"; }
201  //else if ( isSigFixDelay(sig, x, y) ) { printinfix(fout, "@", 8, x, y); }
202  else if ( isSigFixDelay(sig, x, y) ) { printFixDelay(fout, x, y); }
203  else if ( isSigPrefix(sig, x, y) ) { printfun(fout, "prefix", x, y); }
204  else if ( isSigIota(sig, x) ) { printfun(fout, "iota", x); }
205  else if ( isSigBinOp(sig, &i, x, y) ) { printinfix(fout, gBinOpTable[i]->fName, gBinOpTable[i]->fPriority, x, y); }
206  else if ( isSigFFun(sig, ff, largs) ) { printff(fout, ff, largs); }
207  else if ( isSigFConst(sig, type, name, file) ) { fout << tree2str(name); }
208  else if ( isSigFVar(sig, type, name, file) ) { fout << tree2str(name); }
209 
210  else if ( isSigTable(sig, id, x, y) ) { printfun(fout, "TABLE", x, y); }
211  else if ( isSigWRTbl(sig, id, x, y, z) ) { printfun(fout, "write", x, y, z); }
212  else if ( isSigRDTbl(sig, x, y) ) { printfun(fout, "read", x, y); }
213  else if ( isSigGen(sig, x) ) { fout << ppsig(x, fEnv, fPriority); }
214 
215  else if ( isSigDocConstantTbl(sig, x, y) ) { printfun(fout, "docConstantTbl", x, y); }
216  else if ( isSigDocWriteTbl(sig, x, y, z, u) ) { printfun(fout, "docWriteTbl", x, y, z, u); }
217  else if ( isSigDocAccessTbl(sig, x, y) ) { printfun(fout, "docAccessTbl", x, y); }
218 
219  else if ( isSigSelect2(sig, sel, x, y) ) { printfun(fout, "select2", sel, x, y); }
220  else if ( isSigSelect3(sig, sel, x, y, z) ) { printfun(fout, "select3", sel, x, y, z); }
221 
222  else if ( isSigIntCast(sig, x) ) { printfun(fout, "int", x); }
223  else if ( isSigFloatCast(sig, x) ) { printfun(fout, "float", x); }
224 
225  else if ( isSigButton(sig, label) ) { printui(fout, "button", label); }
226  else if ( isSigCheckbox(sig, label) ) { printui(fout, "checkbox", label); }
227  else if ( isSigVSlider(sig, label,c,x,y,z) ) { printui(fout, "vslider", label, c, x, y, z); }
228  else if ( isSigHSlider(sig, label,c,x,y,z) ) { printui(fout, "hslider", label, c, x, y, z); }
229  else if ( isSigNumEntry(sig, label,c,x,y,z) ) { printui(fout, "nentry", label, c, x, y, z); }
230  else if ( isSigVBargraph(sig, label,x,y,z) ) { printui(fout, "vbargraph", label, x, y, z); }
231  else if ( isSigHBargraph(sig, label,x,y,z) ) { printui(fout, "hbargraph", label, x, y, z); }
232  else if ( isSigAttach(sig, x, y) ) { printfun(fout, "attach", x, y); }
233 
234  else {
235  cerr << "NOT A SIGNAL : " << *sig << endl;
236  //exit(1);
237  }
238  return fout;
239 }
240 
bool isSigHSlider(Tree s)
Definition: signals.cpp:217
bool isSigRDTbl(Tree s, Tree &t, Tree &i)
Definition: signals.cpp:77
bool isSigFConst(Tree s)
Definition: signals.cpp:138
bool isSigPrefix(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:66
bool isSigCheckbox(Tree s)
Definition: signals.cpp:205
Tree addElement(Tree e, Tree l)
Definition: list.cpp:272
bool isSigFFun(Tree s, Tree &ff, Tree &largs)
Definition: signals.cpp:133
ostream & printff(ostream &fout, Tree ff, Tree largs) const
Definition: ppsig.cpp:126
bool isSigNumEntry(Tree s)
Definition: signals.cpp:257
bool isSigSelect2(Tree t, Tree &selector, Tree &s1, Tree &s2)
Definition: signals.cpp:116
int fPriority
priority context
Definition: ppsig.hh:52
ostream & printinfix(ostream &fout, const string &opname, int priority, Tree x, Tree y) const
Definition: ppsig.cpp:31
bool isSigIota(Tree t, Tree &t0)
Definition: signals.cpp:70
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const char * ffname(Tree t)
Definition: prim2.cpp:60
bool isSigInput(Tree t, int *i)
Definition: signals.cpp:48
bool isSigFixDelay(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:62
Tree hd(Tree l)
Definition: list.hh:133
const char * name()
Definition: xtended.hh:25
ostream & printrec(ostream &fout, Tree var, Tree lexp, bool hide) const
Definition: ppsig.cpp:146
bool isSigVBargraph(Tree s)
Definition: signals.cpp:285
bool isSigSelect3(Tree t, Tree &selector, Tree &s1, Tree &s2, Tree &s3)
Definition: signals.cpp:119
bool isSigVSlider(Tree s)
Definition: signals.cpp:237
ostream & printout(ostream &fout, int i, Tree x) const
Definition: ppsig.cpp:94
ostream & printfun(ostream &fout, const string &funame, Tree x) const
Definition: ppsig.cpp:39
bool isSigGen(Tree t, Tree &x)
Definition: signals.cpp:91
bool isNil(Tree l)
Definition: list.hh:137
bool isSigReal(Tree t, double *r)
Definition: signals.cpp:44
bool isRef(Tree t, int &level)
is t a de Bruijn recursive reference
ostream & printlist(ostream &fout, Tree largs) const
Definition: ppsig.cpp:113
bool isSigHBargraph(Tree s)
Definition: signals.cpp:279
bool isSigDocConstantTbl(Tree t, Tree &n, Tree &sig)
Definition: signals.cpp:99
bool isList(Tree l)
Definition: list.hh:138
bool isSigTable(Tree t, Tree &id, Tree &n, Tree &sig)
Definition: signals.cpp:85
Tree sig
Definition: ppsig.hh:50
Tree fEnv
recursive environment stack
Definition: ppsig.hh:51
string T(char *c)
Definition: Text.cpp:158
bool isSigBinOp(Tree s, int *op, Tree &x, Tree &y)
Definition: signals.cpp:126
ppsig(Tree s)
Definition: ppsig.hh:55
bool isSigAttach(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:291
ostream & printextended(ostream &fout, Tree sig) const
Definition: ppsig.cpp:164
bool isElement(const set< Loop * > &S, Loop *l)
Definition: klass.cpp:259
bool isSigDocAccessTbl(Tree t, Tree &tbl, Tree &ridx)
Definition: signals.cpp:107
bool isSigWRTbl(Tree u, Tree &id, Tree &t, Tree &i, Tree &s)
Definition: signals.cpp:81
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
bool isSigWaveform(Tree s)
Definition: signals.cpp:211
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
bool isSigInt(Tree t, int *i)
Definition: signals.cpp:41
bool isSigDocWriteTbl(Tree t, Tree &n, Tree &sig, Tree &widx, Tree &wsig)
Definition: signals.cpp:103
bool isSigDelay1(Tree t, Tree &t0)
Definition: signals.cpp:58
bool isSigFloatCast(Tree t)
Definition: signals.cpp:187
bool isSigFVar(Tree s)
Definition: signals.cpp:144
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
bool isSigIntCast(Tree t)
Definition: signals.cpp:184
BinOp * gBinOpTable[]
Definition: binop.cpp:28
bool fHideRecursion
Definition: ppsig.hh:53
bool isProj(Tree t, int *i, Tree &rgroup)
Definition: signals.cpp:151
ostream & printui(ostream &fout, const string &funame, Tree label) const
Definition: ppsig.cpp:64
ostream & printlabel(ostream &fout, Tree pathname) const
Definition: ppsig.cpp:102
ostream & printFixDelay(ostream &fout, Tree exp, Tree delay) const
Definition: ppsig.cpp:132
Tree tl(Tree l)
Definition: list.hh:134
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Definition: tree.cpp:278
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
ostream & print(ostream &fout) const
Definition: ppsig.cpp:179
bool isSigOutput(Tree t, int *i, Tree &t0)
Definition: signals.cpp:52
bool isSigButton(Tree s)
Definition: signals.cpp:199