Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.15
 
1.16
 
MAIN:ragge:20110628093331
 
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 {
<>50 -        printf("        .word 0x%x\n", ipp->ipp_regs[0]);
  50+        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(p) 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 LDOUBLE:
 135135                 case LONGLONG:
 136136                 case ULONGLONG:
 137137                         return(8);
 138138 
 139139                 default:
 140140                         return(4);
 141141                 }
 142142 }
 143143 
 144144 static int
 145145 mixtypes(NODE *p, NODE *q)
 146146 {
 147147         TWORD tp, tq;
 148148 
 149149         tp = p->n_type;
 150150         tq = q->n_type;
 151151 
 152152         return( (tp==FLOAT || tp==DOUBLE) !=
 153153                 (tq==FLOAT || tq==DOUBLE) );
 154154 }
 155155 
 156156 void
 157157 prtype(NODE *n)
 158158 {
 159159         switch (n->n_type)
 160160                 {
 161161                 case DOUBLE:
 162162                         printf("d");
 163163                         return;
 164164 
 165165                 case FLOAT:
 166166                         printf("f");
 167167                         return;
 168168 
 169169                 case LONG:
 170170                 case ULONG:
 171171                 case INT:
 172172                 case UNSIGNED:
 173173                         printf("l");
 174174                         return;
 175175 
 176176                 case SHORT:
 177177                 case USHORT:
 178178                         printf("w");
 179179                         return;
 180180 
 181181                 case CHAR:
 182182                 case UCHAR:
 183183                         printf("b");
 184184                         return;
 185185 
 186186                 default:
 187187                         if ( !ISPTR( n->n_type ) ) cerror("zzzcode- bad type");
 188188                         else {
 189189                                 printf("l");
 190190                                 return;
 191191                                 }
 192192                 }
 193193 }
 194194 
<> 195+/*
  196+ * Emit code to compare two longlong numbers.
  197+ */
  198+static void
  199+twollcomp(NODE *p)
  200+{
  201+        int u;
  202+        int s = getlab2();
  203+        int e = p->n_label;
  204+        int cb1, cb2;
  205+
  206+        u = p->n_op;
  207+        switch (p->n_op) {
  208+        case NE:
  209+                cb1 = 0;
  210+                cb2 = NE;
  211+                break;
  212+        case EQ:
  213+                cb1 = NE;
  214+                cb2 = 0;
  215+                break;
  216+        case LE:
  217+        case LT:
  218+                u += (ULE-LE);
  219+                /* FALLTHROUGH */
  220+        case ULE:
  221+        case ULT:
  222+                cb1 = GT;
  223+                cb2 = LT;
  224+                break;
  225+        case GE:
  226+        case GT:
  227+                u += (ULE-LE);
  228+                /* FALLTHROUGH */
  229+        case UGE:
  230+        case UGT:
  231+                cb1 = LT;
  232+                cb2 = GT;
  233+                break;
  234+        
  235+        default:
  236+                cb1 = cb2 = 0; /* XXX gcc */
  237+        }
  238+        if (p->n_op >= ULE)
  239+                cb1 += 4, cb2 += 4;
  240+        expand(p, 0, "  cmpl UR,UL\n");
  241+        if (cb1) cbgen(cb1, s);
  242+        if (cb2) cbgen(cb2, e);
  243+        expand(p, 0, "  cmpl AL,AR\n");
  244+        cbgen(u, e);
  245+        deflab(s);
  246+}
  247+
  248+
