Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110623134125

Diff

Diff from 1.34 to:

Annotations

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

Annotated File View

ragge
1.34
1 /*      $Id: local.c,v 1.34 2011/06/23 13:41:25 ragge Exp $     */
plunky
1.30
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 {
ragge
1.31
193         cerror("spalloc");
david
1.1
194 }
195
ragge
1.31
196 int
david
1.1
197 ninval(CONSZ offint fszNODE *p)
198 {
david
1.14
199         union { float fdouble dint ilong long l; } u;
david
1.11
200
ragge
1.31
201         switch (p->n_type) {
ragge
1.29
202         case FLOAT:
203                 u.f = (float)p->n_dcon;
204                 printf("\t.long %d\n"u.i);
205                 break;
206         case DOUBLE:
207                 u.d = (double)p->n_dcon;
208                 printf("\t.xword %lld\n"u.l);
209                 break;
210         default:
211                 return 0;
david
1.8
212         }
ragge
1.29
213         return 1;
david
1.1
214 }
215
216 char *
217 exname(char *p)
218 {
219         return p ? p : "";
220 }
221
222 TWORD
223 ctype(TWORD type)
224 {
ragge
1.33
225         switch (BTYPE(type)) {
226         case LONGLONG:
227                 MODTYPE(type,LONG);
228                 break;
229         case ULONGLONG:
230                 MODTYPE(type,ULONG);
231
232         }
david
1.1
233         return type;
234 }
235
236 void
237 calldec(NODE *pNODE *q
238 {
239 }
240
241 void
242 extdec(struct symtab *q)
243 {
244 }
245
246 void
247 defzero(struct symtab *sp)
248 {
ragge
1.34
249         int off;
250         char *name;
251
252         if ((name = sp->soname) == NULL)
253                 name = exname(sp->sname);
254         off = tsize(sp->stypesp->sdfsp->sap);
255         SETOFF(off,SZCHAR);
256         off /= SZCHAR;
257
258         if (sp->sclass == STATIC)
259                 printf("\t.local %s\n"name);
david
1.7
260         if (sp->slevel == 0)
ragge
1.34
261                 printf("\t.comm %s,%d\n"nameoff);
david
1.7
262         else
ragge
1.34
263                 printf("\t.comm " LABFMT ",%d\n"sp->soffsetoff);
david
1.1
264 }
265
266 int
ragge
1.24
267 mypragma(char *str)
david
1.1
268 {
269         return 0;
270 }
271
272 void
273 fixdef(struct symtab *sp)
274 {
275 }
gmcgarry
1.18
276
277 void
278 pass1_lastchance(struct interpass *ip)
279 {
280 }
281
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-03 01:45 +0200