Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20080622152459

Diff

Diff from 1.20 to:

Annotations

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

Annotated File View

david
1.1
1 /*
2  * Copyright (c) 2008 David Crawshaw <david@zentus.com>
3  * 
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  * 
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include "pass1.h"
18 #include "pass2.h"
19
david
1.11
20
david
1.1
21 char *
22 rnames[] = {
23         /* "\%g0", always zero, removed due to 31-element class limit */
24                 "\%g1""\%g2""\%g3""\%g4""\%g5""\%g6""\%g7",
25         "\%o0""\%o1""\%o2""\%o3""\%o4""\%o5""\%o6""\%o7",
26         "\%l0""\%l1""\%l2""\%l3""\%l4""\%l5""\%l6""\%l7",
27         "\%i0""\%i1""\%i2""\%i3""\%i4""\%i5""\%i6""\%i7",
28
29         "\%f0",  "\%f1",  "\%f2",  "\%f3",  "\%f4",  "\%f5",  "\%f6",  "\%f7",
30         "\%f8",  "\%f9",  "\%f10""\%f11""\%f12""\%f13""\%f14""\%f15",
31         "\%f16""\%f17""\%f18""\%f19""\%f20""\%f21""\%f22""\%f23",
david
1.16
32         "\%f24""\%f25""\%f26""\%f27""\%f28""\%f29""\%f30",
david
1.1
33         /*, "\%f31" XXX removed due to 31-element class limit */
david
1.16
34
35         "\%f0",  "\%f2",  "\%f4",  "\%f6",  "\%f8",  "\%f10""\%f12""\%f14",
david
1.18
36         "\%f16""\%f18""\%f20""\%f22""\%f24""\%f26""\%f28""\%f30",
37
38         "\%sp""\%fp",
david
1.1
39 };
40
41 void
42 deflab(int label)
43 {
44         printf(LABFMT ":\n"label);
45 }
46
47 void
48 prologue(struct interpass_prolog *ipp)
49 {
david
1.3
50         int istack;
david
1.1
51
david
1.11
52         stack = V9RESERVE + V9STEP(p2maxautooff);
david
1.3
53
54         for (i=ipp->ipp_regsii >>= 1)
david
1.1
55                 if (i & 1)
david
1.11
56                         stack += 16;
david
1.1
57
58         /* TODO printf("\t.proc %d\n"); */
59         printf("\t.global %s\n"ipp->ipp_name);
60         printf("\t.align 4\n");
61         printf("%s:\n"ipp->ipp_name);
david
1.13
62         if (SIMM13(stack))
63                 printf("\tsave %%sp,-%d,%%sp\n"stack);
64         else {
david
1.14
65                 printf("\tsetx -%d,%%g4,%%g1\n"stack);
david
1.13
66                 printf("\tsave %%sp,%%g1,%%sp\n");
67         }
david
1.1
68 }
69
70 void
71 eoftn(struct interpass_prolog *ipp)
72 {
73         printf("\tret\n");
74         printf("\trestore\n");
75         printf("\t.type %s,#function\n"ipp->ipp_name);
76         printf("\t.size %s,(.-%s)\n"ipp->ipp_nameipp->ipp_name);
77 }
78
79 void
80 hopcode(int fint o)
81 {
82         char *str;
83
84         switch (o) {
david
1.6
85                 case EQ:        str = "brz"break;
86                 case NE:        str = "brnz"break;
david
1.1
87                 case ULE:
david
1.6
88                 case LE:        str = "brlez"break;
david
1.1
89                 case ULT:
david
1.6
90                 case LT:        str = "brlz";  break;
david
1.1
91                 case UGE:
david
1.6
92                 case GE:        str = "brgez"break;
david
1.1
93                 case UGT:
david
1.6
94                 case GT:        str = "brgz";  break;
david
1.1
95                 case PLUS:      str = "add"break;
96                 case MINUS:     str = "sub"break;
97                 case AND:       str = "and"break;
98                 case OR:        str = "or";  break;
99                 case ER:        str = "xor"break;
100                 default:
101                         comperr("unknown hopcode: %d (with %c)"of);
102                         return;
103         }
104
105         printf("%s%c"strf);
106 }
107
108 int
109 tlen(NODE *p)
110 {
111         switch (p->n_type) {
112                 case CHAR:
113                 case UCHAR:
114                         return 1;
115                 case SHORT:
116                 case USHORT:
117                         return (SZSHORT / SZCHAR);
david
1.17
118                 case FLOAT:
119                         return (SZFLOAT / SZCHAR);
david
1.1
120                 case DOUBLE:
121                         return (SZDOUBLE / SZCHAR);
122                 case INT:
123                 case UNSIGNED:
david
1.12
124                         return (SZINT / SZCHAR);
david
1.1
125                 case LONG:
126                 case ULONG:
127                 case LONGLONG:
128                 case ULONGLONG:
129                         return SZLONGLONG / SZCHAR;
130                 default:
131                         if (!ISPTR(p->n_type))
132                                 comperr("tlen type unknown: %d");
133                         return SZPOINT(p->n_type) / SZCHAR;
134         }
135 }
136
137 void
138 zzzcode(NODE * pint c)
139 {
david
1.17
140         char *str;
david
1.13
141         NODE *l, *r;
142         l = p->n_left;
143         r = p->n_right;
144
david
1.4
145         switch (c) {
146
david
1.13
147         case 'A':       /* Add const. */
148                 if (ISPTR(l->n_type) && l->n_rval == FP)
149                         r->n_lval += V9BIAS;
150
151                 if (SIMM13(r->n_lval))
152                         expand(p0"\tadd AL,AR,A1\t\t! add const\n");
153                 else
david
1.14
154                         expand(p0"\tsetx AR,A3,A2\t\t! add const\n"
155                                      "\tadd AL,A2,A1\n");
david
1.13
156                 break;
157         case 'B':       /* Subtract const. */
158                 if (ISPTR(l->n_type) && l->n_rval == FP)
159                         r->n_lval -= V9BIAS;
160
161                 if (SIMM13(r->n_lval))
162                         expand(p0"\tsub AL,AR,A1\t\t! subtract const\n");
163                 else
david
1.14
164                         expand(p0"\tsetx AR,A3,A2\t\t! subtract const\n"
165                                      "\tsub AL,A2,A1\n");
david
1.13
166                 break;
167         case 'C':       /* Load constant to register. */
168                 if (ISPTR(p->n_type))
david
1.4
169                         expand(p0,
david
1.13
170                                 "\tsethi %h44(AL),A1\t\t! load label\n"
david
1.10
171                                 "\tor A1,%m44(AL),A1\n"
172                                 "\tsllx A1,12,A1\n"
173                                 "\tor A1,%l44(AL),A1\n");
david
1.13
174                 else if (SIMM13(p->n_lval))
175                         expand(p0"\tor %g0,AL,A1\t\t\t! load const\n");
176                 else
david
1.14
177                         expand(p0"\tsetx AL,A2,A1\t\t! load const\n");
david
1.4
178                 break;
david
1.17
179         case 'F':       /* Floating-point comparison, cf. hopcode(). */
180                 switch (p->n_op) {
181                         case EQ:        str = "fbe"break;
182                         case NE:        str = "fbne"break;
183                         case ULE:
184                         case LE:        str = "fbule"break;
185                         case ULT:
186                         case LT:        str = "fbul";  break;
187                         case UGE:
188                         case GE:        str = "fbuge"break;
189                         case UGT:
190                         case GT:        str = "fbug";  break;
191                         /* XXX
192                         case PLUS:      str = "add"; break;
193                         case MINUS:     str = "sub"; break;
194                         case AND:       str = "and"; break;
195                         case OR:        str = "or";  break;
196                         case ER:        str = "xor"; break;*/
197                         default:
198                                 comperr("unknown float code: %d"p->n_op);
199                                 return;
200                 }
201                 printf(str);
202                 break;
203
david
1.13
204         case 'Q':       /* Structure assignment. */
205                 /* TODO Check if p->n_stsize is small and use a few ldx's
206                         to move the struct instead of memcpy. The equiv.
207                         could be done on all the architectures. */
208                 if (l->n_rval != O0)
209                         printf("\tmov %s,%s\n"rnames[l->n_rval], rnames[O0]);
210                 if (SIMM13(p->n_stsize))
211                         printf("\tor %%g0,%d,%%o2\n"p->n_stsize);
212                 else
david
1.14
213                         printf("\tsetx %d,%%g1,%%o2\n"p->n_stsize);
david
1.13
214                 printf("\tcall memcpy\t\t\t! struct assign (dest, src, len)\n");
215                 printf("\tnop\n");
david
1.9
216                 break;
david
1.4
217         default:
218                 cerror("unknown zzzcode call: %c"c);
219         }
david
1.1
220 }
221
222 int
223 rewfld(NODE * p)
224 {
225         return (1);
226 }
227
228 int
229 fldexpand(NODE *pint cookiechar **cp)
230 {
231         printf("XXX fldexpand called\n"); /* XXX */
232         return 1;
233 }
234
235 int
236 flshape(NODE * p)
237 {
238         return SRREG;
239 }
240
241 int
242 shtemp(NODE * p)
243 {
244         return 0;
245 }
246
247
248 void
249 adrcon(CONSZ val)
250 {
251 }
252
253 void
254 conput(FILE * fpNODE * p)
255 {
256         if (p->n_op != ICON) {
david
1.2
257                 comperr("conput got bad op: %s"copst(p->n_op));
david
1.1
258                 return;
259         }
260
261         if (p->n_name[0] != '\0') {
262                 fprintf(fp"%s"p->n_name);
david
1.13
263                 if (p->n_lval > 0)
264                         fprintf(fp"+");
david
1.1
265                 if (p->n_lval)
david
1.13
266                         fprintf(fp"%lld"p->n_lval);
david
1.1
267         } else
david
1.10
268                 fprintf(fpCONFMTp->n_lval);
david
1.1
269 }
270
271 void
272 insput(NODE * p)
273 {
274         comperr("insput");
275 }
276
277 void
278 upput(NODE *pint size)
279 {
280         comperr("upput");
281 }
282
283 void
284 adrput(FILE * ioNODE * p)
285 {
david
1.9
286         int64_t off;
287
david
1.1
288         if (p->n_op == FLD) {
289                 printf("adrput a FLD\n");
290                 p = p->n_left;
291         }
292
david
1.7
293         if (p->n_op == UMUL && p->n_right == 0)
294                 p = p->n_left;
295
david
1.9
296         off = p->n_lval;
297
david
1.1
298         switch (p->n_op) {
299         case NAME:
300                 if (p->n_name[0] != '\0')
301                         fputs(p->n_nameio);
david
1.9
302                 if (off > 0)
david
1.8
303                         fprintf(io"+");
david
1.9
304                 if (off != 0)
305                         fprintf(ioCONFMToff);
david
1.1
306                 return;
307         case OREG:
308                 fprintf(io"%s"rnames[p->n_rval]);
david
1.9
309                 if (p->n_rval == FP)
david
1.14
310                         off += V9BIAS;
311                 if (p->n_rval == SP)
312                         off += V9BIAS + V9RESERVE;
david
1.9
313                 if (off > 0)
david
1.8
314                         fprintf(io"+");
david
1.9
315                 if (off)
316                         fprintf(io"%lld"off);
david
1.1
317                 return;
318         case ICON:
319                 /* addressable value of the constant */
320                 conput(iop);
321                 return;
322         case REG:
323                 fputs(rnames[p->n_rval], io);
324                 return;
david
1.15
325         case FUNARG:
326                 /* We do something odd and store the stack offset in n_rval. */
327                 fprintf(io"%d"V9BIAS + V9RESERVE + p->n_rval);
328                 return;
david
1.1
329         default:
david
1.9
330                 comperr("bad address, %s, node %p"copst(p->n_op), p);
david
1.1
331                 return;
332         }
333 }
334
335 void
336 cbgen(int oint lab)
337 {
338 }
339
340 void
341 myreader(struct interpass * ipole)
342 {
343 }
344
345 void
346 mycanon(NODE * p)
347 {
348 }
349
350 void
351 myoptim(struct interpass * ipole)
352 {
353 }
354
355 void
356 rmove(int sint dTWORD t)
357 {
david
1.2
358         printf("\tmov %s,%s\t\t\t! rmove()\n"rnames[s], rnames[d]);
david
1.1
359 }
360
361 int
362 gclass(TWORD t)
363 {
david
1.17
364         if (t == FLOAT)
365                 return CLASSB;
366         if (t == DOUBLE)
367                 return CLASSC;
368         return CLASSA;
david
1.1
369 }
370
371 void
372 lastcall(NODE *p)
373 {
374 }
375
376 int
377 special(NODE *pint shape)
378 {
379         return SRNOPE;
380 }
381
382 void mflags(char *str)
383 {
384 }
385
386 int
387 COLORMAP(int cint *r)
388 {
389         int num=0;
390
391         switch (c) {
392                 case CLASSA:
393                         num += r[CLASSA];
394                         return num < 32;
395                 case CLASSB:
david
1.16
396                         num += r[CLASSB];
david
1.18
397                         num += 2*r[CLASSC];
david
1.16
398                         return num < 32;;
david
1.1
399                 case CLASSC:
400                         num += r[CLASSC];
david
1.18
401                         num += 2*r[CLASSB];
402                         return num < 17;
david
1.16
403                 case CLASSD:
404                         return 0;
david
1.1
405                 default:
david
1.16
406                         comperr("COLORMAP: unknown class: %d"c);
david
1.1
407                         return 0;
408         }
409 }
ragge
1.20
410 /*
411  * Do something target-dependent for xasm arguments.
412  * Supposed to find target-specific constraints and rewrite them.
413  */
414 int
415 myxasm(struct interpass *ipNODE *p)
416 {
417         return 0;
418 }
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-08-28 03:00 +0200