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 #ifndef _COMPILE_SCAL_
25 #define _COMPILE_SCAL_
29 #include "sigtyperules.hh"
30 #include "sigraterules.hh"
31 #include "occurences.hh"
32 #include "property.hh"
34 ////////////////////////////////////////////////////////////////////////
36 * Compile a list of FAUST signals into a scalar C++ class
38 ///////////////////////////////////////////////////////////////////////
40 class ScalarCompiler : public Compiler
43 property<string> fCompileProperty;
44 property<string> fVectorProperty;
45 property<pair<string,string> > fStaticInitProperty; // property added to solve 20101208 kjetil bug
46 property<pair<string,string> > fInstanceInitProperty; // property added to solve 20101208 kjetil bug
48 static map<string, int> fIDCounters;
57 ScalarCompiler ( const string& name, const string& super, int numInputs, int numOutputs) :
58 Compiler(name,super,numInputs,numOutputs,false),
63 ScalarCompiler ( Klass* k) :
68 virtual void compileMultiSignal (Tree lsig);
69 virtual void compileSingleSignal (Tree lsig);
74 virtual string CS (Tree sig);
75 virtual string generateCode (Tree sig);
76 virtual string generateCacheCode(Tree sig, const string& exp) ;
78 virtual string generateVariableStore(Tree sig, const string& exp);
80 string getFreshID (const string& prefix);
82 void compilePreparedSignalList (Tree lsig);
83 Tree prepare(Tree L0);
84 Tree prepare2 (Tree L0);
87 bool getCompiledExpression(Tree sig, string& name);
88 string setCompiledExpression(Tree sig, const string& name);
90 void setVectorNameProperty(Tree sig, const string& vecname);
91 bool getVectorNameProperty(Tree sig, string& vecname);
93 int getSharingCount(Tree t);
94 void setSharingCount(Tree t, int count);
95 void sharingAnalysis(Tree t);
96 void sharingAnnotation(int vctxt, Tree t);
101 string generateXtended (Tree sig);
102 virtual string generateFixDelay (Tree sig, Tree arg, Tree size);
103 string generatePrefix (Tree sig, Tree x, Tree e);
104 string generateIota (Tree sig, Tree arg);
105 string generateBinOp (Tree sig, int opcode, Tree arg1, Tree arg2);
107 string generateFFun (Tree sig, Tree ff, Tree largs);
109 string generateInput (Tree sig, const string& idx);
110 string generateOutput (Tree sig, const string& idx, const string& arg1);
112 string generateTable (Tree sig, Tree tsize, Tree content);
113 string generateStaticTable (Tree sig, Tree tsize, Tree content);
114 string generateWRTbl (Tree sig, Tree tbl, Tree idx, Tree data);
115 string generateRDTbl (Tree sig, Tree tbl, Tree idx);
116 string generateSigGen (Tree sig, Tree content);
117 string generateStaticSigGen(Tree sig, Tree content);
119 string generateSelect2 (Tree sig, Tree sel, Tree s1, Tree s2);
120 string generateSelect3 (Tree sig, Tree sel, Tree s1, Tree s2, Tree s3);
122 string generateRecProj (Tree sig, Tree exp, int i);
123 void generateRec (Tree sig, Tree var, Tree le);
125 string generateIntCast (Tree sig, Tree x);
126 string generateFloatCast (Tree sig, Tree x);
128 string generateButton (Tree sig, Tree label);
129 string generateCheckbox (Tree sig, Tree label);
130 string generateVSlider (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
131 string generateHSlider (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
132 string generateNumEntry (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
134 string generateVBargraph (Tree sig, Tree label, Tree min, Tree max, const string& exp);
135 string generateHBargraph (Tree sig, Tree label, Tree min, Tree max, const string& exp);
137 string generateNumber(Tree sig, const string& exp);
138 string generateFConst (Tree sig, const string& file, const string& name);
139 string generateFVar (Tree sig, const string& file, const string& name);
141 virtual string generateDelayVec(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd);
142 string generateDelayVecNoTemp(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd);
143 //string generateDelayVecWithTemp(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd);
144 virtual void generateDelayLine(const string& ctype, const string& vname, int mxd, const string& exp);
146 // up et down sampling
147 virtual string generateUpSample (Tree sig, Tree arg, Tree size);
148 virtual string generateDownSample (Tree sig, Tree arg, Tree size);
152 void getTypedNames(Type t, const string& prefix, string& ctype, string& vname);
153 void ensureIotaCode();
154 int pow2limit(int x);