Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.2
 
1.3
 
MAIN:gmcgarry:20071116001740
 
local.c
_>3131  * Simon Olsson (simols-1@student.ltu.se) 2005.
 3232  */
 3333 
<>34 -# include "pass1.h"
  34+#include "pass1.h"
3535 
<>36 -/*      this file contains code which is dependent on the target machine */
 37 -
3836 static int inbits, inval;
 3937 
<>40 -static void
 41 -fixupfuncargs(NODE *r, int *reg)
  38+#ifdef MIPS_BIGENDIAN
  39+/*
  40+ * If we're big endian, then all OREG loads of a type
  41+ * larger than the destination, must have the
  42+ * offset changed to point to the correct bytes in memory.
  43+ */
  44+static NODE *
  45+offchg(NODE *p)
4246 {
<>43 -#ifdef PCC_DEBUG
 44 -        if (xdebug)
 45 -                printf("fixupfuncargs(): r=%p\n", r);
 46 -#endif
  47+        NODE *l = p->n_left;
4748 
<>48 -        if (r->n_op == CM) {
 49 -                /* recurse to the bottom of the tree */
 50 -                fixupfuncargs(r->n_left, reg);
  49+        if (p->n_op != SCONV)
  50+                return;
5151 
<>52 -                if (*reg > A3) {
 53 -                        r->n_right = block(FUNARG, r->n_right, NIL,
 54 -                            r->n_right->n_type, r->n_right->n_df,
 55 -                            r->n_right->n_sue);
 56 -                        (*reg)++;
 57 -                        return;
 58 -                }
  52+        switch (l->n_type) {
  53+        case SHORT:
  54+        case USHORT:
  55+                if (DEUNSIGN(p->n_type) == CHAR)
  56+                        l->n_lval += 1;
  57+                break;
  58+        case LONG:
  59+        case ULONG:
  60+        case INT:
  61+        case UNSIGNED:
  62+                if (DEUNSIGN(p->n_type) == CHAR)
  63+                        l->n_lval += 3;
  64+                else if (DEUNSIGNED(p->n_type) == SHORT)
  65+                        l->n_lval += 2;
  66+                break;
  67+        case LONGLONG:
  68+        case ULONGLONG:
  69+                if (DEUNSIGN(p->n_type) == CHAR)
  70+                        l->n_lval += 7;
  71+                else if (DEUNSIGNED(p->n_type) == SHORT)
  72+                        l->n_lval += 6;
  73+                else if (DEUNSIGN(p->n_type) == INT ||
  74+                    DEUNSIGN(p->n_type) == LONG)
  75+                        p->n_lval += 4;
  76+        default:
  77+                comperr("offchg: unknown type");
  78+                break;
  79+        }
5980 
<>60 -                r->n_right = block(ASSIGN, NIL, r->n_right,
 61 -                            r->n_right->n_type, r->n_right->n_df,
 62 -                            r->n_right->n_sue);
 63 -                r->n_right->n_left = block(REG, NIL, NIL, r->n_right->n_type, 0, MKSUE(INT));
 64 -
 65 -                if (r->n_right->n_type == ULONGLONG || r->n_right->n_type == LONGLONG) {
 66 -                        r->n_right->n_left->n_rval = A0A1 + (*reg) - A0;
 67 -                        (*reg) += 2;
 68 -                } else {
 69 -                        r->n_right->n_left->n_rval = (*reg);
 70 -                        (*reg)++;
 71 -                }
 72 -
 73 -        } else {
 74 -                NODE *l = talloc();
 75 -                *l = *r;
 76 -                r->n_op = ASSIGN;
 77 -                r->n_left = block(REG, NIL, NIL, l->n_type, 0, MKSUE(INT));
 78 -                r->n_right = l;
 79 -                if (r->n_right->n_type == ULONGLONG || r->n_right->n_type == LONGLONG) {
 80 -                        r->n_left->n_rval = A0A1 + (*reg) - A0;
 81 -                        (*reg) += 2;
 82 -                } else {
 83 -                        r->n_left->n_rval = (*reg);
 84 -                        (*reg)++;
 85 -                }
 86 -        }
  81+        return p;
8782 }
<> 83+#endif
8884 
<>89 -
  85+/* this is called to do local transformations on
  86+ * an expression tree preparitory to its being
  87+ * written out in intermediate code.
  88+ */
