Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.7
 
1.8
 
MAIN:ragge:20080927073522
 
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);
 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 
<>534 -        if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left)) ) return(1);
  534+        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; {
<>539 -        return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left)) );
  539+        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;
<>558 -        return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left)) );
  558+        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
<>562 -shumul( p ) register NODE *p; {
  562+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;
<>573 -        if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON ) return( STARNM );
  573+        if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
  574+                if (shape & STARNM)
  575+                        return SRDIR;
574576 
 575577 #ifdef notyet
 576578         if( ( o == INCR || o == ASG MINUS ) &&
 577579             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 578580             p->n_right->n_name[0] == '\0' )
 579581                 {
 580582                 switch (p->n_left->n_type)
 581583                         {
 582584                         case CHAR|PTR:
 583585                         case UCHAR|PTR:
 584586                                 o = 1;
 585587                                 break;
 586588 
 587589                         case SHORT|PTR:
 588590                         case USHORT|PTR:
 589591                                 o = 2;
 590592                                 break;
 591593 
 592594                         case INT|PTR:
 593595                         case UNSIGNED|PTR:
 594596                         case LONG|PTR:
 595597                         case ULONG|PTR:
 596598                         case FLOAT|PTR:
 597599                                 o = 4;
 598600                                 break;
 599601 
 600602                         case DOUBLE|PTR:
 601603                                 o = 8;
 602604                                 break;
 603605 
 604606                         default:
 605607                                 if ( ISPTR(p->n_left->n_type) ) {
 606608                                         o = 4;
 607609                                         break;
 608610                                         }
 609611                                 else return(0);
 610612                         }
 611613                 return( p->n_right->n_lval == o ? STARREG : 0);
 612614                 }
 613615 #endif
 614616 
<>615 -        return( 0 );
  617+        return( SRNOPE );
