Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.29
 
1.30
 
MAIN:ragge:20120710162932
 
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 }
 5454 
 5555 /*
 5656  * Called after all instructions in a function are emitted.
 5757  * Generates code for epilog here.
 5858  */
 5959 void
 6060 eoftn(struct interpass_prolog *ipp)
 6161 {
 6262         if (ipp->ipp_ip.ip_lbl == 0)
 6363                 return; /* no code needs to be generated */
 6464         printf("        ret\n");
 6565 }
 6666 
 6767 struct hoptab { int opmask; char * opstring; } ioptab[] = {
 6868 
 6969         { PLUS"add", },
 7070         { MINUS,        "sub", },
 7171         { MUL,  "mul", },
 7272         { DIV,  "div", },
 7373         { OR,   "bis", },
 7474         { ER,   "xor", },
 7575         { AND,  "bic", },
 7676         { -1, ""     },
 7777 };
 7878 
 7979 void
 8080 hopcode( f, o ){
 8181         /* output the appropriate string from the above table */
 8282 
 8383         register struct hoptab *q;
 8484 
 8585         for( q = ioptabq->opmask>=0; ++q ){
 8686                 if( q->opmask == o ){
 8787                         printf( "%s", q->opstring );
 8888 /* tbl
 8989                         if( f == 'F' ) printf( "e" );
 9090                         else if( f == 'D' ) printf( "d" );
 9191    tbl */
 9292 /* tbl */
 9393                         switch( f ) {
 9494                                 case 'L':
 9595                                 case 'W':
 9696                                 case 'B':
 9797                                 case 'D':
 9898                                 case 'F':
 9999                                         printf("%c", tolower(f));
 100100                                         break;
 101101 
 102102                                 }
 103103 /* tbl */
 104104                         return;
 105105                         }
 106106                 }
 107107         cerror( "no hoptab for %s", opst[o] );
 108108         }
 109109 
 110110 char *
 111111 rnames[] = {  /* keyed to register number tokens */
 112112 
 113113         "%r0", "%r1", "%r2", "%r3", "%r4", "%r5",
 114114         "%r6", "%r7", "%r8", "%r9", "%r10", "%r11",
 115115         "%ap", "%fp", "%sp", "%pc",
 116116         /* The concatenated regs has the name of the lowest */
 117117         "%r0", "%r1", "%r2", "%r3", "%r4", "%r5",
 118118         "%r6", "%r7", "%r8", "%r9", "%r10"
 119119         };
 120120 
 121121 int
 122122 tlen(NODE *p)
 123123 {
 124124         switch(p->n_type) {
 125125         case CHAR:
 126126         case UCHAR:
 127127                 return(1);
 128128 
 129129         case SHORT:
 130130         case USHORT:
 131131                 return(2);
 132132 
 133133         case DOUBLE:
 134134         case LONGLONG:
 135135         case ULONGLONG:
 136136                 return(8);
 137137 
 138138         default:
 139139                 return(4);
 140140         }
 141141 }
 142142 
 143143 void
 144144 prtype(NODE *n)
 145145 {
 146146         static char pt[] = { 0, 0, 'b', 'b', 'w', 'w', 'l', 'l', 0, 0,
 147147             'q', 'q', 'f', 'd' };
 148148         TWORD t = n->n_type;
 149149 
 150150         if (ISPTR(t))
 151151                 t = UNSIGNED;
 152152 
 153153         if (t > DOUBLE || pt[t] == 0)
 154154                 comperr("prtype: bad type");
 155155         putchar(pt[t]);
 156156 }
 157157 
 158158 /*
 159159  * Emit conversions as given by the following table. Dest is always reg,
 160160  *   if it should be something else let peephole optimizer deal with it.
 161161  *   This code ensures type correctness in 32-bit registers.
 162162  *   XXX is that necessary?
 163163  *
 164164  * From                         To
 165165  *       char   uchar  short  ushort int    uint   ll    ull   float double
 166166  * char  movb   movb   cvtbw  cvtbw  cvtbl  cvtbl  A     A     cvtbf cvtbd
 167167  * uchar movb   movb   movzbw movzbw movzbl movzbl B     B     G     G
 168168  * short movb   movb   movw   movw   cvtwl  cvtwl  C(A)  C(A)  cvtwf cvtwd
 169169  * ushrt movb   movb   movw   movw   movzwl movzwl D(B)  D(B)  H     H
 170170  * int   movb   movb   movw   movw   movl   movl   E     E     cvtlf cvtld
 171171  * uint  movb   movb   movw   movw   movl   movl   F     F     I     I
 172172  * ll    movb   movb   movw   movw   movl   movl   movq  movq  J     K
 173173  * ull   movb   movb   movw   movw   movl   movl   movq  movq  L     M
 174174  * float cvtfb  cvtfb  cvtfw  cvtfw  cvtfl  cvtfl  N     O     movf  cvtfd
 175175  * doubl cvtdb  cvtdb  cvtdw  cvtdw  cvtdl  cvtdl  P     Q     cvtdf movd
 176176  *
 177177  *  A: cvtbl + sign extend
 178178  *  B: movzbl + zero extend
 179179  *  G: movzbw + cvtwX
 180180  *  H: movzwl + cvtwX
 181181  *  I: cvtld + addX
 182182  *  J: call __floatdisf
 183183  *  K: call __floatdidf
 184184  *  L: xxx + call __floatdisf
 185185  *  M: xxx + call __floatdidf
 186186  *  N: call __fixsfdi
 187187  *  O: call __fixunssfdi
 188188  *  P: call __fixdfdi
 189189  *  Q: call __fixunsdfdi
 190190  */
 191191 
 192192 #define MVD     1 /* mov + dest type */
 193193 #define CVT     2 /* cvt + src type + dst type */
 194194 #define MVZ     3 /* movz + src type + dst type */
 195195 #define CSE     4 /* cvt + src type + l + sign extend upper */
 196196 #define MZE     5 /* movz + src type + l + zero extend upper */
 197197 #define MLE     6 /* movl + sign extend upper */
 198198 #define MLZ     7 /* movl + zero extend upper */
 199199 #define MZC     8 /* movz + cvt */
 200200 
 201201 static char scary[][10] = {
 202202         { MVD, MVD, CVT, CVT, CVT, CVT, CSE, CSE, CVT, CVT },
 203203         { MVD, MVD, MVZ, MVZ, MVZ, MVZ, MZE, MZE, MZC, MZC },
 204204         { MVD, MVD, MVD, MVD, CVT, CVT, CSE, CSE, CVT, CVT },
 205205         { MVD, MVD, MVD, MVD, MVZ, MVZ, MZE, MZE, MZC, MZC },
 206206         { MVD, MVD, MVD, MVD, MVD, MVD, MLE, MLE, CVT, CVT },
 207207         { MVD, MVD, MVD, MVD, MVD, MVD, MLZ, MLZ, 'I', 'I' },
 208208         { MVD, MVD, MVD, MVD, MVD, MVD, MVD, MVD, 'J', 'K' },
 209209         { MVD, MVD, MVD, MVD, MVD, MVD, MVD, MVD, 'L', 'M' },
 210210         { CVT, CVT, CVT, CVT, CVT, CVT, 'N', 'O', MVD, CVT },
 211211         { CVT, CVT, CVT, CVT, CVT, CVT, 'P', 'Q', CVT, MVD },
 212212 };
 213213 
 214214 static void
 215215 sconv(NODE *p)
 216216 {
 217217         NODE *l = p->n_left;
 218218         TWORD ts, td;
 219219         int o;
 220220 
 221221         /*
 222222          * Source node may be in register or memory.
 223223          * Result is always in register.
 224224          */
 225225         ts = l->n_type;
 226226         if (ISPTR(ts))
 227227                 ts = UNSIGNED;
 228228         td = p->n_type;
 229229         ts = ts < LONG ? ts-2 : ts-4;
 230230         td = td < LONG ? td-2 : td-4;
 231231 
 232232         o = scary[ts][td];
 233233         switch (o) {
 234234         case MLE:
 235235         case MLZ:
 236236                 expand(p, INAREG|INBREG, "\tmovl\tAL,A1\n");
 237237                 break;
 238238 
 239239         case MVD:
 240240                 if (l->n_op == REG && regno(l) == regno(getlr(p, '1')))
 241241                         break; /* unneccessary move */
 242242                 expand(p, INAREG|INBREG, "\tmovZR\tAL,A1\n");
 243243                 break;
 244244 
 245245         case CSE:
 246246                 expand(p, INAREG|INBREG, "\tcvtZLl\tAL,A1\n");
 247247                 break;
 248248 
 249249         case CVT:
 250250                 expand(p, INAREG|INBREG, "\tcvtZLZR\tAL,A1\n");
 251251                 break;
 252252 
 253253         case MZE:
 254254                 expand(p, INAREG|INBREG, "\tmovzZLl\tAL,A1\n");
 255255                 break;
 256256 
 257257         case MVZ:
 258258                 expand(p, INAREG|INBREG, "\tmovzZLZR\tAL,A1\n");
 259259                 break;
 260260 
 261261         case MZC:
 262262                 expand(p, INAREG|INBREG, "\tmovzZLl\tAL,A1\n");
 263263                 expand(p, INAREG|INBREG, "\tcvtlZR\tA1,A1\n");
 264264                 break;
 265265 
 266266         case 'I': /* unsigned to double */
 267267                 expand(p, INAREG|INBREG, "\tcvtld\tAL,A1\n");
 268268                 printf("\tjgeq\t1f\n");
 269269                 expand(p, INAREG|INBREG, "\taddd2\t$0d4.294967296e+9,A1\n");
 270270                 printf("1:\n");
 271271                 break;
 272272         default:
 273273                 comperr("unsupported conversion %d", o);
 274274         }
 275275         switch (o) {
 276276         case MLE:
 277277         case CSE:
 278278                 expand(p, INBREG, "\tashl\t$-31,A1,U1\n");
 279279                 break;
 280280         case MLZ:
 281281         case MZE:
 282282                 expand(p, INAREG|INBREG, "\tclrl\tU1\n");
 283283                 break;
 284284         }
 285285 }
 286286 
 287287 /*
 288288  * Assign a constant from p to q.  Both are expected to be leaves by now.
 289289  * This is for 64-bit integers.
 290290  */
 291291 static void
 292292 casg64(NODE *p)
 293293 {
 294294         NODE *l, *r;
 295295         char *str;
 296296         int mneg = 1;
 297297         
 298298         l = p->n_left;
 299299         r = p->n_right;
 300300 
 301301 #ifdef PCC_DEBUG
 302302         if (r->n_op != ICON)
 303303                 comperr("casg");
 304304 #endif
 305305         if (r->n_name[0] != '\0') {
 306306                 /* named constant, nothing to do */
 307307                 str = "movq\tAR,AL";
 308308                 mneg = 0;
 309309         } else if (r->n_lval == 0) {
 310310                 str = "clrq\tAL";
 311311                 mneg = 0;
 312312         } else if (r->n_lval < 0) {
 313313                 if (r->n_lval >= -63) {
 314314                         r->n_lval = -r->n_lval;
 315315                         str = "mnegl\tAR,AL";
 316316                 } else if (r->n_lval >= -128) {
 317317                         str = "cvtbl\tAR,AL";
 318318                 } else if (r->n_lval >= -32768) {
 319319                         str = "cvtwl\tAR,AL";
 320320                 } else if (r->n_lval >= -4294967296LL) {
 321321                         str = "movl\tAR,AL";
 322322                 } else {
 323323                         str = "movq\tAR,AL";
 324324                         mneg = 0;
 325325                 }
 326326         } else {
 327327                 mneg = 0;
 328328                 if (r->n_lval <= 63 || r->n_lval > 4294967295LL) {
 329329                         str = "movq\tAR,AL";
 330330                 } else if (r->n_lval <= 255) {
 331331                         str = "movzbl\tAR,AL\n\tclrl\tUL";
 332332                 } else if (r->n_lval <= 65535) {
 333333                         str = "movzwl\tAR,AL\n\tclrl\tUL";
 334334                 } else /* if (r->n_lval <= 4294967295) */ {
 335335                         str = "movl\tAR,AL\n\tclrl\tUL";
 336336                 }
 337337         }
 338338         expand(p, FOREFF, str);
 339339         if (mneg)
 340340                 expand(p, FOREFF, "\n\tmnegl $-1,UL");
 341341 }
 342342 
 343343 /*
 344344  * Assign a constant from p to q.  Both are expected to be leaves by now.
 345345  * This is only for 32-bit integer types.
 346346  */
 347347 static void
 348348 casg(NODE *p)
 349349 {
 350350         NODE *l, *r;
 351351         char *str;
 352352         
 353353         l = p->n_left;
 354354         r = p->n_right;
 355355 
 356356 #ifdef PCC_DEBUG
 357357         if (r->n_op != ICON)
 358358                 comperr("casg");
 359359 #endif
 360360         if (r->n_name[0] != '\0') {
 361361                 /* named constant, nothing to do */
 362362                 str = "movZL\tAR,AL";
 363363         } else if (r->n_lval == 0) {
 364364                 str = "clrZL\tAL";
 365365         } else if (r->n_lval < 0) {
 366366                 if (r->n_lval >= -63) {
 367367                         r->n_lval = -r->n_lval;
 368368                         str = "mnegZL\tAR,AL";
 369369                 } else if (r->n_lval >= -128) {
 370370                         if (l->n_type == CHAR)
 371371                                 str = "movb\tAR,AL";
 372372                         else
 373373                                 str = "cvtbZL\tAR,AL";
 374374                 } else if (r->n_lval >= -32768) {
 375375                         if (l->n_type == SHORT)
 376376                                 str = "movw\tAR,AL";
 377377                         else
 378378                                 str = "cvtwZL\tAR,AL";
 379379                 } else
 380380                         str = "movZL\tAR,AL";
 381381         } else {
 382382                 if (r->n_lval <= 63 || r->n_lval > 65535) {
 383383                         str = "movZL\tAR,AL";
 384384                 } else if (r->n_lval <= 255) {
 385385                         str = l->n_type < SHORT ?
 386386                             "movb\tAR,AL" : "movzbZL\tAR,AL";
 387387                 } else /* if (r->n_lval <= 65535) */ {
 388388                         str = l->n_type < INT ?
 389389                             "movw\tAR,AL" : "movzwZL\tAR,AL";
 390390                 }
 391391         }
 392392         expand(p, FOREFF, str);
 393393 }
 394394 
 395395 /*
 396396  * Emit code to compare two longlong numbers.
 397397  */
 398398 static void
 399399 twollcomp(NODE *p)
 400400 {
 401401         int u;
 402402         int s = getlab2();
 403403         int e = p->n_label;
 404404         int cb1, cb2;
 405405 
 406406         u = p->n_op;
 407407         switch (p->n_op) {
 408408         case NE:
 409409                 cb1 = 0;
 410410                 cb2 = NE;
 411411                 break;
 412412         case EQ:
 413413                 cb1 = NE;
 414414                 cb2 = 0;
 415415                 break;
 416416         case LE:
 417417         case LT:
 418418                 u += (ULE-LE);
 419419                 /* FALLTHROUGH */
 420420         case ULE:
 421421         case ULT:
 422422                 cb1 = GT;
 423423                 cb2 = LT;
 424424                 break;
 425425         case GE:
 426426         case GT:
 427427                 u += (ULE-LE);
 428428                 /* FALLTHROUGH */
 429429         case UGE:
 430430         case UGT:
 431431                 cb1 = LT;
 432432                 cb2 = GT;
 433433                 break;
 434434         
 435435         default:
 436436                 cb1 = cb2 = 0; /* XXX gcc */
 437437         }
 438438         if (p->n_op >= ULE)
 439439                 cb1 += 4, cb2 += 4;
 440440         expand(p, 0, "  cmpl UL,UR\n");
 441441         if (cb1) cbgen(cb1, s);
 442442         if (cb2) cbgen(cb2, e);
 443443         expand(p, 0, "  cmpl AL,AR\n");
 444444         cbgen(u, e);
 445445         deflab(s);
 446446 }
 447447 
 448448 
 449449 void
 450450 zzzcode(NODE *p, int c)
 451451 {
 452452         NODE *l, *r;
 453453         int m;
 454454         char *ch;
 455455 
 456456         switch (c) {
 457457         case 'N'/* logical ops, turned into 0-1 */
 458458                 /* use register given by register 1 */
 459459                 cbgen( 0, m=getlab2());
 460460                 deflab( p->n_label );
 461461                 printf( "       clrl    %s\n", rnames[getlr( p, '1' )->n_rval] );
 462462                 deflab( m );
 463463                 return;
 464464 
 465465         case 'A': /* Assign a constant directly to a memory position */
 466466                 printf("\t");
 467467                 if (p->n_type < LONG || ISPTR(p->n_type))
 468468                         casg(p);
 469469                 else
 470470                         casg64(p);
 471471                 printf("\n");
 472472                 break;
 473473 
 474474         case 'B': /* long long compare */
 475475                 twollcomp(p);
 476476                 break;
 477477 
 478478         case 'C':       /* num words pushed on arg stack */
 479479                 printf("$%d", p->n_qual);
 480480                 break;
 481481 
 482482         case 'D':       /* INCR and DECR */
 483483                 zzzcode(p->n_left, 'A');
 484484                 printf("\n      ");
 485485 
 486486 #if 0
 487487         case 'E':       /* INCR and DECR, FOREFF */
 488488                 if (p->n_right->n_lval == 1)
 489489                         {
 490490                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
 491491                         prtype(p->n_left);
 492492                         printf("        ");
 493493                         adrput(stdout, p->n_left);
 494494                         return;
 495495                         }
 496496                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
 497497                 prtype(p->n_left);
 498498                 printf("2       ");
 499499                 adrput(stdout, p->n_right);
 500500                 printf(",");
 501501                 adrput(p->n_left);
 502502                 return;
 503503 #endif
 504504 
 505505         case 'F':       /* register type of right operand */
 506506                 {
 507507                 register NODE *n;
 508508                 register int ty;
 509509 
 510510                 n = getlr( p, 'R' );
 511511                 ty = n->n_type;
 512512 
 513513                 if (x2debug) printf("->%d<-", ty);
 514514 
 515515                 if ( ty==DOUBLE) printf("d");
 516516                 else if ( ty==FLOAT ) printf("f");
 517517                 else printf("l");
 518518                 return;
 519519                 }
 520520 
 521521         case 'G': /* emit conversion instructions */
 522522                 sconv(p);
 523523                 break;
 524524 
 525525         case 'J': /* jump or ret? */
 526526                 {
 527527                         struct interpass *ip =
 528528                             DLIST_PREV((struct interpass *)p2env.epp, qelem);
 529529                         if (ip->type != IP_DEFLAB ||
 530530                             ip->ip_lbl != getlr(p, 'L')->n_lval)
 531531                                 expand(p, FOREFF, "jbr  LL");
 532532                         else
 533533                                 printf("ret");
 534534                 }
 535535                 break;
 536536 
 537537         case 'L':       /* type of left operand */
 538538         case 'R':       /* type of right operand */
 539539                 {
 540540                 register NODE *n;
 541541 
 542542                 n = getlr ( p, c);
 543543                 if (x2debug) printf("->%d<-", n->n_type);
 544544 
 545545                 prtype(n);
 546546                 return;
 547547                 }
 548548 
 549549         case 'O': /* print out emulated ops */
 550550                 expand(p, FOREFF, "\tmovq       AR,-(%sp)\n");
 551551                 expand(p, FOREFF, "\tmovq       AL,-(%sp)\n");
 552552                 if (p->n_op == DIV && p->n_type == ULONGLONG) ch = "udiv";
 553553                 else if (p->n_op == DIV) ch = "div";
 554554                 else if (p->n_op == MOD && p->n_type == ULONGLONG) ch = "umod";
 555555                 else if (p->n_op == MOD) ch = "mod";
 556556                 else if (p->n_op == MUL) ch = "mul";
 557557                 else ch = 0, comperr("ZO %d", p->n_op);
 558558                 printf("\tcalls $4,__%sdi3\n", ch);
 559559                 break;
 560560 
 561561 
 562562         case 'Z':       /* complement mask for bit instr */
 563563                 printf("$%Ld", ~p->n_right->n_lval);
 564564                 return;
 565565 
 566566         case 'U':       /* 32 - n, for unsigned right shifts */
 567567                 m = p->n_left->n_type == UCHAR ? 8 :
 568568                     p->n_left->n_type == USHORT ? 16 : 32;
 569569                 printf("$" CONFMT, m - p->n_right->n_lval);
 570570                 return;
 571571 
 572572         case 'T':       /* rounded structure length for arguments */
 573573                 {
 574574                 int size;
 575575 
 576576                 size = p->n_stsize;
 577577                 SETOFF( size, 4);
 578578                 printf("$%d", size);
 579579                 return;
 580580                 }
 581581 
 582582         case 'S'/* structure assignment */
 583583                 {
 584584                         register int size;
 585585 
 586586                         size = p->n_stsize;
 587587                         l = r = NULL; /* XXX gcc */
 588588                         if( p->n_op == STASG ){
 589589                                 l = p->n_left;
 590590                                 r = p->n_right;
 591591 
 592592                                 }
 593593                         else if( p->n_op == STARG ){
 594594                                 /* store an arg into a temporary */
 595595                                 printf("\tsubl2 $%d,%%sp\n",
 596596                                     size < 4 ? 4 : size);
 597597                                 l = mklnode(OREG, 0, SP, INT);
 598598                                 r = p->n_left;
 599599                                 }
 600600                         else cerror( "STASG bad" );
 601601 
 602602                         if( r->n_op == ICON ) r->n_op = NAME;
 603603                         else if( r->n_op == REG ) r->n_op = OREG;
 604604                         else if( r->n_op != OREG ) cerror( "STASG-r" );
 605605 
 606606                         if( size <= 0 || size > 65535 )
 607607                                 cerror("structure size <0=0 or >65535");
 608608 
 609609                         switch(size) {
 610610                                 case 1:
 611611                                         printf("        movb    ");
 612612                                         break;
 613613                                 case 2:
 614614                                         printf("        movw    ");
 615615                                         break;
 616616                                 case 4:
 617617                                         printf("        movl    ");
 618618                                         break;
 619619                                 case 8:
 620620                                         printf("        movq    ");
 621621                                         break;
 622622                                 default:
 623623                                         printf("        movc3   $%d,", size);
 624624                                         break;
 625625                         }
 626626                         adrput(stdout, r);
 627627                         printf(",");
 628628                         adrput(stdout, l);
 629629                         printf("\n");
 630630 
 631631                         if( r->n_op == NAME ) r->n_op = ICON;
 632632                         else if( r->n_op == OREG ) r->n_op = REG;
 633633                         if (p->n_op == STARG)
 634634                                 tfree(l);
 635635 
 636636                         }
 637637                 break;
 638638 
 639639         default:
 640640                 comperr("illegal zzzcode '%c'", c);
 641641         }
 642642 }
 643643 
 644644 void
 645645 rmove(int rt, int rs, TWORD t)
 646646 {
 647647         printf( "       %s      %s,%s\n",
 648648                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 649649                 rnames[rt], rnames[rs] );
 650650 }
 651651 
 652652 int
 653653 rewfld(NODE *p)
 654654 {
 655655         return(1);
 656656 }
 657657 
 658658 #if 0
 659659 int
 660660 callreg(NODE *p)
 661661 {
 662662         return( R0 );
 663663 }
 664664 
 665665 int
 666666 base(register NODE *p)
 667667 {
 668668         register int o = p->op;
 669669 
 670670         if( (o==ICON && p->name[0] != '\0')) return( 100 ); /* ie no base reg */
 671671         if( o==REG ) return( p->rval );
 672672     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
 673673                 return( p->left->rval );
 674674     if( o==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 675675                 return( p->rval + 0200*1 );
 676676         if( o==INCR && p->left->op==REG ) return( p->left->rval + 0200*2 );
 677677         if( o==ASG MINUS && p->left->op==REG) return( p->left->rval + 0200*4 );
 678678         if( o==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
 679679           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 680680                 return( p->left->left->rval + 0200*(1+2) );
 681681         return( -1 );
 682682 }
 683683 
 684684 int
 685685 offset(register NODE *p, int tyl)
 686686 {
 687687 
 688688         if( tyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) return( p->rval );
 689689         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
 690690               (p->right->op==ICON && p->right->name[0]=='\0')
 691691               && (1<<p->right->lval)==tyl))
 692692                 return( p->left->rval );
 693693         return( -1 );
 694694 }
 695695 #endif
 696696 
 697697 #if 0
 698698 void
 699699 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 700700         register NODE *t;
 701701         NODE *f;
 702702 
 703703         p->n_op = OREG;
 704704         f = p->n_left;  /* have to free this subtree later */
 705705 
 706706         /* init base */
 707707         switch (q->n_op) {
 708708                 case ICON:
 709709                 case REG:
 710710                 case OREG:
 711711                         t = q;
 712712                         break;
 713713 
 714714                 case MINUS:
 715715                         q->n_right->n_lval = -q->n_right->n_lval;
 716716                 case PLUS:
 717717                         t = q->n_right;
 718718                         break;
 719719 
 720720                 case UMUL:
 721721                         t = q->n_left->n_left;
 722722                         break;
 723723 
 724724                 default:
 725725                         cerror("illegal makeor2");
 726726                         t = NULL; /* XXX gcc */
 727727         }
 728728 
 729729         p->n_lval = t->n_lval;
 730730         p->n_name = t->n_name;
 731731 
 732732         /* init offset */
 733733         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
 734734 
 735735         tfree(f);
 736736         return;
 737737         }
 738738 
 739739 int
 740740 canaddr( p ) NODE *p; {
 741741         register int o = p->n_op;
 742742 
 743743         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left, STARNM|SOREG)) ) return(1);
 744744         return(0);
 745745         }
 746746 
 747747 shltype( o, p ) register NODE *p; {
 748748         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 749749         }
 750750 #endif
 751751 
 752752 int
 753753 fldexpand(NODE *p, int cookie, char **cp)
 754754 {
 755755         return 0;
 756756 }
 757757 
 758758 int
 759759 flshape(register NODE *p)
 760760 {
 761761         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 762762                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 763763 }
 764764 
 765765 int
 766766 shtemp(register NODE *p)
 767767 {
 768768         if( p->n_op == STARG ) p = p->n_left;
 769769         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 770770 }
 771771 
 772772 /*
 773773  * Shape matches for UMUL.  Cooperates with offstar().
 774774  */
 775775 int
 776776 shumul(NODE *p, int shape)
 777777 {
 778778 
 779779         if (x2debug)
 780780                 printf("shumul(%p)\n", p);
 781781 
 782782         /* Turns currently anything into OREG on vax */
 783783         if (shape & SOREG)
 784784                 return SROREG;
 785785         return SRNOPE;
 786786 }
 787787 
 788788 
 789789 #ifdef notdef
 790790 int
 791791 shumul( p, shape ) register NODE *p; int shape; {
 792792         register int o;
 793793 
 794794         if (x2debug) {
 795795                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 796796                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 797797                 }
 798798 
 799799 
 800800         o = p->n_op;
 801801         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
 802802                 if (shape & STARNM)
 803803                         return SRDIR;
 804804 
 805805         if( ( o == INCR || o == ASG MINUS ) &&
 806806             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 807807             p->n_right->n_name[0] == '\0' )
 808808                 {
 809809                 switch (p->n_left->n_type)
 810810                         {
 811811                         case CHAR|PTR:
 812812                         case UCHAR|PTR:
 813813                                 o = 1;
 814814                                 break;
 815815 
 816816                         case SHORT|PTR:
 817817                         case USHORT|PTR:
 818818                                 o = 2;
 819819                                 break;
 820820 
 821821                         case INT|PTR:
 822822                         case UNSIGNED|PTR:
 823823                         case LONG|PTR:
 824824                         case ULONG|PTR:
 825825                         case FLOAT|PTR:
 826826                                 o = 4;
 827827                                 break;
 828828 
 829829                         case DOUBLE|PTR:
 830830                                 o = 8;
 831831                                 break;
 832832 
 833833                         default:
 834834                                 if ( ISPTR(p->n_left->n_type) ) {
 835835                                         o = 4;
 836836                                         break;
 837837                                         }
 838838                                 else return(0);
 839839                         }
 840840                 return( p->n_right->n_lval == o ? STARREG : 0);
 841841                 }
 842842 
 843843         return( SRNOPE );
 844844         }
 845845 #endif
 846846 
 847847 void
 848848 adrcon(CONSZ val)
 849849 {
 850850         printf( "$" );
 851851         printf( CONFMT, val );
 852852 }
 853853 
 854854 void
 855855 conput(FILE *fp, NODE *p)
 856856 {
 857857         switch( p->n_op ){
 858858 
 859859         case ICON:
 860860                 acon( p );
 861861                 return;
 862862 
 863863         case REG:
 864864                 printf( "%s", rnames[p->n_rval] );
 865865                 return;
 866866 
 867867         default:
 868868                 cerror( "illegal conput" );
 869869                 }
 870870         }
 871871 
 872872 void
 873873 insput(register NODE *p)
 874874 {
 875875         cerror( "insput" );
 876876 }
 877877 
 878878 /*
 879879  * Write out the upper address, like the upper register of a 2-register
 880880  * reference, or the next memory location.
 881881  */
 882882 void
 883883 upput(NODE *p, int size)
 884884 {
 885885 
 886886         size /= SZCHAR;
 887887         switch (p->n_op) {
 888888         case REG:
 889889                 fprintf(stdout, "%s", rnames[regno(p)-16+1]);
 890890                 break;
 891891 
 892892         case NAME:
 893893         case OREG:
 894894                 p->n_lval += size;
 895895                 adrput(stdout, p);
 896896                 p->n_lval -= size;
 897897                 break;
 898898         case ICON:
 899899                 fprintf(stdout, "$" CONFMT, p->n_lval >> 32);
 900900                 break;
 901901         default:
 902902                 comperr("upput bad op %d size %d", p->n_op, size);
 903903         }
 904904 }
 905905 
 906906 void
 907907 adrput(FILE *fp, NODE *p)
 908908 {
 909909         register int r;
 910910         /* output an address, with offsets, from p */
 911911 
 912912         if( p->n_op == FLD ){
 913913                 p = p->n_left;
 914914                 }
 915915         switch( p->n_op ){
 916916 
 917917         case NAME:
 918918                 acon( p );
 919919                 return;
 920920 
 921921         case ICON:
 922922                 /* addressable value of the constant */
 923923                 if (p->n_name[0] == '\0') /* uses xxxab */
 924924                         printf("$");
 925925                 acon(p);
 926926                 return;
 927927 
 928928         case REG:
 929929                 printf( "%s", rnames[p->n_rval] );
 930930                 return;
 931931 
 932932         case OREG:
 933933                 r = p->n_rval;
 934934                 if( R2TEST(r) ){ /* double indexing */
 935935                         register int flags;
 936936 
 937937                         flags = R2UPK3(r);
 938938                         if( flags & 1 ) printf("*");
 939939                         if( flags & 4 ) printf("-");
 940940                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 941941                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 942942                         if( flags & 2 ) printf("+");
 943943                         printf( "[%s]", rnames[R2UPK2(r)] );
 944944                         return;
 945945                         }
 946946                 if( r == AP ){  /* in the argument region */
 947947                         if( p->n_lval <= 0 || p->n_name[0] != '\0' )
 948948                                 werror( "bad arg temp" );
 949949                         printf( CONFMT, p->n_lval );
 950950                         printf( "(%%ap)" );
 951951                         return;
 952952                         }
 953953                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 954954                 printf( "(%s)", rnames[p->n_rval] );
 955955                 return;
 956956 
 957957         case UMUL:
 958958                 /* STARNM or STARREG found */
 959959                 if( tshape(p, STARNM) ) {
 960960                         printf( "*" );
 961961                         adrput(0p->n_left);
 962962                         }
 963963                 else {  /* STARREG - really auto inc or dec */
 964964                         register NODE *q;
 965965 
 966966 /* tbl
 967967                         p = p->n_left;
 968968                         p->n_left->n_op = OREG;
 969969                         if( p->n_op == INCR ) {
 970970                                 adrput( p->n_left );
 971971                                 printf( "+" );
 972972                                 }
 973973                         else {
 974974                                 printf( "-" );
 975975                                 adrput( p->n_left );
 976976                                 }
 977977    tbl */
 978978 #ifdef notyet
 979979                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 980980                                 rnames[p->n_left->n_left->n_rval],
 981981                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 982982 #else
 983983                         printf("%c(%s)%c", '-',
 984984                                 rnames[p->n_left->n_left->n_rval],
 985985                                 '\0' );
 986986 #endif
 987987                         p->n_op = OREG;
 988988                         p->n_rval = p->n_left->n_left->n_rval;
 989989                         q = p->n_left;
 990990 #ifdef notyet
 991991 
 992992                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 993993 #else
 994994                         p->n_lval = 0;
 995995 #endif
 996996                         p->n_name[0] = '\0';
 997997                         tfree(q);
 998998                 }
 999999                 return;
 10001000 
 10011001         default:
 10021002                 cerror( "illegal address" );
 10031003                 return;
 10041004         }
 10051005 
 10061006 }
 10071007 
 10081008 /*
 10091009  * print out a constant
 10101010  */
 10111011 void
 10121012 acon(NODE *p)
 10131013 {
 10141014 
 10151015         if (p->n_name[0] == '\0') {
 10161016                 printf(CONFMT, p->n_lval);
 10171017         } else if( p->n_lval == 0 ) {
 10181018                 printf("%s", p->n_name);
 10191019         } else {
 10201020                 printf("%s+", p->n_name);
 10211021                 printf(CONFMT, p->n_lval);
 10221022         }
 10231023 }
 10241024 
 10251025 #if 0
 10261026 genscall( p, cookie ) register NODE *p; {
 10271027         /* structure valued call */
 10281028         return( gencall( p, cookie ) );
 10291029         }
 10301030 
 10311031 /* tbl */
 10321032 int gc_numbytes;
 10331033 /* tbl */
 10341034 
 10351035 gencall( p, cookie ) register NODE *p; {
 10361036         /* generate the call given by p */
 10371037         register NODE *p1, *ptemp;
 10381038         register temp, temp1;
 10391039         register m;
 10401040 
 10411041         if( p->right ) temp = argsize( p->right );
 10421042         else temp = 0;
 10431043 
 10441044         if( p->op == STCALL || p->op == UNARY STCALL ){
 10451045                 /* set aside room for structure return */
 10461046 
 10471047                 if( p->stsize > temp ) temp1 = p->stsize;
 10481048                 else temp1 = temp;
 10491049                 }
 10501050 
 10511051         if( temp > maxargs ) maxargs = temp;
 10521052         SETOFF(temp1,4);
 10531053 
 10541054         if( p->right ){ /* make temp node, put offset in, and generate args */
 10551055                 ptemp = talloc();
 10561056                 ptemp->op = OREG;
 10571057                 ptemp->lval = -1;
 10581058                 ptemp->rval = SP;
 10591059                 ptemp->name[0] = '\0';
 10601060                 ptemp->rall = NOPREF;
 10611061                 ptemp->su = 0;
 10621062                 genargs( p->right, ptemp );
 10631063                 nfree(ptemp);
 10641064                 }
 10651065 
 10661066         p1 = p->left;
 10671067         if( p1->op != ICON ){
 10681068                 if( p1->op != REG ){
 10691069                         if( p1->op != OREG || R2TEST(p1->rval) ){
 10701070                                 if( p1->op != NAME ){
 10711071                                         order( p1, INAREG );
 10721072                                         }
 10731073                                 }
 10741074                         }
 10751075                 }
 10761076 
 10771077 /*
 10781078         if( p1->op == REG && p->rval == R5 ){
 10791079                 cerror( "call register overwrite" );
 10801080                 }
 10811081  */
 10821082 /* tbl
 10831083         setup gc_numbytes so reference to ZC works */
 10841084 
 10851085         gc_numbytes = temp;
 10861086 /* tbl */
 10871087 
 10881088         p->op = UNARY CALL;
 10891089         m = match( p, INTAREG|INTBREG );
 10901090 /* tbl
 10911091         switch( temp ) {
 10921092         case 0:
 10931093                 break;
 10941094         case 2:
 10951095                 printf( "       tst     (%sp)+\n" );
 10961096                 break;
 10971097         case 4:
 10981098                 printf( "       cmp     (%sp)+,(%sp)+\n" );
 10991099                 break;
 11001100         default:
 11011101                 printf( "       add     $%d,%sp\n", temp);
 11021102                 }
 11031103    tbl */
 11041104         return(m != MDONE);
 11051105         }
 11061106 #endif
 11071107 
 11081108 static char *
 11091109 ccbranches[] = {
 11101110         "jeql",
 11111111         "jneq",
 11121112         "jleq",
 11131113         "jlss",
 11141114         "jgeq",
 11151115         "jgtr",
 11161116         "jlequ",
 11171117         "jlssu",
 11181118         "jgequ",
 11191119         "jgtru",
 11201120 };
 11211121 
 11221122 /*
 11231123  * printf conditional and unconditional branches
 11241124  */
 11251125 void
 11261126 cbgen(int o, int lab)
 11271127 {
 11281128 
 11291129         if (o == 0) {
 11301130                 printf("        jbr     " LABFMT "\n", lab);
 11311131         } else {
 11321132                 if (o > UGT)
 11331133                         comperr("bad conditional branch: %s", opst[o]);
 11341134                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 11351135         }
 11361136 }
 11371137 
 11381138 static void
 11391139 mkcall(NODE *p, char *name)
 11401140 {
 11411141         p->n_op = CALL;
 11421142         p->n_right = mkunode(FUNARG, p->n_left, 0, p->n_left->n_type);
 11431143         p->n_left = mklnode(ICON, 0, 0, FTN|p->n_type);
<>1144 -        p->n_left->n_name = "__fixunsdfdi";
  1144+        p->n_left->n_name = name;
11451145 }
 11461146 
 11471147 /* do local tree transformations and optimizations */
 11481148 static void
 11491149 optim2(NODE *p, void *arg)
 11501150 {
 11511151         NODE *r, *s;
 11521152         TWORD lt;
 11531153 
 11541154         switch (p->n_op) {
 11551155         case MOD:
 11561156                 if (p->n_type == USHORT || p->n_type == UCHAR) {
 11571157                         r = mkunode(SCONV, p->n_left, 0, UNSIGNED);
 11581158                         r = mkunode(FUNARG, r, 0, UNSIGNED);
 11591159                         s = mkunode(SCONV, p->n_right, 0, UNSIGNED);
 11601160                         s = mkunode(FUNARG, s, 0, UNSIGNED);
 11611161                         r = mkbinode(CM, r, s, INT);
 11621162                         s = mklnode(ICON, 0, 0, FTN|UNSIGNED);
 11631163                         s->n_name = "__urem";
 11641164                         p->n_left = mkbinode(CALL, s, r, UNSIGNED);
 11651165                         p->n_op = SCONV;
 11661166                 } else if (p->n_type == UNSIGNED) {
 11671167                         p->n_left = mkunode(FUNARG, p->n_left, 0, UNSIGNED);
 11681168                         p->n_right = mkunode(FUNARG, p->n_right, 0, UNSIGNED);
 11691169                         p->n_right = mkbinode(CM, p->n_left, p->n_right, INT);
 11701170                         p->n_left = mklnode(ICON, 0, 0, FTN|UNSIGNED);
 11711171                         p->n_left->n_name = "__urem";
 11721172                         p->n_op = CALL;
 11731173                 }
 11741174                 break;
 11751175 
 11761176         case RS:
 11771177                 if (p->n_type == ULONGLONG) {
 11781178                         p->n_right = mkbinode(CM,
 11791179                             mkunode(FUNARG, p->n_left, 0, p->n_left->n_type),
 11801180                             mkunode(FUNARG, p->n_right, 0, p->n_right->n_type),
 11811181                             INT);
 11821182                         p->n_left = mklnode(ICON, 0, 0, FTN|p->n_type);
 11831183                         p->n_left->n_name = "__lshrdi3";
 11841184                         p->n_op = CALL;
 11851185                 } else if (p->n_type == INT) {
 11861186                         /* convert >> to << with negative shift count */
 11871187                         /* RS of char & short must use extv */
 11881188                         if (p->n_right->n_op == ICON) {
 11891189                                 p->n_right->n_lval = -p->n_right->n_lval;
 11901190                         } else if (p->n_right->n_op == UMINUS) {
 11911191                                 r = p->n_right->n_left;
 11921192                                 nfree(p->n_right);
 11931193                                 p->n_right = r;
 11941194                         } else {
 11951195                                 p->n_right = mkunode(UMINUS, p->n_right,
 11961196                                     0, p->n_right->n_type);
 11971197                         }
 11981198                         p->n_op = LS;
 11991199                 }
 12001200                 break;
 12011201 
 12021202         case AND:
 12031203                 /* commute L and R to eliminate compliments and constants */
 12041204                 if ((p->n_left->n_op == ICON && p->n_left->n_name[0] == 0) ||
 12051205                     p->n_left->n_op==COMPL) {
 12061206                         r = p->n_left;
 12071207                         p->n_left = p->n_right;
 12081208                         p->n_right = r;
 12091209                 }
 12101210                 /* change meaning of AND to ~R&L - bic on pdp11 */
 12111211                 r = p->n_right;
 12121212                 if (r->n_op == ICON && r->n_name[0] == 0) {
 12131213                         /* compliment constant */
 12141214                         r->n_lval = ~r->n_lval;
 12151215                 } else if (r->n_op == COMPL) { /* ~~A => A */
 12161216                         s = r->n_left;
 12171217                         nfree(r);
 12181218                         p->n_right = s;
 12191219                 } else { /* insert complement node */
 12201220                         p->n_right = mkunode(COMPL, r, 0, r->n_type);
 12211221                 }
 12221222                 break;
 12231223         case SCONV:
 12241224                 lt = p->n_left->n_type;
 12251225                 switch (p->n_type) {
 12261226                 case LONGLONG:
 12271227                         if (lt == FLOAT)
 12281228                                 mkcall(p, "__fixsfdi");
 12291229                         else if (lt == DOUBLE)
 12301230                                 mkcall(p, "__fixdfdi");
 12311231                         break;
 12321232                 case ULONGLONG:
 12331233                         if (lt == FLOAT)
 12341234                                 mkcall(p, "__fixunssfdi");
 12351235                         else if (lt == DOUBLE)
 12361236                                 mkcall(p, "__fixunsdfdi");
 12371237                         break;
 12381238                 case FLOAT:
 12391239                         if (lt == LONGLONG)
 12401240                                 mkcall(p, "__floatdisf");
 12411241                         else if (lt == ULONGLONG) {
 12421242                                 p->n_left = mkunode(SCONV, p->n_left,0, DOUBLE);
 12431243                                 p->n_type = FLOAT;
 12441244                                 mkcall(p->n_left, "__floatunsdidf");
 12451245                         } else if (lt == UNSIGNED) {
 12461246                                 /* insert an extra double-to-float sconv */
 12471247                                 p->n_left = mkunode(SCONV, p->n_left,0, DOUBLE);
 12481248                         }
 12491249                         break;
 12501250                 case DOUBLE:
 12511251                         if (lt == LONGLONG)
 12521252                                 mkcall(p, "__floatdidf");
 12531253                         else if (lt == ULONGLONG)
<>1254 -                                mkcall(p->n_left, "__floatunsdidf");
  1254+                                mkcall(p, "__floatunsdidf");
<_12551255                         break;
 12561256                         
 12571257                 }
 12581258                 break;
 12591259         }
 12601260 }
 12611261 
 12621262 void
 12631263 myreader(struct interpass *ipole)
 12641264 {
 12651265         struct interpass *ip;
 12661266 
 12671267         DLIST_FOREACH(ip, ipole, qelem) {
 12681268                 if (ip->type != IP_NODE)
 12691269                         continue;
 12701270                 walkf(ip->ip_node, optim2, 0);
 12711271         }
 12721272 }
 12731273 
 12741274 void
 12751275 mycanon(NODE *p)
 12761276 {
 12771277 }
 12781278 
 12791279 void
 12801280 myoptim(struct interpass *ip)
 12811281 {
 12821282 }
 12831283 
 12841284 /*
 12851285  * Return argument size in regs.
 12861286  */
 12871287 static int
 12881288 argsiz(NODE *p)
 12891289 {
 12901290         TWORD t = p->n_type;
 12911291 
 12921292         if (t == STRTY || t == UNIONTY)
 12931293                 return p->n_stsize/(SZINT/SZCHAR);
 12941294         return szty(t);
 12951295 }
 12961296 
 12971297 /*
 12981298  * Last chance to do something before calling a function.
 12991299  */
 13001300 void
 13011301 lastcall(NODE *p)
 13021302 {
 13031303         NODE *op = p;
 13041304         int size = 0;
 13051305 
 13061306         /* Calculate argument sizes */
 13071307         p->n_qual = 0;
 13081308         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 13091309                 return;
 13101310         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 13111311                 size += argsiz(p->n_right);
 13121312         if (p->n_op != ASSIGN)
 13131313                 size += argsiz(p);
 13141314         op->n_qual = size; /* XXX */
 13151315 }
 13161316 
 13171317 /*
 13181318  * Return a class suitable for a specific type.
 13191319  */
 13201320 int
 13211321 gclass(TWORD t)
 13221322 {
 13231323         return (szty(t) == 2 ? CLASSB : CLASSA);
 13241324 }
 13251325 
 13261326 /*
 13271327  * For class c, find worst-case displacement of the number of
 13281328  * registers in the array r[] indexed by class.
 13291329  */
 13301330 int
 13311331 COLORMAP(int c, int *r)
 13321332 {
 13331333         int num;
 13341334         int a,b;
 13351335 
 13361336         a = r[CLASSA];
 13371337         b = r[CLASSB];
 13381338         switch (c) {
 13391339         case CLASSA:
 13401340                 /* there are 12 classa, so min 6 classb are needed to block */
 13411341                 num = b * 2;
 13421342                 num += a;
 13431343                 return num < 12;
 13441344         case CLASSB:
 13451345                 if (b > 3) return 0;
 13461346                 if (b > 2 && a) return 0;
 13471347                 if (b > 1 && a > 2) return 0;
 13481348                 if (b && a > 3) return 0;
 13491349                 if (a > 5) return 0;
 13501350                 return 1;
 13511351         }
 13521352         comperr("COLORMAP");
 13531353         return 0; /* XXX gcc */
 13541354 }
 13551355 
 13561356 /*
 13571357  * Special shapes.
 13581358  */
 13591359 int
 13601360 special(NODE *p, int shape)
 13611361 {
 13621362         return SRNOPE;
 13631363 }
 13641364 
 13651365 /*
 13661366  * Target-dependent command-line options.
 13671367  */
 13681368 void
 13691369 mflags(char *str)
 13701370 {
 13711371 }
 13721372 /*
 13731373  * Do something target-dependent for xasm arguments.
 13741374  * Supposed to find target-specific constraints and rewrite them.
 13751375  */
 13761376 int
 13771377 myxasm(struct interpass *ip, NODE *p)
 13781378 {
 13791379         return 0;
 13801380 }
 13811381 
 13821382 int
 13831383 xasmconstregs(char *s)
 13841384 {
 13851385         int i;
 13861386 
 13871387         for (i = 0; i < 16; i++)
 13881388                 if (strcmp(&rnames[i][1], s) == 0)
 13891389                         return i;
 13901390         return -1;
 13911391 }
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-09-21 10:11 +0200