Merge branch 'OOP' of https://scm.cri.ensmp.fr/git/Faustine into OOP
[Faustine.git] / interpretor / faust-0.9.47mr3 / compiler / evaluate / loopDetector.cpp
1 #include "loopDetector.hh"
2 #include "ppbox.hh"
3
4 bool loopDetector::detect(Tree t)
5 {
6 fPhase++;
7 int w = fPhase%fBuffersize;
8 fBuffer[w] = t;
9 if ((fPhase%fCheckperiod) == 0) {
10 // time to check for a cycle
11 for (int i=1; i<fBuffersize; i++) {
12 int r = w-i; if (r < 0) { r += fBuffersize; }
13 assert(r>=0);
14 assert(r<fBuffersize);
15 assert(r != w);
16 if (fBuffer[r] == t) {
17 cerr << "ERROR : after "
18 << fPhase
19 << " evaluation steps, the compiler has detected an endless evaluation cycle of "
20 << i
21 << " steps"
22 << endl;
23 exit(1);
24 }
25 }
26 }
27 return false;
28 }