<_616618         }
 617619 
 618620 void
 619621 adrcon( val ) CONSZ val; {
 620622         printf( "$" );
 621623         printf( CONFMT, val );
 622624         }
 623625 
 624626 void
 625627 conput(FILE *fp, NODE *p)
 626628 {
 627629         switch( p->n_op ){
 628630 
 629631         case ICON:
 630632                 acon( p );
 631633                 return;
 632634 
 633635         case REG:
 634636                 printf( "%s", rnames[p->n_rval] );
 635637                 return;
 636638 
 637639         default:
 638640                 cerror( "illegal conput" );
 639641                 }
 640642         }
 641643 
 642644 void
 643645 insput( p ) register NODE *p; {
 644646         cerror( "insput" );
 645647         }
 646648 
 647649 void
 648650 upput( p , size) register NODE *p; {
 649651         cerror( "upput" );
 650652         }
 651653 
 652654 void
 653655 adrput(FILE *fp, NODE *p)
 654656 {
 655657         register int r;
 656658         /* output an address, with offsets, from p */
 657659 
 658660         if( p->n_op == FLD ){
 659661                 p = p->n_left;
 660662                 }
 661663         switch( p->n_op ){
 662664 
 663665         case NAME:
 664666                 acon( p );
 665667                 return;
 666668 
 667669         case ICON:
 668670                 /* addressable value of the constant */
 669671                 if (p->n_name[0] == '\0') /* uses xxxab */
 670672                         printf("$");
 671673                 acon(p);
 672674                 return;
 673675 
 674676         case REG:
 675677                 printf( "%s", rnames[p->n_rval] );
 676678                 return;
 677679 
 678680         case OREG:
 679681                 r = p->n_rval;
 680682                 if( R2TEST(r) ){ /* double indexing */
 681683                         register int flags;
 682684 
 683685                         flags = R2UPK3(r);
 684686                         if( flags & 1 ) printf("*");
 685687                         if( flags & 4 ) printf("-");
 686688                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 687689                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 688690                         if( flags & 2 ) printf("+");
 689691                         printf( "[%s]", rnames[R2UPK2(r)] );
 690692                         return;
 691693                         }
 692694                 if( r == AP ){  /* in the argument region */
 693695                         if( p->n_lval <= 0 || p->n_name[0] != '\0' ) werror( "bad arg temp" );
 694696                         printf( CONFMT, p->n_lval );
 695697                         printf( "(ap)" );
 696698                         return;
 697699                         }
 698700                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 699701                 printf( "(%s)", rnames[p->n_rval] );
 700702                 return;
 701703 
 702704         case UMUL:
 703705                 /* STARNM or STARREG found */
 704706                 if( tshape(p, STARNM) ) {
 705707                         printf( "*" );
 706708                         adrput(0p->n_left);
 707709                         }
 708710                 else {  /* STARREG - really auto inc or dec */
 709711                         register NODE *q;
 710712 
 711713 /* tbl
 712714                         p = p->n_left;
 713715                         p->n_left->n_op = OREG;
 714716                         if( p->n_op == INCR ) {
 715717                                 adrput( p->n_left );
 716718                                 printf( "+" );
 717719                                 }
 718720                         else {
 719721                                 printf( "-" );
 720722                                 adrput( p->n_left );
 721723                                 }
 722724    tbl */
 723725 #ifdef notyet
 724726                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 725727                                 rnames[p->n_left->n_left->n_rval],
 726728                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 727729 #else
 728730                         printf("%c(%s)%c", '-',
 729731                                 rnames[p->n_left->n_left->n_rval],
 730732                                 '\0' );
 731733 #endif
 732734                         p->n_op = OREG;
 733735                         p->n_rval = p->n_left->n_left->n_rval;
 734736                         q = p->n_left;
 735737 #ifdef notyet
 736738 
 737739                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 738740 #else
 739741                         p->n_lval = 0;
 740742 #endif
 741743                         p->n_name[0] = '\0';
 742744                         tfree(q);
 743745                 }
 744746                 return;
 745747 
 746748         default:
 747749                 cerror( "illegal address" );
 748750                 return;
 749751         }
 750752 
 751753 }
 752754 
 753755 /*
 754756  * print out a constant
 755757  */
 756758 void
 757759 acon(NODE *p)
 758760 {
 759761 
 760762         if (p->n_name[0] == '\0') {
 761763                 printf(CONFMT, p->n_lval);
 762764         } else if( p->n_lval == 0 ) {
 763765                 printf("%s", p->n_name);
 764766         } else {
 765767                 printf("%s+", p->n_name);
 766768                 printf(CONFMT, p->n_lval);
 767769         }
 768770 }
 769771 
 770772 #if 0
 771773 genscall( p, cookie ) register NODE *p; {
 772774         /* structure valued call */
 773775         return( gencall( p, cookie ) );
 774776         }
 775777 
 776778 /* tbl */
 777779 int gc_numbytes;
 778780 /* tbl */
 779781 
 780782 gencall( p, cookie ) register NODE *p; {
 781783         /* generate the call given by p */
 782784         register NODE *p1, *ptemp;
 783785         register temp, temp1;
 784786         register m;
 785787 
 786788         if( p->right ) temp = argsize( p->right );
 787789         else temp = 0;
 788790 
 789791         if( p->op == STCALL || p->op == UNARY STCALL ){
 790792                 /* set aside room for structure return */
 791793 
 792794                 if( p->stsize > temp ) temp1 = p->stsize;
 793795                 else temp1 = temp;
 794796                 }
 795797 
 796798         if( temp > maxargs ) maxargs = temp;
 797799         SETOFF(temp1,4);
 798800 
 799801         if( p->right ){ /* make temp node, put offset in, and generate args */
 800802                 ptemp = talloc();
 801803                 ptemp->op = OREG;
 802804                 ptemp->lval = -1;
 803805                 ptemp->rval = SP;
 804806                 ptemp->name[0] = '\0';
 805807                 ptemp->rall = NOPREF;
 806808                 ptemp->su = 0;
 807809                 genargs( p->right, ptemp );
 808810                 nfree(ptemp);
 809811                 }
 810812 
 811813         p1 = p->left;
 812814         if( p1->op != ICON ){
 813815                 if( p1->op != REG ){
 814816                         if( p1->op != OREG || R2TEST(p1->rval) ){
 815817                                 if( p1->op != NAME ){
 816818                                         order( p1, INAREG );
 817819                                         }
 818820                                 }
 819821                         }
 820822                 }
 821823 
 822824 /*
 823825         if( p1->op == REG && p->rval == R5 ){
 824826                 cerror( "call register overwrite" );
 825827                 }
 826828  */
 827829 /* tbl
 828830         setup gc_numbytes so reference to ZC works */
 829831 
 830832         gc_numbytes = temp;
 831833 /* tbl */
 832834 
 833835         p->op = UNARY CALL;
 834836         m = match( p, INTAREG|INTBREG );
 835837 /* tbl
 836838         switch( temp ) {
 837839         case 0:
 838840                 break;
 839841         case 2:
 840842                 printf( "       tst     (sp)+\n" );
 841843                 break;
 842844         case 4:
 843845                 printf( "       cmp     (sp)+,(sp)+\n" );
 844846                 break;
 845847         default:
 846848                 printf( "       add     $%d,sp\n", temp);
 847849                 }
 848850    tbl */
 849851         return(m != MDONE);
 850852         }
 851853 #endif
 852854 
 853855 static char *
 854856 ccbranches[] = {
 855857         "jeql",
 856858         "jneq",
 857859         "jleq",
 858860         "jlss",
 859861         "jgeq",
 860862         "jgtr",
 861863         "jlequ",
 862864         "jlssu",
 863865         "jgequ",
 864866         "jgtru",
 865867 };
 866868 
 867869 /*
 868870  * printf conditional and unconditional branches
 869871  */
 870872 void
 871873 cbgen(int o, int lab)
 872874 {
 873875 
 874876         if (o == 0) {
 875877                 printf("        jbr     " LABFMT "\n", lab);
 876878         } else {
 877879                 if (o > UGT)
 878880                         comperr("bad conditional branch: %s", opst[o]);
 879881                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 880882         }
 881883 }
 882884 
 883885 static void
 884886 optim2(NODE *p)
 885887 {
 886888         /* do local tree transformations and optimizations */
 887889 
 888890         register NODE *r;
 889891 
 890892         switch( p->n_op ) {
 891893 
 892894         case AND:
 893895                 /* commute L and R to eliminate compliments and constants */
 894896                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
 895897                         r = p->n_left;
 896898                         p->n_left = p->n_right;
 897899                         p->n_right = r;
 898900                         }
 899901 #if 0
 900902         case ASG AND:
 901903                 /* change meaning of AND to ~R&L - bic on pdp11 */
 902904                 r = p->n_right;
 903905                 if( r->op==ICON && r->name[0]==0 ) { /* compliment constant */
 904906                         r->lval = ~r->lval;
 905907                         }
 906908                 else if( r->op==COMPL ) { /* ~~A => A */
 907909                         r->op = FREE;
 908910                         p->right = r->left;
 909911                         }
 910912                 else { /* insert complement node */
 911913                         p->right = talloc();
 912914                         p->right->op = COMPL;
 913915                         p->right->rall = NOPREF;
 914916                         p->right->type = r->type;
 915917                         p->right->left = r;
 916918                         p->right->right = NULL;
 917919                         }
 918920                 break;
 919921 #endif
 920922                 }
 921923         }
 922924 
 923925 void
 924926 myreader(struct interpass *ipole)
 925927 {
 926928         struct interpass *ip;
 927929 
 928930         DLIST_FOREACH(ip, ipole, qelem) {
 929931                 if (ip->type != IP_NODE)
 930932                         continue;
 931933                 walkf(ip->ip_node, optim2);
 932934         }
 933935 }
 934936 
 935937 void
 936938 mycanon(NODE *p)
 937939 {
 938940 }
 939941 
 940942 void
 941943 myoptim(struct interpass *ip)
 942944 {
 943945 }
 944946 
 945947 /*
 946948  * Return argument size in regs.
 947949  */
 948950 static int
 949951 argsiz(NODE *p)
 950952 {
 951953         TWORD t = p->n_type;
 952954 
 953955         if (t == STRTY || t == UNIONTY)
 954956                 return p->n_stsize/(SZINT/SZCHAR);
 955957         return szty(t);
 956958 }
 957959 
 958960 /*
 959961  * Last chance to do something before calling a function.
 960962  */
 961963 void
 962964 lastcall(NODE *p)
 963965 {
 964966         NODE *op = p;
 965967         int size = 0;
 966968 
 967969         /* Calculate argument sizes */
 968970         p->n_qual = 0;
 969971         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 970972                 return;
 971973         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 972974                 size += argsiz(p->n_right);
 973975         size += argsiz(p);
 974976         op->n_qual = size; /* XXX */
 975977 }
 976978 
 977979 /*
 978980  * Return a class suitable for a specific type.
 979981  */
 980982 int
 981983 gclass(TWORD t)
 982984 {
 983985         return (szty(t) == 2 ? CLASSB : CLASSA);
 984986 }
 985987 
 986988 /*
 987989  * For class c, find worst-case displacement of the number of
 988990  * registers in the array r[] indexed by class.
 989991  */
 990992 int
 991993 COLORMAP(int c, int *r)
 992994 {
 993995         int num;
 994996 
 995997         switch (c) {
 996998         case CLASSA:
 997999                 /* there are 12 classa, so min 6 classb are needed to block */
 9981000                 num = r[CLASSB] * 2;
 9991001                 num += r[CLASSA];
 10001002                 return num < 12;
 10011003         case CLASSB:
 10021004                 /* 6 classa may block all classb */
 10031005                 num = r[CLASSB] + r[CLASSA];
 10041006                 return num < 6;
 10051007         }
 10061008         comperr("COLORMAP");
 10071009         return 0; /* XXX gcc */
 10081010 }
 10091011 
 10101012 /*
 10111013  * Special shapes.
 10121014  */
 10131015 int
 10141016 special(NODE *p, int shape)
 10151017 {
 10161018         return SRNOPE;
 10171019 }
 10181020 
 10191021 /*
 10201022  * Target-dependent command-line options.
 10211023  */
 10221024 void
 10231025 mflags(char *str)
 10241026 {
 10251027 }
 10261028 /*
 10271029  * Do something target-dependent for xasm arguments.
 10281030  * Supposed to find target-specific constraints and rewrite them.
 10291031  */
 10301032 int
 10311033 myxasm(struct interpass *ip, NODE *p)
 10321034 {
 10331035         return 0;
 10341036 }
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-29 02:03 +0100