|
FAUST compiler
0.9.9.6b8
|
00001 /************************************************************************ 00002 ************************************************************************ 00003 FAUST compiler 00004 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale 00005 --------------------------------------------------------------------- 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 ************************************************************************ 00020 ************************************************************************/ 00021 00022 00023 00024 #include "ppsig.hh" 00025 #include "binop.hh" 00026 #include "prim2.hh" 00027 #include "xtended.hh" 00028 #include "recursivness.hh" 00029 00030 ostream& ppsig::printinfix (ostream& fout, const string& opname, int priority, Tree x, Tree y) const 00031 { 00032 if (fPriority > priority) fout << "("; 00033 fout << ppsig(x,fEnv,priority) << opname << ppsig(y,fEnv,priority); 00034 if (fPriority > priority) fout << ")"; 00035 return fout; 00036 } 00037 00038 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x) const 00039 { 00040 return fout << funame << '(' << ppsig(x,fEnv) << ')'; 00041 } 00042 00043 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y) const 00044 { 00045 return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ')'; 00046 } 00047 00048 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z) const 00049 { 00050 return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ')'; 00051 } 00052 00053 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z, Tree zz) const 00054 { 00055 return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ',' << ppsig(zz,fEnv) << ')'; 00056 } 00057 00058 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z, Tree z2, Tree z3) const 00059 { 00060 return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ',' << ppsig(z2,fEnv) << ',' << ppsig(z3,fEnv) << ')'; 00061 } 00062 00063 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label) const 00064 { 00065 fout << funame << '('; 00066 printlabel(fout, label); 00067 return fout << ')'; 00068 } 00069 00070 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label, Tree lo, Tree hi, Tree step) const 00071 { 00072 fout << funame << '('; 00073 printlabel(fout, label); 00074 return fout 00075 << ',' << ppsig(lo,fEnv) 00076 << ',' << ppsig(hi,fEnv) 00077 << ',' << ppsig(step,fEnv) 00078 << ')'; 00079 } 00080 00081 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label, Tree cur, Tree lo, Tree hi, Tree step) const 00082 { 00083 fout << funame << '('; 00084 printlabel(fout, label); 00085 return fout 00086 << ',' << ppsig(cur,fEnv) 00087 << ',' << ppsig(lo,fEnv) 00088 << ',' << ppsig(hi,fEnv) 00089 << ',' << ppsig(step,fEnv) 00090 << ')'; 00091 } 00092 00093 ostream& ppsig::printout (ostream& fout, int i, Tree x) const 00094 { 00095 if (fPriority > 0) fout << "("; 00096 fout << "OUT" << i << " = " << ppsig(x, fEnv, 0); 00097 if (fPriority > 0) fout << ")"; 00098 return fout; 00099 } 00100 00101 ostream& ppsig::printlabel (ostream& fout, Tree pathname) const 00102 { 00103 fout << *hd(pathname); 00104 pathname = tl(pathname); 00105 while (!isNil(pathname)) { 00106 fout << '/' << *tl(hd(pathname)); 00107 pathname = tl(pathname); 00108 } 00109 return fout; 00110 } 00111 00112 ostream& ppsig::printlist (ostream& fout, Tree largs) const 00113 { 00114 string sep = ""; 00115 fout << '('; 00116 while (!isNil(largs)) { 00117 fout << sep << ppsig(hd(largs), fEnv); 00118 sep = ", "; 00119 largs = tl(largs); 00120 } 00121 fout << ')'; 00122 return fout; 00123 } 00124 00125 ostream& ppsig::printff (ostream& fout, Tree ff, Tree largs) const 00126 { 00127 fout << ffname(ff); printlist(fout, largs); 00128 return fout; 00129 } 00130 00131 ostream& ppsig::printFixDelay (ostream& fout, Tree exp, Tree delay) const 00132 { 00133 int d; 00134 00135 if (isSigInt(delay, &d) && (d==1)) { 00136 fout << ppsig(exp,fEnv,8) << "'"; 00137 } else { 00138 printinfix(fout, "@", 8, exp, delay); 00139 } 00140 return fout; 00141 } 00142 00143 // else if ( isSigFixDelay(sig, x, y) ) { printinfix(fout, "@", 8, x, y); } 00144 00145 ostream& ppsig::printrec (ostream& fout, Tree var, Tree lexp, bool hide) const 00146 { 00147 if (isElement(var, fEnv) ) { 00148 fout << *var; 00149 } else if (hide) { 00150 fout << *var; 00151 } else { 00152 fout << "letrec(" << *var << " = " << ppsig(lexp, addElement(var, fEnv)) << ")"; 00153 } 00154 return fout; 00155 } 00156 00157 ostream& ppsig::printrec (ostream& fout, Tree lexp, bool hide) const 00158 { 00159 fout << "debruijn(" << ppsig(lexp,fEnv) << ")"; 00160 return fout; 00161 } 00162 00163 ostream& ppsig::printextended (ostream& fout, Tree sig) const 00164 { 00165 string sep = ""; 00166 xtended* p = (xtended*) getUserData(sig); 00167 00168 fout << p->name() << '('; 00169 for (int i = 0; i < sig->arity(); i++) { 00170 fout << sep << ppsig(sig->branch(i), fEnv); 00171 sep = ", "; 00172 } 00173 fout << ')'; 00174 return fout; 00175 } 00176 00177 00178 ostream& ppsig::print (ostream& fout) const 00179 { 00180 int i; 00181 double r; 00182 Tree c, sel, x, y, z, u, var, le, label, id, ff, largs, type, name, file; 00183 00184 if ( isList(sig) ) { printlist(fout, sig); } 00185 else if ( isProj(sig, &i, x) ) { fout << "proj" << i << '(' << ppsig(x, fEnv) << ')'; } 00186 else if ( isRec(sig, var, le) ) { printrec(fout, var, le, fHideRecursion /*&& (getRecursivness(sig)==0)*/ ); } 00187 00188 // debruinj notation 00189 else if ( isRec(sig, le) ) { printrec(fout, le, fHideRecursion ); } 00190 else if ( isRef(sig, i) ) { fout << "REF[" << i << "]"; } 00191 00192 else if ( getUserData(sig) ) { printextended(fout, sig); } 00193 else if ( isSigInt(sig, &i) ) { fout << i; } 00194 else if ( isSigReal(sig, &r) ) { fout << r; } 00195 else if ( isSigInput(sig, &i) ) { fout << "IN[" << i << "]"; } 00196 else if ( isSigOutput(sig, &i, x) ) { printout(fout, i, x) ; } 00197 00198 else if ( isSigDelay1(sig, x) ) { fout << ppsig(x, fEnv, 9) << "'"; } 00199 //else if ( isSigFixDelay(sig, x, y) ) { printinfix(fout, "@", 8, x, y); } 00200 else if ( isSigFixDelay(sig, x, y) ) { printFixDelay(fout, x, y); } 00201 else if ( isSigPrefix(sig, x, y) ) { printfun(fout, "prefix", x, y); } 00202 else if ( isSigIota(sig, x) ) { printfun(fout, "iota", x); } 00203 else if ( isSigBinOp(sig, &i, x, y) ) { printinfix(fout, gBinOpTable[i]->fName, gBinOpTable[i]->fPriority, x, y); } 00204 else if ( isSigFFun(sig, ff, largs) ) { printff(fout, ff, largs); } 00205 else if ( isSigFConst(sig, type, name, file) ) { fout << tree2str(name); } 00206 else if ( isSigFVar(sig, type, name, file) ) { fout << tree2str(name); } 00207 00208 else if ( isSigTable(sig, id, x, y) ) { printfun(fout, "TABLE", x, y); } 00209 else if ( isSigWRTbl(sig, id, x, y, z) ) { printfun(fout, "write", x, y, z); } 00210 else if ( isSigRDTbl(sig, x, y) ) { printfun(fout, "read", x, y); } 00211 else if ( isSigGen(sig, x) ) { fout << ppsig(x, fEnv, fPriority); } 00212 00213 else if ( isSigDocConstantTbl(sig, x, y) ) { printfun(fout, "docConstantTbl", x, y); } 00214 else if ( isSigDocWriteTbl(sig, x, y, z, u) ) { printfun(fout, "docWriteTbl", x, y, z, u); } 00215 else if ( isSigDocAccessTbl(sig, x, y) ) { printfun(fout, "docAccessTbl", x, y); } 00216 00217 else if ( isSigSelect2(sig, sel, x, y) ) { printfun(fout, "select2", sel, x, y); } 00218 else if ( isSigSelect3(sig, sel, x, y, z) ) { printfun(fout, "select3", sel, x, y, z); } 00219 00220 else if ( isSigIntCast(sig, x) ) { printfun(fout, "int", x); } 00221 else if ( isSigFloatCast(sig, x) ) { printfun(fout, "float", x); } 00222 00223 else if ( isSigButton(sig, label) ) { printui(fout, "button", label); } 00224 else if ( isSigCheckbox(sig, label) ) { printui(fout, "checkbox", label); } 00225 else if ( isSigVSlider(sig, label,c,x,y,z) ) { printui(fout, "vslider", label, c, x, y, z); } 00226 else if ( isSigHSlider(sig, label,c,x,y,z) ) { printui(fout, "hslider", label, c, x, y, z); } 00227 else if ( isSigNumEntry(sig, label,c,x,y,z) ) { printui(fout, "nentry", label, c, x, y, z); } 00228 else if ( isSigVBargraph(sig, label,x,y,z) ) { printui(fout, "vbargraph", label, x, y, z); } 00229 else if ( isSigHBargraph(sig, label,x,y,z) ) { printui(fout, "hbargraph", label, x, y, z); } 00230 else if ( isSigAttach(sig, x, y) ) { printfun(fout, "attach", x, y); } 00231 00232 else { 00233 cerr << "NOT A SIGNAL : " << *sig << endl; 00234 //exit(1); 00235 } 00236 return fout; 00237 } 00238
1.8.0