Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.3
 
1.4
 
MAIN:gmcgarry:20071116001740
 
code.c
_>11 /*      $Id$    */
 22 /*
 33  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
 44  * All rights reserved.
 55  *
 66  * Redistribution and use in source and binary forms, with or without
 77  * modification, are permitted provided that the following conditions
 88  * are met:
 99  * 1. Redistributions of source code must retain the above copyright
 1010  *    notice, this list of conditions and the following disclaimer.
 1111  * 2. Redistributions in binary form must reproduce the above copyright
 1212  *    notice, this list of conditions and the following disclaimer in the
 1313  *    documentation and/or other materials provided with the distribution.
 1414  * 3. The name of the author may not be used to endorse or promote products
 1515  *    derived from this software without specific prior written permission
 1616  *
 1717  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 1818  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 1919  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 2020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 2121  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 2222  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 2323  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 2424  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 2525  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 2626  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 2727  */
 2828 
 2929 
 3030 /*
 3131  * MIPS port by Jan Enoksson (janeno-1@student.ltu.se) and
 3232  * Simon Olsson (simols-1@student.ltu.se) 2005.
 3333  */
 3434 
 3535 # include "pass1.h"
 3636 # include "manifest.h"
 3737 
 3838 /* Offset to arguments passed to a function. */
 3939 int passedargoff;
 4040 
 4141 /*
 4242  * cause the alignment to become a multiple of n
 4343  * never called for text segment.
 4444  */
 4545 void
 4646 defalign(int n)
 4747 {
 4848         n /= SZCHAR;
 4949         if (n == 1)
 5050                 return;
<>51 -        printf("        .align %d\n", n);
  51+        printf("\t.align %d\n", n);
5252 }
 5353 
 5454 /*
 5555  * define the current location as the name p->sname
 5656  * never called for text segment.
 5757  */
 5858 void
 5959 defnam(struct symtab *p)
 6060 {
 6161         char *c = p->sname;
 6262 
 6363 #ifdef GCC_COMPAT
 6464         c = gcc_findname(p);
 6565 #endif
 6666         if (p->sclass == EXTDEF)
<>67 -                printf("        .globl %s\n", c);
  67+                printf("\t.globl %s\n", c);
  68+#ifdef USE_GAS
  69+        printf("\t.type %s,@object\n", c);
  70+        printf("\t.size %s," CONFMT "\n", c, tsize(p->stype, p->sdf, p->ssue));
  71+#endif
6872         printf("%s:\n", c);
 6973 }
 7074 
<>71 -
7275 /*
 7376  * code for the end of a function
 7477  * deals with struct return here
 7578  */
 7679 void
 7780 efcode()
 7881 {
 7982         if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN)
 8083                 return;
 8184 }
 8285 
 8386 /*
<>84 - * helper for bfcode() to put register arguments on stack.
 85 - */
 86 -static void
 87 -argmove(struct symtab *s, int regno)
 88 -{
 89 -        NODE *p, *r;
 90 -
 91 -        s->sclass = PARAM;
 92 -        s->soffset = NOOFFSET;
 93 -
 94 -        oalloc(s, &passedargoff);
 95 -
 96 -        spname = s;
 97 -        p = buildtree(NAME, NIL, NIL);
 98 -        r = bcon(0);
 99 -        r->n_op = REG;
 100 -        r->n_rval = regno;
 101 -        r->n_type = p->n_type;
 102 -        r->n_sue = p->n_sue;
 103 -        r->n_df = p->n_df;
 104 -        ecode(buildtree(ASSIGN, p, r));
 105 -}
 106 -
 107 -/*
10887  * code for the beginning of a function; a is an array of
 10988  * indices in symtab for the arguments; n is the number
 11089  */
 11190 void
<>112 -bfcode(struct symtab **a, int n)
  91+bfcode(struct symtab **sp, int cnt)
