FAUST compiler  0.9.9.6b8
loopDetector.cpp
Go to the documentation of this file.
00001 #include "loopDetector.hh"
00002 #include "ppbox.hh"
00003 
00004 bool loopDetector::detect(Tree t)
00005 {
00006     fPhase++;
00007     int w = fPhase%fBuffersize;
00008     fBuffer[w] = t;
00009     if ((fPhase%fCheckperiod) == 0) {
00010         // time to check for a cycle
00011         for (int i=1; i<fBuffersize; i++) {
00012             int r = w-i; if (r < 0) { r += fBuffersize; }
00013             assert(r>=0);
00014             assert(r<fBuffersize);
00015             assert(r != w);
00016             if (fBuffer[r] == t) {
00017                 cerr    << "ERROR : after "
00018                         << fPhase
00019                         << " evaluation steps, the compiler has detected an endless evaluation cycle of "
00020                         << i
00021                         << " steps"
00022                         << endl;
00023                 exit(1);
00024             }
00025         }
00026     }
00027     return false;
00028 }