Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.2
 
1.3
 
MAIN:ragge:20071112190327
 
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 {
 7979         if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN)
 8080                 return;
 8181 }
 8282 
 8383 /*
 8484  * helper for bfcode() to put register arguments on stack.
 8585  */
 8686 static void
 8787 argmove(struct symtab *s, int regno)
 8888 {
 8989         NODE *p, *r;
 9090 
 9191         s->sclass = PARAM;
 9292         s->soffset = NOOFFSET;
 9393 
 9494         oalloc(s, &passedargoff);
 9595 
 9696         spname = s;
 9797         p = buildtree(NAME, NIL, NIL);
 9898         r = bcon(0);
 9999         r->n_op = REG;
 100100         r->n_rval = regno;
 101101         r->n_type = p->n_type;
 102102         r->n_sue = p->n_sue;
 103103         r->n_df = p->n_df;
 104104         ecode(buildtree(ASSIGN, p, r));
 105105 }
 106106 
 107107 /*
 108108  * code for the beginning of a function; a is an array of
 109109  * indices in symtab for the arguments; n is the number
 110110  */
 111111 void
 112112 bfcode(struct symtab **a, int n)
 113113 {
 114114         int i, m;
 115115 
 116116         /* Passed arguments start 64 bits above the framepointer. */
 117117         passedargoff = ARGINIT;
 118118         
 119119         if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) {
 120120                 /* Function returns struct, adjust arg offset */
 121121                 for (i = 0; i < n; i++)
 122122                         a[i]->soffset += SZPOINT(INT);
 123123         }
 124124 
 125125         m = n <= 4 ? n : 4;
 126126         
 127127         for(i = 0; i < m; i++) {
 128128             /*
 129129             if(a[i]->stype == LONGLONG || a[i]->stype == ULONGLONG) {
 130130                 printf("longlong\n");
 131131                 argmove(a[i], A0+i);
 132132 
 133133                 if(i+1 < 4) {
 134134                     argmove(a[i], A0+i+1);
 135135                 }
 136136                 
 137137                 i++;            
 138138                 } else*/
 139139             argmove(a[i], A0+i);
 140140 
 141141         }
 142142 }
 143143 
 144144 
 145145 /*
 146146  * by now, the automatics and register variables are allocated
 147147  */
 148148 void
 149149 bccode()
 150150 {
 151151         SETOFF(autooff, SZINT);
 152152 }
 153153 
 154154 /* called just before final exit */
 155155 /* flag is 1 if errors, 0 if none */
 156156 void
 157157 ejobcode(int flag )
 158158 {
 159159 }
 160160 
 161161 void
 162162 bjobcode()
 163163 {
 164164 }
 165165 
 166166 /*
 167167  * Print character t at position i in one string, until t == -1.
 168168  * Locctr & label is already defined.
 169169  */
 170170 void
 171171 bycode(int t, int i)
 172172 {
 173173         static int lastoctal = 0;
 174174 
 175175         /* put byte i+1 in a string */
 176176 
 177177         if (t < 0) {
 178178                 if (i != 0)
 179179                         puts("\"");
 180180         } else {
 181181                 if (i == 0)
 182182                         printf("\t.asciiz \"");
 183183                 if (t == 0)
 184184                         return;
 185185                 else if (t == '\\' || t == '"') {
 186186                         lastoctal = 0;
 187187                         putchar('\\');
 188188                         putchar(t);
 189189                 } else if (t == 012) {
 190190                         printf("\\n");
 191191                 } else if (t < 040 || t >= 0177) {
 192192                         lastoctal++;
 193193                         printf("\\%o",t);
 194194                 } else if (lastoctal && '0' <= t && t <= '9') {
 195195                         lastoctal = 0;
 196196                         printf("\"\n\t.asciiz \"%c", t);
 197197                 } else {        
 198198                         lastoctal = 0;
 199199                         putchar(t);
 200200                 }
 201201         }
 202202 }
 203203 
 204204 /*
 205205  * n integer words of zeros
 206206  */
 207207 void
 208208 zecode(int n)
 209209 {
 210210         printf("        .zero %d\n", n * (SZINT/SZCHAR));
 211211 //      inoff += n * SZINT;
 212212 }
 213213 
 214214 /*
 215215  * return the alignment of field of type t
 216216  */
 217217 int
 218218 fldal(unsigned int t)
 219219 {
 220220         uerror("illegal field type");
 221221         return(ALINT);
 222222 }
 223223 
 224224 /* fix up type of field p */
 225225 void
 226226 fldty(struct symtab *p)
 227227 {
 228228 }
 229229 
 230230 /* p points to an array of structures, each consisting
 231231  * of a constant value and a label.
 232232  * The first is >=0 if there is a default label;
 233233  * its value is the label number
 234234  * The entries p[1] to p[n] are the nontrivial cases
 235235  * XXX - fix genswitch.
 236236  */
 237237 void
 238238 genswitch(int num, struct swents **p, int n)
 239239 {
 240240         NODE *r;
 241241         int i;
 242242 
 243243         /* simple switch code */
 244244         for (i = 1; i <= n; ++i) {
 245245                 /* already in 1 */
 246246                 r = tempnode(num, INT, 0, MKSUE(INT));
 247247                 r = buildtree(NE, r, bcon(p[i]->sval));
 248248                 cbranch(buildtree(NOT, r, NIL), bcon(p[i]->slab));
 249249         }
 250250         if (p[0]->slab > 0)
 251251                 branch(p[0]->slab);
 252252 }
<_ 253+/*
  254+ * Called with a function call with arguments as argument.
  255+ * This is done early in buildtree() and only done once.
  256+ */
  257+NODE *
  258+funcode(NODE *p)
  259+{
  260+        return p;
  261+}
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-10-31 22:32 +0100