ScalarCompiler Class Reference

Compile a list of FAUST signals into a scalar C++ class. More...

#include <compile_scal.hh>

Inherits Compiler.

List of all members.

Public Member Functions

virtual string CS (Tree sig)
 Compile a signal.

Private Member Functions

bool getCompiledExpression (Tree sig, string &name)
 Test if a signal is already compiled.
string setCompiledExpression (Tree sig, const string &name)
 Set the string of a compiled expression is already compiled.
void setVectorNameProperty (Tree sig, const string &vecname)
 Set the vector name property of a signal, the name of the vector used to store the previous values of the signal to implement a delay.
bool getVectorNameProperty (Tree sig, string &vecname)
 Get the vector name property of a signal, the name of the vector used to store the previous values of the signal to implement a delay.
string generateCode (Tree sig)
 Main code generator dispatch.
string generateXtended (Tree sig)
 retrieve the type annotation of sig
string generateFixDelay (Tree sig, Tree arg, Tree size)
 Generate code for accessing a delayed signal.
string generateSelect2 (Tree sig, Tree sel, Tree s1, Tree s2)
 Generate a select2 code.
string generateSelect3 (Tree sig, Tree sel, Tree s1, Tree s2, Tree s3)
 Generate a select3 code.
string generateRecProj (Tree sig, Tree exp, int i)
 Generate code for a projection of a group of mutually recursive definitions.
void generateRec (Tree sig, Tree var, Tree le)
 Generate code for a group of mutually recursive definitions.
string generateDelayVec (Tree sig, const string &exp, const string &ctype, const string &vname, int mxd)
 Generate code for the delay mecchanism.
string generateDelayVecNoTemp (Tree sig, const string &exp, const string &ctype, const string &vname, int mxd)
 Generate code for the delay mecchanism without using temporary variables.
void generateDelayLine (const string &ctype, const string &vname, int mxd, const string &exp)
 Generate code for the delay mecchanism without using temporary variables.
void ensureIotaCode ()
 Generate code for a unique IOTA variable increased at each sample and used to index ring buffers.


Detailed Description

Compile a list of FAUST signals into a scalar C++ class.

Definition at line 39 of file compile_scal.hh.


Member Function Documentation

string ScalarCompiler::CS ( Tree  sig  )  [virtual]

Compile a signal.

Parameters:
sig the signal expression to compile.
Returns:
the C code translation of sig as a string

Definition at line 193 of file compile_scal.cpp.

References generateCode(), getCompiledExpression(), and setCompiledExpression().

Referenced by generateCode(), generateFixDelay(), generateRec(), generateSelect2(), generateSelect3(), and generateXtended().

00194 {
00195     //contextor   contextRecursivness;
00196     string      code;
00197 
00198     if (!getCompiledExpression(sig, code)) {
00199         // not compiled yet
00200 /*        if (getRecursivness(sig) != contextRecursivness.get()) {
00201             contextRecursivness.set(getRecursivness(sig));
00202         }*/
00203         code = generateCode(sig);
00204         setCompiledExpression(sig, code);
00205     }
00206     return code;
00207 }

string ScalarCompiler::generateCode ( Tree  sig  )  [private]

Main code generator dispatch.

Parameters:
sig the signal expression to compile.
Returns:
the C code translation of sig

Definition at line 218 of file compile_scal.cpp.

References CS(), generateFixDelay(), generateRecProj(), generateSelect2(), generateSelect3(), generateXtended(), and getUserData().

Referenced by CS().

