File: loopDetector.cpp

package info (click to toggle)
faust 0.9.95~repack1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 164,732 kB
  • ctags: 18,777
  • sloc: cpp: 90,427; sh: 6,116; java: 4,501; objc: 4,428; ansic: 3,301; makefile: 1,298; ruby: 950; yacc: 511; xml: 398; lex: 218; python: 136
file content (28 lines) | stat: -rw-r--r-- 806 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "loopDetector.hh"
#include "ppbox.hh"

bool loopDetector::detect(Tree t)
{
    fPhase++;
    int w = fPhase%fBuffersize;
    fBuffer[w] = t;
    if ((fPhase%fCheckperiod) == 0) {
        // time to check for a cycle
        for (int i=1; i<fBuffersize; i++) {
            int r = w-i; if (r < 0) { r += fBuffersize; }
            assert(r>=0);
            assert(r<fBuffersize);
            assert(r != w);
            if (fBuffer[r] == t) {
                cerr 	<< "ERROR : after "
                        << fPhase
                        << " evaluation steps, the compiler has detected an endless evaluation cycle of "
                        << i
                        << " steps"
                        << endl;
                exit(1);
            }
        }
    }
    return false;
}