Mercurial > hg > CbC > old > device
annotate mc-inline.c @ 828:d0f48d1ea798
rvalue_t separation
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 27 Nov 2010 14:14:17 +0900 |
parents | 8e7241d81f66 |
children | ff5dfee80829 |
rev | line source |
---|---|
462 | 1 /* Micro-C Partial Evaluator Part */ |
2 | |
607 | 3 /************************************************************************ |
4 ** Copyright (C) 2006 Shinji Kono | |
5 ** 連絡先: 琉球大学情報工学科 河野 真治 | |
795 | 6 *)* (E-Mail Address: kono@ie.u-ryukyu.ac.jp) |
607 | 7 ** |
8 ** このソースのいかなる複写,改変,修正も許諾します。ただし、 | |
9 ** その際には、誰が貢献したを示すこの部分を残すこと。 | |
10 ** 再配布や雑誌の付録などの問い合わせも必要ありません。 | |
11 ** 営利利用も上記に反しない範囲で許可します。 | |
12 ** バイナリの配布の際にはversion messageを保存することを条件とします。 | |
13 ** このプログラムについては特に何の保証もしない、悪しからず。 | |
14 ** | |
15 ** Everyone is permitted to do anything on this program | |
16 ** including copying, modifying, improving, | |
17 ** as long as you don't try to pretend that you wrote it. | |
18 ** i.e., the above copyright notice has to appear in all copies. | |
19 ** Binary distribution requires original version messages. | |
20 ** You don't have to ask before copying, redistribution or publishing. | |
21 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. | |
22 ***********************************************************************/ | |
625 | 23 |
24 /* | |
25 | |
26 Inline handler | |
27 | |
28 inline code is stored as parse tree | |
29 expr already has parse tree | |
30 statement part is handled here | |
31 | |
32 st_hoge() code generator (called from gexpr()) | |
33 p_hoge() partial evaluator called in gen_inline() | |
34 after p_hoge(), it contains no ST_* node. | |
35 | |
36 PVAR has an offset for pvartable, it can be | |
37 constant, local variable or global variable | |
38 other complex expression is evaluated before the code expansion | |
39 | |
40 We always perform inline expansion. | |
41 Non static inline function can be referenced from other. Real | |
42 function body is generated by pfdecl() in mc-parse.c. | |
43 | |
44 */ | |
45 | |
462 | 46 #include <stdio.h> |
47 #include "mc.h" | |
48 #include "mc-parse.h" | |
49 #include "mc-codegen.h" | |
50 #include "mc-switch.h" | |
464 | 51 #include "mc-code.h" |
52 #include "mc-inline.h" | |
462 | 53 |
463 | 54 static int pvartable; |
55 static int pdisp; | |
462 | 56 |
514 | 57 static int ret_register,ret_reg_mode; |
58 | |
527 | 59 static int inline_lvars; |
60 | |
462 | 61 /* |
62 Basic code generator from parse tree | |
63 */ | |
64 | |
65 extern void | |
66 st_decl(int e1){ | |
67 // NMTBL *n = (NMTBL *)caddr(e1); | |
68 // int stmode = cadddr(e1); | |
69 } | |
70 | |
71 extern void | |
72 st_if(int e1){ | |
73 int l1,l2,slfree; | |
74 int e2=caddr(e1),e3; | |
75 // conv->if_(); | |
76 slfree=lfree; | |
77 checkret(); | |
78 l1 = bexpr(car(e2),0,fwdlabel()); | |
79 // conv->if_then_(); | |
80 g_expr_u(cadr(e2)); | |
81 checkret(); | |
82 if ((e3=caddr(e2))) { // else | |
83 // conv->if_else_(); | |
84 if ((l2 = control)) | |
85 gen_jmp(l2=fwdlabel()); | |
86 fwddef(l1); | |
87 g_expr_u(e3); | |
88 checkret(); | |
89 if (l2) fwddef(l2); | |
90 } else { | |
91 fwddef(l1); | |
92 } | |
93 // conv->if_endif_(); | |
94 } | |
95 | |
96 | |
97 extern void | |
98 st_do(int e1){ | |
99 int sbreak,scontinue,l; | |
100 | |
101 sbreak=blabel; | |
102 scontinue=clabel; | |
103 blabel=fwdlabel(); | |
104 clabel=fwdlabel(); | |
105 control=1; | |
106 checkret(); | |
107 l=backdef(); | |
108 // conv->dowhile_(); | |
109 g_expr_u(cadddr(e1)); | |
110 checkret(); | |
111 // conv->dowhile_cond_(); | |
112 bexpr(caddr(e1),1,l); | |
113 // conv->dowhile_end_(); | |
114 fwddef(blabel); | |
115 clabel=scontinue; | |
116 blabel=sbreak; | |
117 } | |
118 | |
119 | |
120 extern void | |
121 st_while(int e1){ | |
122 int sbreak,scontinue,e; | |
123 | |
124 sbreak=blabel; | |
125 scontinue=clabel; | |
126 blabel=fwdlabel(); | |
127 control=1; | |
128 checkret(); | |
129 clabel=backdef(); | |
130 // conv->while_(); | |
131 // conv->while_body_(); | |
132 if(!(e=cadddr(e1))) { | |
133 bexpr(caddr(e1),1,clabel); | |
134 // conv->sm_(); | |
135 } else { | |
136 bexpr(caddr(e1),0,blabel); | |
137 g_expr_u(e); | |
138 checkret(); | |
139 if(control) | |
140 gen_jmp(clabel); | |
141 } | |
142 // conv->while_end_(); | |
143 fwddef(blabel); | |
144 clabel=scontinue; | |
145 blabel=sbreak; | |
146 } | |
147 | |
148 | |
149 extern void | |
150 st_for(int e1){ | |
151 int p0,p1,p2,body; | |
152 int l,e; | |
153 int sbreak=blabel; | |
154 int scontinue=clabel; | |
155 | |
156 e = caddr(e1); | |
157 p0 = car(e); p1 = cadr(e); p2 = caddr(e); body = cadddr(e); | |
158 | |
159 blabel=fwdlabel(); | |
160 // conv->for_(); | |
161 if (p0) { | |
162 checkret(); | |
163 g_expr_u(p0); | |
164 } | |
165 // conv->for1_(); | |
166 control=1; | |
167 checkret(); | |
168 l=backdef(); | |
169 if (p1) { | |
170 bexpr(p1,0,blabel); | |
171 } | |
172 // conv->for2_(); | |
173 // conv->for_body_(); | |
174 if (!p2) { | |
175 clabel=l; | |
176 g_expr_u(body); | |
177 checkret(); | |
178 } else { | |
179 clabel=fwdlabel(); | |
180 g_expr_u(body); | |
181 checkret(); | |
182 fwddef(clabel); | |
183 g_expr_u(p2); | |
184 } | |
185 // conv->for_end_(); | |
186 gen_jmp(l); | |
187 fwddef(blabel); | |
188 clabel=scontinue; | |
189 blabel=sbreak; | |
190 } | |
191 | |
192 | |
193 extern void | |
194 st_switch(int e1){ | |
195 int sbreak,scase,sdefault,slfree,svalue,slist; | |
558 | 196 int cst,e; |
462 | 197 |
198 checkret(); | |
199 slist = cslist; | |
200 cslist = 0; | |
201 sbreak=blabel; /* save parents break label */ | |
202 blabel=fwdlabel(); | |
203 sdefault=dlabel; /* save parents default label */ | |
204 dlabel=0; | |
205 scase=cslabel; /* save parents next case label */ | |
206 // conv->switch_(); | |
207 slfree=lfree; | |
208 svalue=csvalue1; /* save parents switch value */ | |
558 | 209 e =caddr(e1); /* switch value */ |
210 if (car(e)==CONST) { | |
211 cst = 1; | |
212 csvalue1=glist2(CONST,cadr(e)); | |
213 gen_jmp( cslabel=fwdlabel()); | |
214 } else { | |
215 cst = 0; | |
690 | 216 g_expr(e); /* switch value */ |
558 | 217 csvalue1=csvalue() ; |
218 cslabel = control = 0; | |
219 } | |
462 | 220 // conv->switch_body_(); |
221 g_expr_u(cadddr(e1)); | |
222 // conv->switch_end_(); | |
223 checkret(); | |
224 #if CASE_CODE | |
558 | 225 if (!cst) { |
226 if (control) gen_jmp(blabel); | |
227 genswitch(cslist,cslabel); | |
228 } else if (!cslist) { | |
648 | 229 if(dlabel) df_label(cslabel,dlabel); |
715 | 230 else { |
231 fwddef(cslabel); | |
232 } | |
233 cslist= 1; | |
558 | 234 } |
462 | 235 #else |
558 | 236 if (!(cst && cslist)) { |
648 | 237 if(dlabel) df_label(cslabel,dlabel); |
558 | 238 else fwddef(cslabel); |
239 } | |
462 | 240 #endif |
558 | 241 free_glist2(csvalue1); |
242 if (cst && !cslist) { | |
243 if(pending_jmp!=cslabel) | |
244 fwddef(cslabel); | |
245 else pending_jmp = 0; // cslabel is here | |
246 } | |
247 fwddef(blabel); | |
462 | 248 csvalue1=svalue; |
249 cslabel=scase; | |
250 dlabel=sdefault; | |
251 blabel=sbreak; | |
252 cslist = slist; | |
253 } | |
254 | |
255 | |
256 extern void | |
257 st_comp(int e1){ | |
258 g_expr_u(caddr(e1)); | |
259 } | |
260 | |
261 | |
262 extern void | |
263 st_break(int e1){ | |
264 checkret(); | |
265 // conv->break_(); | |
266 if (control) | |
267 gen_jmp(blabel); | |
268 } | |
269 | |
270 | |
271 extern void | |
272 st_continue(int e1){ | |
273 checkret(); | |
274 // conv->continue_(); | |
275 if (control) gen_jmp(clabel); | |
276 } | |
277 | |
278 | |
279 extern void | |
280 st_case(int e1){ | |
281 #if CASE_CODE | |
569 | 282 int l=0,clist=caddr(e1),c; |
558 | 283 int cst = (car(csvalue1)==CONST); |
284 if (cst) { | |
285 c=cadr(csvalue1); | |
286 for(;clist;clist=cadr(clist)) { | |
287 if (car(clist)==c) break; | |
288 } | |
289 if (!clist) return; // no match | |
290 } else | |
291 l = fwdlabel(); | |
462 | 292 if (retpending) { |
293 ret(); retpending=0; | |
294 } | |
558 | 295 if (cst) { |
296 if (cslist) { // may duplicat csvalue | |
297 return; | |
298 } | |
299 cslist=1; | |
300 fwddef(cslabel); | |
301 return; | |
302 } | |
462 | 303 if (!cslabel) { |
304 if (!control) { | |
305 cmpdimm(car(clist),csvalue1,cslabel=fwdlabel(),1); | |
306 caddr(clist)=0; | |
307 } else { | |
308 error(-1); | |
309 } | |
310 } | |
311 while(clist) { | |
312 caddr(clist) = l; | |
313 clist = cadr(c=clist); cadr(c) = 0; // insert destroy cadr of clist | |
314 cslist=insert_ascend(cslist,c,docase_eq); | |
315 } | |
316 fwddef(l); | |
317 control=1; | |
318 #else | |
558 | 319 int c,clist,l; |
320 int cst = (car(csvalue1)==CONST); | |
321 clist = caddr(e1); | |
322 if (cst) { | |
323 c=cadr(csvalue1); | |
324 for(;clist;clist=cadr(clist)) { | |
325 if (car(clist)==c) break; // no match | |
326 } | |
327 if (!clist) return; | |
328 } | |
329 if (cst) { | |
330 if (!cslist) { | |
331 if (retpending) { | |
332 ret(); retpending=0; | |
333 } | |
334 fwddef(cslabel); | |
335 cslist = 1; | |
336 } // else error(CSERR); | |
337 return; | |
338 } | |
462 | 339 if (retpending) { |
340 ret(); retpending=0; | |
341 } | |
342 l=fwdlabel(); | |
343 if (control) { | |
344 control=0; | |
345 gen_jmp(l); | |
346 } | |
347 if (cslabel) fwddef(cslabel); | |
558 | 348 while(cadr(clist)) { |
349 cmpdimm(car(clist),csvalue1,l,0); | |
350 clist=cadr(clist); | |
462 | 351 } |
558 | 352 cmpdimm(car(clist),csvalue1,cslabel=fwdlabel(),1); |
462 | 353 if (l) fwddef(l); |
354 #endif | |
355 } | |
356 | |
357 | |
358 extern void | |
359 st_default(int e1){ | |
558 | 360 // int cst = (car(csvalue1)==CONST); |
462 | 361 control=1; |
362 checkret(); | |
363 if (dlabel) error(STERR); // double default: | |
364 dlabel = backdef(); | |
365 // conv->case_(0,1); | |
366 } | |
367 | |
368 | |
369 extern void | |
370 st_return(int e1){ | |
514 | 371 int e,t; |
462 | 372 |
373 if (!cslabel) gen_jmp(cslabel = fwdlabel()); | |
374 if(!(e=caddr(e1))) { | |
513 | 375 // no return value |
462 | 376 retpending = 1; |
377 return; | |
378 } | |
551 | 379 t = type_value(cadr(fnptr->ty)); |
380 if (t>0 && (car(t)==STRUCT || car(t)==UNION)) { | |
381 // copy is included in e, pass the pointer | |
382 t = list2(POINTER,type_value(cadr(fnptr->ty))); | |
383 } | |
705 | 384 if (e) { |
385 g_expr(e); | |
386 } | |
387 if (e && t!=VOID) { | |
388 if (ret_reg_mode==0) { | |
389 // return value register is not fixed | |
390 ret_reg_mode=1; | |
391 ret_register = code_get_fixed_creg(USE_CREG,t); | |
392 } else { | |
393 code_set_fixed_creg(ret_register,1,t); | |
394 } | |
462 | 395 } |
396 // conv->return_end_(); | |
397 retpending = 1; | |
398 } | |
399 | |
400 extern void | |
401 st_goto(int e){ | |
696 | 402 int e1; |
462 | 403 |
404 checkret(); | |
405 e1 = caddr(e); | |
406 if (car(e1)==RINDIRECT) { | |
407 gen_indirect_goto(cadr(e1)); | |
505 | 408 return ; |
552 | 409 } else if (car(e1)==RLVAR) { |
551 | 410 gen_indirect_goto(e1); |
411 return ; | |
552 | 412 } else if (car(e1)==LVAR||car(e1)==FLABEL) { |
551 | 413 gen_jmp(cadr(e1)); |
462 | 414 control=0; |
505 | 415 return ; |
691 | 416 } else if (car(e1)==JUMP) { |
462 | 417 /* CbC continuation */ |
418 // conv->jump_(env); | |
551 | 419 // should be separate function |
696 | 420 jump(cadr(e1),caddr(e1)); |
462 | 421 control=0; |
422 // conv->sm_(); | |
505 | 423 return ; |
551 | 424 } else { |
425 error(-1); | |
462 | 426 } |
427 } | |
428 | |
429 | |
430 #if ASM_CODE | |
431 extern void | |
432 st_asm(int e1){ | |
433 checkret(); | |
434 g_expr_u(list3(ASM,caddr(e1),cadddr(e1))); | |
435 } | |
436 #endif | |
437 | |
438 | |
439 extern void | |
440 st_label(int e1){ | |
551 | 441 int lb = caddr(e1); |
462 | 442 control=1; |
443 checkret(); | |
551 | 444 if (car(lb)==LVAR) { // label variable case |
445 } else if (car(lb)!=FLABEL) error(-1); | |
446 fwddef(cadr(lb)); | |
462 | 447 } |
448 | |
690 | 449 static |
450 char *plinebuf; // last comment in parse tree (for compiler debug) | |
451 | |
713 | 452 static int plineno; |
453 | |
462 | 454 extern void |
455 st_comment(int e1){ | |
574 | 456 glineno++; |
585 | 457 printf("## %d ",glineno); |
713 | 458 plineno = caddr(e1); |
459 gen_comment(plinebuf=(char *)ncadddr(e1)); | |
462 | 460 } |
461 | |
462 /* | |
463 partial evaluator | |
464 */ | |
465 | |
466 static int | |
557 | 467 p_vartable(int adisp,int ldisp) |
462 | 468 { |
464 | 469 int i; |
505 | 470 int pvartable = getfree(adisp-ldisp); // have to be local heap |
509 | 471 pdisp = pvartable-ldisp; |
472 for(i=ldisp;i<0;i++) { | |
473 heap[pdisp+i] = 0; | |
463 | 474 } |
505 | 475 return pvartable; |
462 | 476 } |
477 | |
795 | 478 extern int |
462 | 479 p_lvar(int e1) |
480 { | |
463 | 481 int sz = is_memory(e1); |
482 int d = cadr(e1); | |
527 | 483 int d1,e; |
502 | 484 if ((d1=(heap[pdisp+d]))) return d1; |
574 | 485 fprintf(stderr,"## undeclared ivar %d\n",d); |
795 | 486 error(-1); |
527 | 487 e = heap[pdisp+d]=list3(LVAR,new_lvar(sz),0); |
488 inline_lvars = glist2(e,inline_lvars); | |
489 return e; | |
462 | 490 } |
491 | |
492 static int | |
493 pfunction(int e) | |
494 { | |
501 | 495 // list4(INLINE,e1,arglist,ftype); |
496 // include code segement case | |
497 int e1 = pexpr(cadr(e)); | |
498 int arglist = caddr(e); | |
499 int newargs = 0; | |
500 int ftype = cadddr(e); | |
501 int e3; | |
502 for (e3 = arglist; e3; e3 = cadr(e3)) { | |
514 | 503 newargs = list3( pexpr(car(e3)), newargs, caddr(e3)); |
501 | 504 } |
505 newargs = reverse0(newargs); | |
513 | 506 return list4(car(e),e1,newargs,ftype); |
462 | 507 } |
508 | |
509 static int | |
510 prindirect(int e) | |
511 { | |
818
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
512 #if 0 |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
513 int offset = caddr(e); |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
514 int e1 = pexpr(cadr(e)); |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
515 e1 = binop(ADD,e1,list2(CONST,offset),list2(POINTER,type),INT); |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
516 type = cadddr(e); |
819
dc8df3977c17
lvar offset in prindirect
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
818
diff
changeset
|
517 if (car(e1)==LVAR) return rvalue(e1); |
dc8df3977c17
lvar offset in prindirect
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
818
diff
changeset
|
518 if (OP(car(e1))==REGISTER && car(cadr(e))==IVAR) return rvalue(e1); |
dc8df3977c17
lvar offset in prindirect
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
818
diff
changeset
|
519 return list3(car(e),e1,0); |
818
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
520 #else |
525 | 521 int lvar; |
533 | 522 int offset = caddr(e); |
690 | 523 int type0; |
819
dc8df3977c17
lvar offset in prindirect
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
818
diff
changeset
|
524 if (offset!=0) error(-1); |
690 | 525 type = cadddr(e); |
526 type0 = type_value(type); | |
527 if (type0>0 && car(type0)==POINTER) | |
528 type=set_type_with_attr(cadr(type),type); | |
530 | 529 if (car(lvar=cadr(e))==IVAR) { |
818
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
530 lvar=p_lvar(cadr(e)); // can be anything.... |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
531 switch(car(lvar)) { |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
532 case LVAR: |
828 | 533 type = cadddr(e); |
534 return rvalue(lvar); | |
818
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
535 case REGISTER: case DREGISTER: |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
536 case FREGISTER: case LREGISTER: |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
537 case CONST: case FCONST: case DCONST: case LCONST: |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
538 // should do type check |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
539 if (offset) error(-1); |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
540 return lvar; |
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
541 } |
819
dc8df3977c17
lvar offset in prindirect
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
818
diff
changeset
|
542 } |
533 | 543 return list3(car(e),pexpr(cadr(e)),offset); |
818
c59753132812
remove rvalue_t from CONV
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
801
diff
changeset
|
544 #endif |
462 | 545 } |
546 | |
547 static int | |
527 | 548 pindirect(int e) |
549 { | |
553 | 550 //int lvar; |
551 //if (car(lvar=cadr(e))==IVAR) | |
552 // lvar=p_lvar(cadr(e)); // can be anything.... | |
527 | 553 return list3(car(e),pexpr(cadr(e)),caddr(e)); |
554 } | |
555 | |
556 static int | |
462 | 557 paddress(int e) |
558 { | |
601 | 559 // if (car(cadr(e))==INDIRECT) return pexpr(cadr(cadr(e))); |
501 | 560 return list2(car(e),pexpr(cadr(e))); |
462 | 561 } |
562 | |
563 static int | |
464 | 564 p_conv(int e1,int e2) |
462 | 565 { |
690 | 566 int t,stype = type; |
557 | 567 if (is_const(e2) && (t=type_of_conv(e1))) { |
690 | 568 type = INT; |
569 e1 = correct_type(e2,t); | |
570 type = stype; | |
571 return e1; | |
557 | 572 } |
527 | 573 return list3(CONV,pexpr(e2),e1); |
462 | 574 } |
575 | |
576 static int | |
464 | 577 pbinop(int op,int e1,int e2) |
462 | 578 { |
557 | 579 e1 = pexpr(e1); |
580 e2 = pexpr(e2); | |
819
dc8df3977c17
lvar offset in prindirect
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
818
diff
changeset
|
581 if (is_const(e1)||is_const(e2)) { |
557 | 582 int t; |
583 if((t= type_of_bop(op))) | |
599 | 584 return binop(OP(op),e1,e2,t,t); |
557 | 585 } |
586 return list3(op,e1,e2); | |
502 | 587 } |
588 | |
589 static int | |
526 | 590 plor(int op,int e1,int e2) |
591 { | |
555 | 592 int e = pexpr(e1); |
593 return list3(op,e,pexpr(e2)); | |
526 | 594 } |
595 | |
596 static int | |
597 pland(int op,int e1,int e2) | |
598 { | |
555 | 599 int e = pexpr(e1); |
600 return list3(op,e,pexpr(e2)); | |
526 | 601 } |
602 | |
603 static int | |
462 | 604 psassign(int e) |
605 { | |
555 | 606 int e1 = pexpr(cadr(e)); |
607 int e2 = pexpr(caddr(e)); | |
608 return list4(car(e),e1,e2,cadddr(e)); | |
462 | 609 } |
610 | |
611 static int | |
612 passign(int e) | |
613 { | |
555 | 614 int e1 = pexpr(cadr(e)); |
615 int e2 = pexpr(caddr(e)); | |
616 return list3(car(e),e1,e2); | |
462 | 617 } |
618 | |
619 static int | |
620 passop(int e) | |
621 { | |
555 | 622 int e1 = pexpr(cadr(e)); |
623 int e2 = pexpr(caddr(e)); | |
624 return list4(car(e),e1,e2,cadddr(e)); | |
462 | 625 } |
626 | |
627 static int | |
628 pdassign(int e) | |
629 { | |
555 | 630 int e1 = pexpr(cadr(e)); |
631 int e2 = pexpr(caddr(e)); | |
632 return list3(car(e),e1,e2); | |
462 | 633 } |
634 | |
635 static int | |
636 pdassop(int e) | |
637 { | |
555 | 638 int e1 = pexpr(cadr(e)); |
639 int e2 = pexpr(caddr(e)); | |
640 return list4(car(e),e1,e2,cadddr(e)); | |
462 | 641 } |
642 | |
643 static int | |
644 plassign(int e) | |
645 { | |
555 | 646 int e1 = pexpr(cadr(e)); |
647 int e2 = pexpr(caddr(e)); | |
648 return list3(car(e),e1,e2); | |
462 | 649 } |
650 | |
651 static int | |
652 plassop(int e) | |
653 { | |
555 | 654 int e1 = pexpr(cadr(e)); |
655 int e2 = pexpr(caddr(e)); | |
656 return list4(car(e),e1,e2,cadddr(e)); | |
462 | 657 } |
658 | |
659 static int | |
660 palloc(int e) | |
661 { | |
695 | 662 int e1 = pexpr(e); |
663 if (car(e1)==CONST) | |
664 return list2(ADDRESS,list3(LVAR,new_lvar_align(cadr(e1),16),0)); | |
665 return list2(ALLOCA,e1); | |
462 | 666 } |
667 | |
668 static int | |
464 | 669 pcomma(int e1,int e2) |
462 | 670 { |
556 | 671 int e = pexpr(e1); |
555 | 672 return list3(COMMA,e,pexpr(e2)); |
462 | 673 } |
674 | |
675 static int | |
676 prbit_field(int e) | |
677 { | |
822
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
678 int e1 = list3(car(e),pexpr(cadr(e)),caddr(e)); |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
679 type = cadr(caddr(e)); // value type |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
680 return e1; |
462 | 681 } |
682 | |
683 static int | |
684 pbassign(int e) | |
685 { | |
553 | 686 // list4(BASS,e1,e2,list2(BASS,t))); |
687 int e1=pexpr(caddr(e)); | |
688 return list4(car(e),pexpr(cadr(e)),e1,cadddr(e)); | |
462 | 689 } |
690 | |
691 static int | |
692 pbassop(int e) | |
693 { | |
695 | 694 int e1 = caddr(e); |
695 if (car(e)==BASSOP) e1=pexpr(e1); | |
553 | 696 return list4(car(e),pexpr(cadr(e)),e1,cadddr(e)); |
462 | 697 } |
698 | |
681 | 699 /* |
700 variable initialization with offset | |
701 */ | |
702 | |
703 static int | |
704 passign_data(int var,int target_type, int e,int t,int offset) | |
705 { | |
706 int ass,sz,bfd; | |
707 | |
708 #if STRUCT_ALIGN | |
786
3ebbec5a72dc
i64 strinit inlined struct init does not zero fill
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
785
diff
changeset
|
709 if (t!=EMPTY) { |
681 | 710 int strtype=0; |
711 if (t>0 && (car(t)==STRUCT||car(t)==UNION)) | |
712 strtype=1; | |
713 sz = size(t); | |
794
032dc03be02e
i64 arg_register in inline mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
788
diff
changeset
|
714 if (lp64 && (sz%size_of_longlong==0||strtype)) { |
032dc03be02e
i64 arg_register in inline mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
788
diff
changeset
|
715 offset = align(offset,size_of_longlong); |
032dc03be02e
i64 arg_register in inline mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
788
diff
changeset
|
716 } else if (sz%size_of_int==0||strtype) { |
032dc03be02e
i64 arg_register in inline mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
788
diff
changeset
|
717 offset = align(offset,size_of_int); |
681 | 718 } |
719 } | |
720 #endif | |
721 if (car(e)==ADDRESS||car(e)==GVAR) { | |
702 | 722 if (scalar(t)) { |
681 | 723 t = list2(POINTER,VOID); // fake |
702 | 724 } else if (t>0 && car(t)==ARRAY) { |
681 | 725 } else { |
726 error(TYERR); | |
727 } | |
728 } | |
729 if (t==EMPTY) { | |
730 /* empty space in partial initialization */ | |
731 return offset+cadr(e); | |
732 } | |
733 type = t; | |
702 | 734 // e = rvalue_t(e,t); |
681 | 735 if (!scalar(type) && (type>0 && (car(type)!=ADDRESS && car(type)!=ARRAY))) |
736 e = correct_type(e,target_type); | |
737 /* If this is a local declared constant, we don't have to assign. | |
738 But some one may take it's address. We have to generate assign. | |
739 */ | |
740 ass = assign_expr0( | |
741 offset? | |
770
b674d8421430
i64 inline ( indirect call )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
767
diff
changeset
|
742 lp64?list3(LADD,var,llist2(LCONST,offset)): // binop? |
b674d8421430
i64 inline ( indirect call )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
767
diff
changeset
|
743 list3(ADD,var,list2(CONST,offset)): |
681 | 744 var, |
745 e,target_type,t); // already correct_typed | |
746 init_vars = list2(ass,init_vars); | |
747 if (t>0&&car(t)==BIT_FIELD) { | |
748 sz = 0; | |
749 bfd = cadr(caddr(t)); /* bit_field_disp */ | |
750 #if BIT_FIELD_CODE | |
751 code_bit_field_disp(t,&offset,&bfd,&sz); | |
752 #endif | |
753 return offset+sz; | |
754 } | |
785 | 755 return offset+size(target_type); |
681 | 756 } |
757 | |
758 static int pdecl_data(int var, int target_type, int init,int offset); | |
759 | |
760 static void | |
761 pflush_decl_data(int var,int sz) | |
762 { | |
763 int offset; | |
764 int offset0=0; | |
765 int e; | |
766 int t,offset1=0; | |
767 int smode=mode; | |
768 int init = decl_str_init; | |
769 | |
770 decl_str_init = 0; | |
771 mode = STADECL; | |
772 /* | |
773 decl_str_init | |
774 output delayed decl data | |
775 list4(offset,next,expression,list2(type0,type1)); | |
776 */ | |
777 while (init) { | |
778 offset= car(init); | |
779 e=caddr(init); | |
780 t=car(cadddr(init)); // type of source | |
781 type=cadr(cadddr(init)); // destination type | |
782 if (offset!=offset0) { | |
783 // make space | |
784 passign_data(var,EMPTY,list2(CONST,offset-offset0),EMPTY,offset0); | |
785 } | |
786 e = pexpr(e); | |
787 // offset0 = passign_data(var,type,e,t,offset); | |
788 offset0 = pdecl_data(var,type,e,offset); | |
789 init = cadr(init); | |
790 } | |
791 offset = offset0; | |
792 if ((sz=(offset1+sz-offset))>0) | |
793 passign_data(var,EMPTY,list2(CONST,sz),EMPTY,offset0); | |
794 local_nptr = 0; | |
795 mode=smode; | |
796 } | |
797 | |
798 static int | |
799 str_init_eq() | |
800 { | |
801 // error(-1); // duplicate struct field value | |
802 return 2; // allow override keep unique | |
803 } | |
804 | |
805 | |
806 static int | |
807 pdecl_data_array(int var,int init,int target_type,int offset) | |
808 { | |
809 int type0 = cadr(target_type); /* array item type */ | |
810 int e; | |
811 | |
812 for(; init; init = cadr(init)) { | |
813 // unordered data with tag or array offset | |
814 if (car(init)!=DECL_DATA_ARRAY) { | |
815 error(-1); | |
816 } | |
817 e = pexpr(caddr(init)); | |
818 offset = pdecl_data(var,type0,e,offset); | |
819 } | |
820 return offset; | |
821 } | |
822 | |
788 | 823 #if 0 |
824 static void | |
825 pzfill(int var, int offset, int sz) | |
826 { | |
827 int c0 = list2(CONST,0); | |
828 int l0 = llist2(LCONST,0L); | |
829 while(sz>0) { | |
830 int t,c; | |
831 switch(sz) { | |
832 case 1: t = UCHAR; c = c0; break; | |
833 case 2: t = USHORT; c = c0; break; | |
834 case 4: t = UNSIGNED; c = c0; break; | |
835 default: t = ULONGLONG; c = l0; break; | |
836 } | |
837 int ass = assign_expr0( | |
838 offset? | |
839 lp64?list3(LADD,var,llist2(LCONST,offset)): // binop? | |
840 list3(ADD,var,list2(CONST,offset)): | |
841 var, | |
842 c ,t,t); // already correct_typed | |
843 init_vars = list2(ass,init_vars); | |
844 sz -= size(t); | |
845 offset += size(t); | |
846 } | |
847 } | |
848 #endif | |
849 | |
681 | 850 static int |
851 pdecl_data_field(int var,int init,int target_type,int offset) | |
852 { | |
853 int type0 = target_type; /* list of fields */ | |
854 int e,t,type1,foffset; | |
855 NMTBL *n; | |
856 | |
857 for(; init; init = cadr(init)) { | |
858 // unordered data with tag or array offset | |
859 if (car(init)!=DECL_DATA_FIELD) { | |
860 error(-1); | |
861 } | |
711 | 862 n = ncadddr(init); |
681 | 863 type1 = search_struct_type(type0,n->nm,&foffset); |
864 e = caddr(init); | |
865 if (car(e)!=DECL_DATA) error(-1); | |
866 t = caddr(e); | |
867 decl_str_init=insert_ascend(decl_str_init, | |
868 glist4(offset+foffset,0,e,glist2(type1,t)),str_init_eq); | |
869 } | |
870 return offset; | |
871 } | |
872 | |
873 static int | |
874 pdecl_data_list(int var,int init,int target_type,int offset) | |
875 { | |
876 int type0 = caddr(target_type); /* list of fields */ | |
877 int e; | |
878 | |
703 | 879 for(; init; init = cadr(init),type0 = cadr(type0)) { |
880 if (car(init)==DECL_DATA) { | |
692 | 881 // casted initilizer ? |
703 | 882 //error(-1); |
883 e = cadr(init); // value | |
884 if (!e) continue; // {...,} case | |
885 e = pexpr(e); | |
886 offset = pdecl_data(var,caddr(init),e,offset); | |
692 | 887 continue; |
888 } | |
681 | 889 // ordered data |
703 | 890 if (car(init)!=DECL_DATA_LIST) { |
681 | 891 error(-1); |
892 } | |
703 | 893 e = caddr(init); |
894 if (!e) continue; // {...,} case | |
895 e = pexpr(e); | |
681 | 896 offset = pdecl_data(var,car(type0),e,offset); |
897 } | |
898 return offset; | |
899 } | |
900 | |
901 static int | |
902 pdecl_data(int var, int target_type, int init,int offset) | |
903 { | |
904 int t,e; | |
905 int save_decl_str_init = decl_str_init; | |
906 decl_str_init = 0; | |
907 target_type = type_value(target_type); | |
908 | |
692 | 909 if (init==0) { |
910 // empty declaration | |
911 // it can happen like a = (struct hoge){}; | |
912 return offset; | |
913 } | |
682 | 914 e = cadr(init); |
681 | 915 if (car(init)==DECL_DATA) { |
682 | 916 switch(car(e)) { |
681 | 917 case DECL_DATA_LIST: |
918 offset = pdecl_data_list(var,e,target_type,offset); | |
919 break; | |
920 case DECL_DATA_FIELD: | |
921 offset = pdecl_data_field(var,e,target_type,offset); | |
922 break; | |
923 case DECL_DATA_ARRAY: | |
924 offset = pdecl_data_array(var,e,target_type,offset); | |
925 break; | |
926 default: | |
927 e = pexpr(e); | |
928 t = caddr(init); // type of source | |
929 offset = passign_data(var,target_type,e,t,offset); | |
930 } | |
931 } else { | |
932 error(-1); | |
933 } | |
934 if (decl_str_init) { | |
935 int sz = size(target_type); | |
936 pflush_decl_data(var,sz); | |
937 } | |
938 decl_str_init = save_decl_str_init; | |
939 return offset; | |
940 } | |
941 | |
561 | 942 // handle local variable declaration |
681 | 943 // initialization is accumrated in init argument |
561 | 944 // should consider int k=some_compile_time_constant; |
462 | 945 static int |
946 p_decl(int e) | |
947 { | |
681 | 948 // list4(ST_DECL,parse,(int)n,list3(mode,stmode,ctmode),init); |
712 | 949 int ctmode=caddr(e); |
950 NMTBL *n=ncaddddr(e); | |
463 | 951 int dsp = n->dsp; |
569 | 952 int v=0; |
552 | 953 int sstmode = stmode; |
954 int smode = mode; | |
681 | 955 int save_init_vars = init_vars; |
712 | 956 int init = cadddr(e); // variable initialization |
681 | 957 |
958 init_vars = 0; | |
500 | 959 // in real partial evaluation, we have to check whether this variable |
960 // is used or not. | |
552 | 961 if (ctmode) { |
962 mode = car(ctmode); stmode = cadr(ctmode); ctmode = caddr(ctmode); | |
574 | 963 } else { |
964 mode = LDECL; stmode = 0; ctmode = 0; | |
552 | 965 } |
463 | 966 switch(stmode) { |
528 | 967 case EXTRN: case EXTRN1: case STATIC: |
552 | 968 // def(n,ctmode); we don't need this. already done. |
969 // stmode = sstmode; | |
681 | 970 if (init) error(-1); |
552 | 971 stmode = sstmode; |
972 mode = smode; | |
681 | 973 init_vars = save_init_vars; |
552 | 974 return pexpr(cadr(e)); |
529 | 975 #if 1 |
463 | 976 case REGISTER: |
977 switch(n->ty) { | |
978 case ULONGLONG: case LONGLONG: | |
979 v = get_lregister_var(n); break; | |
980 case FLOAT: | |
981 v = get_dregister_var(n,0); break; | |
982 case DOUBLE: | |
983 v = get_dregister_var(n,1); break; | |
984 default: | |
985 if (scalar(n->ty)) | |
524 | 986 v = get_register_var(n); |
463 | 987 else |
988 error(TYERR); | |
989 } | |
529 | 990 break; |
528 | 991 #endif |
701 | 992 // case LLDECL: LLDECL is mode, not stmode (bad design) |
993 // v = list2(FLABEL,fwdlabel()); break; | |
463 | 994 default: |
701 | 995 if (mode==STADECL) { |
996 if (init) { | |
711 | 997 v = list3n(GVAR,0,n); |
701 | 998 gen_decl_data(init,v); |
999 } | |
1000 stmode = sstmode; | |
1001 mode = smode; | |
1002 init_vars = save_init_vars; | |
1003 return pexpr(cadr(e)); | |
1004 } | |
552 | 1005 if (n->sc==FLABEL) |
711 | 1006 v = list3n(LVAR,fwdlabel(),n); |
801 | 1007 else { |
1008 NMTBL tn; | |
1009 tn = *n; | |
1010 code_lvar_alignment(disp,&tn,n->ty,size(n->ty)); | |
1011 v = list3n(LVAR,tn.dsp,n); | |
1012 } | |
463 | 1013 } |
552 | 1014 if (n->sc!=FLABEL) |
1015 inline_lvars = glist2(v,inline_lvars); | |
574 | 1016 if (heap[pdisp+dsp]) { |
712 | 1017 fprintf(stderr,"## double p_decl %s %s\n",(ncaddr(heap[pdisp+dsp]))->nm,n->nm); |
574 | 1018 error(-1); |
1019 } | |
463 | 1020 heap[pdisp+dsp]=v; |
552 | 1021 stmode = sstmode; |
1022 mode = smode; | |
681 | 1023 if (init) { |
1024 pdecl_data(v,n->ty,init,0); | |
1025 if (init_vars) { | |
1026 int e1 = pexpr(cadr(e)); | |
1027 init_vars = reverse0(init_vars); | |
1028 while (init_vars) { | |
1029 e1 = list3(ST_COMP,e1,car(init_vars)); | |
1030 init_vars = cadr(init_vars); | |
1031 } | |
1032 init_vars = save_init_vars; | |
1033 return e1; | |
1034 } | |
1035 } | |
1036 init_vars = save_init_vars; | |
463 | 1037 return pexpr(cadr(e)); |
462 | 1038 } |
1039 | |
1040 static int | |
500 | 1041 p_if(int e1) |
462 | 1042 { |
500 | 1043 int cond,l1,l2; |
1044 int e2=caddr(e1),e3; | |
1045 cond = pexpr(car(e2)); | |
1046 // conv->if_then_(); | |
1047 l1 = pexpr(cadr(e2)); | |
1048 if ((e3=caddr(e2))) { // else | |
1049 l2 = pexpr(e3); | |
1050 } else { | |
1051 l2 = 0; | |
1052 } | |
1053 return list3(ST_IF,pexpr(cadr(e1)),list3(cond,l1,l2)); | |
462 | 1054 } |
1055 | |
1056 static int | |
1057 p_do(int e) | |
1058 { | |
524 | 1059 int e2 = pexpr(caddr(e)); |
1060 int e3 = pexpr(cadddr(e)); | |
1061 return list4(ST_DO,pexpr(cadr(e)),e2,e3); | |
462 | 1062 } |
1063 | |
1064 static int | |
1065 p_while(int e) | |
1066 { | |
524 | 1067 int e2 = pexpr(caddr(e)); |
1068 int e3 = pexpr(cadddr(e)); | |
1069 return list4(ST_WHILE,pexpr(cadr(e)),e2,e3); | |
462 | 1070 } |
1071 | |
1072 static int | |
1073 p_for(int e) | |
1074 { | |
501 | 1075 int e1=caddr(e); |
524 | 1076 int p0=pexpr(car(e1)); |
1077 int p1=pexpr(cadr(e1)); | |
1078 int p2=pexpr(caddr(e1)); | |
1079 int p3=pexpr(cadddr(e1)); | |
625 | 1080 // unfolding for constant case? |
524 | 1081 return list3(ST_FOR,pexpr(cadr(e)), list4(p0,p1,p2,p3)); |
462 | 1082 } |
1083 | |
1084 static int | |
1085 p_switch(int e) | |
1086 { | |
690 | 1087 int e2 = pexpr(caddr(e)); // switch variable |
1088 int e3 = pexpr(cadddr(e)); // a statement in switch | |
625 | 1089 // if cadr(e) is a constant, we have to prune case statement. |
690 | 1090 // No we cannot. A statement in case may contain labels or |
1091 // falling down entry. | |
1092 // case constants are need to be pexpred in p_case. | |
1093 | |
524 | 1094 return list4(ST_SWITCH,pexpr(cadr(e)),e2,e3); |
462 | 1095 } |
1096 | |
1097 static int | |
1098 p_comp(int e) | |
1099 { | |
690 | 1100 int e1; |
1101 e1=pexpr(caddr(e)); | |
524 | 1102 return list3(ST_COMP,pexpr(cadr(e)),e1); |
462 | 1103 } |
1104 | |
1105 static int | |
1106 p_break(int e) | |
1107 { | |
502 | 1108 return list2(ST_BREAK,pexpr(cadr(e))); |
462 | 1109 } |
1110 | |
1111 static int | |
1112 p_continue(int e) | |
1113 { | |
502 | 1114 return list2(ST_CONTINUE,pexpr(cadr(e))); |
462 | 1115 } |
1116 | |
1117 static int | |
1118 p_case(int e) | |
1119 { | |
506 | 1120 int new=0,clist = caddr(e); |
1121 // insert destory clist, we have to copy it now | |
690 | 1122 // car(clist) have to be expred, it may contain operators. |
506 | 1123 for(;clist;clist=cadr(clist)) |
713 | 1124 // new=glist3(cexpr(pexpr(car(clist))),new,0); |
1125 new=glist3(car(clist),new,0); | |
506 | 1126 return list3(ST_CASE,pexpr(cadr(e)),reverse0(new)); |
462 | 1127 } |
1128 | |
1129 static int | |
1130 p_default(int e) | |
1131 { | |
625 | 1132 // should be removed if case value is a constant |
502 | 1133 return list2(ST_DEFAULT,pexpr(cadr(e))); |
462 | 1134 } |
1135 | |
1136 static int | |
1137 p_return(int e) | |
1138 { | |
524 | 1139 int e1=pexpr(caddr(e)); |
1140 return list3(ST_RETURN,pexpr(cadr(e)),e1); | |
462 | 1141 } |
1142 | |
1143 static int | |
1144 p_goto(int e) | |
1145 { | |
555 | 1146 int e1,lb,e2; |
501 | 1147 if ((e1=caddr(e))) { |
1148 switch(car(e1)) { | |
1149 case RINDIRECT: e1=pexpr(e1); break; | |
555 | 1150 case CODE: e2=pexpr(cadr(e1)); |
609 | 1151 e1=list3(JUMP,e2,pexpr(caddr(e1))); break; |
551 | 1152 case FLABEL: /* error(-1); */ break; |
1153 case IVAR: | |
1154 lb = cadr(e1); | |
1155 if (!(e1=heap[pdisp+lb])) { | |
1156 e1 = heap[pdisp+lb]=list2(FLABEL,fwdlabel()); | |
1157 } | |
691 | 1158 break; |
1159 case JUMP: | |
1160 e1 = list3(JUMP,pexpr(cadr(e1)),pexpr(caddr(e1))); | |
1161 break; | |
1162 default: | |
1163 error(-1); | |
501 | 1164 } |
1165 } | |
502 | 1166 return list3(ST_GOTO,pexpr(cadr(e)),e1); |
501 | 1167 } |
1168 | |
1169 static int | |
1170 p_list_expr(int e) | |
1171 { | |
1172 int e3,new = 0; | |
1173 for (e3 = e; e3; e3 = cadr(e3)) { | |
1174 new= list2( pexpr(car(e3)), new); | |
1175 } | |
1176 return reverse0(new); | |
462 | 1177 } |
1178 | |
1179 static int | |
1180 p_asm(int e) | |
1181 { | |
501 | 1182 int param=caddr(e); |
1183 int e1 = p_list_expr(cadddr(e)); | |
1184 return list4(ST_ASM,pexpr(cadr(e)),param,e1); | |
462 | 1185 } |
1186 | |
1187 static int | |
1188 p_label(int e) | |
1189 { | |
551 | 1190 int e1,lb; |
1191 if ((e1=caddr(e))) { | |
1192 switch(car(e1)) { | |
1193 case FLABEL: /* error(-1); */ break; | |
1194 case IVAR: | |
1195 lb = cadr(e1); | |
1196 if (!(e1=heap[pdisp+lb])) { | |
1197 e1 = heap[pdisp+lb]=list2(FLABEL,fwdlabel()); | |
1198 } | |
1199 } | |
1200 } | |
1201 return list3(ST_LABEL,pexpr(cadr(e)),e1); | |
1202 } | |
1203 | |
1204 static int | |
1205 p_label_var(int e) | |
1206 { | |
1207 int d,e1; | |
1208 switch(car(e1=e)) { | |
1209 case LVAR: /* error(-1) */ break; | |
1210 case IVAR: | |
1211 // should this done in p_decl? (in __label__?) | |
1212 d = cadr(e); | |
1213 if (!(e1=(heap[pdisp+d]))) { | |
552 | 1214 // error(-1); |
551 | 1215 e1 = heap[pdisp+d]=list3(LVAR,fwdlabel(),caddr(e)); |
1216 } | |
1217 } | |
1218 return list2(LABEL,e1); | |
462 | 1219 } |
1220 | |
1221 static int | |
1222 p_bool(int e) | |
1223 { | |
501 | 1224 error(-1); |
464 | 1225 return e; |
1226 } | |
462 | 1227 |
464 | 1228 static int |
1229 p_comment(int e) | |
1230 { | |
574 | 1231 glineno++; |
713 | 1232 plineno = caddr(e); |
1233 return list4n(ST_COMMENT,pexpr(cadr(e)),caddr(e),ncadddr(e)); | |
462 | 1234 } |
1235 | |
508 | 1236 static int |
512 | 1237 p_inline(int e) |
508 | 1238 { |
1239 int e3; | |
1240 int narg; | |
1241 | |
1242 /* inline function arguments */ | |
1243 narg = 0; | |
1244 for (e3 = caddr(e); e3; e3 = cadr(e3)) { | |
1245 narg=list3(pexpr(car(e3)),narg,caddr(e3)); | |
1246 } | |
1247 return list4(INLINE,cadr(e),reverse0(narg),cadddr(e)); | |
1248 } | |
1249 | |
463 | 1250 extern int |
1251 pexpr(int e1) | |
462 | 1252 { |
1253 int e2,e3; | |
1254 | |
463 | 1255 // if (inmode) error(-1); |
502 | 1256 if (e1==0) return 0; |
462 | 1257 e2 = cadr(e1); |
1258 switch (car(e1)){ | |
1259 case GVAR: case RGVAR: case CRGVAR: case CURGVAR: case SRGVAR: | |
788 | 1260 case URGVAR: |
462 | 1261 case SURGVAR: case REGISTER: |
1262 case DREGISTER: case FREGISTER: | |
500 | 1263 case FRGVAR: case DRGVAR: |
462 | 1264 case LREGISTER: |
500 | 1265 case LRGVAR: case LURGVAR: |
551 | 1266 case CONST: |
462 | 1267 case DCONST: case FCONST: |
1268 case LCONST: | |
1269 case STRING: | |
778
a177c65f3e37
large string (STRINGS)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
770
diff
changeset
|
1270 case STRINGS: |
462 | 1271 case FNAME: |
503 | 1272 case FLABEL: |
616 | 1273 case BUILTIN_INF: |
1274 case BUILTIN_INFF: | |
1275 case BUILTIN_INFL: | |
462 | 1276 return e1; |
551 | 1277 case RSTRUCT: |
1278 // list3(RSTRUCT,e,size) | |
1279 return pexpr(e2); | |
1280 case LABEL: | |
1281 return p_label_var(e2); | |
462 | 1282 case LVAR: |
1283 case RLVAR: case CRLVAR: case CURLVAR: case SRLVAR: case SURLVAR: | |
500 | 1284 case FRLVAR: case DRLVAR: |
1285 case LRLVAR: case LURLVAR: | |
1286 return e1; | |
1287 case IVAR: | |
462 | 1288 return p_lvar(e1); |
696 | 1289 case CODE: |
462 | 1290 case FUNCTION: |
1291 return pfunction(e1); | |
609 | 1292 case JUMP: |
601 | 1293 e2 = pexpr(e2); |
574 | 1294 return list3(car(e1),e2,pexpr(cadddr(e1))); |
601 | 1295 case ARRAY: |
1296 e2 = pexpr(e2); | |
1297 e1 = binop(ADD,e2,pexpr(caddr(e1)),cadddr(e1),caddddr(e1)); | |
1298 return indop(e1); | |
1299 case PERIOD: | |
1300 e2 = pexpr(e2); | |
711 | 1301 nptr = ncadddr(e1); |
1302 type = caddr(e1); | |
601 | 1303 return strop(e2,0); |
1304 case ARROW: | |
1305 e2 = pexpr(e2); | |
711 | 1306 nptr = ncadddr(e1); |
1307 type = caddr(e1); | |
601 | 1308 return strop(e2,1); |
462 | 1309 case INLINE: |
512 | 1310 return p_inline(e1); |
462 | 1311 case INDIRECT: |
527 | 1312 return pindirect(e1); |
462 | 1313 case RINDIRECT: case URINDIRECT: |
1314 case CRINDIRECT: case CURINDIRECT: | |
1315 case SRINDIRECT: case SURINDIRECT: | |
1316 case FRINDIRECT: case DRINDIRECT: | |
1317 case LRINDIRECT: case LURINDIRECT: | |
1318 return prindirect(e1); | |
1319 case ADDRESS: | |
502 | 1320 return paddress(e1); |
566 | 1321 case ST_OP: |
1322 e3=caddr(e1); | |
1323 e1=pexpr(car(e3)); | |
705 | 1324 return binop0(e2,e1,pexpr(cadr(e3)),caddr(e3),cadddr(e3)); |
462 | 1325 case MINUS: |
463 | 1326 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1327 if (car(e3)==CONST) return list2(CONST,-cadr(e3)); |
1328 return list2(car(e1),e3); | |
1329 #if LONGLONG_CODE | |
1330 case LMINUS: | |
463 | 1331 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1332 if (car(e3)==LCONST) return llist2(LCONST,-lcadr(e3)); |
1333 return list2(car(e1),e3); | |
1334 #endif | |
1335 #if FLOAT_CODE | |
1336 case DMINUS: | |
463 | 1337 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1338 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3)); |
1339 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3)); | |
1340 return list2(car(e1),e3); | |
1341 case FMINUS: | |
463 | 1342 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1343 if (car(e3)==DCONST) return dlist2(DCONST,-dcadr(e3)); |
1344 if (car(e3)==FCONST) return dlist2(FCONST,-dcadr(e3)); | |
1345 return list2(car(e1),e3); | |
1346 #endif | |
1347 case CONV: | |
501 | 1348 return p_conv(caddr(e1),e2); |
462 | 1349 case BNOT: /* ~ */ |
463 | 1350 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1351 if (car(e3)==CONST) return list2(CONST,~cadr(e3)); |
1352 return list2(BNOT,e3); | |
1353 case LNOT: /* ! */ | |
463 | 1354 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1355 if (car(e3)==CONST) return list2(CONST,!cadr(e3)); |
1356 return list2(LNOT,e3); | |
1357 case PREINC: | |
1358 case UPREINC: | |
463 | 1359 if ((e3 = pexpr(e2))==e2) return e1; |
557 | 1360 if (car(e3)==CONST) return list2(CONST,cadr(e3)+caddr(e1)); |
503 | 1361 return list4(car(e1),e3,caddr(e1),cadddr(e1)); |
462 | 1362 case POSTINC: |
1363 case UPOSTINC: | |
463 | 1364 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1365 if (car(e3)==CONST) return e3; |
503 | 1366 return list4(car(e1),e3,caddr(e1),cadddr(e1)); |
462 | 1367 #if FLOAT_CODE |
1368 case DPREINC: /* ++d */ | |
463 | 1369 if ((e3 = pexpr(e2))==e2) return e1; |
1370 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2)); | |
1371 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2)); | |
503 | 1372 return list4(car(e1),e3,caddr(e1),cadddr(e1)); |
462 | 1373 case DPOSTINC: /* d++ */ |
463 | 1374 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1375 if (car(e3)==FCONST||car(e3)==DCONST) return e3; |
503 | 1376 return list4(car(e1),e3,caddr(e1),cadddr(e1)); |
462 | 1377 case FPREINC: /* ++f */ |
463 | 1378 if ((e3 = pexpr(e2))==e2) return e1; |
1379 if (car(e3)==FCONST) return dlist2(FCONST,dcadr(e3)+cadr(e2)); | |
1380 if (car(e3)==DCONST) return dlist2(DCONST,dcadr(e3)+cadr(e2)); | |
503 | 1381 return list4(car(e1),e3,caddr(e1),cadddr(e1)); |
462 | 1382 case FPOSTINC: /* f++ */ |
463 | 1383 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1384 if (car(e3)==FCONST||car(e3)==DCONST) return e3; |
503 | 1385 return list4(car(e1),e3,caddr(e1),cadddr(e1)); |
462 | 1386 #endif |
1387 #if LONGLONG_CODE | |
1388 case LPREINC: /* ++d */ | |
1389 case LUPREINC: /* ++d */ | |
463 | 1390 if ((e3 = pexpr(e2))==e2) return e1; |
1391 if (car(e3)==LCONST) return llist2(LCONST,lcadr(e3)+cadr(e2)); | |
503 | 1392 return list4(car(e1),e3,caddr(e1),cadddr(e1)); |
462 | 1393 case LPOSTINC: /* d++ */ |
1394 case LUPOSTINC: /* d++ */ | |
463 | 1395 if ((e3 = pexpr(e2))==e2) return e1; |
462 | 1396 if (car(e3)==LCONST) return e3; |
503 | 1397 return list4(car(e1),e3,caddr(e1),cadddr(e1)); |
462 | 1398 #endif |
1399 case MUL: case UMUL: | |
1400 case DIV: case UDIV: | |
1401 case MOD: case UMOD: | |
1402 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT: | |
1403 case ADD: case SUB: case BAND: case EOR: case BOR: case CMP: case CMPGE: | |
1404 case UCMP: case CMPEQ: case CMPNEQ: case UCMPGE: | |
1405 #if FLOAT_CODE | |
1406 case DMUL: case DDIV: | |
1407 case DADD: case DSUB: | |
1408 case DCMP: case DCMPGE: case DCMPEQ: case DCMPNEQ: | |
1409 case FMUL: case FDIV: | |
1410 case FADD: case FSUB: | |
1411 case FCMP: case FCMPGE: case FCMPEQ: case FCMPNEQ: | |
1412 #endif | |
1413 #if LONGLONG_CODE | |
1414 case LMUL: case LUMUL: | |
1415 case LDIV: case LUDIV: | |
1416 case LMOD: case LUMOD: | |
1417 case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT: | |
1418 case LADD: case LSUB: case LBAND: case LEOR: case LBOR: case LCMP: | |
1419 #endif | |
501 | 1420 return pbinop(car(e1),e2,caddr(e1)); |
557 | 1421 // relational operator |
1422 case GT: case UGT: case GE: case UGE: case LT: | |
1423 case ULT: case LE: case ULE: | |
1424 case LOP+GT: case LOP+UGT: case LOP+GE: case LOP+UGE: case LOP+LT: | |
1425 case LOP+ULT: case LOP+LE: case LOP+ULE: | |
1426 case DOP+GT: case DOP+GE: case DOP+LT: case DOP+LE: | |
1427 case FOP+GT: case FOP+GE: case FOP+LT: case FOP+LE: | |
1428 case FOP+EQ: case FOP+NEQ: | |
1429 case EQ: case NEQ: case DOP+EQ: case DOP+NEQ: | |
1430 case LOP+EQ: case LOP+NEQ: | |
1431 return pbinop(car(e1),e2,caddr(e1)); | |
1432 case LAND: | |
1433 return pland(car(e1),cadr(e1),caddr(e1)); | |
1434 case LOR: | |
1435 return plor(car(e1),cadr(e1),caddr(e1)); | |
528 | 1436 case LCOND: case DCOND: case FCOND: case COND: case UCOND: case LUCOND: |
555 | 1437 e2 = pexpr(e2); |
1438 if (car(e2)==CONST) return | |
1439 caddr(e1)? pexpr(cadr(e2)?caddr(e1):cadddr(e1)) : | |
1440 pexpr(cadr(e2)?e2:cadddr(e1)); // GNU extension h?:g | |
1441 e3=pexpr(caddr(e1)); | |
1442 return list4(car(e1),e2,e3,pexpr(cadddr(e1))); | |
462 | 1443 case STASS: |
1444 return psassign(e1); | |
1445 case ASS: case CASS: case SASS: | |
1446 return passign(e1); | |
1447 case SASSOP: case SUASSOP: | |
1448 case ASSOP: case CASSOP: case CUASSOP: | |
1449 return passop(e1); | |
1450 #if FLOAT_CODE | |
1451 case FASS: case DASS: | |
1452 return pdassign(e1); | |
1453 case DASSOP: case FASSOP: | |
1454 return pdassop(e1); | |
616 | 1455 |
1456 case BUILTIN_FABS: | |
1457 case BUILTIN_FABSF: | |
1458 case BUILTIN_FABSL: | |
1459 e2 = pexpr(e2); | |
1460 if (is_const(e2)) { | |
1461 if (dcadr(e2) >= 0.0 ) return e2; | |
1462 return pexpr(list2(car(e1)==BUILTIN_FABSF? | |
1463 FMINUS:DMINUS,e2)); | |
1464 } | |
1465 return list2(car(e1),e2); | |
462 | 1466 #endif |
1467 #if LONGLONG_CODE | |
1468 case LASS: | |
1469 return plassign(e1); | |
1470 case LASSOP: case LUASSOP: | |
1471 return plassop(e1); | |
1472 #endif | |
1473 case ALLOCA: | |
501 | 1474 return palloc(e2); |
462 | 1475 case BUILTINP: |
463 | 1476 return list2(CONST,is_const(pexpr(e2))); |
462 | 1477 case COMMA: |
555 | 1478 return pcomma(e2,caddr(e1)); |
462 | 1479 case RETURN: |
1480 case ENVIRONMENT: | |
1481 case LCALL: | |
1482 return e1; | |
1483 #if BIT_FIELD_CODE | |
1484 case RBIT_FIELD: | |
1485 return prbit_field(e1); | |
553 | 1486 case BIT_FIELD: |
1487 return list3(BIT_FIELD,pexpr(e2),caddr(e1)); | |
462 | 1488 case BASS: |
1489 return pbassign(e1); | |
1490 case BPREINC: | |
1491 case BPOSTINC: | |
1492 case BASSOP: | |
1493 return pbassop(e1); | |
1494 #endif | |
1495 #if ASM_CODE | |
1496 case ASM: | |
1497 return list3(ASM,list4( | |
501 | 1498 car(e2),cadr(e2),caddr(e2),cadddr(e2)), |
1499 caddr(e1)); | |
462 | 1500 #endif |
681 | 1501 case CAST: |
692 | 1502 if (e2==0) { |
1503 // casted empty structure (struct hoge){} | |
1504 // I think we can skip it. It means nothing in declaration | |
822
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1505 // but it make zero fill, we have to handle it later |
692 | 1506 return 0; |
1507 } else if (car(e2)==DECL_DATA) { | |
681 | 1508 // casted initialized structure (struct hoge){...} |
1509 return list3(DECL_DATA,pexpr(cadr(e2)),caddr(e2)); | |
1510 } | |
1511 if (type_compatible(caddr(e1),cadddr(e1))) { | |
690 | 1512 return pexpr(e2); // rvalue ? |
687 | 1513 } else { |
822
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1514 #if 1 |
690 | 1515 e2 = pexpr(e2); // will override type |
822
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1516 type = cadddr(e1); |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1517 return correct_type(e2,caddr(e1)); |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1518 #else |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1519 e2 = pexpr(e2); // will override type |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1520 e2 = correct_type(e2,caddr(e1)); |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1521 type = caddr(e1); |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1522 return e2; |
8e7241d81f66
parse mode/non parse mode on ppc, ia32, i64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
819
diff
changeset
|
1523 #endif |
687 | 1524 // return list4(CAST,pexpr(e2),caddr(e1),cadddr(e1)); |
1525 } | |
681 | 1526 case DECL_DATA: |
1527 return list3(DECL_DATA,pexpr(e2),caddr(e1)); | |
1528 case DECL_DATA_LIST: | |
697 | 1529 case DECL_DATA_ARRAY: |
711 | 1530 return list4(car(e1),pexpr(e2),pexpr(caddr(e1)),cadddr(e1)); |
681 | 1531 case DECL_DATA_FIELD: |
711 | 1532 return list4n(car(e1),pexpr(e2),pexpr(caddr(e1)),ncadddr(e1)); |
462 | 1533 case ST_DECL: return p_decl(e1); |
1534 case ST_IF: return p_if(e1); | |
1535 case ST_DO: return p_do(e1); | |
1536 case ST_WHILE: return p_while(e1); | |
1537 case ST_FOR: return p_for(e1); | |
1538 case ST_SWITCH: return p_switch(e1); | |
1539 case ST_COMP: return p_comp(e1); | |
1540 case ST_BREAK: return p_break(e1); | |
1541 case ST_CONTINUE: return p_continue(e1); | |
1542 case ST_CASE: return p_case(e1); | |
1543 case ST_DEFAULT: return p_default(e1); | |
1544 case ST_RETURN: return p_return(e1); | |
1545 case ST_GOTO: return p_goto(e1); | |
1546 case ST_ASM: return p_asm(e1); | |
1547 case ST_LABEL: return p_label(e1); | |
1548 case ST_COMMENT: return p_comment(e1); | |
1549 default: | |
551 | 1550 error(-1); |
462 | 1551 return p_bool(e1); |
1552 } | |
1553 return VOID; | |
1554 } | |
1555 | |
625 | 1556 /* |
1557 Prepare pvariable table | |
1558 */ | |
1559 | |
557 | 1560 static int |
1561 replace_inline_parameter(NMTBL *anptr,int t,int e4,int narg,int evals) | |
1562 { | |
1563 int arg; | |
1564 if (has_attr(anptr,KONST) && !has_attr(anptr,HAS_ADDRESS)) { | |
625 | 1565 // replacable const variable |
557 | 1566 if (is_memory(e4)) { |
1567 heap[pdisp+narg]=reference(e4); | |
1568 return evals; | |
1569 } else if (is_const(e4)) { | |
1570 heap[pdisp+narg]=e4; | |
1571 return evals; | |
1572 } | |
1573 } | |
625 | 1574 // we need real local variable for this inline |
711 | 1575 arg = heap[pdisp+narg]=list3n(LVAR,new_lvar(size(t)),anptr); |
557 | 1576 inline_lvars = glist2(arg,inline_lvars); |
1577 evals=list2(assign_expr0(arg,e4,anptr->ty,t),evals); | |
1578 return evals; | |
1579 } | |
1580 | |
1581 /* | |
1582 setup parameter replacement of inline call | |
1583 */ | |
1584 | |
1585 static void | |
696 | 1586 enter_inline(NMTBL *n, int e,int toplevel) |
557 | 1587 { |
1588 int e1 = attr_value(n,INLINE); | |
1589 int arg_disp = cadr(e1); // number of arguments | |
1590 int narg,e3,e4, e5, fargtype; | |
1591 int evals = 0; | |
696 | 1592 int t, replace; |
557 | 1593 NMTBL *anptr; |
1594 | |
1595 fnptr = n; // st_return see this | |
1596 pvartable = p_vartable(arg_disp, /* number of arg */ | |
1597 caddr(e1) /* number of local parameter */); | |
1598 | |
704 | 1599 replace = (is_code(fnptr)||toplevel); |
696 | 1600 |
557 | 1601 /* function arguments type */ |
1602 fargtype = n->dsp; // we cannot do destruct reverse here | |
463 | 1603 |
557 | 1604 /* inline function arguments */ |
1605 narg = 0; | |
1606 if (!fargtype) { | |
1607 goto no_args; // wrong number of arguments | |
1608 } | |
699 | 1609 |
557 | 1610 for (e3 = e5 = reverse0(caddr(e)); e3; e3 = cadr(e3)) { |
712 | 1611 anptr = ncadddr(fargtype); |
557 | 1612 if (!anptr) break; // should not happen? |
1613 t=caddr(e3); // type | |
1614 e4 = car(e3); | |
696 | 1615 if (replace) { |
1616 heap[pdisp+narg]=reference(e4); | |
1617 } else { | |
1618 evals = replace_inline_parameter(anptr,t,e4,narg,evals); | |
1619 } | |
557 | 1620 narg ++; |
1621 fargtype = cadr(fargtype); | |
1622 } | |
1623 caddr(e) = reverse0(e5); // make it normal | |
1624 if (eval_order==NORMAL) evals = reverse0(evals); | |
1625 for(;evals;evals=cadr(evals)) { | |
1626 g_expr_u(car(evals)); | |
1627 } | |
1628 no_args: | |
1629 return; | |
1630 } | |
1631 | |
1632 /* | |
1633 pass local static variable list to our parents | |
1634 clean up and free used inline parameters | |
1635 */ | |
1636 | |
1637 static void | |
696 | 1638 leave_inline(int e1,int toplevel) |
557 | 1639 { |
1640 NMTBL *n; | |
712 | 1641 NMTBL *local_statics = ncadddr(e1); // local static list |
557 | 1642 |
696 | 1643 if (retcont && !toplevel) error(STERR); |
1644 // inline can't handle return/environment except top level | |
557 | 1645 |
1646 if (local_statics && local_statics != &null_nptr) { | |
1647 // append our local static variables to the parent list | |
1648 n = local_statics; | |
1649 while(n->next != &null_nptr) n=n->next; | |
1650 n->next = local_static_list; local_static_list = local_statics; | |
767
c14a1426cfed
i64 strop/simp1/alloca
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
715
diff
changeset
|
1651 ncadddr(e1) = 0; // prevent duplicate initialize |
557 | 1652 } |
625 | 1653 |
1654 // free used local variables or registers | |
557 | 1655 while(inline_lvars) { |
1656 int e; | |
1657 int l = car(inline_lvars); | |
1658 switch(car(l)) { | |
1659 case LVAR: free_lvar(cadr(l)); break; | |
1660 case REGISTER: case DREGISTER: | |
1661 case FREGISTER: case LREGISTER: | |
1662 free_register(cadr(l)); | |
1663 } | |
1664 e = cadr(inline_lvars); | |
1665 free_glist2(inline_lvars); | |
1666 inline_lvars = e; | |
1667 } | |
1668 } | |
530 | 1669 |
463 | 1670 extern int |
696 | 1671 gen_inline(int e, int toplevel) |
462 | 1672 { |
514 | 1673 // these saved value should be some struct |
1674 int sretlabel; | |
1675 NMTBL *sfnptr; | |
552 | 1676 int svartable; |
696 | 1677 |
513 | 1678 int scslabel = cslabel; |
463 | 1679 int sdisp = pdisp; |
552 | 1680 int sret_register; |
1681 int sret_reg_mode; | |
1682 int sinline_lvars; | |
1683 int slfree; | |
531 | 1684 // int slreg_count=lreg_count; |
513 | 1685 |
711 | 1686 NMTBL *n = (NMTBL*)ncaddr(cadr(e)); |
463 | 1687 int e1 = attr_value(n,INLINE); |
500 | 1688 int parse = car(e1); // inline parse tree |
557 | 1689 int dots; |
508 | 1690 int ret_type = function_type(cadddr(e),&dots); |
463 | 1691 |
552 | 1692 checkret(); |
1693 checkjmp(-1); | |
1694 | |
1695 svartable = pvartable; | |
696 | 1696 |
552 | 1697 scslabel = cslabel; |
1698 sdisp = pdisp; | |
1699 sret_register = ret_register; | |
1700 sret_reg_mode = ret_reg_mode; | |
1701 sinline_lvars = inline_lvars; | |
1702 slfree=lfree; | |
1703 // int slreg_count=lreg_count; | |
514 | 1704 |
1705 sretlabel = retlabel; | |
1706 sfnptr = fnptr; | |
696 | 1707 |
513 | 1708 cslabel = -1; |
1709 retpending = 0; | |
527 | 1710 inline_lvars = 0; |
705 | 1711 if (!toplevel) { |
1712 retlabel = fwdlabel(); | |
1713 } | |
513 | 1714 |
696 | 1715 enter_inline(n,e,toplevel); |
526 | 1716 |
704 | 1717 if (toplevel) { |
705 | 1718 ret_register = code_set_return_register(0); // fnptr required |
704 | 1719 ret_reg_mode = 1; |
1720 } else { | |
705 | 1721 ret_register = 555; |
704 | 1722 ret_reg_mode = 0; |
1723 } | |
1724 | |
557 | 1725 // partial evaluation of parse tree |
1726 // constant propergation, etc. | |
1727 parse = pexpr(parse); | |
463 | 1728 pdisp = sdisp; |
464 | 1729 pvartable = svartable; |
513 | 1730 |
557 | 1731 // generate code if necessary |
513 | 1732 if (ret_type!=VOID) |
557 | 1733 g_expr0(parse); |
513 | 1734 else |
557 | 1735 g_expr_u(parse); |
1736 | |
705 | 1737 if (!toplevel) { |
1738 checkret(); | |
1739 fwddef(retlabel); | |
1740 control=1; | |
1741 } | |
513 | 1742 |
696 | 1743 leave_inline(e1,toplevel); |
510 | 1744 |
513 | 1745 fnptr = sfnptr; |
1746 retlabel = sretlabel; | |
696 | 1747 |
513 | 1748 cslabel = scslabel; |
514 | 1749 ret_register = sret_register; |
1750 ret_reg_mode = sret_reg_mode; | |
527 | 1751 inline_lvars = sinline_lvars; |
528 | 1752 lfree=slfree; |
513 | 1753 |
508 | 1754 return ret_type; |
462 | 1755 } |
1756 | |
1757 /* end */ |