9089 NODE *
 9190 clocal(NODE *p)
 9291 {
<>93 -        /* this is called to do local transformations on
 94 -           an expression tree preparitory to its being
 95 -           written out in intermediate code.
 96 -        */
 97 -
 98 -        /* the major essential job is rewriting the
 99 -           automatic variables and arguments in terms of
 100 -           REG and OREG nodes */
 101 -        /* conversion ops which are not necessary are also clobbered here */
 102 -        /* in addition, any special features (such as rewriting
 103 -           exclusive or) are easily handled here as well */
 104 -
 105 -        register struct symtab *q;
 106 -        register NODE *r, *l;
 107 -        register int o;
 108 -        register int m, ml;
  92+        struct symtab *q;
  93+        NODE *r, *l;
  94+        int o;
  95+        int m, ml;
10996         TWORD t;
 11097 
 11198 //printf("in:\n");
 11299 //fwalk(p, eprint, 0);
<> 100+
113101         switch( o = p->n_op ){
 114102 
<>115 -        case CALL:
 116 -
 117 -                {
 118 -                int reg = A0;
 119 -                fixupfuncargs(p->n_right, &reg);
 120 -                }
 121 -
 122 -#if 0
 123 -                for (r = p->n_right; r->n_op == CM; r = r->n_left) {
 124 -                        if (r->n_right->n_op != STARG &&
 125 -                            r->n_right->n_op != FUNARG) {
 126 -                                r->n_right = block(FUNARG, r->n_right, NIL,
 127 -                                    r->n_right->n_type, r->n_right->n_df,
 128 -                                    r->n_right->n_sue);
 129 -                                }
 130 -                }
 131 -                if (r->n_op != STARG && r->n_op != FUNARG) {
 132 -                        l = talloc();
 133 -                        *l = *r;
 134 -                        r->n_op = FUNARG; r->n_left = l; r->n_type = l->n_type;
 135 -                }
 136 -
 137 -                break;
 138 -#endif
 139 -
140103         case NAME:
 141104                 if ((q = p->n_sp) == NULL)
 142105                         return p; /* Nothing to care about */
     
 !
148111                         /* fake up a structure reference */
 149112                         r = block(REG, NIL, NIL, PTR+STRTY, 0, 0);
 150113                         r->n_lval = 0;
<>151 -                        r->n_rval = FPREG;
  114+                        r->n_rval = FP;
152115                         p = stref(block(STREF, r, p, 0, 0, 0));
 153116                         break;
 154117 
     
 !
235198                         return l;
 236199                 }
 237200 
<> 201+#ifdef MIPS_BIGENDIAN
  202+                /*
  203+                 * If we're big endian, then all OREG loads of a type
  204+                 * larger than the destination, must have the
  205+                 * offset changed to point to the correct bytes in memory.
  206+                 */
  207+                if (l->n_type == OREG)
  208+                        p = offchg(p);
  209+#endif
  210+
238211                 if ((p->n_type & TMASK) == 0 && (l->n_type & TMASK) == 0 &&
 239212                     btdims[p->n_type].suesize == btdims[l->n_type].suesize) {
 240213                         if (p->n_type != FLOAT && p->n_type != DOUBLE &&
     
 !
248221                         }
 249222                 }
 250223 
<>251 -#if 0
252224                 if ((p->n_type == INT || p->n_type == UNSIGNED) &&
 253225                     ISPTR(l->n_type)) {
 254226                         nfree(p);
 255227                         return l;
 256228                 }
<>257 -#endif
258229 
 259230                 o = l->n_op;
 260231                 m = p->n_type;
     
 !
338309                 p->n_op = ASSIGN;
 339310                 p->n_right = p->n_left;
 340311                 p->n_left = block(REG, NIL, NIL, p->n_type, 0, MKSUE(INT));
<>341 -                p->n_left->n_rval = RETREG(p->n_type);;
  312+                p->n_left->n_rval = RETREG(p->n_type);
342313                 break;
 343314         }
