00001 00002 /************************************************************************ 00003 ************************************************************************ 00004 FAUST compiler 00005 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale 00006 --------------------------------------------------------------------- 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 ************************************************************************ 00021 ************************************************************************/ 00022 00023 #ifndef __LOOPDETECTOR__ 00024 #define __LOOPDETECTOR__ 00025 00026 00027 00038 #include "boxes.hh" 00039 #include "sourcereader.hh" 00040 00041 class loopDetector 00042 { 00043 const int fBuffersize; 00044 const int fCheckperiod; 00045 vector<Tree> fBuffer; 00046 int fPhase; 00047 00048 public: 00049 loopDetector(int buffersize, int checkperiod) : fBuffersize(buffersize), fCheckperiod(checkperiod), fBuffer(buffersize), fPhase(fBuffersize) {} 00050 bool detect (Tree t); 00051 private: 00052 Tree get (int n) { return fBuffer[(fPhase-n)%fBuffersize]; } 00053 void listPossibleCycles (vector<int>& v); 00054 bool isCycle (int period); 00055 00056 }; 00057 00058 00059 #endif 00060