195249 void
 196250 zzzcode( p, c ) register NODE *p; {
 197251         int m;
 198252         int val;
 199253         switch( c ){
 200254 
 201255         case 'N'/* logical ops, turned into 0-1 */
 202256                 /* use register given by register 1 */
 203257                 cbgen( 0, m=getlab2());
 204258                 deflab( p->n_label );
 205259                 printf( "       clrl    %s\n", rnames[getlr( p, '1' )->n_rval] );
 206260                 deflab( m );
 207261                 return;
 208262 
 209263         case 'A':
 210264                 {
 211265                 register NODE *l, *r;
 212266 
 213267                 if (xdebug) e2print(p, 0, &val, &val);
 214268                 r = getlr(p, 'R');
 215269                 if (optype(p->n_op) == LTYPE || p->n_op == UMUL) {
 216270                         l = resc;
 217271                         l->n_type = (r->n_type==FLOAT || r->n_type==DOUBLE ? DOUBLE : INT);
 218272                 } else
 219273                         l = getlr(p, 'L');
 220274                 if (r->n_op == ICON  && r->n_name[0] == '\0') {
 221275                         if (r->n_lval == 0) {
 222276                                 printf("clr");
 223277                                 prtype(l);
 224278                                 printf("        ");
 225279                                 adrput(stdout, l);
 226280                                 return;
 227281                         }
 228282                         if (r->n_lval < 0 && r->n_lval >= -63) {
 229283                                 printf("mneg");
 230284                                 prtype(l);
 231285                                 r->n_lval = -r->n_lval;
 232286                                 goto ops;
 233287                         }
 234288                         r->n_type = (r->n_lval < 0 ?
 235289                                         (r->n_lval >= -128 ? CHAR
 236290                                         : (r->n_lval >= -32768 ? SHORT
 237291                                         : INT )) : r->n_type);
 238292                         r->n_type = (r->n_lval >= 0 ?
 239293                                         (r->n_lval <= 63 ? INT
 240294                                         : ( r->n_lval <= 127 ? CHAR
 241295                                         : (r->n_lval <= 255 ? UCHAR
 242296                                         : (r->n_lval <= 32767 ? SHORT
 243297                                         : (r->n_lval <= 65535 ? USHORT
 244298                                         : INT ))))) : r->n_type );
 245299                         }
 246300                 if (l->n_op == REG && l->n_type != FLOAT && l->n_type != DOUBLE)
 247301                         l->n_type = INT;
 248302                 if (!mixtypes(l,r))
 249303                         {
 250304                         if (tlen(l) == tlen(r))
 251305                                 {
 252306                                 printf("mov");
 253307                                 prtype(l);
 254308                                 goto ops;
 255309                                 }
 256310                         else if (tlen(l) > tlen(r) && ISUNSIGNED(r->n_type))
 257311                                 {
 258312                                 printf("movz");
 259313                                 }
 260314                         else
 261315                                 {
 262316                                 printf("cvt");
 263317                                 }
 264318                         }
 265319                 else
 266320                         {
 267321                         printf("cvt");
 268322                         }
 269323                 prtype(r);
 270324                 prtype(l);
 271325         ops:
 272326                 printf("        ");
 273327                 adrput(stdout, r);
 274328                 printf(",");
 275329                 adrput(stdout, l);
 276330                 return;
 277331                 }
 278332 
<> 333+        case 'B': /* long long compare */
  334+                twollcomp(p);
  335+                break;
  336+
279337         case 'C':       /* num words pushed on arg stack */
 280338                 printf("$%d", p->n_qual);
 281339                 break;
 282340 
 283341         case 'D':       /* INCR and DECR */
 284342                 zzzcode(p->n_left, 'A');
 285343                 printf("\n      ");
 286344 
 287345 #if 0
 288346         case 'E':       /* INCR and DECR, FOREFF */
 289347                 if (p->n_right->n_lval == 1)
 290348                         {
 291349                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
 292350                         prtype(p->n_left);
 293351                         printf("        ");
 294352                         adrput(stdout, p->n_left);
 295353                         return;
 296354                         }
 297355                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
 298356                 prtype(p->n_left);
 299357                 printf("2       ");
 300358                 adrput(stdout, p->n_right);
 301359                 printf(",");
 302360                 adrput(p->n_left);
 303361                 return;
 304362 #endif
 305363 
 306364         case 'F':       /* register type of right operand */
 307365                 {
 308366                 register NODE *n;
 309367                 extern int xdebug;
 310368                 register int ty;
 311369 
 312370                 n = getlr( p, 'R' );
 313371                 ty = n->n_type;
 314372 
 315373                 if (xdebug) printf("->%d<-", ty);
 316374 
 317375                 if ( ty==DOUBLE) printf("d");
 318376                 else if ( ty==FLOAT ) printf("f");
 319377                 else printf("l");
 320378                 return;
 321379                 }
 322380 
 323381         case 'J': /* jump or ret? */
 324382                 {
 325383                         struct interpass *ip =
 326384                             DLIST_PREV((struct interpass *)p2env.epp, qelem);
 327385                         if (ip->type != IP_DEFLAB ||
 328386                             ip->ip_lbl != getlr(p, 'L')->n_lval)
 329387                                 expand(p, FOREFF, "jbr  LL");
 330388                         else
 331389                                 printf("ret");
 332390                 }
 333391                 break;
 334392 
 335393         case 'L':       /* type of left operand */
 336394         case 'R':       /* type of right operand */
 337395                 {
 338396                 register NODE *n;
 339397                 extern int xdebug;
 340398 
 341399                 n = getlr ( p, c);
 342400                 if (xdebug) printf("->%d<-", n->n_type);
 343401 
 344402                 prtype(n);
 345403                 return;
 346404                 }
 347405 
 348406         case 'Z':       /* complement mask for bit instr */
 349407                 printf("$%Ld", ~p->n_right->n_lval);
 350408                 return;
 351409 
 352410         case 'U':       /* 32 - n, for unsigned right shifts */
 353411                 printf("$" CONFMT, 32 - p->n_right->n_lval );
 354412                 return;
 355413 
 356414         case 'T':       /* rounded structure length for arguments */
 357415                 {
 358416                 int size;
 359417 
 360418                 size = p->n_stsize;
 361419                 SETOFF( size, 4);
 362420                 printf("$%d", size);
 363421                 return;
 364422                 }
 365423 
 366424         case 'S'/* structure assignment */
 367425                 {
 368426                         register NODE *l, *r;
 369427                         register int size;
 370428 
 371429                         size = p->n_stsize;
 372430                         l = r = NULL; /* XXX gcc */
 373431                         if( p->n_op == STASG ){
 374432                                 l = p->n_left;
 375433                                 r = p->n_right;
 376434 
 377435                                 }
 378436                         else if( p->n_op == STARG ){
 379437                                 /* store an arg into a temporary */
 380438                                 printf("\tsubl2 $%d,%%sp\n",
 381439                                     size < 4 ? 4 : size);
 382440                                 l = mklnode(OREG, 0, SP, INT);
 383441                                 r = p->n_left;
 384442                                 }
 385443                         else cerror( "STASG bad" );
 386444 
 387445                         if( r->n_op == ICON ) r->n_op = NAME;
 388446                         else if( r->n_op == REG ) r->n_op = OREG;
 389447                         else if( r->n_op != OREG ) cerror( "STASG-r" );
 390448 
 391449                         if( size <= 0 || size > 65535 )
 392450                                 cerror("structure size <0=0 or >65535");
 393451 
 394452                         switch(size) {
 395453                                 case 1:
 396454                                         printf("        movb    ");
 397455                                         break;
 398456                                 case 2:
 399457                                         printf("        movw    ");
 400458                                         break;
 401459                                 case 4:
 402460                                         printf("        movl    ");
 403461                                         break;
 404462                                 case 8:
 405463                                         printf("        movq    ");
 406464                                         break;
 407465                                 default:
 408466                                         printf("        movc3   $%d,", size);
 409467                                         break;
 410468                         }
 411469                         adrput(stdout, r);
 412470                         printf(",");
 413471                         adrput(stdout, l);
 414472                         printf("\n");
 415473 
 416474                         if( r->n_op == NAME ) r->n_op = ICON;
 417475                         else if( r->n_op == OREG ) r->n_op = REG;
 418476                         if (p->n_op == STARG)
 419477                                 tfree(l);
 420478 
 421479                         }
 422480                 break;
 423481 
 424482         default:
 425483                 comperr("illegal zzzcode '%c'", c);
 426484                 }
 427485         }
 428486 
 429487 void
 430488 rmove( int rt,int  rs, TWORD t ){
 431489         printf( "       %s      %s,%s\n",
 432490                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 433491                 rnames[rs], rnames[rt] );
 434492         }
 435493 
 436494 #if 0
 437495 setregs(){ /* set up temporary registers */
 438496         fregs = 6;      /* tbl- 6 free regs on VAX (0-5) */
 439497         ;
 440498         }
 441499 
 442500 szty(t){ /* size, in registers, needed to hold thing of type t */
 443501         return( (t==DOUBLE||t==FLOAT) ? 2 : 1 );
 444502         }
 445503 #endif
 446504 
 447505 int
 448506 rewfld( p ) NODE *p; {
 449507         return(1);
 450508         }
 451509 
 452510 #if 0
 453511 callreg(p) NODE *p; {
 454512         return( R0 );
 455513         }
 456514 
 457515 base( p ) register NODE *p; {
 458516         register int o = p->op;
 459517 
 460518         if( (o==ICON && p->name[0] != '\0')) return( 100 ); /* ie no base reg */
 461519         if( o==REG ) return( p->rval );
 462520     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
 463521                 return( p->left->rval );
 464522     if( o==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 465523                 return( p->rval + 0200*1 );
 466524         if( o==INCR && p->left->op==REG ) return( p->left->rval + 0200*2 );
 467525         if( o==ASG MINUS && p->left->op==REG) return( p->left->rval + 0200*4 );
 468526         if( o==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
 469527           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 470528                 return( p->left->left->rval + 0200*(1+2) );
 471529         return( -1 );
 472530         }
 473531 
 474532 offset( p, tyl ) register NODE *p; int tyl; {
 475533 
 476534         if( tyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) return( p->rval );
 477535         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
 478536               (p->right->op==ICON && p->right->name[0]=='\0')
 479537               && (1<<p->right->lval)==tyl))
 480538                 return( p->left->rval );
 481539         return( -1 );
 482540         }
 483541 #endif
 484542 
 485543 #if 0
 486544 void
 487545 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 488546         register NODE *t;
 489547         NODE *f;
 490548 
 491549         p->n_op = OREG;
 492550         f = p->n_left;  /* have to free this subtree later */
 493551 
 494552         /* init base */
 495553         switch (q->n_op) {
 496554                 case ICON:
 497555                 case REG:
 498556                 case OREG:
 499557                         t = q;
 500558                         break;
 501559 
 502560                 case MINUS:
 503561                         q->n_right->n_lval = -q->n_right->n_lval;
 504562                 case PLUS:
 505563                         t = q->n_right;
 506564                         break;
 507565 
 508566                 case UMUL:
 509567                         t = q->n_left->n_left;
 510568                         break;
 511569 
 512570                 default:
 513571                         cerror("illegal makeor2");
 514572                         t = NULL; /* XXX gcc */
 515573         }
 516574 
 517575         p->n_lval = t->n_lval;
 518576         p->n_name = t->n_name;
 519577 
 520578         /* init offset */
 521579         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
 522580 
 523581         tfree(f);
 524582         return;
 525583         }
 526584 
 527585 int
 528586 canaddr( p ) NODE *p; {
 529587         register int o = p->n_op;
 530588 
 531589         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left, STARNM|SOREG)) ) return(1);
 532590         return(0);
 533591         }
 534592 
 535593 shltype( o, p ) register NODE *p; {
 536594         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 537595         }
 538596 #endif
 539597 
 540598 int
 541599 fldexpand(NODE *p, int cookie, char **cp)
 542600 {
 543601         return 0;
 544602 }
 545603 
 546604 int
 547605 flshape( p ) register NODE *p; {
 548606         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 549607                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 550608         }
 551609 
 552610 int
 553611 shtemp( p ) register NODE *p; {
 554612         if( p->n_op == STARG ) p = p->n_left;
 555613         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 556614         }
 557615 
