string DocCompiler::generateCacheCode(Tree sig, const string& exp) { // cerr << "!! entering generateCacheCode with sig=\"" << ppsig(sig) << "\"" << endl; string vname, ctype, code, vectorname; int sharing = getSharingCount(sig); Occurences* o = fOccMarkup.retrieve(sig); // check reentrance if(getCompiledExpression(sig, code)) { // cerr << "!! generateCacheCode called a true getCompiledExpression" << endl; return code; } // check for expression occuring in delays if(o->getMaxDelay() > 0) { if(getVectorNameProperty(sig, vectorname)) { return exp; } getTypedNames(getCertifiedSigType(sig), "r", ctype, vname); gDocNoticeFlagMap["recursigs"] = true; // cerr << "- r : generateCacheCode : vame=\"" << vname << "\", for sig=\"" << ppsig(sig) << "\"" << endl; if(sharing > 1) { // cerr << " generateCacheCode calls generateDelayVec(generateVariableStore) on vame=\"" << vname << "\"" << endl; return generateDelayVec(sig, generateVariableStore(sig, exp), ctype, vname, o->getMaxDelay()); } else { // cerr << " generateCacheCode calls generateDelayVec(exp) on vame=\"" << vname << "\"" << endl; return generateDelayVec(sig, exp, ctype, vname, o->getMaxDelay()); } } else if(sharing == 1 || getVectorNameProperty(sig, vectorname) || isVerySimpleFormula(sig)) { // cerr << "! generateCacheCode : sharing == 1 : return \"" << exp << "\"" << endl; return exp; } else if(sharing > 1) { // cerr << "! generateCacheCode : sharing > 1 : return \"" << exp << "\"" << endl; return generateVariableStore(sig, exp); } else { cerr << "Error in sharing count (" << sharing << ") for " << *sig << endl; exit(1); } return "Error in generateCacheCode"; }
/** * Compile a signal * @param sig the signal expression to compile. * @return the C code translation of sig as a string */ string DocCompiler::CS (Tree sig, int priority) { string code; if (!getCompiledExpression(sig, code)) { // not compiled yet. code = generateCode(sig, priority); setCompiledExpression(sig, code); } return code; }
string VectorCompiler::generateCodeNonRec (Tree sig) { string code; if (getCompiledExpression(sig, code)) { // already visited return code; } else { //cerr << "VectorCompiler::generateCodeNonRec( " << ppsig(sig) << " )" << endl; code = generateLoopCode(sig); setCompiledExpression(sig, code); return code; } }
/** * Compile a signal * @param sig the signal expression to compile. * @return the C code translation of sig as a string */ string VectorCompiler::CS (Tree sig) { string code; //cerr << "ENTER VectorCompiler::CS : "<< ppsig(sig) << endl; if (!getCompiledExpression(sig, code)) { code = generateCode(sig); //cerr << "CS : " << code << " for " << ppsig(sig) << endl; setCompiledExpression(sig, code); } else { // we require an already compiled expression // therefore we must update the dependencies of // the current loop int i; Tree x, d, r; Loop* ls; Loop* tl = fClass->topLoop(); if (fClass->getLoopProperty(sig,ls)) { // sig has a loop property //cerr << "CASE SH : fBackwardLoopDependencies.insert : " << tl << " --depend(A)son--> " << ls << endl; tl->fBackwardLoopDependencies.insert(ls); } else if (isSigFixDelay(sig, x, d) && fClass->getLoopProperty(x,ls)) { //cerr << "CASE DL : fBackwardLoopDependencies.insert : " << tl << " --depend(B)son--> " << ls << endl; tl->fBackwardLoopDependencies.insert(ls); } else if (isSigFixDelay(sig, x, d) && isProj(x, &i, r) && fClass->getLoopProperty(r,ls)) { //cerr << "CASE DR : fBackwardLoopDependencies.insert : " << tl << " --depend(B)son--> " << ls << endl; tl->fBackwardLoopDependencies.insert(ls); } else if (isProj(sig, &i, r) && fClass->getLoopProperty(r,ls)) { //cerr << "CASE R* : fBackwardLoopDependencies.insert : " << tl << " --depend(B)son--> " << ls << endl; tl->fBackwardLoopDependencies.insert(ls); } else { if (isProj(sig, &i, r)) { //cerr << "SYMBOL RECURSIF EN COURS ??? " << *r << endl; } else if (getCertifiedSigType(sig)->variability()<kSamp) { //cerr << "SLOW EXPRESSION " << endl; } else { //cerr << "Expression absorbée" << *sig << endl; } } } //cerr << "EXIT VectorCompiler::CS : "<< ppsig(sig) << "---code---> " << code << endl; return code; }
void VectorCompiler::generateCodeRecursions (Tree sig) { Tree id, body; string code; //cerr << "VectorCompiler::generateCodeRecursions( " << ppsig(sig) << " )" << endl; if (getCompiledExpression(sig, code)) { //cerr << "** ALREADY VISITED : " << code << " ===> " << ppsig(sig) << endl; return; } else if( isRec(sig, id, body) ) { //cerr << "we have a recursive expression non compiled yet : " << ppsig(sig) << endl; setCompiledExpression(sig, "[RecursionVisited]"); fClass->openLoop(sig, "count"); generateRec(sig, id, body); fClass->closeLoop(sig); } else { // we go down the expression vector<Tree> subsigs; int n = getSubSignals(sig, subsigs, false); for (int i=0; i<n; i++) { generateCodeRecursions(subsigs[i]); } } }