Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110623134125

Diff

Diff from 1.26 to:

Annotations

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

Annotated File View

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