<> 616+/*
  617+ * Shape matches for UMUL.  Cooperates with offstar().
  618+ */
558619 int
<> 620+shumul(NODE *p, int shape)
  621+{
  622+
  623+        if (x2debug)
  624+                printf("shumul(%p)\n", p);
  625+
  626+        /* Turns currently anything into OREG on vax */
  627+        if (shape & SOREG)
  628+                return SROREG;
  629+        return SRNOPE;
  630+}
  631+
  632+
  633+#ifdef notdef
  634+int
559635 shumul( p, shape ) register NODE *p; int shape; {
 560636         register int o;
 561637         extern int xdebug;
 562638 
 563639         if (xdebug) {
 564640                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 565641                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 566642                 }
 567643 
 568644 
 569645         o = p->n_op;
 570646         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
 571647                 if (shape & STARNM)
 572648                         return SRDIR;
 573649 
<>574 -#ifdef notyet
575650         if( ( o == INCR || o == ASG MINUS ) &&
 576651             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 577652             p->n_right->n_name[0] == '\0' )
 578653                 {
 579654                 switch (p->n_left->n_type)
 580655                         {
 581656                         case CHAR|PTR:
 582657                         case UCHAR|PTR:
 583658                                 o = 1;
 584659                                 break;
 585660 
 586661                         case SHORT|PTR:
 587662                         case USHORT|PTR:
 588663                                 o = 2;
 589664                                 break;
 590665 
 591666                         case INT|PTR:
 592667                         case UNSIGNED|PTR:
 593668                         case LONG|PTR:
 594669                         case ULONG|PTR:
 595670                         case FLOAT|PTR:
 596671                                 o = 4;
 597672                                 break;
 598673 
 599674                         case DOUBLE|PTR:
 600675                                 o = 8;
 601676                                 break;
 602677 
 603678                         default:
 604679                                 if ( ISPTR(p->n_left->n_type) ) {
 605680                                         o = 4;
 606681                                         break;
 607682                                         }
 608683                                 else return(0);
 609684                         }
 610685                 return( p->n_right->n_lval == o ? STARREG : 0);
 611686                 }
<>612 -#endif
613687 
 614688         return( SRNOPE );
 615689         }
