60
|
1 #define EXTERN /**/
|
|
2
|
|
3 #include "mc.h"
|
|
4
|
66
|
5 #include "conv/convdef.h"
|
60
|
6
|
68
|
7 extern void type_print(int type,NMTBL *nptr,FILE *out);
|
74
|
8 extern void type_print1(int type,NMTBL *nptr,FILE *out,int cont);
|
68
|
9 extern void sym_print(int type,FILE *out);
|
76
|
10 extern NMTBL str_ret;
|
68
|
11
|
69
|
12 static FILE *vout,*svout;
|
|
13 static FILE *null;
|
60
|
14
|
|
15 static void
|
67
|
16 comment_(int c)
|
66
|
17 {
|
67
|
18 fprintf(vout,"%c",c);
|
66
|
19 }
|
|
20
|
|
21 static void
|
|
22 open_(char *s)
|
65
|
23 {
|
|
24 char *p=cheapp;
|
66
|
25 while ((*cheapp++ = *s++)) {
|
65
|
26 if (*s=='.') {
|
|
27 *cheapp++=*s++; *cheapp++='c';
|
|
28 *cheapp++='c'; *cheapp++=0;
|
|
29 break;
|
|
30 }
|
|
31 }
|
76
|
32 #if 0
|
65
|
33 vout = fopen(p,"w");
|
69
|
34 #else
|
|
35 vout = stderr;p=p;
|
|
36 #endif
|
|
37 null=fopen("/dev/null","w");
|
66
|
38 if (!vout) error(-1);
|
65
|
39 }
|
|
40
|
|
41 static void
|
69
|
42 conv_()
|
|
43 {
|
|
44 vout=svout;
|
|
45 }
|
|
46
|
|
47 static void
|
|
48 noconv_(int c)
|
|
49 {
|
|
50 svout=vout;
|
|
51 vout=c?null:vout;
|
|
52 }
|
|
53
|
|
54 static void
|
66
|
55 print_(char *s)
|
60
|
56 {
|
|
57 fprintf(vout,"c: %s\n",s);
|
|
58 }
|
65
|
59
|
|
60 static void
|
66
|
61 close_()
|
65
|
62 {
|
|
63 fclose(vout);
|
|
64 }
|
66
|
65
|
|
66 void
|
67
|
67 case_begin_(int cases,int def){
|
|
68 fprintf(vout,"case ");
|
|
69 }
|
|
70
|
|
71 void
|
66
|
72 case_(int cases,int def){
|
67
|
73 if (def)
|
|
74 fprintf(vout,"default:");
|
|
75 else
|
69
|
76 fprintf(vout,"%d:",car(cases));
|
66
|
77 }
|
|
78
|
|
79 void
|
76
|
80 code_(NMTBL *n,int args){
|
68
|
81 fprintf(vout,"code %s(",n->nm);
|
|
82 while(args) {
|
|
83 n=(NMTBL *)car(args);
|
|
84 type_print(n->ty,n,vout);
|
|
85 args=cadr(args);
|
|
86 if(args) fprintf(vout,",");
|
|
87 }
|
76
|
88 fprintf(vout,")\n{");
|
66
|
89 }
|
|
90
|
|
91 void
|
|
92 code_end_(){
|
76
|
93 fprintf(vout,"}");
|
66
|
94 }
|
|
95
|
|
96 void
|
|
97 comma_(){
|
67
|
98 fprintf(vout,",");
|
66
|
99 }
|
|
100
|
|
101 void
|
|
102 cond_(){
|
|
103
|
|
104 }
|
|
105
|
|
106 void
|
|
107 cond1_(){
|
69
|
108 fprintf(vout,"?");
|
66
|
109 }
|
|
110
|
|
111 void
|
|
112 cond2_(){
|
69
|
113 fprintf(vout,":");
|
66
|
114 }
|
|
115
|
|
116 void
|
|
117 cond_end_(){
|
|
118
|
|
119 }
|
|
120
|
|
121 void
|
|
122 decl_data_begin_(){
|
|
123
|
|
124 }
|
|
125
|
|
126 void
|
|
127 decl_data_end_(){
|
|
128
|
|
129 }
|
|
130
|
|
131 void
|
|
132 def_(NMTBL *n){
|
|
133 }
|
|
134
|
|
135 void
|
|
136 dowhile_(){
|
72
|
137 fprintf(vout,"do");
|
66
|
138 }
|
|
139
|
|
140 void
|
|
141 dowhile_cond_(){
|
72
|
142 fprintf(vout,"while(");
|
66
|
143 }
|
|
144
|
|
145 void
|
|
146 dowhile_end_(){
|
72
|
147 fprintf(vout,");");
|
66
|
148 }
|
|
149
|
|
150 int
|
|
151 error_(n){
|
|
152 return 0;
|
|
153 }
|
|
154
|
|
155 void
|
|
156 extern_(){
|
67
|
157 fprintf(vout,"extern ");
|
66
|
158 }
|
|
159
|
|
160 void
|
|
161 for_(){
|
68
|
162 fprintf(vout,"for(");
|
66
|
163 }
|
|
164
|
|
165 void
|
|
166 for1_(){
|
68
|
167 fprintf(vout,";");
|
66
|
168 }
|
|
169
|
|
170 void
|
|
171 for2_(){
|
68
|
172 fprintf(vout,";");
|
66
|
173 }
|
|
174
|
|
175 void
|
69
|
176 for_body_(){
|
68
|
177 fprintf(vout,")");
|
66
|
178 }
|
|
179
|
|
180 void
|
|
181 for_end_(){
|
|
182
|
|
183 }
|
|
184
|
|
185 void
|
|
186 funcall_(int type){
|
68
|
187 fprintf(vout,"(");
|
66
|
188 }
|
|
189
|
|
190 void
|
|
191 funcall_args_(){
|
68
|
192 fprintf(vout,")");
|
66
|
193 }
|
|
194
|
|
195 void
|
75
|
196 function_(NMTBL *n,int args,int cont){
|
|
197 type_print1(n->ty,0,vout,cont);
|
68
|
198 fprintf(vout,"%s(",n->nm);
|
72
|
199 args=reverse0(args);
|
68
|
200 while(args) {
|
|
201 n=(NMTBL *)car(args);
|
|
202 type_print(n->ty,n,vout);
|
|
203 args=cadr(args);
|
76
|
204 if(args) {
|
|
205 if(car(args)==(int)&str_ret) break;
|
|
206 fprintf(vout,",");
|
|
207 }
|
68
|
208 }
|
|
209 fprintf(vout,")");
|
66
|
210 }
|
|
211
|
|
212 void
|
|
213 function_end_(){
|
|
214
|
|
215 }
|
|
216
|
|
217 void
|
|
218 goto_(){
|
76
|
219 fprintf(vout,"goto ");
|
66
|
220 }
|
|
221
|
|
222 void
|
|
223 goto_label_(){
|
|
224
|
|
225 }
|
|
226
|
|
227 void
|
68
|
228 id_(int sym,NMTBL *nptr){
|
69
|
229 fprintf(vout,"%s",nptr->nm);
|
68
|
230 }
|
|
231
|
|
232 void
|
|
233 string_(char *s){
|
69
|
234 int c;
|
|
235 fprintf(vout,"\"");
|
|
236 while((c=*s++)) {
|
|
237 if(c=='\n') fprintf(vout,"\\n");
|
|
238 else if(c=='\r') fprintf(vout,"\\r");
|
|
239 else if(c=='\e') fprintf(vout,"\\e");
|
|
240 else if(!(' '<=c&&c<=0x7f)) fprintf(vout,"\\%03o",c);
|
|
241 else fprintf(vout,"%c",c);
|
|
242 }
|
|
243 fprintf(vout,"\"");
|
68
|
244 }
|
|
245
|
|
246 void
|
|
247 const_(int symval){
|
|
248 fprintf(vout,"%d",symval);
|
|
249 }
|
66
|
250
|
68
|
251 void
|
|
252 return_f_(){
|
|
253 fprintf(vout,"return");
|
|
254 }
|
|
255
|
|
256 void
|
|
257 defined_(char *s){
|
|
258 fprintf(vout,"defined(%s)",s);
|
|
259 }
|
|
260
|
|
261 void
|
|
262 environment_(){
|
|
263 fprintf(vout,"environment");
|
66
|
264 }
|
|
265
|
|
266 void
|
|
267 if_(){
|
68
|
268 fprintf(vout,"if (");
|
66
|
269 }
|
|
270
|
|
271 void
|
|
272 if_else_(){
|
69
|
273 fprintf(vout," else ");
|
66
|
274 }
|
|
275
|
|
276 void
|
|
277 if_endif_(){
|
|
278 }
|
|
279
|
|
280 void
|
|
281 if_then_(){
|
69
|
282 fprintf(vout,")");
|
66
|
283 }
|
|
284
|
|
285 void
|
|
286 jump_(int env){
|
|
287
|
|
288 }
|
|
289
|
|
290 void
|
|
291 label_(){
|
72
|
292 fprintf(vout,"%s:",nptr->nm);
|
66
|
293 }
|
|
294
|
|
295 void
|
67
|
296 lpar_(){
|
|
297 fprintf(vout,"(");
|
|
298 }
|
|
299
|
|
300 void
|
|
301 rpar_(){
|
|
302 fprintf(vout,")");
|
|
303 }
|
|
304
|
|
305 void
|
66
|
306 lbra_(int sym){
|
67
|
307 fprintf(vout,"[");
|
|
308 }
|
66
|
309
|
67
|
310 void
|
|
311 rbra_(int sym){
|
|
312 fprintf(vout,"]");
|
66
|
313 }
|
|
314
|
|
315 void
|
|
316 lc_(){
|
67
|
317 fprintf(vout,"{");
|
|
318 }
|
66
|
319
|
67
|
320 void
|
|
321 rc_(){
|
|
322 fprintf(vout,"}");
|
66
|
323 }
|
|
324
|
|
325 void
|
|
326 localvar_end_(){
|
|
327
|
|
328 }
|
|
329
|
|
330 void
|
|
331 op_(int sym){
|
68
|
332 sym_print(sym,vout);
|
66
|
333 }
|
|
334
|
|
335 void
|
|
336 postfix_(int sym){
|
69
|
337 sym_print(sym,vout);
|
66
|
338 }
|
|
339
|
|
340 void
|
|
341 prefix_(int sym){
|
69
|
342 sym_print(sym,vout);
|
66
|
343 }
|
|
344
|
|
345 void
|
|
346 register_(){
|
67
|
347 fprintf(vout,"register ");
|
66
|
348 }
|
|
349
|
|
350 void
|
|
351 return_(){
|
69
|
352 fprintf(vout,"return ");
|
66
|
353 }
|
|
354
|
|
355 void
|
|
356 return_end_(){
|
70
|
357 fprintf(vout,";");
|
66
|
358 }
|
|
359
|
|
360 void
|
67
|
361 return_type_(int t,NMTBL *nptr,int cont){
|
74
|
362 type_print1(t,nptr,vout,cont);
|
66
|
363 }
|
|
364
|
|
365 void
|
|
366 sm_(){
|
67
|
367 fprintf(vout,";");
|
66
|
368 }
|
|
369
|
|
370 void
|
|
371 static_(){
|
67
|
372 fprintf(vout,"static ");
|
66
|
373 }
|
|
374
|
|
375 void
|
|
376 switch_(){
|
68
|
377 fprintf(vout,"switch (");
|
66
|
378 }
|
|
379
|
|
380 void
|
|
381 switch_body_(){
|
71
|
382 fprintf(vout,")");
|
66
|
383 }
|
|
384
|
|
385 void
|
|
386 switch_end_(){
|
|
387 }
|
|
388
|
|
389 void
|
|
390 typedef_(){
|
67
|
391 fprintf(vout,"typedef ");
|
66
|
392 }
|
|
393
|
|
394 void
|
70
|
395 sdecl_(int s)
|
|
396 {
|
|
397 fprintf(vout,s==UNION?"union ":"struct ");
|
|
398 }
|
|
399
|
|
400 void
|
66
|
401 while_(){
|
68
|
402 fprintf(vout,"while (");
|
66
|
403 }
|
|
404
|
|
405 void
|
|
406 while_body_(){
|
69
|
407 fprintf(vout,")");
|
66
|
408 }
|
|
409
|
|
410 void
|
|
411 while_end_(){
|
69
|
412 }
|
|
413
|
|
414 void
|
|
415 decl_data_()
|
|
416 {
|
|
417 }
|
|
418
|
|
419 void
|
|
420 break_()
|
|
421 {
|
|
422 fprintf(vout,"break;");
|
|
423 }
|
|
424
|
|
425 void
|
|
426 continue_()
|
|
427 {
|
|
428 fprintf(vout,"continue;");
|
66
|
429 }
|
|
430
|
|
431 /* end */
|