New directory tree, with preprocessor/ inside interpretor/.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / documentator / doc_compile.hh
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 _DOC_COMPILE_SCAL_
25 #define _DOC_COMPILE_SCAL_
26
27
28 #include <string>
29 #include <list>
30 #include <map>
31
32 #include "sigtyperules.hh"
33 #include "occurences.hh"
34 #include "property.hh"
35 #include "signals.hh"
36 #include "lateq.hh"
37 #include "Text.hh"
38 #include "doc_Text.hh"
39 #include "description.hh"
40
41
42 ///////////////////////////////////////////////////////////////////////
43 /**
44 * Compile a list of FAUST signals into a list of LaTeX formulas.
45 */
46 ///////////////////////////////////////////////////////////////////////
47
48 class DocCompiler
49 {
50 protected:
51
52 property<string> fCompileProperty;
53 property<string> fVectorProperty;
54
55 Lateq* fLateq;
56 Description* fDescription;
57
58 static map<string, int> fIDCounters;
59 Tree fSharingKey;
60 OccMarkup fOccMarkup;
61 int fPriority; ///< math priority context
62
63
64 public:
65
66 DocCompiler (int numInputs, int numOutputs)
67 :
68 fLateq(new Lateq(numInputs, numOutputs)),
69 fDescription(0),
70 fPriority(0)
71 {}
72
73 DocCompiler ( Lateq* k, int priority)
74 :
75 fLateq(k),
76 fDescription(0),
77 fPriority(priority)
78 {}
79
80 ~DocCompiler()
81 {}
82
83 Lateq* compileLateq (Tree L, Lateq* compiledEqn);
84 Tree annotate(Tree L0);
85
86 Lateq* getLateq() { return (Lateq*)fLateq; }
87 void setDescription(Description* descr) { fDescription= descr; }
88 Description* getDescription() { return fDescription; }
89
90
91 protected:
92
93 string CS (Tree sig, int priority);
94 string generateCode (Tree sig, int priority);
95 string generateCacheCode(Tree sig, const string& exp) ;
96 string generateVariableStore(Tree sig, const string& exp);
97
98 string getFreshID (const string& prefix);
99
100 bool getCompiledExpression(Tree sig, string& name);
101 string setCompiledExpression(Tree sig, const string& name);
102
103 void setVectorNameProperty(Tree sig, const string& vecname);
104 bool getVectorNameProperty(Tree sig, string& vecname);
105
106 int getSharingCount(Tree t);
107 void setSharingCount(Tree t, int count);
108 void sharingAnalysis(Tree t);
109 void sharingAnnotation(int vctxt, Tree t);
110
111 bool isShortEnough(string& s, unsigned int max);
112
113
114 /* Code generation. */
115
116 string generateXtended (Tree sig, int priority);
117 string generateFixDelay (Tree sig, Tree arg, Tree size, int priority);
118 string generatePrefix (Tree sig, Tree x, Tree e, int priority);
119 string generateIota (Tree sig, Tree arg);
120 string generateBinOp (Tree sig, int opcode, Tree arg1, Tree arg2, int priority);
121
122 string generateFFun (Tree sig, Tree ff, Tree largs, int priority);
123
124 string generateInput (Tree sig, const string& idx);
125 string generateOutput (Tree sig, const string& idx, const string& arg1);
126
127 // string generateDocReadOnlyTbl (Tree sig, Tree size, Tree content, Tree ridx);
128 // string generateDocReadWriteTbl (Tree sig, Tree size, Tree content, Tree widx, Tree wsig, Tree ridx);
129 string generateDocConstantTbl (Tree sig, Tree size, Tree content);
130 string generateDocWriteTbl (Tree sig, Tree size, Tree content, Tree widx, Tree wsig);
131 string generateDocAccessTbl (Tree sig, Tree tbl, Tree ridx);
132
133 string generateSelect2 (Tree sig, Tree sel, Tree s1, Tree s2, int priority);
134 string generateSelect3 (Tree sig, Tree sel, Tree s1, Tree s2, Tree s3, int priority);
135
136 string generateRecProj (Tree sig, Tree exp, int i, int priority);
137 void generateRec (Tree sig, Tree var, Tree le, int priority);
138
139 string generateIntCast (Tree sig, Tree x, int priority);
140 string generateFloatCast (Tree sig, Tree x, int priority);
141
142 string generateButton (Tree sig, Tree label);
143 string generateCheckbox (Tree sig, Tree label);
144 string generateVSlider (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
145 string generateHSlider (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
146 string generateNumEntry (Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step);
147
148 string generateVBargraph (Tree sig, Tree label, Tree min, Tree max, const string& exp);
149 string generateHBargraph (Tree sig, Tree label, Tree min, Tree max, const string& exp);
150 string generateAttach (Tree sig, Tree x, Tree y, int priority);
151
152 string generateNumber(Tree sig, const string& exp);
153 string generateFConst (Tree sig, const string& file, const string& name);
154 string generateFVar (Tree sig, const string& file, const string& name);
155
156 string generateDelayVec(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd);
157 string generateDelayVecNoTemp(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd);
158 void generateDelayLine(const string& ctype, const string& vname, int mxd, const string& exp);
159
160 void getTypedNames(Type t, const string& prefix, string& ctype, string& vname);
161 void printGCCall(Tree sig, const string& calledFunction);
162
163
164 /* Managment of user interface elements. */
165
166 void getUIDocInfos(Tree path, string& label, string& unit);
167 string getUIDir (Tree pathname);
168 string prepareBinaryUI(const string& name, Tree pathname);
169 string prepareIntervallicUI(const string& name, Tree path, Tree tcur, Tree tmin, Tree tmax);
170 };
171
172 #endif