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:
[legend]

List of all members.

Public Member Functions

 ScalarCompiler (const string &name, const string &super, int numInputs, int numOutputs)
 ScalarCompiler (Klass *k)
virtual void compileMultiSignal (Tree lsig)
virtual void compileSingleSignal (Tree lsig)

Protected Member Functions

virtual string CS (Tree sig)
 Compile a signal.
virtual string generateCode (Tree sig)
 Main code generator dispatch.
virtual string generateCacheCode (Tree sig, const string &exp)
virtual string generateVariableStore (Tree sig, const string &exp)
string getFreshID (const string &prefix)
void compilePreparedSignalList (Tree lsig)
Tree prepare (Tree L0)
Tree prepare2 (Tree L0)
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.
int getSharingCount (Tree t)
void setSharingCount (Tree t, int count)
void sharingAnalysis (Tree t)
void sharingAnnotation (int vctxt, Tree t)
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 generatePrefix (Tree sig, Tree x, Tree e)
string generateIota (Tree sig, Tree arg)
string generateBinOp (Tree sig, int opcode, Tree arg1, Tree arg2)
string generateFFun (Tree sig, Tree ff, Tree largs)
string generateInput (Tree sig, const string &idx)
string generateOutput (Tree sig, const string &idx, const string &arg1)
string generateTable (Tree sig, Tree tsize, Tree content)
string generateStaticTable (Tree sig, Tree tsize, Tree content)
string generateWRTbl (Tree sig, Tree tbl, Tree idx, Tree data)
string generateRDTbl (Tree sig, Tree tbl, Tree idx)
string generateSigGen (Tree sig, Tree content)
string generateStaticSigGen (Tree sig, Tree content)
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 generateIntCast (Tree sig, Tree x)
string generateFloatCast (Tree sig, Tree x)
string generateButton (Tree sig, Tree label)
string generateCheckbox (Tree sig, Tree label)
string generateVSlider (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
string generateHSlider (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
string generateNumEntry (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
string generateVBargraph (Tree sig, Tree label, Tree min, Tree max, const string &exp)
string generateHBargraph (Tree sig, Tree label, Tree min, Tree max, const string &exp)
string generateNumber (Tree sig, const string &exp)
string generateFConst (Tree sig, const string &file, const string &name)
string generateFVar (Tree sig, const string &file, const string &name)
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 getTypedNames (Type t, const string &prefix, string &ctype, string &vname)
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.

Protected Attributes

property< string > fCompileProperty
property< string > fVectorProperty
Tree fSharingKey
OccMarkup fOccMarkup
bool fHasIota

Static Protected Attributes

static map< string, int > fIDCounters

Detailed Description

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

Definition at line 39 of file compile_scal.hh.


Constructor & Destructor Documentation

ScalarCompiler::ScalarCompiler ( const string &  name,
const string &  super,
int  numInputs,
int  numOutputs 
) [inline]

Definition at line 53 of file compile_scal.hh.

00054                                                                                              :
00055         Compiler(name,super,numInputs,numOutputs,false),
00056         fHasIota(false)
    {}

ScalarCompiler::ScalarCompiler ( Klass k  )  [inline]

Definition at line 58 of file compile_scal.hh.

00058                                : 
00059         Compiler(k),
00060         fHasIota(false)
00061     {}


Member Function Documentation

void ScalarCompiler::compileMultiSignal ( Tree  lsig  )  [virtual]

Implements Compiler.

Reimplemented in VectorCompiler.

Definition at line 129 of file compile_scal.cpp.

References Klass::addExecCode(), Klass::addZone3(), CS(), Compiler::fClass, Compiler::fDescription, Compiler::fUIRoot, Compiler::generateMacroInterfaceTree(), Compiler::generateUserInterfaceTree(), hd(), Klass::inputs(), isList(), Klass::outputs(), prepare(), Compiler::prepareUserInterfaceTree(), subst(), T(), tl(), Description::ui(), xcast(), and xfloat().

00130 {
00131     //contextor recursivness(0);
00132     L = prepare(L);     // optimize, share and annotate expression
00133     
00134     for (int i = 0; i < fClass->inputs(); i++) {
00135         fClass->addZone3(subst("$1* input$0 = input[$0];", T(i), xfloat()));
00136     }
00137     for (int i = 0; i < fClass->outputs(); i++) {
00138         fClass->addZone3(subst("$1* output$0 = output[$0];", T(i), xfloat()));
00139     }
00140     
00141     for (int i = 0; isList(L); L = tl(L), i++) {
00142         Tree sig = hd(L);
00143         fClass->addExecCode(subst("output$0[i] = $2$1;", T(i), CS(sig), xcast()));
00144     }
00145     generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot));
00146     generateMacroInterfaceTree("", prepareUserInterfaceTree(fUIRoot));
00147     if (fDescription) {
00148         fDescription->ui(prepareUserInterfaceTree(fUIRoot));
00149     }
00150 }

Here is the call graph for this function:

void ScalarCompiler::compilePreparedSignalList ( Tree  lsig  )  [protected]
void ScalarCompiler::compileSingleSignal ( Tree  lsig  )  [virtual]

Implements Compiler.

Definition at line 157 of file compile_scal.cpp.

References Klass::addExecCode(), CS(), Compiler::fClass, Compiler::fDescription, Compiler::fUIRoot, Compiler::generateMacroInterfaceTree(), Compiler::generateUserInterfaceTree(), prepare2(), Compiler::prepareUserInterfaceTree(), subst(), and Description::ui().

Referenced by signal2klass().

00158 {
00159     //contextor recursivness(0);
00160     sig = prepare2(sig);        // optimize and annotate expression
00161     fClass->addExecCode(subst("output[i] = $0;", CS(sig)));
00162     generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot));
00163     generateMacroInterfaceTree("", prepareUserInterfaceTree(fUIRoot));
00164     if (fDescription) {
00165         fDescription->ui(prepareUserInterfaceTree(fUIRoot));
00166     }
00167 }

Here is the call graph for this function:

Here is the caller graph for this function:

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 compileMultiSignal(), compileSingleSignal(), generateBinOp(), generateCode(), generateFFun(), generateFixDelay(), generateFloatCast(), generateIntCast(), generatePrefix(), generateRDTbl(), generateRec(), generateSelect2(), generateSelect3(), generateTable(), generateWRTbl(), 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:

