Beispiel #1
0
static bool isBoxNumeric (Tree in, Tree& out)
{
    int 	numInputs, numOutputs;
    double 	x;
    int		i;
    Tree 	v, abstr, genv, vis, lenv, var, body;

    if (isBoxInt(in, &i) || isBoxReal(in, &x)) {
        out = in;
        return true;
    } else if (isClosure(in, abstr, genv, vis, lenv) && isBoxAbstr(abstr, var, body)) {
        return false;
    } else {
        v = a2sb(in);
        if ( getBoxType(v, &numInputs, &numOutputs) && (numInputs == 0) && (numOutputs == 1) ) {
            // potential numerical expression
            Tree lsignals = boxPropagateSig(gGlobal->nil, v , makeSigInputList(numInputs) );
            Tree res = simplify(hd(lsignals));
            if (isSigReal(res, &x)) 	{
                out = boxReal(x);
                return true;
            }
            if (isSigInt(res, &i))  	{
                out = boxInt(i);
                return true;
            }
        }
        return false;
    }
}
Beispiel #2
0
/**
 * @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";
}
Beispiel #3
0
/**
 * 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);
}
Beispiel #4
0
/**
 * 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)
  ;
}
Beispiel #5
0
/**
 * Try to do a numeric simplification of a block-diagram
 */
Tree numericBoxSimplification(Tree box)
{
    int     ins, outs;
    Tree    result;
    int     i;
    double  x;

    if (!getBoxType(box, &ins, &outs)) {
        stringstream error;
        error << "ERROR in file " << __FILE__ << ':' << __LINE__ << ", Can't compute the box type of : " << *box << endl;
        throw faustexception(error.str());
    }

    if (ins==0 && outs==1) {
        // this box can potentially denote a number
        if (isBoxInt(box, &i) || isBoxReal(box, &x)) {
           result = box;
        } else {
            // propagate signals to discover if it simplifies to a number
            int     i;
            double  x;
            Tree    lsignals = boxPropagateSig(gGlobal->nil, box , makeSigInputList(0));
            Tree    s = simplify(hd(lsignals));

            if (isSigReal(s, &x)) 	{
                result = boxReal(x);
            } else if (isSigInt(s, &i))  	{
                result = boxInt(i);
            } else {
                result = insideBoxSimplification(box);
            }
        }
    } else {
        // this box can't denote a number
        result = insideBoxSimplification(box);
    }
    return result;
}
Beispiel #6
0
void printSignal(Tree sig, FILE* out, int prec)
{
	int 	i;
	double	r;
    Tree 	 x, y, z, u, le, id;
	    
		 if ( isSigInt(sig, &i) ) 			{ fprintf(out, "%d", i); 	}
	else if ( isSigReal(sig, &r) ) 			{ fprintf(out, "%f", r); 	}
	else if ( isSigInput(sig, &i) ) 		{ fprintf(out, "IN%d", i);	}
	else if ( isSigOutput(sig, &i, x) ) 	{ fprintf(out, "OUT%d := ", i); printSignal(x, out, 0); }
	
	else if ( isSigBinOp(sig, &i, x, y) )	{ 
		if (prec > binopprec[i]) fputs("(", out); 
		printSignal(x,out,binopprec[i]); fputs(binopname[i], out); printSignal(y, out, binopprec[i]); 
		if (prec > binopprec[i]) fputs(")", out); 	
	}
	else if ( isSigDelay1(sig, x) ) 		{ fputs("mem(", out); printSignal(x,out,0); fputs(")", out);		}
	else if ( isSigPrefix(sig, x, y) ) 		{ fputs("prefix(", out); printSignal(x,out,0); fputs(",", out);	 printSignal(y,out,0); fputs(")", out);		}
	else if ( isSigAttach(sig, x, y) ) 		{ fputs("attach(", out); printSignal(x,out,0); fputs(",", out);	 printSignal(y,out,0); fputs(")", out);		}
	else if ( isSigFixDelay(sig, x, y) ) 	{ 
		if (prec > 4) fputs("(", out); 
		printSignal(x,out,4); fputs("@", out); printSignal(y, out, 4); 
		if (prec > 4) fputs(")", out); 	
	}

	else if ( isProj(sig, &i, x) ) 			{ printSignal(x,out,prec); fprintf(out, "#%d", i); 		}
    else if ( isRef(sig, i) ) 				{ fprintf(out, "$%d", i);	}
	else if ( isRef(sig, x) ) 				{ print(x, out); 			}
	else if ( isRec(sig, le))				{ fputs("\\_.", out); printSignal(le, out, prec);	}
	else if ( isRec(sig, x, le))			{ fputs("\\", out); print(x,out); fputs(".", out); printSignal(le, out, prec);	}
	
	else if ( isSigTable(sig, id, x, y) ) 	{ fputs("table(", out); printSignal(x,out,0); fputc(',', out); printSignal(y,out,0); fputc(')', out);   }
	else if ( isSigWRTbl(sig, id, x, y, z) ){ printSignal(x,out,0); fputc('[',out); printSignal(y,out,0); fputs("] := (", out); printSignal(z,out,0); fputc(')', out);   }
	else if ( isSigRDTbl(sig, x, y) ) 		{ printSignal(x,out,0); fputc('[', out); printSignal(y,out,0); fputc(']', out);   }

    else if (isSigDocConstantTbl(sig,x,y)) 	{ fputs("sigDocConstantTbl(", out); printSignal(x,out,0); fputc(',', out);
                                                                                printSignal(y,out,0); fputc(')', out);   }

    else if (isSigDocWriteTbl(sig,x,y,z,u)) { fputs("sigDocWriteTbl(", out);    printSignal(x,out,0); fputc(',', out);
                                                                                printSignal(y,out,0); fputc(',', out);
                                                                                printSignal(z,out,0); fputc(',', out);
                                                                                printSignal(u,out,0); fputc(')', out);   }

    else if (isSigDocAccessTbl(sig,x,y)) 	{ fputs("sigDocAccessTbl(", out);   printSignal(x,out,0); fputc(',', out);
                                                                                printSignal(y,out,0); fputc(')', out);   }


	else if ( isSigGen(sig, x) ) 			{ printSignal(x,out,prec); 				}
 
	else if ( isSigIntCast(sig, x) ) 		{ fputs("int(", out); printSignal(x,out,0); fputs(")", out);		}
	else if ( isSigFloatCast(sig, x) ) 		{ fputs("float(", out); printSignal(x,out,0); fputs(")", out);		}

	else if (isList(sig)) {
		char sep = '{';
		do { 
			fputc(sep, out);
			printSignal(hd(sig), out, 0);
			sep=',';
			sig = tl(sig);
		} while (isList(sig));
		fputc('}', out);
	}
	else
		print(sig, out);
}
Beispiel #7
0
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;
}