Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.1
 
1.2
 
MAIN:ragge:20071026150641
 
local2.c
_>3333  * POSSIBILITY OF SUCH DAMAGE.
 3434  */
 3535 
<>36 -# include "mfile2"
  36+# include "pass2.h"
3737 # include "ctype.h"
 3838 /* a lot of the machine dependent parts of the second pass */
 3939 
<> 40+static void prtype(NODE *n);
  41+static void acon(NODE *p);
  42+
4043 # define BITMASK(n) ((1L<<n)-1)
 4144 
<>42 -where(c){
 43 -        fprintf( stderr, "%s, line %d: ", filename, lineno );
 44 -        }
  45+/*
  46+ * Print out the prolog assembler.
  47+ * addto and regoff are already calculated.
  48+ */
  49+void
  50+prologue(struct interpass_prolog *ipp)
  51+{
  52+        if (ipp->ipp_vis)
  53+                printf("        .globl %s\n", ipp->ipp_name);
  54+        printf("        .align 4\n");
  55+        printf("%s:\n", ipp->ipp_name);
  56+        printf("        .word 0x%x\n", ipp->ipp_regs);
  57+        if (p2maxautooff)
  58+                printf("        subl2 $%d,%%sp\n", p2maxautooff);
  59+}
4560 
<>46 -lineid( l, fn ) char *fn; {
 47 -        /* identify line l and file fn */
 48 -        printf( "#      line %d, file %s\n", l, fn );
 49 -        }
  61+/*
  62+ * Called after all instructions in a function are emitted.
  63+ * Generates code for epilog here.
  64+ */
  65+void
  66+eoftn(struct interpass_prolog *ipp)
  67+{
  68+        if (ipp->ipp_ip.ip_lbl == 0)
  69+                return; /* no code needs to be generated */
  70+        printf("        ret\n");
  71+}
5072 
<>51 -eobl2(){
 52 -        OFFSZ spoff;    /* offset from stack pointer */
 53 -
 54 -        spoff = maxoff;
 55 -        if( spoff >= AUTOINIT ) spoff -= AUTOINIT;
 56 -        spoff /= SZCHAR;
 57 -        SETOFF(spoff,4);
 58 -        printf( "       .set    .F%d,%Ld\n", ftnno, spoff );
 59 -        maxargs = -1;
 60 -        }
 61 -
6273 struct hoptab { int opmask; char * opstring; } ioptab[] = {
 6374 
<>64 -        ASG PLUS, "add",
 65 -        ASG MINUS, "sub",
 66 -        ASG MUL, "mul",
 67 -        ASG DIV, "div",
 68 -        ASG OR, "bis",
 69 -        ASG ER, "xor",
 70 -        ASG AND, "bic",
 71 -        PLUS,   "add",
 72 -        MINUS,  "sub",
 73 -        MUL,    "mul",
 74 -        DIV,    "div",
 75 -        OR,     "bis",
 76 -        ER,     "xor",
 77 -        AND,    "bic",
 78 -        -1, ""    };
  75+        { PLUS"add", },
  76+        { MINUS,        "sub", },
  77+        { MUL,  "mul", },
  78+        { DIV,  "div", },
  79+        { OR,   "bis", },
  80+        { ER,   "xor", },
  81+        { AND,  "bic", },
  82+        { -1, ""     },
  83+};