00219 {
00220 #if 0
00221     fprintf(stderr, "CALL generateCode(");
00222         print(env, stderr);
00223         fprintf(stderr, ", ");
00224         printSignal(sig, stderr);
00225     fprintf(stderr, ")\n");
00226 #endif
00227 
00228     int     i;
00229     float   r;
00230     Tree    c, sel, x, y, z, label, id, ff, largs, type, name, file;
00231 
00232     //printf("compilation of %p : ", sig); print(sig); printf("\n");
00233 
00234          if ( getUserData(sig) )                    { return generateXtended(sig); }
00235     else if ( isSigInt(sig, &i) )                   { return generateNumber(sig, T(i)); }
00236     else if ( isSigReal(sig, &r) )                  { return generateNumber(sig, T(r)); }
00237     else if ( isSigInput(sig, &i) )                 { return generateInput  (sig, T(i));            }
00238     else if ( isSigOutput(sig, &i, x) )             { return generateOutput     (sig, T(i), CS(x));}
00239 
00240     else if ( isSigFixDelay(sig, x, y) )            { return generateFixDelay   (sig, x, y);            }
00241     else if ( isSigPrefix(sig, x, y) )              { return generatePrefix     (sig, x, y);            }
00242     else if ( isSigIota(sig, x) )                   { return generateIota       (sig, x);               }
00243 
00244     else if ( isSigBinOp(sig, &i, x, y) )           { return generateBinOp  (sig, i, x, y);         }
00245     else if ( isSigFFun(sig, ff, largs) )           { return generateFFun       (sig, ff, largs);       }
00246     else if ( isSigFConst(sig, type, name, file) )  { return generateFConst(sig, tree2str(file), tree2str(name)); }
00247     else if ( isSigFVar(sig, type, name, file) )    { return generateFVar(sig, tree2str(file), tree2str(name)); }
00248 
00249     else if ( isSigTable(sig, id, x, y) )           { return generateTable  (sig, x, y);            }
00250     else if ( isSigWRTbl(sig, id, x, y, z) )        { return generateWRTbl  (sig, x, y, z);         }
00251     else if ( isSigRDTbl(sig, x, y) )               { return generateRDTbl  (sig, x, y);            }
00252 
00253     else if ( isSigSelect2(sig, sel, x, y) )        { return generateSelect2    (sig, sel, x, y);       }
00254     else if ( isSigSelect3(sig, sel, x, y, z) )     { return generateSelect3    (sig, sel, x, y, z);    }
00255 
00256     else if ( isSigGen(sig, x) )                    { return generateSigGen     (sig, x);               }
00257 
00258     else if ( isProj(sig, &i, x) )                  { return generateRecProj    (sig, x, i);    }
00259 
00260     else if ( isSigIntCast(sig, x) )                { return generateIntCast   (sig, x);                }
00261     else if ( isSigFloatCast(sig, x) )              { return generateFloatCast (sig, x);                }
00262 
00263     else if ( isSigButton(sig, label) )             { return generateButton     (sig, label);           }
00264     else if ( isSigCheckbox(sig, label) )           { return generateCheckbox   (sig, label);           }
00265     else if ( isSigVSlider(sig, label,c,x,y,z) )    { return generateVSlider    (sig, label, c,x,y,z); }
00266     else if ( isSigHSlider(sig, label,c,x,y,z) )    { return generateHSlider    (sig, label, c,x,y,z); }
00267     else if ( isSigNumEntry(sig, label,c,x,y,z) )   { return generateNumEntry   (sig, label, c,x,y,z); }
00268 
00269     else if ( isSigVBargraph(sig, label,x,y,z) )    { return generateVBargraph  (sig, label, x, y, CS(z)); }
00270     else if ( isSigHBargraph(sig, label,x,y,z) )    { return generateHBargraph  (sig, label, x, y, CS(z)); }
00271     else if ( isSigAttach(sig, x, y) )              { CS(y); return CS(x); }
00272 
00273     else {
00274         printf("Error in compiling signal, unrecognized signal : ");
00275         print(sig);
00276         printf("\n");
00277         exit(1);
00278     }
00279     return "error in generate code";
00280 }

string ScalarCompiler::generateDelayVec ( Tree  sig,
const string &  exp,
const string &  ctype,
const string &  vname,
int  mxd 
) [private]

Generate code for the delay mecchanism.

The generated code depend of the maximum delay attached to exp and the "less temporaries" switch

Definition at line 1115 of file compile_scal.cpp.

References generateDelayVecNoTemp().

01116 {
01117     string s = generateDelayVecNoTemp(sig, exp, ctype, vname, mxd);
01118     if (getSigType(sig)->variability() < kSamp) {
01119         return exp;
01120     } else {
01121         return s;
01122     }
01123 }

string ScalarCompiler::generateFixDelay ( Tree  sig,
Tree  exp,
Tree  delay 
) [private]

