Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.1
 
1.2
 
MAIN:gmcgarry:20071105145703
 
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;
 5151         printf("        .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)
 6767                 printf("        .globl %s\n", c);
 6868         printf("%s:\n", c);
 6969 }
 7070 
 7171 
 7272 /*
 7373  * code for the end of a function
 7474  * deals with struct return here
 7575  */
 7676 void
 7777 efcode()
 7878 {
<>79 -        NODE *p, *q;
 80 -        int sz;
 81 -
8279         if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN)
 8380                 return;
 8481 }
 8582 
 8683 /*
 8784  * helper for bfcode() to put register arguments on stack.
 8885  */
 8986 static void
 9087 argmove(struct symtab *s, int regno)
 9188 {
 9289         NODE *p, *r;
 9390 
 9491         s->sclass = PARAM;
 9592         s->soffset = NOOFFSET;
 9693 
 9794         oalloc(s, &passedargoff);
 9895 
 9996         spname = s;
 10097         p = buildtree(NAME, NIL, NIL);
 10198         r = bcon(0);
 10299         r->n_op = REG;
 103100         r->n_rval = regno;
 104101         r->n_type = p->n_type;
 105102         r->n_sue = p->n_sue;
 106103         r->n_df = p->n_df;
 107104         ecode(buildtree(ASSIGN, p, r));
 108105 }
 109106 
 110107 /*
 111108  * code for the beginning of a function; a is an array of
 112109  * indices in symtab for the arguments; n is the number
 113110  */
 114111 void
 115112 bfcode(struct symtab **a, int n)
 116113 {
 117114         int i, m;
 118115 
 119116         /* Passed arguments start 64 bits above the framepointer. */
<>120 -        passedargoff = 64;
  117+        passedargoff = ARGINIT;
121118         
 122119         if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) {
 123120                 /* Function returns struct, adjust arg offset */
 124121                 for (i = 0; i < n; i++)
 125122                         a[i]->soffset += SZPOINT(INT);
 126123         }
 127124 
 128125         m = n <= 4 ? n : 4;
 129126         
 130127         for(i = 0; i < m; i++) {
 131128             /*
 132129             if(a[i]->stype == LONGLONG || a[i]->stype == ULONGLONG) {
 133130                 printf("longlong\n");
 134131                 argmove(a[i], A0+i);
 135132 
 136133                 if(i+1 < 4) {
 137134                     argmove(a[i], A0+i+1);
 138135                 }
 139136                 
 140137                 i++;            
 141138                 } else*/
 142139             argmove(a[i], A0+i);
 143140 
 144141         }
 145142 }
 146143 
 147144 
 148145 /*
 149146  * by now, the automatics and register variables are allocated
 150147  */
 151148 void
 152149 bccode()
 153150 {
 154151         SETOFF(autooff, SZINT);
 155152 }
 156153 
 157154 /* called just before final exit */
 158155 /* flag is 1 if errors, 0 if none */
 159156 void
 160157 ejobcode(int flag )
 161158 {
 162159 }
 163160 
 164161 void
 165162 bjobcode()
 166163 {
 167164 }
 168165 
 169166 /*
 170167  * Print character t at position i in one string, until t == -1.
 171168  * Locctr & label is already defined.
 172169  */
 173170 void
 174171 bycode(int t, int i)
 175172 {
<>176 -        static  int     lastoctal = 0;
  173+        static int lastoctal = 0;
177174 
 178175         /* put byte i+1 in a string */
 179176 
 180177         if (t < 0) {
 181178                 if (i != 0)
 182179                         puts("\"");
 183180         } else {
 184181                 if (i == 0)
<>185 -                        printf("\t.ascii \"");
 186 -                if (t == '\\' || t == '"') {
  182+                        printf("\t.asciiz \"");
  183+                if (t == 0)
  184+                        return;
  185+                else if (t == '\\' || t == '"') {
187186                         lastoctal = 0;
 188187                         putchar('\\');
 189188                         putchar(t);
<> 189+                } else if (t == 012) {
  190+                        printf("\\n");
190191                 } else if (t < 040 || t >= 0177) {
 191192                         lastoctal++;
 192193                         printf("\\%o",t);
 193194                 } else if (lastoctal && '0' <= t && t <= '9') {
 194195                         lastoctal = 0;
<>195 -                        printf("\"\n\t.ascii \"%c", t);
  196+                        printf("\"\n\t.asciiz \"%c", t);
196197                 } else {        
 197198                         lastoctal = 0;
 198199                         putchar(t);
 199200                 }
 200201         }
 201202 }
 202203 
 203204 /*
 204205  * n integer words of zeros
 205206  */
 206207 void
 207208 zecode(int n)
 208209 {
 209210         printf("        .zero %d\n", n * (SZINT/SZCHAR));
<>210 -        inoff += n * SZINT;
  211+//      inoff += n * SZINT;
211212 }
 212213 
 213214 /*
 214215  * return the alignment of field of type t
 215216  */
 216217 int
 217218 fldal(unsigned int t)
 218219 {
 219220         uerror("illegal field type");
 220221         return(ALINT);
 221222 }
 222223 
 223224 /* fix up type of field p */
 224225 void
 225226 fldty(struct symtab *p)
 226227 {
 227228 }
 228229 
 229230 /* p points to an array of structures, each consisting
 230231  * of a constant value and a label.
 231232  * The first is >=0 if there is a default label;
 232233  * its value is the label number
 233234  * The entries p[1] to p[n] are the nontrivial cases
 234235  * XXX - fix genswitch.
 235236  */
 236237 void
<>237 -genswitch(struct swents **p, int n)
  238+genswitch(int num, struct swents **p, int n)
238239 {
<> 240+        NODE *r;
  241+        int i;
  242+
  243+        /* simple switch code */
  244+        for (i = 1; i <= n; ++i) {
  245+                /* already in 1 */
  246+                r = tempnode(num, INT, 0, MKSUE(INT));
  247+                r = buildtree(NE, r, bcon(p[i]->sval));
  248+                cbranch(buildtree(NOT, r, NIL), bcon(p[i]->slab));
  249+        }
  250+        if (p[0]->slab > 0)
  251+                branch(p[0]->slab);
<_239252 }
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-11-01 12:51 +0100