Mercurial > hg > CbC > old > device
annotate mc-codegen.c @ 297:0f79c95df73a
switch index no compile error
author | kono |
---|---|
date | Sun, 06 Jun 2004 20:19:36 +0900 |
parents | 284aa4eaab0d |
children | 117baacd1ed0 |
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 | |
61 | 653 |
105 | 654 static int |
655 register_to_lvar(int e) | |
656 { | |
657 error(REG_ERR); | |
658 return 0; | |
659 #if 0 | |
660 ÅÓÃæ¤Ç¥ì¥¸¥¹¥¿¤«¤éLVAR¤ËÊѹ¹¤·¤Æ¤â¡¢´Ö¤Ë¹ç¤ï¤Ê¤¤¡£ | |
661 | |
662 NMTBL *n = (NMTBL*)caddr(e); | |
663 int reg = cadr(e); | |
664 int tag = car(e); | |
665 int lvar; | |
666 int t; | |
667 if (!n||n==&null_nptr) error(REG_ERR); | |
668 if (tag==REGISTER) { | |
669 n->dsp = new_lvar(size_of_int); | |
670 t = INT; | |
671 } else if (tag==DREGISTER) { | |
672 n->dsp = new_lvar(size_of_double); | |
673 t = DOUBLE; | |
138 | 674 } else if (tag==FREGISTER) { |
675 n->dsp = new_lvar(size_of_float); | |
676 t = DOUBLE; | |
195 | 677 } else if (tag==LREGISTER) { |
678 n->dsp = new_lvar(size_of_longlong); | |
679 t = LONGLONG; | |
105 | 680 } else error(-1); |
681 n->sc = LVAR; | |
682 lvar = list2(LVAR,n->dsp); | |
683 g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),t,t)); | |
195 | 684 if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER||tag==LREGISTER) { |
105 | 685 free_register(reg); |
686 return g_expr0(lvar); | |
687 #endif | |
688 } | |
689 | |
277 | 690 // parallel assignment of registers. |
691 // | |
692 // target = list3(target_regnum,next,source_regnum); | |
693 | |
694 void | |
695 parallel_rassign(int assigns) | |
696 { | |
697 int free,tmp,tmp_target,remains,t0,t2,src; | |
698 tmp = 0; | |
699 for(;;) { | |
700 remains = 0; | |
701 // find free target | |
702 for(free=assigns;free;free=cadr(free)) { | |
703 if (!caddr(free)) continue; // already done | |
704 remains++; | |
705 t0 = car(free); // target register | |
706 // check target is free | |
707 for(src=assigns;src;src=cadr(src)) { | |
708 if ((t2=caddr(src)) && t0==t2) break; // target is in source | |
709 } | |
710 if (src==0) { | |
711 break; // free is a free target | |
712 } | |
713 } | |
714 if (remains==0) { | |
715 if (tmp) { | |
716 code_rlvar(tmp,tmp_target); | |
717 } | |
718 return; | |
719 } | |
720 if (free) { // free target | |
721 if (t0!=caddr(free)) | |
722 code_assign_register(t0,0,caddr(free)); | |
723 } else { // no free target | |
724 for(free=assigns;free;free=cadr(free)) { | |
725 if (caddr(free)) break; // not yet done | |
726 } | |
727 if (!free) error(-1); | |
728 tmp = new_lvar(size_of_int); | |
729 tmp_target = car(free); | |
730 code_assign_lvar(tmp,caddr(free),0); | |
731 } | |
732 caddr(free)=0; // mark it done | |
733 } | |
734 } | |
735 | |
61 | 736 /* goto arguments list */ |
737 /* target list4(list2(tag,disp),cdr,ty,source_expr) */ | |
738 /* source expr=listn(tag,...) */ | |
739 /* source (after) list2(tag,disp) */ | |
740 /* source list list3(e,cdr,sz) */ | |
741 | |
284 | 742 #define DEBUG_PARALLEL_ASSIGN 0 |
61 | 743 |
744 int | |
745 overrap(int t,int sz,int source) | |
746 { | |
747 int s,s0,s1; | |
748 int t0=cadr(t); | |
749 int t1=t0+sz; | |
750 for(;source;source=cadr(source)) { | |
751 s=car(source); s0=cadr(s); | |
752 if(car(s)==REGISTER && car(t)==REGISTER) { | |
753 if(s0==t0) return s; | |
754 } else if (is_same_type(s,t)) { | |
755 s1=s0+caddr(source); | |
756 #if DEBUG_PARALLEL_ASSIGN>1 | |
757 printf("# ovedrrap source %d t0 %d t1 %d\n",car(car(t)),t0,t1); | |
758 printf("# ovedrrap target %d s0 %d s1 %d\n",car(car(source)),s0,s1); | |
759 printf("# ovedrrap equal = %d\n",((t0<=s0&&s0<t1)||(t0<s1&&s1<=t1))); | |
760 #endif | |
761 if((t0<=s0&&s0<t1)||(t0<s1&&s1<=t1)) return s; | |
762 } | |
763 } | |
764 return 0; | |
765 } | |
766 | |
767 void | |
768 remove_target(int *target,int t,int *use) | |
769 { | |
770 int use0=*use; | |
147 | 771 int reg; |
61 | 772 while(use0) { |
773 if (car(use0)==t) { | |
147 | 774 reg = car(caddr(use0)); |
775 if (reg==REGISTER||reg==FREGISTER||reg==DREGISTER) | |
99 | 776 free_register(cadr(caddr(use0))); |
61 | 777 break; |
778 } | |
779 use0 = cadr(use0); | |
780 } | |
781 remove0(target,t); | |
782 } | |
783 | |
784 void | |
785 save_target(int t,int s,int *target,int *use,int sz,int ty) | |
786 { | |
787 int e1; | |
788 /*¿·¤·¤¤¥ì¥¸¥¹¥¿(or ¥¹¥¿¥Ã¥¯)¤ò¼èÆÀ¤¹¤ë*/ | |
789 if (sz==size_of_int && (e1=get_register())!=-1) { | |
105 | 790 e1=list3(REGISTER,e1,0); |
61 | 791 *use=list3(t,*use,e1); |
99 | 792 g_expr_u(assign_expr0(e1,s,ty,ty)); |
793 *target = append4(*target,t,ty,e1); | |
195 | 794 #if FLOAT_CODE |
138 | 795 } else if (sz==size_of_double && (e1=get_dregister(1))!=-1) { |
105 | 796 e1=list3(DREGISTER,e1,0); |
99 | 797 *use=list3(t,*use,e1); |
83 | 798 g_expr_u(assign_expr0(e1,s,ty,ty)); |
61 | 799 *target = append4(*target,t,ty,e1); |
138 | 800 } else if (sz==size_of_float && (e1=get_dregister(0))!=-1) { |
801 e1=list3(FREGISTER,e1,0); | |
802 *use=list3(t,*use,e1); | |
803 g_expr_u(assign_expr0(e1,s,ty,ty)); | |
804 *target = append4(*target,t,ty,e1); | |
195 | 805 #endif |
205 | 806 #if LONGLONG_CODE |
807 } else if (sz==size_of_longlong && (e1=get_lregister())!=-1) { | |
808 e1=list3(LREGISTER,e1,0); | |
809 *use=list3(t,*use,e1); | |
810 g_expr_u(assign_expr0(e1,s,ty,ty)); | |
811 *target = append4(*target,t,ty,e1); | |
812 #endif | |
61 | 813 } else { |
94 | 814 g_expr_u(assign_expr0((e1=list2(LVAR,new_lvar(sz))),s,ty,ty)); |
61 | 815 *target = append4(*target,t,ty,e1); |
117 | 816 *use=list3(t,*use,e1); |
61 | 817 } |
818 } | |
819 | |
820 int | |
821 circular_dependency(int t,int s,int *target,int *source) | |
822 { | |
823 int target0=*target; | |
824 int t1,sz,ty,s1; | |
825 while(target0) { | |
826 if (cadddr(target0)==s) { | |
827 t1=car(target0); | |
828 s=cadddr(target0); | |
829 sz=size(ty=caddr(target0)); | |
830 if(t==t1) { | |
831 #if DEBUG_PARALLEL_ASSIGN | |
832 printf("# circular dependency %d ty %d+%d sz %d\n",car(t1),ty,cadr(t1),sz); | |
833 #endif | |
834 return 1; | |
835 } | |
836 if ((s1=overrap(t1,sz,*source))) { | |
837 /* another overrap start over */ | |
838 return circular_dependency(t,s1,target,source); | |
839 } | |
840 } | |
841 target0=cadr(target0); | |
842 } | |
843 return 0; | |
844 } | |
845 | |
846 void | |
847 parallel_assign(int *target,int *source,int *processing,int *use) | |
848 { | |
849 int t,s,sz,ty,target0,s1; | |
850 while(*target) { | |
851 target0=*target; | |
852 while(target0) { | |
853 t=car(target0); s=cadddr(target0); | |
854 sz=size(ty=caddr(target0)); | |
855 if(car(t)==car(s) && cadr(t)==cadr(s)) { | |
856 /*½ñ¤¹þ¤ßÀ褬¼«Ê¬¼«¿È*/ | |
857 #if DEBUG_PARALLEL_ASSIGN | |
858 printf("# remove same %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz); | |
859 #endif | |
860 remove_target(target,t,use); | |
861 /* Ç˲õ¤µ¤ì¤Æ¤Ïº¤¤ë¤Î¤Ç¡¢source list¤«¤é¤Ï½ü¤«¤Ê¤¤ */ | |
862 } else if (!(s1=overrap(t,sz,*source))) { | |
863 /* ½Å¤Ê¤Ã¤Æ¤Ê¤¤¤Î¤Ç°Â¿´¤·¤Æ½ñ¤¹þ¤á¤ë */ | |
864 #if DEBUG_PARALLEL_ASSIGN | |
865 printf("# normal assign %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz); | |
866 #endif | |
83 | 867 g_expr_u(assign_expr0(t,s,ty,ty)); |
61 | 868 remove_target(target,t,use); remove0(source,s); |
869 } else { | |
870 if(circular_dependency(t,s1,target,source)) { | |
871 #if DEBUG_PARALLEL_ASSIGN | |
872 printf("# saving %d ty %d+%d sz %d\n",car(t),ty,cadr(t),sz); | |
873 #endif | |
874 remove_target(target,t,use); remove0(source,s); | |
875 save_target(t,s,target,use,sz,ty); | |
876 } | |
877 } | |
878 target0=cadr(target0); | |
879 } | |
880 } | |
881 } | |
882 | |
883 void | |
884 remove0(int *parent,int e) | |
885 { | |
886 int list; | |
887 while ((list=*parent)) { | |
888 if (car(list)==e) { | |
889 *parent= cadr(list); return; | |
890 } else { | |
891 parent=&cadr(list); | |
892 } | |
893 } | |
894 } | |
895 | |
105 | 896 /* |
61 | 897 void |
898 remove0_all(int *parent,int e) | |
899 { | |
900 int list; | |
901 while ((list=*parent)) { | |
902 if (car(list)==e) { | |
903 *parent= cadr(list); | |
904 } else { | |
905 parent=&cadr(list); | |
906 } | |
907 } | |
908 } | |
105 | 909 */ |
61 | 910 |
911 int | |
912 is_simple(int e1) | |
913 { | |
914 return ( | |
99 | 915 e1==CONST || e1==FNAME || e1==LVAR || e1==REGISTER ||e1==DREGISTER || |
195 | 916 e1==FREGISTER || e1==LREGISTER || |
81 | 917 e1==GVAR || e1==RGVAR || e1==RLVAR || e1==CRLVAR || e1==CRGVAR || |
195 | 918 e1==DRLVAR || e1==FRLVAR || e1==LRLVAR || |
165 | 919 e1==CURLVAR || e1==SURLVAR || e1==CURGVAR || e1==SURGVAR |
61 | 920 ); |
921 } | |
922 | |
923 int | |
924 is_same_type(int e1,int e2) | |
925 { | |
926 int ce1=car(e1); | |
927 int ce2=car(e2); | |
928 return ( | |
81 | 929 (ce1==LVAR && (ce2==RLVAR||ce2==CRLVAR||ce2==FRLVAR||ce2==DRLVAR)) |
165 | 930 || (ce1==LVAR && (ce2==SRLVAR||ce2==SURLVAR||ce2==CURLVAR)) |
81 | 931 || (ce2==LVAR && (ce1==RLVAR||ce1==CRLVAR||ce1==FRLVAR||ce1==DRLVAR)) |
165 | 932 || (ce2==LVAR && (ce1==SRLVAR||ce1==SURLVAR||ce1==CURLVAR)) |
195 | 933 || (ce2==LVAR && (ce1==LRLVAR)) |
81 | 934 || (ce1==GVAR && (ce2==RGVAR||ce2==CRGVAR||ce2==FRGVAR||ce2==DRGVAR)) |
165 | 935 || (ce1==GVAR && (ce2==SRGVAR||ce2==SURGVAR||ce2==CURGVAR)) |
81 | 936 || (ce2==GVAR && (ce1==RGVAR||ce1==CRGVAR||ce1==FRGVAR||ce1==DRGVAR)) |
165 | 937 || (ce2==GVAR && (ce1==SRGVAR||ce1==SURGVAR||ce1==CURGVAR)) |
195 | 938 || (ce2==GVAR && (ce1==LRGVAR)) |
61 | 939 ); |
940 } | |
941 | |
942 int | |
943 is_memory(int e1) | |
944 { | |
945 int ce1=car(e1); | |
946 return ( | |
195 | 947 ce1==LVAR ||ce1==RLVAR||ce1==CRLVAR || ce1==DRLVAR || ce1==LRLVAR || |
948 ce1==GVAR ||ce1==RGVAR||ce1==CRGVAR || ce1==DRGVAR || ce1==LRGVAR || | |
949 ce1==FRLVAR || ce1==FRGVAR || | |
165 | 950 ce1==CURGVAR ||ce1==SURGVAR||ce1==SRGVAR || |
219 | 951 ce1==REGISTER|| ce1==DREGISTER || ce1==FREGISTER || |
952 ce1==LREGISTER | |
61 | 953 ); |
954 } | |
955 | |
98 | 956 |
61 | 957 void |
958 jump(int e1, int env) | |
959 { | |
99 | 960 int e2,e3,e4,sz,arg_size,ty,regs,fregs; |
147 | 961 int t0,s0,r,reg; |
127 | 962 NMTBL *code0 = 0; |
61 | 963 int target = 0; |
964 int source = 0; | |
965 int processing = 0; | |
966 int use = 0; | |
967 | |
968 /* ¤Þ¤º¡¢¥µ¥¤¥º¤ò·×»»¤·¤Ê¤¬¤é¡¢·è¤Þ¤Ã¤¿·Á¤ËÍ¡£ */ | |
969 | |
99 | 970 arg_size = 0; regs = 0; |
971 fregs = 0; | |
61 | 972 for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) { |
973 e2 = car(e3); sz = size(ty=caddr(e3)); | |
138 | 974 if (scalar(ty) && (r = get_input_register_var(regs,0,1))) { |
975 target=list4(r,target,ty,e2); regs++; | |
976 } else if (ty==FLOAT && (r = get_input_dregister_var(fregs,0,1,0))) { | |
977 target=list4(r, target,ty,e2); fregs++; | |
978 } else if (ty==DOUBLE && (r = get_input_dregister_var(fregs,0,1,1))) { | |
979 target=list4(r, target,ty,e2); fregs++; | |
61 | 980 } else { |
981 target=list4(list2(LVAR,0), target,ty,e2); | |
982 } | |
128 | 983 /* keep arg space for register variables */ |
984 arg_size += sz; | |
61 | 985 #if DEBUG_PARALLEL_ASSIGN |
986 printf("# target %d ty %d+%d sz %d\n",car(car(target)),ty,cadr(car(target)),sz); | |
987 #endif | |
988 } | |
989 | |
990 /* disp ¤òÈô¤ÓÀè»÷¹ç¤ï¤»¤Æ½¤Àµ */ | |
98 | 991 if (is_code(fnptr)) { |
61 | 992 if (-arg_size<disp) disp = -arg_size; |
993 } else { | |
994 if (disp_offset-arg_size<disp) disp = disp_offset-arg_size; | |
995 } | |
996 | |
997 /* Ê£»¨¤Ê¼°¤òÁ°¤â¤Ã¤Æ·×»»¤·¤Æ¤ª¤¯ */ | |
998 /* ɬÍפʤé¶É½êÊÑ¿ô¤òÍѤ¤¤ë¡£ */ | |
999 /* ¶É½êÊÑ¿ô¤Ø¤Î¥ª¥Õ¥»¥Ã¥È¤ò³Ð¤¨¤Æ¤ª¤¯ */ | |
1000 | |
1001 for (e2 = target; e2; e2 = cadr(e2)) { | |
1002 t0=car(e2); s0=cadddr(e2); | |
1003 sz=size(ty=caddr(e2)); | |
1004 if(car(t0)==LVAR) { | |
1005 /* ¤³¤³¤Ç¡¢½ñ¹þÀ襢¥É¥ì¥¹¤ò·è¤á¤ë */ | |
1006 cadr(t0)=-arg_size; | |
1007 } | |
128 | 1008 arg_size-=sz; |
61 | 1009 if (!is_simple(car(s0))) { |
94 | 1010 g_expr_u(assign_expr0((e4=list2(LVAR,new_lvar(sz))),s0,ty,ty)); |
117 | 1011 use=list3(ty,use,e1); |
61 | 1012 cadddr(e2)=e4; |
1013 s0=e4; | |
1014 } else if (is_same_type(t0,s0)) { | |
1015 if(cadr(t0)==cadr(s0)) { | |
1016 #if DEBUG_PARALLEL_ASSIGN | |
1017 printf("# remove same memory %d ty %d+%d sz %d\n",car(t0),ty,cadr(t0),sz); | |
1018 #endif | |
269 | 1019 /* we should check size also (but currently useless) */ |
61 | 1020 remove0(&target,t0); |
1021 /* still we have source to avoid overwrite */ | |
1022 } | |
1023 } | |
1024 if(is_memory(s0)) { | |
1025 source=list3(s0,source,sz); | |
1026 #if DEBUG_PARALLEL_ASSIGN | |
1027 printf("# source %d ty %d+%d sz %d\n",car(car(source)),ty,cadr(car(source)),sz); | |
1028 #endif | |
1029 } | |
1030 } | |
1031 | |
1032 /* compute jump address */ | |
1033 e2 = cadr(e1); | |
1034 if (car(e2) == FNAME) { | |
1035 code0=(NMTBL *)cadr(e2); | |
98 | 1036 if (!is_code(code0)) { |
61 | 1037 error(TYERR); return; |
1038 } | |
1039 } else { /* indirect */ | |
1040 g_expr(e2); | |
1041 emit_push(); | |
1042 } | |
1043 if (env) { | |
1044 g_expr(env); | |
1045 emit_push(); | |
1046 } | |
1047 | |
1048 /* ÊÂÎóÂåÆþ¤ò¼Â¹Ô */ | |
1049 parallel_assign(&target,&source,&processing,&use); | |
1050 while (use) { | |
147 | 1051 reg = car(caddr(use)); |
195 | 1052 if (reg==REGISTER||reg==FREGISTER||reg==DREGISTER||reg==LREGISTER) |
99 | 1053 free_register(cadr(caddr(use))); |
117 | 1054 else if (car(caddr(use))==LVAR) |
1055 free_lvar(cadr(caddr(use))); | |
99 | 1056 use=cadr(use); |
61 | 1057 } |
1058 if(target) error(-1); | |
1059 | |
1060 if (env) { | |
1061 /* change the frame pointer */ | |
1062 e3 = emit_pop(0); | |
1063 code_frame_pointer(e3); | |
1064 emit_pop_free(e3); | |
98 | 1065 } else if (is_function(fnptr)) { |
128 | 1066 if (car(e2) != FNAME) { |
1067 e2 = emit_pop(0); | |
1068 code_fix_frame_pointer(disp_offset); | |
1069 code_indirect_jmp(e2); | |
1070 emit_pop_free(e2); | |
1071 return; | |
1072 } | |
61 | 1073 code_fix_frame_pointer(disp_offset); |
1074 } | |
1075 | |
1076 if (car(e2) == FNAME) { | |
1077 code_jmp(code0->nm); | |
1078 } else { | |
1079 e2 = emit_pop(0); | |
1080 code_indirect_jmp(e2); | |
1081 emit_pop_free(e2); | |
1082 } | |
1083 } | |
1084 | |
1085 void | |
1086 machinop(int e1) | |
1087 { | |
240 | 1088 int e2,e3,op; |
61 | 1089 |
1090 e2 = cadr(e1); | |
1091 op = car(e1); | |
1092 e3 = caddr(e1); | |
240 | 1093 if (code_const_op_p(op,e3)) { |
189 | 1094 g_expr(e2); |
240 | 1095 oprtc(op,USE_CREG,e3); |
189 | 1096 return; |
1097 } | |
61 | 1098 g_expr(e3); |
1099 emit_push(); | |
1100 g_expr(e2); | |
221 | 1101 tosop(op,USE_CREG,(e2=pop_register())); |
61 | 1102 emit_pop_free(e2); |
1103 return; | |
1104 } | |
1105 | |
195 | 1106 #if FLOAT_CODE |
81 | 1107 void |
133 | 1108 dmachinop(int e1,int d) |
81 | 1109 { |
1110 int e2,e3,op; | |
1111 | |
1112 e2 = cadr(e1); | |
1113 op = car(e1); | |
1114 e3 = caddr(e1); | |
1115 g_expr(e3); | |
133 | 1116 emit_dpush(d); |
81 | 1117 g_expr(e2); |
221 | 1118 dtosop(car(e1),USE_CREG,(e2=emit_dpop(d))); |
138 | 1119 emit_dpop_free(e2,d); |
81 | 1120 return; |
1121 } | |
195 | 1122 #endif |
1123 | |
1124 #if LONGLONG_CODE | |
1125 void | |
1126 lmachinop(int e1) | |
1127 { | |
1128 int e2,e3,op; | |
1129 | |
1130 e2 = cadr(e1); | |
1131 op = car(e1); | |
1132 e3 = caddr(e1); | |
213 | 1133 if (code_lconst_op_p(op,e3)) { |
1134 g_expr(e2); | |
221 | 1135 loprtc(op,USE_CREG,e3); |
213 | 1136 return; |
1137 } | |
195 | 1138 g_expr(e3); |
1139 emit_lpush(); | |
1140 g_expr(e2); | |
221 | 1141 ltosop(car(e1),USE_CREG,(e2=emit_lpop())); |
195 | 1142 emit_lpop_free(e2); |
1143 return; | |
1144 } | |
1145 #endif | |
81 | 1146 |
61 | 1147 void |
1148 sassign(int e1) | |
1149 { | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1150 int e2,e3,e4,sz,xreg,det,offset; |
61 | 1151 |
1152 /* structure assignment */ | |
1153 e2 = cadr(e1); /* pointer variable to the struct */ | |
1154 e3 = cadr(e2); /* offset of the variable (distination) */ | |
1155 e4 = caddr(e1); /* right value (source) */ | |
1156 sz = cadddr(e1); /* size of struct or union */ | |
269 | 1157 if (is_same_type(e2,e4)&&cadr(e2)==cadr(e4)) { |
1158 if (use) g_expr(e4); | |
1159 return; | |
1160 } | |
61 | 1161 g_expr(e4); |
1162 emit_push(); | |
1163 g_expr(e2); | |
1164 xreg = emit_pop(0); | |
1165 /* °ìÈÌŪ¤Ë¤Ï¥³¥Ô¡¼¤Î¥ª¡¼¥Ð¥é¥Ã¥×¤Î¾õ¶·¤Ï¼Â¹Ô»þ¤Ë¤·¤«¤ï¤«¤é¤Ê¤¤ */ | |
1166 /* ¤·¤«¤·¡¢¤ï¤«¤ë¾ì¹ç¤â¤¢¤ë */ | |
1167 if (car(e4)==RSTRUCT) e4=cadr(e4); | |
1168 if (is_same_type(e2,e4)) { | |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1169 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
|
1170 det=1; |
61 | 1171 } else { |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1172 det = 0; offset=0; |
61 | 1173 } |
258
22949117768f
Complex function argments. Struct is done. Long long is odd.
kono
parents:
256
diff
changeset
|
1174 emit_copy(xreg,USE_CREG,sz,offset,1,det); |
61 | 1175 emit_pop_free(xreg); |
1176 return; | |
1177 } | |
1178 | |
269 | 1179 static void |
118 | 1180 assign_opt(int e5,int e2,int e4,int byte) |
1181 { | |
1182 int reg; | |
1183 /* e2=e4 */ | |
1184 if (e5==REGISTER) { | |
1185 reg = cadr(e4); | |
1186 switch(car(e2)) { | |
1187 case GVAR: code_assign_gvar(e2,reg,byte); return; | |
119 | 1188 case LVAR: code_assign_lvar(cadr(e2),reg,byte); return; |
118 | 1189 case REGISTER: code_assign_register(cadr(e2),byte,reg); return; |
1190 } | |
1191 g_expr(e2); | |
233 | 1192 code_assign(USE_CREG,byte,reg); |
118 | 1193 return; |
1194 } | |
1195 /* e2 is register now */ | |
1196 if (car(e2)!=REGISTER) error(-1); | |
1197 reg = cadr(e2); | |
1198 switch(e5) { | |
162 | 1199 case CRGVAR: |
165 | 1200 case CURGVAR: code_crgvar(e4,reg,e5==CRGVAR,1); return; |
1201 case SRGVAR: | |
1202 case SURGVAR: code_crgvar(e4,reg,e5==SRGVAR,size_of_short); return; | |
118 | 1203 case RGVAR: code_rgvar(e4,reg); return; |
162 | 1204 case CRLVAR: |
165 | 1205 case CURLVAR: code_crlvar(cadr(e4),reg,e5==CRLVAR,1); return; |
1206 case SRLVAR: | |
1207 case SURLVAR: code_crlvar(cadr(e4),reg,e5==SRLVAR,size_of_short); return; | |
119 | 1208 case RLVAR: code_rlvar(cadr(e4),reg); return; |
118 | 1209 case GVAR: code_gvar(e4,reg); return; |
119 | 1210 case LVAR: code_lvar(cadr(e4),reg); return; |
118 | 1211 case CONST: code_const(cadr(e4),reg); return; |
1212 case ADDRESS: | |
1213 if (car(cadr(e4))==STRING) code_string(cadr(e4),reg); | |
1214 else code_gvar(cadr(e4),reg); | |
1215 return; | |
1216 case FNAME: code_fname((NMTBL*)cadr(e4),reg); return; | |
1217 case STRING: code_string(e4,reg); return; | |
135 | 1218 default: error(-1); |
118 | 1219 } |
1220 } | |
1221 | |
1222 void | |
61 | 1223 assign(int e1) |
1224 { | |
118 | 1225 int e2,e4,byte,e5; |
61 | 1226 |
166 | 1227 byte=(car(e1) == CASS)?1:(car(e1) == SASS)?size_of_short:0; |
61 | 1228 /* e2=e4 */ |
1229 e2 = cadr(e1); | |
118 | 1230 e4 = caddr(e1);e5=car(e4); |
269 | 1231 if (is_same_type(e2,e4)&&cadr(e2)==cadr(e4)) { |
1232 if (use) g_expr(e4); | |
1233 return; | |
1234 } | |
118 | 1235 if (!use && ( |
1236 (e5==REGISTER) || | |
1237 (car(e2)==REGISTER&&( | |
1238 e5== CRGVAR || e5== CRLVAR || e5== RGVAR || e5== RLVAR || | |
162 | 1239 e5== CURGVAR || e5== CURLVAR || |
165 | 1240 e5== SURGVAR || e5== SURLVAR || |
118 | 1241 e5== GVAR || e5== LVAR || |
1242 e5== CONST || e5== FNAME || e5== STRING || | |
1243 (e5==ADDRESS&&car(cadr(e4))==STRING) || | |
1244 (e5==ADDRESS&&car(cadr(e4))==GVAR) )))) { | |
1245 assign_opt(e5,e2,e4,byte); | |
1246 return; | |
1247 } | |
61 | 1248 switch(car(e2)) { |
1249 case GVAR: /* i=3 */ | |
1250 g_expr(e4); | |
221 | 1251 code_assign_gvar(e2,USE_CREG,byte); |
61 | 1252 return; |
1253 case LVAR: | |
1254 g_expr(e4); | |
221 | 1255 code_assign_lvar(cadr(e2),USE_CREG,byte); |
61 | 1256 return; |
1257 case REGISTER: | |
1258 g_expr(e4); | |
221 | 1259 code_assign_register(cadr(e2),byte,USE_CREG); |
61 | 1260 return; |
1261 } | |
1262 g_expr(e2); | |
1263 emit_push(); | |
1264 g_expr(e4); | |
1265 e2 = emit_pop(0); | |
221 | 1266 code_assign(e2,byte,USE_CREG); |
61 | 1267 emit_pop_free(e2); |
1268 return; | |
1269 } | |
1270 | |
195 | 1271 #if FLOAT_CODE |
1272 | |
269 | 1273 static void |
118 | 1274 dassign_opt(int e5,int e2,int e4,int d) |
1275 { | |
1276 int reg; | |
1277 /* e2=e4 */ | |
138 | 1278 if (e5==DREGISTER||e5==FREGISTER) { |
118 | 1279 reg = cadr(e4); |
1280 switch(car(e2)) { | |
1281 case GVAR: /* i=3 */ | |
1282 code_dassign_gvar(e2,reg,d); | |
1283 return; | |
1284 case LVAR: | |
119 | 1285 code_dassign_lvar(cadr(e2),reg,d); |
118 | 1286 return; |
1287 case DREGISTER: | |
138 | 1288 case FREGISTER: |
118 | 1289 if (reg!=cadr(e2)) |
138 | 1290 code_dassign_dregister(cadr(e2),d,reg); |
118 | 1291 return; |
135 | 1292 default: |
1293 error(-1); | |
118 | 1294 } |
1295 } | |
1296 /* e2 is register now */ | |
138 | 1297 if (car(e2)!=DREGISTER && car(e2)!=FREGISTER) error(-1); |
118 | 1298 reg = cadr(e2); |
1299 switch(e5) { | |
135 | 1300 case FRGVAR: |
118 | 1301 case DRGVAR: code_drgvar(e4,d,reg); return; |
135 | 1302 case FRLVAR: |
119 | 1303 case DRLVAR: code_drlvar(cadr(e4),d,reg); return; |
135 | 1304 case FCONST: |
264 | 1305 case DCONST: code_dconst(e4,reg,d); return; |
135 | 1306 default: |
118 | 1307 error(-1); |
1308 } | |
1309 } | |
1310 | |
1311 void | |
81 | 1312 dassign(int e1) |
1313 { | |
118 | 1314 int e2,e3,e4,d,e5; |
81 | 1315 |
1316 /* e2=e4 */ | |
1317 e2 = cadr(e1); | |
1318 e3 = cadr(e2); | |
118 | 1319 e4 = caddr(e1); e5=car(e4); |
269 | 1320 if (is_same_type(e2,e4)&&cadr(e2)==cadr(e4)) { |
1321 if (use) g_expr(e4); | |
1322 return; | |
1323 } | |
249 | 1324 if (car(e1)==DASS) d=1; |
1325 else if (car(e1)==FASS) d=0; | |
1326 else error(-1); | |
118 | 1327 if (!use && ( |
138 | 1328 (e5==DREGISTER) || (e5==FREGISTER) || |
133 | 1329 (car(e2)==DREGISTER&&(e5==DRGVAR||e5==DRLVAR||e5==DCONST))|| |
249 | 1330 (car(e2)==FREGISTER&&(e5==FRGVAR||e5==FRLVAR||e5==FCONST)) |
118 | 1331 )) { |
1332 dassign_opt(e5,e2,e4,d); | |
1333 return; | |
1334 } | |
81 | 1335 switch(car(e2)) { |
82 | 1336 case GVAR: |
81 | 1337 g_expr(e4); |
221 | 1338 code_dassign_gvar(e2,USE_CREG,d); |
81 | 1339 return; |
1340 case LVAR: | |
1341 g_expr(e4); | |
221 | 1342 code_dassign_lvar(cadr(e2),USE_CREG,d); |
81 | 1343 return; |
111 | 1344 case DREGISTER: |
138 | 1345 case FREGISTER: |
111 | 1346 g_expr(e4); |
221 | 1347 code_dassign_dregister(cadr(e2),d,USE_CREG); |
111 | 1348 return; |
81 | 1349 } |
1350 g_expr(e2); | |
82 | 1351 emit_push(); |
81 | 1352 g_expr(e4); |
82 | 1353 e2 = emit_pop(0); |
221 | 1354 code_dassign(e2,USE_CREG,d); |
82 | 1355 emit_pop_free(e2); |
81 | 1356 return; |
1357 } | |
1358 | |
195 | 1359 #endif |
1360 | |
1361 #if LONGLONG_CODE | |
1362 | |
1363 void | |
1364 lassign_opt(int e5,int e2,int e4) | |
1365 { | |
1366 int reg; | |
1367 /* e2=e4 */ | |
1368 if (e5==LREGISTER) { | |
1369 reg = cadr(e4); | |
1370 switch(car(e2)) { | |
1371 case GVAR: /* i=3 */ | |
1372 code_lassign_gvar(e2,reg); | |
1373 return; | |
1374 case LVAR: | |
1375 code_lassign_lvar(cadr(e2),reg); | |
1376 return; | |
1377 case LREGISTER: | |
1378 if (reg!=cadr(e2)) | |
1379 code_lassign_lregister(cadr(e2),reg); | |
1380 return; | |
1381 default: | |
1382 error(-1); | |
1383 } | |
1384 } | |
1385 /* e2 is register now */ | |
1386 if (car(e2)!=LREGISTER) error(-1); | |
1387 reg = cadr(e2); | |
1388 switch(e5) { | |
1389 case LRGVAR: code_lrgvar(e4,reg); return; | |
1390 case LRLVAR: code_lrlvar(cadr(e4),reg); return; | |
1391 case LCONST: code_lconst(e4,reg); return; | |
1392 default: | |
1393 error(-1); | |
1394 } | |
1395 } | |
1396 | |
1397 void | |
1398 lassign(int e1) | |
1399 { | |
1400 int e2,e3,e4,e5; | |
1401 | |
1402 /* e2=e4 */ | |
1403 e2 = cadr(e1); | |
1404 e3 = cadr(e2); | |
1405 e4 = caddr(e1); e5=car(e4); | |
269 | 1406 if (is_same_type(e2,e4)&&cadr(e2)==cadr(e4)) { |
1407 if (use) g_expr(e4); | |
1408 return; | |
1409 } | |
195 | 1410 if (!use && ( |
1411 (e5==LREGISTER) || | |
1412 (car(e2)==LREGISTER&&(e5==LRGVAR||e5==LRLVAR||e5==LCONST)) | |
1413 )) { | |
1414 lassign_opt(e5,e2,e4); | |
1415 return; | |
1416 } | |
1417 switch(car(e2)) { | |
1418 case GVAR: | |
1419 g_expr(e4); | |
221 | 1420 code_lassign_gvar(e2,USE_CREG); |
195 | 1421 return; |
1422 case LVAR: | |
1423 g_expr(e4); | |
221 | 1424 code_lassign_lvar(cadr(e2),USE_CREG); |
195 | 1425 return; |
1426 case LREGISTER: | |
1427 g_expr(e4); | |
221 | 1428 code_lassign_lregister(cadr(e2),USE_CREG); |
195 | 1429 return; |
1430 } | |
1431 g_expr(e2); | |
219 | 1432 emit_push(); |
195 | 1433 g_expr(e4); |
219 | 1434 e2 = emit_pop(0); |
221 | 1435 code_lassign(e2,USE_CREG); |
219 | 1436 emit_pop_free(e2); |
195 | 1437 return; |
1438 } | |
1439 | |
1440 #endif | |
1441 | |
81 | 1442 void |
61 | 1443 assop(int e1) |
1444 { | |
165 | 1445 int e2,e3,byte,op,sign,size; |
255 | 1446 int n,t; |
61 | 1447 |
1448 /* e2 op= e3 */ | |
162 | 1449 if (car(e1) == CUASSOP) { |
165 | 1450 byte = 1; sign = 0; size = 1; |
162 | 1451 } else if (car(e1) == CASSOP) { |
165 | 1452 byte = 1; sign = 1; size = 1; |
1453 } else if (car(e1) == SUASSOP) { | |
1454 byte = size_of_short; sign = 0; size = size_of_short; | |
1455 } else if (car(e1) == SASSOP) { | |
1456 byte = size_of_short; sign = 1; size = size_of_short; | |
162 | 1457 } else { |
165 | 1458 byte = 0; sign = 1; size = size_of_int; |
162 | 1459 } |
61 | 1460 e2 = cadr(e1); |
1461 if (car(e2)==INDIRECT) e2=cadr(e2); | |
1462 e3 = caddr(e1); | |
1463 op = cadddr(e1); | |
1464 | |
285 | 1465 if (car(e2)==REGISTER) { |
1466 if (code_const_op_p(op,e3)) { | |
1467 oprtc(op,cadr(e2),e3); | |
1468 } else { | |
1469 g_expr(e3); | |
1470 code_register_assop(cadr(e2),USE_CREG,op,byte); | |
1471 } | |
1472 if (use) { | |
1473 code_register(cadr(e2),USE_CREG); | |
1474 } | |
1475 return; | |
1476 } | |
255 | 1477 if (car(e3)==CONST) { |
1478 /* e2 = e2 op e3; */ | |
1479 t = sign?INT:UNSIGNED; | |
285 | 1480 // oprtc expected |
1481 if (car(e2)==LVAR||car(e2)==GVAR) { | |
255 | 1482 g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); |
1483 return; | |
1484 } | |
1485 /* new = &e2 */ | |
1486 /* *new = *new op e3 */ | |
1487 n = list2(LVAR,new_lvar(size_of_int)); | |
1488 g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT)); | |
1489 g_expr(assign_expr0(list2(INDIRECT,n),list3(op,n,e3),t,t)); | |
1490 free_lvar(cadr(n)); | |
1491 return; | |
1492 } | |
61 | 1493 g_expr(e3); |
1494 emit_push(); | |
1495 g_expr(e2); | |
221 | 1496 code_assop(op,USE_CREG,byte,sign); |
61 | 1497 return; |
1498 } | |
1499 | |
195 | 1500 #if FLOAT_CODE |
1501 | |
81 | 1502 void |
1503 dassop(int e1) | |
1504 { | |
83 | 1505 int e2,e3,op,d; |
81 | 1506 |
83 | 1507 /* e2 op= e3 */ |
1508 d = (car(e1) == DASSOP); | |
1509 e2 = cadr(e1); | |
1510 if (car(e2)==INDIRECT) e2=cadr(e2); | |
1511 e3 = caddr(e1); | |
1512 op = cadddr(e1); | |
1513 | |
1514 g_expr(e3); | |
144 | 1515 if (car(e2)==DREGISTER||car(e2)==FREGISTER) { |
273 | 1516 emit_dpush(d); |
219 | 1517 code_register_dassop(cadr(e2),op,d); |
273 | 1518 if (use) |
1519 code_dregister(cadr(e2),USE_CREG,d); | |
1520 return; | |
144 | 1521 } |
238 | 1522 emit_dpush(d); |
1523 g_expr(e2); | |
221 | 1524 code_dassop(op,USE_CREG,d); |
83 | 1525 return; |
81 | 1526 } |
61 | 1527 |
195 | 1528 #endif |
1529 | |
1530 #if LONGLONG_CODE | |
1531 | |
238 | 1532 static int |
1533 long_sign(int op) | |
1534 { | |
1535 return (op==LUDIV||op==LUMOD||op==LULSHIFT||op==LURSHIFT)?ULONGLONG:LONGLONG; | |
1536 } | |
1537 | |
195 | 1538 void |
1539 lassop(int e1) | |
1540 { | |
1541 int e2,e3,op; | |
238 | 1542 int n,t; |
195 | 1543 |
1544 /* e2 op= e3 */ | |
1545 e2 = cadr(e1); | |
1546 if (car(e2)==INDIRECT) e2=cadr(e2); | |
1547 e3 = caddr(e1); | |
1548 op = cadddr(e1); | |
1549 | |
286 | 1550 if (car(e2)==LREGISTER) { |
285 | 1551 if (code_lconst_op_p(op,e3)) { |
1552 loprtc(op,cadr(e2),e3); | |
286 | 1553 if (use) { |
1554 code_lregister(cadr(e2),USE_CREG); | |
1555 } | |
1556 return; | |
1557 } | |
1558 if (code_lassop_p) { | |
285 | 1559 g_expr(e3); |
1560 emit_lpush(); | |
1561 code_register_lassop(cadr(e2),op); | |
286 | 1562 if (use) { |
1563 code_lregister(cadr(e2),USE_CREG); | |
1564 } | |
1565 return; | |
285 | 1566 } |
1567 } | |
238 | 1568 if (!code_lassop_p||car(e3)==LCONST) { |
1569 /* e2 = e2 op e3; */ | |
1570 t = long_sign(op); | |
286 | 1571 if (car(e2)==LREGISTER||car(e2)==LVAR||car(e2)==GVAR) { |
238 | 1572 g_expr(assign_expr0(e2,list3(op,rvalue_t(e2,t),e3),t,t)); |
239 | 1573 return; |
238 | 1574 } |
1575 /* new = &e2 */ | |
1576 /* *new = *new op e3 */ | |
1577 n = list2(LVAR,new_lvar(size_of_int)); | |
239 | 1578 g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT)); |
238 | 1579 g_expr(assign_expr0(list2(INDIRECT,n),list3(op,n,e3),t,t)); |
1580 free_lvar(cadr(n)); | |
1581 return; | |
1582 } | |
1583 | |
195 | 1584 g_expr(e3); |
286 | 1585 if (car(e2)==LREGISTER) { |
1586 emit_lpush(); | |
1587 code_register_lassop(cadr(e2),op); | |
1588 if (use) | |
1589 code_lregister(cadr(e2),USE_CREG); | |
1590 return; | |
1591 } | |
238 | 1592 emit_lpush(); |
1593 g_expr(e2); | |
221 | 1594 code_lassop(op,USE_CREG); |
195 | 1595 return; |
1596 } | |
1597 | |
1598 #endif | |
1599 | |
95 | 1600 void |
287 | 1601 cmpdimm(int e, int csreg,int label,int cond) |
95 | 1602 { |
287 | 1603 code_cmpdimm(e, csreg,label,cond); |
95 | 1604 } |
1605 | |
1606 int | |
1607 csvalue() | |
1608 { | |
1609 return code_csvalue(); | |
1610 } | |
1611 | |
1612 | |
61 | 1613 int |
1614 fwdlabel(void) | |
1615 { | |
1616 return labelno++; | |
1617 } | |
1618 | |
1619 void | |
1620 fwddef(int l) | |
1621 { | |
1622 control=1; | |
66 | 1623 if (!chk) |
92 | 1624 code_label(l); |
61 | 1625 } |
1626 | |
1627 int | |
1628 backdef(void) | |
1629 { | |
1630 control=1; | |
66 | 1631 if (!chk) |
92 | 1632 code_label(labelno); |
61 | 1633 return labelno++; |
1634 } | |
1635 | |
1636 void | |
1637 def_label(int cslabel, int dlabel) | |
1638 { | |
1639 int fl; | |
1640 | |
1641 fl = 0; | |
1642 if (control) { | |
1643 jmp(fl=fwdlabel()); | |
1644 } | |
1645 fwddef(cslabel); | |
1646 if (dlabel) | |
1647 jmp(dlabel); | |
1648 if (fl) { | |
1649 fwddef(fl); | |
1650 } | |
1651 } | |
1652 | |
1653 void | |
1654 gen_source(char *s) | |
1655 { | |
1656 printf("%s",s); | |
1657 } | |
1658 | |
1659 void | |
1660 ret(void) | |
1661 { | |
107 | 1662 code_set_return_register(1); |
61 | 1663 jmp(retlabel); |
1664 } | |
1665 | |
66 | 1666 void |
1667 opening(char *filename) | |
1668 { | |
1669 emit_init(); | |
1670 if (!chk) | |
1671 code_opening(filename); | |
1672 } | |
1673 | |
1674 void | |
1675 closing() | |
1676 { | |
1677 if (!chk) | |
1678 code_closing(); | |
1679 } | |
1680 | |
99 | 1681 int |
1682 contains_in_list(int e,int type) | |
1683 { | |
1684 while(e) { | |
1685 if(contains(car(e),type)) return 1; | |
1686 e = cadr(e); | |
1687 } | |
1688 return 0; | |
1689 } | |
1690 | |
1691 int | |
1692 contains(int e,int type) | |
1693 { | |
1694 while(e) { | |
1695 if (car(e)==type) return 1; | |
256
d80e6387c539
powerpc function call complex arugment pre computation.
kono
parents:
255
diff
changeset
|
1696 if (!car(e)) return 0; |
164 | 1697 if (LIST_ARGS(car(e))){ |
99 | 1698 /* list arguments */ |
1699 return contains_in_list(caddr(e),type); | |
164 | 1700 } else if (UNARY_ARGS(car(e))) { |
99 | 1701 /* unary operators */ |
1702 e = cadr(e); | |
1703 continue; | |
164 | 1704 } else if (BINARY_ARGS(car(e))) { |
99 | 1705 /* biary operators */ |
1706 if (contains(cadr(e),type)) return 1; | |
1707 e = caddr(e); | |
1708 continue; | |
164 | 1709 } else if (TARNARY_ARGS(car(e))) { |
99 | 1710 /* tarary operators */ |
1711 if (contains(cadr(e), type)) return 1; | |
1712 if (contains(caddr(e),type)) return 1; | |
1713 e = cadddr(e); | |
1714 continue; | |
164 | 1715 } else if (NULLARY_ARGS(car(e))) { |
135 | 1716 /* nullary operators */ |
1717 return 0; | |
164 | 1718 } else { |
135 | 1719 fprintf(stderr,"Unknown Tree ID %d\n",car(e)); |
1720 error(-1); | |
99 | 1721 return 0; |
1722 } | |
1723 } | |
1724 return 0; | |
1725 } | |
1726 | |
223 | 1727 int |
1728 contains_in_list_p(int e,int (*p)(int)) | |
1729 { | |
1730 while(e) { | |
1731 if(contains_p(car(e),p)) return 1; | |
1732 e = cadr(e); | |
1733 } | |
1734 return 0; | |
1735 } | |
1736 | |
1737 int | |
1738 contains_p(int e,int (*p)(int)) | |
1739 { | |
1740 while(e) { | |
256
d80e6387c539
powerpc function call complex arugment pre computation.
kono
parents:
255
diff
changeset
|
1741 if (!car(e)) return 0; |
223 | 1742 if (p(car(e))) return 1; |
1743 if (LIST_ARGS(car(e))){ | |
1744 /* list arguments */ | |
1745 return contains_in_list_p(caddr(e),p); | |
1746 } else if (UNARY_ARGS(car(e))) { | |
1747 /* unary operators */ | |
1748 e = cadr(e); | |
1749 continue; | |
1750 } else if (BINARY_ARGS(car(e))) { | |
1751 /* biary operators */ | |
1752 if (contains_p(cadr(e),p)) return 1; | |
1753 e = caddr(e); | |
1754 continue; | |
1755 } else if (TARNARY_ARGS(car(e))) { | |
1756 /* tarary operators */ | |
1757 if (contains_p(cadr(e), p)) return 1; | |
1758 if (contains_p(caddr(e),p)) return 1; | |
1759 e = cadddr(e); | |
1760 continue; | |
1761 } else if (NULLARY_ARGS(car(e))) { | |
1762 /* nullary operators */ | |
1763 return 0; | |
1764 } else { | |
1765 fprintf(stderr,"Unknown Tree ID %d\n",car(e)); | |
1766 error(-1); | |
1767 return 0; | |
1768 } | |
1769 } | |
1770 return 0; | |
1771 } | |
1772 | |
61 | 1773 /* end */ |