| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <assert.h> |
| 23 |
|
| 24 |
#include "pass1.h" |
| 25 |
#include "pass2.h" |
| 26 |
|
| 27 |
#ifdef LANG_CXX |
| 28 |
#define p1listf listf |
| 29 |
#define p1tfree tfree |
| 30 |
#else |
| 31 |
#define NODE P1ND |
| 32 |
#define talloc p1alloc |
| 33 |
#define tcopy p1tcopy |
| 34 |
#define nfree p1nfree |
| 35 |
#endif |
| 36 |
|
| 37 |
static int rvnr; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
void |
| 43 |
setseg(int seg, char *name) |
| 44 |
{ |
| 45 |
switch (seg) { |
| 46 |
case PROG: name = ".text"; break; |
| 47 |
case DATA: |
| 48 |
case LDATA: name = ".data"; break; |
| 49 |
case UDATA: break; |
| 50 |
case PICLDATA: name = ".section .data.rel.local,\"aw\",@progbits";break; |
| 51 |
case PICDATA: name = ".section .data.rel.rw,\"aw\",@progbits"; break; |
| 52 |
case PICRDATA: name = ".section .data.rel.ro,\"aw\",@progbits"; break; |
| 53 |
case STRNG: |
| 54 |
case RDATA: name = ".section .rodata"; break; |
| 55 |
case TLSDATA: name = ".section .tdata,\"awT\",@progbits"; break; |
| 56 |
case TLSUDATA: name = ".section .tbss,\"awT\",@nobits"; break; |
| 57 |
case CTORS: name = ".section\t.ctors,\"aw\",@progbits"; break; |
| 58 |
case DTORS: name = ".section\t.dtors,\"aw\",@progbits"; break; |
| 59 |
case NMSEG: |
| 60 |
printf("\t.section %s,\"a%c\",@progbits\n", name, |
| 61 |
cftnsp ? 'x' : 'w'); |
| 62 |
return; |
| 63 |
} |
| 64 |
printf("\t%s\n", name); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
void |
| 72 |
defloc(struct symtab *sp) |
| 73 |
{ |
| 74 |
char *n; |
| 75 |
|
| 76 |
n = getexname(sp); |
| 77 |
#ifdef USE_GAS |
| 78 |
if (ISFTN(t)) |
| 79 |
printf("\t.type %s,%%function\n", n); |
| 80 |
#endif |
| 81 |
if (sp->sclass == EXTDEF) |
| 82 |
printf("\t.global %s\n", n); |
| 83 |
if (sp->slevel == 0 && !ISFTN(sp->stype)) |
| 84 |
printf("%s:\n", n); |
| 85 |
else |
| 86 |
printf(LABFMT ":\n", sp->soffset); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
static void |
| 93 |
putintemp(struct symtab *sym) |
| 94 |
{ |
| 95 |
NODE *p; |
| 96 |
|
| 97 |
p = tempnode(0, sym->stype, sym->sdf, sym->sap); |
| 98 |
p = buildtree(ASSIGN, p, nametree(sym)); |
| 99 |
sym->soffset = regno(p->n_left); |
| 100 |
sym->sflags |= STNODE; |
| 101 |
ecomp(p); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
static void |
| 107 |
param_64bit(struct symtab *sym, int *argofsp, int dotemps) |
| 108 |
{ |
| 109 |
int argofs = *argofsp; |
| 110 |
NODE *p, *q; |
| 111 |
int navail; |
| 112 |
|
| 113 |
#if ALLONGLONG == 64 |
| 114 |
|
| 115 |
++argofs; |
| 116 |
argofs &= ~1; |
| 117 |
*argofsp = argofs; |
| 118 |
#endif |
| 119 |
|
| 120 |
navail = NARGREGS - argofs; |
| 121 |
|
| 122 |
if (navail < 2) { |
| 123 |
|
| 124 |
if (features(FEATURE_BIGENDIAN)) { |
| 125 |
cerror("param_64bit"); |
| 126 |
p = q = NULL; |
| 127 |
} else { |
| 128 |
q = block(REG, NIL, NIL, INT, 0, 0); |
| 129 |
regno(q) = R0 + argofs; |
| 130 |
if (dotemps) { |
| 131 |
q = block(SCONV, q, NIL, |
| 132 |
ULONGLONG, 0, 0); |
| 133 |
p = nametree(sym); |
| 134 |
p->n_type = ULONGLONG; |
| 135 |
p->n_df = 0; |
| 136 |
p->n_ap = NULL; |
| 137 |
p = block(LS, p, bcon(32), ULONGLONG, 0, 0); |
| 138 |
q = block(PLUS, p, q, ULONGLONG, 0, 0); |
| 139 |
p = tempnode(0, ULONGLONG, 0, 0); |
| 140 |
sym->soffset = regno(p); |
| 141 |
sym->sflags |= STNODE; |
| 142 |
} else { |
| 143 |
p = nametree(sym); |
| 144 |
regno(p) = sym->soffset; |
| 145 |
p->n_type = INT; |
| 146 |
p->n_df = 0; |
| 147 |
p->n_ap = NULL; |
| 148 |
} |
| 149 |
} |
| 150 |
p = buildtree(ASSIGN, p, q); |
| 151 |
ecomp(p); |
| 152 |
*argofsp = argofs + 2; |
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
q = block(REG, NIL, NIL, sym->stype, sym->sdf, sym->sap); |
| 157 |
regno(q) = R16 + argofs; |
| 158 |
if (dotemps) { |
| 159 |
p = tempnode(0, sym->stype, sym->sdf, sym->sap); |
| 160 |
sym->soffset = regno(p); |
| 161 |
sym->sflags |= STNODE; |
| 162 |
} else { |
| 163 |
p = nametree(sym); |
| 164 |
} |
| 165 |
p = buildtree(ASSIGN, p, q); |
| 166 |
ecomp(p); |
| 167 |
*argofsp = argofs + 2; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
static void |
| 173 |
param_32bit(struct symtab *sym, int *argofsp, int dotemps) |
| 174 |
{ |
| 175 |
NODE *p, *q; |
| 176 |
|
| 177 |
q = block(REG, NIL, NIL, sym->stype, sym->sdf, sym->sap); |
| 178 |
regno(q) = R0 + (*argofsp)++; |
| 179 |
if (dotemps) { |
| 180 |
p = tempnode(0, sym->stype, sym->sdf, sym->sap); |
| 181 |
sym->soffset = regno(p); |
| 182 |
sym->sflags |= STNODE; |
| 183 |
} else { |
| 184 |
p = nametree(sym); |
| 185 |
} |
| 186 |
p = buildtree(ASSIGN, p, q); |
| 187 |
ecomp(p); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
static void |
| 193 |
param_double(struct symtab *sym, int *argofsp, int dotemps) |
| 194 |
{ |
| 195 |
NODE *p, *q, *t; |
| 196 |
int tmpnr; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
t = tempnode(0, ULONGLONG, 0, 0); |
| 205 |
tmpnr = regno(t); |
| 206 |
q = block(REG, NIL, NIL, INT, 0, 0); |
| 207 |
q->n_rval = R16 + (*argofsp)++; |
| 208 |
p = buildtree(ASSIGN, t, q); |
| 209 |
ecomp(p); |
| 210 |
|
| 211 |
if (dotemps) { |
| 212 |
sym->soffset = tmpnr; |
| 213 |
sym->sflags |= STNODE; |
| 214 |
} else { |
| 215 |
q = tempnode(tmpnr, sym->stype, sym->sdf, sym->sap); |
| 216 |
p = nametree(sym); |
| 217 |
p = buildtree(ASSIGN, p, q); |
| 218 |
ecomp(p); |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
static void |
| 225 |
param_float(struct symtab *sym, int *argofsp, int dotemps) |
| 226 |
{ |
| 227 |
NODE *p, *q, *t; |
| 228 |
int tmpnr; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
t = tempnode(0, INT, 0, 0); |
| 237 |
tmpnr = regno(t); |
| 238 |
q = block(REG, NIL, NIL, INT, 0, 0); |
| 239 |
q->n_rval = R0 + (*argofsp)++; |
| 240 |
p = buildtree(ASSIGN, t, q); |
| 241 |
ecomp(p); |
| 242 |
|
| 243 |
if (dotemps) { |
| 244 |
sym->soffset = tmpnr; |
| 245 |
sym->sflags |= STNODE; |
| 246 |
} else { |
| 247 |
q = tempnode(tmpnr, sym->stype, sym->sdf, sym->sap); |
| 248 |
p = nametree(sym); |
| 249 |
p = buildtree(ASSIGN, p, q); |
| 250 |
ecomp(p); |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
static void |
| 257 |
param_retstruct(void) |
| 258 |
{ |
| 259 |
NODE *p, *q; |
| 260 |
|
| 261 |
p = tempnode(0, PTR-FTN+cftnsp->stype, 0, cftnsp->sap); |
| 262 |
rvnr = regno(p); |
| 263 |
q = block(REG, NIL, NIL, PTR+STRTY, 0, cftnsp->sap); |
| 264 |
regno(q) = R0; |
| 265 |
p = buildtree(ASSIGN, p, q); |
| 266 |
ecomp(p); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
static void |
| 274 |
param_struct(struct symtab *sym, int *argofsp) |
| 275 |
{ |
| 276 |
int argofs = *argofsp; |
| 277 |
NODE *p, *q; |
| 278 |
int navail; |
| 279 |
int sz; |
| 280 |
int off; |
| 281 |
int num; |
| 282 |
int i; |
| 283 |
|
| 284 |
navail = NARGREGS - argofs; |
| 285 |
sz = tsize(sym->stype, sym->sdf, sym->sap) / SZINT; |
| 286 |
off = ARGINIT/SZINT + argofs; |
| 287 |
num = sz > navail ? navail : sz; |
| 288 |
for (i = 0; i < num; i++) { |
| 289 |
q = block(REG, NIL, NIL, INT, 0, 0); |
| 290 |
regno(q) = R0 + argofs++; |
| 291 |
p = block(REG, NIL, NIL, INT, 0, 0); |
| 292 |
regno(p) = SP; |
| 293 |
p = block(PLUS, p, bcon(4*off++), INT, 0, 0); |
| 294 |
p = block(UMUL, p, NIL, INT, 0, 0); |
| 295 |
p = buildtree(ASSIGN, p, q); |
| 296 |
ecomp(p); |
| 297 |
} |
| 298 |
|
| 299 |
*argofsp = argofs; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
void |
| 310 |
bfcode(struct symtab **sp, int cnt) |
| 311 |
{ |
| 312 |
union arglist *usym; |
| 313 |
int saveallargs = 0; |
| 314 |
int i, argofs = 0; |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
usym = cftnsp->sdf->dfun; |
| 321 |
while (usym && usym->type != TNULL) { |
| 322 |
if (usym->type == TELLIPSIS) { |
| 323 |
saveallargs = 1; |
| 324 |
break; |
| 325 |
} |
| 326 |
++usym; |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) { |
| 331 |
param_retstruct(); |
| 332 |
++argofs; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
for (i = 0; i < cnt; i++) { |
| 337 |
|
| 338 |
if (sp[i] == NULL) |
| 339 |
continue; |
| 340 |
|
| 341 |
if ((argofs >= NARGREGS) && !xtemps) |
| 342 |
break; |
| 343 |
|
| 344 |
if (argofs > NARGREGS) { |
| 345 |
putintemp(sp[i]); |
| 346 |
} else if (sp[i]->stype == STRTY || sp[i]->stype == UNIONTY) { |
| 347 |
param_struct(sp[i], &argofs); |
| 348 |
} else if (DEUNSIGN(sp[i]->stype) == LONGLONG || DEUNSIGN(sp[i]->stype) == LONG) { |
| 349 |
param_64bit(sp[i], &argofs, xtemps && !saveallargs); |
| 350 |
} else if (sp[i]->stype == DOUBLE || sp[i]->stype == LDOUBLE) { |
| 351 |
if (features(FEATURE_HARDFLOAT)) |
| 352 |
param_double(sp[i], &argofs, |
| 353 |
xtemps && !saveallargs); |
| 354 |
else |
| 355 |
param_64bit(sp[i], &argofs, |
| 356 |
xtemps && !saveallargs); |
| 357 |
} else if (sp[i]->stype == FLOAT) { |
| 358 |
if (features(FEATURE_HARDFLOAT)) |
| 359 |
param_float(sp[i], &argofs, |
| 360 |
xtemps && !saveallargs); |
| 361 |
else |
| 362 |
param_32bit(sp[i], &argofs, |
| 363 |
xtemps && !saveallargs); |
| 364 |
} else { |
| 365 |
param_32bit(sp[i], &argofs, xtemps && !saveallargs); |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
while (saveallargs && argofs < NARGREGS) { |
| 371 |
NODE *p, *q; |
| 372 |
int off = ARGINIT/SZINT + argofs; |
| 373 |
q = block(REG, NIL, NIL, INT, 0, 0); |
| 374 |
regno(q) = R0 + argofs++; |
| 375 |
p = block(REG, NIL, NIL, INT, 0, 0); |
| 376 |
regno(p) = SPREG; |
| 377 |
p = block(PLUS, p, bcon(4*off), INT, 0, 0); |
| 378 |
p = block(UMUL, p, NIL, INT, 0, 0); |
| 379 |
p = buildtree(ASSIGN, p, q); |
| 380 |
ecomp(p); |
| 381 |
} |
| 382 |
|
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
void |
| 389 |
efcode(void) |
| 390 |
{ |
| 391 |
NODE *p, *q; |
| 392 |
int tempnr; |
| 393 |
|
| 394 |
if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN) |
| 395 |
return; |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
q = block(REG, NIL, NIL, PTR+STRTY, 0, cftnsp->sap); |
| 406 |
q->n_rval = R0; |
| 407 |
p = tempnode(0, PTR+STRTY, 0, cftnsp->sap); |
| 408 |
tempnr = regno(p); |
| 409 |
p = buildtree(ASSIGN, p, q); |
| 410 |
ecomp(p); |
| 411 |
|
| 412 |
|
| 413 |
q = tempnode(tempnr, PTR+STRTY, 0, cftnsp->sap); |
| 414 |
q = buildtree(UMUL, q, NIL); |
| 415 |
|
| 416 |
|
| 417 |
p = tempnode(rvnr, PTR+STRTY, 0, cftnsp->sap); |
| 418 |
p = buildtree(UMUL, p, NIL); |
| 419 |
|
| 420 |
|
| 421 |
p = buildtree(ASSIGN, p, q); |
| 422 |
ecomp(p); |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
void |
| 429 |
ejobcode(int flag) |
| 430 |
{ |
| 431 |
printf("\t.ident \"PCC: %s\"\n", VERSSTR); |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
void |
| 440 |
bjobcode(void) |
| 441 |
{ |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
void |
| 448 |
fldty(struct symtab *p) |
| 449 |
{ |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
int |
| 459 |
mygenswitch(int num, TWORD type, struct swents **p, int n) |
| 460 |
{ |
| 461 |
return 0; |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
static NODE * |
| 475 |
straighten(NODE *p) |
| 476 |
{ |
| 477 |
NODE *r = p->n_right; |
| 478 |
|
| 479 |
if (p->n_op != CM || r->n_op != CM) |
| 480 |
return p; |
| 481 |
|
| 482 |
p->n_right = r->n_left; |
| 483 |
r->n_left = p; |
| 484 |
|
| 485 |
return r; |
| 486 |
} |
| 487 |
|
| 488 |
static NODE * |
| 489 |
reverse1(NODE *p, NODE *a) |
| 490 |
{ |
| 491 |
NODE *l = p->n_left; |
| 492 |
NODE *r = p->n_right; |
| 493 |
|
| 494 |
a->n_right = r; |
| 495 |
p->n_left = a; |
| 496 |
|
| 497 |
if (l->n_op == CM) { |
| 498 |
return reverse1(l, p); |
| 499 |
} else { |
| 500 |
p->n_right = l; |
| 501 |
return p; |
| 502 |
} |
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
static NODE * |
| 509 |
reverse(NODE *p) |
| 510 |
{ |
| 511 |
NODE *l = p->n_left; |
| 512 |
NODE *r = p->n_right; |
| 513 |
|
| 514 |
p->n_left = r; |
| 515 |
|
| 516 |
if (l->n_op == CM) |
| 517 |
return reverse1(l, p); |
| 518 |
|
| 519 |
p->n_right = l; |
| 520 |
|
| 521 |
return p; |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
static NODE * |
| 528 |
pusharg(NODE *p, int *regp) |
| 529 |
{ |
| 530 |
NODE *q; |
| 531 |
int sz; |
| 532 |
|
| 533 |
|
| 534 |
sz = tsize(p->n_type, p->n_df, p->n_ap); |
| 535 |
if (sz < SZINT) |
| 536 |
p = block(SCONV, p, NIL, INT, 0, 0); |
| 537 |
|
| 538 |
q = block(REG, NIL, NIL, INT, 0, 0); |
| 539 |
regno(q) = SP; |
| 540 |
|
| 541 |
if (szty(p->n_type) == 1) { |
| 542 |
++(*regp); |
| 543 |
q = block(MINUSEQ, q, bcon(4), INT, 0, 0); |
| 544 |
} else { |
| 545 |
(*regp) += 2; |
| 546 |
q = block(MINUSEQ, q, bcon(8), INT, 0, 0); |
| 547 |
} |
| 548 |
|
| 549 |
q = block(UMUL, q, NIL, p->n_type, p->n_df, p->n_ap); |
| 550 |
|
| 551 |
return buildtree(ASSIGN, q, p); |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
static NODE * |
| 557 |
movearg_32bit(NODE *p, int *regp) |
| 558 |
{ |
| 559 |
int reg = *regp; |
| 560 |
NODE *q; |
| 561 |
|
| 562 |
q = block(REG, NIL, NIL, p->n_type, p->n_df, p->n_ap); |
| 563 |
regno(q) = reg++; |
| 564 |
q = buildtree(ASSIGN, q, p); |
| 565 |
|
| 566 |
*regp = reg; |
| 567 |
return q; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
static NODE * |
| 573 |
movearg_64bit(NODE *p, int *regp) |
| 574 |
{ |
| 575 |
int reg = *regp; |
| 576 |
NODE *q, *r; |
| 577 |
|
| 578 |
#if ALLONGLONG == 64 |
| 579 |
|
| 580 |
++reg; |
| 581 |
reg &= ~1; |
| 582 |
*regp = reg; |
| 583 |
#endif |
| 584 |
|
| 585 |
if (reg > R3) { |
| 586 |
q = pusharg(p, regp); |
| 587 |
} else if (reg == R3) { |
| 588 |
|
| 589 |
r = tcopy(p); |
| 590 |
if (!features(FEATURE_BIGENDIAN)) { |
| 591 |
q = block(SCONV, p, NIL, INT, 0, 0); |
| 592 |
q = movearg_32bit(q, regp); |
| 593 |
r = buildtree(RS, r, bcon(32)); |
| 594 |
r = block(SCONV, r, NIL, INT, 0, 0); |
| 595 |
r = pusharg(r, regp); |
| 596 |
} else { |
| 597 |
q = buildtree(RS, p, bcon(32)); |
| 598 |
q = block(SCONV, q, NIL, INT, 0, 0); |
| 599 |
q = movearg_32bit(q, regp); |
| 600 |
r = block(SCONV, r, NIL, INT, 0, 0); |
| 601 |
r = pusharg(r, regp); |
| 602 |
} |
| 603 |
q = straighten(block(CM, q, r, p->n_type, p->n_df, p->n_ap)); |
| 604 |
} else { |
| 605 |
q = block(REG, NIL, NIL, p->n_type, p->n_df, p->n_ap); |
| 606 |
regno(q) = R16 + (reg - R0); |
| 607 |
q = buildtree(ASSIGN, q, p); |
| 608 |
*regp = reg + 2; |
| 609 |
} |
| 610 |
|
| 611 |
return q; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
static NODE * |
| 617 |
movearg_float(NODE *p, int *regp) |
| 618 |
{ |
| 619 |
NODE *q, *r; |
| 620 |
TWORD ty = INCREF(p->n_type); |
| 621 |
int tmpnr; |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
if (xtemps) { |
| 629 |
|
| 630 |
r = block(REG, NIL, NIL, ty, p->n_df, p->n_ap); |
| 631 |
regno(r) = SP; |
| 632 |
r = block(PLUS, r, bcon(-4), ty, p->n_df, p->n_ap); |
| 633 |
r = block(UMUL, r, NIL, p->n_type, p->n_df, p->n_ap); |
| 634 |
r = buildtree(ASSIGN, r, p); |
| 635 |
ecomp(r); |
| 636 |
|
| 637 |
|
| 638 |
r = block(REG, NIL, NIL, PTR+INT, 0, 0); |
| 639 |
regno(r) = SP; |
| 640 |
r = block(PLUS, r, bcon(-8), PTR+INT, 0, 0); |
| 641 |
r = block(UMUL, r, NIL, INT, 0, 0); |
| 642 |
q = tempnode(0, INT, 0, 0); |
| 643 |
tmpnr = regno(q); |
| 644 |
r = buildtree(ASSIGN, q, r); |
| 645 |
ecomp(r); |
| 646 |
} else { |
| 647 |
|
| 648 |
q = tempnode(0, p->n_type, p->n_df, p->n_ap); |
| 649 |
tmpnr = regno(q); |
| 650 |
r = buildtree(ASSIGN, q, p); |
| 651 |
ecomp(r); |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
r = tempnode(tmpnr, INT, 0, 0); |
| 656 |
q = block(REG, NIL, NIL, INT, 0, 0); |
| 657 |
regno(q) = (*regp)++; |
| 658 |
p = buildtree(ASSIGN, q, r); |
| 659 |
|
| 660 |
return p; |
| 661 |
} |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
static NODE * |
| 666 |
movearg_double(NODE *p, int *regp) |
| 667 |
{ |
| 668 |
NODE *q, *r; |
| 669 |
TWORD ty = INCREF(p->n_type); |
| 670 |
int tmpnr; |
| 671 |
|
| 672 |
if (xtemps) { |
| 673 |
|
| 674 |
r = block(REG, NIL, NIL, ty, p->n_df, p->n_ap); |
| 675 |
regno(r) = SP; |
| 676 |
r = block(PLUS, r, bcon(-8), ty, p->n_df, p->n_ap); |
| 677 |
r = block(UMUL, r, NIL, p->n_type, p->n_df, p->n_ap); |
| 678 |
r = buildtree(ASSIGN, r, p); |
| 679 |
ecomp(r); |
| 680 |
|
| 681 |
|
| 682 |
r = block(REG, NIL, NIL, PTR+LONGLONG, 0, 0); |
| 683 |
regno(r) = SP; |
| 684 |
r = block(PLUS, r, bcon(-8), PTR+LONGLONG, 0, 0); |
| 685 |
r = block(UMUL, r, NIL, LONGLONG, 0, 0); |
| 686 |
q = tempnode(0, LONGLONG, 0, 0); |
| 687 |
tmpnr = regno(q); |
| 688 |
r = buildtree(ASSIGN, q, r); |
| 689 |
ecomp(r); |
| 690 |
} else { |
| 691 |
|
| 692 |
q = tempnode(0, p->n_type, p->n_df, p->n_ap); |
| 693 |
tmpnr = regno(q); |
| 694 |
r = buildtree(ASSIGN, q, p); |
| 695 |
ecomp(r); |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
r = tempnode(tmpnr, LONGLONG, 0, 0); |
| 700 |
q = block(REG, NIL, NIL, LONGLONG, 0, 0); |
| 701 |
regno(q) = R16 - R0 + (*regp); |
| 702 |
p = buildtree(ASSIGN, q, r); |
| 703 |
|
| 704 |
(*regp) += 2; |
| 705 |
|
| 706 |
return p; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
static NODE * |
| 713 |
movearg_struct(NODE *p, int *regp) |
| 714 |
{ |
| 715 |
int reg = *regp; |
| 716 |
NODE *l, *q, *t, *r; |
| 717 |
int tmpnr; |
| 718 |
int navail; |
| 719 |
int num; |
| 720 |
int sz; |
| 721 |
int ty; |
| 722 |
int i; |
| 723 |
|
| 724 |
assert(p->n_op == STARG); |
| 725 |
|
| 726 |
navail = NARGREGS - (reg - R0); |
| 727 |
navail = navail < 0 ? 0 : navail; |
| 728 |
sz = tsize(p->n_type, p->n_df, p->n_ap) / SZINT; |
| 729 |
num = sz > navail ? navail : sz; |
| 730 |
|
| 731 |
|
| 732 |
l = p->n_left; |
| 733 |
nfree(p); |
| 734 |
ty = l->n_type; |
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
t = tempnode(0, ty, l->n_df, l->n_ap); |
| 741 |
tmpnr = regno(t); |
| 742 |
q = buildtree(ASSIGN, t, l); |
| 743 |
|
| 744 |
|
| 745 |
for (i = 0; i < num; i++) { |
| 746 |
t = tempnode(tmpnr, ty, 0, 0); |
| 747 |
t = block(SCONV, t, NIL, PTR+INT, 0, 0); |
| 748 |
t = block(PLUS, t, bcon(4*i), PTR+INT, 0, 0); |
| 749 |
t = buildtree(UMUL, t, NIL); |
| 750 |
|
| 751 |
r = block(REG, NIL, NIL, INT, 0, 0); |
| 752 |
regno(r) = reg++; |
| 753 |
r = buildtree(ASSIGN, r, t); |
| 754 |
|
| 755 |
q = block(CM, q, r, INT, 0, 0); |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
for (i = num; i < sz; i++) { |
| 760 |
t = tempnode(tmpnr, ty, 0, 0); |
| 761 |
t = block(SCONV, t, NIL, PTR+INT, 0, 0); |
| 762 |
t = block(PLUS, t, bcon(4*i), PTR+INT, 0, 0); |
| 763 |
t = buildtree(UMUL, t, NIL); |
| 764 |
r = pusharg(t, ®); |
| 765 |
q = block(CM, q, r, INT, 0, 0); |
| 766 |
} |
| 767 |
|
| 768 |
q = reverse(q); |
| 769 |
|
| 770 |
*regp = reg; |
| 771 |
return q; |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
static NODE * |
| 776 |
moveargs(NODE *p, int *regp) |
| 777 |
{ |
| 778 |
NODE *r, **rp; |
| 779 |
int reg; |
| 780 |
|
| 781 |
if (p->n_op == CM) { |
| 782 |
p->n_left = moveargs(p->n_left, regp); |
| 783 |
r = p->n_right; |
| 784 |
rp = &p->n_right; |
| 785 |
} else { |
| 786 |
r = p; |
| 787 |
rp = &p; |
| 788 |
} |
| 789 |
|
| 790 |
reg = *regp; |
| 791 |
|
| 792 |
if (reg > R3 && r->n_op != STARG) { |
| 793 |
*rp = pusharg(r, regp); |
| 794 |
} else if (r->n_op == STARG) { |
| 795 |
*rp = movearg_struct(r, regp); |
| 796 |
} else if (DEUNSIGN(r->n_type) == LONGLONG) { |
| 797 |
*rp = movearg_64bit(r, regp); |
| 798 |
} else if (r->n_type == DOUBLE || r->n_type == LDOUBLE) { |
| 799 |
*rp = movearg_double(r, regp); |
| 800 |
} else if (r->n_type == FLOAT) { |
| 801 |
*rp = movearg_float(r, regp); |
| 802 |
} else { |
| 803 |
*rp = movearg_32bit(r, regp); |
| 804 |
} |
| 805 |
|
| 806 |
return straighten(p); |
| 807 |
} |
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
static NODE * |
| 815 |
retstruct(NODE *p) |
| 816 |
{ |
| 817 |
NODE *l, *r, *t, *q; |
| 818 |
TWORD ty; |
| 819 |
|
| 820 |
l = p->n_left; |
| 821 |
r = p->n_right; |
| 822 |
|
| 823 |
ty = DECREF(l->n_type) - FTN; |
| 824 |
|
| 825 |
|
| 826 |
q = tempnode(0, ty, l->n_df, l->n_ap); |
| 827 |
q = buildtree(ADDROF, q, NIL); |
| 828 |
|
| 829 |
|
| 830 |
if (r->n_op != CM) { |
| 831 |
p->n_right = block(CM, q, r, INCREF(ty), l->n_df, l->n_ap); |
| 832 |
} else { |
| 833 |
for (t = r; t->n_left->n_op == CM; t = t->n_left) |
| 834 |
; |
| 835 |
t->n_left = block(CM, q, t->n_left, INCREF(ty), |
| 836 |
l->n_df, l->n_ap); |
| 837 |
} |
| 838 |
|
| 839 |
return p; |
| 840 |
} |
| 841 |
|
| 842 |
NODE * |
| 843 |
builtin_frame_address(const struct bitable *bt, NODE *a) |
| 844 |
{ |
| 845 |
assert(0); |
| 846 |
return NULL; |
| 847 |
} |
| 848 |
|
| 849 |
NODE * |
| 850 |
builtin_return_address(const struct bitable *bt, NODE *a) |
| 851 |
{ |
| 852 |
assert(0); |
| 853 |
return NULL; |
| 854 |
} |
| 855 |
|
| 856 |
NODE * |
| 857 |
builtin_cfa(const struct bitable *bt, NODE *a) |
| 858 |
{ |
| 859 |
assert(0); |
| 860 |
return NULL; |
| 861 |
} |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
NODE * |
| 868 |
funcode(NODE *p) |
| 869 |
{ |
| 870 |
int reg = R0; |
| 871 |
|
| 872 |
if (p->n_type == STRTY+FTN || p->n_type == UNIONTY+FTN) { |
| 873 |
p = retstruct(p); |
| 874 |
reg = R1; |
| 875 |
} |
| 876 |
|
| 877 |
p->n_right = moveargs(p->n_right, ®); |
| 878 |
|
| 879 |
if (p->n_right == NULL) |
| 880 |
p->n_op += (UCALL - CALL); |
| 881 |
|
| 882 |
return p; |
| 883 |
} |