69e7d00e6ce72be5839480da48e7991ac219e54d
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 ************************************************************************/
28 #include "sigtyperules.hh"
30 // imprime le type d'un signal en clair
32 void printSigType (Tree tp
)
37 if (isTableType(tp
, t0
)) {
40 } else if (isSigType(tp
, &n
, &v
, &c
)) {
44 //printf(" {%d,%d,%d} ", n, v, c);
50 void printSigTypeList (Tree l
)
55 putchar(sep
); sep
= ',';
64 void printSigType (int n
, int v
, int c
)
71 const char* binopname
[]= {
72 "+", "-", "*", "/", "%",
74 ">", "<", ">=", "<=", "==", "!=",
85 void printSignal(Tree sig
, FILE* out
, int prec
)
89 Tree x
, y
, z
, u
, le
, id
;
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); }
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
);
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
);
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
); }
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
); }
120 else if (isSigDocConstantTbl(sig
,x
,y
)) { fputs("sigDocConstantTbl(", out
); printSignal(x
,out
,0); fputc(',', out
);
121 printSignal(y
,out
,0); fputc(')', out
); }
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
); }
128 else if (isSigDocAccessTbl(sig
,x
,y
)) { fputs("sigDocAccessTbl(", out
); printSignal(x
,out
,0); fputc(',', out
);
129 printSignal(y
,out
,0); fputc(')', out
); }
132 else if ( isSigGen(sig
, x
) ) { printSignal(x
,out
,prec
); }
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
); }
137 else if (isList(sig
)) {
141 printSignal(hd(sig
), out
, 0);
144 } while (isList(sig
));