<> 315+
344316 //printf("ut:\n");
 345317 //fwalk(p, eprint, 0);
 346318 
<>347 -
348319         return(p);
 349320 }
 350321 
     
 !
385356  * being added to a pointer of type t, in order to be off bits offset
 386357  * into a structure
 387358  * t, d, and s are the type, dimension offset, and sizeoffset
<>388 - * For pdp10, return the type-specific index number which calculation
 389 - * is based on its size. For example, short a[3] would return 3.
390359  * Be careful about only handling first-level pointers, the following
 391360  * indirections must be fullword.
 392361  */
 393362 NODE *
 394363 offcon(OFFSZ off, TWORD t, union dimfun *d, struct suedef *sue)
 395364 {
<>396 -        register NODE *p;
  365+        NODE *p;
397366 
 398367         if (xdebug)
 399368                 printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
 400369                     off, t, d, sue->suesize);
 401370 
<>402 -        p = bcon(0);
 403 -        p->n_lval = off/SZCHAR/* Default */
 404 -        return(p);
  371+        p = bcon(off/SZCHAR);
  372+        return p;
405373 }
 406374 
 407375 /*
     
 !
448416 void
 449417 ninval(CONSZ off, int fsz, NODE *p)
 450418 {
<>451 -        struct symtab *q;
 452 -        TWORD t;
 453 -        int i;
  419+        union { float f; double d; long double l; int i[3]; } u;
  420+        struct symtab *q;
  421+        TWORD t;
  422+#ifndef USE_GAS
  423+        int i;
  424+#endif
454425 
<>455 -        p = p->n_left;
 456 -        t = p->n_type;
 457 -        if (t > BTMASK)
 458 -                t = INT; /* pointer */
  426+        t = p->n_type;
  427+        if (t > BTMASK)
  428+                t = INT; /* pointer */
459429 
<>460 -        switch (t) {
 461 -        case LONGLONG:
 462 -        case ULONGLONG:
 463 -                i = (p->n_lval >> 32);
 464 -                p->n_lval &= 0xffffffff;
 465 -                p->n_type = INT;
 466 -                ninval(off, 32, p);
 467 -                p->n_lval = i;
 468 -                ninval(off+32, 32, p);
 469 -                break;
 470 -        case INT:
 471 -        case UNSIGNED:
 472 -                printf("\t.long 0x%x", (int)p->n_lval);
 473 -                if ((q = p->n_sp) != NULL) {
 474 -                        if ((q->sclass == STATIC && q->slevel > 0) ||
 475 -                            q->sclass == ILABEL) {
 476 -                                printf("+" LABFMT, q->soffset);
 477 -                        } else
 478 -                                printf("+%s", exname(q->sname));
 479 -                }
 480 -                printf("\n");
 481 -                break;
 482 -        default:
 483 -                cerror("ninval");
 484 -        }
 485 -}
  430+        if (p->n_op != ICON && p->n_op != FCON)
  431+                cerror("ninval: init node not constant");
486432 
<>487 -#if 0
 488 -/*
 489 - * print out an integer.
 490 - */
 491 -void
 492 -inval(CONSZ word)
 493 -{
 494 -        word &= 0xffffffff;
 495 -        printf("        .long 0x%llx\n", word);
 496 -}
  433+        if (p->n_op == ICON && p->n_sp != NULL && DEUNSIGN(t) != INT)
  434+                uerror("element not constant");
