1 /************************************************************************
2 ************************************************************************
4 Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 ************************************************************************
20 ************************************************************************/
24 /*****************************************************************************
25 ******************************************************************************
27 Y. Orlarey, (c) Grame 2002
28 ------------------------------------------------------------------------------
29 Compile a list of FAUST signals into a C++ class .
33 2002-02-08 : First version
35 ******************************************************************************
36 *****************************************************************************/
42 #include "compile_vect.hh"
43 #include "compile_scal.hh"
45 #include "sigtyperules.hh"
46 #include "sigprint.hh"
50 /*****************************************************************************
51 ******************************************************************************
55 ******************************************************************************
56 *****************************************************************************/
58 //------------------------------------------------------------------------------
59 // Create a specific property key for the sharing count of subtrees of t
60 //------------------------------------------------------------------------------
62 int ScalarCompiler::getSharingCount(Tree sig
)
64 //cerr << "getSharingCount of : " << *sig << " = ";
66 if (getProperty(sig
, fSharingKey
, c
)) {
67 //cerr << c->node().getInt() << endl;
68 return c
->node().getInt();
75 void ScalarCompiler::setSharingCount(Tree sig
, int count
)
77 //cerr << "setSharingCount of : " << *sig << " <- " << count << endl;
78 setProperty(sig
, fSharingKey
, tree(count
));
83 //------------------------------------------------------------------------------
84 // Create a specific property key for the sharing count of subtrees of t
85 //------------------------------------------------------------------------------
88 void ScalarCompiler::sharingAnalysis(Tree t
)
90 fSharingKey
= shprkey(t
);
93 sharingAnnotation(kSamp
, hd(t
));
97 sharingAnnotation(kSamp
, t
);
103 //------------------------------------------------------------------------------
104 // Create a specific property key for the sharing count of subtrees of t
105 //------------------------------------------------------------------------------
106 void ScalarCompiler::sharingAnnotation(int vctxt
, Tree sig
)
110 //cerr << "START sharing annotation of " << *sig << endl;
111 int count
= getSharingCount(sig
);
114 // it is not our first visit
115 setSharingCount(sig
, count
+1);
118 // it is our first visit,
119 int v
= getCertifiedSigType(sig
)->variability();
121 // check "time sharing" cases
123 setSharingCount(sig
, 2); // time sharing occurence : slower expression in faster context
125 setSharingCount(sig
, 1); // regular occurence
128 if (isSigSelect3(sig
,c
,y
,x
,z
)) {
129 // make a special case for select3 implemented with real if
130 // because the c expression will be used twice in the C++
132 sharingAnnotation(v
, c
);
133 sharingAnnotation(v
, c
);
134 sharingAnnotation(v
, x
);
135 sharingAnnotation(v
, y
);
136 sharingAnnotation(v
, z
);
138 // Annotate the sub signals
140 int n
= getSubSignals(sig
, subsig
);
141 if (n
>0 && ! isSigGen(sig
)) {
142 for (int i
=0; i
<n
; i
++) sharingAnnotation(v
, subsig
[i
]);
146 //cerr << "END sharing annotation of " << *sig << endl;