Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.31
 
1.32
 
MAIN:ragge:20120827163356
 
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 
<> 606+                if (size != 0) {
606607                         if( size <= 0 || size > 65535 )
 607608                                 cerror("structure size <0=0 or >65535");
 608609 
 609610                         switch(size) {
 610611                                 case 1:
 611612                                         printf("        movb    ");
 612613                                         break;
 613614                                 case 2:
 614615                                         printf("        movw    ");
 615616                                         break;
 616617                                 case 4:
 617618                                         printf("        movl    ");
 618619                                         break;
 619620                                 case 8:
 620621                                         printf("        movq    ");
 621622                                         break;
 622623                                 default:
 623624                                         printf("        movc3   $%d,", size);
 624625                                         break;
 625626                         }
 626627                         adrput(stdout, r);
 627628                         printf(",");
 628629                         adrput(stdout, l);
 629630                         printf("\n");
<> 631+                }
<_630632 
 631633                         if( r->n_op == NAME ) r->n_op = ICON;
 632634                         else if( r->n_op == OREG ) r->n_op = REG;
 633635                         if (p->n_op == STARG)
 634636                                 tfree(l);
 635637 
 636638                         }
 637639                 break;
 638640 
 639641         default:
 640642                 comperr("illegal zzzcode '%c'", c);
 641643         }
 642644 }
 643645 
 644646 void
 645647 rmove(int rt, int rs, TWORD t)
 646648 {
 647649         printf( "       %s      %s,%s\n",
 648650                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 649651                 rnames[rt], rnames[rs] );
 650652 }
 651653 
 652654 int
 653655 rewfld(NODE *p)
 654656 {
 655657         return(1);
 656658 }
 657659 
 658660 #if 0
 659661 int
 660662 callreg(NODE *p)
 661663 {
 662664         return( R0 );
 663665 }
 664666 
 665667 int
 666668 base(register NODE *p)
 667669 {
 668670         register int o = p->op;
 669671 
 670672         if( (o==ICON && p->name[0] != '\0')) return( 100 ); /* ie no base reg */
 671673         if( o==REG ) return( p->rval );
 672674     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
 673675                 return( p->left->rval );
 674676     if( o==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 675677                 return( p->rval + 0200*1 );
 676678         if( o==INCR && p->left->op==REG ) return( p->left->rval + 0200*2 );
 677679         if( o==ASG MINUS && p->left->op==REG) return( p->left->rval + 0200*4 );
 678680         if( o==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
 679681           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 680682                 return( p->left->left->rval + 0200*(1+2) );
 681683         return( -1 );
 682684 }
 683685 
 684686 int
 685687 offset(register NODE *p, int tyl)
 686688 {
 687689 
 688690         if( tyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) return( p->rval );
 689691         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
 690692               (p->right->op==ICON && p->right->name[0]=='\0')
 691693               && (1<<p->right->lval)==tyl))
 692694                 return( p->left->rval );
 693695         return( -1 );
 694696 }
 695697 #endif
 696698 
 697699 #if 0
 698700 void
 699701 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 700702         register NODE *t;
 701703         NODE *f;
 702704 
 703705         p->n_op = OREG;
 704706         f = p->n_left;  /* have to free this subtree later */
 705707 
 706708         /* init base */
 707709         switch (q->n_op) {
 708710                 case ICON:
 709711                 case REG:
 710712                 case OREG:
 711713                         t = q;
 712714                         break;
 713715 
 714716                 case MINUS:
 715717                         q->n_right->n_lval = -q->n_right->n_lval;
 716718                 case PLUS:
 717719                         t = q->n_right;
 718720                         break;
 719721 
 720722                 case UMUL:
 721723                         t = q->n_left->n_left;
 722724                         break;
 723725 
 724726                 default:
 725727                         cerror("illegal makeor2");
 726728                         t = NULL; /* XXX gcc */
 727729         }
 728730 
 729731         p->n_lval = t->n_lval;
 730732         p->n_name = t->n_name;
 731733 
 732734         /* init offset */
 733735         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
 734736 
 735737         tfree(f);
 736738         return;
 737739         }
 738740 
 739741 int
 740742 canaddr( p ) NODE *p; {
 741743         register int o = p->n_op;
 742744 
 743745         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left, STARNM|SOREG)) ) return(1);
 744746         return(0);
 745747         }
 746748 
 747749 shltype( o, p ) register NODE *p; {
 748750         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 749751         }
 750752 #endif
 751753 
 752754 int
 753755 fldexpand(NODE *p, int cookie, char **cp)
 754756 {
 755757         return 0;
 756758 }
 757759 
 758760 int
 759761 flshape(register NODE *p)
 760762 {
 761763         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 762764                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 763765 }
 764766 
 765767 int
 766768 shtemp(register NODE *p)
 767769 {
 768770         if( p->n_op == STARG ) p = p->n_left;
 769771         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 770772 }
 771773 
 772774 /*
 773775  * Shape matches for UMUL.  Cooperates with offstar().
 774776  */
 775777 int
 776778 shumul(NODE *p, int shape)
 777779 {
 778780 
 779781         if (x2debug)
 780782                 printf("shumul(%p)\n", p);
 781783 
 782784         /* Turns currently anything into OREG on vax */
 783785         if (shape & SOREG)
 784786                 return SROREG;
 785787         return SRNOPE;
 786788 }
 787789 
 788790 
 789791 #ifdef notdef
 790792 int
 791793 shumul( p, shape ) register NODE *p; int shape; {
 792794         register int o;
 793795 
 794796         if (x2debug) {
 795797                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 796798                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 797799                 }
 798800 
 799801 
 800802         o = p->n_op;
 801803         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
 802804                 if (shape & STARNM)
 803805                         return SRDIR;
 804806 
 805807         if( ( o == INCR || o == ASG MINUS ) &&
 806808             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 807809             p->n_right->n_name[0] == '\0' )
 808810                 {
 809811                 switch (p->n_left->n_type)
 810812                         {
 811813                         case CHAR|PTR:
 812814                         case UCHAR|PTR:
 813815                                 o = 1;
 814816                                 break;
 815817 
 816818                         case SHORT|PTR:
 817819                         case USHORT|PTR:
 818820                                 o = 2;
 819821                                 break;
 820822 
 821823                         case INT|PTR:
 822824                         case UNSIGNED|PTR:
 823825                         case LONG|PTR:
 824826                         case ULONG|PTR:
 825827                         case FLOAT|PTR:
 826828                                 o = 4;
 827829                                 break;
 828830 
 829831                         case DOUBLE|PTR:
 830832                                 o = 8;
 831833                                 break;
 832834 
 833835                         default:
 834836                                 if ( ISPTR(p->n_left->n_type) ) {
 835837                                         o = 4;
 836838                                         break;
 837839                                         }
 838840                                 else return(0);
 839841                         }
 840842                 return( p->n_right->n_lval == o ? STARREG : 0);
 841843                 }
 842844 
 843845         return( SRNOPE );
 844846         }
 845847 #endif
 846848 
 847849 void
 848850 adrcon(CONSZ val)
 849851 {
 850852         printf( "$" );
 851853         printf( CONFMT, val );
 852854 }
 853855 
 854856 void
 855857 conput(FILE *fp, NODE *p)
 856858 {
 857859         switch( p->n_op ){
 858860 
 859861         case ICON:
 860862                 acon( p );
 861863                 return;
 862864 
 863865         case REG:
 864866                 printf( "%s", rnames[p->n_rval] );
 865867                 return;
 866868 
 867869         default:
 868870                 cerror( "illegal conput" );
 869871                 }
 870872         }
 871873 
 872874 void
 873875 insput(register NODE *p)
 874876 {
 875877         cerror( "insput" );
 876878 }
 877879 
 878880 /*
 879881  * Write out the upper address, like the upper register of a 2-register
 880882  * reference, or the next memory location.
 881883  */
 882884 void
 883885 upput(NODE *p, int size)
 884886 {
 885887 
 886888         size /= SZCHAR;
 887889         switch (p->n_op) {
 888890         case REG:
 889891                 fprintf(stdout, "%s", rnames[regno(p)-16+1]);
 890892                 break;
 891893 
 892894         case NAME:
 893895         case OREG:
 894896                 p->n_lval += size;
 895897                 adrput(stdout, p);
 896898                 p->n_lval -= size;
 897899                 break;
 898900         case ICON:
 899901                 fprintf(stdout, "$" CONFMT, p->n_lval >> 32);
 900902                 break;
 901903         default:
 902904                 comperr("upput bad op %d size %d", p->n_op, size);
 903905         }
 904906 }
 905907 
 906908 void
 907909 adrput(FILE *fp, NODE *p)
 908910 {
 909911         register int r;
 910912         /* output an address, with offsets, from p */
 911913 
 912914         if( p->n_op == FLD ){
 913915                 p = p->n_left;
 914916                 }
 915917         switch( p->n_op ){
 916918 
 917919         case NAME:
 918920                 acon( p );
 919921                 return;
 920922 
 921923         case ICON:
 922924                 /* addressable value of the constant */
 923925                 if (p->n_name[0] == '\0') /* uses xxxab */
 924926                         printf("$");
 925927                 acon(p);
 926928                 return;
 927929 
 928930         case REG:
 929931                 printf( "%s", rnames[p->n_rval] );
 930932                 return;
 931933 
 932934         case OREG:
 933935                 r = p->n_rval;
 934936                 if( R2TEST(r) ){ /* double indexing */
 935937                         register int flags;
 936938 
 937939                         flags = R2UPK3(r);
 938940                         if( flags & 1 ) printf("*");
 939941                         if( flags & 4 ) printf("-");
 940942                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 941943                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 942944                         if( flags & 2 ) printf("+");
 943945                         printf( "[%s]", rnames[R2UPK2(r)] );
 944946                         return;
 945947                         }
 946948                 if( r == AP ){  /* in the argument region */
 947949                         if( p->n_lval <= 0 || p->n_name[0] != '\0' )
 948950                                 werror( "bad arg temp" );
 949951                         printf( CONFMT, p->n_lval );
 950952                         printf( "(%%ap)" );
 951953                         return;
 952954                         }
 953955                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 954956                 printf( "(%s)", rnames[p->n_rval] );
 955957                 return;
 956958 
 957959         case UMUL:
 958960                 /* STARNM or STARREG found */
 959961                 if( tshape(p, STARNM) ) {
 960962                         printf( "*" );
 961963                         adrput(0p->n_left);
 962964                         }
 963965                 else {  /* STARREG - really auto inc or dec */
 964966                         register NODE *q;
 965967 
 966968 /* tbl
 967969                         p = p->n_left;
 968970                         p->n_left->n_op = OREG;
 969971                         if( p->n_op == INCR ) {
 970972                                 adrput( p->n_left );
 971973                                 printf( "+" );
 972974                                 }
 973975                         else {
 974976                                 printf( "-" );
 975977                                 adrput( p->n_left );
 976978                                 }
 977979    tbl */
 978980 #ifdef notyet
 979981                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 980982                                 rnames[p->n_left->n_left->n_rval],
 981983                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 982984 #else
 983985                         printf("%c(%s)%c", '-',
 984986                                 rnames[p->n_left->n_left->n_rval],
 985987                                 '\0' );
 986988 #endif
 987989                         p->n_op = OREG;
 988990                         p->n_rval = p->n_left->n_left->n_rval;
 989991                         q = p->n_left;
 990992 #ifdef notyet
 991993 
 992994                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 993995 #else
 994996                         p->n_lval = 0;
 995997 #endif
 996998                         p->n_name[0] = '\0';
 997999                         tfree(q);
 9981000                 }
 9991001                 return;
 10001002 
 10011003         default:
 10021004                 cerror( "illegal address" );
 10031005                 return;
 10041006         }
 10051007 
 10061008 }
 10071009 
 10081010 /*
 10091011  * print out a constant
 10101012  */
 10111013 void
 10121014 acon(NODE *p)
 10131015 {
 10141016 
 10151017         if (p->n_name[0] == '\0') {
 10161018                 printf(CONFMT, p->n_lval);
 10171019         } else if( p->n_lval == 0 ) {
 10181020                 printf("%s", p->n_name);
 10191021         } else {
 10201022                 printf("%s+", p->n_name);
 10211023                 printf(CONFMT, p->n_lval);
 10221024         }
 10231025 }
 10241026 
 10251027 #if 0
 10261028 genscall( p, cookie ) register NODE *p; {
 10271029         /* structure valued call */
 10281030         return( gencall( p, cookie ) );
 10291031         }
 10301032 
 10311033 /* tbl */
 10321034 int gc_numbytes;
 10331035 /* tbl */
 10341036 
 10351037 gencall( p, cookie ) register NODE *p; {
 10361038         /* generate the call given by p */
 10371039         register NODE *p1, *ptemp;
 10381040         register temp, temp1;
 10391041         register m;
 10401042 
 10411043         if( p->right ) temp = argsize( p->right );
 10421044         else temp = 0;
 10431045 
 10441046         if( p->op == STCALL || p->op == UNARY STCALL ){
 10451047                 /* set aside room for structure return */
 10461048 
 10471049                 if( p->stsize > temp ) temp1 = p->stsize;
 10481050                 else temp1 = temp;
 10491051                 }
 10501052 
 10511053         if( temp > maxargs ) maxargs = temp;
 10521054         SETOFF(temp1,4);
 10531055 
 10541056         if( p->right ){ /* make temp node, put offset in, and generate args */
 10551057                 ptemp = talloc();
 10561058                 ptemp->op = OREG;
 10571059                 ptemp->lval = -1;
 10581060                 ptemp->rval = SP;
 10591061                 ptemp->name[0] = '\0';
 10601062                 ptemp->rall = NOPREF;
 10611063                 ptemp->su = 0;
 10621064                 genargs( p->right, ptemp );
 10631065                 nfree(ptemp);
 10641066                 }
 10651067 
 10661068         p1 = p->left;
 10671069         if( p1->op != ICON ){
 10681070                 if( p1->op != REG ){
 10691071                         if( p1->op != OREG || R2TEST(p1->rval) ){
 10701072                                 if( p1->op != NAME ){
 10711073                                         order( p1, INAREG );
 10721074                                         }
 10731075                                 }
 10741076                         }
 10751077                 }
 10761078 
 10771079 /*
 10781080         if( p1->op == REG && p->rval == R5 ){
 10791081                 cerror( "call register overwrite" );
 10801082                 }
 10811083  */
 10821084 /* tbl
 10831085         setup gc_numbytes so reference to ZC works */
 10841086 
 10851087         gc_numbytes = temp;
 10861088 /* tbl */
 10871089 
 10881090         p->op = UNARY CALL;
 10891091         m = match( p, INTAREG|INTBREG );
 10901092 /* tbl
 10911093         switch( temp ) {
 10921094         case 0:
 10931095                 break;
 10941096         case 2:
 10951097                 printf( "       tst     (%sp)+\n" );
 10961098                 break;
 10971099         case 4:
 10981100                 printf( "       cmp     (%sp)+,(%sp)+\n" );
 10991101                 break;
 11001102         default:
 11011103                 printf( "       add     $%d,%sp\n", temp);
 11021104                 }
 11031105    tbl */
 11041106         return(m != MDONE);
 11051107         }
 11061108 #endif
 11071109 
 11081110 static char *
 11091111 ccbranches[] = {
 11101112         "jeql",
 11111113         "jneq",
 11121114         "jleq",
 11131115         "jlss",
 11141116         "jgeq",
 11151117         "jgtr",
 11161118         "jlequ",
 11171119         "jlssu",
 11181120         "jgequ",
 11191121         "jgtru",
 11201122 };
 11211123 
 11221124 /*
 11231125  * printf conditional and unconditional branches
 11241126  */
 11251127 void
 11261128 cbgen(int o, int lab)
 11271129 {
 11281130 
 11291131         if (o == 0) {
 11301132                 printf("        jbr     " LABFMT "\n", lab);
 11311133         } else {
 11321134                 if (o > UGT)
 11331135                         comperr("bad conditional branch: %s", opst[o]);
 11341136                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 11351137         }
 11361138 }
 11371139 
 11381140 static void
 11391141 mkcall(NODE *p, char *name)
 11401142 {
 11411143         p->n_op = CALL;
 11421144         p->n_right = mkunode(FUNARG, p->n_left, 0, p->n_left->n_type);
 11431145         p->n_left = mklnode(ICON, 0, 0, FTN|p->n_type);
 11441146         p->n_left->n_name = name;
 11451147 }
 11461148 
 11471149 /* do local tree transformations and optimizations */
 11481150 static void
 11491151 optim2(NODE *p, void *arg)
 11501152 {
 11511153         NODE *r, *s;
 11521154         TWORD lt;
 11531155 
 11541156         switch (p->n_op) {
 11551157         case MOD:
 11561158                 if (p->n_type == USHORT || p->n_type == UCHAR) {
 11571159                         r = mkunode(SCONV, p->n_left, 0, UNSIGNED);
 11581160                         r = mkunode(FUNARG, r, 0, UNSIGNED);
 11591161                         s = mkunode(SCONV, p->n_right, 0, UNSIGNED);
 11601162                         s = mkunode(FUNARG, s, 0, UNSIGNED);
 11611163                         r = mkbinode(CM, r, s, INT);
 11621164                         s = mklnode(ICON, 0, 0, FTN|UNSIGNED);
 11631165                         s->n_name = "__urem";
 11641166                         p->n_left = mkbinode(CALL, s, r, UNSIGNED);
 11651167                         p->n_op = SCONV;
 11661168                 } else if (p->n_type == UNSIGNED) {
 11671169                         p->n_left = mkunode(FUNARG, p->n_left, 0, UNSIGNED);
 11681170                         p->n_right = mkunode(FUNARG, p->n_right, 0, UNSIGNED);
 11691171                         p->n_right = mkbinode(CM, p->n_left, p->n_right, INT);
 11701172                         p->n_left = mklnode(ICON, 0, 0, FTN|UNSIGNED);
 11711173                         p->n_left->n_name = "__urem";
 11721174                         p->n_op = CALL;
 11731175                 }
 11741176                 break;
 11751177 
 11761178         case RS:
 11771179                 if (p->n_type == ULONGLONG) {
 11781180                         p->n_right = mkbinode(CM,
 11791181                             mkunode(FUNARG, p->n_left, 0, p->n_left->n_type),
 11801182                             mkunode(FUNARG, p->n_right, 0, p->n_right->n_type),
 11811183                             INT);
 11821184                         p->n_left = mklnode(ICON, 0, 0, FTN|p->n_type);
 11831185                         p->n_left->n_name = "__lshrdi3";
 11841186                         p->n_op = CALL;
 11851187                 } else if (p->n_type == INT) {
 11861188                         /* convert >> to << with negative shift count */
 11871189                         /* RS of char & short must use extv */
 11881190                         if (p->n_right->n_op == ICON) {
 11891191                                 p->n_right->n_lval = -p->n_right->n_lval;
 11901192                         } else if (p->n_right->n_op == UMINUS) {
 11911193                                 r = p->n_right->n_left;
 11921194                                 nfree(p->n_right);
 11931195                                 p->n_right = r;
 11941196                         } else {
 11951197                                 p->n_right = mkunode(UMINUS, p->n_right,
 11961198                                     0, p->n_right->n_type);
 11971199                         }
 11981200                         p->n_op = LS;
 11991201                 }
 12001202                 break;
 12011203 
 12021204         case AND:
 12031205                 /* commute L and R to eliminate compliments and constants */
 12041206                 if ((p->n_left->n_op == ICON && p->n_left->n_name[0] == 0) ||
 12051207                     p->n_left->n_op==COMPL) {
 12061208                         r = p->n_left;
 12071209                         p->n_left = p->n_right;
 12081210                         p->n_right = r;
 12091211                 }
 12101212                 /* change meaning of AND to ~R&L - bic on pdp11 */
 12111213                 r = p->n_right;
 12121214                 if (r->n_op == ICON && r->n_name[0] == 0) {
 12131215                         /* compliment constant */
 12141216                         r->n_lval = ~r->n_lval;
 12151217                 } else if (r->n_op == COMPL) { /* ~~A => A */
 12161218                         s = r->n_left;
 12171219                         nfree(r);
 12181220                         p->n_right = s;
 12191221                 } else { /* insert complement node */
 12201222                         p->n_right = mkunode(COMPL, r, 0, r->n_type);
 12211223                 }
 12221224                 break;
 12231225         case SCONV:
 12241226                 lt = p->n_left->n_type;
 12251227                 switch (p->n_type) {
 12261228                 case LONGLONG:
 12271229                         if (lt == FLOAT)
 12281230                                 mkcall(p, "__fixsfdi");
 12291231                         else if (lt == DOUBLE)
 12301232                                 mkcall(p, "__fixdfdi");
 12311233                         break;
 12321234                 case ULONGLONG:
 12331235                         if (lt == FLOAT)
 12341236                                 mkcall(p, "__fixunssfdi");
 12351237                         else if (lt == DOUBLE)
 12361238                                 mkcall(p, "__fixunsdfdi");
 12371239                         break;
 12381240                 case FLOAT:
 12391241                         if (lt == LONGLONG)
 12401242                                 mkcall(p, "__floatdisf");
 12411243                         else if (lt == ULONGLONG) {
 12421244                                 p->n_left = mkunode(SCONV, p->n_left,0, DOUBLE);
 12431245                                 p->n_type = FLOAT;
 12441246                                 mkcall(p->n_left, "__floatundidf");
 12451247                         } else if (lt == UNSIGNED) {
 12461248                                 /* insert an extra double-to-float sconv */
 12471249                                 p->n_left = mkunode(SCONV, p->n_left,0, DOUBLE);
 12481250                         }
 12491251                         break;
 12501252                 case DOUBLE:
 12511253                         if (lt == LONGLONG)
 12521254                                 mkcall(p, "__floatdidf");
 12531255                         else if (lt == ULONGLONG)
 12541256                                 mkcall(p, "__floatundidf");
 12551257                         break;
 12561258                         
 12571259                 }
 12581260                 break;
 12591261         }
 12601262 }
 12611263 
 12621264 void
 12631265 myreader(struct interpass *ipole)
 12641266 {
 12651267         struct interpass *ip;
 12661268 
 12671269         DLIST_FOREACH(ip, ipole, qelem) {
 12681270                 if (ip->type != IP_NODE)
 12691271                         continue;
 12701272                 walkf(ip->ip_node, optim2, 0);
 12711273         }
 12721274 }
 12731275 
 12741276 void
 12751277 mycanon(NODE *p)
 12761278 {
 12771279 }
 12781280 
 12791281 void
 12801282 myoptim(struct interpass *ip)
 12811283 {
 12821284 }
 12831285 
 12841286 /*
 12851287  * Return argument size in regs.
 12861288  */
 12871289 static int
 12881290 argsiz(NODE *p)
 12891291 {
 12901292         TWORD t = p->n_type;
 12911293 
 12921294         if (t == STRTY || t == UNIONTY)
 12931295                 return p->n_stsize/(SZINT/SZCHAR);
 12941296         return szty(t);
 12951297 }
 12961298 
 12971299 /*
 12981300  * Last chance to do something before calling a function.
 12991301  */
 13001302 void
 13011303 lastcall(NODE *p)
 13021304 {
 13031305         NODE *op = p;
 13041306         int size = 0;
 13051307 
 13061308         /* Calculate argument sizes */
 13071309         p->n_qual = 0;
 13081310         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 13091311                 return;
 13101312         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 13111313                 size += argsiz(p->n_right);
 13121314         if (p->n_op != ASSIGN)
 13131315                 size += argsiz(p);
 13141316         op->n_qual = size; /* XXX */
 13151317 }
 13161318 
 13171319 /*
 13181320  * Return a class suitable for a specific type.
 13191321  */
 13201322 int
 13211323 gclass(TWORD t)
 13221324 {
 13231325         return (szty(t) == 2 ? CLASSB : CLASSA);
 13241326 }
 13251327 
 13261328 /*
 13271329  * For class c, find worst-case displacement of the number of
 13281330  * registers in the array r[] indexed by class.
 13291331  */
 13301332 int
 13311333 COLORMAP(int c, int *r)
 13321334 {
 13331335         int num;
 13341336         int a,b;
 13351337 
 13361338         a = r[CLASSA];
 13371339         b = r[CLASSB];
 13381340         switch (c) {
 13391341         case CLASSA:
 13401342                 /* there are 12 classa, so min 6 classb are needed to block */
 13411343                 num = b * 2;
 13421344                 num += a;
 13431345                 return num < 12;
 13441346         case CLASSB:
 13451347                 if (b > 3) return 0;
 13461348                 if (b > 2 && a) return 0;
 13471349                 if (b > 1 && a > 2) return 0;
 13481350                 if (b && a > 3) return 0;
 13491351                 if (a > 5) return 0;
 13501352                 return 1;
 13511353         }
 13521354         comperr("COLORMAP");
 13531355         return 0; /* XXX gcc */
 13541356 }
 13551357 
 13561358 /*
 13571359  * Special shapes.
 13581360  */
 13591361 int
 13601362 special(NODE *p, int shape)
 13611363 {
 13621364         return SRNOPE;
 13631365 }
 13641366 
 13651367 /*
 13661368  * Target-dependent command-line options.
 13671369  */
 13681370 void
 13691371 mflags(char *str)
 13701372 {
 13711373 }
 13721374 /*
 13731375  * Do something target-dependent for xasm arguments.
 13741376  * Supposed to find target-specific constraints and rewrite them.
 13751377  */
 13761378 int
 13771379 myxasm(struct interpass *ip, NODE *p)
 13781380 {
 13791381         return 0;
 13801382 }
 13811383 
 13821384 int
 13831385 xasmconstregs(char *s)
 13841386 {
 13851387         int i;
 13861388 
 13871389         for (i = 0; i < 16; i++)
 13881390                 if (strcmp(&rnames[i][1], s) == 0)
 13891391                         return i;
 13901392         return -1;
 13911393 }
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 00:20 +0100