Quick Search:

Mode

Context

Displaying the whole file. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.34
 
1.35
 
MAIN:ragge:20120925191750
 
local2.c
_>11 /*      $Id$    */
 22 /*
 33  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
 44  *
 55  * Redistribution and use in source and binary forms, with or without
 66  * modification, are permitted provided that the following conditions
 77  * are met:
 88  *
 99  * Redistributions of source code and documentation must retain the above
 1010  * copyright notice, this list of conditions and the following disclaimer.
 1111  * Redistributions in binary form must reproduce the above copyright
 1212  * notice, this list of conditionsand the following disclaimer in the
 1313  * documentation and/or other materials provided with the distribution.
 1414  * All advertising materials mentioning features or use of this software
 1515  * must display the following acknowledgement:
 1616  *      This product includes software developed or owned by Caldera
 1717  *      International, Inc.
 1818  * Neither the name of Caldera International, Inc. nor the names of other
 1919  * contributors may be used to endorse or promote products derived from
 2020  * this software without specific prior written permission.
 2121  *
 2222  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
 2323  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
 2424  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 2525  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 2626  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
 2727  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 2828  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 2929  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 3030  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
 3131  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 3232  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 3333  * POSSIBILITY OF SUCH DAMAGE.
 3434  */
 3535 
 3636 # include "pass2.h"
 3737 # include "ctype.h"
 3838 /* a lot of the machine dependent parts of the second pass */
 3939 
 4040 static void prtype(NODE *n);
 4141 static void acon(NODE *p);
 4242 
 4343 /*
 4444  * Print out the prolog assembler.
 4545  * addto and regoff are already calculated.
 4646  */
 4747 void
 4848 prologue(struct interpass_prolog *ipp)
 4949 {
 5050         printf("        .word 0x%llx\n", (unsigned long long)ipp->ipp_regs[0]);
 5151         if (p2maxautooff)
 5252                 printf("        subl2 $%d,%%sp\n", p2maxautooff);
 5353         if (pflag) {
 5454                 int i = getlab2();
 5555                 printf("\tmovab\t" LABFMT ",%%r0\n", i);
 5656                 printf("\tjsb\t__mcount\n");
 5757                 printf("\t.data\n");
 5858                 printf("\t.align  2\n");
 5959                 printf(LABFMT ":\t.long\t0\n", i);
 6060                 printf("\t.text\n");
 6161         }
 6262 }
 6363 
 6464 /*
 6565  * Called after all instructions in a function are emitted.
 6666  * Generates code for epilog here.
 6767  */
 6868 void
 6969 eoftn(struct interpass_prolog *ipp)
 7070 {
 7171         if (ipp->ipp_ip.ip_lbl == 0)
 7272                 return; /* no code needs to be generated */
 7373         printf("        ret\n");
 7474 }
 7575 
 7676 struct hoptab { int opmask; char * opstring; } ioptab[] = {
 7777 
 7878         { PLUS"add", },
 7979         { MINUS,        "sub", },
 8080         { MUL,  "mul", },
 8181         { DIV,  "div", },
 8282         { OR,   "bis", },
 8383         { ER,   "xor", },
 8484         { AND,  "bic", },
 8585         { -1, ""     },
 8686 };
 8787 
 8888 void
 8989 hopcode( f, o ){
 9090         /* output the appropriate string from the above table */
 9191 
 9292         register struct hoptab *q;
 9393 
 9494         for( q = ioptabq->opmask>=0; ++q ){
 9595                 if( q->opmask == o ){
 9696                         printf( "%s", q->opstring );
 9797 /* tbl
 9898                         if( f == 'F' ) printf( "e" );
 9999                         else if( f == 'D' ) printf( "d" );
 100100    tbl */
 101101 /* tbl */
 102102                         switch( f ) {
 103103                                 case 'L':
 104104                                 case 'W':
 105105                                 case 'B':
 106106                                 case 'D':
 107107                                 case 'F':
 108108                                         printf("%c", tolower(f));
 109109                                         break;
 110110 
 111111                                 }
 112112 /* tbl */
 113113                         return;
 114114                         }
 115115                 }
 116116         cerror( "no hoptab for %s", opst[o] );
 117117         }
 118118 
 119119 char *
 120120 rnames[] = {  /* keyed to register number tokens */
 121121 
 122122         "%r0", "%r1", "%r2", "%r3", "%r4", "%r5",
 123123         "%r6", "%r7", "%r8", "%r9", "%r10", "%r11",
 124124         "%ap", "%fp", "%sp", "%pc",
 125125         /* The concatenated regs has the name of the lowest */
 126126         "%r0", "%r1", "%r2", "%r3", "%r4", "%r5",
 127127         "%r6", "%r7", "%r8", "%r9", "%r10"
 128128         };
 129129 
 130130 int
 131131 tlen(NODE *p)
 132132 {
 133133         switch(p->n_type) {
 134134         case CHAR:
 135135         case UCHAR:
 136136                 return(1);
 137137 
 138138         case SHORT:
 139139         case USHORT:
 140140                 return(2);
 141141 
 142142         case DOUBLE:
 143143         case LONGLONG:
 144144         case ULONGLONG:
 145145                 return(8);
 146146 
 147147         default:
 148148                 return(4);
 149149         }
 150150 }
 151151 
 152152 void
 153153 prtype(NODE *n)
 154154 {
 155155         static char pt[] = { 0, 0, 'b', 'b', 'w', 'w', 'l', 'l', 0, 0,
 156156             'q', 'q', 'f', 'd' };
 157157         TWORD t = n->n_type;
 158158 
 159159         if (ISPTR(t))
 160160                 t = UNSIGNED;
 161161 
 162162         if (t > DOUBLE || pt[t] == 0)
 163163                 comperr("prtype: bad type");
 164164         putchar(pt[t]);
 165165 }
 166166 
 167167 /*
 168168  * Emit conversions as given by the following table. Dest is always reg,
 169169  *   if it should be something else let peephole optimizer deal with it.
 170170  *   This code ensures type correctness in 32-bit registers.
 171171  *   XXX is that necessary?
 172172  *
 173173  * From                         To
 174174  *       char   uchar  short  ushort int    uint   ll    ull   float double
 175175  * char  movb   movb   cvtbw  cvtbw  cvtbl  cvtbl  A     A     cvtbf cvtbd
 176176  * uchar movb   movb   movzbw movzbw movzbl movzbl B     B     G     G
 177177  * short movb   movb   movw   movw   cvtwl  cvtwl  C(A)  C(A)  cvtwf cvtwd
 178178  * ushrt movb   movb   movw   movw   movzwl movzwl D(B)  D(B)  H     H
 179179  * int   movb   movb   movw   movw   movl   movl   E     E     cvtlf cvtld
 180180  * uint  movb   movb   movw   movw   movl   movl   F     F     I     I
 181181  * ll    movb   movb   movw   movw   movl   movl   movq  movq  J     K
 182182  * ull   movb   movb   movw   movw   movl   movl   movq  movq  L     M
 183183  * float cvtfb  cvtfb  cvtfw  cvtfw  cvtfl  cvtfl  N     O     movf  cvtfd
 184184  * doubl cvtdb  cvtdb  cvtdw  cvtdw  cvtdl  cvtdl  P     Q     cvtdf movd
 185185  *
 186186  *  A: cvtbl + sign extend
 187187  *  B: movzbl + zero extend
 188188  *  G: movzbw + cvtwX
 189189  *  H: movzwl + cvtwX
 190190  *  I: cvtld + addX
 191191  *  J: call __floatdisf
 192192  *  K: call __floatdidf
 193193  *  L: xxx + call __floatdisf
 194194  *  M: xxx + call __floatdidf
 195195  *  N: call __fixsfdi
 196196  *  O: call __fixunssfdi
 197197  *  P: call __fixdfdi
 198198  *  Q: call __fixunsdfdi
 199199  */
 200200 
 201201 #define MVD     1 /* mov + dest type */
 202202 #define CVT     2 /* cvt + src type + dst type */
 203203 #define MVZ     3 /* movz + src type + dst type */
 204204 #define CSE     4 /* cvt + src type + l + sign extend upper */
 205205 #define MZE     5 /* movz + src type + l + zero extend upper */
 206206 #define MLE     6 /* movl + sign extend upper */
 207207 #define MLZ     7 /* movl + zero extend upper */
 208208 #define MZC     8 /* movz + cvt */
 209209 
 210210 static char scary[][10] = {
 211211         { MVD, MVD, CVT, CVT, CVT, CVT, CSE, CSE, CVT, CVT },
 212212         { MVD, MVD, MVZ, MVZ, MVZ, MVZ, MZE, MZE, MZC, MZC },
 213213         { MVD, MVD, MVD, MVD, CVT, CVT, CSE, CSE, CVT, CVT },
 214214         { MVD, MVD, MVD, MVD, MVZ, MVZ, MZE, MZE, MZC, MZC },
 215215         { MVD, MVD, MVD, MVD, MVD, MVD, MLE, MLE, CVT, CVT },
 216216         { MVD, MVD, MVD, MVD, MVD, MVD, MLZ, MLZ, 'I', 'I' },
 217217         { MVD, MVD, MVD, MVD, MVD, MVD, MVD, MVD, 'J', 'K' },
 218218         { MVD, MVD, MVD, MVD, MVD, MVD, MVD, MVD, 'L', 'M' },
 219219         { CVT, CVT, CVT, CVT, CVT, CVT, 'N', 'O', MVD, CVT },
 220220         { CVT, CVT, CVT, CVT, CVT, CVT, 'P', 'Q', CVT, MVD },
 221221 };
 222222 
 223223 static void
 224224 sconv(NODE *p)
 225225 {
 226226         NODE *l = p->n_left;
 227227         TWORD ts, td;
 228228         int o;
 229229 
 230230         /*
 231231          * Source node may be in register or memory.
 232232          * Result is always in register.
 233233          */
 234234         ts = l->n_type;
 235235         if (ISPTR(ts))
 236236                 ts = UNSIGNED;
 237237         td = p->n_type;
 238238         ts = ts < LONG ? ts-2 : ts-4;
 239239         td = td < LONG ? td-2 : td-4;
 240240 
 241241         o = scary[ts][td];
 242242         switch (o) {
 243243         case MLE:
 244244         case MLZ:
 245245                 expand(p, INAREG|INBREG, "\tmovl\tAL,A1\n");
 246246                 break;
 247247 
 248248         case MVD:
 249249                 if (l->n_op == REG && regno(l) == regno(getlr(p, '1')))
 250250                         break; /* unneccessary move */
 251251                 expand(p, INAREG|INBREG, "\tmovZR\tAL,A1\n");
 252252                 break;
 253253 
 254254         case CSE:
 255255                 expand(p, INAREG|INBREG, "\tcvtZLl\tAL,A1\n");
 256256                 break;
 257257 
 258258         case CVT:
 259259                 expand(p, INAREG|INBREG, "\tcvtZLZR\tAL,A1\n");
 260260                 break;
 261261 
 262262         case MZE:
 263263                 expand(p, INAREG|INBREG, "\tmovzZLl\tAL,A1\n");
 264264                 break;
 265265 
 266266         case MVZ:
 267267                 expand(p, INAREG|INBREG, "\tmovzZLZR\tAL,A1\n");
 268268                 break;
 269269 
 270270         case MZC:
 271271                 expand(p, INAREG|INBREG, "\tmovzZLl\tAL,A1\n");
 272272                 expand(p, INAREG|INBREG, "\tcvtlZR\tA1,A1\n");
 273273                 break;
 274274 
 275275         case 'I': /* unsigned to double */
 276276                 expand(p, INAREG|INBREG, "\tcvtld\tAL,A1\n");
 277277                 printf("\tjgeq\t1f\n");
 278278                 expand(p, INAREG|INBREG, "\taddd2\t$0d4.294967296e+9,A1\n");
 279279                 printf("1:\n");
 280280                 break;
 281281         default:
 282282                 comperr("unsupported conversion %d", o);
 283283         }
 284284         switch (o) {
 285285         case MLE:
 286286         case CSE:
 287287                 expand(p, INBREG, "\tashl\t$-31,A1,U1\n");
 288288                 break;
 289289         case MLZ:
 290290         case MZE:
 291291                 expand(p, INAREG|INBREG, "\tclrl\tU1\n");
 292292                 break;
 293293         }
 294294 }
 295295 
 296296 /*
 297297  * Assign a constant from p to q.  Both are expected to be leaves by now.
 298298  * This is for 64-bit integers.
 299299  */
 300300 static void
 301301 casg64(NODE *p)
 302302 {
 303303         NODE *l, *r;
 304304         char *str;
 305305         int mneg = 1;
 306306         
 307307         l = p->n_left;
 308308         r = p->n_right;
 309309 
 310310 #ifdef PCC_DEBUG
 311311         if (r->n_op != ICON)
 312312                 comperr("casg");
 313313 #endif
 314314         if (r->n_name[0] != '\0') {
 315315                 /* named constant, nothing to do */
 316316                 str = "movq\tAR,AL";
 317317                 mneg = 0;
 318318         } else if (r->n_lval == 0) {
 319319                 str = "clrq\tAL";
 320320                 mneg = 0;
 321321         } else if (r->n_lval < 0) {
 322322                 if (r->n_lval >= -63) {
 323323                         r->n_lval = -r->n_lval;
 324324                         str = "mnegl\tAR,AL";
 325325                 } else if (r->n_lval >= -128) {
 326326                         str = "cvtbl\tAR,AL";
 327327                 } else if (r->n_lval >= -32768) {
 328328                         str = "cvtwl\tAR,AL";
 329329                 } else if (r->n_lval >= -4294967296LL) {
 330330                         str = "movl\tAR,AL";
 331331                 } else {
 332332                         str = "movq\tAR,AL";
 333333                         mneg = 0;
 334334                 }
 335335         } else {
 336336                 mneg = 0;
 337337                 if (r->n_lval <= 63 || r->n_lval > 4294967295LL) {
 338338                         str = "movq\tAR,AL";
 339339                 } else if (r->n_lval <= 255) {
 340340                         str = "movzbl\tAR,AL\n\tclrl\tUL";
 341341                 } else if (r->n_lval <= 65535) {
 342342                         str = "movzwl\tAR,AL\n\tclrl\tUL";
 343343                 } else /* if (r->n_lval <= 4294967295) */ {
 344344                         str = "movl\tAR,AL\n\tclrl\tUL";
 345345                 }
 346346         }
 347347         expand(p, FOREFF, str);
 348348         if (mneg)
 349349                 expand(p, FOREFF, "\n\tmnegl $-1,UL");
 350350 }
 351351 
 352352 /*
 353353  * Assign a constant from p to q.  Both are expected to be leaves by now.
 354354  * This is only for 32-bit integer types.
 355355  */
 356356 static void
 357357 casg(NODE *p)
 358358 {
 359359         NODE *l, *r;
 360360         char *str;
 361361         
 362362         l = p->n_left;
 363363         r = p->n_right;
 364364 
 365365 #ifdef PCC_DEBUG
 366366         if (r->n_op != ICON)
 367367                 comperr("casg");
 368368 #endif
 369369         if (r->n_name[0] != '\0') {
 370370                 /* named constant, nothing to do */
 371371                 str = "movZL\tAR,AL";
 372372         } else if (r->n_lval == 0) {
 373373                 str = "clrZL\tAL";
 374374         } else if (r->n_lval < 0) {
 375375                 if (r->n_lval >= -63) {
 376376                         r->n_lval = -r->n_lval;
 377377                         str = "mnegZL\tAR,AL";
 378378                 } else if (r->n_lval >= -128) {
 379379                         if (l->n_type == CHAR)
 380380                                 str = "movb\tAR,AL";
 381381                         else
 382382                                 str = "cvtbZL\tAR,AL";
 383383                 } else if (r->n_lval >= -32768) {
 384384                         if (l->n_type == SHORT)
 385385                                 str = "movw\tAR,AL";
 386386                         else
 387387                                 str = "cvtwZL\tAR,AL";
 388388                 } else
 389389                         str = "movZL\tAR,AL";
 390390         } else {
 391391                 if (r->n_lval <= 63 || r->n_lval > 65535) {
 392392                         str = "movZL\tAR,AL";
 393393                 } else if (r->n_lval <= 255) {
 394394                         str = l->n_type < SHORT ?
 395395                             "movb\tAR,AL" : "movzbZL\tAR,AL";
 396396                 } else /* if (r->n_lval <= 65535) */ {
 397397                         str = l->n_type < INT ?
 398398                             "movw\tAR,AL" : "movzwZL\tAR,AL";
 399399                 }
 400400         }
 401401         expand(p, FOREFF, str);
 402402 }
 403403 
 404404 /*
 405405  * Emit code to compare two longlong numbers.
 406406  */
 407407 static void
 408408 twollcomp(NODE *p)
 409409 {
 410410         int u;
 411411         int s = getlab2();
 412412         int e = p->n_label;
 413413         int cb1, cb2;
 414414 
 415415         u = p->n_op;
 416416         switch (p->n_op) {
 417417         case NE:
 418418                 cb1 = 0;
 419419                 cb2 = NE;
 420420                 break;
 421421         case EQ:
 422422                 cb1 = NE;
 423423                 cb2 = 0;
 424424                 break;
 425425         case LE:
 426426         case LT:
 427427                 u += (ULE-LE);
 428428                 /* FALLTHROUGH */
 429429         case ULE:
 430430         case ULT:
 431431                 cb1 = GT;
 432432                 cb2 = LT;
 433433                 break;
 434434         case GE:
 435435         case GT:
 436436                 u += (ULE-LE);
 437437                 /* FALLTHROUGH */
 438438         case UGE:
 439439         case UGT:
 440440                 cb1 = LT;
 441441                 cb2 = GT;
 442442                 break;
 443443         
 444444         default:
 445445                 cb1 = cb2 = 0; /* XXX gcc */
 446446         }
 447447         if (p->n_op >= ULE)
 448448                 cb1 += 4, cb2 += 4;
 449449         expand(p, 0, "  cmpl UL,UR\n");
 450450         if (cb1) cbgen(cb1, s);
 451451         if (cb2) cbgen(cb2, e);
 452452         expand(p, 0, "  cmpl AL,AR\n");
 453453         cbgen(u, e);
 454454         deflab(s);
 455455 }
 456456 
 457457 
 458458 void
 459459 zzzcode(NODE *p, int c)
 460460 {
 461461         NODE *l, *r;
<> 462+        TWORD t;
462463         int m;
 463464         char *ch;
 464465 
 465466         switch (c) {
 466467         case 'N'/* logical ops, turned into 0-1 */
 467468                 /* use register given by register 1 */
 468469                 cbgen( 0, m=getlab2());
 469470                 deflab( p->n_label );
 470471                 printf( "       clrl    %s\n", rnames[getlr( p, '1' )->n_rval] );
 471472                 deflab( m );
 472473                 return;
 473474 
 474475         case 'A': /* Assign a constant directly to a memory position */
 475476                 printf("\t");
 476477                 if (p->n_type < LONG || ISPTR(p->n_type))
 477478                         casg(p);
 478479                 else
 479480                         casg64(p);
 480481                 printf("\n");
 481482                 break;
 482483 
 483484         case 'B': /* long long compare */
 484485                 twollcomp(p);
 485486                 break;
 486487 
 487488         case 'C':       /* num words pushed on arg stack */
 488489                 printf("$%d", p->n_qual);
 489490                 break;
 490491 
 491492         case 'D':       /* INCR and DECR */
 492493                 zzzcode(p->n_left, 'A');
 493494                 printf("\n      ");
 494495 
 495496 #if 0
 496497         case 'E':       /* INCR and DECR, FOREFF */
 497498                 if (p->n_right->n_lval == 1)
 498499                         {
 499500                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
 500501                         prtype(p->n_left);
 501502                         printf("        ");
 502503                         adrput(stdout, p->n_left);
 503504                         return;
 504505                         }
 505506                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
 506507                 prtype(p->n_left);
 507508                 printf("2       ");
 508509                 adrput(stdout, p->n_right);
 509510                 printf(",");
 510511                 adrput(p->n_left);
 511512                 return;
 512513 #endif
 513514 
 514515         case 'F':       /* register type of right operand */
 515516                 {
 516517                 register NODE *n;
 517518                 register int ty;
 518519 
 519520                 n = getlr( p, 'R' );
 520521                 ty = n->n_type;
 521522 
 522523                 if (x2debug) printf("->%d<-", ty);
 523524 
 524525                 if ( ty==DOUBLE) printf("d");
 525526                 else if ( ty==FLOAT ) printf("f");
 526527                 else printf("l");
 527528                 return;
 528529                 }
 529530 
 530531         case 'G': /* emit conversion instructions */
 531532                 sconv(p);
 532533                 break;
 533534 
 534535         case 'J': /* jump or ret? */
 535536                 {
 536537                         struct interpass *ip =
 537538                             DLIST_PREV((struct interpass *)p2env.epp, qelem);
 538539                         if (ip->type != IP_DEFLAB ||
 539540                             ip->ip_lbl != getlr(p, 'L')->n_lval)
 540541                                 expand(p, FOREFF, "jbr  LL");
 541542                         else
 542543                                 printf("ret");
 543544                 }
 544545                 break;
 545546 
 546547         case 'L':       /* type of left operand */
 547548         case 'R':       /* type of right operand */
 548549                 {
 549550                 register NODE *n;
 550551 
 551552                 n = getlr ( p, c);
 552553                 if (x2debug) printf("->%d<-", n->n_type);
 553554 
 554555                 prtype(n);
 555556                 return;
 556557                 }
 557558 
 558559         case 'O': /* print out emulated ops */
 559560                 expand(p, FOREFF, "\tmovq       AR,-(%sp)\n");
 560561                 expand(p, FOREFF, "\tmovq       AL,-(%sp)\n");
 561562                 if (p->n_op == DIV && p->n_type == ULONGLONG) ch = "udiv";
 562563                 else if (p->n_op == DIV) ch = "div";
 563564                 else if (p->n_op == MOD && p->n_type == ULONGLONG) ch = "umod";
 564565                 else if (p->n_op == MOD) ch = "mod";
 565566                 else if (p->n_op == MUL) ch = "mul";
 566567                 else ch = 0, comperr("ZO %d", p->n_op);
 567568                 printf("\tcalls $4,__%sdi3\n", ch);
 568569                 break;
 569570 
 570571 
 571572         case 'Z':       /* complement mask for bit instr */
 572573                 printf("$%Ld", ~p->n_right->n_lval);
 573574                 return;
 574575 
 575576         case 'U':       /* 32 - n, for unsigned right shifts */
<>576 -                m = p->n_left->n_type == UCHAR ? 8 :
 577 -                    p->n_left->n_type == USHORT ? 16 : 32;
  577+                t = DEUNSIGN(p->n_left->n_type);
  578+                m = t == CHAR ? 8 : t == SHORT ? 16 : 32;
578579                 printf("$" CONFMT, m - p->n_right->n_lval);
 579580                 return;
 580581 
 581582         case 'T':       /* rounded structure length for arguments */
 582583                 {
 583584                 int size;
 584585 
 585586                 size = p->n_stsize;
 586587                 SETOFF( size, 4);
 587588                 printf("$%d", size);
 588589                 return;
 589590                 }
 590591 
 591592         case 'S'/* structure assignment */
 592593                 {
 593594                         register int size;
 594595 
 595596                         size = p->n_stsize;
 596597                         l = r = NULL; /* XXX gcc */
 597598                         if( p->n_op == STASG ){
 598599                                 l = p->n_left;
 599600                                 r = p->n_right;
 600601 
 601602                                 }
 602603                         else if( p->n_op == STARG ){
 603604                                 /* store an arg into a temporary */
 604605                                 printf("\tsubl2 $%d,%%sp\n",
 605606                                     size < 4 ? 4 : size);
 606607                                 l = mklnode(OREG, 0, SP, INT);
 607608                                 r = p->n_left;
 608609                                 }
 609610                         else cerror( "STASG bad" );
 610611 
 611612                         if( r->n_op == ICON ) r->n_op = NAME;
 612613                         else if( r->n_op == REG ) r->n_op = OREG;
 613614                         else if( r->n_op != OREG ) cerror( "STASG-r" );
 614615 
 615616                 if (size != 0) {
 616617                         if( size <= 0 || size > 65535 )
 617618                                 cerror("structure size <0=0 or >65535");
 618619 
 619620                         switch(size) {
 620621                                 case 1:
 621622                                         printf("        movb    ");
 622623                                         break;
 623624                                 case 2:
 624625                                         printf("        movw    ");
 625626                                         break;
 626627                                 case 4:
 627628                                         printf("        movl    ");
 628629                                         break;
 629630                                 case 8:
 630631                                         printf("        movq    ");
 631632                                         break;
 632633                                 default:
 633634                                         printf("        movc3   $%d,", size);
 634635                                         break;
 635636                         }
 636637                         adrput(stdout, r);
 637638                         printf(",");
 638639                         adrput(stdout, l);
 639640                         printf("\n");
 640641                 }
 641642 
 642643                         if( r->n_op == NAME ) r->n_op = ICON;
 643644                         else if( r->n_op == OREG ) r->n_op = REG;
 644645                         if (p->n_op == STARG)
 645646                                 tfree(l);
 646647 
 647648                         }
 648649                 break;
 649650 
 650651         default:
 651652                 comperr("illegal zzzcode '%c'", c);
 652653         }
 653654 }
 654655 
 655656 void
 656657 rmove(int rt, int rs, TWORD t)
 657658 {
 658659         printf( "       %s      %s,%s\n",
 659660                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 660661                 rnames[rt], rnames[rs] );
 661662 }
 662663 
 663664 int
 664665 rewfld(NODE *p)
 665666 {
 666667         return(1);
 667668 }
 668669 
 669670 #if 0
 670671 int
 671672 callreg(NODE *p)
 672673 {
 673674         return( R0 );
 674675 }
 675676 
 676677 int
 677678 base(register NODE *p)
 678679 {
 679680         register int o = p->op;
 680681 
 681682         if( (o==ICON && p->name[0] != '\0')) return( 100 ); /* ie no base reg */
 682683         if( o==REG ) return( p->rval );
 683684     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
 684685                 return( p->left->rval );
 685686     if( o==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 686687                 return( p->rval + 0200*1 );
 687688         if( o==INCR && p->left->op==REG ) return( p->left->rval + 0200*2 );
 688689         if( o==ASG MINUS && p->left->op==REG) return( p->left->rval + 0200*4 );
 689690         if( o==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
 690691           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 691692                 return( p->left->left->rval + 0200*(1+2) );
 692693         return( -1 );
 693694 }
 694695 
 695696 int
 696697 offset(register NODE *p, int tyl)
 697698 {
 698699 
 699700         if( tyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) return( p->rval );
 700701         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
 701702               (p->right->op==ICON && p->right->name[0]=='\0')
 702703               && (1<<p->right->lval)==tyl))
 703704                 return( p->left->rval );
 704705         return( -1 );
 705706 }
 706707 #endif
 707708 
 708709 #if 0
 709710 void
 710711 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 711712         register NODE *t;
 712713         NODE *f;
 713714 
 714715         p->n_op = OREG;
 715716         f = p->n_left;  /* have to free this subtree later */
 716717 
 717718         /* init base */
 718719         switch (q->n_op) {
 719720                 case ICON:
 720721                 case REG:
 721722                 case OREG:
 722723                         t = q;
 723724                         break;
 724725 
 725726                 case MINUS:
 726727                         q->n_right->n_lval = -q->n_right->n_lval;
 727728                 case PLUS:
 728729                         t = q->n_right;
 729730                         break;
 730731 
 731732                 case UMUL:
 732733                         t = q->n_left->n_left;
 733734                         break;
 734735 
 735736                 default:
 736737                         cerror("illegal makeor2");
 737738                         t = NULL; /* XXX gcc */
 738739         }
 739740 
 740741         p->n_lval = t->n_lval;
 741742         p->n_name = t->n_name;
 742743 
 743744         /* init offset */
 744745         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
 745746 
 746747         tfree(f);
 747748         return;
 748749         }
 749750 
 750751 int
 751752 canaddr( p ) NODE *p; {
 752753         register int o = p->n_op;
 753754 
 754755         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left, STARNM|SOREG)) ) return(1);
 755756         return(0);
 756757         }
 757758 
 758759 shltype( o, p ) register NODE *p; {
 759760         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 760761         }
 761762 #endif
 762763 
 763764 int
 764765 fldexpand(NODE *p, int cookie, char **cp)
 765766 {
 766767         return 0;
 767768 }
 768769 
 769770 int
 770771 flshape(register NODE *p)
 771772 {
 772773         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 773774                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 774775 }
 775776 
 776777 int
 777778 shtemp(register NODE *p)
 778779 {
 779780         if( p->n_op == STARG ) p = p->n_left;
 780781         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 781782 }
 782783 
 783784 /*
 784785  * Shape matches for UMUL.  Cooperates with offstar().
 785786  */
 786787 int
 787788 shumul(NODE *p, int shape)
 788789 {
 789790 
 790791         if (x2debug)
 791792                 printf("shumul(%p)\n", p);
 792793 
 793794         /* Turns currently anything into OREG on vax */
 794795         if (shape & SOREG)
 795796                 return SROREG;
 796797         return SRNOPE;
 797798 }
 798799 
 799800 
 800801 #ifdef notdef
 801802 int
 802803 shumul( p, shape ) register NODE *p; int shape; {
 803804         register int o;
 804805 
 805806         if (x2debug) {
 806807                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 807808                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 808809                 }
 809810 
 810811 
 811812         o = p->n_op;
 812813         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
 813814                 if (shape & STARNM)
 814815                         return SRDIR;
 815816 
 816817         if( ( o == INCR || o == ASG MINUS ) &&
 817818             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 818819             p->n_right->n_name[0] == '\0' )
 819820                 {
 820821                 switch (p->n_left->n_type)
 821822                         {
 822823                         case CHAR|PTR:
 823824                         case UCHAR|PTR:
 824825                                 o = 1;
 825826                                 break;
 826827 
 827828                         case SHORT|PTR:
 828829                         case USHORT|PTR:
 829830                                 o = 2;
 830831                                 break;
 831832 
 832833                         case INT|PTR:
 833834                         case UNSIGNED|PTR:
 834835                         case LONG|PTR:
 835836                         case ULONG|PTR:
 836837                         case FLOAT|PTR:
 837838                                 o = 4;
 838839                                 break;
 839840 
 840841                         case DOUBLE|PTR:
 841842                                 o = 8;
 842843                                 break;
 843844 
 844845                         default:
 845846                                 if ( ISPTR(p->n_left->n_type) ) {
 846847                                         o = 4;
 847848                                         break;
 848849                                         }
 849850                                 else return(0);
 850851                         }
 851852                 return( p->n_right->n_lval == o ? STARREG : 0);
 852853                 }
 853854 
 854855         return( SRNOPE );
 855856         }
 856857 #endif
 857858 
 858859 void
 859860 adrcon(CONSZ val)
 860861 {
 861862         printf( "$" );
 862863         printf( CONFMT, val );
 863864 }
 864865 
 865866 void
 866867 conput(FILE *fp, NODE *p)
 867868 {
 868869         switch( p->n_op ){
 869870 
 870871         case ICON:
 871872                 acon( p );
 872873                 return;
 873874 
 874875         case REG:
 875876                 printf( "%s", rnames[p->n_rval] );
 876877                 return;
 877878 
 878879         default:
 879880                 cerror( "illegal conput" );
 880881                 }
 881882         }
 882883 
 883884 void
 884885 insput(register NODE *p)
 885886 {
 886887         cerror( "insput" );
 887888 }
 888889 
 889890 /*
 890891  * Write out the upper address, like the upper register of a 2-register
 891892  * reference, or the next memory location.
 892893  */
 893894 void
 894895 upput(NODE *p, int size)
 895896 {
 896897 
 897898         size /= SZCHAR;
 898899         switch (p->n_op) {
 899900         case REG:
 900901                 fprintf(stdout, "%s", rnames[regno(p)-16+1]);
 901902                 break;
 902903 
 903904         case NAME:
 904905                 if (kflag)
 905906                         comperr("upput NAME");
 906907         case OREG:
 907908                 p->n_lval += size;
 908909                 adrput(stdout, p);
 909910                 p->n_lval -= size;
 910911                 break;
 911912         case ICON:
 912913                 fprintf(stdout, "$" CONFMT, p->n_lval >> 32);
 913914                 break;
 914915         default:
 915916                 comperr("upput bad op %d size %d", p->n_op, size);
 916917         }
 917918 }
 918919 
 919920 void
 920921 adrput(FILE *fp, NODE *p)
 921922 {
 922923         register int r;
 923924         /* output an address, with offsets, from p */
 924925 
 925926         if( p->n_op == FLD ){
 926927                 p = p->n_left;
 927928                 }
 928929         switch( p->n_op ){
 929930 
 930931         case NAME:
 931932                 acon( p );
 932933                 return;
 933934 
 934935         case ICON:
 935936                 /* addressable value of the constant */
 936937                 if (p->n_name[0] == '\0') /* uses xxxab */
 937938                         printf("$");
 938939                 acon(p);
 939940                 return;
 940941 
 941942         case REG:
 942943                 printf( "%s", rnames[p->n_rval] );
 943944                 return;
 944945 
 945946         case OREG:
 946947                 r = p->n_rval;
 947948                 if( R2TEST(r) ){ /* double indexing */
 948949                         register int flags;
 949950 
 950951                         flags = R2UPK3(r);
 951952                         if( flags & 1 ) printf("*");
 952953                         if( flags & 4 ) printf("-");
 953954                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 954955                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 955956                         if( flags & 2 ) printf("+");
 956957                         printf( "[%s]", rnames[R2UPK2(r)] );
 957958                         return;
 958959                         }
 959960                 if( r == AP ){  /* in the argument region */
 960961                         if( p->n_lval <= 0 || p->n_name[0] != '\0' )
 961962                                 werror( "bad arg temp" );
 962963                         printf( CONFMT, p->n_lval );
 963964                         printf( "(%%ap)" );
 964965                         return;
 965966                         }
 966967                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 967968                 printf( "(%s)", rnames[p->n_rval] );
 968969                 return;
 969970 
 970971         case UMUL:
 971972                 /* STARNM or STARREG found */
 972973                 if( tshape(p, STARNM) ) {
 973974                         printf( "*" );
 974975                         adrput(0p->n_left);
 975976                         }
 976977                 else {  /* STARREG - really auto inc or dec */
 977978                         register NODE *q;
 978979 
 979980 /* tbl
 980981                         p = p->n_left;
 981982                         p->n_left->n_op = OREG;
 982983                         if( p->n_op == INCR ) {
 983984                                 adrput( p->n_left );
 984985                                 printf( "+" );
 985986                                 }
 986987                         else {
 987988                                 printf( "-" );
 988989                                 adrput( p->n_left );
 989990                                 }
 990991    tbl */
 991992 #ifdef notyet
 992993                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 993994                                 rnames[p->n_left->n_left->n_rval],
 994995                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 995996 #else
 996997                         printf("%c(%s)%c", '-',
 997998                                 rnames[p->n_left->n_left->n_rval],
 998999                                 '\0' );
 9991000 #endif
 10001001                         p->n_op = OREG;
 10011002                         p->n_rval = p->n_left->n_left->n_rval;
 10021003                         q = p->n_left;
 10031004 #ifdef notyet
 10041005 
 10051006                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 10061007 #else
 10071008                         p->n_lval = 0;
 10081009 #endif
 10091010                         p->n_name[0] = '\0';
 10101011                         tfree(q);
 10111012                 }
 10121013                 return;
 10131014 
 10141015         default:
 10151016                 cerror( "illegal address" );
 10161017                 return;
 10171018         }
 10181019 
 10191020 }
 10201021 
 10211022 /*
 10221023  * print out a constant
 10231024  */
 10241025 void
 10251026 acon(NODE *p)
 10261027 {
 10271028 
 10281029         if (p->n_name[0] == '\0') {
 10291030                 printf(CONFMT, p->n_lval);
 10301031         } else if( p->n_lval == 0 ) {
 10311032                 printf("%s", p->n_name);
 10321033         } else {
 10331034                 printf("%s+", p->n_name);
 10341035                 printf(CONFMT, p->n_lval);
 10351036         }
 10361037 }
 10371038 
 10381039 #if 0
 10391040 genscall( p, cookie ) register NODE *p; {
 10401041         /* structure valued call */
 10411042         return( gencall( p, cookie ) );
 10421043         }
 10431044 
 10441045 /* tbl */
 10451046 int gc_numbytes;
 10461047 /* tbl */
 10471048 
 10481049 gencall( p, cookie ) register NODE *p; {
 10491050         /* generate the call given by p */
 10501051         register NODE *p1, *ptemp;
 10511052         register temp, temp1;
 10521053         register m;
 10531054 
 10541055         if( p->right ) temp = argsize( p->right );
 10551056         else temp = 0;
 10561057 
 10571058         if( p->op == STCALL || p->op == UNARY STCALL ){
 10581059                 /* set aside room for structure return */
 10591060 
 10601061                 if( p->stsize > temp ) temp1 = p->stsize;
 10611062                 else temp1 = temp;
 10621063                 }
 10631064 
 10641065         if( temp > maxargs ) maxargs = temp;
 10651066         SETOFF(temp1,4);
 10661067 
 10671068         if( p->right ){ /* make temp node, put offset in, and generate args */
 10681069                 ptemp = talloc();
 10691070                 ptemp->op = OREG;
 10701071                 ptemp->lval = -1;
 10711072                 ptemp->rval = SP;
 10721073                 ptemp->name[0] = '\0';
 10731074                 ptemp->rall = NOPREF;
 10741075                 ptemp->su = 0;
 10751076                 genargs( p->right, ptemp );
 10761077                 nfree(ptemp);
 10771078                 }
 10781079 
 10791080         p1 = p->left;
 10801081         if( p1->op != ICON ){
 10811082                 if( p1->op != REG ){
 10821083                         if( p1->op != OREG || R2TEST(p1->rval) ){
 10831084                                 if( p1->op != NAME ){
 10841085                                         order( p1, INAREG );
 10851086                                         }
 10861087                                 }
 10871088                         }
 10881089                 }
 10891090 
 10901091 /*
 10911092         if( p1->op == REG && p->rval == R5 ){
 10921093                 cerror( "call register overwrite" );
 10931094                 }
 10941095  */
 10951096 /* tbl
 10961097         setup gc_numbytes so reference to ZC works */
 10971098 
 10981099         gc_numbytes = temp;
 10991100 /* tbl */
 11001101 
 11011102         p->op = UNARY CALL;
 11021103         m = match( p, INTAREG|INTBREG );
 11031104 /* tbl
 11041105         switch( temp ) {
 11051106         case 0:
 11061107                 break;
 11071108         case 2:
 11081109                 printf( "       tst     (%sp)+\n" );
 11091110                 break;
 11101111         case 4:
 11111112                 printf( "       cmp     (%sp)+,(%sp)+\n" );
 11121113                 break;
 11131114         default:
 11141115                 printf( "       add     $%d,%sp\n", temp);
 11151116                 }
 11161117    tbl */
 11171118         return(m != MDONE);
 11181119         }
 11191120 #endif
 11201121 
 11211122 static char *
 11221123 ccbranches[] = {
 11231124         "jeql",
 11241125         "jneq",
 11251126         "jleq",
 11261127         "jlss",
 11271128         "jgeq",
 11281129         "jgtr",
 11291130         "jlequ",
 11301131         "jlssu",
 11311132         "jgequ",
 11321133         "jgtru",
 11331134 };
 11341135 
 11351136 /*
 11361137  * printf conditional and unconditional branches
 11371138  */
 11381139 void
 11391140 cbgen(int o, int lab)
 11401141 {
 11411142 
 11421143         if (o == 0) {
 11431144                 printf("        jbr     " LABFMT "\n", lab);
 11441145         } else {
 11451146                 if (o > UGT)
 11461147                         comperr("bad conditional branch: %s", opst[o]);
 11471148                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 11481149         }
 11491150 }
 11501151 
 11511152 static void
 11521153 mkcall(NODE *p, char *name)
 11531154 {
 11541155         p->n_op = CALL;
 11551156         p->n_right = mkunode(FUNARG, p->n_left, 0, p->n_left->n_type);
 11561157         p->n_left = mklnode(ICON, 0, 0, FTN|p->n_type);
 11571158         p->n_left->n_name = name;
 11581159 }
 11591160 
 11601161 /* do local tree transformations and optimizations */
 11611162 static void
 11621163 optim2(NODE *p, void *arg)
 11631164 {
 11641165         NODE *r, *s;
 11651166         TWORD lt;
 11661167 
 11671168         switch (p->n_op) {
 11681169         case MOD:
 11691170                 if (p->n_type == USHORT || p->n_type == UCHAR) {
 11701171                         r = mkunode(SCONV, p->n_left, 0, UNSIGNED);
 11711172                         r = mkunode(FUNARG, r, 0, UNSIGNED);
 11721173                         s = mkunode(SCONV, p->n_right, 0, UNSIGNED);
 11731174                         s = mkunode(FUNARG, s, 0, UNSIGNED);
 11741175                         r = mkbinode(CM, r, s, INT);
 11751176                         s = mklnode(ICON, 0, 0, FTN|UNSIGNED);
 11761177                         s->n_name = "__urem";
 11771178                         p->n_left = mkbinode(CALL, s, r, UNSIGNED);
 11781179                         p->n_op = SCONV;
 11791180                 } else if (p->n_type == UNSIGNED) {
 11801181                         p->n_left = mkunode(FUNARG, p->n_left, 0, UNSIGNED);
 11811182                         p->n_right = mkunode(FUNARG, p->n_right, 0, UNSIGNED);
 11821183                         p->n_right = mkbinode(CM, p->n_left, p->n_right, INT);
 11831184                         p->n_left = mklnode(ICON, 0, 0, FTN|UNSIGNED);
 11841185                         p->n_left->n_name = "__urem";
 11851186                         p->n_op = CALL;
 11861187                 }
 11871188                 break;
 11881189 
 11891190         case RS:
 11901191                 if (p->n_type == ULONGLONG) {
 11911192                         p->n_right = mkbinode(CM,
 11921193                             mkunode(FUNARG, p->n_left, 0, p->n_left->n_type),
 11931194                             mkunode(FUNARG, p->n_right, 0, p->n_right->n_type),
 11941195                             INT);
 11951196                         p->n_left = mklnode(ICON, 0, 0, FTN|p->n_type);
 11961197                         p->n_left->n_name = "__lshrdi3";
 11971198                         p->n_op = CALL;
<>1198 -                } else if (p->n_type == INT) {
  1199+                } else if (p->n_type == INT || p->n_type == LONGLONG) {
<_11991200                         /* convert >> to << with negative shift count */
 12001201                         /* RS of char & short must use extv */
 12011202                         if (p->n_right->n_op == ICON) {
 12021203                                 p->n_right->n_lval = -p->n_right->n_lval;
 12031204                         } else if (p->n_right->n_op == UMINUS) {
 12041205                                 r = p->n_right->n_left;
 12051206                                 nfree(p->n_right);
 12061207                                 p->n_right = r;
 12071208                         } else {
 12081209                                 p->n_right = mkunode(UMINUS, p->n_right,
 12091210                                     0, p->n_right->n_type);
 12101211                         }
 12111212                         p->n_op = LS;
 12121213                 }
 12131214                 break;
 12141215 
 12151216         case AND:
 12161217                 /* commute L and R to eliminate compliments and constants */
 12171218                 if ((p->n_left->n_op == ICON && p->n_left->n_name[0] == 0) ||
 12181219                     p->n_left->n_op==COMPL) {
 12191220                         r = p->n_left;
 12201221                         p->n_left = p->n_right;
 12211222                         p->n_right = r;
 12221223                 }
 12231224                 /* change meaning of AND to ~R&L - bic on pdp11 */
 12241225                 r = p->n_right;
 12251226                 if (r->n_op == ICON && r->n_name[0] == 0) {
 12261227                         /* compliment constant */
 12271228                         r->n_lval = ~r->n_lval;
 12281229                 } else if (r->n_op == COMPL) { /* ~~A => A */
 12291230                         s = r->n_left;
 12301231                         nfree(r);
 12311232                         p->n_right = s;
 12321233                 } else { /* insert complement node */
 12331234                         p->n_right = mkunode(COMPL, r, 0, r->n_type);
 12341235                 }
 12351236                 break;
 12361237         case SCONV:
 12371238                 lt = p->n_left->n_type;
 12381239                 switch (p->n_type) {
 12391240                 case LONGLONG:
 12401241                         if (lt == FLOAT)
 12411242                                 mkcall(p, "__fixsfdi");
 12421243                         else if (lt == DOUBLE)
 12431244                                 mkcall(p, "__fixdfdi");
 12441245                         break;
 12451246                 case ULONGLONG:
 12461247                         if (lt == FLOAT)
 12471248                                 mkcall(p, "__fixunssfdi");
 12481249                         else if (lt == DOUBLE)
 12491250                                 mkcall(p, "__fixunsdfdi");
 12501251                         break;
 12511252                 case FLOAT:
 12521253                         if (lt == LONGLONG)
 12531254                                 mkcall(p, "__floatdisf");
 12541255                         else if (lt == ULONGLONG) {
 12551256                                 p->n_left = mkunode(SCONV, p->n_left,0, DOUBLE);
 12561257                                 p->n_type = FLOAT;
 12571258                                 mkcall(p->n_left, "__floatundidf");
 12581259                         } else if (lt == UNSIGNED) {
 12591260                                 /* insert an extra double-to-float sconv */
 12601261                                 p->n_left = mkunode(SCONV, p->n_left,0, DOUBLE);
 12611262                         }
 12621263                         break;
 12631264                 case DOUBLE:
 12641265                         if (lt == LONGLONG)
 12651266                                 mkcall(p, "__floatdidf");
 12661267                         else if (lt == ULONGLONG)
 12671268                                 mkcall(p, "__floatundidf");
 12681269                         break;
 12691270                         
 12701271                 }
 12711272                 break;
 12721273         }
 12731274 }
 12741275 
 12751276 static void
 12761277 aofname(NODE *p, void *arg)
 12771278 {
 12781279         int o = optype(p->n_op);
 12791280         TWORD t;
 12801281 
 12811282         if (o == LTYPE || p->n_op == ADDROF)
 12821283                 return;
 12831284         t = p->n_left->n_type;
 12841285         if (p->n_left->n_op == NAME && ISLONGLONG(t))
 12851286                 p->n_left = mkunode(UMUL,
 12861287                     mkunode(ADDROF, p->n_left, 0, INCREF(t)), 0, t);
 12871288         if (o == BITYPE && p->n_right->n_op == NAME &&
 12881289             ISLONGLONG(p->n_right->n_type)) {
 12891290                 t = p->n_right->n_type;
 12901291                 p->n_right = mkunode(UMUL,
 12911292                     mkunode(ADDROF, p->n_right, 0, INCREF(t)), 0, t);
 12921293         }
 12931294 }
 12941295 
 12951296 void
 12961297 myreader(struct interpass *ipole)
 12971298 {
 12981299         struct interpass *ip;
 12991300 
 13001301         DLIST_FOREACH(ip, ipole, qelem) {
 13011302                 if (ip->type != IP_NODE)
 13021303                         continue;
 13031304                 if (kflag)
 13041305                         walkf(ip->ip_node, aofname, 0);
 13051306                 walkf(ip->ip_node, optim2, 0);
 13061307         }
 13071308 }
 13081309 
 13091310 void
 13101311 mycanon(NODE *p)
 13111312 {
 13121313 }
 13131314 
 13141315 void
 13151316 myoptim(struct interpass *ip)
 13161317 {
 13171318 }
 13181319 
 13191320 /*
 13201321  * Return argument size in regs.
 13211322  */
 13221323 static int
 13231324 argsiz(NODE *p)
 13241325 {
 13251326         TWORD t = p->n_type;
 13261327 
 13271328         if (t == STRTY || t == UNIONTY)
 13281329                 return p->n_stsize/(SZINT/SZCHAR);
 13291330         return szty(t);
 13301331 }
 13311332 
 13321333 /*
 13331334  * Last chance to do something before calling a function.
 13341335  */
 13351336 void
 13361337 lastcall(NODE *p)
 13371338 {
 13381339         NODE *op = p;
 13391340         int size = 0;
 13401341 
 13411342         /* Calculate argument sizes */
 13421343         p->n_qual = 0;
 13431344         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 13441345                 return;
 13451346         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 13461347                 size += argsiz(p->n_right);
 13471348         if (p->n_op != ASSIGN)
 13481349                 size += argsiz(p);
 13491350         op->n_qual = size; /* XXX */
 13501351 }
 13511352 
 13521353 /*
 13531354  * Return a class suitable for a specific type.
 13541355  */
 13551356 int
 13561357 gclass(TWORD t)
 13571358 {
 13581359         return (szty(t) == 2 ? CLASSB : CLASSA);
 13591360 }
 13601361 
 13611362 /*
 13621363  * For class c, find worst-case displacement of the number of
 13631364  * registers in the array r[] indexed by class.
 13641365  */
 13651366 int
 13661367 COLORMAP(int c, int *r)
 13671368 {
 13681369         int num;
 13691370         int a,b;
 13701371 
 13711372         a = r[CLASSA];
 13721373         b = r[CLASSB];
 13731374         switch (c) {
 13741375         case CLASSA:
 13751376                 /* there are 12 classa, so min 6 classb are needed to block */
 13761377                 num = b * 2;
 13771378                 num += a;
 13781379                 return num < 12;
 13791380         case CLASSB:
 13801381                 if (b > 3) return 0;
 13811382                 if (b > 2 && a) return 0;
 13821383                 if (b > 1 && a > 2) return 0;
 13831384                 if (b && a > 3) return 0;
 13841385                 if (a > 5) return 0;
 13851386                 return 1;
 13861387         }
 13871388         comperr("COLORMAP");
 13881389         return 0; /* XXX gcc */
 13891390 }
 13901391 
 13911392 /*
 13921393  * Special shapes.
 13931394  */
 13941395 int
 13951396 special(NODE *p, int shape)
 13961397 {
 13971398         return SRNOPE;
 13981399 }
 13991400 
 14001401 /*
 14011402  * Target-dependent command-line options.
 14021403  */
 14031404 void
 14041405 mflags(char *str)
 14051406 {
 14061407 }
 14071408 /*
 14081409  * Do something target-dependent for xasm arguments.
 14091410  * Supposed to find target-specific constraints and rewrite them.
 14101411  */
 14111412 int
 14121413 myxasm(struct interpass *ip, NODE *p)
 14131414 {
 14141415         char *c;
 14151416         int i;
 14161417 
 14171418         /* Discard o<> constraints since they will not be generated */
 14181419         for (c = p->n_name; *c; c++) {
 14191420                 if (*c == 'o' || *c == '<' || *c == '>') {
 14201421                         for (i = 0; c[i]; i++)
 14211422                                 c[i] = c[i+1];
 14221423                         c--;
 14231424                 }
 14241425         }
 14251426         return 0;
 14261427 }
 14271428 
 14281429 int
 14291430 xasmconstregs(char *s)
 14301431 {
 14311432         int i;
 14321433 
 14331434         for (i = 0; i < 16; i++)
 14341435                 if (strcmp(&rnames[i][1], s) == 0)
 14351436                         return i;
 14361437         return -1;
 14371438 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-10-31 14:34 +0100