Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.12
 
1.13
 
MAIN:ragge:20110627115025
 
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%lx\n", 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 
 195195 void
 196196 zzzcode( p, c ) register NODE *p; {
 197197         int m;
 198198         int val;
 199199         switch( c ){
 200200 
 201201         case 'N'/* logical ops, turned into 0-1 */
 202202                 /* use register given by register 1 */
 203203                 cbgen( 0, m=getlab2());
 204204                 deflab( p->n_label );
 205205                 printf( "       clrl    %s\n", rnames[getlr( p, '1' )->n_rval] );
 206206                 deflab( m );
 207207                 return;
 208208 
 209209         case 'A':
 210210                 {
 211211                 register NODE *l, *r;
 212212 
 213213                 if (xdebug) e2print(p, 0, &val, &val);
 214214                 r = getlr(p, 'R');
 215215                 if (optype(p->n_op) == LTYPE || p->n_op == UMUL) {
 216216                         l = resc;
 217217                         l->n_type = (r->n_type==FLOAT || r->n_type==DOUBLE ? DOUBLE : INT);
 218218                 } else
 219219                         l = getlr(p, 'L');
 220220                 if (r->n_op == ICON  && r->n_name[0] == '\0') {
 221221                         if (r->n_lval == 0) {
 222222                                 printf("clr");
 223223                                 prtype(l);
 224224                                 printf("        ");
 225225                                 adrput(stdout, l);
 226226                                 return;
 227227                         }
 228228                         if (r->n_lval < 0 && r->n_lval >= -63) {
 229229                                 printf("mneg");
 230230                                 prtype(l);
 231231                                 r->n_lval = -r->n_lval;
 232232                                 goto ops;
 233233                         }
 234234                         r->n_type = (r->n_lval < 0 ?
 235235                                         (r->n_lval >= -128 ? CHAR
 236236                                         : (r->n_lval >= -32768 ? SHORT
 237237                                         : INT )) : r->n_type);
 238238                         r->n_type = (r->n_lval >= 0 ?
 239239                                         (r->n_lval <= 63 ? INT
 240240                                         : ( r->n_lval <= 127 ? CHAR
 241241                                         : (r->n_lval <= 255 ? UCHAR
 242242                                         : (r->n_lval <= 32767 ? SHORT
 243243                                         : (r->n_lval <= 65535 ? USHORT
 244244                                         : INT ))))) : r->n_type );
 245245                         }
 246246                 if (l->n_op == REG && l->n_type != FLOAT && l->n_type != DOUBLE)
 247247                         l->n_type = INT;
 248248                 if (!mixtypes(l,r))
 249249                         {
 250250                         if (tlen(l) == tlen(r))
 251251                                 {
 252252                                 printf("mov");
 253253                                 prtype(l);
 254254                                 goto ops;
 255255                                 }
 256256                         else if (tlen(l) > tlen(r) && ISUNSIGNED(r->n_type))
 257257                                 {
 258258                                 printf("movz");
 259259                                 }
 260260                         else
 261261                                 {
 262262                                 printf("cvt");
 263263                                 }
 264264                         }
 265265                 else
 266266                         {
 267267                         printf("cvt");
 268268                         }
 269269                 prtype(r);
 270270                 prtype(l);
 271271         ops:
 272272                 printf("        ");
 273273                 adrput(stdout, r);
 274274                 printf(",");
 275275                 adrput(stdout, l);
 276276                 return;
 277277                 }
 278278 
 279279         case 'C':       /* num words pushed on arg stack */
<>280 -                if (p->n_op == STCALL || p->n_op == USTCALL)
 281 -                        p->n_qual++;
282280                 printf("$%d", p->n_qual);
 283281                 break;
 284282 
 285283         case 'D':       /* INCR and DECR */
 286284                 zzzcode(p->n_left, 'A');
 287285                 printf("\n      ");
 288286 
 289287 #if 0
 290288         case 'E':       /* INCR and DECR, FOREFF */
 291289                 if (p->n_right->n_lval == 1)
 292290                         {
 293291                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
 294292                         prtype(p->n_left);
 295293                         printf("        ");
 296294                         adrput(stdout, p->n_left);
 297295                         return;
 298296                         }
 299297                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
 300298                 prtype(p->n_left);
 301299                 printf("2       ");
 302300                 adrput(stdout, p->n_right);
 303301                 printf(",");
 304302                 adrput(p->n_left);
 305303                 return;
 306304 #endif
 307305 
 308306         case 'F':       /* register type of right operand */
 309307                 {
 310308                 register NODE *n;
 311309                 extern int xdebug;
 312310                 register int ty;
 313311 
 314312                 n = getlr( p, 'R' );
 315313                 ty = n->n_type;
 316314 
 317315                 if (xdebug) printf("->%d<-", ty);
 318316 
 319317                 if ( ty==DOUBLE) printf("d");
 320318                 else if ( ty==FLOAT ) printf("f");
 321319                 else printf("l");
 322320                 return;
 323321                 }
 324322 
 325323         case 'J': /* jump or ret? */
 326324                 {
 327325                         struct interpass *ip =
 328326                             DLIST_PREV((struct interpass *)p2env.epp, qelem);
 329327                         if (ip->type != IP_DEFLAB ||
 330328                             ip->ip_lbl != getlr(p, 'L')->n_lval)
 331329                                 expand(p, FOREFF, "jbr  LL");
 332330                         else
 333331                                 printf("ret");
 334332                 }
 335333                 break;
 336334 
 337335         case 'L':       /* type of left operand */
 338336         case 'R':       /* type of right operand */
 339337                 {
 340338                 register NODE *n;
 341339                 extern int xdebug;
 342340 
 343341                 n = getlr ( p, c);
 344342                 if (xdebug) printf("->%d<-", n->n_type);
 345343 
 346344                 prtype(n);
 347345                 return;
 348346                 }
 349347 
 350348         case 'Z':       /* complement mask for bit instr */
 351349                 printf("$%Ld", ~p->n_right->n_lval);
 352350                 return;
 353351 
 354352         case 'U':       /* 32 - n, for unsigned right shifts */
 355353                 printf("$" CONFMT, 32 - p->n_right->n_lval );
 356354                 return;
 357355 
 358356         case 'T':       /* rounded structure length for arguments */
 359357                 {
 360358                 int size;
 361359 
 362360                 size = p->n_stsize;
 363361                 SETOFF( size, 4);
 364362                 printf("$%d", size);
 365363                 return;
 366364                 }
 367365 
 368366         case 'S'/* structure assignment */
 369367                 {
 370368                         register NODE *l, *r;
 371369                         register int size;
 372370 
 373371                         l = r = NULL; /* XXX gcc */
 374372                         if( p->n_op == STASG ){
 375373                                 l = p->n_left;
 376374                                 r = p->n_right;
 377375 
 378376                                 }
 379377                         else if( p->n_op == STARG ){  /* store an arg into a temporary */
 380378                                 l = getlr( p, '3' );
 381379                                 r = p->n_left;
 382380                                 }
 383381                         else cerror( "STASG bad" );
 384382 
 385383                         if( r->n_op == ICON ) r->n_op = NAME;
 386384                         else if( r->n_op == REG ) r->n_op = OREG;
 387385                         else if( r->n_op != OREG ) cerror( "STASG-r" );
 388386 
 389387                         size = p->n_stsize;
 390388 
 391389                         if( size <= 0 || size > 65535 )
 392390                                 cerror("structure size <0=0 or >65535");
 393391 
 394392                         switch(size) {
 395393                                 case 1:
 396394                                         printf("        movb    ");
 397395                                         break;
 398396                                 case 2:
 399397                                         printf("        movw    ");
 400398                                         break;
 401399                                 case 4:
 402400                                         printf("        movl    ");
 403401                                         break;
 404402                                 case 8:
 405403                                         printf("        movq    ");
 406404                                         break;
 407405                                 default:
 408406                                         printf("        movc3   $%d,", size);
 409407                                         break;
 410408                         }
 411409                         adrput(stdout, r);
 412410                         printf(",");
 413411                         adrput(stdout, l);
 414412                         printf("\n");
 415413 
 416414                         if( r->n_op == NAME ) r->n_op = ICON;
 417415                         else if( r->n_op == OREG ) r->n_op = REG;
 418416 
 419417                         }
 420418                 break;
 421419 
 422420         default:
 423421                 comperr("illegal zzzcode '%c'", c);
 424422                 }
 425423         }
 426424 
 427425 void
 428426 rmove( int rt,int  rs, TWORD t ){
 429427         printf( "       %s      %s,%s\n",
 430428                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 431429                 rnames[rs], rnames[rt] );
 432430         }
 433431 
 434432 #if 0
 435433 setregs(){ /* set up temporary registers */
 436434         fregs = 6;      /* tbl- 6 free regs on VAX (0-5) */
 437435         ;
 438436         }
 439437 
 440438 szty(t){ /* size, in registers, needed to hold thing of type t */
 441439         return( (t==DOUBLE||t==FLOAT) ? 2 : 1 );
 442440         }
 443441 #endif
 444442 
 445443 int
 446444 rewfld( p ) NODE *p; {
 447445         return(1);
 448446         }
 449447 
 450448 #if 0
 451449 callreg(p) NODE *p; {
 452450         return( R0 );
 453451         }
 454452 
 455453 base( p ) register NODE *p; {
 456454         register int o = p->op;
 457455 
 458456         if( (o==ICON && p->name[0] != '\0')) return( 100 ); /* ie no base reg */
 459457         if( o==REG ) return( p->rval );
 460458     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
 461459                 return( p->left->rval );
 462460     if( o==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 463461                 return( p->rval + 0200*1 );
 464462         if( o==INCR && p->left->op==REG ) return( p->left->rval + 0200*2 );
 465463         if( o==ASG MINUS && p->left->op==REG) return( p->left->rval + 0200*4 );
 466464         if( o==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
 467465           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 468466                 return( p->left->left->rval + 0200*(1+2) );
 469467         return( -1 );
 470468         }
 471469 
 472470 offset( p, tyl ) register NODE *p; int tyl; {
 473471 
 474472         if( tyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) return( p->rval );
 475473         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
 476474               (p->right->op==ICON && p->right->name[0]=='\0')
 477475               && (1<<p->right->lval)==tyl))
 478476                 return( p->left->rval );
 479477         return( -1 );
 480478         }
 481479 #endif
 482480 
 483481 #if 0
 484482 void
 485483 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 486484         register NODE *t;
 487485         NODE *f;
 488486 
 489487         p->n_op = OREG;
 490488         f = p->n_left;  /* have to free this subtree later */
 491489 
 492490         /* init base */
 493491         switch (q->n_op) {
 494492                 case ICON:
 495493                 case REG:
 496494                 case OREG:
 497495                         t = q;
 498496                         break;
 499497 
 500498                 case MINUS:
 501499                         q->n_right->n_lval = -q->n_right->n_lval;
 502500                 case PLUS:
 503501                         t = q->n_right;
 504502                         break;
 505503 
 506504                 case UMUL:
 507505                         t = q->n_left->n_left;
 508506                         break;
 509507 
 510508                 default:
 511509                         cerror("illegal makeor2");
 512510                         t = NULL; /* XXX gcc */
 513511         }
 514512 
 515513         p->n_lval = t->n_lval;
 516514         p->n_name = t->n_name;
 517515 
 518516         /* init offset */
 519517         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
 520518 
 521519         tfree(f);
 522520         return;
 523521         }
 524522 
 525523 int
 526524 canaddr( p ) NODE *p; {
 527525         register int o = p->n_op;
 528526 
 529527         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left, STARNM|SOREG)) ) return(1);
 530528         return(0);
 531529         }
 532530 
 533531 shltype( o, p ) register NODE *p; {
 534532         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 535533         }
 536534 #endif
 537535 
 538536 int
 539537 fldexpand(NODE *p, int cookie, char **cp)
 540538 {
 541539         return 0;
 542540 }
 543541 
 544542 int
 545543 flshape( p ) register NODE *p; {
 546544         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 547545                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 548546         }
 549547 
 550548 int
 551549 shtemp( p ) register NODE *p; {
 552550         if( p->n_op == STARG ) p = p->n_left;
 553551         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 554552         }
 555553 
 556554 int
 557555 shumul( p, shape ) register NODE *p; int shape; {
 558556         register int o;
 559557         extern int xdebug;
 560558 
 561559         if (xdebug) {
 562560                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 563561                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 564562                 }
 565563 
 566564 
 567565         o = p->n_op;
 568566         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
 569567                 if (shape & STARNM)
 570568                         return SRDIR;
 571569 
 572570 #ifdef notyet
 573571         if( ( o == INCR || o == ASG MINUS ) &&
 574572             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 575573             p->n_right->n_name[0] == '\0' )
 576574                 {
 577575                 switch (p->n_left->n_type)
 578576                         {
 579577                         case CHAR|PTR:
 580578                         case UCHAR|PTR:
 581579                                 o = 1;
 582580                                 break;
 583581 
 584582                         case SHORT|PTR:
 585583                         case USHORT|PTR:
 586584                                 o = 2;
 587585                                 break;
 588586 
 589587                         case INT|PTR:
 590588                         case UNSIGNED|PTR:
 591589                         case LONG|PTR:
 592590                         case ULONG|PTR:
 593591                         case FLOAT|PTR:
 594592                                 o = 4;
 595593                                 break;
 596594 
 597595                         case DOUBLE|PTR:
 598596                                 o = 8;
 599597                                 break;
 600598 
 601599                         default:
 602600                                 if ( ISPTR(p->n_left->n_type) ) {
 603601                                         o = 4;
 604602                                         break;
 605603                                         }
 606604                                 else return(0);
 607605                         }
 608606                 return( p->n_right->n_lval == o ? STARREG : 0);
 609607                 }
 610608 #endif
 611609 
 612610         return( SRNOPE );
 613611         }
 614612 
 615613 void
 616614 adrcon( val ) CONSZ val; {
 617615         printf( "$" );
 618616         printf( CONFMT, val );
 619617         }
 620618 
 621619 void
 622620 conput(FILE *fp, NODE *p)
 623621 {
 624622         switch( p->n_op ){
 625623 
 626624         case ICON:
 627625                 acon( p );
 628626                 return;
 629627 
 630628         case REG:
 631629                 printf( "%s", rnames[p->n_rval] );
 632630                 return;
 633631 
 634632         default:
 635633                 cerror( "illegal conput" );
 636634                 }
 637635         }
 638636 
 639637 void
 640638 insput( p ) register NODE *p; {
 641639         cerror( "insput" );
 642640         }
 643641 
 644642 void
 645643 upput( p , size) register NODE *p; {
 646644         cerror( "upput" );
 647645         }
 648646 
 649647 void
 650648 adrput(FILE *fp, NODE *p)
 651649 {
 652650         register int r;
 653651         /* output an address, with offsets, from p */
 654652 
 655653         if( p->n_op == FLD ){
 656654                 p = p->n_left;
 657655                 }
 658656         switch( p->n_op ){
 659657 
 660658         case NAME:
 661659                 acon( p );
 662660                 return;
 663661 
 664662         case ICON:
 665663                 /* addressable value of the constant */
 666664                 if (p->n_name[0] == '\0') /* uses xxxab */
 667665                         printf("$");
 668666                 acon(p);
 669667                 return;
 670668 
 671669         case REG:
 672670                 printf( "%s", rnames[p->n_rval] );
 673671                 return;
 674672 
 675673         case OREG:
 676674                 r = p->n_rval;
 677675                 if( R2TEST(r) ){ /* double indexing */
 678676                         register int flags;
 679677 
 680678                         flags = R2UPK3(r);
 681679                         if( flags & 1 ) printf("*");
 682680                         if( flags & 4 ) printf("-");
 683681                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 684682                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 685683                         if( flags & 2 ) printf("+");
 686684                         printf( "[%s]", rnames[R2UPK2(r)] );
 687685                         return;
 688686                         }
 689687                 if( r == AP ){  /* in the argument region */
 690688                         if( p->n_lval <= 0 || p->n_name[0] != '\0' ) werror( "bad arg temp" );
 691689                         printf( CONFMT, p->n_lval );
 692690                         printf( "(ap)" );
 693691                         return;
 694692                         }
 695693                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 696694                 printf( "(%s)", rnames[p->n_rval] );
 697695                 return;
 698696 
 699697         case UMUL:
 700698                 /* STARNM or STARREG found */
 701699                 if( tshape(p, STARNM) ) {
 702700                         printf( "*" );
 703701                         adrput(0p->n_left);
 704702                         }
 705703                 else {  /* STARREG - really auto inc or dec */
 706704                         register NODE *q;
 707705 
 708706 /* tbl
 709707                         p = p->n_left;
 710708                         p->n_left->n_op = OREG;
 711709                         if( p->n_op == INCR ) {
 712710                                 adrput( p->n_left );
 713711                                 printf( "+" );
 714712                                 }
 715713                         else {
 716714                                 printf( "-" );
 717715                                 adrput( p->n_left );
 718716                                 }
 719717    tbl */
 720718 #ifdef notyet
 721719                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 722720                                 rnames[p->n_left->n_left->n_rval],
 723721                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 724722 #else
 725723                         printf("%c(%s)%c", '-',
 726724                                 rnames[p->n_left->n_left->n_rval],
 727725                                 '\0' );
 728726 #endif
 729727                         p->n_op = OREG;
 730728                         p->n_rval = p->n_left->n_left->n_rval;
 731729                         q = p->n_left;
 732730 #ifdef notyet
 733731 
 734732                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 735733 #else
 736734                         p->n_lval = 0;
 737735 #endif
 738736                         p->n_name[0] = '\0';
 739737                         tfree(q);
 740738                 }
 741739                 return;
 742740 
 743741         default:
 744742                 cerror( "illegal address" );
 745743                 return;
 746744         }
 747745 
 748746 }
 749747 
 750748 /*
 751749  * print out a constant
 752750  */
 753751 void
 754752 acon(NODE *p)
 755753 {
 756754 
 757755         if (p->n_name[0] == '\0') {
 758756                 printf(CONFMT, p->n_lval);
 759757         } else if( p->n_lval == 0 ) {
 760758                 printf("%s", p->n_name);
 761759         } else {
 762760                 printf("%s+", p->n_name);
 763761                 printf(CONFMT, p->n_lval);
 764762         }
 765763 }
 766764 
 767765 #if 0
 768766 genscall( p, cookie ) register NODE *p; {
 769767         /* structure valued call */
 770768         return( gencall( p, cookie ) );
 771769         }
 772770 
 773771 /* tbl */
 774772 int gc_numbytes;
 775773 /* tbl */
 776774 
 777775 gencall( p, cookie ) register NODE *p; {
 778776         /* generate the call given by p */
 779777         register NODE *p1, *ptemp;
 780778         register temp, temp1;
 781779         register m;
 782780 
 783781         if( p->right ) temp = argsize( p->right );
 784782         else temp = 0;
 785783 
 786784         if( p->op == STCALL || p->op == UNARY STCALL ){
 787785                 /* set aside room for structure return */
 788786 
 789787                 if( p->stsize > temp ) temp1 = p->stsize;
 790788                 else temp1 = temp;
 791789                 }
 792790 
 793791         if( temp > maxargs ) maxargs = temp;
 794792         SETOFF(temp1,4);
 795793 
 796794         if( p->right ){ /* make temp node, put offset in, and generate args */
 797795                 ptemp = talloc();
 798796                 ptemp->op = OREG;
 799797                 ptemp->lval = -1;
 800798                 ptemp->rval = SP;
 801799                 ptemp->name[0] = '\0';
 802800                 ptemp->rall = NOPREF;
 803801                 ptemp->su = 0;
 804802                 genargs( p->right, ptemp );
 805803                 nfree(ptemp);
 806804                 }
 807805 
 808806         p1 = p->left;
 809807         if( p1->op != ICON ){
 810808                 if( p1->op != REG ){
 811809                         if( p1->op != OREG || R2TEST(p1->rval) ){
 812810                                 if( p1->op != NAME ){
 813811                                         order( p1, INAREG );
 814812                                         }
 815813                                 }
 816814                         }
 817815                 }
 818816 
 819817 /*
 820818         if( p1->op == REG && p->rval == R5 ){
 821819                 cerror( "call register overwrite" );
 822820                 }
 823821  */
 824822 /* tbl
 825823         setup gc_numbytes so reference to ZC works */
 826824 
 827825         gc_numbytes = temp;
 828826 /* tbl */
 829827 
 830828         p->op = UNARY CALL;
 831829         m = match( p, INTAREG|INTBREG );
 832830 /* tbl
 833831         switch( temp ) {
 834832         case 0:
 835833                 break;
 836834         case 2:
 837835                 printf( "       tst     (sp)+\n" );
 838836                 break;
 839837         case 4:
 840838                 printf( "       cmp     (sp)+,(sp)+\n" );
 841839                 break;
 842840         default:
 843841                 printf( "       add     $%d,sp\n", temp);
 844842                 }
 845843    tbl */
 846844         return(m != MDONE);
 847845         }
 848846 #endif
 849847 
 850848 static char *
 851849 ccbranches[] = {
 852850         "jeql",
 853851         "jneq",
 854852         "jleq",
 855853         "jlss",
 856854         "jgeq",
 857855         "jgtr",
 858856         "jlequ",
 859857         "jlssu",
 860858         "jgequ",
 861859         "jgtru",
 862860 };
 863861 
 864862 /*
 865863  * printf conditional and unconditional branches
 866864  */
 867865 void
 868866 cbgen(int o, int lab)
 869867 {
 870868 
 871869         if (o == 0) {
 872870                 printf("        jbr     " LABFMT "\n", lab);
 873871         } else {
 874872                 if (o > UGT)
 875873                         comperr("bad conditional branch: %s", opst[o]);
 876874                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 877875         }
 878876 }
 879877 
 880878 static void
 881879 optim2(NODE *p, void *arg)
 882880 {
 883881         /* do local tree transformations and optimizations */
 884882 
 885883         register NODE *r;
 886884 
 887885         switch( p->n_op ) {
 888886 
 889887         case AND:
 890888                 /* commute L and R to eliminate compliments and constants */
 891889                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
 892890                         r = p->n_left;
 893891                         p->n_left = p->n_right;
 894892                         p->n_right = r;
 895893                         }
 896894 #if 0
 897895         case ASG AND:
 898896                 /* change meaning of AND to ~R&L - bic on pdp11 */
 899897                 r = p->n_right;
 900898                 if( r->op==ICON && r->name[0]==0 ) { /* compliment constant */
 901899                         r->lval = ~r->lval;
 902900                         }
 903901                 else if( r->op==COMPL ) { /* ~~A => A */
 904902                         r->op = FREE;
 905903                         p->right = r->left;
 906904                         }
 907905                 else { /* insert complement node */
 908906                         p->right = talloc();
 909907                         p->right->op = COMPL;
 910908                         p->right->rall = NOPREF;
 911909                         p->right->type = r->type;
 912910                         p->right->left = r;
 913911                         p->right->right = NULL;
 914912                         }
 915913                 break;
 916914 #endif
 917915                 }
 918916         }
 919917 
 920918 void
 921919 myreader(struct interpass *ipole)
 922920 {
 923921         struct interpass *ip;
 924922 
 925923         DLIST_FOREACH(ip, ipole, qelem) {
 926924                 if (ip->type != IP_NODE)
 927925                         continue;
 928926                 walkf(ip->ip_node, optim2, 0);
 929927         }
 930928 }
 931929 
 932930 void
 933931 mycanon(NODE *p)
 934932 {
 935933 }
 936934 
 937935 void
 938936 myoptim(struct interpass *ip)
 939937 {
 940938 }
 941939 
 942940 /*
 943941  * Return argument size in regs.
 944942  */
 945943 static int
 946944 argsiz(NODE *p)
 947945 {
 948946         TWORD t = p->n_type;
 949947 
 950948         if (t == STRTY || t == UNIONTY)
 951949                 return p->n_stsize/(SZINT/SZCHAR);
 952950         return szty(t);
 953951 }
 954952 
 955953 /*
 956954  * Last chance to do something before calling a function.
 957955  */
 958956 void
 959957 lastcall(NODE *p)
 960958 {
 961959         NODE *op = p;
 962960         int size = 0;
 963961 
 964962         /* Calculate argument sizes */
 965963         p->n_qual = 0;
 966964         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 967965                 return;
 968966         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 969967                 size += argsiz(p->n_right);
<>970 -        size += argsiz(p);
  968+        if (p->n_op != ASSIGN)
  969+                size += argsiz(p);
<_971970         op->n_qual = size; /* XXX */
 972971 }
 973972 
 974973 /*
 975974  * Return a class suitable for a specific type.
 976975  */
 977976 int
 978977 gclass(TWORD t)
 979978 {
 980979         return (szty(t) == 2 ? CLASSB : CLASSA);
 981980 }
 982981 
 983982 /*
 984983  * For class c, find worst-case displacement of the number of
 985984  * registers in the array r[] indexed by class.
 986985  */
 987986 int
 988987 COLORMAP(int c, int *r)
 989988 {
 990989         int num;
 991990 
 992991         switch (c) {
 993992         case CLASSA:
 994993                 /* there are 12 classa, so min 6 classb are needed to block */
 995994                 num = r[CLASSB] * 2;
 996995                 num += r[CLASSA];
 997996                 return num < 12;
 998997         case CLASSB:
 999998                 /* 6 classa may block all classb */
 1000999                 num = r[CLASSB] + r[CLASSA];
 10011000                 return num < 6;
 10021001         }
 10031002         comperr("COLORMAP");
 10041003         return 0; /* XXX gcc */
 10051004 }
 10061005 
 10071006 /*
 10081007  * Special shapes.
 10091008  */
 10101009 int
 10111010 special(NODE *p, int shape)
 10121011 {
 10131012         return SRNOPE;
 10141013 }
 10151014 
 10161015 /*
 10171016  * Target-dependent command-line options.
 10181017  */
 10191018 void
 10201019 mflags(char *str)
 10211020 {
 10221021 }
 10231022 /*
 10241023  * Do something target-dependent for xasm arguments.
 10251024  * Supposed to find target-specific constraints and rewrite them.
 10261025  */
 10271026 int
 10281027 myxasm(struct interpass *ip, NODE *p)
 10291028 {
 10301029         return 0;
 10311030 }
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-11-01 13:30 +0100