Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.9
 
1.10
 
MAIN:ragge:20081116133615
 
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         if (ipp->ipp_vis)
 5151                 printf("        .globl %s\n", ipp->ipp_name);
 5252         printf("        .align 4\n");
 5353         printf("%s:\n", ipp->ipp_name);
 5454         printf("        .word 0x%x\n", ipp->ipp_regs[0]);
 5555         if (p2maxautooff)
 5656                 printf("        subl2 $%d,%%sp\n", p2maxautooff);
 5757 }
 5858 
 5959 /*
 6060  * Called after all instructions in a function are emitted.
 6161  * Generates code for epilog here.
 6262  */
 6363 void
 6464 eoftn(struct interpass_prolog *ipp)
 6565 {
 6666         if (ipp->ipp_ip.ip_lbl == 0)
 6767                 return; /* no code needs to be generated */
 6868         printf("        ret\n");
 6969 }
 7070 
 7171 struct hoptab { int opmask; char * opstring; } ioptab[] = {
 7272 
 7373         { PLUS"add", },
 7474         { MINUS,        "sub", },
 7575         { MUL,  "mul", },
 7676         { DIV,  "div", },
 7777         { OR,   "bis", },
 7878         { ER,   "xor", },
 7979         { AND,  "bic", },
 8080         { -1, ""     },
 8181 };
 8282 
 8383 void
 8484 hopcode( f, o ){
 8585         /* output the appropriate string from the above table */
 8686 
 8787         register struct hoptab *q;
 8888 
 8989         for( q = ioptabq->opmask>=0; ++q ){
 9090                 if( q->opmask == o ){
 9191                         printf( "%s", q->opstring );
 9292 /* tbl
 9393                         if( f == 'F' ) printf( "e" );
 9494                         else if( f == 'D' ) printf( "d" );
 9595    tbl */
 9696 /* tbl */
 9797                         switch( f ) {
 9898                                 case 'L':
 9999                                 case 'W':
 100100                                 case 'B':
 101101                                 case 'D':
 102102                                 case 'F':
 103103                                         printf("%c", tolower(f));
 104104                                         break;
 105105 
 106106                                 }
 107107 /* tbl */
 108108                         return;
 109109                         }
 110110                 }
 111111         cerror( "no hoptab for %s", opst[o] );
 112112         }
 113113 
 114114 char *
 115115 rnames[] = {  /* keyed to register number tokens */
 116116 
 117117         "r0", "r1", "r2", "r3", "r4", "r5",
 118118         "r6", "r7", "r8", "r9", "r10", "r11",
 119119         "ap", "fp", "sp", "pc",
 120120         /* The concatenated regs has the name of the lowest */
 121121         "r0", "r1", "r2", "r3", "r4", "r5",
 122122         "r6", "r7", "r8", "r9", "r10"
 123123         };
 124124 
 125125 int
 126126 tlen(p) NODE *p;
 127127 {
 128128         switch(p->n_type) {
 129129                 case CHAR:
 130130                 case UCHAR:
 131131                         return(1);
 132132 
 133133                 case SHORT:
 134134                 case USHORT:
 135135                         return(2);
 136136 
 137137                 case DOUBLE:
 138138                 case LDOUBLE:
 139139                 case LONGLONG:
 140140                 case ULONGLONG:
 141141                         return(8);
 142142 
 143143                 default:
 144144                         return(4);
 145145                 }
 146146 }
 147147 
 148148 static int
 149149 mixtypes(NODE *p, NODE *q)
 150150 {
 151151         TWORD tp, tq;
 152152 
 153153         tp = p->n_type;
 154154         tq = q->n_type;
 155155 
 156156         return( (tp==FLOAT || tp==DOUBLE) !=
 157157                 (tq==FLOAT || tq==DOUBLE) );
 158158 }
 159159 
 160160 void
 161161 prtype(NODE *n)
 162162 {
 163163         switch (n->n_type)
 164164                 {
 165165                 case DOUBLE:
 166166                         printf("d");
 167167                         return;
 168168 
 169169                 case FLOAT:
 170170                         printf("f");
 171171                         return;
 172172 
 173173                 case LONG:
 174174                 case ULONG:
 175175                 case INT:
 176176                 case UNSIGNED:
 177177                         printf("l");
 178178                         return;
 179179 
 180180                 case SHORT:
 181181                 case USHORT:
 182182                         printf("w");
 183183                         return;
 184184 
 185185                 case CHAR:
 186186                 case UCHAR:
 187187                         printf("b");
 188188                         return;
 189189 
 190190                 default:
 191191                         if ( !ISPTR( n->n_type ) ) cerror("zzzcode- bad type");
 192192                         else {
 193193                                 printf("l");
 194194                                 return;
 195195                                 }
 196196                 }
 197197 }
 198198 
 199199 void
 200200 zzzcode( p, c ) register NODE *p; {
 201201         int m;
 202202         int val;
 203203         switch( c ){
 204204 
 205205         case 'N'/* logical ops, turned into 0-1 */
 206206                 /* use register given by register 1 */
 207207                 cbgen( 0, m=getlab());
 208208                 deflab( p->n_label );
 209209                 printf( "       clrl    %s\n", rnames[getlr( p, '1' )->n_rval] );
 210210                 deflab( m );
 211211                 return;
 212212 
 213213         case 'A':
 214214                 {
 215215                 register NODE *l, *r;
 216216 
 217217                 if (xdebug) e2print(p, 0, &val, &val);
 218218                 r = getlr(p, 'R');
 219219                 if (optype(p->n_op) == LTYPE || p->n_op == UMUL) {
 220220                         l = resc;
 221221                         l->n_type = (r->n_type==FLOAT || r->n_type==DOUBLE ? DOUBLE : INT);
 222222                 } else
 223223                         l = getlr(p, 'L');
 224224                 if (r->n_op == ICON  && r->n_name[0] == '\0') {
 225225                         if (r->n_lval == 0) {
 226226                                 printf("clr");
 227227                                 prtype(l);
 228228                                 printf("        ");
 229229                                 adrput(stdout, l);
 230230                                 return;
 231231                         }
 232232                         if (r->n_lval < 0 && r->n_lval >= -63) {
 233233                                 printf("mneg");
 234234                                 prtype(l);
 235235                                 r->n_lval = -r->n_lval;
 236236                                 goto ops;
 237237                         }
 238238                         r->n_type = (r->n_lval < 0 ?
 239239                                         (r->n_lval >= -128 ? CHAR
 240240                                         : (r->n_lval >= -32768 ? SHORT
 241241                                         : INT )) : r->n_type);
 242242                         r->n_type = (r->n_lval >= 0 ?
 243243                                         (r->n_lval <= 63 ? INT
 244244                                         : ( r->n_lval <= 127 ? CHAR
 245245                                         : (r->n_lval <= 255 ? UCHAR
 246246                                         : (r->n_lval <= 32767 ? SHORT
 247247                                         : (r->n_lval <= 65535 ? USHORT
 248248                                         : INT ))))) : r->n_type );
 249249                         }
 250250                 if (l->n_op == REG && l->n_type != FLOAT && l->n_type != DOUBLE)
 251251                         l->n_type = INT;
 252252                 if (!mixtypes(l,r))
 253253                         {
 254254                         if (tlen(l) == tlen(r))
 255255                                 {
 256256                                 printf("mov");
 257257                                 prtype(l);
 258258                                 goto ops;
 259259                                 }
 260260                         else if (tlen(l) > tlen(r) && ISUNSIGNED(r->n_type))
 261261                                 {
 262262                                 printf("movz");
 263263                                 }
 264264                         else
 265265                                 {
 266266                                 printf("cvt");
 267267                                 }
 268268                         }
 269269                 else
 270270                         {
 271271                         printf("cvt");
 272272                         }
 273273                 prtype(r);
 274274                 prtype(l);
 275275         ops:
 276276                 printf("        ");
 277277                 adrput(stdout, r);
 278278                 printf(",");
 279279                 adrput(stdout, l);
 280280                 return;
 281281                 }
 282282 
 283283         case 'C':       /* num words pushed on arg stack */
 284284                 if (p->n_op == STCALL || p->n_op == USTCALL)
 285285                         p->n_qual++;
 286286                 printf("$%d", p->n_qual);
 287287                 break;
 288288 
 289289         case 'D':       /* INCR and DECR */
 290290                 zzzcode(p->n_left, 'A');
 291291                 printf("\n      ");
 292292 
 293293 #if 0
 294294         case 'E':       /* INCR and DECR, FOREFF */
 295295                 if (p->n_right->n_lval == 1)
 296296                         {
 297297                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
 298298                         prtype(p->n_left);
 299299                         printf("        ");
 300300                         adrput(stdout, p->n_left);
 301301                         return;
 302302                         }
 303303                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
 304304                 prtype(p->n_left);
 305305                 printf("2       ");
 306306                 adrput(stdout, p->n_right);
 307307                 printf(",");
 308308                 adrput(p->n_left);
 309309                 return;
 310310 #endif
 311311 
 312312         case 'F':       /* register type of right operand */
 313313                 {
 314314                 register NODE *n;
 315315                 extern int xdebug;
 316316                 register int ty;
 317317 
 318318                 n = getlr( p, 'R' );
 319319                 ty = n->n_type;
 320320 
 321321                 if (xdebug) printf("->%d<-", ty);
 322322 
 323323                 if ( ty==DOUBLE) printf("d");
 324324                 else if ( ty==FLOAT ) printf("f");
 325325                 else printf("l");
 326326                 return;
 327327                 }
 328328 
 329329         case 'J': /* jump or ret? */
 330330                 {
 331331                         extern struct interpass_prolog *epp;
 332332                         struct interpass *ip =
 333333                             DLIST_PREV((struct interpass *)epp, qelem);
 334334                         if (ip->type != IP_DEFLAB ||
 335335                             ip->ip_lbl != getlr(p, 'L')->n_lval)
 336336                                 expand(p, FOREFF, "jbr  LL");
 337337                         else
 338338                                 printf("ret");
 339339                 }
 340340                 break;
 341341 
 342342         case 'L':       /* type of left operand */
 343343         case 'R':       /* type of right operand */
 344344                 {
 345345                 register NODE *n;
 346346                 extern int xdebug;
 347347 
 348348                 n = getlr ( p, c);
 349349                 if (xdebug) printf("->%d<-", n->n_type);
 350350 
 351351                 prtype(n);
 352352                 return;
 353353                 }
 354354 
 355355         case 'Z':       /* complement mask for bit instr */
 356356                 printf("$%Ld", ~p->n_right->n_lval);
 357357                 return;
 358358 
 359359         case 'U':       /* 32 - n, for unsigned right shifts */
 360360                 printf("$" CONFMT, 32 - p->n_right->n_lval );
 361361                 return;
 362362 
 363363         case 'T':       /* rounded structure length for arguments */
 364364                 {
 365365                 int size;
 366366 
 367367                 size = p->n_stsize;
 368368                 SETOFF( size, 4);
 369369                 printf("$%d", size);
 370370                 return;
 371371                 }
 372372 
 373373         case 'S'/* structure assignment */
 374374                 {
 375375                         register NODE *l, *r;
 376376                         register int size;
 377377 
 378378                         l = r = NULL; /* XXX gcc */
 379379                         if( p->n_op == STASG ){
 380380                                 l = p->n_left;
 381381                                 r = p->n_right;
 382382 
 383383                                 }
 384384                         else if( p->n_op == STARG ){  /* store an arg into a temporary */
 385385                                 l = getlr( p, '3' );
 386386                                 r = p->n_left;
 387387                                 }
 388388                         else cerror( "STASG bad" );
 389389 
 390390                         if( r->n_op == ICON ) r->n_op = NAME;
 391391                         else if( r->n_op == REG ) r->n_op = OREG;
 392392                         else if( r->n_op != OREG ) cerror( "STASG-r" );
 393393 
 394394                         size = p->n_stsize;
 395395 
 396396                         if( size <= 0 || size > 65535 )
 397397                                 cerror("structure size <0=0 or >65535");
 398398 
 399399                         switch(size) {
 400400                                 case 1:
 401401                                         printf("        movb    ");
 402402                                         break;
 403403                                 case 2:
 404404                                         printf("        movw    ");
 405405                                         break;
 406406                                 case 4:
 407407                                         printf("        movl    ");
 408408                                         break;
 409409                                 case 8:
 410410                                         printf("        movq    ");
 411411                                         break;
 412412                                 default:
 413413                                         printf("        movc3   $%d,", size);
 414414                                         break;
 415415                         }
 416416                         adrput(stdout, r);
 417417                         printf(",");
 418418                         adrput(stdout, l);
 419419                         printf("\n");
 420420 
 421421                         if( r->n_op == NAME ) r->n_op = ICON;
 422422                         else if( r->n_op == OREG ) r->n_op = REG;
 423423 
 424424                         }
 425425                 break;
 426426 
 427427         default:
 428428                 comperr("illegal zzzcode '%c'", c);
 429429                 }
 430430         }
 431431 
 432432 void
 433433 rmove( int rt,int  rs, TWORD t ){
 434434         printf( "       %s      %s,%s\n",
 435435                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 436436                 rnames[rs], rnames[rt] );
 437437         }
 438438 
 439439 #if 0
 440440 setregs(){ /* set up temporary registers */
 441441         fregs = 6;      /* tbl- 6 free regs on VAX (0-5) */
 442442         ;
 443443         }
 444444 
 445445 szty(t){ /* size, in registers, needed to hold thing of type t */
 446446         return( (t==DOUBLE||t==FLOAT) ? 2 : 1 );
 447447         }
 448448 #endif
 449449 
 450450 int
 451451 rewfld( p ) NODE *p; {
 452452         return(1);
 453453         }
 454454 
 455455 #if 0
 456456 callreg(p) NODE *p; {
 457457         return( R0 );
 458458         }
 459459 
 460460 base( p ) register NODE *p; {
 461461         register int o = p->op;
 462462 
 463463         if( (o==ICON && p->name[0] != '\0')) return( 100 ); /* ie no base reg */
 464464         if( o==REG ) return( p->rval );
 465465     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
 466466                 return( p->left->rval );
 467467     if( o==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 468468                 return( p->rval + 0200*1 );
 469469         if( o==INCR && p->left->op==REG ) return( p->left->rval + 0200*2 );
 470470         if( o==ASG MINUS && p->left->op==REG) return( p->left->rval + 0200*4 );
 471471         if( o==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
 472472           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 473473                 return( p->left->left->rval + 0200*(1+2) );
 474474         return( -1 );
 475475         }
 476476 
 477477 offset( p, tyl ) register NODE *p; int tyl; {
 478478 
 479479         if( tyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) return( p->rval );
 480480         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
 481481               (p->right->op==ICON && p->right->name[0]=='\0')
 482482               && (1<<p->right->lval)==tyl))
 483483                 return( p->left->rval );
 484484         return( -1 );
 485485         }
 486486 #endif
 487487 
 488488 #if 0
 489489 void
 490490 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 491491         register NODE *t;
 492492         NODE *f;
 493493 
 494494         p->n_op = OREG;
 495495         f = p->n_left;  /* have to free this subtree later */
 496496 
 497497         /* init base */
 498498         switch (q->n_op) {
 499499                 case ICON:
 500500                 case REG:
 501501                 case OREG:
 502502                         t = q;
 503503                         break;
 504504 
 505505                 case MINUS:
 506506                         q->n_right->n_lval = -q->n_right->n_lval;
 507507                 case PLUS:
 508508                         t = q->n_right;
 509509                         break;
 510510 
 511511                 case UMUL:
 512512                         t = q->n_left->n_left;
 513513                         break;
 514514 
 515515                 default:
 516516                         cerror("illegal makeor2");
 517517                         t = NULL; /* XXX gcc */
 518518         }
 519519 
 520520         p->n_lval = t->n_lval;
 521521         p->n_name = t->n_name;
 522522 
 523523         /* init offset */
 524524         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
 525525 
 526526         tfree(f);
 527527         return;
 528528         }
 529529 
 530530 int
 531531 canaddr( p ) NODE *p; {
 532532         register int o = p->n_op;
 533533 
 534534         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left, STARNM|SOREG)) ) return(1);
 535535         return(0);
 536536         }
 537537 
 538538 shltype( o, p ) register NODE *p; {
 539539         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 540540         }
 541541 #endif
 542542 
 543543 int
 544544 fldexpand(NODE *p, int cookie, char **cp)
 545545 {
 546546         return 0;
 547547 }
 548548 
 549549 int
 550550 flshape( p ) register NODE *p; {
 551551         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 552552                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 553553         }
 554554 
 555555 int
 556556 shtemp( p ) register NODE *p; {
 557557         if( p->n_op == STARG ) p = p->n_left;
 558558         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 559559         }
 560560 
 561561 int
 562562 shumul( p, shape ) register NODE *p; int shape; {
 563563         register int o;
 564564         extern int xdebug;
 565565 
 566566         if (xdebug) {
 567567                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 568568                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 569569                 }
 570570 
 571571 
 572572         o = p->n_op;
 573573         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
 574574                 if (shape & STARNM)
 575575                         return SRDIR;
 576576 
 577577 #ifdef notyet
 578578         if( ( o == INCR || o == ASG MINUS ) &&
 579579             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 580580             p->n_right->n_name[0] == '\0' )
 581581                 {
 582582                 switch (p->n_left->n_type)
 583583                         {
 584584                         case CHAR|PTR:
 585585                         case UCHAR|PTR:
 586586                                 o = 1;
 587587                                 break;
 588588 
 589589                         case SHORT|PTR:
 590590                         case USHORT|PTR:
 591591                                 o = 2;
 592592                                 break;
 593593 
 594594                         case INT|PTR:
 595595                         case UNSIGNED|PTR:
 596596                         case LONG|PTR:
 597597                         case ULONG|PTR:
 598598                         case FLOAT|PTR:
 599599                                 o = 4;
 600600                                 break;
 601601 
 602602                         case DOUBLE|PTR:
 603603                                 o = 8;
 604604                                 break;
 605605 
 606606                         default:
 607607                                 if ( ISPTR(p->n_left->n_type) ) {
 608608                                         o = 4;
 609609                                         break;
 610610                                         }
 611611                                 else return(0);
 612612                         }
 613613                 return( p->n_right->n_lval == o ? STARREG : 0);
 614614                 }
 615615 #endif
 616616 
 617617         return( SRNOPE );
 618618         }
 619619 
 620620 void
 621621 adrcon( val ) CONSZ val; {
 622622         printf( "$" );
 623623         printf( CONFMT, val );
 624624         }
 625625 
 626626 void
 627627 conput(FILE *fp, NODE *p)
 628628 {
 629629         switch( p->n_op ){
 630630 
 631631         case ICON:
 632632                 acon( p );
 633633                 return;
 634634 
 635635         case REG:
 636636                 printf( "%s", rnames[p->n_rval] );
 637637                 return;
 638638 
 639639         default:
 640640                 cerror( "illegal conput" );
 641641                 }
 642642         }
 643643 
 644644 void
 645645 insput( p ) register NODE *p; {
 646646         cerror( "insput" );
 647647         }
 648648 
 649649 void
 650650 upput( p , size) register NODE *p; {
 651651         cerror( "upput" );
 652652         }
 653653 
 654654 void
 655655 adrput(FILE *fp, NODE *p)
 656656 {
 657657         register int r;
 658658         /* output an address, with offsets, from p */
 659659 
 660660         if( p->n_op == FLD ){
 661661                 p = p->n_left;
 662662                 }
 663663         switch( p->n_op ){
 664664 
 665665         case NAME:
 666666                 acon( p );
 667667                 return;
 668668 
 669669         case ICON:
 670670                 /* addressable value of the constant */
 671671                 if (p->n_name[0] == '\0') /* uses xxxab */
 672672                         printf("$");
 673673                 acon(p);
 674674                 return;
 675675 
 676676         case REG:
 677677                 printf( "%s", rnames[p->n_rval] );
 678678                 return;
 679679 
 680680         case OREG:
 681681                 r = p->n_rval;
 682682                 if( R2TEST(r) ){ /* double indexing */
 683683                         register int flags;
 684684 
 685685                         flags = R2UPK3(r);
 686686                         if( flags & 1 ) printf("*");
 687687                         if( flags & 4 ) printf("-");
 688688                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 689689                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 690690                         if( flags & 2 ) printf("+");
 691691                         printf( "[%s]", rnames[R2UPK2(r)] );
 692692                         return;
 693693                         }
 694694                 if( r == AP ){  /* in the argument region */
 695695                         if( p->n_lval <= 0 || p->n_name[0] != '\0' ) werror( "bad arg temp" );
 696696                         printf( CONFMT, p->n_lval );
 697697                         printf( "(ap)" );
 698698                         return;
 699699                         }
 700700                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 701701                 printf( "(%s)", rnames[p->n_rval] );
 702702                 return;
 703703 
 704704         case UMUL:
 705705                 /* STARNM or STARREG found */
 706706                 if( tshape(p, STARNM) ) {
 707707                         printf( "*" );
 708708                         adrput(0p->n_left);
 709709                         }
 710710                 else {  /* STARREG - really auto inc or dec */
 711711                         register NODE *q;
 712712 
 713713 /* tbl
 714714                         p = p->n_left;
 715715                         p->n_left->n_op = OREG;
 716716                         if( p->n_op == INCR ) {
 717717                                 adrput( p->n_left );
 718718                                 printf( "+" );
 719719                                 }
 720720                         else {
 721721                                 printf( "-" );
 722722                                 adrput( p->n_left );
 723723                                 }
 724724    tbl */
 725725 #ifdef notyet
 726726                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 727727                                 rnames[p->n_left->n_left->n_rval],
 728728                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 729729 #else
 730730                         printf("%c(%s)%c", '-',
 731731                                 rnames[p->n_left->n_left->n_rval],
 732732                                 '\0' );
 733733 #endif
 734734                         p->n_op = OREG;
 735735                         p->n_rval = p->n_left->n_left->n_rval;
 736736                         q = p->n_left;
 737737 #ifdef notyet
 738738 
 739739                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 740740 #else
 741741                         p->n_lval = 0;
 742742 #endif
 743743                         p->n_name[0] = '\0';
 744744                         tfree(q);
 745745                 }
 746746                 return;
 747747 
 748748         default:
 749749                 cerror( "illegal address" );
 750750                 return;
 751751         }
 752752 
 753753 }
 754754 
 755755 /*
 756756  * print out a constant
 757757  */
 758758 void
 759759 acon(NODE *p)
 760760 {
 761761 
 762762         if (p->n_name[0] == '\0') {
 763763                 printf(CONFMT, p->n_lval);
 764764         } else if( p->n_lval == 0 ) {
 765765                 printf("%s", p->n_name);
 766766         } else {
 767767                 printf("%s+", p->n_name);
 768768                 printf(CONFMT, p->n_lval);
 769769         }
 770770 }
 771771 
 772772 #if 0
 773773 genscall( p, cookie ) register NODE *p; {
 774774         /* structure valued call */
 775775         return( gencall( p, cookie ) );
 776776         }
 777777 
 778778 /* tbl */
 779779 int gc_numbytes;
 780780 /* tbl */
 781781 
 782782 gencall( p, cookie ) register NODE *p; {
 783783         /* generate the call given by p */
 784784         register NODE *p1, *ptemp;
 785785         register temp, temp1;
 786786         register m;
 787787 
 788788         if( p->right ) temp = argsize( p->right );
 789789         else temp = 0;
 790790 
 791791         if( p->op == STCALL || p->op == UNARY STCALL ){
 792792                 /* set aside room for structure return */
 793793 
 794794                 if( p->stsize > temp ) temp1 = p->stsize;
 795795                 else temp1 = temp;
 796796                 }
 797797 
 798798         if( temp > maxargs ) maxargs = temp;
 799799         SETOFF(temp1,4);
 800800 
 801801         if( p->right ){ /* make temp node, put offset in, and generate args */
 802802                 ptemp = talloc();
 803803                 ptemp->op = OREG;
 804804                 ptemp->lval = -1;
 805805                 ptemp->rval = SP;
 806806                 ptemp->name[0] = '\0';
 807807                 ptemp->rall = NOPREF;
 808808                 ptemp->su = 0;
 809809                 genargs( p->right, ptemp );
 810810                 nfree(ptemp);
 811811                 }
 812812 
 813813         p1 = p->left;
 814814         if( p1->op != ICON ){
 815815                 if( p1->op != REG ){
 816816                         if( p1->op != OREG || R2TEST(p1->rval) ){
 817817                                 if( p1->op != NAME ){
 818818                                         order( p1, INAREG );
 819819                                         }
 820820                                 }
 821821                         }
 822822                 }
 823823 
 824824 /*
 825825         if( p1->op == REG && p->rval == R5 ){
 826826                 cerror( "call register overwrite" );
 827827                 }
 828828  */
 829829 /* tbl
 830830         setup gc_numbytes so reference to ZC works */
 831831 
 832832         gc_numbytes = temp;
 833833 /* tbl */
 834834 
 835835         p->op = UNARY CALL;
 836836         m = match( p, INTAREG|INTBREG );
 837837 /* tbl
 838838         switch( temp ) {
 839839         case 0:
 840840                 break;
 841841         case 2:
 842842                 printf( "       tst     (sp)+\n" );
 843843                 break;
 844844         case 4:
 845845                 printf( "       cmp     (sp)+,(sp)+\n" );
 846846                 break;
 847847         default:
 848848                 printf( "       add     $%d,sp\n", temp);
 849849                 }
 850850    tbl */
 851851         return(m != MDONE);
 852852         }
 853853 #endif
 854854 
 855855 static char *
 856856 ccbranches[] = {
 857857         "jeql",
 858858         "jneq",
 859859         "jleq",
 860860         "jlss",
 861861         "jgeq",
 862862         "jgtr",
 863863         "jlequ",
 864864         "jlssu",
 865865         "jgequ",
 866866         "jgtru",
 867867 };
 868868 
 869869 /*
 870870  * printf conditional and unconditional branches
 871871  */
 872872 void
 873873 cbgen(int o, int lab)
 874874 {
 875875 
 876876         if (o == 0) {
 877877                 printf("        jbr     " LABFMT "\n", lab);
 878878         } else {
 879879                 if (o > UGT)
 880880                         comperr("bad conditional branch: %s", opst[o]);
 881881                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 882882         }
 883883 }
 884884 
 885885 static void
