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