Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20071126044115

Diff

Diff from 1.6 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/arch/mips/code.c

Annotated File View

gmcgarry
1.6
1 /*      $Id: code.c,v 1.6 2007/11/26 04:41:15 gmcgarry Exp $    */
ragge
1.1
2 /*
3  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29
30 /*
31  * MIPS port by Jan Enoksson (janeno-1@student.ltu.se) and
32  * Simon Olsson (simols-1@student.ltu.se) 2005.
33  */
34
35 # include "pass1.h"
36 # include "manifest.h"
37
38 /* Offset to arguments passed to a function. */
39 int passedargoff;
40
41 /*
42  * cause the alignment to become a multiple of n
43  * never called for text segment.
44  */
45 void
46 defalign(int n)
47 {
48         n /= SZCHAR;
49         if (n == 1)
50                 return;
gmcgarry
1.4
51         printf("\t.align %d\n"n);
ragge
1.1
52 }
53
54 /*
55  * define the current location as the name p->sname
56  * never called for text segment.
57  */
58 void
59 defnam(struct symtab *p)
60 {
61         char *c = p->sname;
62
63 #ifdef GCC_COMPAT
64         c = gcc_findname(p);
65 #endif
66         if (p->sclass == EXTDEF)
gmcgarry
1.4
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"ctsize(p->stypep->sdfp->ssue));
71 #endif
ragge
1.1
72         printf("%s:\n"c);
73 }
74
75 /*
76  * code for the end of a function
77  * deals with struct return here
78  */
79 void
80 efcode()
81 {
82         if (cftnsp->stype != STRTY+FTN && cftnsp->stype != UNIONTY+FTN)
83                 return;
84 }
85
86 /*
87  * code for the beginning of a function; a is an array of
88  * indices in symtab for the arguments; n is the number
89  */
90 void
gmcgarry
1.4
91 bfcode(struct symtab **spint cnt)
ragge
1.1
92 {
gmcgarry
1.4
93         NODE *p, *q;
94         int in;
ragge
1.1
95
96         if (cftnsp->stype == STRTY+FTN || cftnsp->stype == UNIONTY+FTN) {
97                 /* Function returns struct, adjust arg offset */
gmcgarry
1.4
98                 for (i = 0i < cnti++)
99                         sp[i]->soffset += SZPOINT(INT);
ragge
1.1
100         }
101
gmcgarry
1.4
102         /* recalculate the arg offset and create TEMP moves */
gmcgarry
1.6
103         for (n = 0i = 0i < cnti++) {
104                 int sz = szty(sp[i]->stype);
105                 if (n + sz <= nargregs) {
gmcgarry
1.4
106                         if (xtemps) {
107                                 p = tempnode(0sp[i]->stype,
108                                     sp[i]->sdfsp[i]->ssue);
109                                 spname = sp[i];
110                                 q = block(REGNILNIL,
111                                     sp[i]->stypesp[i]->sdfsp[i]->ssue);
gmcgarry
1.6
112                                 q->n_rval = sz == 2 ? A0A1 + n : A0 + n;
gmcgarry
1.4
113                                 p = buildtree(ASSIGNpq);
114                                 sp[i]->soffset = p->n_left->n_lval;
115                                 sp[i]->sflags |= STNODE;
116                         } else {
117                                 // sp[i]->soffset += ARGINIT;
118                                 spname = sp[i];
119                                 q = block(REGNILNIL,
120                                     sp[i]->stypesp[i]->sdfsp[i]->ssue);
gmcgarry
1.6
121                                 q->n_rval = sz == 2 ? A0A1 + n : A0 + n;
gmcgarry
1.4
122                                 p = buildtree(ASSIGNbuildtree(NAME00), q);
123                         }
124                         ecomp(p);
125                 } else {
126                         // sp[i]->soffset += ARGINIT;
127                         if (xtemps) {
128                                 /* put stack args in temps if optimizing */
129                                 spname = sp[i];
130                                 p = tempnode(0sp[i]->stype,
131                                     sp[i]->sdfsp[i]->ssue);
132                                 p = buildtree(ASSIGNpbuildtree(NAME00));
133                                 sp[i]->soffset = p->n_left->n_lval;
134                                 sp[i]->sflags |= STNODE;
135                                 ecomp(p);
136                         }
137                 
138                 }
139                 n += szty(sp[i]->stype);
140         }
ragge
1.1
141
142 }
143
144
145 /*
146  * by now, the automatics and register variables are allocated
147  */
148 void
149 bccode()
150 {
151         SETOFF(autooffSZINT);
152 }
153
154 /* called just before final exit */
155 /* flag is 1 if errors, 0 if none */
156 void
157 ejobcode(int flag )
158 {
159 }
160
161 void
162 bjobcode()
163 {
164 }
165
166 /*
167  * Print character t at position i in one string, until t == -1.
168  * Locctr & label is already defined.
169  */
170 void
171 bycode(int tint i)
172 {
gmcgarry
1.2
173         static int lastoctal = 0;
ragge
1.1
174
175         /* put byte i+1 in a string */
176
177         if (t < 0) {
178                 if (i != 0)
179                         puts("\"");
180         } else {
181                 if (i == 0)
gmcgarry
1.2
182                         printf("\t.asciiz \"");
183                 if (t == 0)
184                         return;
185                 else if (t == '\\' || t == '"') {
ragge
1.1
186                         lastoctal = 0;
187                         putchar('\\');
188                         putchar(t);
gmcgarry
1.2
189                 } else if (t == 012) {
190                         printf("\\n");
ragge
1.1
191                 } else if (t < 040 || t >= 0177) {
192                         lastoctal++;
193                         printf("\\%o",t);
194                 } else if (lastoctal && '0' <= t && t <= '9') {
195                         lastoctal = 0;
gmcgarry
1.2
196                         printf("\"\n\t.asciiz \"%c"t);
ragge
1.1
197                 } else {        
198                         lastoctal = 0;
199                         putchar(t);
200                 }
201         }
202 }
203
204 /*
205  * return the alignment of field of type t
206  */
207 int
208 fldal(unsigned int t)
209 {
210         uerror("illegal field type");
211         return(ALINT);
212 }
213
214 /* fix up type of field p */
215 void
216 fldty(struct symtab *p)
217 {
218 }
219
stefan
1.5
220 /*
ragge
1.1
221  * XXX - fix genswitch.
222  */
stefan
1.5
223 int
224 mygenswitch(int numTWORD typestruct swents **pint n)
ragge
1.1
225 {
stefan
1.5
226         return 0;
ragge
1.1
227 }
gmcgarry
1.4
228
229 static void
230 moveargs(NODE **nint *regp)
231 {
232         NODE *r = *n;
233         NODE *t;
234         int sz;
235         int regnum;
236
237         if (r->n_op == CM) {
238                 moveargs(&r->n_leftregp);
239                 n = &r->n_right;
240                 r = r->n_right;
241         }
242
243         regnum = *regp;
244         sz = szty(r->n_type);
245
gmcgarry
1.6
246         if (regnum + sz <= A0 + nargregs) {
gmcgarry
1.4
247                 t = block(REGNILNILr->n_typer->n_dfr->n_sue);
gmcgarry
1.6
248                 switch(r->n_type) {
249                 case DOUBLE:
250                 case LDOUBLE:
251                         t->n_rval = regnum + F0;
252                         break;
253                 case LONGLONG:
254                 case ULONGLONG:
255                         t->n_rval = regnum + A0A1;
256                         break;
257                 default:
258                         t->n_rval = regnum;
259                 }
gmcgarry
1.4
260                 t = buildtree(ASSIGNtr);
261         } else {
262                 t = block(FUNARGrNILr->n_typer->n_dfr->n_sue);
263         }
264
265         *n = t;
266         *regp += sz;
267 }
268
ragge
1.3
269 /*
270  * Called with a function call with arguments as argument.
271  * This is done early in buildtree() and only done once.
272  */
273 NODE *
274 funcode(NODE *p)
275 {
gmcgarry
1.4
276         int regnum = A0;
277         moveargs(&p->n_right, &regnum);
ragge
1.3
278         return p;
279 }
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-17 11:36 +0200