void ScalarCompiler::ensureIotaCode (  )  [protected]

Generate code for a unique IOTA variable increased at each sample and used to index ring buffers.

Definition at line 1245 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addInitCode(), Klass::addPostCode(), Compiler::fClass, and fHasIota.

Referenced by generateDelayLine(), and generateDelayVecNoTemp().

01246 {
01247     if (!fHasIota) {
01248         fHasIota = true;
01249         fClass->addDeclCode("int \tIOTA;");
01250         fClass->addInitCode("IOTA = 0;");
01251         fClass->addPostCode("IOTA = IOTA+1;");
01252     }
01253 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateBinOp ( Tree  sig,
int  opcode,
Tree  arg1,
Tree  arg2 
) [protected]

Definition at line 369 of file compile_scal.cpp.

References CS(), gBinOpTable, generateCacheCode(), and subst().

Referenced by generateCode().

00370 {
00371     return generateCacheCode(sig, subst("($0 $1 $2)", CS(arg1), gBinOpTable[opcode]->fName, CS(arg2)));
00372 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateButton ( Tree  sig,
Tree  label 
) [protected]

Definition at line 498 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addInitCode(), Compiler::addUIWidget(), Compiler::fClass, generateCacheCode(), getFreshID(), hd(), reverse(), subst(), tl(), tree(), uiWidget(), and xfloat().

Referenced by generateCode().

00499 {
00500     string varname = getFreshID("fbutton");
00501     fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat()));
00502     fClass->addInitCode(subst("$0 = 0.0;", varname));
00503     addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
00504     return generateCacheCode(sig, varname);
00505 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateCacheCode ( Tree  sig,
const string &  exp 
) [protected, virtual]

Reimplemented in VectorCompiler.

Definition at line 410 of file compile_scal.cpp.

References fOccMarkup, generateDelayVec(), generateVariableStore(), getCompiledExpression(), Occurences::getMaxDelay(), getSharingCount(), getSigType(), getTypedNames(), and OccMarkup::retrieve().

Referenced by generateBinOp(), generateButton(), generateCheckbox(), generateCode(), generateFixDelay(), generateFloatCast(), generateFVar(), generateHBargraph(), generateHSlider(), generateInput(), generateIntCast(), generateNumEntry(), generateRDTbl(), generateSelect2(), generateSelect3(), generateVBargraph(), generateVSlider(), and generateXtended().

00411 {
00412     string      vname, ctype, code;
00413     int         sharing = getSharingCount(sig);
00414     Occurences* o = fOccMarkup.retrieve(sig);
00415 
00416     // check reentrance
00417     if (getCompiledExpression(sig, code)) {
00418         return code;
00419     }
00420 
00421     // check for expression occuring in delays
00422     if (o->getMaxDelay()>0) {
00423 
00424         getTypedNames(getSigType(sig), "Vec", ctype, vname);
00425         if (sharing>1) {
00426             return generateDelayVec(sig, generateVariableStore(sig,exp), ctype, vname, o->getMaxDelay());
00427         } else {
00428             return generateDelayVec(sig, exp, ctype, vname, o->getMaxDelay());
00429         }
00430 
00431     } else if (sharing == 1) {
00432 
00433         return exp;
00434 
00435     } else if (sharing > 1) {
00436 
00437         return generateVariableStore(sig, exp);
00438 
00439     } else {
00440         cerr << "Error in sharing count (" << sharing << ") for " << *sig << endl;
00441         exit(1);
00442     }
00443 
00444     return "Error in generateCacheCode";
00445 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateCheckbox ( Tree  sig,
Tree  label 
) [protected]

Definition at line 507 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addInitCode(), Compiler::addUIWidget(), Compiler::fClass, generateCacheCode(), getFreshID(), hd(), reverse(), subst(), tl(), tree(), uiWidget(), and xfloat().

Referenced by generateCode().

00508 {
00509     string varname = getFreshID("fcheckbox");
00510     fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat()));
00511     fClass->addInitCode(subst("$0 = 0.0;", varname));
00512     addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
00513     return generateCacheCode(sig, varname);
00514 }

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(), generateBinOp(), generateButton(), generateCacheCode(), generateCheckbox(), generateFConst(), generateFFun(), generateFixDelay(), generateFloatCast(), generateFVar(), generateHBargraph(), generateHSlider(), generateInput(), generateIntCast(), generateIota(), generateNumber(), generateNumEntry(), generateOutput(), generatePrefix(), generateRDTbl(), generateRecProj(), generateSelect2(), generateSelect3(), generateSigGen(), generateTable(), generateVBargraph(), generateVSlider(), generateWRTbl(), generateXtended(), getUserData(), isProj(), isSigAttach(), isSigBinOp(), isSigButton(), isSigCheckbox(), isSigFConst(), isSigFFun(), isSigFixDelay(), isSigFloatCast(), isSigFVar(), isSigGen(), isSigHBargraph(), isSigHSlider(), isSigInput(), isSigInt(), isSigIntCast(), isSigIota(), isSigNumEntry(), isSigOutput(), isSigPrefix(), isSigRDTbl(), isSigReal(), isSigSelect2(), isSigSelect3(), isSigTable(), isSigVBargraph(), isSigVSlider(), isSigWRTbl(), name(), print(), printSignal(), T(), and tree2str().

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 caller graph for this function:

void ScalarCompiler::generateDelayLine ( const string &  ctype,
const string &  vname,
int  mxd,
const string &  exp 
) [protected, virtual]

Generate code for the delay mecchanism without using temporary variables.

Reimplemented in VectorCompiler.

Definition at line 1199 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), Klass::addPostCode(), ensureIotaCode(), Compiler::fClass, gMaxCopyDelay, pow2limit(), subst(), and T().

Referenced by generateRec().

