Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110605085442

Diff

Diff from 1.30 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/arch/sparc64/local.c

Annotated File View

plunky
1.30
1 /*      $Id: local.c,v 1.30 2011/06/05 08:54:42 plunky Exp $    */
2
david
1.1
3 /*
4  * Copyright (c) 2008 David Crawshaw <david@zentus.com>
5  * 
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  * 
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 #include "pass1.h"
20
21 NODE *
22 clocal(NODE *p)
23 {
24         struct symtab *sp;
25         int op;
26         NODE *r, *l;
27
28         op = p->n_op;
29         sp = p->n_sp;
30         l  = p->n_left;
31         r  = p->n_right;
32
33 #ifdef PCC_DEBUG
34         if (xdebug) {
35                 printf("clocal in: %p, %s\n"pcopst(op));
36                 fwalk(peprint0);
37         }
38 #endif
39
40         switch (op) {
david
1.2
41
david
1.1
42         case NAME:
43                 if (sp->sclass == PARAM || sp->sclass == AUTO) {
44                         /*
45                          * Use a fake structure reference to
46                          * write out frame pointer offsets.
47                          */
48                         l = block(REGNILNILPTR+STRTY00);
49                         l->n_lval = 0;
50                         l->n_rval = FP;
51                         r = p;
52                         p = stref(block(STREFlr000));
53                 }
54                 break;
david
1.11
55         case PCONV/* Remove what PCONVs we can. */
56                 if (l->n_op == SCONV)
57                         break;
58
59                 if (l->n_op == ICON || (ISPTR(p->n_type) && ISPTR(l->n_type))) {
david
1.1
60                         l->n_type = p->n_type;
61                         l->n_qual = p->n_qual;
62                         l->n_df = p->n_df;
ragge
1.23
63                         l->n_ap = p->n_ap;
david
1.1
64                         nfree(p);
65                         p = l;
66                 }
67                 break;
68
david
1.4
69         case SCONV:
david
1.17
70         /* Remove redundant conversions. */
david
1.16
71                 if ((p->n_type & TMASK) == 0 && (l->n_type & TMASK) == 0 &&
ragge
1.26
72                     tsize(p->n_typep->n_dfp->n_ap) ==
73                     tsize(l->n_typel->n_dfl->n_ap) &&
david
1.16
74                     p->n_type != FLOAT && p->n_type != DOUBLE &&
75                     l->n_type != FLOAT && l->n_type != DOUBLE &&
76                     l->n_type != DOUBLE && p->n_type != LDOUBLE) {
77                         if (l->n_op == NAME || l->n_op == UMUL ||
78                             l->n_op == TEMP) {
david
1.9
79                                 l->n_type = p->n_type;
80                                 nfree(p);
81                                 p = l;
david
1.16
82                                 break;
david
1.9
83                         }
84                 }
85
david
1.17
86         /* Convert floating point to int before to char or short. */
87         if ((l->n_type == FLOAT || l->n_type == DOUBLE || l->n_type == LDOUBLE)
88             && (DEUNSIGN(p->n_type) == CHAR || DEUNSIGN(p->n_type) == SHORT)) {
ragge
1.23
89             p = block(SCONVpNILp->n_typep->n_dfp->n_ap);
david
1.17
90             p->n_left->n_type = INT;
91             break;
92         }
93
94         /* Transform constants now. */
david
1.4
95                 if (l->n_op != ICON)
96                         break;
97
98                 if (ISPTR(p->n_type)) {
99                         l->n_type = p->n_type;
100                         nfree(p);
101                         p = l;
102                         break;
103                 }
104
105                 switch (p->n_type) {
106                 case BOOL:      l->n_lval = (l->n_lval != 0); break;
107                 case CHAR:      l->n_lval = (char)l->n_lvalbreak;
108                 case UCHAR:     l->n_lval = l->n_lval & 0377break;
109                 case SHORT:     l->n_lval = (short)l->n_lvalbreak;
110                 case USHORT:    l->n_lval = l->n_lval & 0177777break;
david
1.12
111                 case UNSIGNED:  l->n_lval = l->n_lval & 0xffffffffbreak;
david
1.4
112                 case INT:       l->n_lval = (int)l->n_lvalbreak;
david
1.12
113                 case ULONG:
david
1.4
114                 case ULONGLONGl->n_lval = l->n_lvalbreak;
david
1.12
115                 case LONG:
david
1.4
116                 case LONGLONG:  l->n_lval = (long long)l->n_lvalbreak;
david
1.14
117                 case FLOAT:
118                 case DOUBLE:
119                 case LDOUBLE:
120                         l->n_op = FCON;
david
1.15
121                         l->n_dcon = l->n_lval;
david
1.14
122                         break;
david
1.4
123                 case VOID:
124                         break;
125                 default:
126                         cerror("sconv type unknown %d"p->n_type);
127                 }
128
129                 l->n_type = p->n_type;
130                 nfree(p);
131                 p = l;
132                 break;
david
1.6
133
david
1.1
134         case FORCE:
135                 /* Put attached value into the return register. */
136                 p->n_op = ASSIGN;
137                 p->n_right = p->n_left;
ragge
1.25
138                 p->n_left = block(REGNILNILp->n_type00);
david
1.15
139                 p->n_left->n_rval = RETREG_PRE(p->n_type);
david
1.1
140                 break;
141         }
142
143 #ifdef PCC_DEBUG
144         if (xdebug) {
145                 printf("clocal out: %p, %s\n"pcopst(op));
146                 fwalk(peprint0);
147         }
148 #endif
149
150         return p;
151 }
152
153 void
154 myp2tree(NODE *p)
155 {
david
1.14
156         struct symtab *sp;
157
158         if (p->n_op != FCON)
159                 return;
160
161         sp = tmpalloc(sizeof(struct symtab));
162         sp->sclass = STATIC;
163         sp->slevel = 1;
164         sp->soffset = getlab();
165         sp->sflags = 0;
166         sp->stype = p->n_type;
167         sp->squal = (CON >> TSHIFT);
168
169         defloc(sp);
ragge
1.26
170         ninval(0tsize(p->n_typep->n_dfp->n_ap), p);
david
1.14
171
172         p->n_op = NAME;
173         p->n_lval = 0;
174         p->n_sp = sp;
david
1.1
175 }
176
177 int
178 andable(NODE *p)
179 {
180         return 1;
181 }
182
183 int
184 cisreg(TWORD t)
185 {
186         /* SPARCv9 registers are all 64-bits wide. */
187         return 1;
188 }
189
190 void
191 spalloc(NODE *tNODE *pOFFSZ off)
192 {
193 }
194
195 void
196 instring(struct symtab *sp)
197 {
david
1.3
198         char *s, *str;
199
200         defloc(sp);
201         str = sp->sname;
202
203         printf("\t.ascii \"");
ragge
1.22
204         for (s = str; *s != 0; ) {
david
1.13
205                 if (*s++ == '\\')
david
1.3
206                         esccon(&s);
207                 if (s - str > 60) {
208                         fwrite(str1s - strstdout);
209                         printf("\"\n\t.ascii \"");
210                         str = s;
211                 }
212         }
213         fwrite(str1s - strstdout);
214         printf("\\0\"\n");
david
1.1
215 }
216
217 void
218 zbits(OFFSZ offint fsz)
219 {
220 }
221
222 void
223 infld(CONSZ offint fszCONSZ val)
224 {
225 }
226
227 void
228 ninval(CONSZ offint fszNODE *p)
229 {
david
1.11
230         TWORD t;
231         struct symtab *sp;
david
1.14
232         union { float fdouble dint ilong long l; } u;
david
1.11
233
david
1.15
234         t = p->n_type;
david
1.11
235         sp = p->n_sp;
236
237         if (ISPTR(t))
ragge
1.29
238                 p->n_type = t = LONGLONG;
david
1.11
239
david
1.15
240         if (p->n_op == ICON && sp != NULL && DEUNSIGN(t) != LONGLONG)
david
1.8
241                 cerror("ninval: not constant");
242
david
1.11
243         switch (t) {
ragge
1.29
244         case SHORT:
245         case USHORT:
246                 astypnames[USHORT] = astypnames[SHORT] = "\t.half";
247                 return 0;
248         case INT:
249         case UNSIGNED:
250                 astypnames[INT] = astypnames[UNSIGNED] = "\t.long";
251                 return 0;
252         case LONG:
253         case ULONG:
254         case LONGLONG:
255         case ULONGLONG:
256                 printf("\t.xword %lld"p->n_lval);
257                 if (sp != 0) {
258                         if (sp->sclass == STATIC && sp->slevel > 0)
259                                 printf("+" LABFMTsp->soffset);
260                         else
261                                 printf("+%s"sp->soname ?
262                                     sp->soname : exname(sp->sname));
263                 }
264                 printf("\n");
265                 break;
266         case FLOAT:
267                 u.f = (float)p->n_dcon;
268                 printf("\t.long %d\n"u.i);
269                 break;
270         case DOUBLE:
271                 u.d = (double)p->n_dcon;
272                 printf("\t.xword %lld\n"u.l);
273                 break;
274         default:
275                 return 0;
david
1.8
276         }
ragge
1.29
277         return 1;
david
1.1
278 }
279
280 char *
281 exname(char *p)
282 {
283         return p ? p : "";
284 }
285
286 TWORD
287 ctype(TWORD type)
288 {
289         return type;
290 }
291
292 void
293 calldec(NODE *pNODE *q
294 {
295 }
296
297 void
298 extdec(struct symtab *q)
299 {
300 }
301
302 void
303 defzero(struct symtab *sp)
304 {
ragge
1.23
305         int off = (tsize(sp->stypesp->sdfsp->sap) + SZCHAR - 1) / SZCHAR;
david
1.7
306         printf("\t.comm ");
307         if (sp->slevel == 0)
ragge
1.20
308                 printf("%s,%d\n"sp->soname ? sp->soname : exname(sp->sname), off);
david
1.7
309         else
david
1.10
310                 printf(LABFMT ",%d\n"sp->soffsetoff);
david
1.1
311 }
312
313 int
ragge
1.24
314 mypragma(char *str)
david
1.1
315 {
316         return 0;
317 }
318
319 void
320 fixdef(struct symtab *sp)
321 {
322 }
gmcgarry
1.18
323
324 void
325 pass1_lastchance(struct interpass *ip)
326 {
327 }
328
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-01 08:01 +0200