Mercurial > hg > CbC > old > device
annotate mc-codegen.c @ 307:fda28752d301 stdarg-support
stdarg (varargs done... PowerPC, IA32 checked)
author | kono |
---|---|
date | Wed, 09 Jun 2004 23:01:18 +0900 |
parents | 117baacd1ed0 |
children | f73b93de216a |
rev | line source |
---|---|
61 | 1 /* Micro-C Generic Code Generatation Part */ |
2 /* $Id$ */ | |
3 | |
4 #define EXTERN extern | |
5 #include "mc.h" | |
6 #include "mc-codegen.h" | |
7 #include "mc-code.h" | |
8 | |
83 | 9 int use; /* generated value will be used */ |
81 | 10 |
105 | 11 static void remove0(int *parent,int e) ; |
12 /* static void remove0_all(int *parent,int e) ; */ | |
13 static int is_same_type(int e1,int e2); | |
14 static void jump(int e1, int env); | |
15 static void machinop(int e1); | |
16 static void sassign(int e1); | |
17 static void assign(int e1); | |
18 static void assop(int e1); | |
19 static int g_expr0(int e1); | |
20 static int register_to_lvar(int e); | |
289 | 21 static void bexpr_u(int e1, char cond, int l1); |
61 | 22 |
195 | 23 #if FLOAT_CODE |
24 | |
25 /* floating point */ | |
26 | |
27 static void dassop(int e1); | |
28 static void dmachinop(int e1,int d); | |
29 static void dassign(int e1); | |
30 | |
31 #endif | |
32 #if LONGLONG_CODE | |
33 static void lassop(int e1); | |
34 static void lmachinop(int e1); | |
35 static void lassign(int e1); | |
36 #endif | |
37 | |
38 | |
102 | 39 void |
40 codegen_init() | |
41 { | |
42 code_init(); | |
43 } | |
44 | |
137 | 45 void |
46 arg_register(NMTBL *fnptr) | |
47 { | |
48 code_arg_register(fnptr); | |
49 } | |
50 | |
94 | 51 int |
83 | 52 gexpr(int e1,int use0) |
61 | 53 { |
94 | 54 if (chk) return INT; |
61 | 55 gexpr_init(); |
83 | 56 use = use0; |
61 | 57 #if 0 |
58 if(lineno==2862) { | |
94 | 59 return g_expr0(e1); /*break here*/ |
61 | 60 } |
61 #endif | |
94 | 62 return g_expr0(e1); |
61 | 63 } |
64 | |
65 int | |
83 | 66 g_expr_u(int e1) |
67 { | |
94 | 68 int t; |
83 | 69 int suse = use; use=0; |
94 | 70 t=g_expr0(e1); |
147 | 71 code_gexpr(e1); |
72 | |
83 | 73 use=suse; |
94 | 74 return t; |
83 | 75 } |
76 | |
94 | 77 int |
61 | 78 g_expr(int e1) |
79 { | |
94 | 80 int t; |
83 | 81 int suse = use; use=1; |
94 | 82 t=g_expr0(e1); |
147 | 83 code_gexpr(e1); |
84 | |
83 | 85 use=suse; |
94 | 86 return t; |
83 | 87 } |
88 | |
94 | 89 int |
83 | 90 g_expr0(int e1) |
91 { | |
191 | 92 int e2,e3,t,d,t1; |
61 | 93 NMTBL *n; |
94 | |
147 | 95 code_gexpr(e1); |
96 | |
61 | 97 e2 = cadr(e1); |
98 switch (car(e1)){ | |
99 case GVAR: | |
221 | 100 code_gvar(e1,USE_CREG); |
94 | 101 return ADDRESS; |
61 | 102 case RGVAR: |
221 | 103 code_rgvar(e1,USE_CREG); |
94 | 104 return INT; |
61 | 105 case CRGVAR: |
221 | 106 code_crgvar(e1,USE_CREG,1,1); |
94 | 107 return CHAR; |
162 | 108 case CURGVAR: |
221 | 109 code_crgvar(e1,USE_CREG,0,1); |
165 | 110 return UCHAR; |
111 case SRGVAR: | |
221 | 112 code_crgvar(e1,USE_CREG,1,size_of_short); |
165 | 113 return CHAR; |
114 case SURGVAR: | |
221 | 115 code_crgvar(e1,USE_CREG,0,size_of_short); |
162 | 116 return UCHAR; |
61 | 117 case LVAR: |
221 | 118 code_lvar(e2,USE_CREG); |
94 | 119 return ADDRESS; |
61 | 120 case REGISTER: |
221 | 121 code_register(e2,USE_CREG); |
94 | 122 return INT; |
195 | 123 #if FLOAT_CODE |
94 | 124 case DREGISTER: |
221 | 125 code_dregister(e2,USE_CREG,1); |
94 | 126 return DOUBLE; |
137 | 127 case FREGISTER: |
221 | 128 code_dregister(e2,USE_CREG,0); |
137 | 129 return FLOAT; |
195 | 130 #endif |
219 | 131 #if LONGLONG_CODE |
132 case LREGISTER: | |
221 | 133 code_lregister(e2,USE_CREG); |
219 | 134 return LONGLONG; |
135 #endif | |
61 | 136 case RLVAR: |
221 | 137 code_rlvar(e2,USE_CREG); |
94 | 138 return INT; |
61 | 139 case CRLVAR: |
221 | 140 code_crlvar(e2,USE_CREG,1,1); |
94 | 141 return CHAR; |
162 | 142 case CURLVAR: |
221 | 143 code_crlvar(e2,USE_CREG,0,1); |
165 | 144 return UCHAR; |
145 case SRLVAR: | |
221 | 146 code_crlvar(e2,USE_CREG,1,size_of_short); |
165 | 147 return CHAR; |
148 case SURLVAR: | |
221 | 149 code_crlvar(e2,USE_CREG,0,size_of_short); |
162 | 150 return UCHAR; |
195 | 151 #if FLOAT_CODE |
81 | 152 case FRLVAR: |
221 | 153 code_drlvar(e2,0,USE_CREG); |
94 | 154 return FLOAT; |
81 | 155 case FRGVAR: |
221 | 156 code_drgvar(e1,0,USE_CREG); |
94 | 157 return FLOAT; |
81 | 158 case DRLVAR: |
221 | 159 code_drlvar(e2,1,USE_CREG); |
94 | 160 return DOUBLE; |
81 | 161 case DRGVAR: |
221 | 162 code_drgvar(e1,1,USE_CREG); |
94 | 163 return DOUBLE; |
195 | 164 #endif |
202 | 165 #if LONGLONG_CODE |
166 case LRLVAR: | |
221 | 167 code_lrlvar(e2,USE_CREG); |
202 | 168 return LONGLONG; |
169 case LRGVAR: | |
221 | 170 code_lrgvar(e1,USE_CREG); |
202 | 171 return LONGLONG; |
172 case LURLVAR: | |
221 | 173 code_lrlvar(e2,USE_CREG); |
202 | 174 return ULONGLONG; |
175 case LURGVAR: | |
221 | 176 code_lrgvar(e1,USE_CREG); |
202 | 177 return ULONGLONG; |
178 #endif | |
61 | 179 case FNAME: |
221 | 180 code_fname((NMTBL *)(e2),USE_CREG); |
94 | 181 return ADDRESS; |
61 | 182 case CONST: /* ÂåÆþ¤¹¤ëÃͤ¬0¤Ç¤âÆÃÊ̤ʽèÍý¤Ï¤·¤Ê¤¤ */ |
221 | 183 code_const(e2,USE_CREG); |
94 | 184 return INT; |
195 | 185 #if FLOAT_CODE |
81 | 186 case DCONST: |
221 | 187 code_dconst(e1,USE_CREG,1); |
94 | 188 return DOUBLE; |
133 | 189 case FCONST: |
221 | 190 code_dconst(e1,USE_CREG,0); |
133 | 191 return FLOAT; |
195 | 192 #endif |
206 | 193 #if LONGLONG_CODE |
202 | 194 case LCONST: |
221 | 195 code_lconst(e1,USE_CREG); |
202 | 196 return LONGLONG; |
197 #endif | |
61 | 198 case STRING: |
221 | 199 code_string(e1,USE_CREG); |
94 | 200 return ADDRESS; |
61 | 201 case FUNCTION: |
94 | 202 t = function(e1); |
203 return t; | |
61 | 204 case CODE: |
205 jump(e2,caddr(e1)); | |
94 | 206 return VOID; |
61 | 207 case INDIRECT: |
94 | 208 return g_expr0(e2); |
196 | 209 case RINDIRECT: |
245 | 210 return code_rindirect(e2,USE_CREG,caddr(e1),1); |
196 | 211 case URINDIRECT: |
245 | 212 return code_rindirect(e2,USE_CREG,caddr(e1),0); |
196 | 213 case CRINDIRECT: |
245 | 214 return code_crindirect(e2,USE_CREG,caddr(e1),1); |
196 | 215 case CURINDIRECT: |
245 | 216 return code_crindirect(e2,USE_CREG,caddr(e1),0); |
196 | 217 case SRINDIRECT: |
245 | 218 return code_srindirect(e2,USE_CREG,caddr(e1),1); |
219 case SURINDIRECT: | |
221 | 220 return code_srindirect(e2,USE_CREG,caddr(e1),0); |
195 | 221 #if FLOAT_CODE |
197 | 222 case FRINDIRECT: |
221 | 223 return code_drindirect(e2,USE_CREG,caddr(e1),0); |
196 | 224 case DRINDIRECT: |
221 | 225 return code_drindirect(e2,USE_CREG,caddr(e1),1); |
195 | 226 #endif |
196 | 227 #if LONGLONG_CODE |
228 case LRINDIRECT: | |
221 | 229 return code_lrindirect(e2,USE_CREG,caddr(e1),0); |
196 | 230 case LURINDIRECT: |
221 | 231 return code_lrindirect(e2,USE_CREG,caddr(e1),1); |
196 | 232 #endif |
61 | 233 case ADDRESS: |
138 | 234 if (car(e2)==REGISTER||car(e2)==DREGISTER||car(e2)==FREGISTER) |
235 return register_to_lvar(e2); /* too late? */ | |
105 | 236 else |
237 return g_expr0(e2); | |
61 | 238 case MINUS: /* ¥ì¥¸¥¹¥¿¤ËÂФ·¡¢negl¤ò¼Â¹Ô¤¹¤ì¤Ð¼Â¸½²Äǽ */ |
221 | 239 g_expr0(e2); code_neg(USE_CREG); |
94 | 240 return INT; |
212 | 241 #if LONGLONG_CODE |
242 case LMINUS: | |
221 | 243 g_expr0(e2); code_lneg(USE_CREG); |
212 | 244 return LONGLONG; |
245 #endif | |
195 | 246 #if FLOAT_CODE |
81 | 247 case DMINUS: |
221 | 248 g_expr0(e2); code_dneg(USE_CREG,1); |
94 | 249 return DOUBLE; |
133 | 250 case FMINUS: |
221 | 251 g_expr0(e2); code_dneg(USE_CREG,0); |
133 | 252 return FLOAT; |
195 | 253 #endif |
108 | 254 case CONV: |
255 g_expr0(e2); | |
256 switch(caddr(e1)) { | |
195 | 257 #if FLOAT_CODE |
221 | 258 case I2D: code_i2d(USE_CREG); return DOUBLE; |
259 case D2I: code_d2i(USE_CREG); return INT; | |
260 case U2D: code_u2d(USE_CREG); return DOUBLE; | |
261 case F2U: code_f2u(USE_CREG); return UNSIGNED; | |
262 case I2F: code_i2f(USE_CREG); return FLOAT; | |
263 case F2I: code_f2i(USE_CREG); return INT; | |
264 case U2F: code_u2f(USE_CREG); return FLOAT; | |
265 case D2U: code_d2u(USE_CREG); return UNSIGNED; | |
266 case D2F: code_d2f(USE_CREG); return FLOAT; | |
267 case F2D: code_f2d(USE_CREG); return DOUBLE; | |
195 | 268 #endif |
269 #if LONGLONG_CODE | |
221 | 270 case I2LL: code_i2ll(USE_CREG); return LONGLONG; |
271 case I2ULL: code_i2ull(USE_CREG); return ULONGLONG; | |
272 case U2LL: code_u2ll(USE_CREG); return LONGLONG; | |
273 case U2ULL: code_u2ull(USE_CREG); return ULONGLONG; | |
274 case LL2I: code_ll2i(USE_CREG); return INT; | |
275 case LL2U: code_ll2u(USE_CREG); return UNSIGNED; | |
276 case ULL2I: code_ull2i(USE_CREG); return INT; | |
277 case ULL2U: code_ull2u(USE_CREG); return UNSIGNED; | |
195 | 278 #if FLOAT_CODE |
221 | 279 case D2LL: code_d2ll(USE_CREG); return LONGLONG; |
280 case D2ULL: code_d2ull(USE_CREG); return ULONGLONG; | |
281 case F2LL: code_f2ll(USE_CREG); return LONGLONG; | |
282 case F2ULL: code_f2ull(USE_CREG); return ULONGLONG; | |
283 case LL2D: code_ll2d(USE_CREG); return DOUBLE; | |
284 case LL2F: code_ll2f(USE_CREG); return FLOAT; | |
285 case ULL2D: code_ull2d(USE_CREG); return DOUBLE; | |
286 case ULL2F: code_ull2f(USE_CREG); return FLOAT; | |
195 | 287 #endif |
288 #endif | |
289 | |
108 | 290 default: |
291 error(-1); return INT; | |
292 } | |
61 | 293 case BNOT: /* ~ */ |
221 | 294 g_expr0(e2); code_not(USE_CREG); |
94 | 295 return INT; |
61 | 296 case LNOT: /* ! */ |
221 | 297 g_expr0(e2); code_lnot(USE_CREG); |
94 | 298 return INT; |
61 | 299 case PREINC: |
221 | 300 code_preinc(e1,e2,caddr(e1),1,cadddr(e1),USE_CREG); |
168 | 301 return INT; |
302 case UPREINC: | |
221 | 303 code_preinc(e1,e2,caddr(e1),0,cadddr(e1),USE_CREG); |
94 | 304 return INT; |
61 | 305 case POSTINC: |
221 | 306 code_postinc(e1,e2,caddr(e1),1,cadddr(e1),USE_CREG); |
168 | 307 return INT; |
308 case UPOSTINC: | |
221 | 309 code_postinc(e1,e2,caddr(e1),0,cadddr(e1),USE_CREG); |
94 | 310 return INT; |
195 | 311 #if FLOAT_CODE |
147 | 312 case DPREINC: /* ++d */ |
221 | 313 code_dpreinc(e1,e2,1,USE_CREG); |
94 | 314 return DOUBLE; |
147 | 315 case DPOSTINC: /* d++ */ |
221 | 316 code_dpostinc(e1,e2,1,USE_CREG); |
94 | 317 return DOUBLE; |
147 | 318 case FPREINC: /* ++f */ |
221 | 319 code_dpreinc(e1,e2,0,USE_CREG); |
94 | 320 return FLOAT; |
147 | 321 case FPOSTINC: /* f++ */ |
221 | 322 code_dpostinc(e1,e2,0,USE_CREG); |
94 | 323 return FLOAT; |
195 | 324 #endif |
325 #if LONGLONG_CODE | |
326 case LPREINC: /* ++d */ | |
221 | 327 code_lpreinc(e1,e2,USE_CREG); |
219 | 328 return LONGLONG; |
195 | 329 case LPOSTINC: /* d++ */ |
221 | 330 code_lpostinc(e1,e2,USE_CREG); |
219 | 331 return LONGLONG; |
332 case LUPREINC: /* ++d */ | |
221 | 333 code_lpreinc(e1,e2,USE_CREG); |
219 | 334 return ULONGLONG; |
335 case LUPOSTINC: /* d++ */ | |
221 | 336 code_lpostinc(e1,e2,USE_CREG); |
219 | 337 return ULONGLONG; |
195 | 338 #endif |
61 | 339 case MUL: case UMUL: |
340 case DIV: case UDIV: | |
341 case MOD: case UMOD: | |
342 case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT: | |
246 | 343 case ADD: case SUB: case BAND: case EOR: case BOR: case CMP: case CMPGE: |
278 | 344 case UCMP: case CMPEQ: case CMPNEQ: case UCMPGE: |
61 | 345 machinop(e1); |
94 | 346 return INT; |
195 | 347 #if FLOAT_CODE |
81 | 348 case DMUL: case DDIV: |
349 case DADD: case DSUB: | |
250 | 350 case DCMP: case DCMPGE: case DCMPEQ: case DCMPNEQ: |
133 | 351 dmachinop(e1,1); |
94 | 352 return DOUBLE; |
133 | 353 case FMUL: case FDIV: |
354 case FADD: case FSUB: | |
250 | 355 case FCMP: case FCMPGE: case FCMPEQ: case FCMPNEQ: |
133 | 356 dmachinop(e1,0); |
357 return FLOAT; | |
195 | 358 #endif |
359 #if LONGLONG_CODE | |
360 case LMUL: case LUMUL: | |
361 case LDIV: case LUDIV: | |
362 case LMOD: case LUMOD: | |
363 case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT: | |
364 case LADD: case LSUB: case LBAND: case LEOR: case LBOR: case LCMP: | |
365 lmachinop(e1); | |
366 return INT; | |
367 #endif | |
222 | 368 case LCOND: |
369 case DCOND: | |
370 case FCOND: | |
195 | 371 case COND: /* a?0:1 should consider non-brach instruction */ |
372 d = (car(e1)==LCOND?LONGLONG: | |
373 car(e1)==COND?INT:car(e1)==DCOND?DOUBLE:FLOAT); | |
108 | 374 e2=fwdlabel(); |
375 b_expr(cadr(e1),0,e2,0); | |
187 | 376 g_expr0(caddr(e1)); |
221 | 377 t = code_get_fixed_creg(USE_CREG,d); |
108 | 378 jmp(e3=fwdlabel()); |
379 fwddef(e2); | |
191 | 380 t1=g_expr0(cadddr(e1)); |
187 | 381 code_set_fixed_creg(t,1,d); |
61 | 382 fwddef(e3); |
191 | 383 return t1; |
164 | 384 case STASS: |
61 | 385 sassign(e1); |
94 | 386 return RSTRUCT; |
165 | 387 case ASS: case CASS: case SASS: |
61 | 388 assign(e1); |
94 | 389 return INT; |
162 | 390 case ASSOP: case CASSOP: case CUASSOP: |
61 | 391 assop(e1); |
94 | 392 return INT; |
195 | 393 #if FLOAT_CODE |
394 case FASS: case DASS: | |
395 dassign(e1); | |
396 return DOUBLE; | |
81 | 397 case DASSOP: case FASSOP: |
398 dassop(e1); | |
94 | 399 return DOUBLE; |
195 | 400 #endif |
401 #if LONGLONG_CODE | |
402 case LASS: | |
403 lassign(e1); | |
404 return LONGLONG; | |
405 case LASSOP: case LUASSOP: | |
406 lassop(e1); | |
407 return LONGLONG ; | |
408 #endif | |
61 | 409 case RSTRUCT: |
83 | 410 g_expr0(e2); |
94 | 411 return RSTRUCT; |
61 | 412 case COMMA: |
83 | 413 g_expr_u(e2); |
94 | 414 return g_expr0(caddr(e1)); |
61 | 415 case RETURN: |
416 n = (NMTBL *)e2; | |
417 if (retcont==0) | |
418 retcont=fwdlabel(); | |
221 | 419 code_return(USE_CREG); |
94 | 420 return VOID; |
61 | 421 case ENVIRONMENT: |
221 | 422 code_environment(USE_CREG); |
94 | 423 return ADDRESS; |
61 | 424 default: |
221 | 425 code_bool(e1,USE_CREG); /* type? */ |
94 | 426 return INT; |
61 | 427 } |
428 } | |
429 | |
94 | 430 #define dual_ops(op) \ |
431 (op==GT|| op==UGT|| op==GE|| op==UGE|| op==LT|| \ | |
432 op==ULT|| op==LE|| op==ULE|| \ | |
433 op==DOP+GT|| op==DOP+GE|| op==DOP+LT|| op==DOP+LE || \ | |
135 | 434 op==FOP+GT|| op==FOP+GE|| op==FOP+LT|| op==FOP+LE || \ |
435 op==FOP+EQ|| op==FOP+NEQ || \ | |
436 op==EQ|| op==NEQ|| op==DOP+EQ|| op==DOP+NEQ) | |
94 | 437 |
438 int | |
439 rop_dual(op) | |
440 { | |
232 | 441 // x op y => y dual(op) x |
195 | 442 switch(op) { |
443 case GT: return LT; | |
444 case UGT: return ULT; | |
445 case GE: return LE; | |
446 case UGE: return ULE; | |
447 case LT: return GT; | |
448 case ULT: return UGT; | |
449 case LE: return GE; | |
450 case ULE: return UGE; | |
451 case DOP+GT: return DOP+LT; | |
452 case DOP+GE: return DOP+LE; | |
453 case DOP+LT: return DOP+GT; | |
454 case DOP+LE: return DOP+GE; | |
455 case FOP+GT: return FOP+LT; | |
456 case FOP+GE: return FOP+LE; | |
457 case FOP+LT: return FOP+GT; | |
458 case FOP+LE: return FOP+GE; | |
459 | |
460 case LOP+GT: return LOP+LT; | |
461 case LOP+GE: return LOP+LE; | |
462 case LOP+LT: return LOP+GT; | |
463 case LOP+LE: return LOP+GE; | |
464 case LOP+UGT: return FOP+ULT; | |
465 case LOP+UGE: return FOP+ULE; | |
466 case LOP+ULT: return FOP+UGT; | |
467 case LOP+ULE: return FOP+UGE; | |
468 } | |
94 | 469 return op; |
470 } | |
471 | |
61 | 472 void |
289 | 473 bexpr_u(int e1, char cond, int l1) |
61 | 474 { |
94 | 475 int op = car(e1); |
66 | 476 if (chk) return; |
292 | 477 // gexpr_init(); |
94 | 478 if (dual_ops(op) && (car(caddr(e1))==CONST||(car(caddr(e1))==DCONST))) |
479 b_expr(list3(rop_dual(op),caddr(e1),cadr(e1)),cond,l1,0); | |
480 else | |
481 b_expr(e1,cond,l1,0); | |
61 | 482 } |
483 | |
484 void | |
289 | 485 bexpr(int e1, char cond, int l1) |
486 { | |
487 int uses = use; use=1; | |
488 bexpr_u(e1, cond, l1); | |
489 use = uses; | |
490 } | |
491 | |
492 void | |
61 | 493 b_expr(int e1, char cond, int l1,int err) |
494 { | |
94 | 495 int e2,l2,t; |
132 | 496 if (!control) return; |
127 | 497 l2 = 0; |
61 | 498 e2=cadr(e1); |
499 switch(car(e1)) { | |
500 case LNOT: | |
501 b_expr(e2,!cond,l1,0); | |
502 return; | |
280 | 503 case GT: case GE: case LT: case LE: |
504 case EQ: case NEQ: | |
505 rexpr(e1,l1,cond,INT); | |
61 | 506 return; |
280 | 507 case UGT: case UGE: case ULT: case ULE: |
508 rexpr(e1,l1,cond,UNSIGNED); | |
61 | 509 return; |
195 | 510 #if FLOAT_CODE |
82 | 511 case DOP+GT: |
194 | 512 case DOP+GE: |
513 case DOP+EQ: | |
514 case DOP+NEQ: | |
515 case FOP+GT: | |
516 case FOP+GE: | |
517 case FOP+EQ: | |
518 case FOP+NEQ: | |
229 | 519 drexpr(cadr(e1),caddr(e1),l1,car(e1),cond); |
82 | 520 return; |
194 | 521 case FOP+LT: |
231 | 522 case FOP+LE: |
82 | 523 case DOP+LT: |
524 case DOP+LE: | |
232 | 525 drexpr(caddr(e1),cadr(e1),l1,rop_dual(car(e1)),cond); |
82 | 526 return; |
195 | 527 #endif |
528 #if LONGLONG_CODE | |
529 case LOP+GT: | |
530 case LOP+GE: | |
531 case LOP+EQ: | |
532 case LOP+NEQ: | |
210 | 533 case LOP+UGT: |
534 case LOP+UGE: | |
231 | 535 lrexpr(cadr(e1),caddr(e1),l1,car(e1),cond); |
210 | 536 return; |
232 | 537 case LOP+LT: |
538 case LOP+LE: | |
210 | 539 case LOP+ULT: |
540 case LOP+ULE: | |
232 | 541 lrexpr(caddr(e1),cadr(e1),l1,rop_dual(car(e1)),cond); |
210 | 542 return; |
195 | 543 #endif |
61 | 544 case LAND: |
289 | 545 bexpr(e2,0,cond?(l2=fwdlabel()):l1); |
546 bexpr_u(caddr(e1),cond,l1); | |
61 | 547 if(cond) fwddef(l2); |
548 return; | |
549 case LOR: | |
289 | 550 bexpr(e2,1,cond?l1:(l2=fwdlabel())); |
551 bexpr_u(caddr(e1),cond,l1); | |
61 | 552 if(!cond) fwddef(l2); |
553 return; | |
167 | 554 case CRGVAR: case CURGVAR: |
287 | 555 code_cmp_crgvar(e1,USE_CREG,1,l1,cond); |
61 | 556 return; |
167 | 557 case SRGVAR: case SURGVAR: |
287 | 558 code_cmp_crgvar(e1,USE_CREG,size_of_short,l1,cond); |
167 | 559 return; |
560 case CRLVAR: case CURLVAR: | |
287 | 561 code_cmp_crlvar(e2,USE_CREG,1,l1,cond); |
167 | 562 return; |
563 case SRLVAR: case SURLVAR: | |
287 | 564 code_cmp_crlvar(e2,USE_CREG,size_of_short,l1,cond); |
61 | 565 return; |
566 case RGVAR: | |
287 | 567 code_cmp_rgvar(e1,USE_CREG,l1,cond); |
61 | 568 return; |
569 case RLVAR: | |
287 | 570 code_cmp_rlvar(e2,USE_CREG,l1,cond); |
61 | 571 return; |
195 | 572 #if FLOATC_DOE |
81 | 573 case DRLVAR: |
287 | 574 code_cmp_drlvar(e2,USE_CREG,1,l1,cond); |
138 | 575 return; |
576 case FRLVAR: | |
287 | 577 code_cmp_drlvar(e2,USE_CREG,0,l1,cond); |
81 | 578 return; |
579 case DRGVAR: | |
287 | 580 code_cmp_drgvar(e2,USE_CREG,1,l1,cond); |
138 | 581 return; |
582 case FRGVAR: | |
287 | 583 code_cmp_drgvar(e2,USE_CREG,0,l1,cond); |
81 | 584 return; |
138 | 585 case FREGISTER: |
287 | 586 code_cmp_dregister(e2,0,l1,cond); |
138 | 587 return; |
94 | 588 case DREGISTER: |
287 | 589 code_cmp_dregister(e2,1,l1,cond); |
94 | 590 return; |
81 | 591 case DCONST: |
138 | 592 case FCONST: |
132 | 593 if(control&&((dcadr(e2)!=0.0)^cond)) jmp(l1); |
81 | 594 return; |
195 | 595 #endif |
596 #if LONGLONG_DOE | |
597 case LRLVAR: | |
287 | 598 code_cmp_lrlvar(e2,1,l1,cond); |
195 | 599 return; |
600 case LRGVAR: | |
287 | 601 code_cmp_lrgvar(e2,1,l1,cond); |
195 | 602 return; |
603 case LREGISTER: | |
287 | 604 code_cmp_lregister(e2,1,l1,cond); |
195 | 605 return; |
606 case LCONST: | |
607 if(control&&((lcadr(e2)!=0)^cond)) jmp(l1); | |
608 return; | |
609 #endif | |
610 case REGISTER: | |
287 | 611 code_cmp_register(e2,l1,cond); |
195 | 612 return; |
613 case CONST: | |
614 if(control&&((cond&&e2)||(!cond&&!e2))) jmp(l1); | |
615 return; | |
61 | 616 default: |
617 if(err) { | |
81 | 618 error(-1); return; /* recursive g_expr/b_expr */ |
94 | 619 } |
620 t=g_expr(e1); | |
289 | 621 if (!use) return; |
195 | 622 if (0) ; |
623 #if FLOAT_CODE | |
624 else if(t==FLOAT) | |
287 | 625 code_cmp_dregister(USE_CREG,0,l1,cond); |
138 | 626 else if(t==DOUBLE) |
287 | 627 code_cmp_dregister(USE_CREG,1,l1,cond); |
195 | 628 #endif |
629 #if LONGLONG_CODE | |
630 else if(t==LONGLONG||t==ULONGLONG) | |
287 | 631 code_cmp_lregister(USE_CREG,l1,cond); |
195 | 632 #endif |
94 | 633 else |
287 | 634 code_cmp_register(USE_CREG,l1,cond); |
61 | 635 return; |
636 } | |
637 } | |
638 | |
126 | 639 int |
640 is_code(NMTBL *fnptr) | |
641 { | |
642 int type = fnptr->ty; | |
643 return type==CODE|| (type>0 && car(type)==CODE); | |
644 } | |
645 | |
646 int | |
647 is_function(NMTBL *fnptr) | |
648 { | |
649 int type = fnptr->ty; | |
650 return type==FUNCTION || (type>0 && car(type)==FUNCTION); | |
651 } | |
652 | |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
653 int |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
654 function_type(int e1,int *dots) |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
655 { |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
656 int ret_type,t; |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
657 ret_type = cadr(e1); |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
658 if (ret_type==CHAR) ret_type=INT; |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
659 |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
660 /* check argments type is DOTS? */ |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
661 t = caddr(e1); |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
662 if (t==0 || t==DOTS) *dots = 1; |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
663 else { |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
664 *dots = 0; |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
665 for(;t;t = cadr(t)) { |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
666 if (car(t)==DOTS) *dots = 1; |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
667 } |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
668 } |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
669 |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
670 return ret_type; |
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
297
diff
changeset
|
671 } |
61 | 672 |
105 | 673 static int |
674 register_to_lvar(int e) | |
675 { | |
676 error(REG_ERR); | |
677 return 0; | |
678 #if 0 | |
679 ÅÓÃæ¤Ç¥ì¥¸¥¹¥¿¤«¤éLVAR¤ËÊѹ¹¤·¤Æ¤â¡¢´Ö¤Ë¹ç¤ï¤Ê¤¤¡£ | |
680 | |
681 NMTBL *n = (NMTBL*)caddr(e); | |
682 int reg = cadr(e); | |
683 int tag = car(e); | |
684 int lvar; | |
685 int t; | |
686 if (!n||n==&null_nptr) error(REG_ERR); | |
687 if (tag==REGISTER) { | |
688 n->dsp = new_lvar(size_of_int); | |
689 t = INT; | |
690 } else if (tag==DREGISTER) { | |
691 n->dsp = new_lvar(size_of_double); | |
692 t = DOUBLE; | |
138 | 693 } else if (tag==FREGISTER) { |
694 n->dsp = new_lvar(size_of_float); | |
695 t = DOUBLE; | |
195 | 696 } else if (tag==LREGISTER) { |
697 n->dsp = new_lvar(size_of_longlong); | |
698 t = LONGLONG; | |
105 | 699 } else error(-1); |
700 n->sc = LVAR; | |
701 lvar = list2(LVAR,n->dsp); | |
702 g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),t,t)); | |
195 | 703 if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER||tag==LREGISTER) { |
105 | 704 free_register(reg); |
705 return g_expr0(lvar); | |
706 #endif | |
707 } | |
708 | |
277 | 709 // parallel assignment of registers. |
710 // | |
711 // target = list3(target_regnum,next,source_regnum); | |
712 | |
713 void | |
714 parallel_rassign(int assigns) | |
715 { | |
716 int free,tmp,tmp_target,remains,t0,t2,src; | |
717 tmp = 0; | |
718 for(;;) { | |
719 remains = 0; | |
720 // find free target | |
721 for(free=assigns;free;free=cadr(free)) { | |
722 if (!caddr(free)) continue; // already done | |
723 remains++; | |
724 t0 = car(free); // target register | |
725 // check target is free | |
726 for(src=assigns;src;src=cadr(src)) { | |
727 if ((t2=caddr(src)) && t0==t2) break; // target is in source | |
728 } | |
729 if (src==0) { | |
730 break; // free is a free target | |
731 } | |
732 } | |
733 if (remains==0) { | |
734 if (tmp) { | |
735 code_rlvar(tmp,tmp_target); | |
736 } | |
737 return; | |
738 } | |
739 if (free) { // free target | |
740 if (t0!=caddr(free)) | |
741 code_assign_register(t0,0,caddr(free)); | |
742 } else { // no free target | |
743 for(free=assigns;free;free=cadr(free)) { | |
744 if (caddr(free)) break; // not yet done | |
745 } | |
746 if (!free) error(-1); | |
747 tmp = new_lvar(size_of_int); | |
748 tmp_target = car(free); | |
749 code_assign_lvar(tmp,caddr(free),0); | |
750 } | |
751 caddr(free)=0; // mark it done | |
752 } | |
753 } | |
754 | |
61 | 755 /* goto arguments list */ |
756 /* target list4(list2(tag,disp),cdr,ty,source_expr) */ | |
757 /* source expr=listn(tag,...) */ | |
758 /* source (after) list2(tag,disp) */ | |
759 /* source list list3(e,cdr,sz) */ | |
760 | |
284 | 761 #define DEBUG_PARALLEL_ASSIGN 0 |
61 | 762 |
763 int | |
764 overrap(int t,int sz,int source) | |
765 { | |
766 int s,s0,s1; | |
767 int t0=cadr(t); | |
768 int t1=t0+sz; | |
769 for(;source;source=cadr(source)) { | |
770 s=car(source); s0=cadr(s); | |
771 if(car(s)==REGISTER && car(t)==REGISTER) { | |
772 if(s0==t0) return s; | |
773 } else if (is_same_type(s,t)) { | |
774 s1=s0+caddr(source); | |
775 #if DEBUG_PARALLEL_ASSIGN>1 | |
776 printf("# ovedrrap source %d t0 %d t1 %d\n",car(car(t)),t0,t1); | |
777 printf("# ovedrrap target %d s0 %d s1 %d\n",car(car(source)),s0,s1); | |
778 printf("# ovedrrap equal = %d\n",((t0<=s0&&s0<t1)||(t0<s1&&s1<=t1))); | |
779 #endif | |
780 if((t0<=s0&&s0<t1)||(t0<s1&&s1<=t1)) return s; | |
781 } | |
782 } | |
783 return 0; | |
784 } | |
785 | |
786 void | |
787 remove_target(int *target,int t,int *use) | |
788 { | |
789 int use0=*use; | |
147 | 790 int reg; |
61 | 791 while(use0) { |
792 if (car(use0)==t) { | |
147 | 793 reg = car(caddr(use0)); |
794 if (reg==REGISTER||reg==FREGISTER||reg==DREGISTER) | |
99 | 795 free_register(cadr(caddr(use0))); |
61 | 796 break; |
797 } | |
798 use0 = cadr(use0); | |
799 } | |
800 remove0(target,t); | |
801 } | |
802 | |
803 void | |
804 save_target(int t,int s,int *target,int *use,int sz,int ty) | |
805 { | |
806 int e1; | |
807 /*¿·¤·¤¤¥ì¥¸¥¹¥¿(or ¥¹¥¿¥Ã¥¯)¤ò¼èÆÀ¤¹¤ë*/ | |
808 if (sz==size_of_int && (e1=get_register())!=-1) { | |
105 | 809 e1=list3(REGISTER,e1,0); |
61 | 810 *use=list3(t,*use,e1); |
99 | 811 g_expr_u(assign_expr0(e1,s,ty,ty)); |
812 *target = append4(*target,t,ty,e1); | |
195 | 813 #if FLOAT_CODE |
138 | 814 } else if (sz==size_of_double && (e1=get_dregister(1))!=-1) { |
105 | 815 e1=list3(DREGISTER,e1,0); |
99 | 816 *use=list3(t,*use,e1); |
83 | 817 g_expr_u(assign_expr0(e1,s,ty,ty)); |
61 | 818 *target = append4(*target,t,ty,e1); |
138 | 819 } else if (sz==size_of_float && (e1=get_dregister(0))!=-1) { |
820 e1=list3(FREGISTER,e1,0); | |
821 *use=list3(t,*use,e1); | |
822 g_expr_u(assign_expr0(e1,s,ty,ty)); | |
823 *target = append4(*target,t,ty,e1); | |
195 | 824 #endif |
205 | 825 #if LONGLONG_CODE |
826 } else if (sz==size_of_longlong && (e1=get_lregister())!=-1) { | |
827 e1=list3(LREGISTER,e1,0); | |
828 *use=list3(t,*use,e1); | |
829 g_expr_u(assign_expr0(e1,s,ty,ty)); | |
830 *target = append4(*target,t,ty,e1); | |
831 #endif | |
61 | 832 } else { |
94 | 833 g_expr_u(assign_expr0((e1=list2(LVAR,new_lvar(sz))),s,ty,ty)); |
61 | 834 *target = append4(*target,t,ty,e1); |
117 | 835 *use=list3(t,*use,e1); |
61 | 836 } |
837 } | |
838 | |
839 int | |
840 circular_dependency(int t,int s,int *target,int *source) | |
841 { | |
842 int target0=*target; | |
843 int t1,sz,ty,s1; | |
844 while(target0) { | |
845 if (cadddr(target0)==s) { | |
846 t1=car(target0); | |
847 s=cadddr(target0); | |
848 sz=size(ty=caddr(target0)); | |
849 if(t==t1) { | |
850 #if DEBUG_PARALLEL_ASSIGN | |
851 printf("# circular dependency %d ty %d+%d sz %d\n",car(t1),ty,cadr(t1),sz); | |
852 #endif | |
853 return 1; | |
854 } | |
855 if ((s1=overrap(t1,sz,*source))) { | |
856 /* another overrap start over */ | |
857 return circular_dependency(t,s1,target,source); | |
858 } | |
859 } | |
860 target0=cadr(target0); | |
861 } | |
862 return 0; | |
863 } | |
864 | |
865 void | |
866 parallel_assign(int *target,int *source,int *processing,int *use) | |
867 { | |
868 int t,s,sz,ty,target0,s1; | |
869 while(*target) { | |
870 target0=*target; | |
871 while(target0) { | |
872 t=car(target0); s=cadddr(target0); | |
873 sz=size(ty=caddr(target0)); | |
874 if(car(t)==car(s) && cadr(t)==cadr(s)) { | |
875 /*½ñ¤¹þ¤ßÀ褬¼«Ê¬¼«¿È*/ | |
876 #if DEBUG_PARALLEL_ASSIGN | |
877 printf("# remove same %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz); | |
878 #endif | |
879 remove_target(target,t,use); | |
880 /* Ç˲õ¤µ¤ì¤Æ¤Ïº¤¤ë¤Î¤Ç¡¢source list¤«¤é¤Ï½ü¤«¤Ê¤¤ */ | |
881 } else if (!(s1=overrap(t,sz,*source))) { | |
882 /* ½Å¤Ê¤Ã¤Æ¤Ê¤¤¤Î¤Ç°Â¿´¤·¤Æ½ñ¤¹þ¤á¤ë */ | |
883 #if DEBUG_PARALLEL_ASSIGN | |
884 printf("# normal assign %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz); | |
885 #endif | |
83 | 886 g_expr_u(assign_expr0(t,s,ty,ty)); |
61 | 887 remove_target(target,t,use); remove0(source,s); |
888 } else { | |
889 if(circular_dependency(t,s1,target,source)) { | |
890 #if DEBUG_PARALLEL_ASSIGN | |
891 printf("# saving %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz); | |
892 #endif | |
893 remove_target(target,t,use); remove0(source,s); | |
894 save_target(t,s,target,use,sz,ty); | |
895 } | |
896 } | |
897 target0=cadr(target0); | |
898 } | |
899 } | |
900 } | |
901 | |
902 void | |
903 remove0(int *parent,int e) | |
904 { | |
905 int list; | |
906 while ((list=*parent)) { | |
907 if (car(list)==e) { | |
908 *parent= cadr(list); return; | |
909 } else { | |
910 parent=&cadr(list); | |
911 } | |
912 } | |
913 } | |
914 | |
105 | 915 /* |
61 | 916 void |
917 remove0_all(int *parent,int e) | |
918 { | |
919 int list; | |
920 while ((list=*parent)) { | |
921 if (car(list)==e) { | |
922 *parent= cadr(list); | |
923 } else { | |
924 parent=&cadr(list); | |
925 } | |
926 } | |
927 } | |
105 | 928 */ |
61 | 929 |
930 int | |
931 is_simple(int e1) | |
932 { | |
933 return ( | |
99 | 934 e1==CONST || e1==FNAME || e1==LVAR || e1==REGISTER ||e1==DREGISTER || |
195 | 935 e1==FREGISTER || e1==LREGISTER || |
81 | 936 e1==GVAR || e1==RGVAR || e1==RLVAR || e1==CRLVAR || e1==CRGVAR || |
195 | 937 e1==DRLVAR || e1==FRLVAR || e1==LRLVAR || |
165 | 938 e1==CURLVAR || e1==SURLVAR || e1==CURGVAR || e1==SURGVAR |
61 | 939 ); |
940 } | |
941 | |
942 int | |
943 is_same_type(int e1,int e2) | |
944 { | |
945 int ce1=car(e1); | |
946 int ce2=car(e2); | |
947 return ( | |
81 | 948 (ce1==LVAR && (ce2==RLVAR||ce2==CRLVAR||ce2==FRLVAR||ce2==DRLVAR)) |
165 | 949 || (ce1==LVAR && (ce2==SRLVAR||ce2==SURLVAR||ce2==CURLVAR)) |
81 | 950 || (ce2==LVAR && (ce1==RLVAR||ce1==CRLVAR||ce1==FRLVAR||ce1==DRLVAR)) |
165 | 951 || (ce2==LVAR && (ce1==SRLVAR||ce1==SURLVAR||ce1==CURLVAR)) |
195 | 952 || (ce2==LVAR && (ce1==LRLVAR)) |
81 | 953 || (ce1==GVAR && (ce2==RGVAR||ce2==CRGVAR||ce2==FRGVAR||ce2==DRGVAR)) |
165 | 954 || (ce1==GVAR && (ce2==SRGVAR||ce2==SURGVAR||ce2==CURGVAR)) |
81 | 955 || (ce2==GVAR && (ce1==RGVAR||ce1==CRGVAR||ce1==FRGVAR||ce1==DRGVAR)) |
165 | 956 || (ce2==GVAR && (ce1==SRGVAR||ce1==SURGVAR||ce1==CURGVAR)) |
195 | 957 || (ce2==GVAR && (ce1==LRGVAR)) |
61 | 958 ); |
959 } | |
960 | |
961 int | |
962 is_memory(int e1) | |
963 { | |
964 int ce1=car(e1); | |
965 return ( | |
195 | 966 ce1==LVAR ||ce1==RLVAR||ce1==CRLVAR || ce1==DRLVAR || ce1==LRLVAR || |
967 ce1==GVAR ||ce1==RGVAR||ce1==CRGVAR || ce1==DRGVAR || ce1==LRGVAR || | |
968 ce1==FRLVAR || ce1==FRGVAR || | |
165 | 969 ce1==CURGVAR ||ce1==SURGVAR||ce1==SRGVAR || |
219 | 970 ce1==REGISTER|| ce1==DREGISTER || ce1==FREGISTER || |
971 ce1==LREGISTER | |
61 | 972 ); |
973 } | |
974 | |
98 | 975 |
61 | 976 void |
977 jump(int e1, int env) | |
978 { | |
99 | 979 int e2,e3,e4,sz,arg_size,ty,regs,fregs; |
147 | 980 int t0,s0,r,reg; |
127 | 981 NMTBL *code0 = 0; |
61 | 982 int target = 0; |
983 int source = 0; | |
984 int processing = 0; | |
985 int use = 0; | |
986 | |
987 /* ¤Þ¤º¡¢¥µ¥¤¥º¤ò·×»»¤·¤Ê¤¬¤é¡¢·è¤Þ¤Ã¤¿·Á¤ËÍ¡£ */ | |
988 | |
99 | 989 arg_size = 0; regs = 0; |
990 fregs = 0; | |
61 | 991 for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) { |
992 e2 = car(e3); sz = size(ty=caddr(e3)); | |
138 | 993 if (scalar(ty) && (r = get_input_register_var(regs,0,1))) { |
994 target=list4(r,target,ty,e2); regs++; | |
995 } else if (ty==FLOAT && (r = get_input_dregister_var(fregs,0,1,0))) { | |
996 target=list4(r, target,ty,e2); fregs++; | |
997 } else if (ty==DOUBLE && (r = get_input_dregister_var(fregs,0,1,1))) { | |
998 target=list4(r, target,ty,e2); fregs++; | |
61 | 999 } else { |
1000 target=list4(list2(LVAR,0), target,ty,e2); | |
1001 } | |
128 | 1002 /* keep arg space for register variables */ |
1003 arg_size += sz; | |
61 | 1004 #if DEBUG_PARALLEL_ASSIGN |
1005 printf("# target %d ty %d+%d sz %d\n",car(car(target)),ty,cadr(car(target)),sz); | |
1006 #endif | |
1007 } | |
1008 | |
1009 /* disp ¤òÈô¤ÓÀè»÷¹ç¤ï¤»¤Æ½¤Àµ */ | |
98 | 1010 if (is_code(fnptr)) { |
61 | 1011 if (-arg_size<disp) disp = -arg_size; |
1012 } else { | |
1013 if (disp_offset-arg_size<disp) disp = disp_offset-arg_size; | |
1014 } | |
1015 | |
1016 /* Ê£»¨¤Ê¼°¤òÁ°¤â¤Ã¤Æ·×»»¤·¤Æ¤ª¤¯ */ | |
1017 /* ɬÍפʤé¶É½êÊÑ¿ô¤òÍѤ¤¤ë¡£ */ | |
1018 /* ¶É½êÊÑ¿ô¤Ø¤Î¥ª¥Õ¥»¥Ã¥È¤ò³Ð¤¨¤Æ¤ª¤¯ */ | |
1019 | |
1020 for (e2 = target; e2; e2 = cadr(e2)) { | |
1021 t0=car(e2); s0=cadddr(e2); | |
1022 sz=size(ty=caddr(e2)); | |
1023 if(car(t0)==LVAR) { | |
1024 /* ¤³¤³¤Ç¡¢½ñ¹þÀ襢¥É¥ì¥¹¤ò·è¤á¤ë */ | |
1025 cadr(t0)=-arg_size; | |
1026 } | |
128 | 1027 arg_size-=sz; |
61 | 1028 if (!is_simple(car(s0))) { |
94 | 1029 g_expr_u(assign_expr0((e4=list2(LVAR,new_lvar(sz))),s0,ty,ty)); |
117 | 1030 use=list3(ty,use,e1); |
61 | 1031 cadddr(e2)=e4; |
1032 s0=e4; | |
1033 } else if (is_same_type(t0,s0)) { | |
1034 if(cadr(t0)==cadr(s0)) { | |
1035 #if DEBUG_PARALLEL_ASSIGN | |
1036 printf("# remove same memory %d ty %d+%d sz %d\n",car(t0),ty,cadr(t0),sz); | |
1037 #endif | |
269 | 1038 /* we should check size also (but currently useless) */ |
61 | 1039 remove0(&target,t0); |
1040 /* still we have source to avoid overwrite */ | |
1041 } | |
1042 } | |
1043 if(is_memory(s0)) { | |
1044 source=list3(s0,source,sz); | |
1045 #if DEBUG_PARALLEL_ASSIGN | |
1046 printf("# source %d ty %d+%d sz %d\n",car(car(source)),ty,cadr(car(source)),sz); | |
1047 #endif | |
1048 } | |
1049 } | |
1050 | |
1051 /* compute jump address */ | |
1052 e2 = cadr(e1); | |
1053 if (car(e2) == FNAME) { | |
1054 code0=(NMTBL *)cadr(e2); | |
98 | 1055 if (!is_code(code0)) { |
61 | 1056 error(TYERR); return; |
1057 } | |
1058 } else { /* indirect */ | |
1059 g_expr(e2); | |
1060 emit_push(); | |
1061 } | |
1062 if (env) { | |
1063 g_expr(env); | |
1064 emit_push(); | |
1065 } | |
1066 | |
1067 /* ÊÂÎóÂåÆþ¤ò¼Â¹Ô */ | |
1068 parallel_assign(&target,&source,&processing,&use); | |
1069 while (use) { | |
147 | 1070 reg = car(caddr(use)); |
195 | 1071 if (reg==REGISTER||reg==FREGISTER||reg==DREGISTER||reg==LREGISTER) |
99 | 1072 free_register(cadr(caddr(use))); |
117 | 1073 else if (car(caddr(use))==LVAR) |
1074 free_lvar(cadr(caddr(use))); | |
99 | 1075 use=cadr(use); |
61 | 1076 } |
1077 if(target) error(-1); | |
1078 | |
1079 if (env) { | |
1080 /* change the frame pointer */ | |
1081 e3 = emit_pop(0); | |
1082 code_frame_pointer(e3); | |
1083 emit_pop_free(e3); | |
98 | 1084 } else if (is_function(fnptr)) { |
128 | 1085 if (car(e2) != FNAME) { |
1086 e2 = emit_pop(0); | |
1087 code_fix_frame_pointer(disp_offset); | |
1088 code_indirect_jmp(e2); | |
1089 emit_pop_free(e2); | |
1090 return; | |
1091 } | |
61 | 1092 code_fix_frame_pointer(disp_offset); |
1093 } | |
1094 | |
1095 if (car(e2) == FNAME) { | |
1096 code_jmp(code0->nm); | |
1097 } else { | |
1098 e2 = emit_pop(0); | |
1099 code_indirect_jmp(e2); | |
1100 emit_pop_free(e2); | |
1101 } | |
1102 } | |
1103 | |
1104 void | |
1105 machinop(int e1) | |
1106 { | |
240 | 1107 int e2,e3,op; |
61 | 1108 |
1109 e2 = cadr(e1); | |
1110 op = car(e1); | |
1111 e3 = caddr(e1); | |
240 | 1112 if (code_const_op_p(op,e3)) { |
189 | 1113 g_expr(e2); |
240 | 1114 oprtc(op,USE_CREG,e3); |
189 | 1115 return; |
1116 } | |
61 | 1117 g_expr(e3); |
1118 emit_push(); | |
1119 g_expr(e2); | |
221 | 1120 tosop(op,USE_CREG,(e2=pop_register())); |
61 | 1121 emit_pop_free(e2); |
1122 return; | |
1123 } | |
1124 | |
195 | 1125 #if FLOAT_CODE |
81 | 1126 void |
133 | 1127 dmachinop(int e1,int d) |
81 | 1128 { |
1129 int e2,e3,op; | |
1130 | |
1131 e2 = cadr(e1); | |
1132 op = car(e1); | |
1133 e3 = caddr(e1); | |
1134 g_expr(e3); | |
133 | 1135 emit_dpush(d); |
81 | 1136 g_expr(e2); |
221 | 1137 dtosop(car(e1),USE_CREG,(e2=emit_dpop(d))); |
138 | 1138 emit_dpop_free(e2,d); |
81 | 1139 return; |
1140 } | |
195 | 1141 #endif |
1142 | |
1143 #if LONGLONG_CODE | |
1144 void | |
1145 lmachinop(int e1) | |
1146 { | |
1147 int e2,e3,op; | |
1148 | |
1149 e2 = cadr(e1); | |
1150 op = car(e1); | |
1151 e3 = caddr(e1); | |
213 | 1152 if (code_lconst_op_p(op,e3)) { |
1153 g_expr(e2); | |
221 | 1154 loprtc(op,USE_CREG,e3); |
213 | 1155 return; |
1156 } | |
195 | 1157 g_expr(e3); |
1158 emit_lpush(); | |
1159 g_expr(e2); | |
221 | 1160 ltosop(car(e1),USE_CREG,(e2=emit_lpop())); |
195 | 1161 emit_lpop_free(e2); |
1162 return; | |
1163 } | |
1164 #endif | |
81 | 1165 |
61 | 1166 void |
1167 sassign(int e1) | |
1168 { | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1169 int e2,e3,e4,sz,xreg,det,offset; |
61 | 1170 |
1171 /* structure assignment */ | |
1172 e2 = cadr(e1); /* pointer variable to the struct */ | |
1173 e3 = cadr(e2); /* offset of the variable (distination) */ | |
1174 e4 = caddr(e1); /* right value (source) */ | |
1175 sz = cadddr(e1); /* size of struct or union */ | |
269 | 1176 if (is_same_type(e2,e4)&&cadr(e2)==cadr(e4)) { |
1177 if (use) g_expr(e4); | |
1178 return; | |
1179 } | |
61 | 1180 g_expr(e4); |
1181 emit_push(); | |
1182 g_expr(e2); | |
1183 xreg = emit_pop(0); | |
1184 /* °ìÈÌŪ¤Ë¤Ï¥³¥Ô¡¼¤Î¥ª¡¼¥Ð¥é¥Ã¥×¤Î¾õ¶·¤Ï¼Â¹Ô»þ¤Ë¤·¤«¤ï¤«¤é¤Ê¤¤ */ | |
1185 /* ¤·¤«¤·¡¢¤ï¤«¤ë¾ì¹ç¤â¤¢¤ë */ | |
1186 if (car(e4)==RSTRUCT) e4=cadr(e4); | |
1187 if (is_same_type(e2,e4)) { | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1188 if(cadr(e2)<cadr(e4)) { offset=sz; sz=-sz;} |
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1189 det=1; |
61 | 1190 } else { |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1191 det = 0; offset=0; |
61 | 1192 } |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1193 emit_copy(xreg,USE_CREG,sz,offset,1,det); |
61 | 1194 emit_pop_free(xreg); |
1195 return; | |
1196 } | |
1197 | |
269 | 1198 static void |
118 | 1199 assign_opt(int e5,int e2,int e4,int byte) |
1200 { | |
1201 int reg; | |
1202 /* e2=e4 */ | |
1203 if (e5==REGISTER) { | |
1204 reg = cadr(e4); | |
1205 switch(car(e2)) { | |
1206 case GVAR: code_assign_gvar(e2,reg,byte); return; | |
119 | 1207 case LVAR: code_assign_lvar(cadr(e2),reg,byte); return; |
118 | 1208 case REGISTER: code_assign_register(cadr(e2),byte,reg); return; |
1209 } | |
1210 g_expr(e2); | |
233 | 1211 code_assign(USE_CREG,byte,reg); |
118 | 1212 return; |
1213 } | |
1214 /* e2 is register now */ | |
1215 if (car(e2)!=REGISTER) error(-1); | |
1216 reg = cadr(e2); | |
1217 switch(e5) { | |
162 | 1218 case CRGVAR: |
165 | 1219 case CURGVAR: code_crgvar(e4,reg,e5==CRGVAR,1); return; |
1220 case SRGVAR: | |
1221 case SURGVAR: code_crgvar(e4,reg,e5==SRGVAR,size_of_short); return; | |
118 | 1222 case RGVAR: code_rgvar(e4,reg); return; |
162 | 1223 case CRLVAR: |
165 | 1224 case CURLVAR: code_crlvar(cadr(e4),reg,e5==CRLVAR,1); return; |
1225 case SRLVAR: | |
1226 case SURLVAR: code_crlvar(cadr(e4),reg,e5==SRLVAR,size_of_short); return; | |
119 | 1227 case RLVAR: code_rlvar(cadr(e4),reg); return; |
118 | 1228 case GVAR: code_gvar(e4,reg); return; |
119 | 1229 case LVAR: code_lvar(cadr(e4),reg); return; |
118 | 1230 case CONST: code_const(cadr(e4),reg); return; |
1231 case ADDRESS: | |
1232 if (car(cadr(e4))==STRING) code_string(cadr(e4),reg); | |
1233 else code_gvar(cadr(e4),reg); | |
1234 return; | |
1235 case FNAME: code_fname((NMTBL*)cadr(e4),reg); return; | |
1236 case STRING: code_string(e4,reg); return; | |
135 | 1237 default: error(-1); |
118 | 1238 } |
1239 } | |
1240 | |
1241 void | |
61 | 1242 assign(int e1) |
1243 { | |
118 | 1244 int e2,e4,byte,e5; |
61 | 1245 |
166 | 1246 byte=(car(e1) == CASS)?1:(car(e1) == SASS)?size_of_short:0; |
61 | 1247 /* e2=e4 */ |
1248 e2 = cadr(e1); | |
118 | 1249 e4 = caddr(e1);e5=car(e4); |
269 | 1250 if (is_same_type(e2,e4)&&cadr(e2)==cadr(e4)) { |
1251 if (use) g_expr(e4); | |
1252 return; | |
1253 } | |
118 | 1254 if (!use && ( |
1255 (e5==REGISTER) || | |
1256 (car(e2)==REGISTER&&( | |
1257 e5== CRGVAR || e5== CRLVAR || e5== RGVAR || e5== RLVAR || | |
162 | 1258 e5== CURGVAR || e5== CURLVAR || |
165 | 1259 e5== SURGVAR || e5== SURLVAR || |
118 | 1260 e5== GVAR || e5== LVAR || |
1261 e5== CONST || e5== FNAME || e5== STRING || | |
1262 (e5==ADDRESS&&car(cadr(e4))==STRING) || | |
1263 (e5==ADDRESS&&car(cadr(e4))==GVAR) )))) { | |
1264 assign_opt(e5,e2,e4,byte); | |
1265 return; | |
1266 } | |
61 | 1267 switch(car(e2)) { |
1268 case GVAR: /* i=3 */ | |
1269 g_expr(e4); | |
221 | 1270 code_assign_gvar(e2,USE_CREG,byte); |
61 | 1271 return; |
1272 case LVAR: | |
1273 g_expr(e4); | |
221 | 1274 code_assign_lvar(cadr(e2),USE_CREG,byte); |
61 | 1275 return; |
1276 case REGISTER: | |
1277 g_expr(e4); | |
221 | 1278 code_assign_register(cadr(e2),byte,USE_CREG); |
61 | 1279 return; |
1280 } | |
1281 g_expr(e2); | |
1282 emit_push(); | |
1283 g_expr(e4); | |
1284 e2 = emit_pop(0); | |
221 | 1285 code_assign(e2,byte,USE_CREG); |
61 | 1286 emit_pop_free(e2); |
1287 return; | |
1288 } | |
1289 | |
195 | 1290 #if FLOAT_CODE |
1291 | |
269 | 1292 static void |
118 | 1293 dassign_opt(int e5,int e2,int e4,int d) |
1294 { | |
1295 int reg; | |
1296 /* e2=e4 */ | |
138 | 1297 if (e5==DREGISTER||e5==FREGISTER) { |
118 | 1298 reg = cadr(e4); |
1299 switch(car(e2)) { | |
1300 case GVAR: /* i=3 */ | |
1301 code_dassign_gvar(e2,reg,d); | |
1302 return; | |
1303 case LVAR: | |
119 | 1304 code_dassign_lvar(cadr(e2),reg,d); |
118 | 1305 return; |
1306 case DREGISTER: | |
138 | 1307 case FREGISTER: |
118 | 1308 if (reg!=cadr(e2)) |
138 | 1309 code_dassign_dregister(cadr(e2),d,reg); |
118 | 1310 return; |
135 | 1311 default: |
1312 error(-1); | |
118 | 1313 } |
1314 } | |
1315 /* e2 is register now */ | |
138 | 1316 if (car(e2)!=DREGISTER && car(e2)!=FREGISTER) error(-1); |
118 | 1317 reg = cadr(e2); |
1318 switch(e5) { | |
135 | 1319 case FRGVAR: |
118 | 1320 case DRGVAR: code_drgvar(e4,d,reg); return; |
135 | 1321 case FRLVAR: |
119 | 1322 case DRLVAR: code_drlvar(cadr(e4),d,reg); return; |
135 | 1323 case FCONST: |
264 | 1324 case DCONST: code_dconst(e4,reg,d); return; |
135 | 1325 default: |
118 | 1326 error(-1); |
1327 } | |
1328 } | |
1329 | |
1330 void | |
81 | 1331 dassign(int e1) |
1332 { | |
118 | 1333 int e2,e3,e4,d,e5; |
81 | 1334 |
1335 /* e2=e4 */ | |
1336 e2 = cadr(e1); | |
1337 e3 = cadr(e2); | |
118 | 1338 e4 = caddr(e1); e5=car(e4); |
269 | 1339 if (is_same_type(e2,e4)&&cadr(e2)==cadr(e4)) { |
1340 if (use) g_expr(e4); | |
1341 return; | |
1342 } | |
249 | 1343 if (car(e1)==DASS) d=1; |
1344 else if (car(e1)==FASS) d=0; | |
1345 else error(-1); | |
118 | 1346 if (!use && ( |
138 | 1347 (e5==DREGISTER) || (e5==FREGISTER) || |
133 | 1348 (car(e2)==DREGISTER&&(e5==DRGVAR||e5==DRLVAR||e5==DCONST))|| |
249 | 1349 (car(e2)==FREGISTER&&(e5==FRGVAR||e5==FRLVAR||e5==FCONST)) |
118 | 1350 )) { |
1351 dassign_opt(e5,e2,e4,d); | |
1352 return; | |
1353 } | |
81 | 1354 switch(car(e2)) { |
82 | 1355 case GVAR: |
81 | 1356 g_expr(e4); |
221 | 1357 code_dassign_gvar(e2,USE_CREG,d); |
81 | 1358 return; |
1359 case LVAR: | |
1360 g_expr(e4); | |
221 | 1361 code_dassign_lvar(cadr(e2),USE_CREG,d); |
81 | 1362 return; |
111 | 1363 case DREGISTER: |
138 | 1364 case FREGISTER: |
111 | 1365 g_expr(e4); |
221 | 1366 code_dassign_dregister(cadr(e2),d,USE_CREG); |
111 | 1367 return; |
81 | 1368 } |
1369 g_expr(e2); | |
82 | 1370 emit_push(); |
81 | 1371 g_expr(e4); |
82 | 1372 e2 = emit_pop(0); |
221 | 1373 code_dassign(e2,USE_CREG,d); |
82 | 1374 emit_pop_free(e2); |
81 | 1375 return; |
1376 } | |
1377 | |
195 | 1378 #endif |
1379 | |
1380 #if LONGLONG_CODE | |
1381 | |
1382 void | |
1383 lassign_opt(int e5,int e2,int e4) | |
1384 { | |
1385 int reg; | |
1386 /* e2=e4 */ | |
1387 if (e5==LREGISTER) { | |
1388 reg = cadr(e4); | |
1389 switch(car(e2)) { | |
1390 case GVAR: /* i=3 */ | |
1391 code_lassign_gvar(e2,reg); | |
1392 return; | |
1393 case LVAR: | |
1394 code_lassign_lvar(cadr(e2),reg); | |
1395 return; | |
1396 case LREGISTER: | |
1397 if (reg!=cadr(e2)) | |
1398 code_lassign_lregister(cadr(e2),reg); | |
1399 return; | |
1400 default: | |
1401 error(-1); | |
1402 } | |
1403 } | |
1404 /* e2 is register now */ | |
1405 if (car(e2)!=LREGISTER) error(-1); | |
1406 reg = cadr(e2); | |
1407 switch(e5) { | |
1408 case LRGVAR: code_lrgvar(e4,reg); return; | |
1409 case LRLVAR: code_lrlvar(cadr(e4),reg); return; | |
1410 case LCONST: code_lconst(e4,reg); return; | |
1411 default: | |
1412 error(-1); | |
1413 } | |
1414 } | |
1415 | |
1416 void | |
1417 lassign(int e1) | |
1418 { | |
1419 int e2,e3,e4,e5; | |
1420 | |
1421 /* e2=e4 */ | |
1422 e2 = cadr(e1); | |
1423 e3 = cadr(e2); | |
1424 e4 = caddr(e1); e5=car(e4); | |
269 | 1425 if (is_same_type(e2,e4)&&cadr(e2)==cadr(e4)) { |
1426 if (use) g_expr(e4); | |
1427 return; | |
1428 } | |
195 | 1429 if (!use && ( |
1430 (e5==LREGISTER) || | |
1431 (car(e2)==LREGISTER&&(e5==LRGVAR||e5==LRLVAR||e5==LCONST)) | |
1432 )) { | |
1433 lassign_opt(e5,e2,e4); | |
1434 return; | |
1435 } | |
1436 switch(car(e2)) { | |
1437 case GVAR: | |
1438 g_expr(e4); | |
221 | 1439 code_lassign_gvar(e2,USE_CREG); |
195 | 1440 return; |
1441 case LVAR: | |
1442 g_expr(e4); | |
221 | 1443 code_lassign_lvar(cadr(e2),USE_CREG); |
195 | 1444 return; |
1445 case LREGISTER: | |
1446 g_expr(e4); | |
221 | 1447 code_lassign_lregister(cadr(e2),USE_CREG); |
195 | 1448 return; |
1449 } | |
1450 g_expr(e2); | |
219 | 1451 emit_push(); |
195 | 1452 g_expr(e4); |
219 | 1453 e2 = emit_pop(0); |
221 | 1454 code_lassign(e2,USE_CREG); |
219 | 1455 emit_pop_free(e2); |
195 | 1456 return; |
1457 } | |
1458 | |
1459 #endif | |
1460 | |
81 | 1461 void |
61 | 1462 assop(int e1) |
1463 { | |
165 | 1464 int e2,e3,byte,op,sign,size; |
255 | 1465 int n,t; |
61 | 1466 |
1467 /* e2 op= e3 */ | |
162 | 1468 if (car(e1) == CUASSOP) { |
165 | 1469 byte = 1; sign = 0; size = 1; |
162 | 1470 } else if (car(e1) == CASSOP) { |
165 | 1471 byte = 1; sign = 1; size = 1; |
1472 } else if (car(e1) == SUASSOP) { | |
1473 byte = size_of_short; sign = 0; size = size_of_short; | |
1474 } else if (car(e1) == SASSOP) { | |
1475 byte = size_of_short; sign = 1; size = size_of_short; | |
162 | 1476 } else { |
165 | 1477 byte = 0; sign = 1; size = size_of_int; |
162 | 1478 } |
61 | 1479 e2 = cadr(e1); |
1480 if (car(e2)==INDIRECT) e2=cadr(e2); | |
1481 e3 = caddr(e1); | |
1482 op = cadddr(e1); | |
1483 | |
285 | 1484 if (car(e2)==REGISTER) { |
1485 if (code_const_op_p(op,e3)) { | |
1486 oprtc(op,cadr(e2),e3); | |
1487 } else { | |
1488 g_expr(e3); | |
1489 code_register_assop(cadr(e2),USE_CREG,op,byte); | |
1490 } | |
1491 if (use) { | |
1492 code_register(cadr(e2),USE_CREG); | |
1493 } | |
1494 return; | |
1495 } | |
255 | 1496 if (car(e3)==CONST) { |
1497 /* e2 = e2 op e3; */ | |
1498 t = sign?INT:UNSIGNED; | |
285 | 1499 // oprtc expected |
1500 if (car(e2)==LVAR||car(e2)==GVAR) { | |
255 | 1501 g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); |
1502 return; | |
1503 } | |
1504 /* new = &e2 */ | |
1505 /* *new = *new op e3 */ | |
1506 n = list2(LVAR,new_lvar(size_of_int)); | |
1507 g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT)); | |
1508 g_expr(assign_expr0(list2(INDIRECT,n),list3(op,n,e3),t,t)); | |
1509 free_lvar(cadr(n)); | |
1510 return; | |
1511 } | |
61 | 1512 g_expr(e3); |
1513 emit_push(); | |
1514 g_expr(e2); | |
221 | 1515 code_assop(op,USE_CREG,byte,sign); |
61 | 1516 return; |
1517 } | |
1518 | |
195 | 1519 #if FLOAT_CODE |
1520 | |
81 | 1521 void |
1522 dassop(int e1) | |
1523 { | |
83 | 1524 int e2,e3,op,d; |
81 | 1525 |
83 | 1526 /* e2 op= e3 */ |
1527 d = (car(e1) == DASSOP); | |
1528 e2 = cadr(e1); | |
1529 if (car(e2)==INDIRECT) e2=cadr(e2); | |
1530 e3 = caddr(e1); | |
1531 op = cadddr(e1); | |
1532 | |
1533 g_expr(e3); | |
144 | 1534 if (car(e2)==DREGISTER||car(e2)==FREGISTER) { |
273 | 1535 emit_dpush(d); |
219 | 1536 code_register_dassop(cadr(e2),op,d); |
273 | 1537 if (use) |
1538 code_dregister(cadr(e2),USE_CREG,d); | |
1539 return; | |
144 | 1540 } |
238 | 1541 emit_dpush(d); |
1542 g_expr(e2); | |
221 | 1543 code_dassop(op,USE_CREG,d); |
83 | 1544 return; |
81 | 1545 } |
61 | 1546 |
195 | 1547 #endif |
1548 | |
1549 #if LONGLONG_CODE | |
1550 | |
238 | 1551 static int |
1552 long_sign(int op) | |
1553 { | |
1554 return (op==LUDIV||op==LUMOD||op==LULSHIFT||op==LURSHIFT)?ULONGLONG:LONGLONG; | |
1555 } | |
1556 | |
195 | 1557 void |
1558 lassop(int e1) | |
1559 { | |
1560 int e2,e3,op; | |
238 | 1561 int n,t; |
195 | 1562 |
1563 /* e2 op= e3 */ | |
1564 e2 = cadr(e1); | |
1565 if (car(e2)==INDIRECT) e2=cadr(e2); | |
1566 e3 = caddr(e1); | |
1567 op = cadddr(e1); | |
1568 | |
286 | 1569 if (car(e2)==LREGISTER) { |
285 | 1570 if (code_lconst_op_p(op,e3)) { |
1571 loprtc(op,cadr(e2),e3); | |
286 | 1572 if (use) { |
1573 code_lregister(cadr(e2),USE_CREG); | |
1574 } | |
1575 return; | |
1576 } | |
1577 if (code_lassop_p) { | |
285 | 1578 g_expr(e3); |
1579 emit_lpush(); | |
1580 code_register_lassop(cadr(e2),op); | |
286 | 1581 if (use) { |
1582 code_lregister(cadr(e2),USE_CREG); | |
1583 } | |
1584 return; | |
285 | 1585 } |
1586 } | |
238 | 1587 if (!code_lassop_p||car(e3)==LCONST) { |
1588 /* e2 = e2 op e3; */ | |
1589 t = long_sign(op); | |
286 | 1590 if (car(e2)==LREGISTER||car(e2)==LVAR||car(e2)==GVAR) { |
238 | 1591 g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); |
239 | 1592 return; |
238 | 1593 } |
1594 /* new = &e2 */ | |
1595 /* *new = *new op e3 */ | |
1596 n = list2(LVAR,new_lvar(size_of_int)); | |
239 | 1597 g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT)); |
238 | 1598 g_expr(assign_expr0(list2(INDIRECT,n),list3(op,n,e3),t,t)); |
1599 free_lvar(cadr(n)); | |
1600 return; | |
1601 } | |
1602 | |
195 | 1603 g_expr(e3); |
286 | 1604 if (car(e2)==LREGISTER) { |
1605 emit_lpush(); | |
1606 code_register_lassop(cadr(e2),op); | |
1607 if (use) | |
1608 code_lregister(cadr(e2),USE_CREG); | |
1609 return; | |
1610 } | |
238 | 1611 emit_lpush(); |
1612 g_expr(e2); | |
221 | 1613 code_lassop(op,USE_CREG); |
195 | 1614 return; |
1615 } | |
1616 | |
1617 #endif | |
1618 | |
95 | 1619 void |
287 | 1620 cmpdimm(int e, int csreg,int label,int cond) |
95 | 1621 { |
287 | 1622 code_cmpdimm(e, csreg,label,cond); |
95 | 1623 } |
1624 | |
1625 int | |
1626 csvalue() | |
1627 { | |
1628 return code_csvalue(); | |
1629 } | |
1630 | |
1631 | |
61 | 1632 int |
1633 fwdlabel(void) | |
1634 { | |
1635 return labelno++; | |
1636 } | |
1637 | |
1638 void | |
1639 fwddef(int l) | |
1640 { | |
1641 control=1; | |
66 | 1642 if (!chk) |
92 | 1643 code_label(l); |
61 | 1644 } |
1645 | |
1646 int | |
1647 backdef(void) | |
1648 { | |
1649 control=1; | |
66 | 1650 if (!chk) |
92 | 1651 code_label(labelno); |
61 | 1652 return labelno++; |
1653 } | |
1654 | |
1655 void | |
1656 def_label(int cslabel, int dlabel) | |
1657 { | |
1658 int fl; | |
1659 | |
1660 fl = 0; | |
1661 if (control) { | |
1662 jmp(fl=fwdlabel()); | |
1663 } | |
1664 fwddef(cslabel); | |
1665 if (dlabel) | |
1666 jmp(dlabel); | |
1667 if (fl) { | |
1668 fwddef(fl); | |
1669 } | |
1670 } | |
1671 | |
1672 void | |
1673 gen_source(char *s) | |
1674 { | |
1675 printf("%s",s); | |
1676 } | |
1677 | |
1678 void | |
1679 ret(void) | |
1680 { | |
107 | 1681 code_set_return_register(1); |
61 | 1682 jmp(retlabel); |
1683 } | |
1684 | |
66 | 1685 void |
1686 opening(char *filename) | |
1687 { | |
1688 emit_init(); | |
1689 if (!chk) | |
1690 code_opening(filename); | |
1691 } | |
1692 | |
1693 void | |
1694 closing() | |
1695 { | |
1696 if (!chk) | |
1697 code_closing(); | |
1698 } | |
1699 | |
99 | 1700 int |
1701 contains_in_list(int e,int type) | |
1702 { | |
1703 while(e) { | |
1704 if(contains(car(e),type)) return 1; | |
1705 e = cadr(e); | |
1706 } | |
1707 return 0; | |
1708 } | |
1709 | |
1710 int | |
1711 contains(int e,int type) | |
1712 { | |
1713 while(e) { | |
1714 if (car(e)==type) return 1; | |
256
d80e6387c539
powerpc function call complex arugment pre computation.
kono
parents:
255
diff
changeset
|
1715 if (!car(e)) return 0; |
164 | 1716 if (LIST_ARGS(car(e))){ |
99 | 1717 /* list arguments */ |
1718 return contains_in_list(caddr(e),type); | |
164 | 1719 } else if (UNARY_ARGS(car(e))) { |
99 | 1720 /* unary operators */ |
1721 e = cadr(e); | |
1722 continue; | |
164 | 1723 } else if (BINARY_ARGS(car(e))) { |
99 | 1724 /* biary operators */ |
1725 if (contains(cadr(e),type)) return 1; | |
1726 e = caddr(e); | |
1727 continue; | |
164 | 1728 } else if (TARNARY_ARGS(car(e))) { |
99 | 1729 /* tarary operators */ |
1730 if (contains(cadr(e), type)) return 1; | |
1731 if (contains(caddr(e),type)) return 1; | |
1732 e = cadddr(e); | |
1733 continue; | |
164 | 1734 } else if (NULLARY_ARGS(car(e))) { |
135 | 1735 /* nullary operators */ |
1736 return 0; | |
164 | 1737 } else { |
135 | 1738 fprintf(stderr,"Unknown Tree ID %d\n",car(e)); |
1739 error(-1); | |
99 | 1740 return 0; |
1741 } | |
1742 } | |
1743 return 0; | |
1744 } | |
1745 | |
223 | 1746 int |
1747 contains_in_list_p(int e,int (*p)(int)) | |
1748 { | |
1749 while(e) { | |
1750 if(contains_p(car(e),p)) return 1; | |
1751 e = cadr(e); | |
1752 } | |
1753 return 0; | |
1754 } | |
1755 | |
1756 int | |
1757 contains_p(int e,int (*p)(int)) | |
1758 { | |
1759 while(e) { | |
256
d80e6387c539
powerpc function call complex arugment pre computation.
kono
parents:
255
diff
changeset
|
1760 if (!car(e)) return 0; |
223 | 1761 if (p(car(e))) return 1; |
1762 if (LIST_ARGS(car(e))){ | |
1763 /* list arguments */ | |
1764 return contains_in_list_p(caddr(e),p); | |
1765 } else if (UNARY_ARGS(car(e))) { | |
1766 /* unary operators */ | |
1767 e = cadr(e); | |
1768 continue; | |
1769 } else if (BINARY_ARGS(car(e))) { | |
1770 /* biary operators */ | |
1771 if (contains_p(cadr(e),p)) return 1; | |
1772 e = caddr(e); | |
1773 continue; | |
1774 } else if (TARNARY_ARGS(car(e))) { | |
1775 /* tarary operators */ | |
1776 if (contains_p(cadr(e), p)) return 1; | |
1777 if (contains_p(caddr(e),p)) return 1; | |
1778 e = cadddr(e); | |
1779 continue; | |
1780 } else if (NULLARY_ARGS(car(e))) { | |
1781 /* nullary operators */ | |
1782 return 0; | |
1783 } else { | |
1784 fprintf(stderr,"Unknown Tree ID %d\n",car(e)); | |
1785 error(-1); | |
1786 return 0; | |
1787 } | |
1788 } | |
1789 return 0; | |
1790 } | |
1791 | |
61 | 1792 /* end */ |