Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.14
 
1.15
 
MAIN:ragge:20110628073847
 
local2.c
_>11 /*      $Id$    */
 22 /*
 33  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
 44  *
 55  * Redistribution and use in source and binary forms, with or without
 66  * modification, are permitted provided that the following conditions
 77  * are met:
 88  *
 99  * Redistributions of source code and documentation must retain the above
 1010  * copyright notice, this list of conditions and the following disclaimer.
 1111  * Redistributions in binary form must reproduce the above copyright
 1212  * notice, this list of conditionsand the following disclaimer in the
 1313  * documentation and/or other materials provided with the distribution.
 1414  * All advertising materials mentioning features or use of this software
 1515  * must display the following acknowledgement:
 1616  *      This product includes software developed or owned by Caldera
 1717  *      International, Inc.
 1818  * Neither the name of Caldera International, Inc. nor the names of other
 1919  * contributors may be used to endorse or promote products derived from
 2020  * this software without specific prior written permission.
 2121  *
 2222  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
 2323  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
 2424  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 2525  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 2626  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
 2727  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 2828  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 2929  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 3030  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
 3131  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 3232  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 3333  * POSSIBILITY OF SUCH DAMAGE.
 3434  */
 3535 
 3636 # include "pass2.h"
 3737 # include "ctype.h"
 3838 /* a lot of the machine dependent parts of the second pass */
 3939 
 4040 static void prtype(NODE *n);
 4141 static void acon(NODE *p);
 4242 
 4343 /*
 4444  * Print out the prolog assembler.
 4545  * addto and regoff are already calculated.
 4646  */
 4747 void
 4848 prologue(struct interpass_prolog *ipp)
 4949 {
<>50 -        printf("        .word 0x%lx\n", ipp->ipp_regs[0]);
  50+        printf("        .word 0x%x\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 
<>113 -        "r0", "r1", "r2", "r3", "r4", "r5",
 114 -        "r6", "r7", "r8", "r9", "r10", "r11",
 115 -        "ap", "fp", "sp", "pc",
  113+        "%r0", "%r1", "%r2", "%r3", "%r4", "%r5",
  114+        "%r6", "%r7", "%r8", "%r9", "%r10", "%r11",
  115+        "%ap", "%fp", "%sp", "%pc",
116116         /* The concatenated regs has the name of the lowest */
<>117 -        "r0", "r1", "r2", "r3", "r4", "r5",
 118 -        "r6", "r7", "r8", "r9", "r10"
  117+        "%r0", "%r1", "%r2", "%r3", "%r4", "%r5",
  118+        "%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 */
 280280                 printf("$%d", p->n_qual);
 281281                 break;
 282282 
 283283         case 'D':       /* INCR and DECR */
 284284                 zzzcode(p->n_left, 'A');
 285285                 printf("\n      ");
 286286 
 287287 #if 0
 288288         case 'E':       /* INCR and DECR, FOREFF */
 289289                 if (p->n_right->n_lval == 1)
 290290                         {
 291291                         printf("%s", (p->n_op == INCR ? "inc" : "dec") );
 292292                         prtype(p->n_left);
 293293                         printf("        ");
 294294                         adrput(stdout, p->n_left);
 295295                         return;
 296296                         }
 297297                 printf("%s", (p->n_op == INCR ? "add" : "sub") );
 298298                 prtype(p->n_left);
 299299                 printf("2       ");
 300300                 adrput(stdout, p->n_right);
 301301                 printf(",");
 302302                 adrput(p->n_left);
 303303                 return;
 304304 #endif
 305305 
 306306         case 'F':       /* register type of right operand */
 307307                 {
 308308                 register NODE *n;
 309309                 extern int xdebug;
 310310                 register int ty;
 311311 
 312312                 n = getlr( p, 'R' );
 313313                 ty = n->n_type;
 314314 
 315315                 if (xdebug) printf("->%d<-", ty);
 316316 
 317317                 if ( ty==DOUBLE) printf("d");
 318318                 else if ( ty==FLOAT ) printf("f");
 319319                 else printf("l");
 320320                 return;
 321321                 }
 322322 
 323323         case 'J': /* jump or ret? */
 324324                 {
 325325                         struct interpass *ip =
 326326                             DLIST_PREV((struct interpass *)p2env.epp, qelem);
 327327                         if (ip->type != IP_DEFLAB ||
 328328                             ip->ip_lbl != getlr(p, 'L')->n_lval)
 329329                                 expand(p, FOREFF, "jbr  LL");
 330330                         else
 331331                                 printf("ret");
 332332                 }
 333333                 break;
 334334 
 335335         case 'L':       /* type of left operand */
 336336         case 'R':       /* type of right operand */
 337337                 {
 338338                 register NODE *n;
 339339                 extern int xdebug;
 340340 
 341341                 n = getlr ( p, c);
 342342                 if (xdebug) printf("->%d<-", n->n_type);
 343343 
 344344                 prtype(n);
 345345                 return;
 346346                 }
 347347 
 348348         case 'Z':       /* complement mask for bit instr */
 349349                 printf("$%Ld", ~p->n_right->n_lval);
 350350                 return;
 351351 
 352352         case 'U':       /* 32 - n, for unsigned right shifts */
 353353                 printf("$" CONFMT, 32 - p->n_right->n_lval );
 354354                 return;
 355355 
 356356         case 'T':       /* rounded structure length for arguments */
 357357                 {
 358358                 int size;
 359359 
 360360                 size = p->n_stsize;
 361361                 SETOFF( size, 4);
 362362                 printf("$%d", size);
 363363                 return;
 364364                 }
 365365 
 366366         case 'S'/* structure assignment */
 367367                 {
 368368                         register NODE *l, *r;
 369369                         register int size;
 370370 
 371371                         size = p->n_stsize;
 372372                         l = r = NULL; /* XXX gcc */
 373373                         if( p->n_op == STASG ){
 374374                                 l = p->n_left;
 375375                                 r = p->n_right;
 376376 
 377377                                 }
 378378                         else if( p->n_op == STARG ){
 379379                                 /* store an arg into a temporary */
 380380                                 printf("\tsubl2 $%d,%%sp\n",
 381381                                     size < 4 ? 4 : size);
 382382                                 l = mklnode(OREG, 0, SP, INT);
 383383                                 r = p->n_left;
 384384                                 }
 385385                         else cerror( "STASG bad" );
 386386 
 387387                         if( r->n_op == ICON ) r->n_op = NAME;
 388388                         else if( r->n_op == REG ) r->n_op = OREG;
 389389                         else if( r->n_op != OREG ) cerror( "STASG-r" );
 390390 
 391391                         if( size <= 0 || size > 65535 )
 392392                                 cerror("structure size <0=0 or >65535");
 393393 
 394394                         switch(size) {
 395395                                 case 1:
 396396                                         printf("        movb    ");
 397397                                         break;
 398398                                 case 2:
 399399                                         printf("        movw    ");
 400400                                         break;
 401401                                 case 4:
 402402                                         printf("        movl    ");
 403403                                         break;
 404404                                 case 8:
 405405                                         printf("        movq    ");
 406406                                         break;
 407407                                 default:
 408408                                         printf("        movc3   $%d,", size);
 409409                                         break;
 410410                         }
 411411                         adrput(stdout, r);
 412412                         printf(",");
 413413                         adrput(stdout, l);
 414414                         printf("\n");
 415415 
 416416                         if( r->n_op == NAME ) r->n_op = ICON;
 417417                         else if( r->n_op == OREG ) r->n_op = REG;
 418418                         if (p->n_op == STARG)
 419419                                 tfree(l);
 420420 
 421421                         }
 422422                 break;
 423423 
 424424         default:
 425425                 comperr("illegal zzzcode '%c'", c);
 426426                 }
 427427         }
 428428 
 429429 void
 430430 rmove( int rt,int  rs, TWORD t ){
 431431         printf( "       %s      %s,%s\n",
 432432                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 433433                 rnames[rs], rnames[rt] );
 434434         }
 435435 
 436436 #if 0
 437437 setregs(){ /* set up temporary registers */
 438438         fregs = 6;      /* tbl- 6 free regs on VAX (0-5) */
 439439         ;
 440440         }
 441441 
 442442 szty(t){ /* size, in registers, needed to hold thing of type t */
 443443         return( (t==DOUBLE||t==FLOAT) ? 2 : 1 );
 444444         }
 445445 #endif
 446446 
 447447 int
 448448 rewfld( p ) NODE *p; {
 449449         return(1);
 450450         }
 451451 
 452452 #if 0
 453453 callreg(p) NODE *p; {
 454454         return( R0 );
 455455         }
 456456 
 457457 base( p ) register NODE *p; {
 458458         register int o = p->op;
 459459 
 460460         if( (o==ICON && p->name[0] != '\0')) return( 100 ); /* ie no base reg */
 461461         if( o==REG ) return( p->rval );
 462462     if( (o==PLUS || o==MINUS) && p->left->op == REG && p->right->op==ICON)
 463463                 return( p->left->rval );
 464464     if( o==OREG && !R2TEST(p->rval) && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 465465                 return( p->rval + 0200*1 );
 466466         if( o==INCR && p->left->op==REG ) return( p->left->rval + 0200*2 );
 467467         if( o==ASG MINUS && p->left->op==REG) return( p->left->rval + 0200*4 );
 468468         if( o==UNARY MUL && p->left->op==INCR && p->left->left->op==REG
 469469           && (p->type==INT || p->type==UNSIGNED || ISPTR(p->type)) )
 470470                 return( p->left->left->rval + 0200*(1+2) );
 471471         return( -1 );
 472472         }
 473473 
 474474 offset( p, tyl ) register NODE *p; int tyl; {
 475475 
 476476         if( tyl==1 && p->op==REG && (p->type==INT || p->type==UNSIGNED) ) return( p->rval );
 477477         if( (p->op==LS && p->left->op==REG && (p->left->type==INT || p->left->type==UNSIGNED) &&
 478478               (p->right->op==ICON && p->right->name[0]=='\0')
 479479               && (1<<p->right->lval)==tyl))
 480480                 return( p->left->rval );
 481481         return( -1 );
 482482         }
 483483 #endif
 484484 
 485485 #if 0
 486486 void
 487487 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 488488         register NODE *t;
 489489         NODE *f;
 490490 
 491491         p->n_op = OREG;
 492492         f = p->n_left;  /* have to free this subtree later */
 493493 
 494494         /* init base */
 495495         switch (q->n_op) {
 496496                 case ICON:
 497497                 case REG:
 498498                 case OREG:
 499499                         t = q;
 500500                         break;
 501501 
 502502                 case MINUS:
 503503                         q->n_right->n_lval = -q->n_right->n_lval;
 504504                 case PLUS:
 505505                         t = q->n_right;
 506506                         break;
 507507 
 508508                 case UMUL:
 509509                         t = q->n_left->n_left;
 510510                         break;
 511511 
 512512                 default:
 513513                         cerror("illegal makeor2");
 514514                         t = NULL; /* XXX gcc */
 515515         }
 516516 
 517517         p->n_lval = t->n_lval;
 518518         p->n_name = t->n_name;
 519519 
 520520         /* init offset */
 521521         p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
 522522 
 523523         tfree(f);
 524524         return;
 525525         }
 526526 
 527527 int
 528528 canaddr( p ) NODE *p; {
 529529         register int o = p->n_op;
 530530 
 531531         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left, STARNM|SOREG)) ) return(1);
 532532         return(0);
 533533         }
 534534 
 535535 shltype( o, p ) register NODE *p; {
 536536         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 537537         }
 538538 #endif
 539539 
 540540 int
 541541 fldexpand(NODE *p, int cookie, char **cp)
 542542 {
 543543         return 0;
 544544 }
 545545 
 546546 int
 547547 flshape( p ) register NODE *p; {
 548548         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 549549                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 550550         }
 551551 
 552552 int
 553553 shtemp( p ) register NODE *p; {
 554554         if( p->n_op == STARG ) p = p->n_left;
 555555         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left, STARNM|SOREG)) );
 556556         }
 557557 
 558558 int
 559559 shumul( p, shape ) register NODE *p; int shape; {
 560560         register int o;
 561561         extern int xdebug;
 562562 
 563563         if (xdebug) {
 564564                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 565565                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 566566                 }
 567567 
 568568 
 569569         o = p->n_op;
 570570         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON )
 571571                 if (shape & STARNM)
 572572                         return SRDIR;
 573573 
 574574 #ifdef notyet
 575575         if( ( o == INCR || o == ASG MINUS ) &&
 576576             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 577577             p->n_right->n_name[0] == '\0' )
 578578                 {
 579579                 switch (p->n_left->n_type)
 580580                         {
 581581                         case CHAR|PTR:
 582582                         case UCHAR|PTR:
 583583                                 o = 1;
 584584                                 break;
 585585 
 586586                         case SHORT|PTR:
 587587                         case USHORT|PTR:
 588588                                 o = 2;
 589589                                 break;
 590590 
 591591                         case INT|PTR:
 592592                         case UNSIGNED|PTR:
 593593                         case LONG|PTR:
 594594                         case ULONG|PTR:
 595595                         case FLOAT|PTR:
 596596                                 o = 4;
 597597                                 break;
 598598 
 599599                         case DOUBLE|PTR:
 600600                                 o = 8;
 601601                                 break;
 602602 
 603603                         default:
 604604                                 if ( ISPTR(p->n_left->n_type) ) {
 605605                                         o = 4;
 606606                                         break;
 607607                                         }
 608608                                 else return(0);
 609609                         }
 610610                 return( p->n_right->n_lval == o ? STARREG : 0);
 611611                 }
 612612 #endif
 613613 
 614614         return( SRNOPE );
 615615         }
 616616 
 617617 void
 618618 adrcon( val ) CONSZ val; {
 619619         printf( "$" );
 620620         printf( CONFMT, val );
 621621         }
 622622 
 623623 void
 624624 conput(FILE *fp, NODE *p)
 625625 {
 626626         switch( p->n_op ){
 627627 
 628628         case ICON:
 629629                 acon( p );
 630630                 return;
 631631 
 632632         case REG:
 633633                 printf( "%s", rnames[p->n_rval] );
 634634                 return;
 635635 
 636636         default:
 637637                 cerror( "illegal conput" );
 638638                 }
 639639         }
 640640 
 641641 void
 642642 insput( p ) register NODE *p; {
 643643         cerror( "insput" );
 644644         }
 645645 
 646646 void
 647647 upput( p , size) register NODE *p; {
 648648         cerror( "upput" );
 649649         }
 650650 
 651651 void
 652652 adrput(FILE *fp, NODE *p)
 653653 {
 654654         register int r;
 655655         /* output an address, with offsets, from p */
 656656 
 657657         if( p->n_op == FLD ){
 658658                 p = p->n_left;
 659659                 }
 660660         switch( p->n_op ){
 661661 
 662662         case NAME:
 663663                 acon( p );
 664664                 return;
 665665 
 666666         case ICON:
 667667                 /* addressable value of the constant */
 668668                 if (p->n_name[0] == '\0') /* uses xxxab */
 669669                         printf("$");
 670670                 acon(p);
 671671                 return;
 672672 
 673673         case REG:
 674674                 printf( "%s", rnames[p->n_rval] );
 675675                 return;
 676676 
 677677         case OREG:
 678678                 r = p->n_rval;
 679679                 if( R2TEST(r) ){ /* double indexing */
 680680                         register int flags;
 681681 
 682682                         flags = R2UPK3(r);
 683683                         if( flags & 1 ) printf("*");
 684684                         if( flags & 4 ) printf("-");
 685685                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 686686                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 687687                         if( flags & 2 ) printf("+");
 688688                         printf( "[%s]", rnames[R2UPK2(r)] );
 689689                         return;
 690690                         }
 691691                 if( r == AP ){  /* in the argument region */
 692692                         if( p->n_lval <= 0 || p->n_name[0] != '\0' ) werror( "bad arg temp" );
 693693                         printf( CONFMT, p->n_lval );
 694694                         printf( "(ap)" );
 695695                         return;
 696696                         }
 697697                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 698698                 printf( "(%s)", rnames[p->n_rval] );
 699699                 return;
 700700 
 701701         case UMUL:
 702702                 /* STARNM or STARREG found */
 703703                 if( tshape(p, STARNM) ) {
 704704                         printf( "*" );
 705705                         adrput(0p->n_left);
 706706                         }
 707707                 else {  /* STARREG - really auto inc or dec */
 708708                         register NODE *q;
 709709 
 710710 /* tbl
 711711                         p = p->n_left;
 712712                         p->n_left->n_op = OREG;
 713713                         if( p->n_op == INCR ) {
 714714                                 adrput( p->n_left );
 715715                                 printf( "+" );
 716716                                 }
 717717                         else {
 718718                                 printf( "-" );
 719719                                 adrput( p->n_left );
 720720                                 }
 721721    tbl */
 722722 #ifdef notyet
 723723                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 724724                                 rnames[p->n_left->n_left->n_rval],
 725725                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 726726 #else
 727727                         printf("%c(%s)%c", '-',
 728728                                 rnames[p->n_left->n_left->n_rval],
 729729                                 '\0' );
 730730 #endif
 731731                         p->n_op = OREG;
 732732                         p->n_rval = p->n_left->n_left->n_rval;
 733733                         q = p->n_left;
 734734 #ifdef notyet
 735735 
 736736                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 737737 #else
 738738                         p->n_lval = 0;
 739739 #endif
 740740                         p->n_name[0] = '\0';
 741741                         tfree(q);
 742742                 }
 743743                 return;
 744744 
 745745         default:
 746746                 cerror( "illegal address" );
 747747                 return;
 748748         }
 749749 
 750750 }
 751751 
 752752 /*
 753753  * print out a constant
 754754  */
 755755 void
 756756 acon(NODE *p)
 757757 {
 758758 
 759759         if (p->n_name[0] == '\0') {
 760760                 printf(CONFMT, p->n_lval);
 761761         } else if( p->n_lval == 0 ) {
 762762                 printf("%s", p->n_name);
 763763         } else {
 764764                 printf("%s+", p->n_name);
 765765                 printf(CONFMT, p->n_lval);
 766766         }
 767767 }
 768768 
 769769 #if 0
 770770 genscall( p, cookie ) register NODE *p; {
 771771         /* structure valued call */
 772772         return( gencall( p, cookie ) );
 773773         }
 774774 
 775775 /* tbl */
 776776 int gc_numbytes;
 777777 /* tbl */
 778778 
 779779 gencall( p, cookie ) register NODE *p; {
 780780         /* generate the call given by p */
 781781         register NODE *p1, *ptemp;
 782782         register temp, temp1;
 783783         register m;
 784784 
 785785         if( p->right ) temp = argsize( p->right );
 786786         else temp = 0;
 787787 
 788788         if( p->op == STCALL || p->op == UNARY STCALL ){
 789789                 /* set aside room for structure return */
 790790 
 791791                 if( p->stsize > temp ) temp1 = p->stsize;
 792792                 else temp1 = temp;
 793793                 }
 794794 
 795795         if( temp > maxargs ) maxargs = temp;
 796796         SETOFF(temp1,4);
 797797 
 798798         if( p->right ){ /* make temp node, put offset in, and generate args */
 799799                 ptemp = talloc();
 800800                 ptemp->op = OREG;
 801801                 ptemp->lval = -1;
 802802                 ptemp->rval = SP;
 803803                 ptemp->name[0] = '\0';
 804804                 ptemp->rall = NOPREF;
 805805                 ptemp->su = 0;
 806806                 genargs( p->right, ptemp );
 807807                 nfree(ptemp);
 808808                 }
 809809 
 810810         p1 = p->left;
 811811         if( p1->op != ICON ){
 812812                 if( p1->op != REG ){
 813813                         if( p1->op != OREG || R2TEST(p1->rval) ){
 814814                                 if( p1->op != NAME ){
 815815                                         order( p1, INAREG );
 816816                                         }
 817817                                 }
 818818                         }
 819819                 }
 820820 
 821821 /*
 822822         if( p1->op == REG && p->rval == R5 ){
 823823                 cerror( "call register overwrite" );
 824824                 }
 825825  */
 826826 /* tbl
 827827         setup gc_numbytes so reference to ZC works */
 828828 
 829829         gc_numbytes = temp;
 830830 /* tbl */
 831831 
 832832         p->op = UNARY CALL;
 833833         m = match( p, INTAREG|INTBREG );
 834834 /* tbl
 835835         switch( temp ) {
 836836         case 0:
 837837                 break;
 838838         case 2:
 839839                 printf( "       tst     (sp)+\n" );
 840840                 break;
 841841         case 4:
 842842                 printf( "       cmp     (sp)+,(sp)+\n" );
 843843                 break;
 844844         default:
 845845                 printf( "       add     $%d,sp\n", temp);
 846846                 }
 847847    tbl */
 848848         return(m != MDONE);
 849849         }
 850850 #endif
 851851 
 852852 static char *
 853853 ccbranches[] = {
 854854         "jeql",
 855855         "jneq",
 856856         "jleq",
 857857         "jlss",
 858858         "jgeq",
 859859         "jgtr",
 860860         "jlequ",
 861861         "jlssu",
 862862         "jgequ",
 863863         "jgtru",
 864864 };
 865865 
 866866 /*
 867867  * printf conditional and unconditional branches
 868868  */
 869869 void
 870870 cbgen(int o, int lab)
 871871 {
 872872 
 873873         if (o == 0) {
 874874                 printf("        jbr     " LABFMT "\n", lab);
 875875         } else {
 876876                 if (o > UGT)
 877877                         comperr("bad conditional branch: %s", opst[o]);
 878878                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 879879         }
 880880 }
 881881 
 882882 static void
 883883 optim2(NODE *p, void *arg)
 884884 {
 885885         /* do local tree transformations and optimizations */
 886886 
 887887         register NODE *r;
 888888 
 889889         switch( p->n_op ) {
 890890 
 891891         case AND:
 892892                 /* commute L and R to eliminate compliments and constants */
 893893                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
 894894                         r = p->n_left;
 895895                         p->n_left = p->n_right;
 896896                         p->n_right = r;
 897897                         }
 898898 #if 0
 899899         case ASG AND:
 900900                 /* change meaning of AND to ~R&L - bic on pdp11 */
 901901                 r = p->n_right;
 902902                 if( r->op==ICON && r->name[0]==0 ) { /* compliment constant */
 903903                         r->lval = ~r->lval;
 904904                         }
 905905                 else if( r->op==COMPL ) { /* ~~A => A */
 906906                         r->op = FREE;
 907907                         p->right = r->left;
 908908                         }
 909909                 else { /* insert complement node */
 910910                         p->right = talloc();
 911911                         p->right->op = COMPL;
 912912                         p->right->rall = NOPREF;
 913913                         p->right->type = r->type;
 914914                         p->right->left = r;
 915915                         p->right->right = NULL;
 916916                         }
 917917                 break;
 918918 #endif
 919919                 }
 920920         }
 921921 
 922922 void
 923923 myreader(struct interpass *ipole)
 924924 {
 925925         struct interpass *ip;
 926926 
 927927         DLIST_FOREACH(ip, ipole, qelem) {
 928928                 if (ip->type != IP_NODE)
 929929                         continue;
 930930                 walkf(ip->ip_node, optim2, 0);
 931931         }
 932932 }
 933933 
 934934 void
 935935 mycanon(NODE *p)
 936936 {
 937937 }
 938938 
 939939 void
 940940 myoptim(struct interpass *ip)
 941941 {
 942942 }
 943943 
 944944 /*
 945945  * Return argument size in regs.
 946946  */
 947947 static int
 948948 argsiz(NODE *p)
 949949 {
 950950         TWORD t = p->n_type;
 951951 
 952952         if (t == STRTY || t == UNIONTY)
 953953                 return p->n_stsize/(SZINT/SZCHAR);
 954954         return szty(t);
 955955 }
 956956 
 957957 /*
 958958  * Last chance to do something before calling a function.
 959959  */
 960960 void
 961961 lastcall(NODE *p)
 962962 {
 963963         NODE *op = p;
 964964         int size = 0;
 965965 
 966966         /* Calculate argument sizes */
 967967         p->n_qual = 0;
 968968         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 969969                 return;
 970970         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 971971                 size += argsiz(p->n_right);
 972972         if (p->n_op != ASSIGN)
 973973                 size += argsiz(p);
 974974         op->n_qual = size; /* XXX */
 975975 }
 976976 
 977977 /*
 978978  * Return a class suitable for a specific type.
 979979  */
 980980 int
 981981 gclass(TWORD t)
 982982 {
 983983         return (szty(t) == 2 ? CLASSB : CLASSA);
 984984 }
 985985 
 986986 /*
 987987  * For class c, find worst-case displacement of the number of
 988988  * registers in the array r[] indexed by class.
 989989  */
 990990 int
 991991 COLORMAP(int c, int *r)
 992992 {
 993993         int num;
 994994 
 995995         switch (c) {
 996996         case CLASSA:
 997997                 /* there are 12 classa, so min 6 classb are needed to block */
 998998                 num = r[CLASSB] * 2;
 999999                 num += r[CLASSA];
 10001000                 return num < 12;
 10011001         case CLASSB:
 10021002                 /* 6 classa may block all classb */
 10031003                 num = r[CLASSB] + r[CLASSA];
 10041004                 return num < 6;
 10051005         }
 10061006         comperr("COLORMAP");
 10071007         return 0; /* XXX gcc */
 10081008 }
 10091009 
 10101010 /*
 10111011  * Special shapes.
 10121012  */
 10131013 int
 10141014 special(NODE *p, int shape)
 10151015 {
 10161016         return SRNOPE;
 10171017 }
 10181018 
 10191019 /*
 10201020  * Target-dependent command-line options.
 10211021  */
 10221022 void
 10231023 mflags(char *str)
 10241024 {
 10251025 }
 10261026 /*
 10271027  * Do something target-dependent for xasm arguments.
 10281028  * Supposed to find target-specific constraints and rewrite them.
 10291029  */
 10301030 int
 10311031 myxasm(struct interpass *ip, NODE *p)
 10321032 {
 10331033         return 0;
 10341034 }
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-20 22:35 +0100