<> 690+#endif
616691 
 617692 void
 618693 adrcon( val ) CONSZ val; {
 619694         printf( "$" );
 620695         printf( CONFMT, val );
 621696         }
 622697 
 623698 void
 624699 conput(FILE *fp, NODE *p)
 625700 {
 626701         switch( p->n_op ){
 627702 
 628703         case ICON:
 629704                 acon( p );
 630705                 return;
 631706 
 632707         case REG:
 633708                 printf( "%s", rnames[p->n_rval] );
 634709                 return;
 635710 
 636711         default:
 637712                 cerror( "illegal conput" );
 638713                 }
 639714         }
 640715 
 641716 void
 642717 insput( p ) register NODE *p; {
 643718         cerror( "insput" );
 644719         }
 645720 
<> 721+/*
  722+ * Write out the upper address, like the upper register of a 2-register
  723+ * reference, or the next memory location.
  724+ */
646725 void
<>647 -upput( p , size) register NODE *p; {
 648 -        cerror( "upput" );
  726+upput(NODE *p, int size)
  727+{
  728+
  729+        size /= SZCHAR;
  730+        switch (p->n_op) {
  731+        case REG:
  732+                fprintf(stdout, "%s", rnames[regno(p)-16+1]);
  733+                break;
  734+
  735+        case NAME:
  736+        case OREG:
  737+                p->n_lval += size;
  738+                adrput(stdout, p);
  739+                p->n_lval -= size;
  740+                break;
  741+        case ICON:
  742+                fprintf(stdout, "$" CONFMT, p->n_lval >> 32);
  743+                break;
  744+        default:
  745+                comperr("upput bad op %d size %d", p->n_op, size);
649746         }
<> 747+}
<_650748 
 651749 void
 652750 adrput(FILE *fp, NODE *p)
 653751 {
 654752         register int r;
 655753         /* output an address, with offsets, from p */
 656754 
 657755         if( p->n_op == FLD ){
 658756                 p = p->n_left;
 659757                 }
 660758         switch( p->n_op ){
 661759 
 662760         case NAME:
 663761                 acon( p );
 664762                 return;
 665763 
 666764         case ICON:
 667765                 /* addressable value of the constant */
 668766                 if (p->n_name[0] == '\0') /* uses xxxab */
 669767                         printf("$");
 670768                 acon(p);
 671769                 return;
 672770 
 673771         case REG:
 674772                 printf( "%s", rnames[p->n_rval] );
 675773                 return;
 676774 
 677775         case OREG:
 678776                 r = p->n_rval;
 679777                 if( R2TEST(r) ){ /* double indexing */
 680778                         register int flags;
 681779 
 682780                         flags = R2UPK3(r);
 683781                         if( flags & 1 ) printf("*");
 684782                         if( flags & 4 ) printf("-");
 685783                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 686784                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 687785                         if( flags & 2 ) printf("+");
 688786                         printf( "[%s]", rnames[R2UPK2(r)] );
 689787                         return;
 690788                         }
 691789                 if( r == AP ){  /* in the argument region */
 692790                         if( p->n_lval <= 0 || p->n_name[0] != '\0' ) werror( "bad arg temp" );
 693791                         printf( CONFMT, p->n_lval );
 694792                         printf( "(ap)" );
 695793                         return;
 696794                         }
 697795                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 698796                 printf( "(%s)", rnames[p->n_rval] );
 699797                 return;
 700798 
 701799         case UMUL:
 702800                 /* STARNM or STARREG found */
 703801                 if( tshape(p, STARNM) ) {
 704802                         printf( "*" );
 705803                         adrput(0p->n_left);
 706804                         }
 707805                 else {  /* STARREG - really auto inc or dec */
 708806                         register NODE *q;
 709807 
 710808 /* tbl
 711809                         p = p->n_left;
 712810                         p->n_left->n_op = OREG;
 713811                         if( p->n_op == INCR ) {
 714812                                 adrput( p->n_left );
 715813                                 printf( "+" );
 716814                                 }
 717815                         else {
 718816                                 printf( "-" );
 719817                                 adrput( p->n_left );
 720818                                 }
 721819    tbl */
 722820 #ifdef notyet
 723821                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 724822                                 rnames[p->n_left->n_left->n_rval],
 725823                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 726824 #else
 727825                         printf("%c(%s)%c", '-',
 728826                                 rnames[p->n_left->n_left->n_rval],
 729827                                 '\0' );
 730828 #endif
 731829                         p->n_op = OREG;
 732830                         p->n_rval = p->n_left->n_left->n_rval;
 733831                         q = p->n_left;
 734832 #ifdef notyet
 735833 
 736834                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 737835 #else
 738836                         p->n_lval = 0;
 739837 #endif
 740838                         p->n_name[0] = '\0';
 741839                         tfree(q);
 742840                 }
 743841                 return;
 744842 
 745843         default:
 746844                 cerror( "illegal address" );
 747845                 return;
 748846         }
 749847 
 750848 }
 751849 
 752850 /*
 753851  * print out a constant
 754852  */
 755853 void
 756854 acon(NODE *p)
 757855 {
 758856 
 759857         if (p->n_name[0] == '\0') {
 760858                 printf(CONFMT, p->n_lval);
 761859         } else if( p->n_lval == 0 ) {
 762860                 printf("%s", p->n_name);
 763861         } else {
 764862                 printf("%s+", p->n_name);
 765863                 printf(CONFMT, p->n_lval);
 766864         }
 767865 }
 768866 
 769867 #if 0
 770868 genscall( p, cookie ) register NODE *p; {
 771869         /* structure valued call */
 772870         return( gencall( p, cookie ) );
 773871         }
 774872 
 775873 /* tbl */
 776874 int gc_numbytes;
 777875 /* tbl */
 778876 
 779877 gencall( p, cookie ) register NODE *p; {
 780878         /* generate the call given by p */
 781879         register NODE *p1, *ptemp;
 782880         register temp, temp1;
 783881         register m;
 784882 
 785883         if( p->right ) temp = argsize( p->right );
 786884         else temp = 0;
 787885 
 788886         if( p->op == STCALL || p->op == UNARY STCALL ){
 789887                 /* set aside room for structure return */
 790888 
 791889                 if( p->stsize > temp ) temp1 = p->stsize;
 792890                 else temp1 = temp;
 793891                 }
 794892 
 795893         if( temp > maxargs ) maxargs = temp;
 796894         SETOFF(temp1,4);
 797895 
 798896         if( p->right ){ /* make temp node, put offset in, and generate args */
 799897                 ptemp = talloc();
 800898                 ptemp->op = OREG;
 801899                 ptemp->lval = -1;
 802900                 ptemp->rval = SP;
 803901                 ptemp->name[0] = '\0';
 804902                 ptemp->rall = NOPREF;
 805903                 ptemp->su = 0;
 806904                 genargs( p->right, ptemp );
 807905                 nfree(ptemp);
 808906                 }
 809907 
 810908         p1 = p->left;
 811909         if( p1->op != ICON ){
 812910                 if( p1->op != REG ){
 813911                         if( p1->op != OREG || R2TEST(p1->rval) ){
 814912                                 if( p1->op != NAME ){
 815913                                         order( p1, INAREG );
 816914                                         }
 817915                                 }
 818916                         }
 819917                 }
 820918 
 821919 /*
 822920         if( p1->op == REG && p->rval == R5 ){
 823921                 cerror( "call register overwrite" );
 824922                 }
 825923  */
 826924 /* tbl
 827925         setup gc_numbytes so reference to ZC works */
 828926 
 829927         gc_numbytes = temp;
 830928 /* tbl */
 831929 
 832930         p->op = UNARY CALL;
 833931         m = match( p, INTAREG|INTBREG );
 834932 /* tbl
 835933         switch( temp ) {
 836934         case 0:
 837935                 break;
 838936         case 2:
 839937                 printf( "       tst     (sp)+\n" );
 840938                 break;
 841939         case 4:
 842940                 printf( "       cmp     (sp)+,(sp)+\n" );
 843941                 break;
 844942         default:
 845943                 printf( "       add     $%d,sp\n", temp);
 846944                 }
 847945    tbl */
 848946         return(m != MDONE);
 849947         }
 850948 #endif
 851949 
 852950 static char *
 853951 ccbranches[] = {
 854952         "jeql",
 855953         "jneq",
 856954         "jleq",
 857955         "jlss",
 858956         "jgeq",
 859957         "jgtr",
 860958         "jlequ",
 861959         "jlssu",
 862960         "jgequ",
 863961         "jgtru",
 864962 };
 865963 
 866964 /*
 867965  * printf conditional and unconditional branches
 868966  */
 869967 void
 870968 cbgen(int o, int lab)
 871969 {
 872970 
 873971         if (o == 0) {
 874972                 printf("        jbr     " LABFMT "\n", lab);
 875973         } else {
 876974                 if (o > UGT)
 877975                         comperr("bad conditional branch: %s", opst[o]);
 878976                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 879977         }
 880978 }
 881979 
 882980 static void
 883981 optim2(NODE *p, void *arg)
 884982 {
 885983         /* do local tree transformations and optimizations */
 886984 
 887985         register NODE *r;
 888986 
 889987         switch( p->n_op ) {
 890988 
 891989         case AND:
 892990                 /* commute L and R to eliminate compliments and constants */
 893991                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
 894992                         r = p->n_left;
 895993                         p->n_left = p->n_right;
 896994                         p->n_right = r;
 897995                         }
 898996 #if 0
 899997         case ASG AND:
 900998                 /* change meaning of AND to ~R&L - bic on pdp11 */
 901999                 r = p->n_right;
 9021000                 if( r->op==ICON && r->name[0]==0 ) { /* compliment constant */
 9031001                         r->lval = ~r->lval;
 9041002                         }
 9051003                 else if( r->op==COMPL ) { /* ~~A => A */
 9061004                         r->op = FREE;
 9071005                         p->right = r->left;
 9081006                         }
 9091007                 else { /* insert complement node */
 9101008                         p->right = talloc();
 9111009                         p->right->op = COMPL;
 9121010                         p->right->rall = NOPREF;
 9131011                         p->right->type = r->type;
 9141012                         p->right->left = r;
 9151013                         p->right->right = NULL;
 9161014                         }
 9171015                 break;
 9181016 #endif
 9191017                 }
 9201018         }
 9211019 
 9221020 void
 9231021 myreader(struct interpass *ipole)
 9241022 {
 9251023         struct interpass *ip;
 9261024 
 9271025         DLIST_FOREACH(ip, ipole, qelem) {
 9281026                 if (ip->type != IP_NODE)
 9291027                         continue;
 9301028                 walkf(ip->ip_node, optim2, 0);
 9311029         }
 9321030 }
 9331031 
 9341032 void
 9351033 mycanon(NODE *p)
 9361034 {
 9371035 }
 9381036 
 9391037 void
 9401038 myoptim(struct interpass *ip)
 9411039 {
 9421040 }
 9431041 
 9441042 /*
 9451043  * Return argument size in regs.
 9461044  */
 9471045 static int
 9481046 argsiz(NODE *p)
 9491047 {
 9501048         TWORD t = p->n_type;
 9511049 
 9521050         if (t == STRTY || t == UNIONTY)
 9531051                 return p->n_stsize/(SZINT/SZCHAR);
 9541052         return szty(t);
 9551053 }
 9561054 
 9571055 /*
 9581056  * Last chance to do something before calling a function.
 9591057  */
 9601058 void
 9611059 lastcall(NODE *p)
 9621060 {
 9631061         NODE *op = p;
 9641062         int size = 0;
 9651063 
 9661064         /* Calculate argument sizes */
 9671065         p->n_qual = 0;
 9681066         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 9691067                 return;
 9701068         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 9711069                 size += argsiz(p->n_right);
 9721070         if (p->n_op != ASSIGN)
 9731071                 size += argsiz(p);
 9741072         op->n_qual = size; /* XXX */
 9751073 }
 9761074 
 9771075 /*
 9781076  * Return a class suitable for a specific type.
 9791077  */
 9801078 int
 9811079 gclass(TWORD t)
 9821080 {
 9831081         return (szty(t) == 2 ? CLASSB : CLASSA);
 9841082 }
 9851083 
 9861084 /*
 9871085  * For class c, find worst-case displacement of the number of
 9881086  * registers in the array r[] indexed by class.
 9891087  */
 9901088 int
 9911089 COLORMAP(int c, int *r)
 9921090 {
 9931091         int num;
 9941092 
 9951093         switch (c) {
 9961094         case CLASSA:
 9971095                 /* there are 12 classa, so min 6 classb are needed to block */
 9981096                 num = r[CLASSB] * 2;
 9991097                 num += r[CLASSA];
 10001098                 return num < 12;
 10011099         case CLASSB:
 10021100                 /* 6 classa may block all classb */
 10031101                 num = r[CLASSB] + r[CLASSA];
 10041102                 return num < 6;
 10051103         }
 10061104         comperr("COLORMAP");
 10071105         return 0; /* XXX gcc */
 10081106 }
 10091107 
 10101108 /*
 10111109  * Special shapes.
 10121110  */
 10131111 int
 10141112 special(NODE *p, int shape)
 10151113 {
 10161114         return SRNOPE;
 10171115 }
 10181116 
 10191117 /*
 10201118  * Target-dependent command-line options.
 10211119  */
 10221120 void
 10231121 mflags(char *str)
 10241122 {
 10251123 }
 10261124 /*
 10271125  * Do something target-dependent for xasm arguments.
 10281126  * Supposed to find target-specific constraints and rewrite them.
 10291127  */
 10301128 int
 10311129 myxasm(struct interpass *ip, NODE *p)
 10321130 {
 10331131         return 0;
 10341132 }
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-07-10 06:00 +0200