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