<>886 -optim2(NODE *p)
  886+optim2(NODE *p, void *arg)
887887 {
 888888         /* do local tree transformations and optimizations */
 889889 
 890890         register NODE *r;
 891891 
 892892         switch( p->n_op ) {
 893893 
 894894         case AND:
 895895                 /* commute L and R to eliminate compliments and constants */
 896896                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
 897897                         r = p->n_left;
 898898                         p->n_left = p->n_right;
 899899                         p->n_right = r;
 900900                         }
 901901 #if 0
 902902         case ASG AND:
 903903                 /* change meaning of AND to ~R&L - bic on pdp11 */
 904904                 r = p->n_right;
 905905                 if( r->op==ICON && r->name[0]==0 ) { /* compliment constant */
 906906                         r->lval = ~r->lval;
 907907                         }
 908908                 else if( r->op==COMPL ) { /* ~~A => A */
 909909                         r->op = FREE;
 910910                         p->right = r->left;
 911911                         }
 912912                 else { /* insert complement node */
 913913                         p->right = talloc();
 914914                         p->right->op = COMPL;
 915915                         p->right->rall = NOPREF;
 916916                         p->right->type = r->type;
 917917                         p->right->left = r;
 918918                         p->right->right = NULL;
 919919                         }
 920920                 break;
 921921 #endif
 922922                 }
 923923         }
 924924 
 925925 void
 926926 myreader(struct interpass *ipole)
 927927 {
 928928         struct interpass *ip;
 929929 
 930930         DLIST_FOREACH(ip, ipole, qelem) {
 931931                 if (ip->type != IP_NODE)
 932932                         continue;
<>933 -                walkf(ip->ip_node, optim2);
  933+                walkf(ip->ip_node, optim2, 0);
<_934934         }
 935935 }
 936936 
 937937 void
 938938 mycanon(NODE *p)
 939939 {
 940940 }
 941941 
 942942 void
 943943 myoptim(struct interpass *ip)
 944944 {
 945945 }
 946946 
 947947 /*
 948948  * Return argument size in regs.
 949949  */
 950950 static int
 951951 argsiz(NODE *p)
 952952 {
 953953         TWORD t = p->n_type;
 954954 
 955955         if (t == STRTY || t == UNIONTY)
 956956                 return p->n_stsize/(SZINT/SZCHAR);
 957957         return szty(t);
 958958 }
 959959 
 960960 /*
 961961  * Last chance to do something before calling a function.
 962962  */
 963963 void
 964964 lastcall(NODE *p)
 965965 {
 966966         NODE *op = p;
 967967         int size = 0;
 968968 
 969969         /* Calculate argument sizes */
 970970         p->n_qual = 0;
 971971         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 972972                 return;
 973973         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 974974                 size += argsiz(p->n_right);
 975975         size += argsiz(p);
 976976         op->n_qual = size; /* XXX */
 977977 }
 978978 
 979979 /*
 980980  * Return a class suitable for a specific type.
 981981  */
 982982 int
 983983 gclass(TWORD t)
 984984 {
 985985         return (szty(t) == 2 ? CLASSB : CLASSA);
 986986 }
 987987 
 988988 /*
 989989  * For class c, find worst-case displacement of the number of
 990990  * registers in the array r[] indexed by class.
 991991  */
 992992 int
 993993 COLORMAP(int c, int *r)
 994994 {
 995995         int num;
 996996 
 997997         switch (c) {
 998998         case CLASSA:
 999999                 /* there are 12 classa, so min 6 classb are needed to block */
 10001000                 num = r[CLASSB] * 2;
 10011001                 num += r[CLASSA];
 10021002                 return num < 12;
 10031003         case CLASSB:
 10041004                 /* 6 classa may block all classb */
 10051005                 num = r[CLASSB] + r[CLASSA];
 10061006                 return num < 6;
 10071007         }
 10081008         comperr("COLORMAP");
 10091009         return 0; /* XXX gcc */
 10101010 }
 10111011 
 10121012 /*
 10131013  * Special shapes.
 10141014  */
 10151015 int
 10161016 special(NODE *p, int shape)
 10171017 {
 10181018         return SRNOPE;
 10191019 }
 10201020 
 10211021 /*
 10221022  * Target-dependent command-line options.
 10231023  */
 10241024 void
 10251025 mflags(char *str)
 10261026 {
 10271027 }
 10281028 /*
 10291029  * Do something target-dependent for xasm arguments.
 10301030  * Supposed to find target-specific constraints and rewrite them.
 10311031  */
 10321032 int
 10331033 myxasm(struct interpass *ip, NODE *p)
 10341034 {
 10351035         return 0;
 10361036 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-10-30 19:14 +0100