|
FAUST compiler
0.9.9.6b8
|
#include <loopDetector.hh>
Public Member Functions | |
| loopDetector (int buffersize, int checkperiod) | |
| bool | detect (Tree t) |
Private Member Functions | |
| Tree | get (int n) |
| void | listPossibleCycles (vector< int > &v) |
| bool | isCycle (int period) |
Private Attributes | |
| const int | fBuffersize |
| const int | fCheckperiod |
| vector< Tree > | fBuffer |
| int | fPhase |
Definition at line 41 of file loopDetector.hh.
| loopDetector::loopDetector | ( | int | buffersize, |
| int | checkperiod | ||
| ) | [inline] |
Definition at line 49 of file loopDetector.hh.
: fBuffersize(buffersize), fCheckperiod(checkperiod), fBuffer(buffersize), fPhase(fBuffersize) {}
| bool loopDetector::detect | ( | Tree | t | ) |
Definition at line 16 of file loopDetector.cpp.
References fBuffer, fBuffersize, fCheckperiod, fPhase, isCycle(), and listPossibleCycles().
Referenced by eval().
{
//cerr << "detect " << t << endl;
fPhase++;
fBuffer[fPhase%fBuffersize] = t;
if ((fPhase%fCheckperiod) == 0) {
// list possible cycles
vector<int> vc;
listPossibleCycles(vc);
// check each possible cycle
//for (int i = vc.size(); i > 0;) {
for (unsigned int i = 0; i < vc.size(); i++) {
//i--;
if (isCycle(vc[i])) {
cerr << "ERROR : the Faust compiler has detected an endless cycle of "
<< vc[i]
<< " evaluations. Last evaluated expression : "
<< fPhase << endl;
exit(1);
return true;
}
}
}
return false;
}


| Tree loopDetector::get | ( | int | n | ) | [inline, private] |
Definition at line 52 of file loopDetector.hh.
References fBuffer, fBuffersize, and fPhase.
{ return fBuffer[(fPhase-n)%fBuffersize]; }
| bool loopDetector::isCycle | ( | int | period | ) | [private] |
Definition at line 44 of file loopDetector.cpp.
References fBuffersize.
Referenced by detect().
{
//cerr << "check cycle " << period << endl;
int n = fBuffersize/period; // number of periods
for (int i=0; i<period; i++) {
Tree x = get(i);
for (int p=1; p<n; p++) {
if (x != get(i+p*period)) return false;
}
}
return true;
}

| void loopDetector::listPossibleCycles | ( | vector< int > & | v | ) | [private] |
Definition at line 4 of file loopDetector.cpp.
References fBuffersize.
Referenced by detect().
{
//cerr << "list possible cycles" << endl;
Tree t = get(0);
for (int i=1; i<=(fBuffersize/2); i++) {
if (t == get(i)) {
//cout << "possible cycle at " << i << endl;
v.push_back(i);
}
}
}

vector<Tree> loopDetector::fBuffer [private] |
Definition at line 45 of file loopDetector.hh.
const int loopDetector::fBuffersize [private] |
Definition at line 43 of file loopDetector.hh.
Referenced by detect(), get(), isCycle(), and listPossibleCycles().
const int loopDetector::fCheckperiod [private] |
Definition at line 44 of file loopDetector.hh.
Referenced by detect().
int loopDetector::fPhase [private] |
Definition at line 46 of file loopDetector.hh.
1.7.5.1