497435 
<>498 -/* output code to initialize a floating point value */
 499 -/* the proper alignment has been obtained */
 500 -void
 501 -finval(NODE *p)
 502 -{
 503 -        switch (p->n_type) {
 504 -        case LDOUBLE:
 505 -                printf("\t.tfloat\t0t%.20Le\n", p->n_dcon);
 506 -                break;
 507 -        case DOUBLE:
 508 -                printf("\t.dfloat\t0d%.20e\n", (double)p->n_dcon);
 509 -                break;
 510 -        case FLOAT:
 511 -                printf("\t.ffloat\t0f%.20e\n", (float)p->n_dcon);
 512 -                break;
 513 -        }
 514 -}
  436+        switch (t) {
  437+        case LONGLONG:
  438+        case ULONGLONG:
  439+#ifdef USE_GAS
  440+                printf("\t.dword 0x%llx\n", (long long)p->n_lval);
  441+#else
  442+                i = (p->n_lval >> 32);
  443+                p->n_lval &= 0xffffffff;
  444+                p->n_type = INT;
  445+                ninval(off, 32, p);
  446+                p->n_lval = i;
  447+                ninval(off+32, 32, p);
515448 #endif
<> 449+                break;
  450+        case BOOL:
  451+                if (p->n_lval > 1)
  452+                        p->n_lval = p->n_lval != 0;
  453+                /* FALLTHROUGH */
  454+        case INT:
  455+        case UNSIGNED:
  456+                printf("\t.word 0x%x", (int)p->n_lval);
  457+                if ((q = p->n_sp) != NULL) {
  458+                        if ((q->sclass == STATIC && q->slevel > 0) ||
  459+                            q->sclass == ILABEL) {
  460+                                printf("+" LABFMT, q->soffset);
  461+                        } else
  462+                                printf("+%s", exname(q->sname));
  463+                }
  464+                printf("\n");
  465+                break;
  466+        case SHORT:
  467+        case USHORT:
  468+                printf("\t.half 0x%x\n", (int)p->n_lval & 0xffff);
  469+                break;
  470+        case CHAR:
  471+        case UCHAR:
  472+                printf("\t.byte %d\n", (int)p->n_lval & 0xff);
  473+                break;
  474+        case LDOUBLE:
  475+                u.i[2] = 0;
  476+                u.l = (long double)p->n_dcon;
  477+                printf("\t.word\t0x%x,0x%x,0x%x\n", u.i[0], u.i[1], u.i[2]);
  478+                break;
  479+        case DOUBLE:
  480+                u.d = (double)p->n_dcon;
  481+                printf("\t.word\t0x%x\n", u.i[0]);
  482+                printf("\t.word\t0x%x\n", u.i[1]);
  483+                break;
  484+        case FLOAT:
  485+                u.f = (float)p->n_dcon;
  486+                printf("\t.word\t0x%x\n", u.i[0]);
  487+                break;
  488+        default:
  489+                cerror("ninval");
  490+        }
  491+}
516492 
 517493 /* make a name look like an external name in the local machine */
 518494 char *
     
 !
587563         off = (off+(SZCHAR-1))/SZCHAR;
 588564         if (q->slevel == 0)
 589565 #ifdef GCC_COMPAT
<>590 -                printf("        .lcomm %s,0%o\n", gcc_findname(q), off);
  566+                printf("\t.lcomm %s,0%o\n", gcc_findname(q), off);
591567 #else
<>592 -                printf("        .lcomm %s,0%o\n", exname(q->sname), off);
  568+                printf("\t.lcomm %s,0%o\n", exname(q->sname), off);
593569 #endif
 594570         else
<>595 -                printf("        .lcomm " LABFMT ",0%o\n", q->soffset, off);
  571+                printf("\t.lcomm " LABFMT ",0%o\n", q->soffset, off);
596572 }
 597573 
 598574 /*
     
 !
604580         printf(LABFMT ":\n", label);
 605581 }
 606582 
<>607 -static char *loctbl[] = { "text", "data", "data", "data" };
  583+static char *loctbl[] = { "text", "data", "bss", "data" };
608584 
 609585 void
 610586 setloc1(int locc)
 611587 {
<>612 -        if (locc == lastloc)
  588+        //printf("setloc1(%d)\n", locc);
  589+        if ((locc == lastloc) || (lastloc == DATA && locc == STRNG) || (locc == STRNG || lastloc == DATA))
613590                 return;
 614591         lastloc = locc;
<>615 -        printf("        .%s\n", loctbl[locc]);
  592+        printf("\t.%s\n", loctbl[locc]);
<_616593 }
 617594 
 618595 /*
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-01 15:48 +0200