コード例 #1
0
ファイル: privatise.cpp プロジェクト: EBone/faust-1
static Tree labelize(const Tree& newid, const Tree& exp)
{
	Tree	tbl, size, idx, wrt, content, oldid;

	if ( isSigWRTbl(exp, oldid, tbl, idx, wrt) ) 	{
		/*	Ce qui ne peut pas être partagé, ce sont les
			tables dans lesquelles on ecrit. Pour cela
			on leur donne un label unique
		*/
		return sigWRTbl(newid, tbl, idx, wrt);

	} else  if ( isSigTable(exp, oldid, size, content) ) {
		/*	Rien à privatiser dans une table (car size est
			censée etre une expression entiere)
		*/
		return sigTable(newid, size, content);

	} else {

		printf("erreur labelize\n");
		exit(1);
	}

	return exp;
}
コード例 #2
0
ファイル: simplify.cpp プロジェクト: gauravchawla03/Stanford
static Tree docTableConverter (Tree sig)
{
    Tree tbl, tbl2, id, id2, size, igen, isig, ridx, widx, wsig;

    if (isSigRDTbl(sig, tbl, ridx)) {
        // we are in a table to convert
        if (isSigTable(tbl, id, size, igen)) {
            // it's a read only table
            assert(isSigGen(igen, isig));
            return sigDocAccessTbl(sigDocConstantTbl(size,isig),ridx);
        } else {
            // it's a read write table
            assert(isSigWRTbl(tbl,id,tbl2,widx,wsig));
            assert(isSigTable(tbl2, id2, size, igen));
            assert(isSigGen(igen, isig));

            return sigDocAccessTbl(sigDocWriteTbl(size,isig,widx,wsig),ridx);
        }

    } else {
        // nothing to convert
        return sig;
    }
}
コード例 #3
0
ファイル: privatise.cpp プロジェクト: EBone/faust-1
static Tree computePrivatisation(const Tree& k, const Tree& exp)
{
	Tree	tbl, size, idx, wrt, content, id, var, body;

	if ( isSigWRTbl(exp, id, tbl, idx, wrt) ) 	{
		/*	Ce qui ne peut pas être partagé, ce sont les
			tables dans lesquelles on ecrit. Pour cela
			on leur donne un label unique
		*/
		return sigWRTbl(
					id,
					labelize( makePrivatisationLabel(exp), privatisation(k, tbl) ),
					privatisation(k, idx),
					privatisation(k, wrt) );

	} else if ( isSigTable(exp, id, size, content) ) {
		/*	Rien à privatiser dans une table (car size est
			censée etre une expression entiere)
		*/
		return exp;

	} else if ( isSigGen(exp, content) ) {
		/*	On ne visite pas les contenus des tables
		*/
		printf("erreur 1 dans computePrivatisation\n");
		exit(1);

	} else if ( isRec(exp, var, body) ) {
		/*	On ne visite pas les contenus des tables
		*/
		setProperty(exp, k, nil);
		return rec(var, privatisation(k,body));

	} else {
		/*	On parcours les autres arbres en privatisant les branches
		*/

        tvec br;
        int n = exp->arity();
        for (int i = 0; i < n; i++) {
            br.push_back( privatisation(k,exp->branch(i)) );
        }

        return tree(exp->node(), br);

    }
}
コード例 #4
0
ファイル: sigprint.cpp プロジェクト: EBone/faust-1
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);
}
コード例 #5
0
ファイル: ppsig.cpp プロジェクト: kitchenSinkCollection/faust
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;
}
コード例 #6
0
/**
 * 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;
}