01200 {
01201     //assert(mxd > 0);
01202     if (mxd == 0) {
01203         // cerr << "MXD==0 :  " << vname << " := " << exp << endl;
01204         // no need for a real vector
01205         fClass->addExecCode(subst("$0 \t$1 = $2;", ctype, vname, exp));
01206 
01207 
01208     } else if (mxd < gMaxCopyDelay) {
01209 
01210         // short delay : we copy
01211         fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(mxd+1)));
01212         fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i] = 0;", vname, T(mxd+1)));
01213         fClass->addExecCode(subst("$0[0] = $1;", vname, exp));
01214 
01215         // generate post processing copy code to update delay values
01216         if (mxd == 1) {
01217             fClass->addPostCode(subst("$0[1] = $0[0];", vname));
01218         } else if (mxd == 2) {
01219             fClass->addPostCode(subst("$0[2] = $0[1]; $0[1] = $0[0];", vname));
01220         } else {
01221             fClass->addPostCode(subst("for (int i=$0; i>0; i--) $1[i] = $1[i-1];", T(mxd), vname));
01222         }
01223 
01224     } else {
01225 
01226         // generate code for a long delay : we use a ring buffer of size N = 2**x > mxd
01227         int     N = pow2limit(mxd+1);
01228 
01229         // we need a iota index
01230         ensureIotaCode();
01231 
01232         // declare and init
01233         fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(N)));
01234         fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i] = 0;", vname, T(N)));
01235 
01236         // execute
01237         fClass->addExecCode(subst("$0[IOTA&$1] = $2;", vname, T(N-1), exp));
01238     }
01239 }

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(), getSigType(), and kSamp.

Referenced by generateCacheCode(), generateFConst(), generateFVar(), and generateNumber().

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:

Here is the caller graph for this function:

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

Generate code for the delay mecchanism without using temporary variables.

Definition at line 1151 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), Klass::addPostCode(), ensureIotaCode(), Compiler::fClass, gMaxCopyDelay, pow2limit(), setVectorNameProperty(), subst(), and T().

Referenced by generateDelayVec().

01152 {
01153     assert(mxd > 0);
01154 
01155     //bool odocc = fOccMarkup.retrieve(sig)->hasOutDelayOccurences();
01156 
01157     if (mxd < gMaxCopyDelay) {
01158 
01159         // short delay : we copy
01160         fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(mxd+1)));
01161         fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i] = 0;", vname, T(mxd+1)));
01162         fClass->addExecCode(subst("$0[0] = $1;", vname, exp));
01163 
01164         // generate post processing copy code to update delay values
01165         if (mxd == 1) {
01166             fClass->addPostCode(subst("$0[1] = $0[0];", vname));
01167         } else if (mxd == 2) {
01168             //fClass->addPostCode(subst("$0[2] = $0[1];", vname));
01169             fClass->addPostCode(subst("$0[2] = $0[1]; $0[1] = $0[0];", vname));
01170         } else {
01171             fClass->addPostCode(subst("for (int i=$0; i>0; i--) $1[i] = $1[i-1];", T(mxd), vname));
01172         }
01173         setVectorNameProperty(sig, vname);
01174         return subst("$0[0]", vname);
01175 
01176     } else {
01177 
01178         // generate code for a long delay : we use a ring buffer of size N = 2**x > mxd
01179         int     N = pow2limit(mxd+1);
01180 
01181         // we need a iota index
01182         ensureIotaCode();
01183 
01184         // declare and init
01185         fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(N)));
01186         fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i] = 0;", vname, T(N)));
01187 
01188         // execute
01189         fClass->addExecCode(subst("$0[IOTA&$1] = $2;", vname, T(N-1), exp));
01190         setVectorNameProperty(sig, vname);
01191         return subst("$0[IOTA&$1]", vname, T(N-1));
01192     }
01193 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateFConst ( Tree  sig,
const string &  file,
const string &  name 
) [protected]

Definition at line 313 of file compile_scal.cpp.

References Compiler::addIncludeFile(), fOccMarkup, generateDelayVec(), Occurences::getMaxDelay(), getSigType(), getTypedNames(), and OccMarkup::retrieve().

Referenced by generateCode().

00314 {
00315     string      ctype, vname;
00316     Occurences* o = fOccMarkup.retrieve(sig);
00317 
00318     addIncludeFile(file);
00319 
00320     if (o->getMaxDelay()>0) {
00321         getTypedNames(getSigType(sig), "Vec", ctype, vname);
00322         generateDelayVec(sig, exp, ctype, vname, o->getMaxDelay());
00323     }
00324     return exp;
00325 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateFFun ( Tree  sig,
Tree  ff,
Tree  largs 
) [protected]

Definition at line 379 of file compile_scal.cpp.

References Compiler::addIncludeFile(), Compiler::addLibrary(), CS(), ffarity(), ffincfile(), fflibfile(), ffname(), and nth().

Referenced by generateCode().

00380 {
00381     addIncludeFile(ffincfile(ff));  //printf("inc file %s\n", ffincfile(ff));
00382     addLibrary(fflibfile(ff));      //printf("lib file %s\n", fflibfile(ff));
00383 
00384     string code = ffname(ff);
00385     code += '(';
00386     string sep = "";
00387     for (int i = 0; i< ffarity(ff); i++) {
00388         code += sep;
00389         code += CS(nth(largs, i));
00390         sep = ", ";
00391     }
00392     code += ')';
00393     return code;
00394 }

Here is the call graph for this function:

Here is the caller 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(), fOccMarkup, generateCacheCode(), Occurences::getMaxDelay(), getVectorNameProperty(), gMaxCopyDelay, isSigInt(), pow2limit(), OccMarkup::retrieve(), subst(), and T().

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::generateFloatCast ( Tree  sig,
Tree  x 
) [protected]

Definition at line 489 of file compile_scal.cpp.

References CS(), generateCacheCode(), ifloat(), and subst().

Referenced by generateCode().

00490 {
00491     return generateCacheCode(sig, subst("$1($0)", CS(x), ifloat()));
00492 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateFVar ( Tree  sig,
const string &  file,
const string &  name 
) [protected]

Definition at line 332 of file compile_scal.cpp.

References Compiler::addIncludeFile(), fOccMarkup, generateCacheCode(), generateDelayVec(), Occurences::getMaxDelay(), getSigType(), getTypedNames(), and OccMarkup::retrieve().

Referenced by generateCode().

00333 {
00334     string      ctype, vname;
00335     Occurences* o = fOccMarkup.retrieve(sig);
00336 
00337     addIncludeFile(file);
00338 
00339     if (o->getMaxDelay()>0) {
00340         getTypedNames(getSigType(sig), "Vec", ctype, vname);
00341         generateDelayVec(sig, exp, ctype, vname, o->getMaxDelay());
00342     }
00343     return generateCacheCode(sig, exp);
00344 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateHBargraph ( Tree  sig,
Tree  label,
Tree  min,
Tree  max,
const string &  exp 
) [protected]

Definition at line 572 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), Compiler::addUIWidget(), Klass::addZone2(), Compiler::fClass, generateCacheCode(), getFreshID(), getSigType(), hd(), kBlock, kKonst, kSamp, reverse(), subst(), tl(), tree(), uiWidget(), and xfloat().

Referenced by generateCode().

00573 {
00574     string varname = getFreshID("fbargraph");
00575     fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat()));
00576     addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
00577 
00578     Type t = getSigType(sig);
00579     switch (t->variability()) {
00580 
00581         case kKonst :
00582             fClass->addInitCode(subst("$0 = $1;", varname, exp));
00583             break;
00584 
00585         case kBlock :
00586             fClass->addZone2(subst("$0 = $1;", varname, exp));
00587             break;
00588 
00589         case kSamp :
00590             fClass->addExecCode(subst("$0 = $1;", varname, exp));
00591             break;
00592     }
00593 
00594     //return varname;
00595     return generateCacheCode(sig, varname);
00596 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateHSlider ( Tree  sig,
Tree  label,
Tree  cur,
Tree  min,
Tree  max,
Tree  step 
) [protected]

Definition at line 526 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addInitCode(), Compiler::addUIWidget(), Compiler::fClass, generateCacheCode(), getFreshID(), hd(), reverse(), subst(), T(), tl(), tree(), tree2float(), uiWidget(), and xfloat().

Referenced by generateCode().

00527 {
00528     string varname = getFreshID("fslider");
00529     fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat()));
00530     fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur))));
00531     addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
00532     return generateCacheCode(sig, varname);
00533 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateInput ( Tree  sig,
const string &  idx 
) [protected]

