Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.33
 
1.34
 
MAIN:ragge:20120901091746
 
local2.c
_>11 /*      $Id$    */
 22 /*
 33  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
 44  *
 55  * Redistribution and use in source and binary forms, with or without
 66  * modification, are permitted provided that the following conditions
 77  * are met:
 88  *
 99  * Redistributions of source code and documentation must retain the above
 1010  * copyright notice, this list of conditions and the following disclaimer.
 1111  * Redistributions in binary form must reproduce the above copyright
 1212  * notice, this list of conditionsand the following disclaimer in the
 1313  * documentation and/or other materials provided with the distribution.
 1414  * All advertising materials mentioning features or use of this software
 1515  * must display the following acknowledgement:
 1616  *      This product includes software developed or owned by Caldera
 1717  *      International, Inc.
 1818  * Neither the name of Caldera International, Inc. nor the names of other
 1919  * contributors may be used to endorse or promote products derived from
 2020  * this software without specific prior written permission.
 2121  *
 2222  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
 2323  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
 2424  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 2525  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 2626  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
 2727  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 2828  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 2929  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 3030  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
 3131  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 3232  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 3333  * POSSIBILITY OF SUCH DAMAGE.
 3434  */
 3535 
 3636 # include "pass2.h"
 3737 # include "ctype.h"
 3838 /* a lot of the machine dependent parts of the second pass */
 3939 
 4040 static void prtype(NODE *n);
 4141 static void acon(NODE *p);
 4242 
 4343 /*
 4444  * Print out the prolog assembler.
 4545  * addto and regoff are already calculated.
 4646  */
 4747 void
 4848 prologue(struct interpass_prolog *ipp)
 4949 {
 5050         printf("        .word 0x%llx\n", (unsigned long long)ipp->ipp_regs[0]);
 5151         if (p2maxautooff)
 5252                 printf("        subl2 $%d,%%sp\n", p2maxautooff);
 5353         if (pflag) {
 5454                 int i = getlab2();
 5555                 printf("\tmovab\t" LABFMT ",%%r0\n", i);
 5656                 printf("\tjsb\t__mcount\n");
 5757                 printf("\t.data\n");
 5858                 printf("\t.align  2\n");
 5959                 printf(LABFMT ":\t.long\t0\n", i);
 6060                 printf("\t.text\n");
 6161         }
 6262 }
 6363 
 6464 /*
 6565  * Called after all instructions in a function are emitted.
 6666  * Generates code for epilog here.
 6767  */
 6868 void
 6969 eoftn(struct interpass_prolog *ipp)
 7070 {
 7171         if (ipp->ipp_ip.ip_lbl == 0)
 7272                 return; /* no code needs to be generated */
 7373         printf("        ret\n");
 7474 }
 7575 
 7676 struct hoptab { int opmask; char * opstring; } ioptab[] = {
 7777 
 7878         { PLUS"add", },
 7979         { MINUS,        "sub", },
 8080         { MUL,  "mul", },
 8181         { DIV,  "div", },
 8282         { OR,   "bis", },
 8383         { ER,   "xor", },
 8484         { AND,  "bic", },
 8585         { -1, ""     },
 8686 };
 8787 
 8888 void
 8989 hopcode( f, o ){
 9090         /* output the appropriate string from the above table */
 9191 
 9292         register struct hoptab *q;
 9393 
 9494         for( q = ioptabq->opmask>=0; ++q ){
 9595                 if( q->opmask == o ){
 9696                         printf( "%s", q->opstring );
 9797 /* tbl
 9898                         if( f == 'F' ) printf( "e" );
 9999                         else if( f == 'D' ) printf( "d" );
 100100    tbl */
 101101 /* tbl */
 102102                         switch( f ) {
 103103                                 case 'L':
 104104                                 case 'W':
 105105                                 case 'B':
 106106                                 case 'D':
 107107                                 case 'F':
 108108                                         printf("%c", tolower(f));
 109109                                         break;
 110110 
 111111                                 }
 112112 /* tbl */
 113113                         return;
 114114                         }
 115115                 }
 116116         cerror( "no hoptab for %s", opst[o] );
 117117         }
 118118 
 119119 char *
 120120 rnames[] = {  /* keyed to register number tokens */
 121121 
 122122         "%r0", "%r1", "%r2", "%r3", "%r4", "%r5",
 123123         "%r6", "%r7", "%r8", "%r9", "%r10", "%r11",
 124124         "%ap", "%fp", "%sp", "%pc",
 125125         /* The concatenated regs has the name of the lowest */
 126126         "%r0", "%r1", "%r2", "%r3", "%r4", "%r5",
 127127         "%r6", "%r7", "%r8", "%r9", "%r10"
 128128         };
 129129 
 130130 int
 131131 tlen(NODE *p)
 132132 {
 133133         switch(p->n_type) {
 134134         case CHAR:
 135135         case UCHAR:
 136136                 return(1);
 137137 
 138138         case SHORT:
 139139         case USHORT:
 140140                 return(2);
 141141 
 142142         case DOUBLE:
 143143         case LONGLONG:
 144144         case ULONGLONG:
 145145                 return(8);
 146146 
 147147         default:
 148148                 return(4);
 149149         }
 150150 }
 151151 
 152152 void
 153153 prtype(NODE *n)
 154154 {
 155155         static char pt[] = { 0, 0, 'b', 'b', 'w', 'w', 'l', 'l', 0, 0,
 156156             'q', 'q', 'f', 'd' };
 157157         TWORD t = n->n_type;
 158158 
 159159         if (ISPTR(t))
 160160                 t = UNSIGNED;
 161161 
 162162         if (t > DOUBLE || pt[t] == 0)
 163163                 comperr("prtype: bad type");
 164164         putchar(pt[t]);
 165165 }
 166166 
 167167 /*
 168168  * Emit conversions as given by the following table. Dest is always reg,
 169169  *   if it should be something else let peephole optimizer deal with it.
 170170  *   This code ensures type correctness in 32-bit registers.
 171171  *   XXX is that necessary?
 172172  *
 173173  * From                         To
 174174  *       char   uchar  short  ushort int    uint   ll    ull   float double
 175175  * char  movb   movb   cvtbw  cvtbw  cvtbl  cvtbl  A     A     cvtbf cvtbd
 176176  * uchar movb   movb   movzbw movzbw movzbl movzbl B     B     G     G
 177177  * short movb   movb   movw   movw   cvtwl  cvtwl  C(A)  C(A)  cvtwf cvtwd
 178178  * ushrt movb   movb   movw   movw   movzwl movzwl D(B)  D(B)  H     H
 179179  * int   movb   movb   movw   movw   movl   movl   E     E     cvtlf cvtld
 180180  * uint  movb   movb   movw   movw   movl   movl   F     F     I     I
 181181  * ll    movb   movb   movw   movw   movl   movl   movq  movq  J     K
 182182  * ull   movb   movb   movw   movw   movl   movl   movq  movq  L     M
 183183  * float cvtfb  cvtfb  cvtfw  cvtfw  cvtfl  cvtfl  N     O     movf  cvtfd
 184184  * doubl cvtdb  cvtdb  cvtdw  cvtdw  cvtdl  cvtdl  P     Q     cvtdf movd
 185185  *
 186186  *  A: cvtbl + sign extend
 187187  *  B: movzbl + zero extend
 188188  *  G: movzbw + cvtwX
 189189  *  H: movzwl + cvtwX
 190190  *  I: cvtld + addX
 191191  *  J: call __floatdisf
 192192  *  K: call __floatdidf
 193193  *  L: xxx + call __floatdisf
 194194  *  M: xxx + call __floatdidf
 195195  *  N: call __fixsfdi
 196196  *  O: call __fixunssfdi
 197197  *  P: call __fixdfdi
 198198  *  Q: call __fixunsdfdi
 199199  */
 200200 
 201201 #define MVD     1 /* mov + dest type */
 202202 #define CVT     2 /* cvt + src type + dst type */
 203203 #define MVZ     3 /* movz + src type + dst type */
 204204 #define CSE     4 /* cvt + src type + l + sign extend upper */
 205205 #define MZE     5 /* movz + src type + l + zero extend upper */
 206206 #define MLE     6 /* movl + sign extend upper */
 207207 #define MLZ     7 /* movl + zero extend upper */
 208208 #define MZC     8 /* movz + cvt */
 209209 
 210210 static char scary[][10] = {
 211211         { MVD, MVD, CVT, CVT, CVT, CVT, CSE, CSE, CVT, CVT },
 212212         { MVD, MVD, MVZ, MVZ, MVZ, MVZ, MZE, MZE, MZC, MZC },
 213213         { MVD, MVD, MVD, MVD, CVT, CVT, CSE, CSE, CVT, CVT },
 214214         { MVD, MVD, MVD, MVD, MVZ, MVZ, MZE, MZE, MZC, MZC },
 215215         { MVD, MVD, MVD, MVD, MVD, MVD, MLE, MLE, CVT, CVT },
 216216         { MVD, MVD, MVD, MVD, MVD, MVD, MLZ, MLZ, 'I', 'I' },
 217217         { MVD, MVD, MVD, MVD, MVD, MVD, MVD, MVD, 'J', 'K' },
 218218         { MVD, MVD, MVD, MVD, MVD, MVD, MVD, MVD, 'L', 'M' },
 219219         { CVT, CVT, CVT, CVT, CVT, CVT, 'N', 'O', MVD, CVT },
 220220         { CVT, CVT, CVT, CVT, CVT, CVT, 'P', 'Q', CVT, MVD },
 221221 };
 222222 
 223223 static void
 224224 sconv(NODE *p)
 225225 {
 226226         NODE *l = p->n_left;
 227227         TWORD ts, td;
 228228         int o;
 229229 
 230230         /*
 231231          * Source node may be in register or memory.
 232232          * Result is always in register.
 233233          */
 234234         ts = l->n_type;
 235235         if (ISPTR(ts))
 236236                 ts = UNSIGNED;
 237237         td = p->n_type;
 238238         ts = ts < LONG ? ts-2 : ts-4;
 239239         td = td < LONG ? td-2 : td-4;
 240240 
 241241         o = scary[ts][td];
 242242         switch (o) {
 243243         case MLE:
 244244         case MLZ:
 245245                 expand(p, INAREG|INBREG, "\tmovl\tAL,A1\n");
 246246                 break;
 247247 
 248248         case MVD:
 249249                 if (l->n_op == REG && regno(l) == regno(getlr(p, '1')))
 250250                         break; /* unneccessary move */
 251251                 expand(p, INAREG|INBREG, "\tmovZR\tAL,A1\n");
 252252                 break;
 253253 
 254254         case CSE:
 255255                 expand(p, INAREG|INBREG, "\tcvtZLl\tAL,A1\n");
 256256                 break;
 257257 
 258258         case CVT:
 259259                 expand(p, INAREG|INBREG, "\tcvtZLZR\tAL,A1\n");
 260260                 break;
 261261 
 262262         case MZE:
 263263                 expand(p, INAREG|INBREG, "\tmovzZLl\tAL,A1\n");
 264264                 break;
 265265 
 266266         case MVZ:
 267267                 expand(p, INAREG|INBREG, "\tmovzZLZR\tAL,A1\n");
 268268                 break;
 269269 
 270270         case MZC:
 271271                 expand(p, INAREG|INBREG, "\tmovzZLl\tAL,A1\n");
 272272                 expand(p, INAREG|INBREG, "\tcvtlZR\tA1,A1\n");
 273273                 break;
 274274 
 275275         case 'I': /* unsigned to double */
 276276                 expand(p, INAREG|INBREG, "\tcvtld\tAL,A1\n");
 277277                 printf("\tjgeq\t1f\n");
 278278                 expand(p, INAREG|INBREG, "\taddd2\t$0d4.294967296e+9,A1\n");
 279279                 printf("1:\n");
 280280                 break;
 281281         default:
 282282                 comperr("unsupported conversion %d", o);
 283283         }
 284284         switch (o) {
 285285         case MLE:
 286286         case CSE:
 287287                 expand(p, INBREG, "\tashl\t$-31,A1,U1\n");
 288288                 break;
 289289         case MLZ:
 290290         case MZE:
 291291                 expand(p, INAREG|INBREG, "\tclrl\tU1\n");
 292292                 break;
 293293         }
 294294 }
 295295 
 296296 /*
 297297  * Assign a constant from p to q.  Both are expected to be leaves by now.
 298298  * This is for 64-bit integers.
 299299  */
 300300 static void
 301301 casg64(NODE *p)
 302302 {
 303303         NODE *l, *r;
 304304         char *str;
 305305         int mneg = 1;
 306306         
 307307         l = p->n_left;
 308308         r = p->n_right;
 309309 
 310310 #ifdef PCC_DEBUG
 311311         if (r->n_op != ICON)
 312312                 comperr("casg");
 313313 #endif
 314314         if (r->n_name[0] != '\0') {
 315315                 /* named constant, nothing to do */
 316316                 str = "movq\tAR,AL";
 317317                 mneg = 0;
 318318         } else if (r->n_lval == 0) {
 319319                 str = "clrq\tAL";
 320320                 mneg = 0;
 321321         } else if (r->n_lval < 0) {
 322322                 if (r->n_lval >= -63) {
 323323                         r->n_lval = -r->n_lval;
 324324                         str = "mnegl\tAR,AL";
 325325                 } else if (r->n_lval >= -128) {
 326326                         str = "cvtbl\tAR,AL";
 327327                 } else if (r->n_lval >= -32768) {
 328328                         str = "cvtwl\tAR,AL";
 329329                 } else if (r->n_lval >= -4294967296LL) {
 330330                         str = "movl\tAR,AL";
 331331                 } else {
 332332                         str = "movq\tAR,AL";
 333333                         mneg = 0;
 334334                 }
 335335         } else {
 336336                 mneg = 0;
 337337                 if (r->n_lval <= 63 || r->n_lval > 4294967295LL) {
 338338                         str = "movq\tAR,AL";
 339339                 } else if (r->n_lval <= 255) {
 340340                         str = "movzbl\tAR,AL\n\tclrl\tUL";
 341341                 } else if (r->n_lval <= 65535) {
 342342                         str = "movzwl\tAR,AL\n\tclrl\tUL";
 343343                 } else /* if (r->n_lval <= 4294967295) */ {
 344344                         str = "movl\tAR,AL\n\tclrl\tUL";
 345345                 }
 346346         }
 347347         expand(p, FOREFF, str);
 348348         if (mneg)
 349349                 expand(p, FOREFF, "\n\tmnegl $-1,UL");
 350350 }
 351351 
 352352 /*
 353353  * Assign a constant from p to q.  Both are expected to be leaves by now.
 354354  * This is only for 32-bit integer types.
 355355  */
 356356 static void
 357357 casg(NODE *p)
 358358 {
 359359         NODE *l, *r;
 360360         char *str;
 361361         
 362362         l = p->n_left;
 363363         r = p->n_right;
 364364 
 365365 #ifdef PCC_DEBUG
 366366         if (r->n_op != ICON)
 367367                 comperr("casg");
 368368 #endif
 369369         if (r->n_name[0] != '\0') {
 370370                 /* named constant, nothing to do */
 371371                 str = "movZL\tAR,AL";
 372372         } else if (r->n_lval == 0) {
 373373                 str = "clrZL\tAL";
 374374         } else if (r->n_lval < 0) {
 375375                 if (r->n_lval >= -63) {
 376376                         r->n_lval = -r->n_lval;
 377377                         str = "mnegZL\tAR,AL";
 378378                 } else if (r->n_lval >= -128) {
 379379                         if (l->n_type == CHAR)
 380380                                 str = "movb\tAR,AL";
 381381                         else
 382382                                 str = "cvtbZL\tAR,AL";
 383383                 } else if (r->n_lval >= -32768) {
 384384                         if (l->n_type == SHORT)
 385385                                 str = "movw\tAR,AL";
 386386                         else
 387387                                 str = "cvtwZL\tAR,AL";
 388388                 } else
 389389                         str = "movZL\tAR,AL";
 390390         } else {
 391391                 if (r->n_lval <= 63 || r->n_lval > 65535) {
 392392                         str = "movZL\tAR,AL";
 393393                 } else if (r->n_lval <= 255) {
 394394                         str = l->n_type < SHORT ?
 395395                             "movb\tAR,AL" : "movzbZL\tAR,AL";
 396396                 } else /* if (r->n_lval <= 65535) */ {
 397397                         str = l->n_type < INT ?
 398398                             "movw\tAR,AL" : "movzwZL\tAR,AL";
 399399                 }
 400400         }
 401401         expand(p, FOREFF, str);
 402402 }
 403403 
 404404 /*
 405405  * Emit code to compare two longlong numbers.
 406406  */
 407407 static void
 408408 twollcomp(NODE *p)
 409409 {
 410410         int u;
 411411         int s = getlab2();
 412412         int e = p->n_label;
 413413         int cb1, cb2;
 414414 
 415415         u = p->n_op;
 416416         switch (p->n_op) {
 417417         case NE:
 418418                 cb1 = 0;
 419419                 cb2 = NE;
 420420                 break;
 421421         case EQ:
 422422                 cb1 = NE;
 423423                 cb2 = 0;
 424424                 break;
 425425         case LE:
 426426         case LT:
 427427                 u += (ULE-LE);
 428428                 /* FALLTHROUGH */
 429429         case ULE:
 430430         case ULT:
 431431                 cb1 = GT;
 432432                 cb2 = LT;
 433433                 break;
 434434         case GE:
 435435         case GT:
 436436                 u += (ULE-LE);
 437437                 /* FALLTHROUGH */
 438438         case UGE:
 439439         case UGT:
 440440                 cb1 = LT;
 441441                 cb2 = GT;
 442442                 break;
 443443         
 444444         default:
 445445                 cb1 = cb2 = 0; /* XXX gcc */
 446446         }
 447447         if (p->n_op >= ULE)
 448448                 cb1 += 4, cb2 += 4;
 449449         expand(p, 0, "  cmpl UL,UR\n");
 450450         if (cb1) cbgen(cb1, s);
 451451         if (cb2) cbgen(cb2, e);
 452452         expand(p, 0, "  cmpl AL,AR\n");
 453453         cbgen(u, e);
 454454         deflab(s);
 455455 }
 456456 
 457457 
 458458 void
 459459 zzzcode(NODE *p, int c)
 460460 {
 461461         NODE *l, *r;
 462462         int m;
 463463         char *ch;
 464464 
 465465         switch (c) {
 466466         case 'N'/* logical ops, turned into 0-1 */
 467467                 /* use register given by register 1 */
 468468                 cbgen( 0, m=getlab2());
 469469                 deflab( p->n_label );
 470470                 printf( "       clrl    %s\n", rnames[getlr( p, '1' )->n_rval] );
 471471                 deflab( m );
 472472                 return;
 473473 
 474474         case 'A': /* Assign a constant directly to a memory position */
 475475                 printf("\t");
 476476                 if (p->n_type < LONG || ISPTR(p->n_type))
 477477                         casg(p);
 478478                 else
 479479                         casg64(p);
 480480                 printf("\n");
 481481                 break;
 482482 
 483483         case 'B': /* long long compare */
 484484                 twollcomp(p);
 485485                 break;
 486486 
 487487         case 'C':       /* num words pushed on arg stack */
 488488                 printf("$%d", p->n_qual);
 489489                 break;
 490490 
 491491         case 'D':       /* INCR and DECR */
 492492                 zzzcode(p->n_left, 'A');
 493493                 printf("\n      ");
 494494 
 495495 #if 0
 496496         case 'E':       /* INCR and DECR, FOREFF */
 497497                 if (p->n_right->n_lval == 1)
 498498                         {
 499499                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
 500500                         prtype(p->n_left);
 501501                         printf("        ");
 502502                         adrput(stdout, p->n_left);
 503503                         return;
 504504                         }
 505505                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
 506506                 prtype(p->n_left);
 507507                 printf("2       ");
 508508                 adrput(stdout, p->n_right);
 509509                 printf(",");
 510510                 adrput(p->n_left);
 511511                 return;
 512512 #endif
 513513 
 514514         case 'F':       /* register type of right operand */
 515515                 {
 516516                 register NODE *n;
 517517                 register int ty;
 518518 
 519519                 n = getlr( p, 'R' );
 520520                 ty = n->n_type;
 521521 
 522522                 if (x2debug) printf("->%d<-", ty);
 523523 
 524524                 if ( ty==DOUBLE) printf("d");
 525525                 else if ( ty==FLOAT ) printf("f");
 526526                 else printf("l");
 527527                 return;
 528528                 }
 529529 
 530530         case 'G': /* emit conversion instructions */
 531531                 sconv(p);
 532532                 break;
 533533 
 534534         case 'J': /* jump or ret? */
 535535                 {
 536536                         struct interpass *ip =
 537537                             DLIST_PREV((struct interpass *)p2env.epp, qelem);
 538538                         if (ip->type != IP_DEFLAB ||
 539539                             ip->ip_lbl != getlr(p, 'L')->n_lval)
 540540                                 expand(p, FOREFF, "jbr  LL");
 541541                         else
 542542                                 printf("ret");
 543543                 }
 544544                 break;
 545545 
 546546         case 'L':       /* type of left operand */
 547547         case 'R':       /* type of right operand */
 548548                 {
 549549                 register NODE *n;
 550550 
 551551                 n = getlr ( p, c);
 552552                 if (x2debug) printf("->%d<-", n->n_type);
 553553 
 554554                 prtype(n);
 555555                 return;
 556556                 }
 557557 
 558558         case 'O': /* print out emulated ops */
 559559                 expand(p, FOREFF, "\tmovq       AR,-(%sp)\n");
 560560                 expand(p, FOREFF, "\tmovq       AL,-(%sp)\n");
 561561                 if (p->n_op == DIV && p->n_type == ULONGLONG) ch = "udiv";
 562562                 else if (p->n_op == DIV) ch = "div";
 563563                 else if (p->n_op == MOD && p->n_type == ULONGLONG) ch = "umod";
 564564                 else if (p->n_op == MOD) ch = "mod";
 565565                 else if (p->n_op == MUL) ch = "mul";
 566566                 else ch = 0, comperr("ZO %d", p->n_op);
 567567                 printf("\tcalls $4,__%sdi3\n", ch);
 568568                 break;
 569569 
 570570 
 571571         case 'Z':       /* complement mask for bit instr */
 572572                 printf("$%Ld", ~p->n_right->n_lval);
 573573                 return;
 574574 
 575575         case 'U':       /* 32 - n, for unsigned right shifts */
 576576                 m = p->n_left->n_type == UCHAR ? 8 :
 577577                     p->n_left->n_type == USHORT ? 16 : 32;
 578578                 printf("$" CONFMT, m - p->n_right->n_lval);
 579579                 return;
 580580 
 581581         case 'T':       /* rounded structure length for arguments */
 582582                 {
 583583                 int size;
 584584 
 585585                 size = p->n_stsize;
 586586                 SETOFF( size, 4);
 587587                 printf("$%d", size);
 588588                 return;
 589589                 }
 590590 
 591591         case 'S'/* structure assignment */
 592592                 {
 593593                         register int size;
 594594 
 595595                         size = p->n_stsize;
 596596                         l = r = NULL; /* XXX gcc */
 597597                         if( p->n_op == STASG ){
 598598                                 l = p->n_left;
 599599                                 r = p->n_right;
 600600 
 601601                                 }
 602602                         else if( p->n_op == STARG ){
 603603                                 /* store an arg into a temporary */
 604604                                 printf("\tsubl2 $%d,%%sp\n",
 605605                                     size < 4 ? 4 : size);
 606606                                 l = mklnode(OREG, 0, SP, INT);
 607607                                 r = p->n_left;
 608608                                 }
 609609                         else cerror( "STASG bad" );
 610610 
 611611                         if( r->n_op == ICON ) r->n_op = NAME;
 612612                         else if( r->n_op == REG ) r->n_op = OREG;
 613613                         else if( r->n_op != OREG ) cerror( "STASG-r" );
 614614 
 615615                 if (size != 0) {
 616616                         if( size <= 0 || size > 65535 )
 617617                                 cerror("structure size <0=0 or >65535");
 618618 
 619619                         switch(size) {
 620620                                 case 1:
 621621                                         printf("        movb    ");
 622622                                         break;
 623623                                 case 2:
 624624                                         printf("        movw    ");
 625625                                         break;
 626626                                 case 4:
 627627                                         printf("        movl    ");
 628628                                         break;
 629629                                 case 8:
 630630                                         printf("        movq    ");
 631631                                         break;
 632632                                 default:
 633633                                         printf("        movc3   $%d,", size);
 634634                                         break;
 635635                         }
 636636                         adrput(stdout, r);
 637637                         printf(",");
 638638                         adrput(stdout, l);
 639639                         printf("\n");
 640640                 }
 641641 
 642642                         if( r->n_op == NAME ) r->n_op = ICON;
 643643                         else if( r->n_op == OREG ) r->n_op = REG;
 644644                         if (p->n_op == STARG)
 645645                                 tfree(l);
 646646 
 647647                         }
 648648                 break;
 649649 
 650650         default:
 651651                 comperr("illegal zzzcode '%c'", c);
 652652         }
 653653 }
 654654 
 655655 void
 656656 rmove(int rt, int rs, TWORD t)
 657657 {
 658658         printf( "       %s      %s,%s\n",
 659659                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 660660                 rnames[rt], rnames[rs] );
 661661 }
 662662 
 663663 int
 664664 rewfld(NODE *p)
 665665 {
 666666         return(1);
 667667 }
 668668 
 669669 #if 0
 670670 int
 671671 callreg(NODE *p)
 672672 {
 673673         return( R0 );
 674674 }
 675675 
 676676 int
 677677 base(register NODE *p)
 678678 {
 679679         register int o = p->op;
 680680 
 681681         if( (o==ICON && p->name[0] != '\0')) return( 100 ); /* ie no base reg */
 682682         if( o==REG ) return( p->rval );
 683683     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
 684684                 return( p->left->rval );
 685685     if( o==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 686686                 return( p->rval + 0200*1 );
 687687         if( o==INCR && p->left->op==REG ) return( p->left->rval + 0200*2 );
 688688         if( o==ASG MINUS && p->left->op==REG) return( p->left->rval + 0200*4 );
 689689         if( o==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
 690690           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 691691                 return( p->left->left->rval + 0200*(1+2) );
 692692         return( -1 );
 693693 }
 694694 
 695695 int
 696696 offset(register NODE *p, int tyl)
 697697 {
 698698 
 699699         if( tyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) return( p->rval );
 700700         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
 701701               (p->right->op==ICON && p->right->name[0]=='\0')
 702702               && (1<<p->right->lval)==tyl))
 703703                 return( p->left->rval );
 704704         return( -1 );
 705705 }
 706706 #endif
 707707 
 708708 #if 0
 709709 void
 710710 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 711711         register NODE *t;
 712712         NODE *f;
 713713 
 714714         p->n_op = OREG;
 715715         f = p->n_left;  /* have to free this subtree later */
 716716 
 717717         /* init base */
 718718         switch (q->n_op) {
 719719                 case ICON:
 720720                 case REG:
 721721                 case OREG:
 722722                         t = q;
 723723                         break;
 724724 
 725725                 case MINUS:
 726726                         q->n_right->n_lval = -q->n_right->n_lval;
 727727                 case PLUS:
 728728                         t = q->n_right;
 729729                         break;
 730730 
 731731                 case UMUL:
 732732                         t = q->n_left->n_left;
 733733                         break;
 734734 
 735735                 default:
 736736                         cerror("illegal makeor2");
 737737                         t = NULL; /* XXX gcc */
 738738         }
 739739 
 740740         p->n_lval = t->n_lval;
 741741         p->n_name = t->n_name;
 742742 
 743743         /* init offset */
 744744         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
 745745 
 746746         tfree(f);
 747747         return;
 748748         }
 749749 
 750750 int
 751751 canaddr( p ) NODE *p; {
 752752         register int o = p->n_op;
 753753 
 754754         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left, STARNM|SOREG)) ) return(1);
 755755         return(0);
 756756         }
 757757 
 758758 shltype( o, p ) register NODE *p; {
 759759         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 760760         }
 761761 #endif
 762762 
 763763 int
 764764 fldexpand(NODE *p, int cookie, char **cp)
 765765 {
 766766         return 0;
 767767 }
 768768 
 769769 int
 770770 flshape(register NODE *p)
 771771 {
 772772         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 773773                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 774774 }
 775775 
 776776 int
 777777 shtemp(register NODE *p)
 778778 {
 779779         if( p->n_op == STARG ) p = p->n_left;
 780780         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 781781 }
 782782 
 783783 /*
 784784  * Shape matches for UMUL.  Cooperates with offstar().
 785785  */
 786786 int
 787787 shumul(NODE *p, int shape)
 788788 {
 789789 
 790790         if (x2debug)
 791791                 printf("shumul(%p)\n", p);
 792792 
 793793         /* Turns currently anything into OREG on vax */
 794794         if (shape & SOREG)
 795795                 return SROREG;
 796796         return SRNOPE;
 797797 }
 798798 
 799799 
 800800 #ifdef notdef
 801801 int
 802802 shumul( p, shape ) register NODE *p; int shape; {
 803803         register int o;
 804804 
 805805         if (x2debug) {
 806806                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 807807                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 808808                 }
 809809 
 810810 
 811811         o = p->n_op;
 812812         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
 813813                 if (shape & STARNM)
 814814                         return SRDIR;
 815815 
 816816         if( ( o == INCR || o == ASG MINUS ) &&
 817817             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 818818             p->n_right->n_name[0] == '\0' )
 819819                 {
 820820                 switch (p->n_left->n_type)
 821821                         {
 822822                         case CHAR|PTR:
 823823                         case UCHAR|PTR:
 824824                                 o = 1;
 825825                                 break;
 826826 
 827827                         case SHORT|PTR:
 828828                         case USHORT|PTR:
 829829                                 o = 2;
 830830                                 break;
 831831 
 832832                         case INT|PTR:
 833833                         case UNSIGNED|PTR:
 834834                         case LONG|PTR:
 835835                         case ULONG|PTR:
 836836                         case FLOAT|PTR:
 837837                                 o = 4;
 838838                                 break;
 839839 
 840840                         case DOUBLE|PTR:
 841841                                 o = 8;
 842842                                 break;
 843843 
 844844                         default:
 845845                                 if ( ISPTR(p->n_left->n_type) ) {
 846846                                         o = 4;
 847847                                         break;
 848848                                         }
 849849                                 else return(0);
 850850                         }
 851851                 return( p->n_right->n_lval == o ? STARREG : 0);
 852852                 }
 853853 
 854854         return( SRNOPE );
 855855         }
 856856 #endif
 857857 
 858858 void
 859859 adrcon(CONSZ val)
 860860 {
 861861         printf( "$" );
 862862         printf( CONFMT, val );
 863863 }
 864864 
 865865 void
 866866 conput(FILE *fp, NODE *p)
 867867 {
 868868         switch( p->n_op ){
 869869 
 870870         case ICON:
 871871                 acon( p );
 872872                 return;
 873873 
 874874         case REG:
 875875                 printf( "%s", rnames[p->n_rval] );
 876876                 return;
 877877 
 878878         default:
 879879                 cerror( "illegal conput" );
 880880                 }
 881881         }
 882882 
 883883 void
 884884 insput(register NODE *p)
 885885 {
 886886         cerror( "insput" );
 887887 }
 888888 
 889889 /*
 890890  * Write out the upper address, like the upper register of a 2-register
 891891  * reference, or the next memory location.
 892892  */
 893893 void
 894894 upput(NODE *p, int size)
 895895 {
 896896 
 897897         size /= SZCHAR;
 898898         switch (p->n_op) {
 899899         case REG:
 900900                 fprintf(stdout, "%s", rnames[regno(p)-16+1]);
 901901                 break;
 902902 
 903903         case NAME:
<>904 -                comperr("upput NAME");
  904+                if (kflag)
  905+                        comperr("upput NAME");
905906         case OREG:
 906907                 p->n_lval += size;
 907908                 adrput(stdout, p);
 908909                 p->n_lval -= size;
 909910                 break;
 910911         case ICON:
 911912                 fprintf(stdout, "$" CONFMT, p->n_lval >> 32);
 912913                 break;
 913914         default:
 914915                 comperr("upput bad op %d size %d", p->n_op, size);
 915916         }
 916917 }
 917918 
 918919 void
 919920 adrput(FILE *fp, NODE *p)
 920921 {
 921922         register int r;
 922923         /* output an address, with offsets, from p */
 923924 
 924925         if( p->n_op == FLD ){
 925926                 p = p->n_left;
 926927                 }
 927928         switch( p->n_op ){
 928929 
 929930         case NAME:
 930931                 acon( p );
 931932                 return;
 932933 
 933934         case ICON:
 934935                 /* addressable value of the constant */
 935936                 if (p->n_name[0] == '\0') /* uses xxxab */
 936937                         printf("$");
 937938                 acon(p);
 938939                 return;
 939940 
 940941         case REG:
 941942                 printf( "%s", rnames[p->n_rval] );
 942943                 return;
 943944 
 944945         case OREG:
 945946                 r = p->n_rval;
 946947                 if( R2TEST(r) ){ /* double indexing */
 947948                         register int flags;
 948949 
 949950                         flags = R2UPK3(r);
 950951                         if( flags & 1 ) printf("*");
 951952                         if( flags & 4 ) printf("-");
 952953                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 953954                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 954955                         if( flags & 2 ) printf("+");
 955956                         printf( "[%s]", rnames[R2UPK2(r)] );
 956957                         return;
 957958                         }
 958959                 if( r == AP ){  /* in the argument region */
 959960                         if( p->n_lval <= 0 || p->n_name[0] != '\0' )
 960961                                 werror( "bad arg temp" );
 961962                         printf( CONFMT, p->n_lval );
 962963                         printf( "(%%ap)" );
 963964                         return;
 964965                         }
 965966                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 966967                 printf( "(%s)", rnames[p->n_rval] );
 967968                 return;
 968969 
 969970         case UMUL:
 970971                 /* STARNM or STARREG found */
 971972                 if( tshape(p, STARNM) ) {
 972973                         printf( "*" );
 973974                         adrput(0p->n_left);
 974975                         }
 975976                 else {  /* STARREG - really auto inc or dec */
 976977                         register NODE *q;
 977978 
 978979 /* tbl
 979980                         p = p->n_left;
 980981                         p->n_left->n_op = OREG;
 981982                         if( p->n_op == INCR ) {
 982983                                 adrput( p->n_left );
 983984                                 printf( "+" );
 984985                                 }
 985986                         else {
 986987                                 printf( "-" );
 987988                                 adrput( p->n_left );
 988989                                 }
 989990    tbl */
 990991 #ifdef notyet
 991992                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 992993                                 rnames[p->n_left->n_left->n_rval],
 993994                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 994995 #else
 995996                         printf("%c(%s)%c", '-',
 996997                                 rnames[p->n_left->n_left->n_rval],
 997998                                 '\0' );
 998999 #endif
 9991000                         p->n_op = OREG;
 10001001                         p->n_rval = p->n_left->n_left->n_rval;
 10011002                         q = p->n_left;
 10021003 #ifdef notyet
 10031004 
 10041005                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 10051006 #else
 10061007                         p->n_lval = 0;
 10071008 #endif
 10081009                         p->n_name[0] = '\0';
 10091010                         tfree(q);
 10101011                 }
 10111012                 return;
 10121013 
 10131014         default:
 10141015                 cerror( "illegal address" );
 10151016                 return;
 10161017         }
 10171018 
 10181019 }
 10191020 
 10201021 /*
 10211022  * print out a constant
 10221023  */
 10231024 void
 10241025 acon(NODE *p)
 10251026 {
 10261027 
 10271028         if (p->n_name[0] == '\0') {
 10281029                 printf(CONFMT, p->n_lval);
 10291030         } else if( p->n_lval == 0 ) {
 10301031                 printf("%s", p->n_name);
 10311032         } else {
 10321033                 printf("%s+", p->n_name);
 10331034                 printf(CONFMT, p->n_lval);
 10341035         }
 10351036 }
 10361037 
 10371038 #if 0
 10381039 genscall( p, cookie ) register NODE *p; {
 10391040         /* structure valued call */
 10401041         return( gencall( p, cookie ) );
 10411042         }
 10421043 
 10431044 /* tbl */
 10441045 int gc_numbytes;
 10451046 /* tbl */
 10461047 
 10471048 gencall( p, cookie ) register NODE *p; {
 10481049         /* generate the call given by p */
 10491050         register NODE *p1, *ptemp;
 10501051         register temp, temp1;
 10511052         register m;
 10521053 
 10531054         if( p->right ) temp = argsize( p->right );
 10541055         else temp = 0;
 10551056 
 10561057         if( p->op == STCALL || p->op == UNARY STCALL ){
 10571058                 /* set aside room for structure return */
 10581059 
 10591060                 if( p->stsize > temp ) temp1 = p->stsize;
 10601061                 else temp1 = temp;
 10611062                 }
 10621063 
 10631064         if( temp > maxargs ) maxargs = temp;
 10641065         SETOFF(temp1,4);
 10651066 
 10661067         if( p->right ){ /* make temp node, put offset in, and generate args */
 10671068                 ptemp = talloc();
 10681069                 ptemp->op = OREG;
 10691070                 ptemp->lval = -1;
 10701071                 ptemp->rval = SP;
 10711072                 ptemp->name[0] = '\0';
 10721073                 ptemp->rall = NOPREF;
 10731074                 ptemp->su = 0;
 10741075                 genargs( p->right, ptemp );
 10751076                 nfree(ptemp);
 10761077                 }
 10771078 
 10781079         p1 = p->left;
 10791080         if( p1->op != ICON ){
 10801081                 if( p1->op != REG ){
 10811082                         if( p1->op != OREG || R2TEST(p1->rval) ){
 10821083                                 if( p1->op != NAME ){
 10831084                                         order( p1, INAREG );
 10841085                                         }
 10851086                                 }
 10861087                         }
 10871088                 }
 10881089 
 10891090 /*
 10901091         if( p1->op == REG && p->rval == R5 ){
 10911092                 cerror( "call register overwrite" );
 10921093                 }
 10931094  */
 10941095 /* tbl
 10951096         setup gc_numbytes so reference to ZC works */
 10961097 
 10971098         gc_numbytes = temp;
 10981099 /* tbl */
 10991100 
 11001101         p->op = UNARY CALL;
 11011102         m = match( p, INTAREG|INTBREG );
 11021103 /* tbl
 11031104         switch( temp ) {
 11041105         case 0:
 11051106                 break;
 11061107         case 2:
 11071108                 printf( "       tst     (%sp)+\n" );
 11081109                 break;
 11091110         case 4:
 11101111                 printf( "       cmp     (%sp)+,(%sp)+\n" );
 11111112                 break;
 11121113         default:
 11131114                 printf( "       add     $%d,%sp\n", temp);
 11141115                 }
 11151116    tbl */
 11161117         return(m != MDONE);
 11171118         }
 11181119 #endif
 11191120 
 11201121 static char *
 11211122 ccbranches[] = {
 11221123         "jeql",
 11231124         "jneq",
 11241125         "jleq",
 11251126         "jlss",
 11261127         "jgeq",
 11271128         "jgtr",
 11281129         "jlequ",
 11291130         "jlssu",
 11301131         "jgequ",
 11311132         "jgtru",
 11321133 };
 11331134 
 11341135 /*
 11351136  * printf conditional and unconditional branches
 11361137  */
 11371138 void
 11381139 cbgen(int o, int lab)
 11391140 {
 11401141 
 11411142         if (o == 0) {
 11421143                 printf("        jbr     " LABFMT "\n", lab);
 11431144         } else {
 11441145                 if (o > UGT)
 11451146                         comperr("bad conditional branch: %s", opst[o]);
 11461147                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 11471148         }
 11481149 }
 11491150 
 11501151 static void
 11511152 mkcall(NODE *p, char *name)
 11521153 {
 11531154         p->n_op = CALL;
 11541155         p->n_right = mkunode(FUNARG, p->n_left, 0, p->n_left->n_type);
 11551156         p->n_left = mklnode(ICON, 0, 0, FTN|p->n_type);
 11561157         p->n_left->n_name = name;
 11571158 }
 11581159 
 11591160 /* do local tree transformations and optimizations */
 11601161 static void
 11611162 optim2(NODE *p, void *arg)
 11621163 {
 11631164         NODE *r, *s;
 11641165         TWORD lt;
 11651166 
 11661167         switch (p->n_op) {
 11671168         case MOD:
 11681169                 if (p->n_type == USHORT || p->n_type == UCHAR) {
 11691170                         r = mkunode(SCONV, p->n_left, 0, UNSIGNED);
 11701171                         r = mkunode(FUNARG, r, 0, UNSIGNED);
 11711172                         s = mkunode(SCONV, p->n_right, 0, UNSIGNED);
 11721173                         s = mkunode(FUNARG, s, 0, UNSIGNED);
 11731174                         r = mkbinode(CM, r, s, INT);
 11741175                         s = mklnode(ICON, 0, 0, FTN|UNSIGNED);
 11751176                         s->n_name = "__urem";
 11761177                         p->n_left = mkbinode(CALL, s, r, UNSIGNED);
 11771178                         p->n_op = SCONV;
 11781179                 } else if (p->n_type == UNSIGNED) {
 11791180                         p->n_left = mkunode(FUNARG, p->n_left, 0, UNSIGNED);
 11801181                         p->n_right = mkunode(FUNARG, p->n_right, 0, UNSIGNED);
 11811182                         p->n_right = mkbinode(CM, p->n_left, p->n_right, INT);
 11821183                         p->n_left = mklnode(ICON, 0, 0, FTN|UNSIGNED);
 11831184                         p->n_left->n_name = "__urem";
 11841185                         p->n_op = CALL;
 11851186                 }
 11861187                 break;
 11871188 
 11881189         case RS:
 11891190                 if (p->n_type == ULONGLONG) {
 11901191                         p->n_right = mkbinode(CM,
 11911192                             mkunode(FUNARG, p->n_left, 0, p->n_left->n_type),
 11921193                             mkunode(FUNARG, p->n_right, 0, p->n_right->n_type),
 11931194                             INT);
 11941195                         p->n_left = mklnode(ICON, 0, 0, FTN|p->n_type);
 11951196                         p->n_left->n_name = "__lshrdi3";
 11961197                         p->n_op = CALL;
 11971198                 } else if (p->n_type == INT) {
 11981199                         /* convert >> to << with negative shift count */
 11991200                         /* RS of char & short must use extv */
 12001201                         if (p->n_right->n_op == ICON) {
 12011202                                 p->n_right->n_lval = -p->n_right->n_lval;
 12021203                         } else if (p->n_right->n_op == UMINUS) {
 12031204                                 r = p->n_right->n_left;
 12041205                                 nfree(p->n_right);
 12051206                                 p->n_right = r;
 12061207                         } else {
 12071208                                 p->n_right = mkunode(UMINUS, p->n_right,
 12081209                                     0, p->n_right->n_type);
 12091210                         }
 12101211                         p->n_op = LS;
 12111212                 }
 12121213                 break;
 12131214 
 12141215         case AND:
 12151216                 /* commute L and R to eliminate compliments and constants */
 12161217                 if ((p->n_left->n_op == ICON && p->n_left->n_name[0] == 0) ||
 12171218                     p->n_left->n_op==COMPL) {
 12181219                         r = p->n_left;
 12191220                         p->n_left = p->n_right;
 12201221                         p->n_right = r;
 12211222                 }
 12221223                 /* change meaning of AND to ~R&L - bic on pdp11 */
 12231224                 r = p->n_right;
 12241225                 if (r->n_op == ICON && r->n_name[0] == 0) {
 12251226                         /* compliment constant */
 12261227                         r->n_lval = ~r->n_lval;
 12271228                 } else if (r->n_op == COMPL) { /* ~~A => A */
 12281229                         s = r->n_left;
 12291230                         nfree(r);
 12301231                         p->n_right = s;
 12311232                 } else { /* insert complement node */
 12321233                         p->n_right = mkunode(COMPL, r, 0, r->n_type);
 12331234                 }
 12341235                 break;
 12351236         case SCONV:
 12361237                 lt = p->n_left->n_type;
 12371238                 switch (p->n_type) {
 12381239                 case LONGLONG:
 12391240                         if (lt == FLOAT)
 12401241                                 mkcall(p, "__fixsfdi");
 12411242                         else if (lt == DOUBLE)
 12421243                                 mkcall(p, "__fixdfdi");
 12431244                         break;
 12441245                 case ULONGLONG:
 12451246                         if (lt == FLOAT)
 12461247                                 mkcall(p, "__fixunssfdi");
 12471248                         else if (lt == DOUBLE)
 12481249                                 mkcall(p, "__fixunsdfdi");
 12491250                         break;
 12501251                 case FLOAT:
 12511252                         if (lt == LONGLONG)
 12521253                                 mkcall(p, "__floatdisf");
 12531254                         else if (lt == ULONGLONG) {
 12541255                                 p->n_left = mkunode(SCONV, p->n_left,0, DOUBLE);
 12551256                                 p->n_type = FLOAT;
 12561257                                 mkcall(p->n_left, "__floatundidf");
 12571258                         } else if (lt == UNSIGNED) {
 12581259                                 /* insert an extra double-to-float sconv */
 12591260                                 p->n_left = mkunode(SCONV, p->n_left,0, DOUBLE);
 12601261                         }
 12611262                         break;
 12621263                 case DOUBLE:
 12631264                         if (lt == LONGLONG)
 12641265                                 mkcall(p, "__floatdidf");
 12651266                         else if (lt == ULONGLONG)
 12661267                                 mkcall(p, "__floatundidf");
 12671268                         break;
 12681269                         
 12691270                 }
 12701271                 break;
 12711272         }
 12721273 }
 12731274 
 12741275 static void
 12751276 aofname(NODE *p, void *arg)
 12761277 {
 12771278         int o = optype(p->n_op);
 12781279         TWORD t;
 12791280 
 12801281         if (o == LTYPE || p->n_op == ADDROF)
 12811282                 return;
 12821283         t = p->n_left->n_type;
 12831284         if (p->n_left->n_op == NAME && ISLONGLONG(t))
 12841285                 p->n_left = mkunode(UMUL,
 12851286                     mkunode(ADDROF, p->n_left, 0, INCREF(t)), 0, t);
 12861287         if (o == BITYPE && p->n_right->n_op == NAME &&
 12871288             ISLONGLONG(p->n_right->n_type)) {
 12881289                 t = p->n_right->n_type;
 12891290                 p->n_right = mkunode(UMUL,
 12901291                     mkunode(ADDROF, p->n_right, 0, INCREF(t)), 0, t);
 12911292         }
 12921293 }
 12931294 
 12941295 void
 12951296 myreader(struct interpass *ipole)
 12961297 {
 12971298         struct interpass *ip;
 12981299 
 12991300         DLIST_FOREACH(ip, ipole, qelem) {
 13001301                 if (ip->type != IP_NODE)
 13011302                         continue;
 13021303                 if (kflag)
 13031304                         walkf(ip->ip_node, aofname, 0);
 13041305                 walkf(ip->ip_node, optim2, 0);
 13051306         }
 13061307 }
 13071308 
 13081309 void
 13091310 mycanon(NODE *p)
 13101311 {
 13111312 }
 13121313 
 13131314 void
 13141315 myoptim(struct interpass *ip)
 13151316 {
 13161317 }
 13171318 
 13181319 /*
 13191320  * Return argument size in regs.
 13201321  */
 13211322 static int
 13221323 argsiz(NODE *p)
 13231324 {
 13241325         TWORD t = p->n_type;
 13251326 
 13261327         if (t == STRTY || t == UNIONTY)
 13271328                 return p->n_stsize/(SZINT/SZCHAR);
 13281329         return szty(t);
 13291330 }
 13301331 
 13311332 /*
 13321333  * Last chance to do something before calling a function.
 13331334  */
 13341335 void
 13351336 lastcall(NODE *p)
 13361337 {
 13371338         NODE *op = p;
 13381339         int size = 0;
 13391340 
 13401341         /* Calculate argument sizes */
 13411342         p->n_qual = 0;
 13421343         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 13431344                 return;
 13441345         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 13451346                 size += argsiz(p->n_right);
 13461347         if (p->n_op != ASSIGN)
 13471348                 size += argsiz(p);
 13481349         op->n_qual = size; /* XXX */
 13491350 }
 13501351 
 13511352 /*
 13521353  * Return a class suitable for a specific type.
 13531354  */
 13541355 int
 13551356 gclass(TWORD t)
 13561357 {
 13571358         return (szty(t) == 2 ? CLASSB : CLASSA);
 13581359 }
 13591360 
 13601361 /*
 13611362  * For class c, find worst-case displacement of the number of
 13621363  * registers in the array r[] indexed by class.
 13631364  */
 13641365 int
 13651366 COLORMAP(int c, int *r)
 13661367 {
 13671368         int num;
 13681369         int a,b;
 13691370 
 13701371         a = r[CLASSA];
 13711372         b = r[CLASSB];
 13721373         switch (c) {
 13731374         case CLASSA:
 13741375                 /* there are 12 classa, so min 6 classb are needed to block */
 13751376                 num = b * 2;
 13761377                 num += a;
 13771378                 return num < 12;
 13781379         case CLASSB:
 13791380                 if (b > 3) return 0;
 13801381                 if (b > 2 && a) return 0;
 13811382                 if (b > 1 && a > 2) return 0;
 13821383                 if (b && a > 3) return 0;
 13831384                 if (a > 5) return 0;
 13841385                 return 1;
 13851386         }
 13861387         comperr("COLORMAP");
 13871388         return 0; /* XXX gcc */
 13881389 }
 13891390 
 13901391 /*
 13911392  * Special shapes.
 13921393  */
 13931394 int
 13941395 special(NODE *p, int shape)
 13951396 {
 13961397         return SRNOPE;
 13971398 }
 13981399 
 13991400 /*
 14001401  * Target-dependent command-line options.
 14011402  */
 14021403 void
 14031404 mflags(char *str)
 14041405 {
 14051406 }
 14061407 /*
 14071408  * Do something target-dependent for xasm arguments.
 14081409  * Supposed to find target-specific constraints and rewrite them.
 14091410  */
 14101411 int
 14111412 myxasm(struct interpass *ip, NODE *p)
 14121413 {
<> 1414+        char *c;
  1415+        int i;
  1416+
  1417+        /* Discard o<> constraints since they will not be generated */
  1418+        for (c = p->n_name; *c; c++) {
  1419+                if (*c == 'o' || *c == '<' || *c == '>') {
  1420+                        for (i = 0; c[i]; i++)
  1421+                                c[i] = c[i+1];
  1422+                        c--;
  1423+                }
  1424+        }
<_14131425         return 0;
 14141426 }
 14151427 
 14161428 int
 14171429 xasmconstregs(char *s)
 14181430 {
 14191431         int i;
 14201432 
 14211433         for (i = 0; i < 16; i++)
 14221434                 if (strcmp(&rnames[i][1], s) == 0)
 14231435                         return i;
 14241436         return -1;
 14251437 }
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-20 11:55 +0200