FAUST compiler  0.9.9.6b8
compile_scal.hh
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
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.
10 
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.
15 
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  ************************************************************************/
21 
22 
23 
24 #ifndef _COMPILE_SCAL_
25 #define _COMPILE_SCAL_
26 
27 #include <utility>
28 #include "compile.hh"
29 #include "sigtyperules.hh"
30 #include "sigtyperules.hh"
31 #include "occurences.hh"
32 #include "property.hh"
33 
35 
38 
40 class ScalarCompiler : public Compiler
41 {
42  protected:
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
47 
48  static map<string, int> fIDCounters;
51  bool fHasIota;
52 
53 
54  public:
55 
56  ScalarCompiler ( const string& name, const string& super, int numInputs, int numOutputs) :
57  Compiler(name,super,numInputs,numOutputs,false),
58  fHasIota(false)
59  {}
60 
62  Compiler(k),
63  fHasIota(false)
64  {}
65 
66  virtual void compileMultiSignal (Tree lsig);
67  virtual void compileSingleSignal (Tree lsig);
68 
69 
70  protected:
71 
72  virtual string CS (Tree sig);
73  virtual string generateCode (Tree sig);
74  virtual string generateCacheCode(Tree sig, const string& exp) ;
75  virtual string forceCacheCode(Tree sig, const string& exp) ;
76 
77  virtual string generateVariableStore(Tree sig, const string& exp);
78 
79  string getFreshID (const string& prefix);
80 
81  void compilePreparedSignalList (Tree lsig);
82  Tree prepare(Tree L0);
83  Tree prepare2 (Tree L0);
84 
85 
86  bool getCompiledExpression(Tree sig, string& name);
87  string setCompiledExpression(Tree sig, const string& name);
88 
89  void setVectorNameProperty(Tree sig, const string& vecname);
90  bool getVectorNameProperty(Tree sig, string& vecname);
91 
92  int getSharingCount(Tree t);
93  void setSharingCount(Tree t, int count);
94  void sharingAnalysis(Tree t);
95  void sharingAnnotation(int vctxt, Tree t);
96 
97 
98  // generation du code
99 
100  string generateXtended (Tree sig);
101  virtual string generateFixDelay (Tree sig, Tree arg, Tree size);
102  string generatePrefix (Tree sig, Tree x, Tree e);
103  string generateIota (Tree sig, Tree arg);
104  string generateBinOp (Tree sig, int opcode, Tree arg1, Tree arg2);
105 
106  string generateFFun (Tree sig, Tree ff, Tree largs);
107  virtual string generateWaveform (Tree sig);
108 
109  string generateInput (Tree sig, const string& idx);
110  string generateOutput (Tree sig, const string& idx, const string& arg1);
111 
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);
118 
119  string generateSelect2 (Tree sig, Tree sel, Tree s1, Tree s2);
120  string generateSelect3 (Tree sig, Tree sel, Tree s1, Tree s2, Tree s3);
121 
122  string generateRecProj (Tree sig, Tree exp, int i);
123  void generateRec (Tree sig, Tree var, Tree le);
124 
125  string generateIntCast (Tree sig, Tree x);
126  string generateFloatCast (Tree sig, Tree x);
127 
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);
133 
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);
136 
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);
140 
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);
145 
146  void getTypedNames(Type t, const string& prefix, string& ctype, string& vname);
147  void ensureIotaCode();
148  int pow2limit(int x);
149 
150  void declareWaveform(Tree sig, string& vname, int& size);
151 
152 
153 
154 };
155 
156 #endif
Compile a list of FAUST signals into a scalar C++ class.
Definition: compile_scal.hh:40
void ensureIotaCode()
Generate code for a unique IOTA variable increased at each sample and used to index ring buffers...
string setCompiledExpression(Tree sig, const string &name)
Set the string of a compiled expression is already compiled.
virtual string CS(Tree sig)
Compile a signal.
string generateHBargraph(Tree sig, Tree label, Tree min, Tree max, const string &exp)
property< string > fVectorProperty
Definition: compile_scal.hh:44
void getTypedNames(Type t, const string &prefix, string &ctype, string &vname)
int pow2limit(int x)
Compute the minimal power of 2 greater than x.
string generateSelect3(Tree sig, Tree sel, Tree s1, Tree s2, Tree s3)
Generate a select3 code (using if-then-else) ((int n = sel==0)? s0 : ((sel==1)? s1 : s2)) int nn; ((n...
virtual string generateWaveform(Tree sig)
string generatePrefix(Tree sig, Tree x, Tree e)
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
string generateSelect2(Tree sig, Tree sel, Tree s1, Tree s2)
Generate a select2 code.
Tree prepare2(Tree L0)
string generateSigGen(Tree sig, Tree content)
string generateHSlider(Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
string generateFVar(Tree sig, const string &file, const string &name)
string generateIota(Tree sig, Tree arg)
string generateRecProj(Tree sig, Tree exp, int i)
Generate code for a projection of a group of mutually recursive definitions.
string generateBinOp(Tree sig, int opcode, Tree arg1, Tree arg2)
double max(double x, double y)
Definition: interval.hh:60
string generateRDTbl(Tree sig, Tree tbl, Tree idx)
string generateNumEntry(Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
string generateDelayVecNoTemp(Tree sig, const string &exp, const string &ctype, const string &vname, int mxd)
Generate code for the delay mecchanism without using temporary variables.
string generateButton(Tree sig, Tree label)
string generateStaticTable(Tree sig, Tree tsize, Tree content)
virtual string generateDelayVec(Tree sig, const string &exp, const string &ctype, const string &vname, int mxd)
Generate code for the delay mecchanism.
string generateFloatCast(Tree sig, Tree x)
bool getVectorNameProperty(Tree sig, string &vecname)
Get the vector name property of a signal, the name of the vector used to store the previous values of...
string generateVSlider(Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
string getFreshID(const string &prefix)
int getSharingCount(Tree t)
Definition: sharing.cpp:62
Definition: klass.hh:55
void compilePreparedSignalList(Tree lsig)
bool getCompiledExpression(Tree sig, string &name)
Test if a signal is already compiled.
virtual string generateVariableStore(Tree sig, const string &exp)
void sharingAnalysis(Tree t)
Definition: sharing.cpp:88
property< pair< string, string > > fInstanceInitProperty
Definition: compile_scal.hh:46
ScalarCompiler(const string &name, const string &super, int numInputs, int numOutputs)
Definition: compile_scal.hh:56
Tree prepare(Tree L0)
string generateCheckbox(Tree sig, Tree label)
ScalarCompiler(Klass *k)
Definition: compile_scal.hh:61
property< string > fCompileProperty
Definition: compile_scal.hh:43
property< pair< string, string > > fStaticInitProperty
Definition: compile_scal.hh:45
Occurences Markup of a root tree.
Definition: occurences.hh:32
void generateRec(Tree sig, Tree var, Tree le)
Generate code for a group of mutually recursive definitions.
string generateInput(Tree sig, const string &idx)
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
string generateIntCast(Tree sig, Tree x)
string generateXtended(Tree sig)
retrieve the type annotation of sig
virtual void compileSingleSignal(Tree lsig)
OccMarkup fOccMarkup
Definition: compile_scal.hh:50
string generateOutput(Tree sig, const string &idx, const string &arg1)
virtual string generateCacheCode(Tree sig, const string &exp)
string generateWRTbl(Tree sig, Tree tbl, Tree idx, Tree data)
string generateNumber(Tree sig, const string &exp)
virtual string generateFixDelay(Tree sig, Tree arg, Tree size)
Generate code for accessing a delayed signal.
string generateFFun(Tree sig, Tree ff, Tree largs)
void declareWaveform(Tree sig, string &vname, int &size)
Generate code for a waveform.
void setVectorNameProperty(Tree sig, const string &vecname)
Set the vector name property of a signal, the name of the vector used to store the previous values of...
void sharingAnnotation(int vctxt, Tree t)
Definition: sharing.cpp:106
virtual void compileMultiSignal(Tree lsig)
string generateFConst(Tree sig, const string &file, const string &name)
API to the typing system of signals.
double min(double x, double y)
Definition: interval.hh:59
string generateVBargraph(Tree sig, Tree label, Tree min, Tree max, const string &exp)
virtual string generateCode(Tree sig)
Main code generator dispatch.
void setSharingCount(Tree t, int count)
Definition: sharing.cpp:75
string generateStaticSigGen(Tree sig, Tree content)
virtual void generateDelayLine(const string &ctype, const string &vname, int mxd, const string &exp)
Generate code for the delay mecchanism without using temporary variables.
string generateTable(Tree sig, Tree tsize, Tree content)
static map< string, int > fIDCounters
Definition: compile_scal.hh:48
virtual string forceCacheCode(Tree sig, const string &exp)