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 /***************************************************************************** 00025 ****************************************************************************** 00026 FAUST SIGNAL COMPILER 00027 Y. Orlarey, (c) Grame 2002 00028 ------------------------------------------------------------------------------ 00029 Compile a list of FAUST signals into a C++ class . 00030 00031 History : 00032 --------- 00033 2002-02-08 : First version 00034 00035 ****************************************************************************** 00036 *****************************************************************************/ 00037 00038 00039 00040 #include <stdio.h> 00041 00042 #include "compile_vect.hh" 00043 #include "compile_scal.hh" 00044 #include "sigtype.hh" 00045 #include "sigtyperules.hh" 00046 #include "sigprint.hh" 00047 00048 00049 00050 /***************************************************************************** 00051 ****************************************************************************** 00052 00053 SHARING ANALYSIS 00054 00055 ****************************************************************************** 00056 *****************************************************************************/ 00057 00058 //------------------------------------------------------------------------------ 00059 // Create a specific property key for the sharing count of subtrees of t 00060 //------------------------------------------------------------------------------ 00061 00062 int ScalarCompiler::getSharingCount(Tree sig) 00063 { 00064 //cerr << "getSharingCount of : " << *sig << " = "; 00065 Tree c; 00066 if (getProperty(sig, fSharingKey, c)) { 00067 //cerr << c->node().getInt() << endl; 00068 return c->node().getInt(); 00069 } else { 00070 //cerr << 0 << endl; 00071 return 0; 00072 } 00073 } 00074 00075 void ScalarCompiler::setSharingCount(Tree sig, int count) 00076 { 00077 //cerr << "setSharingCount of : " << *sig << " <- " << count << endl; 00078 setProperty(sig, fSharingKey, tree(count)); 00079 } 00080 00081 00082 00083 //------------------------------------------------------------------------------ 00084 // Create a specific property key for the sharing count of subtrees of t 00085 //------------------------------------------------------------------------------ 00086 00087 00088 void ScalarCompiler::sharingAnalysis(Tree t) 00089 { 00090 fSharingKey = shprkey(t); 00091 if (isList(t)) { 00092 while (isList(t)) { 00093 sharingAnnotation(kSamp, hd(t)); 00094 t = tl(t); 00095 } 00096 } else { 00097 sharingAnnotation(kSamp, t); 00098 } 00099 } 00100 00101 00102 00103 //------------------------------------------------------------------------------ 00104 // Create a specific property key for the sharing count of subtrees of t 00105 //------------------------------------------------------------------------------ 00106 void ScalarCompiler::sharingAnnotation(int vctxt, Tree sig) 00107 { 00108 //cerr << "START sharing annotation of " << *sig << endl; 00109 int count = getSharingCount(sig); 00110 00111 if (count > 0) { 00112 // it is not our first visit 00113 setSharingCount(sig, count+1); 00114 00115 } else { 00116 // it is our first visit, 00117 int v = getSigType(sig)->variability(); 00118 00119 // check "time sharing" cases 00120 if (v < vctxt) { 00121 setSharingCount(sig, 2); // time sharing occurence : slower expression in faster context 00122 } else { 00123 setSharingCount(sig, 1); // regular occurence 00124 } 00125 00126 // Annotate the sub signals 00127 vector<Tree> subsig; 00128 int n = getSubSignals(sig, subsig); 00129 if (n>0 && ! isSigGen(sig)) { 00130 for (int i=0; i<n; i++) sharingAnnotation(v, subsig[i]); 00131 } 00132 } 00133 //cerr << "END sharing annotation of " << *sig << endl; 00134 }