Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.6
 
1.7
 
MAIN:ragge:20080622152459
 
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 
 534534         if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left)) ) return(1);
 535535         return(0);
 536536         }
 537537 
 538538 shltype( o, p ) register NODE *p; {
 539539         return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left)) );
 540540         }
 541541 #endif
 542542 
 543543 int
 544544 fldexpand(NODE *p, int cookie, char **cp)
 545545 {
 546546         return 0;
 547547 }
 548548 
 549549 int
 550550 flshape( p ) register NODE *p; {
 551551         return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
 552552                 (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
 553553         }
 554554 
 555555 int
 556556 shtemp( p ) register NODE *p; {
 557557         if( p->n_op == STARG ) p = p->n_left;
 558558         return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left)) );
 559559         }
 560560 
 561561 int
 562562 shumul( p ) register NODE *p; {
 563563         register int o;
 564564         extern int xdebug;
 565565 
 566566         if (xdebug) {
 567567                  printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
 568568                 printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
 569569                 }
 570570 
 571571 
 572572         o = p->n_op;
 573573         if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON ) return( STARNM );
 574574 
 575575 #ifdef notyet
 576576         if( ( o == INCR || o == ASG MINUS ) &&
 577577             ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
 578578             p->n_right->n_name[0] == '\0' )
 579579                 {
 580580                 switch (p->n_left->n_type)
 581581                         {
 582582                         case CHAR|PTR:
 583583                         case UCHAR|PTR:
 584584                                 o = 1;
 585585                                 break;
 586586 
 587587                         case SHORT|PTR:
 588588                         case USHORT|PTR:
 589589                                 o = 2;
 590590                                 break;
 591591 
 592592                         case INT|PTR:
 593593                         case UNSIGNED|PTR:
 594594                         case LONG|PTR:
 595595                         case ULONG|PTR:
 596596                         case FLOAT|PTR:
 597597                                 o = 4;
 598598                                 break;
 599599 
 600600                         case DOUBLE|PTR:
 601601                                 o = 8;
 602602                                 break;
 603603 
 604604                         default:
 605605                                 if ( ISPTR(p->n_left->n_type) ) {
 606606                                         o = 4;
 607607                                         break;
 608608                                         }
 609609                                 else return(0);
 610610                         }
 611611                 return( p->n_right->n_lval == o ? STARREG : 0);
 612612                 }
 613613 #endif
 614614 
 615615         return( 0 );
 616616         }
 617617 
 618618 void
 619619 adrcon( val ) CONSZ val; {
 620620         printf( "$" );
 621621         printf( CONFMT, val );
 622622         }
 623623 
 624624 void
 625625 conput(FILE *fp, NODE *p)
 626626 {
 627627         switch( p->n_op ){
 628628 
 629629         case ICON:
 630630                 acon( p );
 631631                 return;
 632632 
 633633         case REG:
 634634                 printf( "%s", rnames[p->n_rval] );
 635635                 return;
 636636 
 637637         default:
 638638                 cerror( "illegal conput" );
 639639                 }
 640640         }
 641641 
 642642 void
 643643 insput( p ) register NODE *p; {
 644644         cerror( "insput" );
 645645         }
 646646 
 647647 void
 648648 upput( p , size) register NODE *p; {
 649649         cerror( "upput" );
 650650         }
 651651 
 652652 void
 653653 adrput(FILE *fp, NODE *p)
 654654 {
 655655         register int r;
 656656         /* output an address, with offsets, from p */
 657657 
 658658         if( p->n_op == FLD ){
 659659                 p = p->n_left;
 660660                 }
 661661         switch( p->n_op ){
 662662 
 663663         case NAME:
 664664                 acon( p );
 665665                 return;
 666666 
 667667         case ICON:
 668668                 /* addressable value of the constant */
 669669                 if (p->n_name[0] == '\0') /* uses xxxab */
 670670                         printf("$");
 671671                 acon(p);
 672672                 return;
 673673 
 674674         case REG:
 675675                 printf( "%s", rnames[p->n_rval] );
 676676                 return;
 677677 
 678678         case OREG:
 679679                 r = p->n_rval;
 680680                 if( R2TEST(r) ){ /* double indexing */
 681681                         register int flags;
 682682 
 683683                         flags = R2UPK3(r);
 684684                         if( flags & 1 ) printf("*");
 685685                         if( flags & 4 ) printf("-");
 686686                         if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
 687687                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 688688                         if( flags & 2 ) printf("+");
 689689                         printf( "[%s]", rnames[R2UPK2(r)] );
 690690                         return;
 691691                         }
 692692                 if( r == AP ){  /* in the argument region */
 693693                         if( p->n_lval <= 0 || p->n_name[0] != '\0' ) werror( "bad arg temp" );
 694694                         printf( CONFMT, p->n_lval );
 695695                         printf( "(ap)" );
 696696                         return;
 697697                         }
 698698                 if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
 699699                 printf( "(%s)", rnames[p->n_rval] );
 700700                 return;
 701701 
 702702         case UMUL:
 703703                 /* STARNM or STARREG found */
 704704                 if( tshape(p, STARNM) ) {
 705705                         printf( "*" );
 706706                         adrput(0p->n_left);
 707707                         }
 708708                 else {  /* STARREG - really auto inc or dec */
 709709                         register NODE *q;
 710710 
 711711 /* tbl
 712712                         p = p->n_left;
 713713                         p->n_left->n_op = OREG;
 714714                         if( p->n_op == INCR ) {
 715715                                 adrput( p->n_left );
 716716                                 printf( "+" );
 717717                                 }
 718718                         else {
 719719                                 printf( "-" );
 720720                                 adrput( p->n_left );
 721721                                 }
 722722    tbl */
 723723 #ifdef notyet
 724724                         printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
 725725                                 rnames[p->n_left->n_left->n_rval],
 726726                                 (p->n_left->n_op==INCR ? '+' : '\0') );
 727727 #else
 728728                         printf("%c(%s)%c", '-',
 729729                                 rnames[p->n_left->n_left->n_rval],
 730730                                 '\0' );
 731731 #endif
 732732                         p->n_op = OREG;
 733733                         p->n_rval = p->n_left->n_left->n_rval;
 734734                         q = p->n_left;
 735735 #ifdef notyet
 736736 
 737737                         p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
 738738 #else
 739739                         p->n_lval = 0;
 740740 #endif
 741741                         p->n_name[0] = '\0';
 742742                         tfree(q);
 743743                 }
 744744                 return;
 745745 
 746746         default:
 747747                 cerror( "illegal address" );
 748748                 return;
 749749         }
 750750 
 751751 }
 752752 
 753753 /*
 754754  * print out a constant
 755755  */
 756756 void
 757757 acon(NODE *p)
 758758 {
 759759 
 760760         if (p->n_name[0] == '\0') {
 761761                 printf(CONFMT, p->n_lval);
 762762         } else if( p->n_lval == 0 ) {
 763763                 printf("%s", p->n_name);
 764764         } else {
 765765                 printf("%s+", p->n_name);
 766766                 printf(CONFMT, p->n_lval);
 767767         }
 768768 }
 769769 
 770770 #if 0
 771771 genscall( p, cookie ) register NODE *p; {
 772772         /* structure valued call */
 773773         return( gencall( p, cookie ) );
 774774         }
 775775 
 776776 /* tbl */
 777777 int gc_numbytes;
 778778 /* tbl */
 779779 
 780780 gencall( p, cookie ) register NODE *p; {
 781781         /* generate the call given by p */
 782782         register NODE *p1, *ptemp;
 783783         register temp, temp1;
 784784         register m;
 785785 
 786786         if( p->right ) temp = argsize( p->right );
 787787         else temp = 0;
 788788 
 789789         if( p->op == STCALL || p->op == UNARY STCALL ){
 790790                 /* set aside room for structure return */
 791791 
 792792                 if( p->stsize > temp ) temp1 = p->stsize;
 793793                 else temp1 = temp;
 794794                 }
 795795 
 796796         if( temp > maxargs ) maxargs = temp;
 797797         SETOFF(temp1,4);
 798798 
 799799         if( p->right ){ /* make temp node, put offset in, and generate args */
 800800                 ptemp = talloc();
 801801                 ptemp->op = OREG;
 802802                 ptemp->lval = -1;
 803803                 ptemp->rval = SP;
 804804                 ptemp->name[0] = '\0';
 805805                 ptemp->rall = NOPREF;
 806806                 ptemp->su = 0;
 807807                 genargs( p->right, ptemp );
 808808                 nfree(ptemp);
 809809                 }
 810810 
 811811         p1 = p->left;
 812812         if( p1->op != ICON ){
 813813                 if( p1->op != REG ){
 814814                         if( p1->op != OREG || R2TEST(p1->rval) ){
 815815                                 if( p1->op != NAME ){
 816816                                         order( p1, INAREG );
 817817                                         }
 818818                                 }
 819819                         }
 820820                 }
 821821 
 822822 /*
 823823         if( p1->op == REG && p->rval == R5 ){
 824824                 cerror( "call register overwrite" );
 825825                 }
 826826  */
 827827 /* tbl
 828828         setup gc_numbytes so reference to ZC works */
 829829 
 830830         gc_numbytes = temp;
 831831 /* tbl */
 832832 
 833833         p->op = UNARY CALL;
 834834         m = match( p, INTAREG|INTBREG );
 835835 /* tbl
 836836         switch( temp ) {
 837837         case 0:
 838838                 break;
 839839         case 2:
 840840                 printf( "       tst     (sp)+\n" );
 841841                 break;
 842842         case 4:
 843843                 printf( "       cmp     (sp)+,(sp)+\n" );
 844844                 break;
 845845         default:
 846846                 printf( "       add     $%d,sp\n", temp);
 847847                 }
 848848    tbl */
 849849         return(m != MDONE);
 850850         }
 851851 #endif
 852852 
 853853 static char *
 854854 ccbranches[] = {
 855855         "jeql",
 856856         "jneq",
 857857         "jleq",
 858858         "jlss",
 859859         "jgeq",
 860860         "jgtr",
 861861         "jlequ",
 862862         "jlssu",
 863863         "jgequ",
 864864         "jgtru",
 865865 };
 866866 
 867867 /*
 868868  * printf conditional and unconditional branches
 869869  */
 870870 void
 871871 cbgen(int o, int lab)
 872872 {
 873873 
 874874         if (o == 0) {
 875875                 printf("        jbr     " LABFMT "\n", lab);
 876876         } else {
 877877                 if (o > UGT)
 878878                         comperr("bad conditional branch: %s", opst[o]);
 879879                 printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
 880880         }
 881881 }
 882882 
 883883 static void
 884884 optim2(NODE *p)
 885885 {
 886886         /* do local tree transformations and optimizations */
 887887 
 888888         register NODE *r;
 889889 
 890890         switch( p->n_op ) {
 891891 
 892892         case AND:
 893893                 /* commute L and R to eliminate compliments and constants */
 894894                 if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
 895895                         r = p->n_left;
 896896                         p->n_left = p->n_right;
 897897                         p->n_right = r;
 898898                         }
 899899 #if 0
 900900         case ASG AND:
 901901                 /* change meaning of AND to ~R&L - bic on pdp11 */
 902902                 r = p->n_right;
 903903                 if( r->op==ICON && r->name[0]==0 ) { /* compliment constant */
 904904                         r->lval = ~r->lval;
 905905                         }
 906906                 else if( r->op==COMPL ) { /* ~~A => A */
 907907                         r->op = FREE;
 908908                         p->right = r->left;
 909909                         }
 910910                 else { /* insert complement node */
 911911                         p->right = talloc();
 912912                         p->right->op = COMPL;
 913913                         p->right->rall = NOPREF;
 914914                         p->right->type = r->type;
 915915                         p->right->left = r;
 916916                         p->right->right = NULL;
 917917                         }
 918918                 break;
 919919 #endif
 920920                 }
 921921         }
 922922 
 923923 void
 924924 myreader(struct interpass *ipole)
 925925 {
 926926         struct interpass *ip;
 927927 
 928928         DLIST_FOREACH(ip, ipole, qelem) {
 929929                 if (ip->type != IP_NODE)
 930930                         continue;
 931931                 walkf(ip->ip_node, optim2);
 932932         }
 933933 }
 934934 
 935935 void
 936936 mycanon(NODE *p)
 937937 {
 938938 }
 939939 
 940940 void
 941941 myoptim(struct interpass *ip)
 942942 {
 943943 }
 944944 
 945945 /*
 946946  * Return argument size in regs.
 947947  */
 948948 static int
 949949 argsiz(NODE *p)
 950950 {
 951951         TWORD t = p->n_type;
 952952 
 953953         if (t == STRTY || t == UNIONTY)
 954954                 return p->n_stsize/(SZINT/SZCHAR);
 955955         return szty(t);
 956956 }
 957957 
 958958 /*
 959959  * Last chance to do something before calling a function.
 960960  */
 961961 void
 962962 lastcall(NODE *p)
 963963 {
 964964         NODE *op = p;
 965965         int size = 0;
 966966 
 967967         /* Calculate argument sizes */
 968968         p->n_qual = 0;
 969969         if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
 970970                 return;
 971971         for (p = p->n_right; p->n_op == CM; p = p->n_left)
 972972                 size += argsiz(p->n_right);
 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 }
<_ 1026+/*
  1027+ * Do something target-dependent for xasm arguments.
  1028+ * Supposed to find target-specific constraints and rewrite them.
  1029+ */
  1030+int
  1031+myxasm(struct interpass *ip, NODE *p)
  1032+{
  1033+        return 0;
  1034+}
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-09-20 14:01 +0200