Adding 3 example Makefiles to track list.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / signals / sigprint.cpp
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 #include <stdio.h>
25
26 #include "signals.hh"
27 #include "sigtype.hh"
28 #include "sigtyperules.hh"
29
30 // imprime le type d'un signal en clair
31 #if 0
32 void printSigType (Tree tp)
33 {
34 Tree t0;
35 int n, v, c;
36
37 if (isTableType(tp, t0)) {
38 printf("table-of ");
39 printSigType(t0);
40 } else if (isSigType(tp, &n, &v, &c)) {
41 putchar("NR"[n]);
42 putchar("KB S"[v]);
43 putchar("CI X"[c]);
44 //printf(" {%d,%d,%d} ", n, v, c);
45 } else {
46 printf("unknown");
47 }
48 }
49
50 void printSigTypeList (Tree l)
51 {
52 char sep = '(';
53
54 do {
55 putchar(sep); sep = ',';
56 printSigType(hd(l));
57 l = tl(l);
58 } while (isList(l));
59
60 putchar(')');
61 }
62 #endif
63
64 void printSigType (int n, int v, int c)
65 {
66 putchar("NR"[n]);
67 putchar("KB S"[v]);
68 putchar("CI X"[c]);
69 }
70
71 const char* binopname[]= {
72 "+", "-", "*", "/", "%",
73 "<<", ">>",
74 ">", "<", ">=", "<=", "==", "!=",
75 "&", "|", "^"
76 };
77
78 int binopprec[]= {
79 2, 2, 3, 3, 3,
80 1, 1,
81 1, 1, 1, 1, 1, 1,
82 1, 1, 1
83 };
84
85 void printSignal(Tree sig, FILE* out, int prec)
86 {
87 int i;
88 double r;
89 Tree x, y, z, u, le, id;
90
91 if ( isSigInt(sig, &i) ) { fprintf(out, "%d", i); }
92 else if ( isSigReal(sig, &r) ) { fprintf(out, "%f", r); }
93 else if ( isSigInput(sig, &i) ) { fprintf(out, "IN%d", i); }
94 else if ( isSigOutput(sig, &i, x) ) { fprintf(out, "OUT%d := ", i); printSignal(x, out, 0); }
95
96 else if ( isSigBinOp(sig, &i, x, y) ) {
97 if (prec > binopprec[i]) fputs("(", out);
98 printSignal(x,out,binopprec[i]); fputs(binopname[i], out); printSignal(y, out, binopprec[i]);
99 if (prec > binopprec[i]) fputs(")", out);
100 }
101 else if ( isSigDelay1(sig, x) ) { fputs("mem(", out); printSignal(x,out,0); fputs(")", out); }
102 else if ( isSigPrefix(sig, x, y) ) { fputs("prefix(", out); printSignal(x,out,0); fputs(",", out); printSignal(y,out,0); fputs(")", out); }
103 else if ( isSigAttach(sig, x, y) ) { fputs("attach(", out); printSignal(x,out,0); fputs(",", out); printSignal(y,out,0); fputs(")", out); }
104 else if ( isSigFixDelay(sig, x, y) ) {
105 if (prec > 4) fputs("(", out);
106 printSignal(x,out,4); fputs("@", out); printSignal(y, out, 4);
107 if (prec > 4) fputs(")", out);
108 }
109
110 else if ( isProj(sig, &i, x) ) { printSignal(x,out,prec); fprintf(out, "#%d", i); }
111 else if ( isRef(sig, i) ) { fprintf(out, "$%d", i); }
112 else if ( isRef(sig, x) ) { print(x, out); }
113 else if ( isRec(sig, le)) { fputs("\\_.", out); printSignal(le, out, prec); }
114 else if ( isRec(sig, x, le)) { fputs("\\", out); print(x,out); fputs(".", out); printSignal(le, out, prec); }
115
116 else if ( isSigTable(sig, id, x, y) ) { fputs("table(", out); printSignal(x,out,0); fputc(',', out); printSignal(y,out,0); fputc(')', out); }
117 else if ( isSigWRTbl(sig, id, x, y, z) ){ printSignal(x,out,0); fputc('[',out); printSignal(y,out,0); fputs("] := (", out); printSignal(z,out,0); fputc(')', out); }
118 else if ( isSigRDTbl(sig, x, y) ) { printSignal(x,out,0); fputc('[', out); printSignal(y,out,0); fputc(']', out); }
119
120 else if (isSigDocConstantTbl(sig,x,y)) { fputs("sigDocConstantTbl(", out); printSignal(x,out,0); fputc(',', out);
121 printSignal(y,out,0); fputc(')', out); }
122
123 else if (isSigDocWriteTbl(sig,x,y,z,u)) { fputs("sigDocWriteTbl(", out); printSignal(x,out,0); fputc(',', out);
124 printSignal(y,out,0); fputc(',', out);
125 printSignal(z,out,0); fputc(',', out);
126 printSignal(u,out,0); fputc(')', out); }
127
128 else if (isSigDocAccessTbl(sig,x,y)) { fputs("sigDocAccessTbl(", out); printSignal(x,out,0); fputc(',', out);
129 printSignal(y,out,0); fputc(')', out); }
130
131
132 else if ( isSigGen(sig, x) ) { printSignal(x,out,prec); }
133
134 else if ( isSigIntCast(sig, x) ) { fputs("int(", out); printSignal(x,out,0); fputs(")", out); }
135 else if ( isSigFloatCast(sig, x) ) { fputs("float(", out); printSignal(x,out,0); fputs(")", out); }
136
137 else if (isList(sig)) {
138 char sep = '{';
139 do {
140 fputc(sep, out);
141 printSignal(hd(sig), out, 0);
142 sep=',';
143 sig = tl(sig);
144 } while (isList(sig));
145 fputc('}', out);
146 }
147 else
148 print(sig, out);
149 }