FAUST compiler  0.9.9.6b8
Public Member Functions | Private Member Functions | Private Attributes
loopDetector Class Reference

#include <loopDetector.hh>

List of all members.

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< TreefBuffer
int fPhase

Detailed Description

Definition at line 41 of file loopDetector.hh.


Constructor & Destructor Documentation

loopDetector::loopDetector ( int  buffersize,
int  checkperiod 
) [inline]

Definition at line 49 of file loopDetector.hh.

: fBuffersize(buffersize), fCheckperiod(checkperiod), fBuffer(buffersize), fPhase(fBuffersize) {}

Member Function Documentation

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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the caller graph for this function:

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); 
        }
    }
}

Here is the caller graph for this function:


Member Data Documentation

vector<Tree> loopDetector::fBuffer [private]

Definition at line 45 of file loopDetector.hh.

Referenced by detect(), and get().

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.

Referenced by detect(), and get().


The documentation for this class was generated from the following files: