#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.
00049 : 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().
00017 { 00018 //cerr << "detect " << t << endl; 00019 fPhase++; 00020 fBuffer[fPhase%fBuffersize] = t; 00021 if ((fPhase%fCheckperiod) == 0) { 00022 // list possible cycles 00023 vector<int> vc; 00024 listPossibleCycles(vc); 00025 00026 // check each possible cycle 00027 //for (int i = vc.size(); i > 0;) { 00028 for (unsigned int i = 0; i < vc.size(); i++) { 00029 //i--; 00030 if (isCycle(vc[i])) { 00031 cerr << "ERROR : the Faust compiler has detected an endless cycle of " 00032 << vc[i] 00033 << " evaluations. Last evaluated expression : " 00034 << fPhase << endl; 00035 exit(1); 00036 return true; 00037 } 00038 } 00039 } 00040 return false; 00041 }
Tree loopDetector::get | ( | int | n | ) | [inline, private] |
Definition at line 52 of file loopDetector.hh.
References fBuffer, fBuffersize, and fPhase.
00052 { return fBuffer[(fPhase-n)%fBuffersize]; }
bool loopDetector::isCycle | ( | int | period | ) | [private] |
Definition at line 44 of file loopDetector.cpp.
References fBuffersize.
Referenced by detect().
00045 { 00046 //cerr << "check cycle " << period << endl; 00047 int n = fBuffersize/period; // number of periods 00048 for (int i=0; i<period; i++) { 00049 Tree x = get(i); 00050 for (int p=1; p<n; p++) { 00051 if (x != get(i+p*period)) return false; 00052 } 00053 } 00054 return true; 00055 }
void loopDetector::listPossibleCycles | ( | vector< int > & | v | ) | [private] |
Definition at line 4 of file loopDetector.cpp.
References fBuffersize.
Referenced by detect().
00005 { 00006 //cerr << "list possible cycles" << endl; 00007 Tree t = get(0); 00008 for (int i=1; i<=(fBuffersize/2); i++) { 00009 if (t == get(i)) { 00010 //cout << "possible cycle at " << i << endl; 00011 v.push_back(i); 00012 } 00013 } 00014 }
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.