11392 {
<>114 -        int i, m;
  93+        NODE *p, *q;
  94+        int i, n;
11595 
<>116 -        /* Passed arguments start 64 bits above the framepointer. */
 117 -        passedargoff = ARGINIT;
 118 -        
11996         if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) {
 12097                 /* Function returns struct, adjust arg offset */
<>121 -                for (i = 0; i < n; i++)
 122 -                        a[i]->soffset += SZPOINT(INT);
  98+                for (i = 0; i < cnt; i++)
  99+                        sp[i]->soffset += SZPOINT(INT);
123100         }
 124101 
<>125 -        m = n <= 4 ? n : 4;
 126 -        
 127 -        for(i = 0; i < m; i++) {
 128 -            /*
 129 -            if(a[i]->stype == LONGLONG || a[i]->stype == ULONGLONG) {
 130 -                printf("longlong\n");
 131 -                argmove(a[i], A0+i);
  102+        /* recalculate the arg offset and create TEMP moves */
  103+        for (n = A0, i = 0; i < cnt; i++) {
  104+                if (n + szty(sp[i]->stype) <= A0 + MIPS_NARGREGS) {
  105+                        if (xtemps) {
  106+                                p = tempnode(0, sp[i]->stype,
  107+                                    sp[i]->sdf, sp[i]->ssue);
  108+                                spname = sp[i];
  109+                                q = block(REG, NIL, NIL,
  110+                                    sp[i]->stype, sp[i]->sdf, sp[i]->ssue);
  111+                                q->n_rval = n;
  112+                                p = buildtree(ASSIGN, p, q);
  113+                                sp[i]->soffset = p->n_left->n_lval;
  114+                                sp[i]->sflags |= STNODE;
  115+                        } else {
  116+                                // sp[i]->soffset += ARGINIT;
  117+                                spname = sp[i];
  118+                                q = block(REG, NIL, NIL,
  119+                                    sp[i]->stype, sp[i]->sdf, sp[i]->ssue);
  120+                                q->n_rval = n;
  121+                                p = buildtree(ASSIGN, buildtree(NAME, 0, 0), q);
  122+                        }
  123+                        ecomp(p);
  124+                } else {
  125+                        // sp[i]->soffset += ARGINIT;
  126+                        if (xtemps) {
  127+                                /* put stack args in temps if optimizing */
  128+                                spname = sp[i];
  129+                                p = tempnode(0, sp[i]->stype,
  130+                                    sp[i]->sdf, sp[i]->ssue);
  131+                                p = buildtree(ASSIGN, p, buildtree(NAME, 0, 0));
  132+                                sp[i]->soffset = p->n_left->n_lval;
  133+                                sp[i]->sflags |= STNODE;
  134+                                ecomp(p);
  135+                        }
  136+               
  137+                }
  138+                n += szty(sp[i]->stype);
  139+        }
132140 
<>133 -                if(i+1 < 4) {
 134 -                    argmove(a[i], A0+i+1);
 135 -                }
 136 -                
 137 -                i++;            
 138 -                } else*/
 139 -            argmove(a[i], A0+i);
 140 -
 141 -        }
