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