Compile a list of FAUST signals into a scalar C++ class. More...
#include <compile_scal.hh>
Inherits Compiler.
Inherited by VectorCompiler.
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 (using if-then-else) ((int n = sel==0)? s0 : ((sel==1)? s1 : s2)) int nn; ((nn=sel) ? ((nn==1)? s1 : s2) : s0);. | |
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 |
Compile a list of FAUST signals into a scalar C++ class.
Definition at line 39 of file compile_scal.hh.
ScalarCompiler::ScalarCompiler | ( | const string & | name, | |
const string & | super, | |||
int | numInputs, | |||
int | numOutputs | |||
) | [inline] |
Definition at line 53 of file compile_scal.hh.
ScalarCompiler::ScalarCompiler | ( | Klass * | k | ) | [inline] |
Definition at line 58 of file compile_scal.hh.
void ScalarCompiler::compileMultiSignal | ( | Tree | lsig | ) | [virtual] |
Implements Compiler.
Reimplemented in SchedulerCompiler, and VectorCompiler.
Definition at line 128 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().
00129 { 00130 //contextor recursivness(0); 00131 L = prepare(L); // optimize, share and annotate expression 00132 00133 for (int i = 0; i < fClass->inputs(); i++) { 00134 fClass->addZone3(subst("$1* input$0 = input[$0];", T(i), xfloat())); 00135 } 00136 for (int i = 0; i < fClass->outputs(); i++) { 00137 fClass->addZone3(subst("$1* output$0 = output[$0];", T(i), xfloat())); 00138 } 00139 00140 for (int i = 0; isList(L); L = tl(L), i++) { 00141 Tree sig = hd(L); 00142 fClass->addExecCode(subst("output$0[i] = $2$1;", T(i), CS(sig), xcast())); 00143 } 00144 generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot)); 00145 generateMacroInterfaceTree("", prepareUserInterfaceTree(fUIRoot)); 00146 if (fDescription) { 00147 fDescription->ui(prepareUserInterfaceTree(fUIRoot)); 00148 } 00149 }
void ScalarCompiler::compilePreparedSignalList | ( | Tree | lsig | ) | [protected] |
void ScalarCompiler::compileSingleSignal | ( | Tree | lsig | ) | [virtual] |
Implements Compiler.
Definition at line 156 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().
00157 { 00158 //contextor recursivness(0); 00159 sig = prepare2(sig); // optimize and annotate expression 00160 fClass->addExecCode(subst("output[i] = $0;", CS(sig))); 00161 generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot)); 00162 generateMacroInterfaceTree("", prepareUserInterfaceTree(fUIRoot)); 00163 if (fDescription) { 00164 fDescription->ui(prepareUserInterfaceTree(fUIRoot)); 00165 } 00166 }
string ScalarCompiler::CS | ( | Tree | sig | ) | [protected, virtual] |
Compile a signal.
sig | the signal expression to compile. |
Reimplemented in VectorCompiler.
Definition at line 201 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().
00202 { 00203 //contextor contextRecursivness; 00204 string code; 00205 00206 if (!getCompiledExpression(sig, code)) { 00207 // not compiled yet 00208 /* if (getRecursivness(sig) != contextRecursivness.get()) { 00209 contextRecursivness.set(getRecursivness(sig)); 00210 }*/ 00211 code = generateCode(sig); 00212 setCompiledExpression(sig, code); 00213 } 00214 return code; 00215 }
void ScalarCompiler::ensureIotaCode | ( | ) | [protected] |
Generate code for a unique IOTA variable increased at each sample and used to index ring buffers.
Definition at line 1202 of file compile_scal.cpp.
References Klass::addDeclCode(), Klass::addInitCode(), Klass::addPostCode(), Compiler::fClass, and fHasIota.
Referenced by generateDelayLine(), and generateDelayVecNoTemp().
01203 { 01204 if (!fHasIota) { 01205 fHasIota = true; 01206 fClass->addDeclCode("int \tIOTA;"); 01207 fClass->addInitCode("IOTA = 0;"); 01208 fClass->addPostCode("IOTA = IOTA+1;"); 01209 } 01210 }
Definition at line 362 of file compile_scal.cpp.
References CS(), gBinOpTable, generateCacheCode(), and subst().
Referenced by generateCode().
00363 { 00364 return generateCacheCode(sig, subst("($0 $1 $2)", CS(arg1), gBinOpTable[opcode]->fName, CS(arg2))); 00365 }
Definition at line 491 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().
00492 { 00493 string varname = getFreshID("fbutton"); 00494 fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat())); 00495 fClass->addInitCode(subst("$0 = 0.0;", varname)); 00496 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig)); 00497 return generateCacheCode(sig, varname); 00498 }
string ScalarCompiler::generateCacheCode | ( | Tree | sig, | |
const string & | exp | |||
) | [protected, virtual] |
Reimplemented in VectorCompiler.
Definition at line 403 of file compile_scal.cpp.
References fOccMarkup, generateDelayVec(), generateVariableStore(), getCompiledExpression(), Occurences::getMaxDelay(), getSharingCount(), getSigType(), getTypedNames(), and OccMarkup::retrieve().
Referenced by generateBinOp(), generateButton(), generateCheckbox(), generateCode(), generateFFun(), generateFixDelay(), generateFloatCast(), generateFVar(), generateHBargraph(), generateHSlider(), generateInput(), generateIntCast(), generateNumEntry(), generateRDTbl(), generateSelect2(), generateSelect3(), generateVBargraph(), generateVSlider(), and generateXtended().
00404 { 00405 string vname, ctype, code; 00406 int sharing = getSharingCount(sig); 00407 Occurences* o = fOccMarkup.retrieve(sig); 00408 00409 // check reentrance 00410 if (getCompiledExpression(sig, code)) { 00411 return code; 00412 } 00413 00414 // check for expression occuring in delays 00415 if (o->getMaxDelay()>0) { 00416 00417 getTypedNames(getSigType(sig), "Vec", ctype, vname); 00418 if (sharing>1) { 00419 return generateDelayVec(sig, generateVariableStore(sig,exp), ctype, vname, o->getMaxDelay()); 00420 } else { 00421 return generateDelayVec(sig, exp, ctype, vname, o->getMaxDelay()); 00422 } 00423 00424 } else if (sharing == 1) { 00425 00426 return exp; 00427 00428 } else if (sharing > 1) { 00429 00430 return generateVariableStore(sig, exp); 00431 00432 } else { 00433 cerr << "Error in sharing count (" << sharing << ") for " << *sig << endl; 00434 exit(1); 00435 } 00436 00437 return "Error in generateCacheCode"; 00438 }
Definition at line 500 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().
00501 { 00502 string varname = getFreshID("fcheckbox"); 00503 fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat())); 00504 fClass->addInitCode(subst("$0 = 0.0;", varname)); 00505 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig)); 00506 return generateCacheCode(sig, varname); 00507 }
string ScalarCompiler::generateCode | ( | Tree | sig | ) | [protected, virtual] |
Main code generator dispatch.
sig | the signal expression to compile. |
Reimplemented in VectorCompiler.
Definition at line 226 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().
00227 { 00228 #if 0 00229 fprintf(stderr, "CALL generateCode("); 00230 printSignal(sig, stderr); 00231 fprintf(stderr, ")\n"); 00232 #endif 00233 00234 int i; 00235 double r; 00236 Tree c, sel, x, y, z, label, id, ff, largs, type, name, file; 00237 00238 //printf("compilation of %p : ", sig); print(sig); printf("\n"); 00239 00240 if ( getUserData(sig) ) { return generateXtended(sig); } 00241 else if ( isSigInt(sig, &i) ) { return generateNumber(sig, T(i)); } 00242 else if ( isSigReal(sig, &r) ) { return generateNumber(sig, T(r)); } 00243 else if ( isSigInput(sig, &i) ) { return generateInput (sig, T(i)); } 00244 else if ( isSigOutput(sig, &i, x) ) { return generateOutput (sig, T(i), CS(x));} 00245 00246 else if ( isSigFixDelay(sig, x, y) ) { return generateFixDelay (sig, x, y); } 00247 else if ( isSigPrefix(sig, x, y) ) { return generatePrefix (sig, x, y); } 00248 else if ( isSigIota(sig, x) ) { return generateIota (sig, x); } 00249 00250 else if ( isSigBinOp(sig, &i, x, y) ) { return generateBinOp (sig, i, x, y); } 00251 else if ( isSigFFun(sig, ff, largs) ) { return generateFFun (sig, ff, largs); } 00252 else if ( isSigFConst(sig, type, name, file) ) { return generateFConst(sig, tree2str(file), tree2str(name)); } 00253 else if ( isSigFVar(sig, type, name, file) ) { return generateFVar(sig, tree2str(file), tree2str(name)); } 00254 00255 else if ( isSigTable(sig, id, x, y) ) { return generateTable (sig, x, y); } 00256 else if ( isSigWRTbl(sig, id, x, y, z) ) { return generateWRTbl (sig, x, y, z); } 00257 else if ( isSigRDTbl(sig, x, y) ) { return generateRDTbl (sig, x, y); } 00258 00259 else if ( isSigSelect2(sig, sel, x, y) ) { return generateSelect2 (sig, sel, x, y); } 00260 else if ( isSigSelect3(sig, sel, x, y, z) ) { return generateSelect3 (sig, sel, x, y, z); } 00261 00262 else if ( isSigGen(sig, x) ) { return generateSigGen (sig, x); } 00263 00264 else if ( isProj(sig, &i, x) ) { return generateRecProj (sig, x, i); } 00265 00266 else if ( isSigIntCast(sig, x) ) { return generateIntCast (sig, x); } 00267 else if ( isSigFloatCast(sig, x) ) { return generateFloatCast (sig, x); } 00268 00269 else if ( isSigButton(sig, label) ) { return generateButton (sig, label); } 00270 else if ( isSigCheckbox(sig, label) ) { return generateCheckbox (sig, label); } 00271 else if ( isSigVSlider(sig, label,c,x,y,z) ) { return generateVSlider (sig, label, c,x,y,z); } 00272 else if ( isSigHSlider(sig, label,c,x,y,z) ) { return generateHSlider (sig, label, c,x,y,z); } 00273 else if ( isSigNumEntry(sig, label,c,x,y,z) ) { return generateNumEntry (sig, label, c,x,y,z); } 00274 00275 else if ( isSigVBargraph(sig, label,x,y,z) ) { return generateVBargraph (sig, label, x, y, CS(z)); } 00276 else if ( isSigHBargraph(sig, label,x,y,z) ) { return generateHBargraph (sig, label, x, y, CS(z)); } 00277 else if ( isSigAttach(sig, x, y) ) { CS(y); return generateCacheCode(sig, CS(x)); } 00278 00279 else { 00280 printf("Error in compiling signal, unrecognized signal : "); 00281 print(sig); 00282 printf("\n"); 00283 exit(1); 00284 } 00285 return "error in generate code"; 00286 }
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 1156 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().
01157 { 01158 //assert(mxd > 0); 01159 if (mxd == 0) { 01160 // cerr << "MXD==0 : " << vname << " := " << exp << endl; 01161 // no need for a real vector 01162 fClass->addExecCode(subst("$0 \t$1 = $2;", ctype, vname, exp)); 01163 01164 01165 } else if (mxd < gMaxCopyDelay) { 01166 01167 // short delay : we copy 01168 fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(mxd+1))); 01169 fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i] = 0;", vname, T(mxd+1))); 01170 fClass->addExecCode(subst("$0[0] = $1;", vname, exp)); 01171 01172 // generate post processing copy code to update delay values 01173 if (mxd == 1) { 01174 fClass->addPostCode(subst("$0[1] = $0[0];", vname)); 01175 } else if (mxd == 2) { 01176 fClass->addPostCode(subst("$0[2] = $0[1]; $0[1] = $0[0];", vname)); 01177 } else { 01178 fClass->addPostCode(subst("for (int i=$0; i>0; i--) $1[i] = $1[i-1];", T(mxd), vname)); 01179 } 01180 01181 } else { 01182 01183 // generate code for a long delay : we use a ring buffer of size N = 2**x > mxd 01184 int N = pow2limit(mxd+1); 01185 01186 // we need a iota index 01187 ensureIotaCode(); 01188 01189 // declare and init 01190 fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(N))); 01191 fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i] = 0;", vname, T(N))); 01192 01193 // execute 01194 fClass->addExecCode(subst("$0[IOTA&$1] = $2;", vname, T(N-1), exp)); 01195 } 01196 }
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 1094 of file compile_scal.cpp.
References generateDelayVecNoTemp(), getSigType(), and kSamp.
Referenced by generateCacheCode(), generateFConst(), and generateNumber().
01095 { 01096 string s = generateDelayVecNoTemp(sig, exp, ctype, vname, mxd); 01097 if (getSigType(sig)->variability() < kSamp) { 01098 return exp; 01099 } else { 01100 return s; 01101 } 01102 }
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 1108 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().
01109 { 01110 assert(mxd > 0); 01111 01112 //bool odocc = fOccMarkup.retrieve(sig)->hasOutDelayOccurences(); 01113 01114 if (mxd < gMaxCopyDelay) { 01115 01116 // short delay : we copy 01117 fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(mxd+1))); 01118 fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i] = 0;", vname, T(mxd+1))); 01119 fClass->addExecCode(subst("$0[0] = $1;", vname, exp)); 01120 01121 // generate post processing copy code to update delay values 01122 if (mxd == 1) { 01123 fClass->addPostCode(subst("$0[1] = $0[0];", vname)); 01124 } else if (mxd == 2) { 01125 //fClass->addPostCode(subst("$0[2] = $0[1];", vname)); 01126 fClass->addPostCode(subst("$0[2] = $0[1]; $0[1] = $0[0];", vname)); 01127 } else { 01128 fClass->addPostCode(subst("for (int i=$0; i>0; i--) $1[i] = $1[i-1];", T(mxd), vname)); 01129 } 01130 setVectorNameProperty(sig, vname); 01131 return subst("$0[0]", vname); 01132 01133 } else { 01134 01135 // generate code for a long delay : we use a ring buffer of size N = 2**x > mxd 01136 int N = pow2limit(mxd+1); 01137 01138 // we need a iota index 01139 ensureIotaCode(); 01140 01141 // declare and init 01142 fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(N))); 01143 fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i] = 0;", vname, T(N))); 01144 01145 // execute 01146 fClass->addExecCode(subst("$0[IOTA&$1] = $2;", vname, T(N-1), exp)); 01147 setVectorNameProperty(sig, vname); 01148 return subst("$0[IOTA&$1]", vname, T(N-1)); 01149 } 01150 }
string ScalarCompiler::generateFConst | ( | Tree | sig, | |
const string & | file, | |||
const string & | name | |||
) | [protected] |
Definition at line 312 of file compile_scal.cpp.
References Compiler::addIncludeFile(), fOccMarkup, generateDelayVec(), Occurences::getMaxDelay(), getSigType(), getTypedNames(), and OccMarkup::retrieve().
Referenced by generateCode().
00313 { 00314 string ctype, vname; 00315 Occurences* o = fOccMarkup.retrieve(sig); 00316 00317 addIncludeFile(file); 00318 00319 if (o->getMaxDelay()>0) { 00320 getTypedNames(getSigType(sig), "Vec", ctype, vname); 00321 generateDelayVec(sig, exp, ctype, vname, o->getMaxDelay()); 00322 } 00323 return exp; 00324 }
Definition at line 372 of file compile_scal.cpp.
References Compiler::addIncludeFile(), Compiler::addLibrary(), CS(), ffarity(), ffincfile(), fflibfile(), ffname(), generateCacheCode(), and nth().
Referenced by generateCode().
00373 { 00374 addIncludeFile(ffincfile(ff)); //printf("inc file %s\n", ffincfile(ff)); 00375 addLibrary(fflibfile(ff)); //printf("lib file %s\n", fflibfile(ff)); 00376 00377 string code = ffname(ff); 00378 code += '('; 00379 string sep = ""; 00380 for (int i = 0; i< ffarity(ff); i++) { 00381 code += sep; 00382 code += CS(nth(largs, i)); 00383 sep = ", "; 00384 } 00385 code += ')'; 00386 return generateCacheCode(sig, code); 00387 }
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 1051 of file compile_scal.cpp.
References CS(), fOccMarkup, generateCacheCode(), Occurences::getMaxDelay(), getVectorNameProperty(), gMaxCopyDelay, isSigInt(), pow2limit(), OccMarkup::retrieve(), subst(), and T().
Referenced by generateCode().
01052 { 01053 int mxd, d; 01054 string vecname; 01055 01056 //cerr << "ScalarCompiler::generateFixDelay sig = " << *sig << endl; 01057 //cerr << "ScalarCompiler::generateFixDelay exp = " << *exp << endl; 01058 //cerr << "ScalarCompiler::generateFixDelay del = " << *delay << endl; 01059 01060 CS(exp); // ensure exp is compiled to have a vector name 01061 01062 mxd = fOccMarkup.retrieve(exp)->getMaxDelay(); 01063 01064 if (! getVectorNameProperty(exp, vecname)) { 01065 cerr << "No vector name for : " << ppsig(exp) << endl; 01066 assert(0); 01067 } 01068 01069 if (mxd == 0) { 01070 // not a real vector name but a scalar name 01071 return vecname; 01072 01073 } else if (mxd < gMaxCopyDelay) { 01074 if (isSigInt(delay, &d)) { 01075 return subst("$0[$1]", vecname, CS(delay)); 01076 } else { 01077 return generateCacheCode(sig, subst("$0[$1]", vecname, CS(delay))); 01078 } 01079 01080 } else { 01081 01082 // long delay : we use a ring buffer of size 2^x 01083 int N = pow2limit( mxd+1 ); 01084 return generateCacheCode(sig, subst("$0[(IOTA-$1)&$2]", vecname, CS(delay), T(N-1))); 01085 } 01086 }
Definition at line 482 of file compile_scal.cpp.
References CS(), generateCacheCode(), ifloat(), and subst().
Referenced by generateCode().
00483 { 00484 return generateCacheCode(sig, subst("$1($0)", CS(x), ifloat())); 00485 }
string ScalarCompiler::generateFVar | ( | Tree | sig, | |
const string & | file, | |||
const string & | name | |||
) | [protected] |
Definition at line 331 of file compile_scal.cpp.
References Compiler::addIncludeFile(), and generateCacheCode().
Referenced by generateCode().
00332 { 00333 string ctype, vname; 00334 00335 addIncludeFile(file); 00336 return generateCacheCode(sig, exp); 00337 }
string ScalarCompiler::generateHBargraph | ( | Tree | sig, | |
Tree | label, | |||
Tree | min, | |||
Tree | max, | |||
const string & | exp | |||
) | [protected] |
Definition at line 565 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().
00566 { 00567 string varname = getFreshID("fbargraph"); 00568 fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat())); 00569 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig)); 00570 00571 Type t = getSigType(sig); 00572 switch (t->variability()) { 00573 00574 case kKonst : 00575 fClass->addInitCode(subst("$0 = $1;", varname, exp)); 00576 break; 00577 00578 case kBlock : 00579 fClass->addZone2(subst("$0 = $1;", varname, exp)); 00580 break; 00581 00582 case kSamp : 00583 fClass->addExecCode(subst("$0 = $1;", varname, exp)); 00584 break; 00585 } 00586 00587 //return varname; 00588 return generateCacheCode(sig, varname); 00589 }
string ScalarCompiler::generateHSlider | ( | Tree | sig, | |
Tree | label, | |||
Tree | cur, | |||
Tree | min, | |||
Tree | max, | |||
Tree | step | |||
) | [protected] |
Definition at line 519 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().
00520 { 00521 string varname = getFreshID("fslider"); 00522 fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat())); 00523 fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur)))); 00524 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig)); 00525 return generateCacheCode(sig, varname); 00526 }
string ScalarCompiler::generateInput | ( | Tree | sig, | |
const string & | idx | |||
) | [protected] |
Definition at line 344 of file compile_scal.cpp.
References generateCacheCode(), icast(), and subst().
Referenced by generateCode().
00345 { 00346 return generateCacheCode(sig, subst("$1input$0[i]", idx, icast())); 00347 }
Definition at line 477 of file compile_scal.cpp.
References CS(), generateCacheCode(), and subst().
Referenced by generateCode().
00478 { 00479 return generateCacheCode(sig, subst("int($0)", CS(x))); 00480 }
Definition at line 842 of file compile_scal.cpp.
References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), Compiler::fClass, getFreshID(), isPowerOf2(), isSigInt(), subst(), and T().
Referenced by generateCode().
00843 { 00844 int size; 00845 if (!isSigInt(n, &size)) { fprintf(stderr, "error in generateIota\n"); exit(1); } 00846 00847 string vperm = getFreshID("iota"); 00848 00849 fClass->addDeclCode(subst("int \t$0;", vperm)); 00850 fClass->addInitCode(subst("$0 = 0;", vperm)); 00851 00852 if (isPowerOf2(size)) { 00853 fClass->addExecCode(subst("$0 = ($0+1)&$1;", vperm, T(size-1))); 00854 } else { 00855 fClass->addExecCode(subst("if (++$0 == $1) $0=0;", vperm, T(size))); 00856 } 00857 return vperm; 00858 }
string ScalarCompiler::generateNumber | ( | Tree | sig, | |
const string & | exp | |||
) | [protected] |
Definition at line 294 of file compile_scal.cpp.
References fOccMarkup, generateDelayVec(), Occurences::getMaxDelay(), getSigType(), getTypedNames(), and OccMarkup::retrieve().
Referenced by generateCode().
00295 { 00296 string ctype, vname; 00297 Occurences* o = fOccMarkup.retrieve(sig); 00298 00299 // check for number occuring in delays 00300 if (o->getMaxDelay()>0) { 00301 getTypedNames(getSigType(sig), "Vec", ctype, vname); 00302 generateDelayVec(sig, exp, ctype, vname, o->getMaxDelay()); 00303 } 00304 return exp; 00305 }
string ScalarCompiler::generateNumEntry | ( | Tree | sig, | |
Tree | label, | |||
Tree | cur, | |||
Tree | min, | |||
Tree | max, | |||
Tree | step | |||
) | [protected] |
Definition at line 528 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().
00529 { 00530 string varname = getFreshID("fentry"); 00531 fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat())); 00532 fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur)))); 00533 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig)); 00534 return generateCacheCode(sig, varname); 00535 }
string ScalarCompiler::generateOutput | ( | Tree | sig, | |
const string & | idx, | |||
const string & | arg1 | |||
) | [protected] |
Definition at line 350 of file compile_scal.cpp.
References Klass::addExecCode(), Compiler::fClass, subst(), and xcast().
Referenced by generateCode().
00351 { 00352 string dst = subst("output$0[i]", idx); 00353 fClass->addExecCode(subst("$0 = $2$1;", dst, arg, xcast())); 00354 return dst; 00355 }
Definition at line 816 of file compile_scal.cpp.
References Klass::addDeclCode(), Klass::addExecCode(), Klass::addInitCode(), CS(), cType(), Compiler::fClass, getFreshID(), getSigType(), and subst().
Referenced by generateCode().
00817 { 00818 Type te = getSigType(sig);//, tEnv); 00819 00820 string vperm = getFreshID("M"); 00821 string vtemp = getFreshID("T"); 00822 00823 string type = cType(te); 00824 00825 fClass->addDeclCode(subst("$0 \t$1;", type, vperm)); 00826 fClass->addInitCode(subst("$0 = $1;", vperm, CS(x))); 00827 00828 fClass->addExecCode(subst("$0 $1 = $2;", type, vtemp, vperm)); 00829 fClass->addExecCode(subst("$0 = $1;", vperm, CS(e))); 00830 return vtemp; 00831 }
Definition at line 730 of file compile_scal.cpp.
References CS(), generateCacheCode(), generateStaticTable(), getCompiledExpression(), isSigTable(), setCompiledExpression(), and subst().
Referenced by generateCode().
00731 { 00732 // YO le 21/04/05 : La lecture des tables n'�ait pas mise dans le cache 00733 // et donc le code �ait dupliqu�(dans tester.dsp par exemple) 00734 //return subst("$0[$1]", CS(tEnv, tbl), CS(tEnv, idx)); 00735 00736 //cerr << "generateRDTable " << *sig << endl; 00737 // test the special case of a read only table that can be compiled 00738 // has a static member 00739 Tree id, size, content; 00740 if( isSigTable(tbl, id, size, content) ) { 00741 string tblname; 00742 if (!getCompiledExpression(tbl, tblname)) { 00743 tblname = setCompiledExpression(tbl, generateStaticTable(tbl, size, content)); 00744 } 00745 return generateCacheCode(sig, subst("$0[$1]", tblname, CS(idx))); 00746 } else { 00747 return generateCacheCode(sig, subst("$0[$1]", CS(tbl), CS(idx))); 00748 } 00749 }
Generate code for a group of mutually recursive definitions.
Definition at line 778 of file compile_scal.cpp.
References CS(), fOccMarkup, generateDelayLine(), Occurences::getMaxDelay(), getSigType(), getTypedNames(), len(), nth(), OccMarkup::retrieve(), setVectorNameProperty(), and sigProj().
Referenced by generateRecProj().
00779 { 00780 int N = len(le); 00781 00782 vector<bool> used(N); 00783 vector<int> delay(N); 00784 vector<string> vname(N); 00785 vector<string> ctype(N); 00786 00787 // prepare each element of a recursive definition 00788 for (int i=0; i<N; i++) { 00789 Tree e = sigProj(i,sig); // recreate each recursive definition 00790 if (fOccMarkup.retrieve(e)) { 00791 // this projection is used 00792 used[i] = true; 00793 getTypedNames(getSigType(e), "Rec", ctype[i], vname[i]); 00794 setVectorNameProperty(e, vname[i]); 00795 delay[i] = fOccMarkup.retrieve(e)->getMaxDelay(); 00796 } else { 00797 // this projection is not used therefore 00798 // we should not generte code for it 00799 used[i] = false; 00800 } 00801 } 00802 00803 // generate delayline for each element of a recursive definition 00804 for (int i=0; i<N; i++) { 00805 if (used[i]) { 00806 generateDelayLine(ctype[i], vname[i], delay[i], CS(nth(le,i))); 00807 } 00808 } 00809 }
Generate code for a projection of a group of mutually recursive definitions.
Definition at line 761 of file compile_scal.cpp.
References generateRec(), getVectorNameProperty(), isRec(), and subst().
Referenced by generateCode().
00762 { 00763 string vname; 00764 Tree var, le; 00765 00766 if ( ! getVectorNameProperty(sig, vname)) { 00767 assert(isRec(r, var, le)); 00768 generateRec(r, var, le); 00769 assert(getVectorNameProperty(sig, vname)); 00770 } 00771 return subst("$0[0]", vname); 00772 }
Generate a select2 code.
Definition at line 869 of file compile_scal.cpp.
References CS(), generateCacheCode(), and subst().
Referenced by generateCode().
00870 { 00871 return generateCacheCode(sig, subst( "(($0)?$1:$2)", CS(sel), CS(s2), CS(s1) ) ); 00872 }
string ScalarCompiler::generateSelect3 | ( | Tree | sig, | |
Tree | sel, | |||
Tree | s1, | |||
Tree | s2, | |||
Tree | s3 | |||
) | [protected] |
Generate a select3 code (using if-then-else) ((int n = sel==0)? s0 : ((sel==1)? s1 : s2)) int nn; ((nn=sel) ? ((nn==1)? s1 : s2) : s0);.
Definition at line 880 of file compile_scal.cpp.
References CS(), generateCacheCode(), and subst().
Referenced by generateCode().
00881 { 00882 return generateCacheCode(sig, subst( "(($0==0)? $1 : (($0==1)?$2:$3) )", CS(sel), CS(s1), CS(s2), CS(s3) ) ); 00883 }
Definition at line 604 of file compile_scal.cpp.
References Klass::addInitCode(), Klass::addSubKlass(), Compiler::fClass, getFreshID(), signal2klass(), and subst().
Referenced by generateCode().
00605 { 00606 string klassname = getFreshID("SIG"); 00607 string signame = getFreshID("sig"); 00608 00609 fClass->addSubKlass(signal2klass(klassname, content)); 00610 fClass->addInitCode(subst("$0 $1;", klassname, signame)); 00611 00612 return signame; 00613 }
Definition at line 615 of file compile_scal.cpp.
References Klass::addStaticInitCode(), Klass::addSubKlass(), Compiler::fClass, getFreshID(), signal2klass(), and subst().
Referenced by generateStaticTable().
00616 { 00617 string klassname = getFreshID("SIG"); 00618 string signame = getFreshID("sig"); 00619 00620 fClass->addSubKlass(signal2klass(klassname, content)); 00621 fClass->addStaticInitCode(subst("$0 $1;", klassname, signame)); 00622 00623 return signame; 00624 }
Definition at line 668 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().
00669 { 00670 //string generator(CS(content)); 00671 Tree g; 00672 string cexp; 00673 string ctype, vname; 00674 int size; 00675 00676 assert ( isSigGen(content, g) ); 00677 if (!getCompiledExpression(content, cexp)) { 00678 cexp = setCompiledExpression(content, generateStaticSigGen(content, g)); 00679 } 00680 00681 if (!isSigInt(tsize, &size)) { 00682 //fprintf(stderr, "error in ScalarCompiler::generateTable()\n"); exit(1); 00683 cerr << "error in ScalarCompiler::generateTable() : " 00684 << *tsize 00685 << " is not an integer expression " 00686 << endl; 00687 exit(1); 00688 } 00689 // definition du nom et du type de la table 00690 // A REVOIR !!!!!!!!! 00691 Type t = getSigType(content);//, tEnv); 00692 if (t->nature() == kInt) { 00693 vname = getFreshID("itbl"); 00694 ctype = "int"; 00695 } else { 00696 vname = getFreshID("ftbl"); 00697 ctype = ifloat(); 00698 } 00699 00700 // declaration de la table 00701 fClass->addDeclCode(subst("static $0 \t$1[$2];", ctype, vname, T(size))); 00702 fClass->addStaticFields(subst("$0 \tmydsp::$1[$2];", ctype, vname, T(size))); 00703 00704 // initialisation du generateur de contenu 00705 fClass->addStaticInitCode(subst("$0.init(samplingFreq);", cexp)); 00706 // remplissage de la table 00707 fClass->addStaticInitCode(subst("$0.fill($1,$2);", cexp, T(size), vname)); 00708 00709 // on retourne le nom de la table 00710 return vname; 00711 }
Definition at line 631 of file compile_scal.cpp.
References Klass::addDeclCode(), Klass::addInitCode(), CS(), Compiler::fClass, getFreshID(), getSigType(), ifloat(), isSigInt(), kInt, subst(), and T().
Referenced by generateCode().
00632 { 00633 string generator(CS(content)); 00634 string ctype, vname; 00635 int size; 00636 00637 if (!isSigInt(tsize, &size)) { 00638 //fprintf(stderr, "error in ScalarCompiler::generateTable()\n"); exit(1); 00639 cerr << "error in ScalarCompiler::generateTable() : " 00640 << *tsize 00641 << " is not an integer expression " 00642 << endl; 00643 exit(1); 00644 } 00645 // definition du nom et du type de la table 00646 // A REVOIR !!!!!!!!! 00647 Type t = getSigType(content);//, tEnv); 00648 if (t->nature() == kInt) { 00649 vname = getFreshID("itbl"); 00650 ctype = "int"; 00651 } else { 00652 vname = getFreshID("ftbl"); 00653 ctype = ifloat(); 00654 } 00655 00656 // declaration de la table 00657 fClass->addDeclCode(subst("$0 \t$1[$2];", ctype, vname, T(size))); 00658 00659 // initialisation du generateur de contenu 00660 fClass->addInitCode(subst("$0.init(samplingFreq);", generator)); 00661 // remplissage de la table 00662 fClass->addInitCode(subst("$0.fill($1,$2);", generator, T(size), vname)); 00663 00664 // on retourne le nom de la table 00665 return vname; 00666 }
string ScalarCompiler::generateVariableStore | ( | Tree | sig, | |
const string & | exp | |||
) | [protected, virtual] |
Reimplemented in VectorCompiler.
Definition at line 441 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().
00442 { 00443 string vname, ctype; 00444 Type t = getSigType(sig); 00445 00446 switch (t->variability()) { 00447 00448 case kKonst : 00449 00450 getTypedNames(t, "Const", ctype, vname); 00451 fClass->addDeclCode(subst("$0 \t$1;", ctype, vname)); 00452 fClass->addInitCode(subst("$0 = $1;", vname, exp)); 00453 break; 00454 00455 case kBlock : 00456 00457 getTypedNames(t, "Slow", ctype, vname); 00458 fClass->addFirstPrivateDecl(vname); 00459 fClass->addZone2(subst("$0 \t$1 = $2;", ctype, vname, exp)); 00460 break; 00461 00462 case kSamp : 00463 00464 getTypedNames(t, "Temp", ctype, vname); 00465 fClass->addExecCode(subst("$0 $1 = $2;", ctype, vname, exp)); 00466 break; 00467 } 00468 return vname; 00469 }
string ScalarCompiler::generateVBargraph | ( | Tree | sig, | |
Tree | label, | |||
Tree | min, | |||
Tree | max, | |||
const string & | exp | |||
) | [protected] |
Definition at line 538 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().
00539 { 00540 string varname = getFreshID("fbargraph"); 00541 fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat())); 00542 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig)); 00543 00544 Type t = getSigType(sig); 00545 switch (t->variability()) { 00546 00547 case kKonst : 00548 fClass->addInitCode(subst("$0 = $1;", varname, exp)); 00549 break; 00550 00551 case kBlock : 00552 fClass->addZone2(subst("$0 = $1;", varname, exp)); 00553 break; 00554 00555 case kSamp : 00556 fClass->addExecCode(subst("$0 = $1;", varname, exp)); 00557 break; 00558 } 00559 00560 //return varname; 00561 return generateCacheCode(sig, varname); 00562 }
string ScalarCompiler::generateVSlider | ( | Tree | sig, | |
Tree | label, | |||
Tree | cur, | |||
Tree | min, | |||
Tree | max, | |||
Tree | step | |||
) | [protected] |
Definition at line 510 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().
00511 { 00512 string varname = getFreshID("fslider"); 00513 fClass->addDeclCode(subst("$1 \t$0;", varname, xfloat())); 00514 fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur)))); 00515 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig)); 00516 return generateCacheCode(sig, varname); 00517 }
Definition at line 718 of file compile_scal.cpp.
References Klass::addExecCode(), CS(), Compiler::fClass, and subst().
Referenced by generateCode().
00719 { 00720 string tblName(CS(tbl)); 00721 fClass->addExecCode(subst("$0[$1] = $2;", tblName, CS(idx), CS(data))); 00722 return tblName; 00723 }
string ScalarCompiler::generateXtended | ( | Tree | sig | ) | [protected] |
retrieve the type annotation of sig
sig | the signal we want to know the type |
Definition at line 960 of file compile_scal.cpp.
References CTree::arity(), CTree::branch(), CS(), Compiler::fClass, generateCacheCode(), xtended::generateCode(), getSigType(), getUserData(), and xtended::needCache().
Referenced by generateCode().
00961 { 00962 xtended* p = (xtended*) getUserData(sig); 00963 vector<string> args; 00964 vector<Type> types; 00965 00966 for (int i=0; i<sig->arity(); i++) { 00967 args.push_back(CS(sig->branch(i))); 00968 types.push_back(getSigType(sig->branch(i))); 00969 } 00970 00971 if (p->needCache()) { 00972 return generateCacheCode(sig, p->generateCode(fClass, args, types)); 00973 } else { 00974 return p->generateCode(fClass, args, types); 00975 } 00976 }
bool ScalarCompiler::getCompiledExpression | ( | Tree | sig, | |
string & | cexp | |||
) | [protected] |
Test if a signal is already compiled.
sig | the signal expression to compile. | |
name | the string representing the compiled expression. |
Definition at line 179 of file compile_scal.cpp.
References fCompileProperty.
Referenced by VectorCompiler::CS(), CS(), generateCacheCode(), generateRDTbl(), and generateStaticTable().
00180 { 00181 return fCompileProperty.get(sig, cexp); 00182 }
string ScalarCompiler::getFreshID | ( | const string & | prefix | ) | [protected] |
Definition at line 80 of file compile_scal.cpp.
References fIDCounters, subst(), and T().
Referenced by generateButton(), generateCheckbox(), generateHBargraph(), generateHSlider(), generateIota(), generateNumEntry(), generatePrefix(), generateSigGen(), generateStaticSigGen(), generateStaticTable(), generateTable(), generateVBargraph(), generateVSlider(), and getTypedNames().
00081 { 00082 if (fIDCounters.find(prefix) == fIDCounters.end()) { 00083 fIDCounters[prefix]=0; 00084 } 00085 int n = fIDCounters[prefix]; 00086 fIDCounters[prefix] = n+1; 00087 return subst("$0$1", prefix, T(n)); 00088 }
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 }
void ScalarCompiler::getTypedNames | ( | Type | t, | |
const string & | prefix, | |||
string & | ctype, | |||
string & | vname | |||
) | [protected] |
Definition at line 394 of file compile_scal.cpp.
References getFreshID(), ifloat(), kInt, and subst().
Referenced by VectorCompiler::generateCacheCode(), generateCacheCode(), generateFConst(), generateNumber(), generateRec(), VectorCompiler::generateVariableStore(), and generateVariableStore().
00395 { 00396 if (t->nature() == kInt) { 00397 ctype = "int"; vname = subst("i$0", getFreshID(prefix)); 00398 } else { 00399 ctype = ifloat(); vname = subst("f$0", getFreshID(prefix)); 00400 } 00401 }
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.
sig | the signal expression. | |
vecname | the string where to store the vector name. |
Definition at line 1008 of file compile_scal.cpp.
References fVectorProperty.
Referenced by VectorCompiler::generateFixDelay(), generateFixDelay(), and generateRecProj().
01009 { 01010 return fVectorProperty.get(sig, vecname); 01011 }
int ScalarCompiler::pow2limit | ( | int | x | ) | [protected] |
Compute the minimal power of 2 greater than x.
Definition at line 1018 of file compile_scal.cpp.
Referenced by VectorCompiler::dlineLoop(), SchedulerCompiler::dlineLoop(), generateDelayLine(), generateDelayVecNoTemp(), VectorCompiler::generateFixDelay(), and generateFixDelay().
Implements Compiler.
Definition at line 95 of file compile_scal.cpp.
References deBruijn2Sym(), endTiming(), fOccMarkup, OccMarkup::mark(), privatise(), recursivnessAnnotation(), sharingAnalysis(), simplify(), startTiming(), and typeAnnotation().
Referenced by VectorCompiler::compileMultiSignal(), SchedulerCompiler::compileMultiSignal(), and compileMultiSignal().
00096 { 00097 startTiming("ScalarCompiler::prepare"); 00098 startTiming("deBruijn2Sym"); 00099 Tree L1 = deBruijn2Sym(LS); // convert debruijn recursion into symbolic recursion 00100 endTiming("deBruijn2Sym"); 00101 Tree L2 = simplify(L1); // simplify by executing every computable operation 00102 Tree L3 = privatise(L2); // Un-share tables with multiple writers 00103 00104 recursivnessAnnotation(L3); // Annotate L3 with recursivness information 00105 typeAnnotation(L3); // Annotate L3 with type information 00106 sharingAnalysis(L3); // annotate L3 with sharing count 00107 fOccMarkup.mark(L3); // annotate L3 with occurences analysis 00108 endTiming("ScalarCompiler::prepare"); 00109 return L3; 00110 }
Implements Compiler.
Definition at line 112 of file compile_scal.cpp.
References endTiming(), fOccMarkup, OccMarkup::mark(), recursivnessAnnotation(), sharingAnalysis(), startTiming(), and typeAnnotation().
Referenced by compileSingleSignal().
00113 { 00114 startTiming("ScalarCompiler::prepare2"); 00115 recursivnessAnnotation(L0); // Annotate L0 with recursivness information 00116 typeAnnotation(L0); // Annotate L0 with type information 00117 sharingAnalysis(L0); // annotate L0 with sharing count 00118 fOccMarkup.mark(L0); // annotate L0 with occurences analysis 00119 endTiming("ScalarCompiler::prepare2"); 00120 00121 return L0; 00122 }
string ScalarCompiler::setCompiledExpression | ( | Tree | sig, | |
const string & | cexp | |||
) | [protected] |
Set the string of a compiled expression is already compiled.
sig | the signal expression to compile. | |
cexp | the string representing the compiled expression. |
Definition at line 190 of file compile_scal.cpp.
References fCompileProperty.
Referenced by VectorCompiler::CS(), CS(), generateRDTbl(), and generateStaticTable().
00191 { 00192 fCompileProperty.set(sig, cexp); 00193 return cexp; 00194 }
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 }
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.
sig | the signal expression. | |
vecname | the string representing the vector name. |
Definition at line 994 of file compile_scal.cpp.
References fVectorProperty.
Referenced by VectorCompiler::generateCacheCode(), VectorCompiler::generateDelayVec(), generateDelayVecNoTemp(), and generateRec().
00995 { 00996 fVectorProperty.set(sig, vecname); 00997 }
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 }
void ScalarCompiler::sharingAnnotation | ( | int | vctxt, | |
Tree | t | |||
) | [protected] |
Definition at line 106 of file sharing.cpp.
References getSharingCount(), getSigType(), getSubSignals(), isSigGen(), isSigSelect3(), and setSharingCount().
Referenced by sharingAnalysis().
00107 { 00108 Tree c, x, y, z; 00109 00110 //cerr << "START sharing annotation of " << *sig << endl; 00111 int count = getSharingCount(sig); 00112 00113 if (count > 0) { 00114 // it is not our first visit 00115 setSharingCount(sig, count+1); 00116 00117 } else { 00118 // it is our first visit, 00119 int v = getSigType(sig)->variability(); 00120 00121 // check "time sharing" cases 00122 if (v < vctxt) { 00123 setSharingCount(sig, 2); // time sharing occurence : slower expression in faster context 00124 } else { 00125 setSharingCount(sig, 1); // regular occurence 00126 } 00127 00128 if (isSigSelect3(sig,c,y,x,z)) { 00129 // make a special case for select3 implemented with real if 00130 // because the c expression will be used twice in the C++ 00131 // translation 00132 sharingAnnotation(v, c); 00133 sharingAnnotation(v, c); 00134 sharingAnnotation(v, x); 00135 sharingAnnotation(v, y); 00136 sharingAnnotation(v, z); 00137 } else { 00138 // Annotate the sub signals 00139 vector<Tree> subsig; 00140 int n = getSubSignals(sig, subsig); 00141 if (n>0 && ! isSigGen(sig)) { 00142 for (int i=0; i<n; i++) sharingAnnotation(v, subsig[i]); 00143 } 00144 } 00145 } 00146 //cerr << "END sharing annotation of " << *sig << endl; 00147 }
property<string> ScalarCompiler::fCompileProperty [protected] |
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().
OccMarkup ScalarCompiler::fOccMarkup [protected] |
Definition at line 47 of file compile_scal.hh.
Referenced by VectorCompiler::generateCacheCode(), generateCacheCode(), generateFConst(), VectorCompiler::generateFixDelay(), generateFixDelay(), generateNumber(), generateRec(), VectorCompiler::needSeparateLoop(), prepare(), and prepare2().
Tree ScalarCompiler::fSharingKey [protected] |
Definition at line 46 of file compile_scal.hh.
Referenced by getSharingCount(), setSharingCount(), and sharingAnalysis().
property<string> ScalarCompiler::fVectorProperty [protected] |
Definition at line 43 of file compile_scal.hh.
Referenced by getVectorNameProperty(), and setVectorNameProperty().