Definition at line 351 of file compile_scal.cpp.

References generateCacheCode(), icast(), and subst().

Referenced by generateCode().

00352 {
00353     return generateCacheCode(sig, subst("$1input$0[i]", idx, icast()));
00354 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateIntCast ( Tree  sig,
Tree  x 
) [protected]

Definition at line 484 of file compile_scal.cpp.

References CS(), generateCacheCode(), and subst().

Referenced by generateCode().

00485 {
00486     return generateCacheCode(sig, subst("int($0)", CS(x)));
00487 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateIota ( Tree  sig,
Tree  arg 
) [protected]

Definition at line 847 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), Compiler::fClass, getFreshID(), isPowerOf2(), isSigInt(), subst(), and T().

Referenced by generateCode().

00848 {
00849     int size;
00850     if (!isSigInt(n, &size)) { fprintf(stderr, "error in generateIota\n"); exit(1); }
00851 
00852     string vperm = getFreshID("iota");
00853 
00854     fClass->addDeclCode(subst("int \t$0;",  vperm));
00855     fClass->addInitCode(subst("$0 = 0;", vperm));
00856 
00857     if (isPowerOf2(size)) {
00858         fClass->addExecCode(subst("$0 = ($0+1)&$1;", vperm, T(size-1)));
00859     } else {
00860         fClass->addExecCode(subst("if (++$0 == $1) $0=0;", vperm, T(size)));
00861     }
00862     return vperm;
00863 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateNumber ( Tree  sig,
const string &  exp 
) [protected]

Definition at line 295 of file compile_scal.cpp.

References fOccMarkup, generateDelayVec(), Occurences::getMaxDelay(), getSigType(), getTypedNames(), and OccMarkup::retrieve().

Referenced by generateCode().

00296 {
00297     string      ctype, vname;
00298     Occurences* o = fOccMarkup.retrieve(sig);
00299 
00300     // check for number occuring in delays
00301     if (o->getMaxDelay()>0) {
00302         getTypedNames(getSigType(sig), "Vec", ctype, vname);
00303         generateDelayVec(sig, exp, ctype, vname, o->getMaxDelay());
00304     }
00305     return exp;
00306 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateNumEntry ( Tree  sig,
Tree  label,
Tree  cur,
Tree  min,
Tree  max,
Tree  step 
) [protected]

Definition at line 535 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addInitCode(), Compiler::addUIWidget(), Compiler::fClass, generateCacheCode(), getFreshID(), hd(), reverse(), subst(), T(), tl(), tree(), tree2float(), uiWidget(), and xfloat().

Referenced by generateCode().

00536 {
00537     string varname = getFreshID("fentry");
00538     fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat()));
00539     fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur))));
00540     addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
00541     return generateCacheCode(sig, varname);
00542 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateOutput ( Tree  sig,
const string &  idx,
const string &  arg1 
) [protected]

Definition at line 357 of file compile_scal.cpp.

References Klass::addExecCode(), Compiler::fClass, subst(), and xcast().

Referenced by generateCode().

00358 {
00359     string dst = subst("output$0[i]", idx);
00360     fClass->addExecCode(subst("$0 = $2$1;", dst, arg, xcast()));
00361     return dst;
00362 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generatePrefix ( Tree  sig,
Tree  x,
Tree  e 
) [protected]

Definition at line 821 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), CS(), cType(), Compiler::fClass, getFreshID(), getSigType(), and subst().

Referenced by generateCode().

