ScalarCompiler Class Reference

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

#include <compile_scal.hh>

Inherits Compiler.

Inherited by VectorCompiler.

Collaboration diagram for ScalarCompiler:
Collaboration graph
[legend]

List of all members.

Protected Member Functions

virtual string CS (Tree sig)
 Compile a signal.
virtual string generateCode (Tree sig)
 Main code generator dispatch.
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 generateXtended (Tree sig)
 retrieve the type annotation of sig
virtual 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.
virtual 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.
virtual 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.
int pow2limit (int x)
 Compute the minimal power of 2 greater than x.

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  )  [protected, virtual]

Compile a signal.

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

Reimplemented in VectorCompiler.

Definition at line 202 of file compile_scal.cpp.

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

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

00203 {
00204     //contextor   contextRecursivness;
00205     string      code;
00206 
00207     if (!getCompiledExpression(sig, code)) {
00208         // not compiled yet
00209 /*        if (getRecursivness(sig) != contextRecursivness.get()) {
00210             contextRecursivness.set(getRecursivness(sig));
00211         }*/
00212         code = generateCode(sig);
00213         setCompiledExpression(sig, code);
00214     }
00215     return code;
00216 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateCode ( Tree  sig  )  [protected, virtual]

Main code generator dispatch.

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

Reimplemented in VectorCompiler.

Definition at line 227 of file compile_scal.cpp.

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

Referenced by CS().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Generate code for the delay mecchanism.

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

Reimplemented in VectorCompiler.

Definition at line 1137 of file compile_scal.cpp.

References generateDelayVecNoTemp().

01138 {
01139     string s = generateDelayVecNoTemp(sig, exp, ctype, vname, mxd);
01140     if (getSigType(sig)->variability() < kSamp) {
01141         return exp;
01142     } else {
01143         return s;
01144     }
01145 }

Here is the call graph for this function:

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

Generate code for accessing a delayed signal.

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

Reimplemented in VectorCompiler.

Definition at line 1098 of file compile_scal.cpp.

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

Referenced by generateCode().

01099 {
01100     int     mxd, d;
01101     string  vecname;
01102 
01103     CS(exp); // ensure exp is compiled to have a vector name
01104 
01105     mxd = fOccMarkup.retrieve(exp)->getMaxDelay();
01106 
01107     if (! getVectorNameProperty(exp, vecname)) {
01108         cerr << "No vector name for : " << ppsig(exp) << endl;
01109         assert(0);
01110     }
01111 
01112     if (mxd == 0) {
01113         // not a real vector name but a scalar name
01114         return vecname;
01115 
01116     } else if (mxd < gMaxCopyDelay) {
01117         if (isSigInt(delay, &d)) {
01118             return subst("$0[$1]", vecname, CS(delay));
01119         } else {
01120             return generateCacheCode(sig, subst("$0[$1]", vecname, CS(delay)));
01121         }
01122 
01123     } else {
01124 
01125         // long delay : we use a ring buffer of size 2^x
01126         int     N   = pow2limit( mxd+1 );
01127         return generateCacheCode(sig, subst("$0[(IOTA-$1)&$2]", vecname, CS(delay), T(N-1)));
01128     }
01129 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

retrieve the type annotation of sig

Parameters:
sig the signal we want to know the type

Definition at line 1007 of file compile_scal.cpp.

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

Referenced by generateCode().

01008 {
01009     xtended*        p = (xtended*) getUserData(sig);
01010     vector<string>  args;
01011     vector<Type>    types;
01012 
01013     for (int i=0; i<sig->arity(); i++) {
01014         args.push_back(CS(sig->branch(i)));
01015         types.push_back(getSigType(sig->branch(i)));
01016     }
01017 
01018     if (p->needCache()) {
01019         return generateCacheCode(sig, p->generateCode(fClass, args, types));
01020     } else {
01021         return p->generateCode(fClass, args, types);
01022     }
01023 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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 180 of file compile_scal.cpp.

Referenced by VectorCompiler::CS(), and CS().

00181 {
00182     return fCompileProperty.get(sig, cexp);
00183 }

Here is the caller graph for this function:

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

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 1055 of file compile_scal.cpp.

Referenced by VectorCompiler::generateFixDelay(), generateFixDelay(), and generateRecProj().

01056 {
01057     return fVectorProperty.get(sig, vecname);
01058 }

Here is the caller graph for this function:

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

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 191 of file compile_scal.cpp.

Referenced by VectorCompiler::CS(), and CS().

00192 {
00193     fCompileProperty.set(sig, cexp);
00194     return cexp;
00195 }

Here is the caller graph for this function:

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

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 1041 of file compile_scal.cpp.

Referenced by VectorCompiler::generateCacheCode(), VectorCompiler::generateDelayVec(), generateDelayVecNoTemp(), and generateRec().

01042 {
01043         fVectorProperty.set(sig, vecname);
01044 }

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated by  doxygen 1.6.2-20100208