7984 
<> 85+void
8086 hopcode( f, o ){
 8187         /* output the appropriate string from the above table */
 8288 
     
 !
110116 char *
 111117 rnames[] = {  /* keyed to register number tokens */
 112118 
<>113 -        "r0", "r1",
 114 -        "r2", "r3", "r4", "r5",
  119+        "r0", "r1", "r2", "r3", "r4", "r5",
115120         "r6", "r7", "r8", "r9", "r10", "r11",
 116121         "ap", "fp", "sp", "pc",
<>117 -
  122+        /* The concatenated regs has the name of the lowest */
  123+        "r0", "r1", "r2", "r3", "r4", "r5",
  124+        "r6", "r7", "r8", "r9", "r10"
118125         };
 119126 
<>120 -int rstatus[] = {
 121 -        SAREG|STAREG, SAREG|STAREG,
 122 -        SAREG|STAREG, SAREG|STAREG, SAREG|STAREG, SAREG|STAREG,
 123 -        SAREG, SAREG, SAREG, SAREG, SAREG, SAREG,
 124 -        SAREG, SAREG, SAREG, SAREG,
 125 -
 126 -        };
 127 -
  127+int
128128 tlen(p) NODE *p;
 129129 {
<>130 -        switch(p->type) {
  130+        switch(p->n_type) {
131131                 case CHAR:
 132132                 case UCHAR:
 133133                         return(1);
     
 !
137137                         return(2);
 138138 
 139139                 case DOUBLE:
<> 140+                case LDOUBLE:
  141+                case LONGLONG:
  142+                case ULONGLONG:
140143                         return(8);
 141144 
 142145                 default:
 143146                         return(4);
 144147                 }
 145148 }
 146149 
<>147 -mixtypes(p, q) NODE *p, *q;
  150+static int
  151+mixtypes(NODE *p, NODE *q)
148152 {
<>149 -        register tp, tq;
  153+        TWORD tp, tq;
150154 
<>151 -        tp = p->type;
 152 -        tq = q->type;
  155+        tp = p->n_type;
  156+        tq = q->n_type;
153157 
 154158         return( (tp==FLOAT || tp==DOUBLE) !=
 155159                 (tq==FLOAT || tq==DOUBLE) );
 156160 }
 157161 
<>158 -prtype(n) NODE *n;
  162+void
  163+prtype(NODE *n)
159164 {
<>160 -        switch (n->type)
  165+        switch (n->n_type)
161166                 {
 162167                 case DOUBLE:
 163168                         printf("d");
     
 !
185190                         return;
 186191 
 187192                 default:
<>188 -                        if ( !ISPTR( n->type ) ) cerror("zzzcode- bad type");
  193+                        if ( !ISPTR( n->n_type ) ) cerror("zzzcode- bad type");
189194                         else {
 190195                                 printf("l");
 191196                                 return;
 192197                                 }
 193198                 }
 194199 }
 195200 
<> 201+void
196202 zzzcode( p, c ) register NODE *p; {
<>197 -        register m;
 198 -        CONSZ val;
  203+        int m;
  204+        int val;
199205         switch( c ){
 200206 
 201207         case 'N'/* logical ops, turned into 0-1 */
 202208                 /* use register given by register 1 */
<>203 -                cbgen( 0, m=getlab(), 'I' );
 204 -                deflab( p->label );
 205 -                printf( "       clrl    %s\n", rnames[getlr( p, '1' )->rval] );
  209+                cbgen( 0, m=getlab());
  210+                deflab( p->n_label );
  211+                printf( "       clrl    %s\n", rnames[getlr( p, '1' )->n_rval] );
206212                 deflab( m );
 207213                 return;
 208214 
<>209 -        case 'I':
 210 -        case 'P':
 211 -                cbgen( p->op, p->label, c );
 212 -                return;
 213 -
214215         case 'A':
 215216                 {
 216217                 register NODE *l, *r;
 217218 
<>218 -                if (xdebug) eprint(p, 0, &val, &val);
  219+                if (xdebug) e2print(p, 0, &val, &val);
219220                 r = getlr(p, 'R');
<>220 -                if (optype(p->op) == LTYPE || p->op == UNARY MUL)
 221 -                        {
  221+                if (optype(p->n_op) == LTYPE || p->n_op == UMUL) {
222222                         l = resc;
<>223 -                        l->type = (r->type==FLOAT || r->type==DOUBLE ? DOUBLE : INT);
 224 -                        }
 225 -                else
  223+                        l->n_type = (r->n_type==FLOAT || r->n_type==DOUBLE ? DOUBLE : INT);
  224+                } else
226225                         l = getlr(p, 'L');
<>227 -                if (r->op == ICON  && r->name[0] == '\0')
 228 -                        {
 229 -                        if (r->lval == 0)
 230 -                                {
  226+                if (r->n_op == ICON  && r->n_name[0] == '\0') {
  227+                        if (r->n_lval == 0) {
231228                                 printf("clr");
 232229                                 prtype(l);
 233230                                 printf("        ");
<>234 -                                adrput(l);
  231+                                adrput(stdout, l);
235232                                 return;
<>236 -                                }
 237 -                        if (r->lval < 0 && r->lval >= -63)
 238 -                                {
  233+                        }
  234+                        if (r->n_lval < 0 && r->n_lval >= -63) {
239235                                 printf("mneg");
 240236                                 prtype(l);
<>241 -                                r->lval = -r->lval;
  237+                                r->n_lval = -r->n_lval;
242238                                 goto ops;
<>243 -                                }
 244 -                        r->type = (r->lval < 0 ?
 245 -                                        (r->lval >= -128 ? CHAR
 246 -                                        : (r->lval >= -32768 ? SHORT
 247 -                                        : INT )) : r->type);
 248 -                        r->type = (r->lval >= 0 ?
 249 -                                        (r->lval <= 63 ? INT
 250 -                                        : ( r->lval <= 127 ? CHAR
 251 -                                        : (r->lval <= 255 ? UCHAR
 252 -                                        : (r->lval <= 32767 ? SHORT
 253 -                                        : (r->lval <= 65535 ? USHORT
 254 -                                        : INT ))))) : r->type );
255239                         }
<>256 -                if (l->op == REG && l->type != FLOAT && l->type != DOUBLE)
 257 -                        l->type = INT;
  240+                        r->n_type = (r->n_lval < 0 ?
  241+                                        (r->n_lval >= -128 ? CHAR
  242+                                        : (r->n_lval >= -32768 ? SHORT
  243+                                        : INT )) : r->n_type);
  244+                        r->n_type = (r->n_lval >= 0 ?
  245+                                        (r->n_lval <= 63 ? INT
  246+                                        : ( r->n_lval <= 127 ? CHAR
  247+                                        : (r->n_lval <= 255 ? UCHAR
  248+                                        : (r->n_lval <= 32767 ? SHORT
  249+                                        : (r->n_lval <= 65535 ? USHORT
  250+                                        : INT ))))) : r->n_type );
  251+                        }
  252+                if (l->n_op == REG && l->n_type != FLOAT && l->n_type != DOUBLE)
  253+                        l->n_type = INT;
258254                 if (!mixtypes(l,r))
 259255                         {
 260256                         if (tlen(l) == tlen(r))
     
 !
263259                                 prtype(l);
 264260                                 goto ops;
 265261                                 }
<>266 -                        else if (tlen(l) > tlen(r) && ISUNSIGNED(r->type))
  262+                        else if (tlen(l) > tlen(r) && ISUNSIGNED(r->n_type))
267263                                 {
 268264                                 printf("movz");
 269265                                 }
     
 !
280276                 prtype(l);
 281277         ops:
 282278                 printf("        ");
<>283 -                adrput(r);
  279+                adrput(stdout, r);
284280                 printf(",");
<>285 -                adrput(l);
  281+                adrput(stdout, l);
286282                 return;
 287283                 }
 288284 
 289285         case 'C':       /* num words pushed on arg stack */
 290286                 {
<>291 -                extern int gc_numbytes;
 292 -                extern int xdebug;
  287+                        int pr = p->n_qual;
293288 
<>294 -                if (xdebug) printf("->%d<-",gc_numbytes);
 295 -
 296 -                printf("$%d", gc_numbytes/(SZLONG/SZCHAR) );
 297 -                return;
  289+                        if (p->n_op == STCALL || p->n_op == USTCALL)
  290+                                pr += 4;
  291+                        printf("$%d", pr);
  292+                        break;
298293                 }
 299294 
 300295         case 'D':       /* INCR and DECR */
<>301 -                zzzcode(p->left, 'A');
  296+                zzzcode(p->n_left, 'A');
302297                 printf("\n      ");
 303298 
<> 299+#if 0
304300         case 'E':       /* INCR and DECR, FOREFF */
<>305 -                if (p->right->lval == 1)
  301+                if (p->n_right->n_lval == 1)
306302                         {
<>307 -                        printf("%s", (p->op == INCR ? "inc" : "dec") );
 308 -                        prtype(p->left);
  303+                        printf("%s", (p->n_op == INCR ? "inc" : "dec") );
  304+                        prtype(p->n_left);
309305                         printf("        ");
<>310 -                        adrput(p->left);
  306+                        adrput(stdout, p->n_left);
311307                         return;
 312308                         }
<>313 -                printf("%s", (p->op == INCR ? "add" : "sub") );
 314 -                prtype(p->left);
  309+                printf("%s", (p->n_op == INCR ? "add" : "sub") );
  310+                prtype(p->n_left);
315311                 printf("2       ");
<>316 -                adrput(p->right);
  312+                adrput(stdout, p->n_right);
317313                 printf(",");
<>318 -                adrput(p->left);
  314+                adrput(p->n_left);
319315                 return;
<> 316+#endif
320317 
 321318         case 'F':       /* register type of right operand */
 322319                 {
     
 !
325322                 register int ty;
 326323 
 327324                 n = getlr( p, 'R' );
<>328 -                ty = n->type;
  325+                ty = n->n_type;
329326 
 330327                 if (xdebug) printf("->%d<-", ty);
 331328 
     
 !
342339                 extern int xdebug;
 343340 
 344341                 n = getlr ( p, c);
<>345 -                if (xdebug) printf("->%d<-", n->type);
  342+                if (xdebug) printf("->%d<-", n->n_type);
346343 
 347344                 prtype(n);
 348345                 return;
 349346                 }
 350347 
 351348         case 'Z':       /* complement mask for bit instr */
<>352 -                printf("$%Ld", ~p->right->lval);
  349+                printf("$%Ld", ~p->n_right->n_lval);
353350                 return;
 354351 
 355352         case 'U':       /* 32 - n, for unsigned right shifts */
<>356 -                printf("$%d", 32 - p->right->lval );
  353+                printf("$" CONFMT, 32 - p->n_right->n_lval );
357354                 return;
 358355 
 359356         case 'T':       /* rounded structure length for arguments */
 360357                 {
 361358                 int size;
 362359 
<>363 -                size = p->stsize;
  360+                size = p->n_stsize;
364361                 SETOFF( size, 4);
 365362                 printf("$%d", size);
 366363                 return;
     
 !
369366         case 'S'/* structure assignment */
 370367                 {
 371368                         register NODE *l, *r;
<>372 -                        register size;
  369+                        register int size;
373370 
<>374 -                        if( p->op == STASG ){
 375 -                                l = p->left;
 376 -                                r = p->right;
  371+                        l = r = NULL; /* XXX gcc */
  372+                        if( p->n_op == STASG ){
  373+                                l = p->n_left;
  374+                                r = p->n_right;
377375 
 378376                                 }
<>379 -                        else if( p->op == STARG ){  /* store an arg into a temporary */
  377+                        else if( p->n_op == STARG ){  /* store an arg into a temporary */
380378                                 l = getlr( p, '3' );
<>381 -                                r = p->left;
  379+                                r = p->n_left;
382380                                 }
 383381                         else cerror( "STASG bad" );
 384382 
<>385 -                        if( r->op == ICON ) r->op = NAME;
 386 -                        else if( r->op == REG ) r->op = OREG;
 387 -                        else if( r->op != OREG ) cerror( "STASG-r" );
  383+                        if( r->n_op == ICON ) r->n_op = NAME;
  384+                        else if( r->n_op == REG ) r->n_op = OREG;
  385+                        else if( r->n_op != OREG ) cerror( "STASG-r" );
388386 
<>389 -                        size = p->stsize;
  387+                        size = p->n_stsize;
390388 
 391389                         if( size <= 0 || size > 65535 )
 392390                                 cerror("structure size <0=0 or >65535");
     
 !
408406                                         printf("        movc3   $%d,", size);
 409407                                         break;
 410408                         }
<>411 -                        adrput(r);
  409+                        adrput(stdout, r);
412410                         printf(",");
<>413 -                        adrput(l);
  411+                        adrput(stdout, l);
414412                         printf("\n");
 415413 
<>416 -                        if( r->op == NAME ) r->op = ICON;
 417 -                        else if( r->op == OREG ) r->op = REG;
  414+                        if( r->n_op == NAME ) r->n_op = ICON;
  415+                        else if( r->n_op == OREG ) r->n_op = REG;
418416 
 419417                         }
 420418                 break;
 421419 
 422420         default:
<>423 -                cerror( "illegal zzzcode" );
  421+                comperr("illegal zzzcode '%c'", c);
424422                 }
 425423         }
 426424 
<>427 -rmove( rt, rs, t ){
  425+void
  426+rmove( int rt,int  rs, TWORD t ){
428427         printf( "       %s      %s,%s\n",
 429428                 (t==FLOAT ? "movf" : (t==DOUBLE ? "movd" : "movl")),
 430429                 rnames[rs], rnames[rt] );
 431430         }
 432431 
<>433 -struct respref
 434 -respref[] = {
 435 -        INTAREG|INTBREG,        INTAREG|INTBREG,
 436 -        INAREG|INBREG,  INAREG|INBREG|SOREG|STARREG|STARNM|SNAME|SCON,
 437 -        INTEMP, INTEMP,
 438 -        FORARG, FORARG,
 439 -        INTEMP, INTAREG|INAREG|INTBREG|INBREG|SOREG|STARREG|STARNM,
 440 -        0,      0 };
 441 -
  432+#if 0
442433 setregs(){ /* set up temporary registers */
 443434         fregs = 6;      /* tbl- 6 free regs on VAX (0-5) */
 444435         ;
     
 !
447438 szty(t){ /* size, in registers, needed to hold thing of type t */
 448439         return( (t==DOUBLE||t==FLOAT) ? 2 : 1 );
 449440         }
<> 441+#endif
450442 
<> 443+int
451444 rewfld( p ) NODE *p; {
 452445         return(1);
 453446         }
 454447 
<> 448+#if 0
455449 callreg(p) NODE *p; {
 456450         return( R0 );
 457451         }
     
 !
482476                 return( p->left->rval );
 483477         return( -1 );
 484478         }
<> 479+#endif
485480 
<> 481+#if 0
  482+void
486483 makeor2( p, q, b, o) register NODE *p, *q; register int b, o; {
 487484         register NODE *t;
<>488 -        register int i;
489485         NODE *f;
 490486 
<>491 -        p->op = OREG;
 492 -        f = p->left;    /* have to free this subtree later */
  487+        p->n_op = OREG;
  488+        f = p->n_left;  /* have to free this subtree later */
493489 
 494490         /* init base */
<>495 -        switch (q->op) {
  491+        switch (q->n_op) {
496492                 case ICON:
 497493                 case REG:
 498494                 case OREG:
 499495                         t = q;
 500496                         break;
 501497 
 502498                 case MINUS:
<>503 -                        q->right->lval = -q->right->lval;
  499+                        q->n_right->n_lval = -q->n_right->n_lval;
504500                 case PLUS:
<>505 -                        t = q->right;
  501+                        t = q->n_right;
506502                         break;
 507503 
<>508 -                case INCR:
 509 -                case ASG MINUS:
 510 -                        t = q->left;
  504+                case UMUL:
  505+                        t = q->n_left->n_left;
511506                         break;
 512507 
<>513 -                case UNARY MUL:
 514 -                        t = q->left->left;
 515 -                        break;
 516 -
517508                 default:
 518509                         cerror("illegal makeor2");
<> 510+                        t = NULL; /* XXX gcc */
519511         }
 520512 
<>521 -        p->lval = t->lval;
 522 -        for(i=0; i<NCHNAM; ++i)
 523 -                p->name[i] = t->name[i];
  513+        p->n_lval = t->n_lval;
  514+        p->n_name = t->n_name;
524515 
 525516         /* init offset */
<>526 -        p->rval = R2PACK( (b & 0177), o, (b>>7) );
  517+        p->n_rval = R2PACK( (b & 0177), o, (b>>7) );
527518 
 528519         tfree(f);
 529520         return;
 530521         }
 531522 
<> 523+int
532524 canaddr( p ) NODE *p; {
<>533 -        register int o = p->op;
  525+        register int o = p->n_op;
534526 
<>535 -        if( o==NAME || o==REG || o==ICON || o==OREG || (o==UNARY MUL && shumul(p->left)) ) return(1);
  527+        if( o==NAME || o==REG || o==ICON || o==OREG || (o==UMUL && shumul(p->n_left)) ) return(1);
536528         return(0);
 537529         }
 538530 
 539531 shltype( o, p ) register NODE *p; {
<>540 -        return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UNARY MUL && shumul(p->left)) );
  532+        return( o== REG || o == NAME || o == ICON || o == OREG || ( o==UMUL && shumul(p->n_left)) );
541533         }
<> 534+#endif
542535 
<> 536+int
543537 flshape( p ) register NODE *p; {
<>544 -        return( p->op == REG || p->op == NAME || p->op == ICON ||
 545 -                (p->op == OREG && (!R2TEST(p->rval) || tlen(p) == 1)) );
  538+        return( p->n_op == REG || p->n_op == NAME || p->n_op == ICON ||
  539+                (p->n_op == OREG && (!R2TEST(p->n_rval) || tlen(p) == 1)) );
546540         }
 547541 
<> 542+int
548543 shtemp( p ) register NODE *p; {
<>549 -        if( p->op == STARG ) p = p->left;
 550 -        return( p->op==NAME || p->op ==ICON || p->op == OREG || (p->op==UNARY MUL && shumul(p->left)) );
  544+        if( p->n_op == STARG ) p = p->n_left;
  545+        return( p->n_op==NAME || p->n_op ==ICON || p->n_op == OREG || (p->n_op==UMUL && shumul(p->n_left)) );
551546         }
 552547 
<> 548+int
553549 shumul( p ) register NODE *p; {
<>554 -        register o;
  550+        register int o;
555551         extern int xdebug;
 556552 
 557553         if (xdebug) {
<>558 -                 printf("\nshumul:op=%d,lop=%d,rop=%d", p->op, p->left->op, p->right->op);
 559 -                printf(" prname=%s,plty=%d, prlval=%D\n", p->right->name, p->left->type, p->right->lval);
  554+                 printf("\nshumul:op=%d,lop=%d,rop=%d", p->n_op, p->n_left->n_op, p->n_right->n_op);
  555+                printf(" prname=%s,plty=%d, prlval=%lld\n", p->n_right->n_name, p->n_left->n_type, p->n_right->n_lval);
560556                 }
 561557 
 562558 
<>563 -        o = p->op;
 564 -        if( o == NAME || (o == OREG && !R2TEST(p->rval)) || o == ICON ) return( STARNM );
  559+        o = p->n_op;
  560+        if( o == NAME || (o == OREG && !R2TEST(p->n_rval)) || o == ICON ) return( STARNM );
565561 
<> 562+#ifdef notyet
566563         if( ( o == INCR || o == ASG MINUS ) &&
<>567 -            ( p->left->op == REG && p->right->op == ICON ) &&
 568 -            p->right->name[0] == '\0' )
  564+            ( p->n_left->n_op == REG && p->n_right->n_op == ICON ) &&
  565+            p->n_right->n_name[0] == '\0' )
569566                 {
<>570 -                switch (p->left->type)
  567+                switch (p->n_left->n_type)
571568                         {
 572569                         case CHAR|PTR:
 573570                         case UCHAR|PTR:
     
 !
592589                                 break;
 593590 
 594591                         default:
<>595 -                                if ( ISPTR(p->left->type) ) {
  592+                                if ( ISPTR(p->n_left->n_type) ) {
596593                                         o = 4;
 597594                                         break;
 598595                                         }
 599596                                 else return(0);
 600597                         }
<>601 -                return( p->right->lval == o ? STARREG : 0);
  598+                return( p->n_right->n_lval == o ? STARREG : 0);
602599                 }
<> 600+#endif
603601 
 604602         return( 0 );
 605603         }
 606604 
<> 605+void
607606 adrcon( val ) CONSZ val; {
 608607         printf( "$" );
 609608         printf( CONFMT, val );
 610609         }
 611610 
<>612 -conput( p ) register NODE *p; {
 613 -        switch( p->op ){
  611+void
  612+conput(FILE *fp, NODE *p)
  613+{
  614+        switch( p->n_op ){
614615 
 615616         case ICON:
 616617                 acon( p );
 617618                 return;
 618619 
 619620         case REG:
<>620 -                printf( "%s", rnames[p->rval] );
  621+                printf( "%s", rnames[p->n_rval] );
621622                 return;
 622623 
 623624         default:
 624625                 cerror( "illegal conput" );
 625626                 }
 626627         }
 627628 
<> 629+void
628630 insput( p ) register NODE *p; {
 629631         cerror( "insput" );
 630632         }
 631633 
<>632 -upput( p ) register NODE *p; {
  634+void
  635+upput( p , size) register NODE *p; {
633636         cerror( "upput" );
 634637         }
 635638 
<>636 -adrput( p ) register NODE *p; {
  639+void
  640+adrput(FILE *fp, NODE *p)
  641+{
637642         register int r;
 638643         /* output an address, with offsets, from p */
 639644 
<>640 -        if( p->op == FLD ){
 641 -                p = p->left;
  645+        if( p->n_op == FLD ){
  646+                p = p->n_left;
642647                 }
<>643 -        switch( p->op ){
  648+        switch( p->n_op ){
644649 
 645650         case NAME:
 646651                 acon( p );
 647652                 return;
 648653 
 649654         case ICON:
 650655                 /* addressable value of the constant */
<>651 -                printf( "$" );
 652 -                acon( p );
  656+                if (p->n_name[0] == '\0') /* uses xxxab */
  657+                        printf("$");
  658+                acon(p);
653659                 return;
 654660 
 655661         case REG:
<>656 -                printf( "%s", rnames[p->rval] );
  662+                printf( "%s", rnames[p->n_rval] );
657663                 return;
 658664 
 659665         case OREG:
<>660 -                r = p->rval;
  666+                r = p->n_rval;
661667                 if( R2TEST(r) ){ /* double indexing */
 662668                         register int flags;
 663669 
 664670                         flags = R2UPK3(r);
 665671                         if( flags & 1 ) printf("*");
 666672                         if( flags & 4 ) printf("-");
<>667 -                        if( p->lval != 0 || p->name[0] != '\0' ) acon(p);
  673+                        if( p->n_lval != 0 || p->n_name[0] != '\0' ) acon(p);
668674                         if( R2UPK1(r) != 100) printf( "(%s)", rnames[R2UPK1(r)] );
 669675                         if( flags & 2 ) printf("+");
 670676                         printf( "[%s]", rnames[R2UPK2(r)] );
 671677                         return;
 672678                         }
 673679                 if( r == AP ){  /* in the argument region */
<>674 -                        if( p->lval <= 0 || p->name[0] != '\0' ) werror( "bad arg temp" );
 675 -                        printf( CONFMT, p->lval );
  680+                        if( p->n_lval <= 0 || p->n_name[0] != '\0' ) werror( "bad arg temp" );
  681+                        printf( CONFMT, p->n_lval );
676682                         printf( "(ap)" );
 677683                         return;
 678684                         }
<>679 -                if( p->lval != 0 || p->name[0] != '\0') acon( p );
 680 -                printf( "(%s)", rnames[p->rval] );
  685+                if( p->n_lval != 0 || p->n_name[0] != '\0') acon( p );
  686+                printf( "(%s)", rnames[p->n_rval] );
681687                 return;
 682688 
<>683 -        case UNARY MUL:
  689+        case UMUL:
684690                 /* STARNM or STARREG found */
 685691                 if( tshape(p, STARNM) ) {
 686692                         printf( "*" );
<>687 -                        adrput( p->left);
  693+                        adrput(0,  p->n_left);
688694                         }
 689695                 else {  /* STARREG - really auto inc or dec */
 690696                         register NODE *q;
 691697 
 692698 /* tbl
<>693 -                        p = p->left;
 694 -                        p->left->op = OREG;
 695 -                        if( p->op == INCR ) {
 696 -                                adrput( p->left );
  699+                        p = p->n_left;
  700+                        p->n_left->n_op = OREG;
  701+                        if( p->n_op == INCR ) {
  702+                                adrput( p->n_left );
697703                                 printf( "+" );
 698704                                 }
 699705                         else {
 700706                                 printf( "-" );
<>701 -                                adrput( p->left );
  707+                                adrput( p->n_left );
702708                                 }
 703709    tbl */
<>704 -                        printf("%c(%s)%c", (p->left->op==INCR ? '\0' : '-'),
 705 -                                rnames[p->left->left->rval],
 706 -                                (p->left->op==INCR ? '+' : '\0') );
 707 -                        p->op = OREG;
 708 -                        p->rval = p->left->left->rval;
 709 -                        q = p->left;
 710 -                        p->lval = (p->left->op == INCR ? -p->left->right->lval : 0);
 711 -                        p->name[0] = '\0';
  710+#ifdef notyet
  711+                        printf("%c(%s)%c", (p->n_left->n_op==INCR ? '\0' : '-'),
  712+                                rnames[p->n_left->n_left->n_rval],
  713+                                (p->n_left->n_op==INCR ? '+' : '\0') );
  714+#else
  715+                        printf("%c(%s)%c", '-',
  716+                                rnames[p->n_left->n_left->n_rval],
  717+                                '\0' );
  718+#endif
  719+                        p->n_op = OREG;
  720+                        p->n_rval = p->n_left->n_left->n_rval;
  721+                        q = p->n_left;
  722+#ifdef notyet
  723+
  724+                        p->n_lval = (p->n_left->n_op == INCR ? -p->n_left->n_right->n_lval : 0);
  725+#else
  726+                        p->n_lval = 0;
  727+#endif
  728+                        p->n_name[0] = '\0';
712729                         tfree(q);
 713730                 }
 714731                 return;
 715732 
 716733         default:
 717734                 cerror( "illegal address" );
 718735                 return;
<>719 -
 720 -                }
 721 -
722736         }
 723737 
<>724 -acon( p ) register NODE *p; { /* print out a constant */
  738+}
725739 
<>726 -        if( p->name[0] == '\0' ){
 727 -                printf( CONFMT, p->lval);
 728 -                }
 729 -        else if( p->lval == 0 ) {
 730 -                printf( "%.8s", p->name );
 731 -                }
 732 -        else {
 733 -                printf( "%.8s+", p->name );
 734 -                printf( CONFMT, p->lval );
 735 -                }
 736 -        }
 737 -
738740 /*
<>739 -aacon( p ) register NODE *p; { /* print out a constant */
 740 -/*
  741+ * print out a constant
  742+ */
  743+void
  744+acon(NODE *p)
  745+{
741746 
<>742 -        if( p->name[0] == '\0' ){
 743 -                printf( CONFMT, p->lval);
 744 -                return( 0 );
 745 -                }
 746 -        else if( p->lval == 0 ) {
 747 -                printf( "$%.8s", p->name );
 748 -                return( 1 );
 749 -                }
 750 -        else {
 751 -                printf( "$(" );
 752 -                printf( CONFMT, p->lval );
 753 -                printf( "+" );
 754 -                printf( "%.8s)", p->name );
 755 -                return(1);
 756 -                }
  747+        if (p->n_name[0] == '\0') {
  748+                printf(CONFMT, p->n_lval);
  749+        } else if( p->n_lval == 0 ) {
  750+                printf("%s", p->n_name);
  751+        } else {
  752+                printf("%s+", p->n_name);
  753+                printf(CONFMT, p->n_lval);
757754         }
<>758 - */
  755+}
759756 
<> 757+#if 0
760758 genscall( p, cookie ) register NODE *p; {
 761759         /* structure valued call */
 762760         return( gencall( p, cookie ) );
     
 !
794792                 ptemp->rall = NOPREF;
 795793                 ptemp->su = 0;
 796794                 genargs( p->right, ptemp );
<>797 -                ptemp->op = FREE;
  795+                nfree(ptemp);
798796                 }
 799797 
 800798         p1 = p->left;
     
 !
837835    tbl */
 838836         return(m != MDONE);
 839837         }
<> 838+#endif
840839 
<>841 -/* tbl */
 842 -char *
  840+static char *
843841 ccbranches[] = {
<>844 -        "       jeql    L%d\n",
 845 -        "       jneq    L%d\n",
 846 -        "       jleq    L%d\n",
 847 -        "       jlss    L%d\n",
 848 -        "       jgeq    L%d\n",
 849 -        "       jgtr    L%d\n",
 850 -        "       jlequ   L%d\n",
 851 -        "       jlssu   L%d\n",
 852 -        "       jgequ   L%d\n",
 853 -        "       jgtru   L%d\n",
 854 -        };
 855 -/* tbl */
  842+        "jeql",
  843+        "jneq",
  844+        "jleq",
  845+        "jlss",
  846+        "jgeq",
  847+        "jgtr",
  848+        "jlequ",
  849+        "jlssu",
  850+        "jgequ",
  851+        "jgtru",
  852+};
856853 
<>857 -cbgen( o, lab, mode ) { /*   printf conditional and unconditional branches */
  854+/*
  855+ * printf conditional and unconditional branches
  856+ */
  857+void
  858+cbgen(int o, int lab)
  859+{
858860 
<>859 -/* tbl */
 860 -        if( o == 0 ) printf( "  jbr     L%d\n", lab );
 861 -/* tbl */
 862 -        else {
 863 -                if( o > UGT ) cerror( "bad conditional branch: %s", opst[o] );
 864 -                printf( ccbranches[o-EQ], lab );
 865 -                }
  861+        if (o == 0) {
  862+                printf("        jbr     " LABFMT "\n", lab);
  863+        } else {
  864+                if (o > UGT)
  865+                        comperr("bad conditional branch: %s", opst[o]);
  866+                printf("\t%s\t" LABFMT "\n", ccbranches[o-EQ], lab);
866867         }
<> 868+}
867869 
<>868 -nextcook( p, cookie ) NODE *p; {
 869 -        /* we have failed to match p with cookie; try another */
 870 -        if( cookie == FORREW ) return( 0 );  /* hopeless! */
 871 -        if( !(cookie&(INTAREG|INTBREG)) ) return( INTAREG|INTBREG );
 872 -        if( !(cookie&INTEMP) && asgop(p->op) ) return( INTEMP|INAREG|INTAREG|INTBREG|INBREG );
 873 -        return( FORREW );
 874 -        }
 875 -
 876 -lastchance( p, cook ) NODE *p; {
 877 -        /* forget it! */
 878 -        return(0);
 879 -        }
 880 -
 881 -optim2( p ) register NODE *p; {
  870+static void
  871+optim2(NODE *p)
  872+{
882873         /* do local tree transformations and optimizations */
 883874 
 884875         register NODE *r;
 885876 
<>886 -        switch( p->op ) {
  877+        switch( p->n_op ) {
887878 
 888879         case AND:
 889880                 /* commute L and R to eliminate compliments and constants */
<>890 -                if( (p->left->op==ICON&&p->left->name[0]==0) || p->left->op==COMPL ) {
 891 -                        r = p->left;
 892 -                        p->left = p->right;
 893 -                        p->right = r;
  881+                if( (p->n_left->n_op==ICON&&p->n_left->n_name[0]==0) || p->n_left->n_op==COMPL ) {
  882+                        r = p->n_left;
  883+                        p->n_left = p->n_right;
  884+                        p->n_right = r;
894885                         }
<> 886+#if 0
895887         case ASG AND:
 896888                 /* change meaning of AND to ~R&L - bic on pdp11 */
<>897 -                r = p->right;
  889+                r = p->n_right;
898890                 if( r->op==ICON && r->name[0]==0 ) { /* compliment constant */
 899891                         r->lval = ~r->lval;
 900892                         }
     
 !
911903                         p->right->right = NULL;
 912904                         }
 913905                 break;
<>914 -
  906+#endif
915907                 }
 916908         }
 917909 
<> 910+void
  911+myreader(struct interpass *ipole)
  912+{
  913+        struct interpass *ip;
918914 
<>919 -# ifndef ONEPASS
 920 -main( argc, argv ) char *argv[]; {
 921 -        return( mainp2( argc, argv ) );
  915+        DLIST_FOREACH(ip, ipole, qelem) {
  916+                if (ip->type != IP_NODE)
  917+                        continue;
  918+                walkf(ip->ip_node, optim2);
922919         }
<_923 -# endif
  920+}
  921+
  922+/*
  923+ * Return argument size in bytes.
  924+ */
  925+static int
  926+argsiz(NODE *p)
  927+{
  928+        TWORD t = p->n_type;
  929+
  930+        if (t == STRTY || t == UNIONTY)
  931+                return p->n_stsize;
  932+        return szty(t) * (SZINT/SZCHAR);
  933+}
  934+
  935+/*
  936+ * Last chance to do something before calling a function.
  937+ */
  938+void
  939+lastcall(NODE *p)
  940+{
  941+        NODE *op = p;
  942+        int size = 0;
  943+
  944+        /* Calculate argument sizes */
  945+        p->n_qual = 0;
  946+        if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
  947+                return;
  948+        for (p = p->n_right; p->n_op == CM; p = p->n_left)
  949+                size += argsiz(p->n_right);
  950+        size += argsiz(p);
  951+        op->n_qual = size; /* XXX */
  952+}
  953+
  954+/*
  955+ * Return a class suitable for a specific type.
  956+ */
  957+int
  958+gclass(TWORD t)
  959+{
  960+        return (szty(t) == 2 ? CLASSB : CLASSA);
  961+}
  962+
  963+/*
  964+ * For class c, find worst-case displacement of the number of
  965+ * registers in the array r[] indexed by class.
  966+ */
  967+int
  968+COLORMAP(int c, int *r)
  969+{
  970+        int num;
  971+
  972+        switch (c) {
  973+        case CLASSA:
  974+                /* there are 12 classa, so min 6 classb are needed to block */
  975+                num = r[CLASSB] * 2;
  976+                num += r[CLASSA];
  977+                return num < 12;
  978+        case CLASSB:
  979+                /* 6 classa may block all classb */
  980+                num = r[CLASSB] + r[CLASSA];
  981+                return num < 6;
  982+        }
  983+        comperr("COLORMAP");
  984+        return 0; /* XXX gcc */
  985+}
  986+
  987+/*
  988+ * Special shapes.
  989+ */
  990+int
  991+special(NODE *p, int shape)
  992+{
  993+        switch (shape) {
  994+        case SNCON:
  995+                if (p->n_name[0] != '\0')
  996+                        return SRDIR;
  997+                break;
  998+        default:
  999+                comperr("special");
  1000+        }
  1001+        return SRNOPE;
  1002+}
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-02 15:58 +0200