00822 {
00823     Type te = getSigType(sig);//, tEnv);
00824 
00825     string vperm = getFreshID("M");
00826     string vtemp = getFreshID("T");
00827 
00828     string type = cType(te);
00829 
00830     fClass->addDeclCode(subst("$0 \t$1;", type, vperm));
00831     fClass->addInitCode(subst("$0 = $1;", vperm, CS(x)));
00832 
00833     fClass->addExecCode(subst("$0 $1 = $2;", type, vtemp, vperm));
00834     fClass->addExecCode(subst("$0 = $1;", vperm, CS(e)));
00835     return vtemp;
00836 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateRDTbl ( Tree  sig,
Tree  tbl,
Tree  idx 
) [protected]

Definition at line 735 of file compile_scal.cpp.

References CS(), generateCacheCode(), generateStaticTable(), getCompiledExpression(), isSigTable(), setCompiledExpression(), and subst().

Referenced by generateCode().

00736 {
00737     // YO le 21/04/05 : La lecture des tables n'�ait pas mise dans le cache
00738     // et donc le code �ait dupliqu�(dans tester.dsp par exemple)
00739     //return subst("$0[$1]", CS(tEnv, tbl), CS(tEnv, idx));
00740 
00741     //cerr << "generateRDTable " << *sig << endl;
00742     // test the special case of a read only table that can be compiled
00743     // has a static member
00744     Tree    id, size, content;
00745     if( isSigTable(tbl, id, size, content) ) {
00746         string tblname;
00747         if (!getCompiledExpression(tbl, tblname)) {
00748             tblname = setCompiledExpression(tbl, generateStaticTable(tbl, size, content));
00749         }
00750         return generateCacheCode(sig, subst("$0[$1]", tblname, CS(idx)));
00751     } else {
00752         return generateCacheCode(sig, subst("$0[$1]", CS(tbl), CS(idx)));
00753     }
00754 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ScalarCompiler::generateRec ( Tree  sig,
Tree  var,
Tree  le 
) [protected]

Generate code for a group of mutually recursive definitions.

Definition at line 783 of file compile_scal.cpp.

References CS(), fOccMarkup, generateDelayLine(), Occurences::getMaxDelay(), getSigType(), getTypedNames(), len(), nth(), OccMarkup::retrieve(), setVectorNameProperty(), and sigProj().

Referenced by generateRecProj().

00784 {
00785     int             N = len(le);
00786 
00787     vector<bool>    used(N);
00788     vector<int>     delay(N);
00789     vector<string>  vname(N);
00790     vector<string>  ctype(N);
00791 
00792     // prepare each element of a recursive definition
00793     for (int i=0; i<N; i++) {
00794         Tree    e = sigProj(i,sig);     // recreate each recursive definition
00795         if (fOccMarkup.retrieve(e)) {
00796             // this projection is used
00797             used[i] = true;
00798             getTypedNames(getSigType(e), "Rec", ctype[i],  vname[i]);
00799             setVectorNameProperty(e, vname[i]);
00800             delay[i] = fOccMarkup.retrieve(e)->getMaxDelay();
00801         } else {
00802             // this projection is not used therefore
00803             // we should not generte code for it
00804             used[i] = false;
00805         }
00806     }
00807 
00808     // generate delayline for each element of a recursive definition
00809     for (int i=0; i<N; i++) {
00810         if (used[i]) {
00811             generateDelayLine(ctype[i], vname[i], delay[i], CS(nth(le,i)));
00812         }
00813     }
00814 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateRecProj ( Tree  sig,
Tree  exp,
int  i 
) [protected]

Generate code for a projection of a group of mutually recursive definitions.

Definition at line 766 of file compile_scal.cpp.

References generateRec(), getVectorNameProperty(), isRec(), and subst().

Referenced by generateCode().

00767 {
00768     string  vname;
00769     Tree    var, le;
00770 
00771     if ( ! getVectorNameProperty(sig, vname)) {
00772         assert(isRec(r, var, le));
00773         generateRec(r, var, le);
00774         assert(getVectorNameProperty(sig, vname));
00775     }
00776     return subst("$0[0]", vname);
00777 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateSelect2 ( Tree  sig,
Tree  sel,
Tree  s1,
Tree  s2 
) [protected]

Generate a select2 code.

Definition at line 874 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), Klass::addSharedDecl(), Klass::addZone1(), Klass::addZone2b(), CS(), cType(), Compiler::fClass, generateCacheCode(), getFreshID(), getSigType(), kBlock, kKonst, kSamp, min(), and subst().

Referenced by generateCode().

00875 {
00876     Type t  = getSigType(sig);
00877     Type t1 = getSigType(s1);
00878     Type t2 = getSigType(s2);
00879     Type w  = min(t1,t2);
00880 
00881     string type = cType(t);
00882     string var  = getFreshID("S");
00883 
00884     switch (w->variability())
00885     {
00886         case kKonst :
00887             fClass->addDeclCode(subst("$0 \t$1[2];", type, var));
00888             break;
00889         case kBlock :
00890             //fClass->addLocalDecl(type, subst("$0[2]", var));
00891             //fClass->addLocalVecDecl(type, var, 2);
00892             fClass->addSharedDecl(var);
00893             fClass->addZone1(subst("$0 \t$1[2];", type, var));
00894             break;
00895         case kSamp :
00896             fClass->addExecCode(subst("$0 \t$1[2];", type, var));
00897             break;
00898     }
00899 
00900     switch (t1->variability())
00901     {
00902         case kKonst :
00903             fClass->addInitCode(subst("$0[0] = $1;", var, CS(s1)));
00904             break;
00905         case kBlock :
00906             fClass->addZone2b(subst("$0[0] = $1;", var, CS(s1)));
00907             break;
00908         case kSamp :
00909             fClass->addExecCode(subst("$0[0] = $1;", var, CS(s1)));
00910             break;
00911     }
00912 
00913     switch (t2->variability())
00914     {
00915         case kKonst :
00916             fClass->addInitCode(subst("$0[1] = $1;", var, CS(s2)));
00917             break;
00918         case kBlock :
00919             fClass->addZone2b(subst("$0[1] = $1;", var, CS(s2)));
00920             break;
00921         case kSamp :
00922             fClass->addExecCode(subst("$0[1] = $1;", var, CS(s2)));
00923             break;
00924     }
00925 
00926     return generateCacheCode(sig, subst("$0[$1]", var, CS(sel)));
00927 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateSelect3 ( Tree  sig,
Tree  sel,
Tree  s1,
Tree  s2,
Tree  s3 
) [protected]

Generate a select3 code.

Definition at line 933 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), Klass::addSharedDecl(), Klass::addZone1(), Klass::addZone2b(), CS(), cType(), Compiler::fClass, generateCacheCode(), getFreshID(), getSigType(), kBlock, kKonst, kSamp, min(), and subst().

Referenced by generateCode().

00934 {
00935     Type t  = getSigType(sig);
00936     Type t1 = getSigType(s1);
00937     Type t2 = getSigType(s2);
00938     Type t3 = getSigType(s3);
00939     Type w  = min(t1,min(t2,t3));
00940 
00941     string type = cType(t);
00942     string var  = getFreshID("S");
00943 
00944     switch (w->variability())
00945     {
00946         case kKonst :
00947             fClass->addDeclCode(subst("$0 \t$1[3];", type, var));
00948             break;
00949         case kBlock :
00950             //fClass->addLocalDecl(type, subst("$0[3]", var));
00951             //fClass->addLocalVecDecl(type, var, 3);
00952             fClass->addSharedDecl(var);
00953             fClass->addZone1(subst("$0 \t$1[3];", type, var));
00954             break;
00955         case kSamp :
00956             fClass->addExecCode(subst("$0 \t$1[3];", type, var));
00957             break;
00958     }
00959 
00960     switch (t1->variability())
00961     {
00962         case kKonst :
00963             fClass->addInitCode(subst("$0[0] = $1;", var, CS(s1)));
00964             break;
00965         case kBlock :
00966             fClass->addZone2b(subst("$0[0] = $1;", var, CS(s1)));
00967             break;
00968         case kSamp :
00969             fClass->addExecCode(subst("$0[0] = $1;", var, CS(s1)));
00970             break;
00971     }
00972 
00973     switch (t2->variability())
00974     {
00975         case kKonst :
00976             fClass->addInitCode(subst("$0[1] = $1;", var, CS(s2)));
00977             break;
00978         case kBlock :
00979             fClass->addZone2b(subst("$0[1] = $1;", var, CS(s2)));
00980             break;
00981         case kSamp :
00982             fClass->addExecCode(subst("$0[1] = $1;", var, CS(s2)));
00983             break;
00984     }
00985 
00986     switch (t3->variability())
00987     {
00988         case kKonst :
00989             fClass->addInitCode(subst("$0[2] = $1;", var, CS(s3)));
00990             break;
00991         case kBlock :
00992             fClass->addZone2b(subst("$0[2] = $1;", var, CS(s3)));
00993             break;
00994         case kSamp :
00995             fClass->addExecCode(subst("$0[2] = $1;", var, CS(s3)));
00996             break;
00997     }
00998 
00999     return generateCacheCode(sig, subst("$0[$1]", var, CS(sel)));
01000 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateSigGen ( Tree  sig,
Tree  content 
) [protected]

Definition at line 611 of file compile_scal.cpp.

References Klass::addInitCode(), Klass::addSubKlass(), Compiler::fClass, getFreshID(), signal2klass(), and subst().

Referenced by generateCode().

00612 {
00613     string klassname = getFreshID("SIG");
00614     string signame = getFreshID("sig");
00615 
00616     fClass->addSubKlass(signal2klass(klassname, content));
00617     fClass->addInitCode(subst("$0 $1;", klassname, signame));
00618 
00619     return signame;
00620 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateStaticSigGen ( Tree  sig,
Tree  content 
) [protected]

Definition at line 622 of file compile_scal.cpp.

References Klass::addStaticInitCode(), Klass::addSubKlass(), Compiler::fClass, getFreshID(), signal2klass(), and subst().

Referenced by generateStaticTable().

00623 {
00624     string klassname = getFreshID("SIG");
00625     string signame = getFreshID("sig");
00626 
00627     fClass->addSubKlass(signal2klass(klassname, content));
00628     fClass->addStaticInitCode(subst("$0 $1;", klassname, signame));
00629 
00630     return signame;
00631 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateStaticTable ( Tree  sig,
Tree  tsize,
Tree  content 
) [protected]

Definition at line 674 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addStaticFields(), Klass::addStaticInitCode(), Compiler::fClass, generateStaticSigGen(), getCompiledExpression(), getFreshID(), getSigType(), ifloat(), isSigGen(), isSigInt(), kInt, setCompiledExpression(), subst(), and T().

Referenced by generateRDTbl().

00675 {
00676     //string        generator(CS(content));
00677     Tree        g;
00678     string      cexp;
00679     string      ctype, vname;
00680     int         size;
00681 
00682     assert ( isSigGen(content, g) );
00683     if (!getCompiledExpression(content, cexp)) {
00684         cexp = setCompiledExpression(content, generateStaticSigGen(content, g));
00685     }
00686 
00687     if (!isSigInt(tsize, &size)) {
00688         //fprintf(stderr, "error in ScalarCompiler::generateTable()\n"); exit(1);
00689         cerr << "error in ScalarCompiler::generateTable() : "
00690              << *tsize
00691              << " is not an integer expression "
00692              << endl;
00693     }
00694     // definition du nom et du type de la table
00695     // A REVOIR !!!!!!!!!
00696     Type t = getSigType(content);//, tEnv);
00697     if (t->nature() == kInt) {
00698         vname = getFreshID("itbl");
00699         ctype = "int";
00700     } else {
00701         vname = getFreshID("ftbl");
00702         ctype = ifloat(); 
00703     }
00704 
00705     // declaration de la table
00706     fClass->addDeclCode(subst("static $0 \t$1[$2];", ctype, vname, T(size)));
00707     fClass->addStaticFields(subst("$0 \tmydsp::$1[$2];", ctype, vname, T(size)));
00708 
00709     // initialisation du generateur de contenu
00710     fClass->addStaticInitCode(subst("$0.init(samplingFreq);", cexp));
00711     // remplissage de la table
00712     fClass->addStaticInitCode(subst("$0.fill($1,$2);", cexp, T(size), vname));
00713 
00714     // on retourne le nom de la table
00715     return vname;
00716 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateTable ( Tree  sig,
Tree  tsize,
Tree  content 
) [protected]

Definition at line 638 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addInitCode(), CS(), Compiler::fClass, getFreshID(), getSigType(), ifloat(), isSigInt(), kInt, subst(), and T().

Referenced by generateCode().

00639 {
00640     string      generator(CS(content));
00641     string      ctype, vname;
00642     int         size;
00643 
00644     if (!isSigInt(tsize, &size)) {
00645         //fprintf(stderr, "error in ScalarCompiler::generateTable()\n"); exit(1);
00646         cerr << "error in ScalarCompiler::generateTable() : "
00647              << *tsize
00648              << " is not an integer expression "
00649              << endl;
00650     }
00651     // definition du nom et du type de la table
00652     // A REVOIR !!!!!!!!!
00653     Type t = getSigType(content);//, tEnv);
00654     if (t->nature() == kInt) {
00655         vname = getFreshID("itbl");
00656         ctype = "int";
00657     } else {
00658         vname = getFreshID("ftbl");
00659         ctype = ifloat();
00660     }
00661 
00662     // declaration de la table
00663     fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(size)));
00664 
00665     // initialisation du generateur de contenu
00666     fClass->addInitCode(subst("$0.init(samplingFreq);", generator));
00667     // remplissage de la table
00668     fClass->addInitCode(subst("$0.fill($1,$2);", generator, T(size), vname));
00669 
00670     // on retourne le nom de la table
00671     return vname;
00672 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateVariableStore ( Tree  sig,
const string &  exp 
) [protected, virtual]

Reimplemented in VectorCompiler.

Definition at line 448 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addFirstPrivateDecl(), Klass::addInitCode(), Klass::addZone2(), Compiler::fClass, getSigType(), getTypedNames(), kBlock, kKonst, kSamp, and subst().

Referenced by generateCacheCode().

00449 {
00450     string      vname, ctype;
00451     Type        t = getSigType(sig);
00452 
00453     switch (t->variability()) {
00454 
00455         case kKonst :
00456 
00457             getTypedNames(t, "Const", ctype, vname);
00458             fClass->addDeclCode(subst("$0 \t$1;", ctype, vname));
00459             fClass->addInitCode(subst("$0 = $1;", vname, exp));
00460             break;
00461 
00462         case kBlock :
00463 
00464             getTypedNames(t, "Slow", ctype, vname);
00465             fClass->addFirstPrivateDecl(vname);
00466             fClass->addZone2(subst("$0 \t$1 = $2;", ctype, vname, exp));
00467             break;
00468 
00469         case kSamp :
00470 
00471             getTypedNames(t, "Temp", ctype, vname);
00472             fClass->addExecCode(subst("$0 $1 = $2;", ctype, vname, exp));
00473             break;
00474     }
00475     return vname;
00476 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateVBargraph ( Tree  sig,
Tree  label,
Tree  min,
Tree  max,
const string &  exp 
) [protected]

Definition at line 545 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), Compiler::addUIWidget(), Klass::addZone2(), Compiler::fClass, generateCacheCode(), getFreshID(), getSigType(), hd(), kBlock, kKonst, kSamp, reverse(), subst(), tl(), tree(), uiWidget(), and xfloat().

Referenced by generateCode().

00546 {
00547     string varname = getFreshID("fbargraph");
00548     fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat()));
00549     addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
00550 
00551     Type t = getSigType(sig);
00552     switch (t->variability()) {
00553 
00554         case kKonst :
00555             fClass->addInitCode(subst("$0 = $1;", varname, exp));
00556             break;
00557 
00558         case kBlock :
00559             fClass->addZone2(subst("$0 = $1;", varname, exp));
00560             break;
00561 
00562         case kSamp :
00563             fClass->addExecCode(subst("$0 = $1;", varname, exp));
00564             break;
00565     }
00566 
00567     //return varname;
00568     return generateCacheCode(sig, varname);
00569 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateVSlider ( Tree  sig,
Tree  label,
Tree  cur,
Tree  min,
Tree  max,
Tree  step 
) [protected]

Definition at line 517 of file compile_scal.cpp.

References Klass::addDeclCode(), Klass::addInitCode(), Compiler::addUIWidget(), Compiler::fClass, generateCacheCode(), getFreshID(), hd(), reverse(), subst(), T(), tl(), tree(), tree2float(), uiWidget(), and xfloat().

Referenced by generateCode().

00518 {
00519     string varname = getFreshID("fslider");
00520     fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat()));
00521     fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur))));
00522     addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
00523     return generateCacheCode(sig, varname);
00524 }

