Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110605085442

Diff

Diff from 1.25 to:

Annotations

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

Annotated File View

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