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;
|
|
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
|
|
150 error_(n){
|
|
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;
|
75
|
197 type_print1(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){
|
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 */
|