/** * @brief Main code generator dispatch. * * According to the type of the input signal, generateCode calls * the appropriate generator with appropriate arguments. * * @param sig The signal expression to compile. * @param priority The environment priority of the expression. * @return <string> The LaTeX code translation of the signal. */ string DocCompiler::generateCode (Tree sig, int priority) { int i; double r; Tree c, sel, x, y, z, u, label, ff, largs, type, name, file; if ( getUserData(sig) ) { printGCCall(sig,"generateXtended"); return generateXtended (sig, priority); } else if ( isSigInt(sig, &i) ) { printGCCall(sig,"generateNumber"); return generateNumber (sig, docT(i)); } else if ( isSigReal(sig, &r) ) { printGCCall(sig,"generateNumber"); return generateNumber (sig, docT(r)); } else if ( isSigInput(sig, &i) ) { printGCCall(sig,"generateInput"); return generateInput (sig, docT(i+1)); } else if ( isSigOutput(sig, &i, x) ) { printGCCall(sig,"generateOutput"); return generateOutput (sig, docT(i+1), CS(x, priority)); } else if ( isSigFixDelay(sig, x, y) ) { printGCCall(sig,"generateFixDelay"); return generateFixDelay (sig, x, y, priority); } else if ( isSigPrefix(sig, x, y) ) { printGCCall(sig,"generatePrefix"); return generatePrefix (sig, x, y, priority); } else if ( isSigIota(sig, x) ) { printGCCall(sig,"generateIota"); return generateIota (sig, x); } else if ( isSigBinOp(sig, &i, x, y) ) { printGCCall(sig,"generateBinOp"); return generateBinOp (sig, i, x, y, priority); } else if ( isSigFFun(sig, ff, largs) ) { printGCCall(sig,"generateFFun"); return generateFFun (sig, ff, largs, priority); } else if ( isSigFConst(sig, type, name, file) ) { printGCCall(sig,"generateFConst"); return generateFConst (sig, tree2str(file), tree2str(name)); } else if ( isSigFVar(sig, type, name, file) ) { printGCCall(sig,"generateFVar"); return generateFVar (sig, tree2str(file), tree2str(name)); } // new special tables for documentation purposes else if ( isSigDocConstantTbl(sig, x, y) ) { printGCCall(sig,"generateDocConstantTbl"); return generateDocConstantTbl (sig, x, y); } else if ( isSigDocWriteTbl(sig,x,y,z,u) ) { printGCCall(sig,"generateDocWriteTbl"); return generateDocWriteTbl (sig, x, y, z, u); } else if ( isSigDocAccessTbl(sig, x, y) ) { printGCCall(sig, "generateDocAccessTbl"); return generateDocAccessTbl(sig, x, y); } else if ( isSigSelect2(sig, sel, x, y) ) { printGCCall(sig,"generateSelect2"); return generateSelect2 (sig, sel, x, y, priority); } else if ( isSigSelect3(sig, sel, x, y, z) ) { printGCCall(sig,"generateSelect3"); return generateSelect3 (sig, sel, x, y, z, priority); } else if ( isProj(sig, &i, x) ) { printGCCall(sig,"generateRecProj"); return generateRecProj (sig, x, i, priority); } else if ( isSigIntCast(sig, x) ) { printGCCall(sig,"generateIntCast"); return generateIntCast (sig, x, priority); } else if ( isSigFloatCast(sig, x) ) { printGCCall(sig,"generateFloatCast"); return generateFloatCast(sig, x, priority); } else if ( isSigButton(sig, label) ) { printGCCall(sig,"generateButton"); return generateButton (sig, label); } else if ( isSigCheckbox(sig, label) ) { printGCCall(sig,"generateCheckbox"); return generateCheckbox (sig, label); } else if ( isSigVSlider(sig, label,c,x,y,z) ) { printGCCall(sig,"generateVSlider"); return generateVSlider (sig, label, c,x,y,z); } else if ( isSigHSlider(sig, label,c,x,y,z) ) { printGCCall(sig,"generateHSlider"); return generateHSlider (sig, label, c,x,y,z); } else if ( isSigNumEntry(sig, label,c,x,y,z) ) { printGCCall(sig,"generateNumEntry"); return generateNumEntry (sig, label, c,x,y,z); } else if ( isSigVBargraph(sig, label,x,y,z) ) { printGCCall(sig,"generateVBargraph"); return CS(z, priority);}//generateVBargraph (sig, label, x, y, CS(z, priority)); } else if ( isSigHBargraph(sig, label,x,y,z) ) { printGCCall(sig,"generateHBargraph"); return CS(z, priority);}//generateHBargraph (sig, label, x, y, CS(z, priority)); } else if ( isSigAttach(sig, x, y) ) { printGCCall(sig,"generateAttach"); return generateAttach (sig, x, y, priority); } else if ( isSigEnable(sig, x, y) ) { printGCCall(sig,"generateEnable"); return generateEnable (sig, x, y, priority); } else { stringstream error; error << "ERROR in d signal, unrecognized signal : " << *sig << endl; throw faustexception(error.str()); } faustassert(0); return "error in generate code"; }
/** * Test if exp is very simple that is it * can't be considered a real component * @param exp the signal we want to test * @return true if it a very simple signal */ bool verySimple(Tree exp) { int i; double r; Tree type, name, file; return isSigInt(exp, &i) || isSigReal(exp, &r) || isSigInput(exp, &i) || isSigFConst(exp, type, name, file); }
/** * Test if exp is very simple that is it * can't be considered a real component * @param exp the signal we want to test * @return true if it a very simple signal */ static bool isVerySimpleFormula(Tree sig) { int i; double r; Tree type, name, file, label, c, x, y, z; return isSigInt(sig, &i) || isSigReal(sig, &r) || isSigInput(sig, &i) || isSigFConst(sig, type, name, file) || isSigButton(sig, label) || isSigCheckbox(sig, label) || isSigVSlider(sig, label, c, x, y, z) || isSigHSlider(sig, label, c, x, y, z) || isSigNumEntry(sig, label, c, x, y, z) ; }
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; }
/** * Infere the order of a term according to its components * @param sig the signal to analyze * @return the order of sig */ static int infereSigOrder(Tree sig) { int i; double r; Tree sel, s1, s2, s3, s4, ff, id, ls, l, x, y, var, body, type, name, file; xtended* xt = (xtended*) getUserData(sig); // primitive elements if (xt) { //return 3; vector<int> args; for (int i=0; i<sig->arity(); i++) { args.push_back( O(sig->branch(i)) ); } return xt->infereSigOrder(args); } else if (isSigInt(sig, &i)) return 0; else if (isSigReal(sig, &r)) return 0; else if (isSigInput(sig, &i)) return 3; else if (isSigOutput(sig, &i, s1)) return 3; else if (isSigDelay1(sig, s1)) return 3; else if (isSigPrefix(sig, s1, s2)) return 3; else if (isSigFixDelay(sig, s1, s2)) return 3; else if (isSigBinOp(sig, &i, s1, s2)) return max(O(s1),O(s2)); else if (isSigIntCast(sig, s1)) return O(s1); else if (isSigFloatCast(sig, s1)) return O(s1); else if (isSigFFun(sig,ff,ls) && isNil(ls)) return 1; else if (isSigFFun(sig, ff, ls)) return max(1,O(ls)); else if (isSigFConst(sig,type,name,file)) return 1; else if (isSigFVar(sig,type,name,file)) return 2; else if (isSigButton(sig)) return 2; else if (isSigCheckbox(sig)) return 2; else if (isSigVSlider(sig)) return 2; else if (isSigHSlider(sig)) return 2; else if (isSigNumEntry(sig)) return 2; else if (isSigHBargraph(sig, l, x, y, s1)) return O(s1); else if (isSigVBargraph(sig, l, x, y, s1)) return O(s1); else if (isSigAttach(sig, s1, s2)) return O(s1); else if (isRec(sig, var, body)) exit(1); //return 3; // not supposed to happen. else if (isRef(sig, var)) exit(1); //return 3; // not supposed to happen. else if (isProj(sig, &i, s1)) return 3; else if (isSigTable(sig, id, s1, s2)) return 3; else if (isSigWRTbl(sig, id, s1, s2, s3)) return 3; else if (isSigRDTbl(sig, s1, s2)) return 3; else if (isSigDocConstantTbl(sig, s1, s2)) return 3; else if (isSigDocWriteTbl(sig,s1,s2,s3,s4)) return 3; else if (isSigDocAccessTbl(sig,s1,s2)) return 3; else if (isSigGen(sig, s1)) return 3; else if (isSigSelect2(sig,sel,s1,s2)) return 3; else if (isSigSelect3(sig,sel,s1,s2,s3)) return 3; else if (isList(sig)) { int r = 0; while (isList(sig)) { int x = O(hd(sig)); if (x > r) r = x; sig = tl(sig); } return r; } // unrecognized signal here fprintf(stderr, "ERROR infering signal order : unrecognized signal : "); print(sig, stderr); fprintf(stderr, "\n"); exit(1); return 0; }