Generate code for accessing a delayed signal.

The generated code depend of the maximum delay attached to exp and the gLessTempSwitch.

Definition at line 1079 of file compile_scal.cpp.

References CS(), getVectorNameProperty(), and OccMarkup::retrieve().

Referenced by generateCode().

01080 {
01081     int     mxd, d; 
01082     string  vecname;
01083  
01084     CS(exp); // ensure exp is compiled to have a vector name
01085 
01086     mxd = fOccMarkup.retrieve(exp)->getMaxDelay();
01087 
01088     assert(getVectorNameProperty(exp, vecname));
01089 
01090     if (mxd == 0) {
01091         // not a real vector name but a scalar name
01092         return vecname;
01093 
01094     } else if (mxd < gMaxCopyDelay) {
01095         if (isSigInt(delay, &d)) {
01096             return subst("$0[$1]", vecname, CS(delay));
01097         } else {
01098             return generateCacheCode(sig, subst("$0[$1]", vecname, CS(delay)));
01099         }
01100 
01101     } else {
01102 
01103         // long delay : we use a ring buffer of size 2^x
01104         int     N   = pow2limit( mxd+1 );
01105         return generateCacheCode(sig, subst("$0[(IOTA-$1)&$2]", vecname, CS(delay), T(N-1))); 
01106     }
01107 }

string ScalarCompiler::generateXtended ( Tree  sig  )  [private]

retrieve the type annotation of sig

Parameters:
sig the signal we want to know the type

Definition at line 988 of file compile_scal.cpp.

References CTree::arity(), CTree::branch(), CS(), and getUserData().

Referenced by generateCode().

00989 {
00990     xtended*        p = (xtended*) getUserData(sig);
00991     vector<string>  args;
00992     vector<Type>    types;
00993 
00994     for (int i=0; i<sig->arity(); i++) {
00995         args.push_back(CS(sig->branch(i)));
00996         types.push_back(getSigType(sig->branch(i)));
00997     }
00998 
00999     if (p->needCache()) {
01000         return generateCacheCode(sig, p->generateCode(fClass, args, types));
01001     } else {
01002         return p->generateCode(fClass, args, types);
01003     }
01004 }

bool ScalarCompiler::getCompiledExpression ( Tree  sig,
string &  cexp 
) [private]

Test if a signal is already compiled.

Parameters:
sig the signal expression to compile.
name the string representing the compiled expression.
Returns:
true is already compiled

Definition at line 171 of file compile_scal.cpp.

Referenced by CS().

00172 {
00173     return fCompileProperty.get(sig, cexp);
00174 }

bool ScalarCompiler::getVectorNameProperty ( Tree  sig,
string &  vecname 
) [private]

Get the vector name property of a signal, the name of the vector used to store the previous values of the signal to implement a delay.

Parameters:
sig the signal expression.
vecname the string where to store the vector name.
Returns:
true if the signal has this property, false otherwise

Definition at line 1036 of file compile_scal.cpp.

Referenced by generateFixDelay(), and generateRecProj().

01037 {
01038     return fVectorProperty.get(sig, vecname);
01039 }

string ScalarCompiler::setCompiledExpression ( Tree  sig,
const string &  cexp 
) [private]

Set the string of a compiled expression is already compiled.

Parameters:
sig the signal expression to compile.
cexp the string representing the compiled expression.
Returns:
the cexp (for commodity)

Definition at line 182 of file compile_scal.cpp.

Referenced by CS().

00183 {
00184     fCompileProperty.set(sig, cexp);
00185     return cexp;
00186 }

void ScalarCompiler::setVectorNameProperty ( Tree  sig,
const string &  vecname 
) [private]

Set the vector name property of a signal, the name of the vector used to store the previous values of the signal to implement a delay.

Parameters:
sig the signal expression.
vecname the string representing the vector name.
Returns:
true is already compiled

Definition at line 1022 of file compile_scal.cpp.

Referenced by generateDelayVecNoTemp(), and generateRec().

01023 {
01024         fVectorProperty.set(sig, vecname);
01025 }


The documentation for this class was generated from the following files:

Generated on Sat Jul 25 13:26:44 2009 for FAUST compiler by  doxygen 1.5.9