00001 /************************************************************************ 00002 ************************************************************************ 00003 FAUST compiler 00004 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale 00005 --------------------------------------------------------------------- 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 ************************************************************************ 00020 ************************************************************************/ 00021 00022 00023 00024 #ifndef _LOOP_H 00025 #define _LOOP_H 00026 00027 /********************************************************************** 00028 - loop.hh : loop C++ à remplir (projet FAUST) - 00029 00030 00031 Historique : 00032 ----------- 00033 21-01-2008 : implementation initiale (yo) 00034 00035 ***********************************************************************/ 00036 namespace std{} 00037 using namespace std; 00038 00039 #include <string> 00040 #include <list> 00041 #include <stack> 00042 #include <set> 00043 #include <map> 00044 #include "tlib.hh" 00045 00046 #define kMaxCategory 32 00047 00048 /* 00049 * Loops are lines of code that correspond to a recursive expression or a vector expression. 00050 */ 00051 00052 struct Loop 00053 { 00054 const bool fIsRecursive; 00055 const Tree fRecSymbol; 00056 Loop* const fEnclosingLoop; 00057 const string fSize; 00058 // fields concerned by absorbsion 00059 set<Tree> fRecDependencies; 00060 set<Loop*> fBackwardLoopDependencies; 00061 set<Loop*> fForwardLoopDependencies; 00062 list<string> fPreCode; 00063 list<string> fExecCode; 00064 list<string> fPostCode; 00065 // for topological sort 00066 int fOrder; 00067 int fIndex; 00068 // new fields 00069 int fUseCount; 00070 list<Loop*> fExtraLoops; 00071 00072 public: 00073 Loop(Tree recsymbol, Loop* encl, const string& size); 00074 Loop(Loop* encl, const string& size); 00075 00076 bool isEmpty(); 00077 bool hasRecDependencies(); 00078 void addRecDependency(Tree t); 00079 bool findRecDefinition(Tree t); 00080 00081 void addPreCode (const string& str); 00082 void addExecCode (const string& str); 00083 void addPostCode (const string& str); 00084 void println (int n, ostream& fout); 00085 void printoneln (int n, ostream& fout); 00086 00087 void absorb(Loop* l); 00088 // new method 00089 void concat(Loop* l); 00090 }; 00091 00092 #endif