142141 }
 143142 
 144143 
 145144 /*
 146145  * by now, the automatics and register variables are allocated
 147146  */
 148147 void
 149148 bccode()
 150149 {
 151150         SETOFF(autooff, SZINT);
 152151 }
 153152 
 154153 /* called just before final exit */
 155154 /* flag is 1 if errors, 0 if none */
 156155 void
 157156 ejobcode(int flag )
 158157 {
 159158 }
 160159 
 161160 void
 162161 bjobcode()
 163162 {
 164163 }
 165164 
 166165 /*
 167166  * Print character t at position i in one string, until t == -1.
 168167  * Locctr & label is already defined.
 169168  */
 170169 void
 171170 bycode(int t, int i)
 172171 {
 173172         static int lastoctal = 0;
 174173 
 175174         /* put byte i+1 in a string */
 176175 
 177176         if (t < 0) {
 178177                 if (i != 0)
 179178                         puts("\"");
 180179         } else {
 181180                 if (i == 0)
 182181                         printf("\t.asciiz \"");
 183182                 if (t == 0)
 184183                         return;
 185184                 else if (t == '\\' || t == '"') {
 186185                         lastoctal = 0;
 187186                         putchar('\\');
 188187                         putchar(t);
 189188                 } else if (t == 012) {
 190189                         printf("\\n");
 191190                 } else if (t < 040 || t >= 0177) {
 192191                         lastoctal++;
 193192                         printf("\\%o",t);
 194193                 } else if (lastoctal && '0' <= t && t <= '9') {
 195194                         lastoctal = 0;
 196195                         printf("\"\n\t.asciiz \"%c", t);
 197196                 } else {        
 198197                         lastoctal = 0;
 199198                         putchar(t);
 200199                 }
 201200         }
 202201 }
 203202 
 204203 /*
<>205 - * n integer words of zeros
 206 - */
 207 -void
 208 -zecode(int n)
 209 -{
 210 -        printf("        .zero %d\n", n * (SZINT/SZCHAR));
 211 -//      inoff += n * SZINT;
 212 -}
 213 -
 214 -/*
215204  * return the alignment of field of type t
 216205  */
 217206 int
 218207 fldal(unsigned int t)
 219208 {
 220209         uerror("illegal field type");
 221210         return(ALINT);
 222211 }
 223212 
 224213 /* fix up type of field p */
 225214 void
 226215 fldty(struct symtab *p)
 227216 {
 228217 }
 229218 
 230219 /* p points to an array of structures, each consisting
 231220  * of a constant value and a label.
 232221  * The first is >=0 if there is a default label;
 233222  * its value is the label number
 234223  * The entries p[1] to p[n] are the nontrivial cases
 235224  * XXX - fix genswitch.
 236225  */
 237226 void
 238227 genswitch(int num, struct swents **p, int n)
 239228 {
 240229         NODE *r;
 241230         int i;
 242231 
 243232         /* simple switch code */
 244233         for (i = 1; i <= n; ++i) {
 245234                 /* already in 1 */
 246235                 r = tempnode(num, INT, 0, MKSUE(INT));
 247236                 r = buildtree(NE, r, bcon(p[i]->sval));
 248237                 cbranch(buildtree(NOT, r, NIL), bcon(p[i]->slab));
 249238         }
 250239         if (p[0]->slab > 0)
 251240                 branch(p[0]->slab);
 252241 }
<> 242+
  243+static void
  244+moveargs(NODE **n, int *regp)
  245+{
  246+        NODE *r = *n;
  247+        NODE *t;
  248+        int sz;
  249+        int regnum;
  250+
  251+        if (r->n_op == CM) {
  252+                moveargs(&r->n_left, regp);
  253+                n = &r->n_right;
  254+                r = r->n_right;
  255+        }
  256+
  257+        regnum = *regp;
  258+        sz = szty(r->n_type);
  259+
  260+        if (regnum + sz <= A0 + MIPS_NARGREGS) {
  261+                t = block(REG, NIL, NIL, r->n_type, r->n_df, r->n_sue);
  262+                t->n_rval = regnum;
  263+                t = buildtree(ASSIGN, t, r);
  264+        } else {
  265+                t = block(FUNARG, r, NIL, r->n_type, r->n_df, r->n_sue);
  266+        }
  267+
  268+        *n = t;
  269+        *regp += sz;
  270+}
  271+
253272 /*
 254273  * Called with a function call with arguments as argument.
 255274  * This is done early in buildtree() and only done once.
 256275  */
 257276 NODE *
 258277 funcode(NODE *p)
 259278 {
<> 279+        int regnum = A0;
  280+        moveargs(&p->n_right, &regnum);
<_260281         return p;
 261282 }
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-23 16:26 +0200