Here is the call graph for this function:

Here is the caller graph for this function:

string ScalarCompiler::generateWRTbl ( Tree  sig,
Tree  tbl,
Tree  idx,
Tree  data 
) [protected]

Definition at line 723 of file compile_scal.cpp.

References Klass::addExecCode(), CS(), Compiler::fClass, and subst().

Referenced by generateCode().

00724 {
00725     string tblName(CS(tbl));
00726     fClass->addExecCode(subst("$0[$1] = $2;", tblName, CS(idx), CS(data)));
00727     return tblName;
00728 }

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(), Compiler::fClass, generateCacheCode(), xtended::generateCode(), getSigType(), getUserData(), and xtended::needCache().

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.

References fCompileProperty.

Referenced by VectorCompiler::CS(), CS(), generateCacheCode(), generateRDTbl(), and generateStaticTable().

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

Here is the caller graph for this function:

string ScalarCompiler::getFreshID ( const string &  prefix  )  [protected]

Definition at line 81 of file compile_scal.cpp.

References fIDCounters, subst(), and T().

Referenced by generateButton(), generateCheckbox(), generateHBargraph(), generateHSlider(), generateIota(), generateNumEntry(), generatePrefix(), generateSelect2(), generateSelect3(), generateSigGen(), generateStaticSigGen(), generateStaticTable(), generateTable(), generateVBargraph(), generateVSlider(), and getTypedNames().

