462
|
1 /* Micro-C Partial Evaluator Part */
|
|
2 /* $Id$ */
|
|
3
|
|
4 #include <stdio.h>
|
|
5 #include "mc.h"
|
|
6 #include "mc-parse.h"
|
|
7 #include "mc-codegen.h"
|
|
8 #include "mc-switch.h"
|
464
|
9 #include "mc-code.h"
|
|
10 #include "mc-inline.h"
|
462
|
11
|
463
|
12 static int pvartable;
|
|
13 static int pdisp;
|
462
|
14
|
|
15 /*
|
|
16 Basic code generator from parse tree
|
|
17 */
|
|
18
|
|
19 extern void
|
|
20 st_decl(int e1){
|
|
21 // NMTBL *n = (NMTBL *)caddr(e1);
|
|
22 // int stmode = cadddr(e1);
|
|
23 }
|
|
24
|
|
25 extern void
|
|
26 st_if(int e1){
|
|
27 int l1,l2,slfree;
|
|
28 int e2=caddr(e1),e3;
|
|
29 // conv->if_();
|
|
30 slfree=lfree;
|
|
31 checkret();
|
|
32 l1 = bexpr(car(e2),0,fwdlabel());
|
|
33 // conv->if_then_();
|
|
34 g_expr_u(cadr(e2));
|
|
35 checkret();
|
|
36 if ((e3=caddr(e2))) { // else
|
|
37 // conv->if_else_();
|
|
38 if ((l2 = control))
|
|
39 gen_jmp(l2=fwdlabel());
|
|
40 fwddef(l1);
|
|
41 g_expr_u(e3);
|
|
42 checkret();
|
|
43 if (l2) fwddef(l2);
|
|
44 } else {
|
|
45 fwddef(l1);
|
|
46 }
|
|
47 // conv->if_endif_();
|
|
48 }
|
|
49
|
|
50
|
|
51 extern void
|
|
52 st_do(int e1){
|
|
53 int sbreak,scontinue,l;
|
|
54
|
|
55 sbreak=blabel;
|
|
56 scontinue=clabel;
|
|
57 blabel=fwdlabel();
|
|
58 clabel=fwdlabel();
|
|
59 control=1;
|
|
60 checkret();
|
|
61 l=backdef();
|
|
62 // conv->dowhile_();
|
|
63 g_expr_u(cadddr(e1));
|
|
64 checkret();
|
|
65 // conv->dowhile_cond_();
|
|
66 bexpr(caddr(e1),1,l);
|
|
67 // conv->dowhile_end_();
|
|
68 fwddef(blabel);
|
|
69 clabel=scontinue;
|
|
70 blabel=sbreak;
|
|
71 }
|
|
72
|
|
73
|
|
74 extern void
|
|
75 st_while(int e1){
|
|
76 int sbreak,scontinue,e;
|
|
77
|
|
78 sbreak=blabel;
|
|
79 scontinue=clabel;
|
|
80 blabel=fwdlabel();
|
|
81 control=1;
|
|
82 checkret();
|
|
83 clabel=backdef();
|
|
84 // conv->while_();
|
|
85 // conv->while_body_();
|
|
86 if(!(e=cadddr(e1))) {
|
|
87 bexpr(caddr(e1),1,clabel);
|
|
88 // conv->sm_();
|
|
89 } else {
|
|
90 bexpr(caddr(e1),0,blabel);
|
|
91 g_expr_u(e);
|
|
92 checkret();
|
|
93 if(control)
|
|
94 gen_jmp(clabel);
|
|
95 }
|
|
96 // conv->while_end_();
|
|
97 fwddef(blabel);
|
|
98 clabel=scontinue;
|
|
99 blabel=sbreak;
|
|
100 }
|
|
101
|
|
102
|
|
103 extern void
|
|
104 st_for(int e1){
|
|
105 int p0,p1,p2,body;
|
|
106 int l,e;
|
|
107 int sbreak=blabel;
|
|
108 int scontinue=clabel;
|
|
109
|
|
110 e = caddr(e1);
|
|
111 p0 = car(e); p1 = cadr(e); p2 = caddr(e); body = cadddr(e);
|
|
112
|
|
113 blabel=fwdlabel();
|
|
114 // conv->for_();
|
|
115 if (p0) {
|
|
116 checkret();
|
|
117 g_expr_u(p0);
|
|
118 }
|
|
119 // conv->for1_();
|
|
120 control=1;
|
|
121 checkret();
|
|
122 l=backdef();
|
|
123 if (p1) {
|
|
124 bexpr(p1,0,blabel);
|
|
125 }
|
|
126 // conv->for2_();
|
|
127 // conv->for_body_();
|
|
128 if (!p2) {
|
|
129 clabel=l;
|
|
130 g_expr_u(body);
|
|
131 checkret();
|
|
132 } else {
|
|
133 clabel=fwdlabel();
|
|
134 g_expr_u(body);
|
|
135 checkret();
|
|
136 fwddef(clabel);
|
|
137 g_expr_u(p2);
|
|
138 }
|
|
139 // conv->for_end_();
|
|
140 gen_jmp(l);
|
|
141 fwddef(blabel);
|
|
142 clabel=scontinue;
|
|
143 blabel=sbreak;
|
|
144 }
|
|
145
|
|
146
|
|
147 extern void
|
|
148 st_switch(int e1){
|
|
149 int sbreak,scase,sdefault,slfree,svalue,slist;
|
|
150
|
|
151 checkret();
|
|
152 slist = cslist;
|
|
153 cslist = 0;
|
|
154 sbreak=blabel; /* save parents break label */
|
|
155 blabel=fwdlabel();
|
|
156 sdefault=dlabel; /* save parents default label */
|
|
157 dlabel=0;
|
|
158 scase=cslabel; /* save parents next case label */
|
|
159 // conv->switch_();
|
|
160 slfree=lfree;
|
|
161 svalue=csvalue1; /* save parents switch value */
|
|
162 gexpr(caddr(e1),1);
|
|
163 csvalue1=csvalue() ;
|
|
164 // conv->switch_body_();
|
|
165 cslabel = control = 0;
|
|
166 g_expr_u(cadddr(e1));
|
|
167 // conv->switch_end_();
|
|
168 checkret();
|
|
169 #if CASE_CODE
|
|
170 if (control) gen_jmp(blabel);
|
|
171 genswitch(cslist,cslabel);
|
|
172 #else
|
|
173 if(dlabel) def_label(cslabel,dlabel);
|
|
174 else fwddef(cslabel);
|
|
175 #endif
|
|
176 csvalue1=svalue;
|
|
177 cslabel=scase;
|
|
178 dlabel=sdefault;
|
|
179 fwddef(blabel);
|
|
180 blabel=sbreak;
|
|
181 cslist = slist;
|
|
182 }
|
|
183
|
|
184
|
|
185 extern void
|
|
186 st_comp(int e1){
|
|
187 g_expr_u(caddr(e1));
|
|
188 }
|
|
189
|
|
190
|
|
191 extern void
|
|
192 st_break(int e1){
|
|
193 checkret();
|
|
194 // conv->break_();
|
|
195 if (control)
|
|
196 gen_jmp(blabel);
|
|
197 }
|
|
198
|
|
199
|
|
200 extern void
|
|
201 st_continue(int e1){
|
|
202 checkret();
|
|
203 // conv->continue_();
|
|
204 if (control) gen_jmp(clabel);
|
|
205 }
|
|
206
|
|
207
|
|
208 extern void
|
|
209 st_case(int e1){
|
|
210 #if CASE_CODE
|
|
211 int l,clist=caddr(e1),c;
|
|
212 l = fwdlabel();
|
|
213 // conv->case_begin_(0,0);
|
|
214 // conv->case_(0,0);
|
|
215 if (retpending) {
|
|
216 ret(); retpending=0;
|
|
217 }
|
|
218 if (!cslabel) {
|
|
219 if (!control) {
|
|
220 cmpdimm(car(clist),csvalue1,cslabel=fwdlabel(),1);
|
|
221 caddr(clist)=0;
|
|
222 } else {
|
|
223 error(-1);
|
|
224 }
|
|
225 }
|
|
226 while(clist) {
|
|
227 caddr(clist) = l;
|
|
228 clist = cadr(c=clist); cadr(c) = 0; // insert destroy cadr of clist
|
|
229 cslist=insert_ascend(cslist,c,docase_eq);
|
|
230 }
|
|
231 fwddef(l);
|
|
232 control=1;
|
|
233 #else
|
|
234 /* casading branch implementation */
|
|
235 int c,l;
|
|
236 c = caddr(e1);
|
|
237 if (retpending) {
|
|
238 ret(); retpending=0;
|
|
239 }
|
|
240 // conv->case_begin_(0,0);
|
|
241 // conv->case_(0,0);
|
|
242 l=fwdlabel();
|
|
243 if (control) {
|
|
244 control=0;
|
|
245 gen_jmp(l);
|
|
246 }
|
|
247 if (cslabel) fwddef(cslabel);
|
|
248 while(cadr(c)) {
|
|
249 cmpdimm(car(c),csvalue1,l,0);
|
|
250 c=cadr(c);
|
|
251 }
|
|
252 cmpdimm(car(c),csvalue1,cslabel=fwdlabel(),1);
|
|
253 if (l) fwddef(l);
|
|
254 #endif
|
|
255 }
|
|
256
|
|
257
|
|
258 extern void
|
|
259 st_default(int e1){
|
|
260 control=1;
|
|
261 checkret();
|
|
262 if (dlabel) error(STERR); // double default:
|
|
263 dlabel = backdef();
|
|
264 // conv->case_(0,1);
|
|
265 }
|
|
266
|
|
267
|
|
268 extern void
|
|
269 st_return(int e1){
|
|
270 int e;
|
|
271
|
|
272 if (!cslabel) gen_jmp(cslabel = fwdlabel());
|
|
273 if(!(e=caddr(e1))) {
|
|
274 // conv->return_();
|
|
275 // conv->return_end_();
|
|
276 retpending = 1;
|
|
277 return;
|
|
278 }
|
|
279 // conv->return_();
|
|
280 if (struct_return) {
|
|
281 if ((car(type)==STRUCT || car(type)==UNION)&&
|
|
282 size(type)==cadr(struct_return)) {
|
|
283 if(car(e)==RSTRUCT && car(cadr(e))==FUNCTION) {
|
|
284 /* pass the return pointer to the called function */
|
|
285 replace_return_struct(cadr(e),
|
|
286 rvalue_t(car(struct_return),caddr(struct_return)));
|
|
287 replace_return_struct(cadr(e),
|
|
288 rvalue_t(car(struct_return),caddr(struct_return)));
|
|
289 gexpr(cadr(e),0);
|
|
290 } else {
|
|
291 type = caddr(struct_return);
|
|
292 // e1 = rvalue_t(cadr(struct_return),INT); /* size */
|
|
293 e1 = cadr(struct_return); /* size */
|
|
294 gexpr(list4(STASS,rvalue(car(struct_return)),e,e1),0);
|
|
295 }
|
|
296 } else {
|
|
297 error(TYERR); /* should check compatible */
|
|
298 }
|
|
299 } else {
|
|
300 gexpr(correct_type(e,cadr(fnptr->ty)),1);
|
|
301 }
|
|
302 // conv->return_end_();
|
|
303 retpending = 1;
|
|
304 }
|
|
305
|
|
306
|
|
307 extern void
|
|
308 st_goto(int e){
|
|
309 NMTBL *nlist,*nptr0;
|
|
310 int t,e1,e2,env;
|
|
311
|
|
312 checkret();
|
|
313 // conv->goto_();
|
|
314 e1 = caddr(e);
|
|
315 if (car(e1)==RINDIRECT) {
|
|
316 gen_indirect_goto(cadr(e1));
|
|
317 return;
|
|
318 } else if (car(e1)==FLABEL) {
|
|
319 nlist = (NMTBL *)cadr(e1);
|
|
320 nptr0 = name_space_search(nlist,0);
|
|
321 t = nptr0->sc;
|
|
322 if (t==EMPTY||t==EXTRN1||t==EXTRN) {
|
|
323 nptr0 = make_local_scope(nlist,nptr0,0);
|
|
324 nptr0->sc = FLABEL;
|
|
325 nptr0->dsp = fwdlabel();
|
|
326 } else if (!(t==FLABEL||t==BLABEL)) {
|
|
327 error(STERR);
|
|
328 }
|
|
329 gen_jmp(nptr0->dsp);
|
|
330 control=0;
|
|
331 // conv->sm_();
|
|
332 // conv->goto_label_(nptr0);
|
|
333 return;
|
|
334 } else {
|
|
335 /* CbC continuation */
|
|
336 // conv->jump_(env);
|
|
337 e2 = cadr(e1);
|
|
338 env = caddr(e1);
|
|
339 if (car(e2) == FNAME) {
|
|
340 nptr0=(NMTBL *)cadr(e2);
|
|
341 if (nptr0->sc==EMPTY)
|
|
342 nptr0->sc = EXTRN1;
|
|
343 else if(nptr0->sc==FUNCTION)
|
|
344 nptr0->sc = CODE;
|
|
345 if (nptr0->ty>0&&car(nptr0->ty)==FUNCTION)
|
|
346 car(nptr0->ty)=CODE;
|
|
347 }
|
|
348 gexpr(list3(CODE,e1,env),0);
|
|
349 control=0;
|
|
350 // conv->sm_();
|
|
351 return;
|
|
352 }
|
|
353 }
|
|
354
|
|
355
|
|
356 #if ASM_CODE
|
|
357 extern void
|
|
358 st_asm(int e1){
|
|
359 checkret();
|
|
360 g_expr_u(list3(ASM,caddr(e1),cadddr(e1)));
|
|
361 }
|
|
362 #endif
|
|
363
|
|
364
|
|
365 extern void
|
|
366 st_label(int e1){
|
|
367 NMTBL *nptr,*nlist;
|
|
368 nlist = (NMTBL *)caddr(e1);
|
|
369 nptr = name_space_search(nlist,0);
|
|
370 control=1;
|
|
371 checkret();
|
|
372 if(nptr->sc == FLABEL) {
|
|
373 fwddef(nptr->dsp);
|
|
374 } else if(nptr->sc != EMPTY && nptr->sc != EXTRN1 && nptr->sc !=BLABEL) {
|
|
375 error(TYERR);
|
|
376 } else {
|
|
377 nptr->sc=EMPTY;
|
|
378 nptr = make_local_scope(nlist,nptr,0);
|
|
379 nptr->sc = BLABEL;
|
|
380 nptr->dsp = backdef();
|
|
381 }
|
|
382 // conv->label_();
|
|
383 }
|
|
384
|
|
385 extern void
|
|
386 st_comment(int e1){
|
|
387 gen_comment((char *)caddr(e1));
|
|
388 }
|
|
389
|
|
390 /*
|
|
391 partial evaluator
|
|
392 */
|
|
393
|
|
394 static int
|
463
|
395 p_vartable(int e,int adisp,int ldisp)
|
462
|
396 {
|
464
|
397 int i;
|
463
|
398 pvartable = getfree(adisp+ldisp);
|
|
399 pdisp = pvartable+adisp;
|
|
400 for(i=adisp+ldisp;i>=0;i--) {
|
|
401 pvartable = 0;
|
|
402 }
|
462
|
403 return 0;
|
|
404 }
|
|
405
|
|
406 static int
|
|
407 p_lvar(int e1)
|
|
408 {
|
463
|
409 int sz = is_memory(e1);
|
|
410 int d = cadr(e1);
|
|
411 int d1;
|
|
412 if ((d1=(heap[pdisp+e1]))) return d1;
|
464
|
413 return (heap[pdisp+d]=new_lvar(sz));
|
462
|
414 }
|
|
415
|
|
416 static int
|
|
417 pfunction(int e)
|
|
418 {
|
464
|
419 return e;
|
462
|
420 }
|
|
421
|
|
422 static int
|
|
423 prindirect(int e)
|
|
424 {
|
464
|
425 return e;
|
462
|
426 }
|
|
427
|
|
428 static int
|
|
429 paddress(int e)
|
|
430 {
|
464
|
431 return e;
|
462
|
432 }
|
|
433
|
|
434 static int
|
464
|
435 p_conv(int e1,int e2)
|
462
|
436 {
|
464
|
437 return e1;
|
462
|
438 }
|
|
439
|
|
440 static int
|
464
|
441 pbinop(int op,int e1,int e2)
|
462
|
442 {
|
464
|
443 return e1;
|
462
|
444 }
|
|
445
|
|
446 static int
|
|
447 psassign(int e)
|
|
448 {
|
464
|
449 return e;
|
462
|
450 }
|
|
451
|
|
452 static int
|
|
453 passign(int e)
|
|
454 {
|
464
|
455 return e;
|
462
|
456 }
|
|
457
|
|
458 static int
|
|
459 passop(int e)
|
|
460 {
|
464
|
461 return e;
|
462
|
462 }
|
|
463
|
|
464 static int
|
|
465 pdassign(int e)
|
|
466 {
|
464
|
467 return e;
|
462
|
468 }
|
|
469
|
|
470 static int
|
|
471 pdassop(int e)
|
|
472 {
|
464
|
473 return e;
|
462
|
474 }
|
|
475
|
|
476 static int
|
|
477 plassign(int e)
|
|
478 {
|
464
|
479 return e;
|
462
|
480 }
|
|
481
|
|
482 static int
|
|
483 plassop(int e)
|
|
484 {
|
464
|
485 return e;
|
462
|
486 }
|
|
487
|
|
488 static int
|
|
489 palloc(int e)
|
|
490 {
|
464
|
491 return e;
|
462
|
492 }
|
|
493
|
|
494 static int
|
464
|
495 pcomma(int e1,int e2)
|
462
|
496 {
|
464
|
497 return e1;
|
462
|
498 }
|
|
499
|
|
500 static int
|
|
501 prbit_field(int e)
|
|
502 {
|
464
|
503 return e;
|
462
|
504 }
|
|
505
|
|
506 static int
|
|
507 pbassign(int e)
|
|
508 {
|
464
|
509 return e;
|
462
|
510 }
|
|
511
|
|
512 static int
|
|
513 pbassop(int e)
|
|
514 {
|
464
|
515 return e;
|
462
|
516 }
|
|
517
|
|
518 static int
|
|
519 p_decl(int e)
|
|
520 {
|
463
|
521 // list4(ST_DECL,parse,(int)n,stmode);
|
|
522 int stmode=cadddr(e);
|
|
523 NMTBL *n=(NMTBL*)caddr(e);
|
|
524 int dsp = n->dsp;
|
|
525 int v;
|
|
526 switch(stmode) {
|
|
527 case REGISTER:
|
|
528 switch(n->ty) {
|
|
529 case ULONGLONG: case LONGLONG:
|
|
530 v = get_lregister_var(n); break;
|
|
531 case FLOAT:
|
|
532 v = get_dregister_var(n,0); break;
|
|
533 case DOUBLE:
|
|
534 v = get_dregister_var(n,1); break;
|
|
535 default:
|
|
536 if (scalar(n->ty))
|
|
537 v = get_dregister_var(n,1);
|
|
538 else
|
|
539 error(TYERR);
|
|
540 }
|
|
541 case EXTRN: case EXTRN1: case STATIC:
|
|
542 return pexpr(cadr(e));
|
|
543 default:
|
|
544 v = new_lvar(size(n->dsp));
|
|
545 }
|
|
546 if (heap[pdisp+dsp]) error(-1);
|
|
547 heap[pdisp+dsp]=v;
|
|
548 return pexpr(cadr(e));
|
462
|
549 }
|
|
550
|
|
551 static int
|
|
552 p_if(int e)
|
|
553 {
|
464
|
554 return e;
|
462
|
555 }
|
|
556
|
|
557 static int
|
|
558 p_do(int e)
|
|
559 {
|
464
|
560 return e;
|
462
|
561 }
|
|
562
|
|
563 static int
|
|
564 p_while(int e)
|
|
565 {
|
464
|
566 return e;
|
462
|
567 }
|
|
568
|
|
569 static int
|
|
570 p_for(int e)
|
|
571 {
|
464
|
572 return e;
|
462
|
573 }
|
|
574
|
|
575 static int
|
|
576 p_switch(int e)
|
|
577 {
|
464
|
578 return e;
|
462
|
579 }
|
|
580
|
|
581 static int
|
|
582 p_comp(int e)
|
|
583 {
|
464
|
584 return e;
|
462
|
585 }
|
|
586
|
|
587 static int
|
|
588 p_break(int e)
|
|
589 {
|
464
|
590 return e;
|
462
|
591 }
|
|
592
|
|
593 static int
|
|
594 p_continue(int e)
|
|
595 {
|
464
|
596 return e;
|
462
|
597 }
|
|
598
|
|
599 static int
|
|
600 p_case(int e)
|
|
601 {
|
464
|
602 return e;
|
462
|
603 }
|
|
604
|
|
605 static int
|
|
606 p_default(int e)
|
|
607 {
|
464
|
608 return e;
|
462
|
609 }
|
|
610
|
|
611 static int
|
|
612 p_return(int e)
|
|
613 {
|
464
|
614 return e;
|
462
|
615 }
|
|
616
|
|
617 static int
|
|
618 p_goto(int e)
|
|
619 {
|
464
|
620 return e;
|
462
|
621 }
|
|
622
|
|
623 static int
|
|
624 p_asm(int e)
|
|
625 {
|
464
|
626 return e;
|
462
|
627 }
|
|
628
|
|
629 static int
|
|
630 p_label(int e)
|
|
631 {
|
464
|
632 return e;
|
462
|
633 }
|
|
634
|
|
635 static int
|
|
636 p_bool(int e)
|
|
637 {
|
464
|
638 return e;
|
|
639 }
|
462
|
640
|
464
|
641 static int
|
|
642 p_comment(int e)
|
|
643 {
|
|
644 return e;
|
462
|
645 }
|
|
646
|
463
|
647 extern int
|
|
648 pexpr(int e1)
|
462
|
649 {
|
|
650 int e2,e3;
|
|
651
|
463
|
652 // if (inmode) error(-1);
|
462
|
653 e2 = cadr(e1);
|
|
654 switch (car(e1)){
|
|
655 case GVAR: case RGVAR: case CRGVAR: case CURGVAR: case SRGVAR:
|
|
656 case SURGVAR: case REGISTER:
|
|
657 #if FLOAT_CODE
|
|
658 case DREGISTER: case FREGISTER:
|
|
659 #endif
|
|
660 #if LONGLONG_CODE
|
|
661 case LREGISTER:
|
|
662 #endif
|
|
663 case LABEL: case CONST:
|
|
664 #if FLOAT_CODE
|
|
665 case DCONST: case FCONST:
|
|
666 #endif
|
|
667 #if LONGLONG_CODE
|
|
668 case LCONST:
|
|
669 #endif
|
|
670 case STRING:
|
|
671 case FNAME:
|
|
672 case RSTRUCT:
|
|
673 return e1;
|
|
674 case LVAR:
|
|
675 case RLVAR: case CRLVAR: case CURLVAR: case SRLVAR: case SURLVAR:
|
|
676 #if FLOAT_CODE
|
|
677 case FRLVAR: case FRGVAR: case DRLVAR: case DRGVAR:
|
|
678 #endif
|
|
679 #if LONGLONG_CODE
|
|
680 case LRLVAR: case LRGVAR: case LURLVAR: case LURGVAR:
|
|
681 return p_lvar(e1);
|
|
682 #endif
|
|
683 case FUNCTION:
|
|
684 return pfunction(e1);
|
|
685 case CODE:
|
463
|
686 return list2(car(e1),pexpr(e2));
|
462
|
687 case INLINE:
|
463
|
688 return gen_inline(e1);
|
462
|
689 case INDIRECT:
|
|
690 return prindirect(e1);
|
|
691 case RINDIRECT: case URINDIRECT:
|
|
692 case CRINDIRECT: case CURINDIRECT:
|
|
693 case SRINDIRECT: case SURINDIRECT:
|
|
694 #if FLOAT_CODE
|
|
695 case FRINDIRECT: case DRINDIRECT:
|
|
696 #endif
|
|
697 #if LONGLONG_CODE
|
|
698 case LRINDIRECT: case LURINDIRECT:
|
|
699 #endif
|
|
700 return prindirect(e1);
|
|
701 case ADDRESS:
|
463
|
702 return paddress(pexpr(e2));
|
462
|
703 case MINUS:
|
463
|
704 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
705 if (car(e3)==CONST) return list2(CONST,-cadr(e3));
|
|
706 return list2(car(e1),e3);
|
|
707 #if LONGLONG_CODE
|
|
708 case LMINUS:
|
463
|
709 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
710 if (car(e3)==LCONST) return llist2(LCONST,-lcadr(e3));
|
|
711 return list2(car(e1),e3);
|
|
712 #endif
|
|
713 #if FLOAT_CODE
|
|
714 case DMINUS:
|
463
|
715 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
716 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3));
|
|
717 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3));
|
|
718 return list2(car(e1),e3);
|
|
719 case FMINUS:
|
463
|
720 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
721 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3));
|
|
722 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3));
|
|
723 return list2(car(e1),e3);
|
|
724 #endif
|
|
725 case CONV:
|
463
|
726 return p_conv(caddr(e1),pexpr(e2));
|
462
|
727 case BNOT: /* ~ */
|
463
|
728 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
729 if (car(e3)==CONST) return list2(CONST,~cadr(e3));
|
|
730 return list2(BNOT,e3);
|
|
731 case LNOT: /* ! */
|
463
|
732 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
733 if (car(e3)==CONST) return list2(CONST,!cadr(e3));
|
|
734 return list2(LNOT,e3);
|
|
735 case PREINC:
|
|
736 case UPREINC:
|
463
|
737 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
738 if (car(e3)==CONST) return list2(CONST,cadr(e3)+1);
|
|
739 return list2(car(e1),e3);
|
|
740 case POSTINC:
|
|
741 case UPOSTINC:
|
463
|
742 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
743 if (car(e3)==CONST) return e3;
|
|
744 return list2(car(e1),e3);
|
|
745 #if FLOAT_CODE
|
|
746 case DPREINC: /* ++d */
|
463
|
747 if ((e3 = pexpr(e2))==e2) return e1;
|
|
748 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2));
|
|
749 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2));
|
462
|
750 return list2(car(e1),e3);
|
|
751 case DPOSTINC: /* d++ */
|
463
|
752 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
753 if (car(e3)==FCONST||car(e3)==DCONST) return e3;
|
|
754 return list2(car(e1),e3);
|
|
755 case FPREINC: /* ++f */
|
463
|
756 if ((e3 = pexpr(e2))==e2) return e1;
|
|
757 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2));
|
|
758 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2));
|
462
|
759 return list2(car(e1),e3);
|
|
760 case FPOSTINC: /* f++ */
|
463
|
761 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
762 if (car(e3)==FCONST||car(e3)==DCONST) return e3;
|
|
763 return list2(car(e1),e3);
|
|
764 #endif
|
|
765 #if LONGLONG_CODE
|
|
766 case LPREINC: /* ++d */
|
|
767 case LUPREINC: /* ++d */
|
463
|
768 if ((e3 = pexpr(e2))==e2) return e1;
|
|
769 if (car(e3)==LCONST) return llist2(LCONST,lcadr(e3)+cadr(e2));
|
462
|
770 return list2(car(e1),e3);
|
|
771 case LPOSTINC: /* d++ */
|
|
772 case LUPOSTINC: /* d++ */
|
463
|
773 if ((e3 = pexpr(e2))==e2) return e1;
|
462
|
774 if (car(e3)==LCONST) return e3;
|
|
775 return list2(car(e1),e3);
|
|
776 #endif
|
|
777 case MUL: case UMUL:
|
|
778 case DIV: case UDIV:
|
|
779 case MOD: case UMOD:
|
|
780 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
|
|
781 case ADD: case SUB: case BAND: case EOR: case BOR: case CMP: case CMPGE:
|
|
782 case UCMP: case CMPEQ: case CMPNEQ: case UCMPGE:
|
|
783 #if FLOAT_CODE
|
|
784 case DMUL: case DDIV:
|
|
785 case DADD: case DSUB:
|
|
786 case DCMP: case DCMPGE: case DCMPEQ: case DCMPNEQ:
|
|
787 case FMUL: case FDIV:
|
|
788 case FADD: case FSUB:
|
|
789 case FCMP: case FCMPGE: case FCMPEQ: case FCMPNEQ:
|
|
790 #endif
|
|
791 #if LONGLONG_CODE
|
|
792 case LMUL: case LUMUL:
|
|
793 case LDIV: case LUDIV:
|
|
794 case LMOD: case LUMOD:
|
|
795 case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT:
|
|
796 case LADD: case LSUB: case LBAND: case LEOR: case LBOR: case LCMP:
|
|
797 #endif
|
463
|
798 e3 = pexpr(e2); e2 = pexpr(caddr(e1));
|
|
799 if (e3==cadr(e1)&&e2==caddr(e1)) return e1;
|
|
800 return pbinop(car(e1),e3,e2);
|
462
|
801 case LCOND: case DCOND: case FCOND: case COND:
|
463
|
802 e3 = pexpr(e2);
|
|
803 if (car(e3)==CONST) return pexpr(cadr(e3)?caddr(e1):cadddr(e1));
|
|
804 return list4(car(e1),e3,pexpr(cadr(e1)),pexpr(cadr(e2)));
|
462
|
805 case STASS:
|
|
806 return psassign(e1);
|
|
807 case ASS: case CASS: case SASS:
|
|
808 return passign(e1);
|
|
809 case SASSOP: case SUASSOP:
|
|
810 case ASSOP: case CASSOP: case CUASSOP:
|
|
811 return passop(e1);
|
|
812 #if FLOAT_CODE
|
|
813 case FASS: case DASS:
|
|
814 return pdassign(e1);
|
|
815 case DASSOP: case FASSOP:
|
|
816 return pdassop(e1);
|
|
817 #endif
|
|
818 #if LONGLONG_CODE
|
|
819 case LASS:
|
|
820 return plassign(e1);
|
|
821 case LASSOP: case LUASSOP:
|
|
822 return plassop(e1);
|
|
823 #endif
|
|
824 case ALLOCA:
|
463
|
825 return palloc(pexpr(e2));
|
462
|
826 case BUILTINP:
|
463
|
827 return list2(CONST,is_const(pexpr(e2)));
|
462
|
828 case COMMA:
|
463
|
829 return pcomma(pexpr(e2),pexpr(caddr(e1)));
|
462
|
830 case RETURN:
|
|
831 case ENVIRONMENT:
|
|
832 case LCALL:
|
|
833 return e1;
|
|
834 #if BIT_FIELD_CODE
|
|
835 case RBIT_FIELD:
|
|
836 return prbit_field(e1);
|
|
837 case BASS:
|
|
838 return pbassign(e1);
|
|
839 case BPREINC:
|
|
840 case BPOSTINC:
|
|
841 case BASSOP:
|
|
842 return pbassop(e1);
|
|
843 #endif
|
|
844 #if ASM_CODE
|
|
845 case ASM:
|
|
846 return list3(ASM,list4(
|
463
|
847 pexpr(car(e2)),pexpr(cadr(e2)),pexpr(caddr(e2)),pexpr(cadddr(e2))),
|
|
848 pexpr(caddr(e1)));
|
462
|
849 #endif
|
|
850 case ST_DECL: return p_decl(e1);
|
|
851 case ST_IF: return p_if(e1);
|
|
852 case ST_DO: return p_do(e1);
|
|
853 case ST_WHILE: return p_while(e1);
|
|
854 case ST_FOR: return p_for(e1);
|
|
855 case ST_SWITCH: return p_switch(e1);
|
|
856 case ST_COMP: return p_comp(e1);
|
|
857 case ST_BREAK: return p_break(e1);
|
|
858 case ST_CONTINUE: return p_continue(e1);
|
|
859 case ST_CASE: return p_case(e1);
|
|
860 case ST_DEFAULT: return p_default(e1);
|
|
861 case ST_RETURN: return p_return(e1);
|
|
862 case ST_GOTO: return p_goto(e1);
|
|
863 case ST_ASM: return p_asm(e1);
|
|
864 case ST_LABEL: return p_label(e1);
|
|
865 case ST_COMMENT: return p_comment(e1);
|
|
866 default:
|
|
867 return p_bool(e1);
|
|
868 }
|
|
869 return VOID;
|
|
870 }
|
|
871
|
463
|
872 #define round4(i) ((i+(SIZE_OF_INT-1))&~(SIZE_OF_INT-1))
|
|
873
|
|
874 extern int
|
|
875 gen_inline(int e)
|
462
|
876 {
|
463
|
877 int svartable = pvartable;
|
|
878 int sdisp = pdisp;
|
|
879 int narg,arg;
|
|
880 NMTBL *n = (NMTBL*)cadr(cadr(e));
|
|
881 int e1 = attr_value(n,INLINE);
|
|
882 int parse = car(e1);
|
|
883 int arg_disp = cadr(e1);
|
464
|
884 int e3,t;
|
463
|
885
|
|
886 pvartable = p_vartable(e,pdisp=arg_disp,caddr(e1));
|
|
887 /* inline function arguments */
|
|
888 narg = 0;
|
|
889 for (e3 = e1 = reverse0(caddr(e)); e3; e3 = cadr(e3)) {
|
|
890 t=caddr(e3);
|
464
|
891 if (is_const(e3) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) {
|
463
|
892 heap[pdisp+narg]=e3;
|
|
893 } else {
|
|
894 arg = heap[pdisp+narg]=new_lvar(size(t));
|
|
895 g_expr_u(assign_expr0(arg,e3,t,t));
|
|
896 }
|
|
897 narg += (size(t)+3)/4;
|
|
898 }
|
|
899 e = pexpr(parse);
|
|
900 pdisp = sdisp;
|
464
|
901 pvartable = svartable;
|
462
|
902 return e;
|
|
903 }
|
|
904
|
|
905 /* end */
|