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