Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20110604074729

Diff

Diff from 1.27 to:

Annotations

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

Annotated File View

ragge
1.27
1 /*      $Id: local.c,v 1.27 2011/06/04 07:47:29 ragge Exp $     */
ragge
1.1
2 /*
3  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 /*
28  * MIPS port by Jan Enoksson (janeno-1@student.ltu.se) and
29  * Simon Olsson (simols-1@student.ltu.se) 2005.
30  */
31
gmcgarry
1.7
32 #include <assert.h>
gmcgarry
1.3
33 #include "pass1.h"
ragge
1.1
34
gmcgarry
1.15
35 #define IALLOC(sz) (isinlining ? permalloc(sz) : tmpalloc(sz))
36
gmcgarry
1.2
37 static int inbitsinval;
38
gmcgarry
1.3
39 /* this is called to do local transformations on
40  * an expression tree preparitory to its being
41  * written out in intermediate code.
42  */
ragge
1.1
43 NODE *
44 clocal(NODE *p)
45 {
gmcgarry
1.3
46         struct symtab *q;
47         NODE *r, *l;
48         int o;
gmcgarry
1.7
49         int m;
gmcgarry
1.6
50         TWORD ty;
gmcgarry
1.8
51         int tmpnrisptrvoid = 0;
ragge
1.1
52
gmcgarry
1.7
53 #ifdef PCC_DEBUG
54         if (xdebug) {
gmcgarry
1.8
55                 printf("clocal in: %p\n"p);
gmcgarry
1.7
56                 fwalk(peprint0);
57         }
58 #endif
gmcgarry
1.3
59
gmcgarry
1.6
60         switch (o = p->n_op) {
ragge
1.1
61
gmcgarry
1.8
62         case UCALL:
63         case CALL:
64         case STCALL:
65         case USTCALL:
66                 if (p->n_type == VOID)
67                         break;
68                 /*
69                  * if the function returns void*, ecode() invokes
70                  * delvoid() to convert it to uchar*.
71                  * We just let this happen on the ASSIGN to the temp,
72                  * and cast the pointer back to void* on access
73                  * from the temp.
74                  */
75                 if (p->n_type == PTR+VOID)
76                         isptrvoid = 1;
ragge
1.22
77                 r = tempnode(0p->n_typep->n_dfp->n_ap);
ragge
1.12
78                 tmpnr = regno(r);
ragge
1.22
79                 r = block(ASSIGNrpp->n_typep->n_dfp->n_ap);
gmcgarry
1.9
80
ragge
1.22
81                 p = tempnode(tmpnrr->n_typer->n_dfr->n_ap);
gmcgarry
1.8
82                 if (isptrvoid) {
ragge
1.25
83                         p = block(PCONVpNILPTR+VOIDp->n_df0);
gmcgarry
1.8
84                 }
gmcgarry
1.9
85                 p = buildtree(COMOPrp);
gmcgarry
1.8
86                 break;
87
ragge
1.1
88         case NAME:
89                 if ((q = p->n_sp) == NULL)
90                         return p/* Nothing to care about */
91
92                 switch (q->sclass) {
93
94                 case PARAM:
95                 case AUTO:
96                         /* fake up a structure reference */
97                         r = block(REGNILNILPTR+STRTY00);
98                         r->n_lval = 0;
gmcgarry
1.3
99                         r->n_rval = FP;
ragge
1.1
100                         p = stref(block(STREFrp000));
101                         break;
102
103                 case STATIC:
104                         if (q->slevel == 0)
105                                 break;
106                         p->n_lval = 0;
107                         p->n_sp = q;
108                         break;
109
110                 case REGISTER:
111                         p->n_op = REG;
112                         p->n_lval = 0;
113                         p->n_rval = q->soffset;
114                         break;
115
gmcgarry
1.7
116                 }
ragge
1.1
117                 break;
118
119         case FUNARG:
120                 /* Args smaller than int are given as int */
121                 if (p->n_type != CHAR && p->n_type != UCHAR && 
122                     p->n_type != SHORT && p->n_type != USHORT)
123                         break;
ragge
1.25
124                 p->n_left = block(SCONVp->n_leftNILINT00);
ragge
1.1
125                 p->n_type = INT;
ragge
1.25
126                 p->n_ap = 0;
ragge
1.1
127                 p->n_rval = SZINT;
128                 break;
129
130         case CBRANCH:
131                 l = p->n_left;
132
133                 /*
ragge
1.16
134                  * Remove unnecessary conversion ops.
ragge
1.1
135                  */
136                 if (clogop(l->n_op) && l->n_left->n_op == SCONV) {
137                         if (coptype(l->n_op) != BITYPE)
138                                 break;
139                         if (l->n_right->n_op == ICON) {
140                                 r = l->n_left->n_left;
141                                 if (r->n_type >= FLOAT && r->n_type <= LDOUBLE)
142                                         break;
143                                 /* Type must be correct */
gmcgarry
1.6
144                                 ty = r->n_type;
ragge
1.1
145                                 nfree(l->n_left);
146                                 l->n_left = r;
gmcgarry
1.6
147                                 l->n_type = ty;
148                                 l->n_right->n_type = ty;
ragge
1.1
149                         }
150 #if 0
151                           else if (l->n_right->n_op == SCONV &&
152                             l->n_left->n_type == l->n_right->n_type) {
153                                 r = l->n_left->n_left;
154                                 nfree(l->n_left);
155                                 l->n_left = r;
156                                 r = l->n_right->n_left;
157                                 nfree(l->n_right);
158                                 l->n_right = r;
159                         }
160 #endif
161                 }
162                 break;
163
164         case PCONV:
gmcgarry
1.7
165                 /* Remove redundant PCONV's. Be careful */
ragge
1.1
166                 l = p->n_left;
gmcgarry
1.7
167                 if (l->n_op == ICON) {
168                         l->n_lval = (unsigned)l->n_lval;
169                         goto delp;
170                 }
gmcgarry
1.8
171                 if (l->n_type < INT || DEUNSIGN(l->n_type) == LONGLONG) {
gmcgarry
1.7
172                         /* float etc? */
ragge
1.25
173                         p->n_left = block(SCONVlNILUNSIGNED00);
gmcgarry
1.7
174                         break;
175                 }
176                 /* if left is SCONV, cannot remove */
177                 if (l->n_op == SCONV)
178                         break;
179
180                 /* avoid ADDROF TEMP */
181                 if (l->n_op == ADDROF && l->n_left->n_op == TEMP)
ragge
1.1
182                         break;
gmcgarry
1.7
183
184                 /* if conversion to another pointer type, just remove */
185                 if (p->n_type > BTMASK && l->n_type > BTMASK)
186                         goto delp;
187                 break;
188
189         delp:   l->n_type = p->n_type;
ragge
1.1
190                 l->n_qual = p->n_qual;
191                 l->n_df = p->n_df;
ragge
1.22
192                 l->n_ap = p->n_ap;
ragge
1.1
193                 nfree(p);
194                 p = l;
195                 break;
196
197         case SCONV:
198                 l = p->n_left;
199
200                 if (p->n_type == l->n_type) {
201                         nfree(p);
gmcgarry
1.8
202                         p = l;
203                         break;
ragge
1.1
204                 }
205
206                 if ((p->n_type & TMASK) == 0 && (l->n_type & TMASK) == 0 &&
ragge
1.22
207                     btattr[p->n_type].atypsz == btattr[l->n_type].atypsz) {
ragge
1.1
208                         if (p->n_type != FLOAT && p->n_type != DOUBLE &&
209                             l->n_type != FLOAT && l->n_type != DOUBLE &&
210                             l->n_type != LDOUBLE && p->n_type != LDOUBLE) {
gmcgarry
1.8
211                                 if (l->n_op == NAME || l->n_op == UMUL ||
212                                     l->n_op == TEMP) {
ragge
1.1
213                                         l->n_type = p->n_type;
214                                         nfree(p);
gmcgarry
1.8
215                                         p = l;
216                                         break;
ragge
1.1
217                                 }
218                         }
219                 }
220
gmcgarry
1.8
221                 if (DEUNSIGN(p->n_type) == INT && DEUNSIGN(l->n_type) == INT &&
222                     coptype(l->n_op) == BITYPE) {
223                         l->n_type = p->n_type;
224                         nfree(p);
225                         p = l;
226                 }
227
228                 if (DEUNSIGN(p->n_type) == SHORT &&
229                     DEUNSIGN(l->n_type) == SHORT) {
ragge
1.1
230                         nfree(p);
gmcgarry
1.8
231                         p = l;
ragge
1.1
232                 }
233
gmcgarry
1.9
234                 /* convert float/double to int before to (u)char/(u)short */
gmcgarry
1.8
235                 if ((DEUNSIGN(p->n_type) == CHAR ||
236                     DEUNSIGN(p->n_type) == SHORT) &&
237                     (l->n_type == FLOAT || l->n_type == DOUBLE ||
238                     l->n_type == LDOUBLE)) {
ragge
1.22
239                         p = block(SCONVpNILp->n_typep->n_dfp->n_ap);
gmcgarry
1.8
240                         p->n_left->n_type = INT;
241                         break;
242                 }
243
gmcgarry
1.9
244                 /* convert (u)char/(u)short to int before float/double */
245                 if  ((p->n_type == FLOAT || p->n_type == DOUBLE ||
246                     p->n_type == LDOUBLE) && (DEUNSIGN(l->n_type) == CHAR ||
247                     DEUNSIGN(l->n_type) == SHORT)) {
ragge
1.22
248                         p = block(SCONVpNILp->n_typep->n_dfp->n_ap);
gmcgarry
1.9
249                         p->n_left->n_type = INT;
250                         break;
251                 }
gmcgarry
1.8
252
ragge
1.1
253                 o = l->n_op;
254                 m = p->n_type;
255
256                 if (o == ICON) {
257                         CONSZ val = l->n_lval;
258
259                         if (!ISPTR(m)) /* Pointers don't need to be conv'd */
260                             switch (m) {
gmcgarry
1.10
261                         case BOOL:
262                                 l->n_lval = l->n_lval != 0;
263                                 break;
ragge
1.1
264                         case CHAR:
265                                 l->n_lval = (char)val;
266                                 break;
267                         case UCHAR:
268                                 l->n_lval = val & 0377;
269                                 break;
270                         case SHORT:
271                                 l->n_lval = (short)val;
272                                 break;
273                         case USHORT:
274                                 l->n_lval = val & 0177777;
275                                 break;
276                         case ULONG:
277                         case UNSIGNED:
278                                 l->n_lval = val & 0xffffffff;
279                                 break;
280                         case LONG:
281                         case INT:
282                                 l->n_lval = (int)val;
283                                 break;
284                         case LONGLONG:
285                                 l->n_lval = (long long)val;
286                                 break;
287                         case ULONGLONG:
288                                 l->n_lval = val;
289                                 break;
290                         case VOID:
291                                 break;
292                         case LDOUBLE:
293                         case DOUBLE:
294                         case FLOAT:
295                                 l->n_op = FCON;
296                                 l->n_dcon = val;
297                                 break;
298                         default:
299                                 cerror("unknown type %d"m);
300                         }
301                         l->n_type = m;
302                         nfree(p);
303                         p = l;
gmcgarry
1.15
304                 } else if (o == FCON) {
305                         l->n_lval = l->n_dcon;
306                         l->n_sp = NULL;
307                         l->n_op = ICON;
308                         l->n_type = m;
ragge
1.25
309                         l->n_ap = 0;
gmcgarry
1.15
310                         nfree(p);
311                         p = clocal(l);
ragge
1.1
312                 }
313                 break;
314
315         case MOD:
316         case DIV:
317                 if (o == DIV && p->n_type != CHAR && p->n_type != SHORT)
318                         break;
319                 if (o == MOD && p->n_type != CHAR && p->n_type != SHORT)
320                         break;
321                 /* make it an int division by inserting conversions */
ragge
1.25
322                 p->n_left = block(SCONVp->n_leftNILINT00);
323                 p->n_right = block(SCONVp->n_rightNILINT00);
324                 p = block(SCONVpNILp->n_type00);
ragge
1.1
325                 p->n_left->n_type = INT;
326                 break;
327
328         case FORCE:
329                 /* put return value in return reg */
330                 p->n_op = ASSIGN;
331                 p->n_right = p->n_left;
ragge
1.25
332                 p->n_left = block(REGNILNILp->n_type00);
gmcgarry
1.3
333                 p->n_left->n_rval = RETREG(p->n_type);
ragge
1.1
334                 break;
335         }
gmcgarry
1.3
336
gmcgarry
1.8
337 #ifdef PCC_DEBUG
338         if (xdebug) {
339                 printf("clocal out: %p\n"p);
340                 fwalk(peprint0);
341         }
342 #endif
ragge
1.1
343
344         return(p);
345 }
346
347 void
348 myp2tree(NODE *p)
349 {
ragge
1.14
350         struct symtab *sp;
ragge
1.11
351
ragge
1.14
352         if (p->n_op != FCON
ragge
1.11
353                 return;
354
355         /* Write float constants to memory */
356  
gmcgarry
1.15
357         sp = IALLOC(sizeof(struct symtab));
ragge
1.14
358         sp->sclass = STATIC;
ragge
1.25
359         sp->sap = 0;
ragge
1.14
360         sp->slevel = 1/* fake numeric label */
361         sp->soffset = getlab();
362         sp->sflags = 0;
363         sp->stype = p->n_type;
364         sp->squal = (CON >> TSHIFT);
365
366         defloc(sp);
ragge
1.22
367         ninval(0sp->sap->atypszp);
ragge
1.14
368
ragge
1.11
369         p->n_op = NAME;
ragge
1.14
370         p->n_lval = 0;
371         p->n_sp = sp;
ragge
1.11
372
ragge
1.1
373 }
374
375 /*ARGSUSED*/
376 int
377 andable(NODE *p)
378 {
379         return(1);  /* all names can have & taken on them */
380 }
381
382 /*
383  * is an automatic variable of type t OK for a register variable
384  */
385 int
386 cisreg(TWORD t)
387 {
388         if (t == INT || t == UNSIGNED || t == LONG || t == ULONG)
389                 return(1);
390         return 0/* XXX - fix reg assignment in pftn.c */
391 }
392
393 /*
394  * Allocate off bits on the stack.  p is a tree that when evaluated
395  * is the multiply count for off, t is a NAME node where to write
396  * the allocated address.
397  */
398 void
399 spalloc(NODE *tNODE *pOFFSZ off)
400 {
401         NODE *sp;
gmcgarry
1.10
402         int nbytes = off / SZCHAR;
ragge
1.1
403
gmcgarry
1.10
404         p = buildtree(MULpbcon(nbytes));
405         p = buildtree(PLUSpbcon(7));
406         p = buildtree(ANDpbcon(~7));
407
408         /* subtract the size from sp */
409         sp = block(REGNILNILp->n_type00);
410         sp->n_lval = 0;
411         sp->n_rval = SP;
412         ecomp(buildtree(MINUSEQspp));
ragge
1.1
413
414         /* save the address of sp */
ragge
1.22
415         sp = block(REGNILNILPTR+INTt->n_dft->n_ap);
gmcgarry
1.6
416         sp->n_rval = SP;
ragge
1.1
417         t->n_type = sp->n_type;
418         ecomp(buildtree(ASSIGNtsp)); /* Emit! */
419 }
420
421 /*
422  * print out a constant node
423  * mat be associated with a label
424  */
425 void
gmcgarry
1.2
426 ninval(CONSZ offint fszNODE *p)
ragge
1.1
427 {
gmcgarry
1.10
428         union { float fdouble dint i[2]; } u;
gmcgarry
1.3
429         struct symtab *q;
430         TWORD t;
431 #ifndef USE_GAS
gmcgarry
1.5
432         int ij;
gmcgarry
1.3
433 #endif
ragge
1.1
434
gmcgarry
1.3
435         t = p->n_type;
436         if (t > BTMASK)
437                 t = INT/* pointer */
438
439         if (p->n_op != ICON && p->n_op != FCON)
440                 cerror("ninval: init node not constant");
441
442         if (p->n_op == ICON && p->n_sp != NULL && DEUNSIGN(t) != INT)
443                 uerror("element not constant");
444
445         switch (t) {
446         case LONGLONG:
447         case ULONGLONG:
448 #ifdef USE_GAS
gmcgarry
1.10
449                 printf("\t.dword %lld\n", (long long)p->n_lval);
gmcgarry
1.3
450 #else
gmcgarry
1.5
451                 i = p->n_lval >> 32;
452                 j = p->n_lval & 0xffffffff;
gmcgarry
1.3
453                 p->n_type = INT;
gmcgarry
1.5
454                 if (bigendian) {
455                         p->n_lval = j;
456                         ninval(off32p);
457                         p->n_lval = i;
458                         ninval(off+3232p);
459                 } else {
460                         p->n_lval = i;
461                         ninval(off32p);
462                         p->n_lval = j;
463                         ninval(off+3232p);
464                 }
gmcgarry
1.3
465 #endif
466                 break;
467         case BOOL:
468                 if (p->n_lval > 1)
469                         p->n_lval = p->n_lval != 0;
470                 /* FALLTHROUGH */
471         case INT:
472         case UNSIGNED:
gmcgarry
1.10
473                 printf("\t.word " CONFMT, (CONSZ)p->n_lval);
gmcgarry
1.3
474                 if ((q = p->n_sp) != NULL) {
ragge
1.18
475                         if ((q->sclass == STATIC && q->slevel > 0)) {
gmcgarry
1.3
476                                 printf("+" LABFMTq->soffset);
477                         } else
ragge
1.19
478                                 printf("+%s",
479                                     q->soname ? q->soname : exname(q->sname));
gmcgarry
1.3
480                 }
481                 printf("\n");
482                 break;
483         case SHORT:
484         case USHORT:
gmcgarry
1.10
485                 printf("\t.half %d\n", (int)p->n_lval & 0xffff);
gmcgarry
1.3
486                 break;
487         case CHAR:
488         case UCHAR:
489                 printf("\t.byte %d\n", (int)p->n_lval & 0xff);
490                 break;
491         case LDOUBLE:
492         case DOUBLE:
493                 u.d = (double)p->n_dcon;
gmcgarry
1.9
494                 if (bigendian) {
gmcgarry
1.10
495                         printf("\t.word\t%d\n"u.i[0]);
496                         printf("\t.word\t%d\n"u.i[1]);
gmcgarry
1.9
497                 } else {
gmcgarry
1.10
498                         printf("\t.word\t%d\n"u.i[1]);
499                         printf("\t.word\t%d\n"u.i[0]);
gmcgarry
1.9
500                 }
gmcgarry
1.3
501                 break;
502         case FLOAT:
503                 u.f = (float)p->n_dcon;
504                 printf("\t.word\t0x%x\n"u.i[0]);
505                 break;
506         default:
507                 cerror("ninval");
508         }
ragge
1.1
509 }
510
511 /* make a name look like an external name in the local machine */
512 char *
513 exname(char *p)
514 {
515         if (p == NULL)
516                 return "";
517         return p;
518 }
519
520 /*
521  * map types which are not defined on the local machine
522  */
523 TWORD
524 ctype(TWORD type)
525 {
526         switch (BTYPE(type)) {
527         case LONG:
528                 MODTYPE(type,INT);
529                 break;
530
531         case ULONG:
532                 MODTYPE(type,UNSIGNED);
533
534         }
535         return (type);
536 }
537
538 /* curid is a variable which is defined but
539  * is not initialized (and not a function );
540  * This routine returns the storage class for an uninitialized declaration
541  */
542 int
ragge
1.22
543 noinit(void)
ragge
1.1
544 {
545         return(EXTERN);
546 }
547
548 void
549 calldec(NODE *pNODE *q
550 {
551 }
552
553 void
554 extdec(struct symtab *q)
555 {
556 }
557
ragge
1.14
558 /*
559  * Print out a string of characters.
560  * Assume that the assembler understands C-style escape
561  * sequences.
562  */
563 void
564 instring(struct symtab *sp)
565 {
566         char *s, *str;
567
568         defloc(sp);
569         str = sp->sname;
570
571         /* be kind to assemblers and avoid long strings */
572         printf("\t.ascii \"");
573         for (s = str; *s != 0; ) {
574                 if (*s++ == '\\') {
575                         (void)esccon(&s);
576                 }
577                 if (s - str > 60) {
578                         fwrite(str1s - strstdout);
579                         printf("\"\n\t.ascii \"");
580                         str = s;
581                 }
582         }
583         fwrite(str1s - strstdout);
584         printf("\\0\"\n");
585 }
586
587 /* make a common declaration for id, if reasonable */
588 void
589 defzero(struct symtab *sp)
590 {
591         int off;
592
ragge
1.22
593         off = tsize(sp->stypesp->sdfsp->sap);
ragge
1.14
594         off = (off+(SZCHAR-1))/SZCHAR;
595         printf("        .%scomm "sp->sclass == STATIC ? "l" : "");
596         if (sp->slevel == 0)
ragge
1.19
597                 printf("%s,0%o\n"sp->soname ? sp->soname : exname(sp->sname), off);
ragge
1.14
598         else
599                 printf(LABFMT ",0%o\n"sp->soffsetoff);
600 }
601
602
603 #ifdef notdef
ragge
1.1
604 /* make a common declaration for id, if reasonable */
605 void
606 commdec(struct symtab *q)
607 {
608         int off;
609
610         off = tsize(q->stypeq->sdfq->ssue);
611         off = (off+(SZCHAR-1))/SZCHAR;
612
ragge
1.13
613         printf("        .comm %s,%d\n"exname(q->soname), off);
ragge
1.1
614 }
615
616 /* make a local common declaration for id, if reasonable */
617 void
618 lcommdec(struct symtab *q)
619 {
620         int off;
621
622         off = tsize(q->stypeq->sdfq->ssue);
623         off = (off+(SZCHAR-1))/SZCHAR;
624         if (q->slevel == 0)
ragge
1.13
625                 printf("\t.lcomm %s,%d\n"exname(q->soname), off);
ragge
1.1
626         else
gmcgarry
1.9
627                 printf("\t.lcomm " LABFMT ",%d\n"q->soffsetoff);
ragge
1.1
628 }
629
630 /*
631  * print a (non-prog) label.
632  */
633 void
634 deflab1(int label)
635 {
636         printf(LABFMT ":\n"label);
637 }
638
gmcgarry
1.9
639 /* ro-text, rw-data, ro-data, ro-strings */
640 static char *loctbl[] = { "text""data""rdata""rdata" };
ragge
1.1
641
642 void
643 setloc1(int locc)
644 {
gmcgarry
1.10
645         if (locc == lastloc && locc != STRNG)
ragge
1.1
646                 return;
gmcgarry
1.15
647         if (locc == RDATA && lastloc == STRNG)
gmcgarry
1.10
648                 return;
649
650         if (locc != lastloc) {
651                 lastloc = locc;
652                 printf("\t.%s\n"loctbl[locc]);
653         }
654
655         if (locc == STRNG)
656                 printf("\t.align 2\n");
ragge
1.1
657 }
ragge
1.14
658 #endif
gmcgarry
1.2
659
660 /*
661  * Initialize a bitfield.
662  */
663 void
664 infld(CONSZ offint fszCONSZ val)
665 {
666         if (idebug)
667                 printf("infld off %lld, fsz %d, val %lld inbits %d\n",
668                     offfszvalinbits);
669         val &= (1 << fsz)-1;
670         while (fsz + inbits >= SZCHAR) {
671                 inval |= (val << inbits);
672                 printf("\t.byte %d\n"inval & 255);
673                 fsz -= (SZCHAR - inbits);
674                 val >>= (SZCHAR - inbits);
675                 inval = inbits = 0;
676         }
677         if (fsz) {
678                 inval |= (val << inbits);
679                 inbits += fsz;
680         }
681 }
682
683 /*
684  * set fsz bits in sequence to zero.
685  */
686 void
687 zbits(OFFSZ offint fsz)
688 {
689         int m;
690
691         if (idebug)
692                 printf("zbits off %lld, fsz %d inbits %d\n"offfszinbits);
693         if ((m = (inbits % SZCHAR))) {
694                 m = SZCHAR - m;
695                 if (fsz < m) {
696                         inbits += fsz;
697                         return;
698                 } else {
699                         fsz -= m;
700                         printf("\t.byte %d\n"inval);
701                         inval = inbits = 0;
702                 }
703         }
704         if (fsz >= SZCHAR) {
705                 printf("\t.zero %d\n"fsz/SZCHAR);
706                 fsz -= (fsz/SZCHAR) * SZCHAR;
707         }
708         if (fsz) {
709                 inval = 0;
710                 inbits = fsz;
711         }
712 }
gmcgarry
1.6
713
714 /*
715  * va_start(ap, last) implementation.
716  *
717  * f is the NAME node for this builtin function.
718  * a is the argument list containing:
719  *         CM
720  *      ap   last
gmcgarry
1.7
721  *
722  * It turns out that this is easy on MIPS.  Just write the
723  * argument registers to the stack in va_arg_start() and
724  * use the traditional method of walking the stackframe.
gmcgarry
1.6
725  */
726 NODE *
ragge
1.23
727 mips_builtin_stdarg_start(NODE *fNODE *aTWORD t)
gmcgarry
1.6
728 {
gmcgarry
1.7
729         NODE *p, *q;
gmcgarry
1.6
730         int sz = 1;
731
732         /* check num args and type */
733         if (a == NULL || a->n_op != CM || a->n_left->n_op == CM ||
734             !ISPTR(a->n_left->n_type))
735                 goto bad;
736
737         /* must first deal with argument size; use int size */
738         p = a->n_right;
gmcgarry
1.7
739         if (p->n_type < INT) {
740                 /* round up to word */
ragge
1.22
741                 sz = SZINT / tsize(p->n_typep->n_dfp->n_ap);
gmcgarry
1.7
742         }
743
744         p = buildtree(ADDROFpNIL);  /* address of last arg */
745         p = optim(buildtree(PLUSpbcon(sz)));
746         q = block(NAMENILNILPTR+VOID00);
747         q = buildtree(CASTqp);
748         p = q->n_right;
749         nfree(q->n_left);
750         nfree(q);
751         p = buildtree(ASSIGNa->n_leftp);
752         tfree(f);
753         nfree(a);
754
755         return p;
756
gmcgarry
1.6
757 bad:
gmcgarry
1.7
758         uerror("bad argument to __builtin_stdarg_start");
759         return bcon(0);
gmcgarry
1.6
760 }
761
762 NODE *
ragge
1.23
763 mips_builtin_va_arg(NODE *fNODE *aTWORD t)
gmcgarry
1.6
764 {
gmcgarry
1.7
765         NODE *p, *q, *r;
766         int sztmpnr;
767
768         /* check num args and type */
769         if (a == NULL || a->n_op != CM || a->n_left->n_op == CM ||
770             !ISPTR(a->n_left->n_type) || a->n_right->n_op != TYPE)
771                 goto bad;
772
gmcgarry
1.15
773         r = a->n_right;
gmcgarry
1.7
774
gmcgarry
1.15
775         /* get type size */
ragge
1.22
776         sz = tsize(r->n_typer->n_dfr->n_ap) / SZCHAR;
gmcgarry
1.9
777         if (sz < SZINT/SZCHAR) {
778                 werror("%s%s promoted to int when passed through ...",
779                         r->n_type & 1 ? "unsigned " : "",
780                         DEUNSIGN(r->n_type) == SHORT ? "short" : "char");
781                 sz = SZINT/SZCHAR;
782         }
gmcgarry
1.15
783
784         /* alignment */
785         p = tcopy(a->n_left);
786         if (sz > SZINT/SZCHAR && r->n_type != UNIONTY && r->n_type != STRTY) {
787                 p = buildtree(PLUSpbcon(7));
ragge
1.22
788                 p = block(ANDpbcon(-8), p->n_typep->n_dfp->n_ap);
gmcgarry
1.15
789         }
790
791         /* create a copy to a temp node */
ragge
1.22
792         q = tempnode(0p->n_typep->n_dfp->n_ap);
gmcgarry
1.15
793         tmpnr = regno(q);
794         p = buildtree(ASSIGNqp);
795
ragge
1.22
796         q = tempnode(tmpnrp->n_typep->n_df,p->n_ap);
gmcgarry
1.15
797         q = buildtree(PLUSqbcon(sz));
798         q = buildtree(ASSIGNa->n_leftq);
799
gmcgarry
1.7
800         q = buildtree(COMOPpq);
801
802         nfree(a->n_right);
803         nfree(a);
804         nfree(f); 
805
ragge
1.22
806         p = tempnode(tmpnrINCREF(r->n_type), r->n_dfr->n_ap);
gmcgarry
1.7
807         p = buildtree(UMULpNIL);
808         p = buildtree(COMOPqp);
809
810         return p;
811
812 bad:
813         uerror("bad argument to __builtin_va_arg");
814         return bcon(0);
gmcgarry
1.6
815 }
816
817 NODE *
ragge
1.23
818 mips_builtin_va_end(NODE *fNODE *aTWORD t)
gmcgarry
1.6
819 {
gmcgarry
1.7
820         tfree(f);
821         tfree(a);
822         return bcon(0);
gmcgarry
1.6
823 }
824
825 NODE *
ragge
1.23
826 mips_builtin_va_copy(NODE *fNODE *aTWORD t)
gmcgarry
1.6
827 {
gmcgarry
1.7
828         if (a == NULL || a->n_op != CM || a->n_left->n_op == CM)
829                 goto bad;
830         tfree(f);
831         f = buildtree(ASSIGNa->n_lefta->n_right);
832         nfree(a);
gmcgarry
1.6
833         return f;
gmcgarry
1.7
834
835 bad:
836         uerror("bad argument to __buildtin_va_copy");
837         return bcon(0);
gmcgarry
1.6
838 }
gmcgarry
1.15
839
gmcgarry
1.17
840 static int constructor;
841 static int destructor;
842
ragge
1.13
843 /*
844  * Give target the opportunity of handling pragmas.
845  */
846 int
ragge
1.24
847 mypragma(char *str)
ragge
1.13
848 {
ragge
1.24
849
850         if (strcmp(str"tls") == 0) { 
gmcgarry
1.17
851                 uerror("thread-local storage not supported for this target");
852                 return 1;
853         } 
ragge
1.24
854         if (strcmp(str"constructor") == 0 || strcmp(str"init") == 0) {
gmcgarry
1.17
855                 constructor = 1;
856                 return 1;
857         }
ragge
1.24
858         if (strcmp(str"destructor") == 0 || strcmp(str"fini") == 0) {
gmcgarry
1.17
859                 destructor = 1;
860                 return 1;
861         }
862
gmcgarry
1.15
863         return 0;
864 }
ragge
1.13
865
866 /*
867  * Called when a identifier has been declared, to give target last word.
868  */
869 void
870 fixdef(struct symtab *sp)
871 {
gmcgarry
1.17
872         if ((constructor || destructor) && (sp->sclass != PARAM)) {
873                 printf("\t.section .%ctors,\"aw\",@progbits\n",
874                     constructor ? 'c' : 'd');
875                 printf("\t.p2align 2\n");
876                 printf("\t.long %s\n"exname(sp->sname));
gmcgarry
1.21
877                 printf("\t.previous\n");
gmcgarry
1.17
878                 constructor = destructor = 0;
879         }
880 }
881
882 void
883 pass1_lastchance(struct interpass *ip)
884 {
ragge
1.13
885 }
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-01 13:14 +0200