00082 {
00083     if (fIDCounters.find(prefix) == fIDCounters.end()) {
00084         fIDCounters[prefix]=0;
00085     }
00086     int n = fIDCounters[prefix];
00087     fIDCounters[prefix] = n+1;
00088     return subst("$0$1", prefix, T(n));
00089 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ScalarCompiler::getSharingCount ( Tree  t  )  [protected]

Definition at line 62 of file sharing.cpp.

References fSharingKey, Node::getInt(), getProperty(), and CTree::node().

Referenced by VectorCompiler::generateCacheCode(), generateCacheCode(), VectorCompiler::needSeparateLoop(), and sharingAnnotation().

00063 {
00064     //cerr << "getSharingCount of : " << *sig << " = ";
00065     Tree c;
00066     if (getProperty(sig, fSharingKey, c)) {
00067         //cerr << c->node().getInt() << endl;
00068         return c->node().getInt();
00069     } else {
00070         //cerr << 0 << endl;
00071         return 0;
00072     }
00073 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ScalarCompiler::getTypedNames ( Type  t,
const string &  prefix,
string &  ctype,
string &  vname 
) [protected]

Definition at line 401 of file compile_scal.cpp.

References getFreshID(), ifloat(), kInt, and subst().

Referenced by VectorCompiler::generateCacheCode(), generateCacheCode(), generateFConst(), generateFVar(), generateNumber(), generateRec(), VectorCompiler::generateVariableStore(), and generateVariableStore().

00402 {
00403     if (t->nature() == kInt) {
00404         ctype = "int"; vname = subst("i$0", getFreshID(prefix));
00405     } else {
00406         ctype = ifloat(); vname = subst("f$0", getFreshID(prefix));
00407     }
00408 }

Here is the call graph for this function:

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.

References fVectorProperty.

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

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

Here is the caller graph for this function:

int ScalarCompiler::pow2limit ( int  x  )  [protected]

Compute the minimal power of 2 greater than x.

Definition at line 1065 of file compile_scal.cpp.

Referenced by generateDelayLine(), generateDelayVecNoTemp(), VectorCompiler::generateFixDelay(), and generateFixDelay().

01066 {
01067     int n = 2;
01068     while (n < x) { n = 2*n; }
01069     return n;
01070 }

Here is the caller graph for this function:

Tree ScalarCompiler::prepare ( Tree  L0  )  [protected, virtual]

Implements Compiler.

Definition at line 96 of file compile_scal.cpp.

References deBruijn2Sym(), endTiming(), fOccMarkup, OccMarkup::mark(), privatise(), recursivnessAnnotation(), sharingAnalysis(), simplify(), startTiming(), and typeAnnotation().

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

00097 {
00098 startTiming("ScalarCompiler::prepare");
00099  startTiming("deBruijn2Sym");
00100     Tree L1 = deBruijn2Sym(LS);     // convert debruijn recursion into symbolic recursion
00101  endTiming("deBruijn2Sym");
00102     Tree L2 = simplify(L1);         // simplify by executing every computable operation
00103     Tree L3 = privatise(L2);        // Un-share tables with multiple writers
00104 
00105     recursivnessAnnotation(L3);     // Annotate L3 with recursivness information
00106     typeAnnotation(L3);             // Annotate L3 with type information
00107     sharingAnalysis(L3);            // annotate L3 with sharing count
00108     fOccMarkup.mark(L3);            // annotate L3 with occurences analysis
00109 endTiming("ScalarCompiler::prepare");
00110     return L3;
00111 }

Here is the call graph for this function:

Here is the caller graph for this function:

Tree ScalarCompiler::prepare2 ( Tree  L0  )  [protected, virtual]

Implements Compiler.

Definition at line 113 of file compile_scal.cpp.

References endTiming(), fOccMarkup, OccMarkup::mark(), recursivnessAnnotation(), sharingAnalysis(), startTiming(), and typeAnnotation().

Referenced by compileSingleSignal().

00114 {
00115 startTiming("ScalarCompiler::prepare2");
00116     recursivnessAnnotation(L0);     // Annotate L0 with recursivness information
00117     typeAnnotation(L0);             // Annotate L0 with type information
00118     sharingAnalysis(L0);            // annotate L0 with sharing count
00119     fOccMarkup.mark(L0);            // annotate L0 with occurences analysis
00120 endTiming("ScalarCompiler::prepare2");
00121 
00122     return L0;
00123 }

Here is the call graph for this function:

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.

References fCompileProperty.

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

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

Here is the caller graph for this function:

void ScalarCompiler::setSharingCount ( Tree  t,
int  count 
) [protected]

Definition at line 75 of file sharing.cpp.

References fSharingKey, setProperty(), and tree().

Referenced by sharingAnnotation().

00076 {
00077     //cerr << "setSharingCount of : " << *sig << " <- " << count << endl;
00078     setProperty(sig, fSharingKey, tree(count));
00079 }

Here is the call graph for this function:

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.

References fVectorProperty.

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

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

Here is the caller graph for this function:

void ScalarCompiler::sharingAnalysis ( Tree  t  )  [protected]

Definition at line 88 of file sharing.cpp.

References fSharingKey, hd(), isList(), kSamp, sharingAnnotation(), shprkey(), and tl().

Referenced by prepare(), and prepare2().

00089 {
00090     fSharingKey = shprkey(t);
00091     if (isList(t)) {
00092         while (isList(t)) {
00093             sharingAnnotation(kSamp, hd(t));
00094             t = tl(t);
00095         }
00096     } else {
00097         sharingAnnotation(kSamp, t);
00098     }
00099 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ScalarCompiler::sharingAnnotation ( int  vctxt,
Tree  t 
) [protected]

Definition at line 106 of file sharing.cpp.

References getSharingCount(), getSigType(), getSubSignals(), isSigGen(), and setSharingCount().

Referenced by sharingAnalysis().

00107 {
00108     //cerr << "START sharing annotation of " << *sig << endl;
00109     int count = getSharingCount(sig);
00110 
00111     if (count > 0) {
00112         // it is not our first visit
00113         setSharingCount(sig, count+1);
00114 
00115     } else {
00116         // it is our first visit,
00117         int v = getSigType(sig)->variability();
00118 
00119         // check "time sharing" cases
00120         if (v < vctxt) {
00121             setSharingCount(sig, 2);    // time sharing occurence : slower expression in faster context
00122         } else {
00123             setSharingCount(sig, 1);    // regular occurence
00124         }
00125 
00126         // Annotate the sub signals
00127         vector<Tree> subsig;
00128         int n = getSubSignals(sig, subsig);
00129         if (n>0 && ! isSigGen(sig)) {
00130             for (int i=0; i<n; i++) sharingAnnotation(v, subsig[i]);
00131         }
00132     }
00133     //cerr << "END sharing annotation of " << *sig << endl;
00134 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 42 of file compile_scal.hh.

Referenced by getCompiledExpression(), and setCompiledExpression().

bool ScalarCompiler::fHasIota [protected]

Definition at line 48 of file compile_scal.hh.

Referenced by ensureIotaCode().

map< string, int > ScalarCompiler::fIDCounters [static, protected]

Definition at line 45 of file compile_scal.hh.

Referenced by getFreshID().

Definition at line 46 of file compile_scal.hh.

Referenced by getSharingCount(), setSharingCount(), and sharingAnalysis().

Definition at line 43 of file compile_scal.hh.

Referenced by getVectorNameProperty(), and setVectorNameProperty().


The documentation for this class was generated from the following files:
Generated on Thu Apr 29 00:00:23 2010 for FAUST compiler by  doxygen 1.6.3