ostream& ppsig::printinfix (ostream& fout, const string& opname, int priority, Tree x, Tree y) const { if (fPriority > priority) fout << "("; fout << ppsig(x,fEnv,priority) << opname << ppsig(y,fEnv,priority); if (fPriority > priority) fout << ")"; return fout; }
static Tree traced_simplification(Tree sig) { assert(sig); #ifdef TRACE cerr << ++TABBER << "Start simplification of : " << ppsig(sig) << endl; /* fprintf(stderr, "\nStart simplification of : "); printSignal(sig, stderr); fprintf(stderr, "\n"); */ #endif Tree r = simplification(sig); assert(r!=0); #ifdef TRACE cerr << --TABBER << "Simplification of : " << ppsig(sig) << " Returns : " << ppsig(r) << endl; /* fprintf(stderr, "Simplification of : "); printSignal(sig, stderr); fprintf(stderr, " -> "); printSignal(r, stderr); fprintf(stderr, "\n"); */ #endif return r; }
ostream& ppsig::printui (ostream& fout, const string& funame, Tree label, Tree lo, Tree hi, Tree step) const { fout << funame << '('; printlabel(fout, label); return fout << ',' << ppsig(lo,fEnv) << ',' << ppsig(hi,fEnv) << ',' << ppsig(step,fEnv) << ')'; }
/** * Generate LaTeX code for "prefix", a 1sample-delay explicitely initialized. * * @param sig The signal expression to treat. * @param x The initial value for the delay line. * @param e The value for the delay line, after initialization. * @param priority The priority of the environment of the expression. * * @return <string> The LaTeX code translation of the signal, cached. */ string DocCompiler::generatePrefix(Tree sig, Tree x, Tree e, int priority) { string var = getFreshID("m"); string exp0 = CS(x, priority); string exp1 = CS(e, priority); // ensure exp1 is compiled to have a vector name string vecname; if(!getVectorNameProperty(e, vecname)) { cerr << "No vector name for : " << ppsig(e) << endl; assert(0); } string ltqPrefixDef; ltqPrefixDef += subst("$0(t) = \n", var); ltqPrefixDef += "\\left\\{\\begin{array}{ll}\n"; ltqPrefixDef += subst("$0 & \\mbox{, when \\,} t = 0\\\\\n", exp0); ltqPrefixDef += subst("$0 & \\mbox{, when \\,} t > 0\n", subst("$0(t\\!-\\!1)", vecname)); ltqPrefixDef += "\\end{array}\\right."; fLateq->addPrefixSigFormula(ltqPrefixDef); gDocNoticeFlagMap["prefixsigs"] = true; return generateCacheCode(sig, subst("$0(t)", var)); }
ostream& ppsig::printout (ostream& fout, int i, Tree x) const { if (fPriority > 0) fout << "("; fout << "OUT" << i << " = " << ppsig(x, fEnv, 0); if (fPriority > 0) fout << ")"; return fout; }
ostream& ppsig::printrec (ostream& fout, Tree var, Tree lexp, bool hide) const { if (isElement(var, fEnv) ) { fout << *var; } else if (hide) { fout << *var; } else { fout << "letrec(" << *var << " = " << ppsig(lexp, addElement(var, fEnv)) << ")"; } return fout; }
ostream& ppsig::printFixDelay (ostream& fout, Tree exp, Tree delay) const { int d; if (isSigInt(delay, &d) && (d==1)) { fout << ppsig(exp,fEnv,8) << "'"; } else { printinfix(fout, "@", 8, exp, delay); } return fout; }
ostream& ppsig::printlist (ostream& fout, Tree largs) const { string sep = ""; fout << '('; while (!isNil(largs)) { fout << sep << ppsig(hd(largs), fEnv); sep = ", "; largs = tl(largs); } fout << ')'; return fout; }
ostream& ppsig::printextended (ostream& fout, Tree sig) const { string sep = ""; xtended* p = (xtended*) getUserData(sig); fout << p->name() << '('; for (int i = 0; i < sig->arity(); i++) { fout << sep << ppsig(sig->branch(i), fEnv); sep = ", "; } fout << ')'; return fout; }
/** * Print calling information of generateCode, for debug purposes. * * @remark * To turn printing on, turn the 'printCalls' boolean to true. */ void DocCompiler::printGCCall(Tree sig, const string& calledFunction) { bool printCalls = false; bool maskSigs = false; if(printCalls) { cerr << " -> generateCode calls " << calledFunction; if(maskSigs) { cerr << endl; } else { cerr << " on " << ppsig(sig) << endl; } } }
string VectorCompiler::generateFixDelay (Tree sig, Tree exp, Tree delay) { int mxd, d; string vecname; //cerr << "VectorCompiler::generateFixDelay " << ppsig(sig) << endl; CS(exp); // ensure exp is compiled to have a vector name mxd = fOccMarkup.retrieve(exp)->getMaxDelay(); if (! getVectorNameProperty(exp, vecname)) { cerr << "ERROR no vector name for " << ppsig(exp) << endl; exit(1); } if (mxd == 0) { // not a real vector name but a scalar name return subst("$0[i]", vecname); } else if (mxd < gMaxCopyDelay){ if (isSigInt(delay, &d)) { if (d == 0) { return subst("$0[i]", vecname); } else { return subst("$0[i-$1]", vecname, T(d)); } } else { return subst("$0[i-$1]", vecname, CS(delay)); } } else { // long delay : we use a ring buffer of size 2^x int N = pow2limit( mxd+gVecSize ); if (isSigInt(delay, &d)) { if (d == 0) { return subst("$0[($0_idx+i)&$1]", vecname, T(N-1)); } else { return subst("$0[($0_idx+i-$2)&$1]", vecname, T(N-1), T(d)); } } else { return subst("$0[($0_idx+i-$2)&$1]", vecname, T(N-1), CS(delay)); } } }
/** * Generate code for accessing a delayed signal. The generated code depend of * the maximum delay attached to exp and the gGlobal->gLessTempSwitch. * * @todo Priorités à revoir pour le parenthésage (associativité de - et /), * avec gBinOpLateqTable dans binop.cpp. */ string DocCompiler::generateFixDelay (Tree sig, Tree exp, Tree delay, int priority) { int d; string vecname; CS(exp, 0); // ensure exp is compiled to have a vector name if (! getVectorNameProperty(exp, vecname)) { cerr << "No vector name for : " << ppsig(exp) << endl; faustassert(0); } if (isSigInt(delay, &d) && (d == 0)) { //cerr << "@ generateFixDelay : d = " << d << endl; return subst("$0(t)", vecname); } else { //cerr << "@ generateFixDelay : d = " << d << endl; return subst("$0(t\\!-\\!$1)", vecname, CS(delay, 7)); } }
ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z, Tree z2, Tree z3) const { return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ',' << ppsig(z2,fEnv) << ',' << ppsig(z3,fEnv) << ')'; }
ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x) const { return fout << funame << '(' << ppsig(x,fEnv) << ')'; }
ostream& ppsig::print (ostream& fout) const { int i; double r; Tree c, sel, x, y, z, u, var, le, label, id, ff, largs, type, name, file; if ( isList(sig) ) { printlist(fout, sig); } else if ( isProj(sig, &i, x) ) { fout << "proj" << i << '(' << ppsig(x, fEnv) << ')'; } else if ( isRec(sig, var, le) ) { printrec(fout, var, le, fHideRecursion /*&& (getRecursivness(sig)==0)*/ ); } // debruinj notation else if ( isRec(sig, le) ) { printrec(fout, le, fHideRecursion ); } else if ( isRef(sig, i) ) { fout << "REF[" << i << "]"; } else if ( getUserData(sig) ) { printextended(fout, sig); } else if ( isSigInt(sig, &i) ) { fout << i; } else if ( isSigReal(sig, &r) ) { fout << T(r); } else if ( isSigWaveform(sig) ) { fout << "waveform{...}"; } else if ( isSigInput(sig, &i) ) { fout << "IN[" << i << "]"; } else if ( isSigOutput(sig, &i, x) ) { printout(fout, i, x) ; } else if ( isSigDelay1(sig, x) ) { fout << ppsig(x, fEnv, 9) << "'"; } //else if ( isSigFixDelay(sig, x, y) ) { printinfix(fout, "@", 8, x, y); } else if ( isSigFixDelay(sig, x, y) ) { printFixDelay(fout, x, y); } else if ( isSigPrefix(sig, x, y) ) { printfun(fout, "prefix", x, y); } else if ( isSigIota(sig, x) ) { printfun(fout, "iota", x); } else if ( isSigBinOp(sig, &i, x, y) ) { printinfix(fout, gBinOpTable[i]->fName, gBinOpTable[i]->fPriority, x, y); } else if ( isSigFFun(sig, ff, largs) ) { printff(fout, ff, largs); } else if ( isSigFConst(sig, type, name, file) ) { fout << tree2str(name); } else if ( isSigFVar(sig, type, name, file) ) { fout << tree2str(name); } else if ( isSigTable(sig, id, x, y) ) { printfun(fout, "TABLE", x, y); } else if ( isSigWRTbl(sig, id, x, y, z) ) { printfun(fout, "write", x, y, z); } else if ( isSigRDTbl(sig, x, y) ) { printfun(fout, "read", x, y); } else if ( isSigGen(sig, x) ) { fout << ppsig(x, fEnv, fPriority); } else if ( isSigDocConstantTbl(sig, x, y) ) { printfun(fout, "docConstantTbl", x, y); } else if ( isSigDocWriteTbl(sig, x, y, z, u) ) { printfun(fout, "docWriteTbl", x, y, z, u); } else if ( isSigDocAccessTbl(sig, x, y) ) { printfun(fout, "docAccessTbl", x, y); } else if ( isSigSelect2(sig, sel, x, y) ) { printfun(fout, "select2", sel, x, y); } else if ( isSigSelect3(sig, sel, x, y, z) ) { printfun(fout, "select3", sel, x, y, z); } else if ( isSigIntCast(sig, x) ) { printfun(fout, "int", x); } else if ( isSigFloatCast(sig, x) ) { printfun(fout, "float", x); } else if ( isSigButton(sig, label) ) { printui(fout, "button", label); } else if ( isSigCheckbox(sig, label) ) { printui(fout, "checkbox", label); } else if ( isSigVSlider(sig, label,c,x,y,z) ) { printui(fout, "vslider", label, c, x, y, z); } else if ( isSigHSlider(sig, label,c,x,y,z) ) { printui(fout, "hslider", label, c, x, y, z); } else if ( isSigNumEntry(sig, label,c,x,y,z) ) { printui(fout, "nentry", label, c, x, y, z); } else if ( isSigVBargraph(sig, label,x,y,z) ) { printui(fout, "vbargraph", label, x, y, z); } else if ( isSigHBargraph(sig, label,x,y,z) ) { printui(fout, "hbargraph", label, x, y, z); } else if ( isSigAttach(sig, x, y) ) { printfun(fout, "attach", x, y); } else { cerr << "NOT A SIGNAL : " << *sig << endl; //exit(1); } return fout; }
ostream& ppsig::printrec (ostream& fout, Tree lexp, bool hide) const { fout << "debruijn(" << ppsig(lexp,fEnv) << ")"; return fout; }