Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20121201085340

Diff

Diff from 1.33 to:

Annotations

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

Annotated File View

ragge
1.33
1 /*      $Id: local.c,v 1.33 2012/12/01 08:53:40 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.3
37 /* this is called to do local transformations on
38  * an expression tree preparitory to its being
39  * written out in intermediate code.
40  */
ragge
1.1
41 NODE *
42 clocal(NODE *p)
43 {
gmcgarry
1.3
44         struct symtab *q;
45         NODE *r, *l;
46         int o;
gmcgarry
1.7
47         int m;
gmcgarry
1.6
48         TWORD ty;
gmcgarry
1.8
49         int tmpnrisptrvoid = 0;
ragge
1.1
50
gmcgarry
1.7
51 #ifdef PCC_DEBUG
52         if (xdebug) {
gmcgarry
1.8
53                 printf("clocal in: %p\n"p);
gmcgarry
1.7
54                 fwalk(peprint0);
55         }
56 #endif
gmcgarry
1.3
57
gmcgarry
1.6
58         switch (o = p->n_op) {
ragge
1.1
59
gmcgarry
1.8
60         case UCALL:
61         case CALL:
62         case STCALL:
63         case USTCALL:
64                 if (p->n_type == VOID)
65                         break;
66                 /*
67                  * if the function returns void*, ecode() invokes
68                  * delvoid() to convert it to uchar*.
69                  * We just let this happen on the ASSIGN to the temp,
70                  * and cast the pointer back to void* on access
71                  * from the temp.
72                  */
73                 if (p->n_type == PTR+VOID)
74                         isptrvoid = 1;
ragge
1.22
75                 r = tempnode(0p->n_typep->n_dfp->n_ap);
ragge
1.12
76                 tmpnr = regno(r);
ragge
1.22
77                 r = block(ASSIGNrpp->n_typep->n_dfp->n_ap);
gmcgarry
1.9
78
ragge
1.22
79                 p = tempnode(tmpnrr->n_typer->n_dfr->n_ap);
gmcgarry
1.8
80                 if (isptrvoid) {
ragge
1.25
81                         p = block(PCONVpNILPTR+VOIDp->n_df0);
gmcgarry
1.8
82                 }
gmcgarry
1.9
83                 p = buildtree(COMOPrp);
gmcgarry
1.8
84                 break;
85
ragge
1.1
86         case NAME:
87                 if ((q = p->n_sp) == NULL)
88                         return p/* Nothing to care about */
89
90                 switch (q->sclass) {
91
92                 case PARAM:
93                 case AUTO:
94                         /* fake up a structure reference */
95                         r = block(REGNILNILPTR+STRTY00);
96                         r->n_lval = 0;
gmcgarry
1.3
97                         r->n_rval = FP;
ragge
1.1
98                         p = stref(block(STREFrp000));
99                         break;
100
101                 case STATIC:
102                         if (q->slevel == 0)
103                                 break;
104                         p->n_lval = 0;
105                         p->n_sp = q;
106                         break;
107
108                 case REGISTER:
109                         p->n_op = REG;
110                         p->n_lval = 0;
111                         p->n_rval = q->soffset;
112                         break;
113
gmcgarry
1.7
114                 }
ragge
1.1
115                 break;
116
117         case FUNARG:
118                 /* Args smaller than int are given as int */
119                 if (p->n_type != CHAR && p->n_type != UCHAR && 
120                     p->n_type != SHORT && p->n_type != USHORT)
121                         break;
ragge
1.25
122                 p->n_left = block(SCONVp->n_leftNILINT00);
ragge
1.1
123                 p->n_type = INT;
ragge
1.25
124                 p->n_ap = 0;
ragge
1.1
125                 p->n_rval = SZINT;
126                 break;
127
128         case CBRANCH:
129                 l = p->n_left;
130
131                 /*
ragge
1.16
132                  * Remove unnecessary conversion ops.
ragge
1.1
133                  */
134                 if (clogop(l->n_op) && l->n_left->n_op == SCONV) {
135                         if (coptype(l->n_op) != BITYPE)
136                                 break;
137                         if (l->n_right->n_op == ICON) {
138                                 r = l->n_left->n_left;
139                                 if (r->n_type >= FLOAT && r->n_type <= LDOUBLE)
140                                         break;
141                                 /* Type must be correct */
gmcgarry
1.6
142                                 ty = r->n_type;
ragge
1.1
143                                 nfree(l->n_left);
144                                 l->n_left = r;
gmcgarry
1.6
145                                 l->n_type = ty;
146                                 l->n_right->n_type = ty;
ragge
1.1
147                         }
148 #if 0
149                           else if (l->n_right->n_op == SCONV &&
150                             l->n_left->n_type == l->n_right->n_type) {
151                                 r = l->n_left->n_left;
152                                 nfree(l->n_left);
153                                 l->n_left = r;
154                                 r = l->n_right->n_left;
155                                 nfree(l->n_right);
156                                 l->n_right = r;
157                         }
158 #endif
159                 }
160                 break;
161
162         case PCONV:
gmcgarry
1.7
163                 /* Remove redundant PCONV's. Be careful */
ragge
1.1
164                 l = p->n_left;
gmcgarry
1.7
165                 if (l->n_op == ICON) {
166                         l->n_lval = (unsigned)l->n_lval;
167                         goto delp;
168                 }
gmcgarry
1.8
169                 if (l->n_type < INT || DEUNSIGN(l->n_type) == LONGLONG) {
gmcgarry
1.7
170                         /* float etc? */
ragge
1.25
171                         p->n_left = block(SCONVlNILUNSIGNED00);
gmcgarry
1.7
172                         break;
173                 }
174                 /* if left is SCONV, cannot remove */
175                 if (l->n_op == SCONV)
176                         break;
177
178                 /* avoid ADDROF TEMP */
179                 if (l->n_op == ADDROF && l->n_left->n_op == TEMP)
ragge
1.1
180                         break;
gmcgarry
1.7
181
182                 /* if conversion to another pointer type, just remove */
183                 if (p->n_type > BTMASK && l->n_type > BTMASK)
184                         goto delp;
185                 break;
186
187         delp:   l->n_type = p->n_type;
ragge
1.1
188                 l->n_qual = p->n_qual;
189                 l->n_df = p->n_df;
ragge
1.22
190                 l->n_ap = p->n_ap;
ragge
1.1
191                 nfree(p);
192                 p = l;
193                 break;
194
195         case SCONV:
196                 l = p->n_left;
197
198                 if (p->n_type == l->n_type) {
199                         nfree(p);
gmcgarry
1.8
200                         p = l;
201                         break;
ragge
1.1
202                 }
203
204                 if ((p->n_type & TMASK) == 0 && (l->n_type & TMASK) == 0 &&
ragge
1.31
205                     tsize(p->n_typep->n_dfp->n_ap) ==
206                     tsize(l->n_typel->n_dfl->n_ap)) {
ragge
1.1
207                         if (p->n_type != FLOAT && p->n_type != DOUBLE &&
208                             l->n_type != FLOAT && l->n_type != DOUBLE &&
209                             l->n_type != LDOUBLE && p->n_type != LDOUBLE) {
gmcgarry
1.8
210                                 if (l->n_op == NAME || l->n_op == UMUL ||
211                                     l->n_op == TEMP) {
ragge
1.1
212                                         l->n_type = p->n_type;
213                                         nfree(p);
gmcgarry
1.8
214                                         p = l;
215                                         break;
ragge
1.1
216                                 }
217                         }
218                 }
219
gmcgarry
1.8
220                 if (DEUNSIGN(p->n_type) == INT && DEUNSIGN(l->n_type) == INT &&
221                     coptype(l->n_op) == BITYPE) {
222                         l->n_type = p->n_type;
223                         nfree(p);
224                         p = l;
225                 }
226
227                 if (DEUNSIGN(p->n_type) == SHORT &&
228                     DEUNSIGN(l->n_type) == SHORT) {
ragge
1.1
229                         nfree(p);
gmcgarry
1.8
230                         p = l;
ragge
1.1
231                 }
232
gmcgarry
1.9
233                 /* convert float/double to int before to (u)char/(u)short */
gmcgarry
1.8
234                 if ((DEUNSIGN(p->n_type) == CHAR ||
235                     DEUNSIGN(p->n_type) == SHORT) &&
236                     (l->n_type == FLOAT || l->n_type == DOUBLE ||
237                     l->n_type == LDOUBLE)) {
ragge
1.22
238                         p = block(SCONVpNILp->n_typep->n_dfp->n_ap);
gmcgarry
1.8
239                         p->n_left->n_type = INT;
240                         break;
241                 }
242
gmcgarry
1.9
243                 /* convert (u)char/(u)short to int before float/double */
244                 if  ((p->n_type == FLOAT || p->n_type == DOUBLE ||
245                     p->n_type == LDOUBLE) && (DEUNSIGN(l->n_type) == CHAR ||
246                     DEUNSIGN(l->n_type) == SHORT)) {
ragge
1.22
247                         p = block(SCONVpNILp->n_typep->n_dfp->n_ap);
gmcgarry
1.9
248                         p->n_left->n_type = INT;
249                         break;
250                 }
gmcgarry
1.8
251
ragge
1.1
252                 o = l->n_op;
253                 m = p->n_type;
254
255                 if (o == ICON) {
256                         CONSZ val = l->n_lval;
257
258                         if (!ISPTR(m)) /* Pointers don't need to be conv'd */
259                             switch (m) {
gmcgarry
1.10
260                         case BOOL:
261                                 l->n_lval = l->n_lval != 0;
262                                 break;
ragge
1.1
263                         case CHAR:
264                                 l->n_lval = (char)val;
265                                 break;
266                         case UCHAR:
267                                 l->n_lval = val & 0377;
268                                 break;
269                         case SHORT:
270                                 l->n_lval = (short)val;
271                                 break;
272                         case USHORT:
273                                 l->n_lval = val & 0177777;
274                                 break;
275                         case ULONG:
276                         case UNSIGNED:
277                                 l->n_lval = val & 0xffffffff;
278                                 break;
279                         case LONG:
280                         case INT:
281                                 l->n_lval = (int)val;
282                                 break;
283                         case LONGLONG:
284                                 l->n_lval = (long long)val;
285                                 break;
286                         case ULONGLONG:
287                                 l->n_lval = val;
288                                 break;
289                         case VOID:
290                                 break;
291                         case LDOUBLE:
292                         case DOUBLE:
293                         case FLOAT:
294                                 l->n_op = FCON;
295                                 l->n_dcon = val;
296                                 break;
297                         default:
298                                 cerror("unknown type %d"m);
299                         }
300                         l->n_type = m;
301                         nfree(p);
302                         p = l;
gmcgarry
1.15
303                 } else if (o == FCON) {
304                         l->n_lval = l->n_dcon;
305                         l->n_sp = NULL;
306                         l->n_op = ICON;
307                         l->n_type = m;
ragge
1.25
308                         l->n_ap = 0;
gmcgarry
1.15
309                         nfree(p);
310                         p = clocal(l);
ragge
1.1
311                 }
312                 break;
313
314         case MOD:
315         case DIV:
316                 if (o == DIV && p->n_type != CHAR && p->n_type != SHORT)
317                         break;
318                 if (o == MOD && p->n_type != CHAR && p->n_type != SHORT)
319                         break;
320                 /* make it an int division by inserting conversions */
ragge
1.25
321                 p->n_left = block(SCONVp->n_leftNILINT00);
322                 p->n_right = block(SCONVp->n_rightNILINT00);
323                 p = block(SCONVpNILp->n_type00);
ragge
1.1
324                 p->n_left->n_type = INT;
325                 break;
326
327         case FORCE:
328                 /* put return value in return reg */
329                 p->n_op = ASSIGN;
330                 p->n_right = p->n_left;
ragge
1.25
331                 p->n_left = block(REGNILNILp->n_type00);
gmcgarry
1.3
332                 p->n_left->n_rval = RETREG(p->n_type);
ragge
1.1
333                 break;
334         }
gmcgarry
1.3
335
gmcgarry
1.8
336 #ifdef PCC_DEBUG
337         if (xdebug) {
338                 printf("clocal out: %p\n"p);
339                 fwalk(peprint0);
340         }
341 #endif
ragge
1.1
342
343         return(p);
344 }
345
346 void
347 myp2tree(NODE *p)
348 {
ragge
1.14
349         struct symtab *sp;
ragge
1.11
350
ragge
1.14
351         if (p->n_op != FCON
ragge
1.11
352                 return;
353
354         /* Write float constants to memory */
355  
gmcgarry
1.15
356         sp = IALLOC(sizeof(struct symtab));
ragge
1.14
357         sp->sclass = STATIC;
ragge
1.25
358         sp->sap = 0;
ragge
1.14
359         sp->slevel = 1/* fake numeric label */
360         sp->soffset = getlab();
361         sp->sflags = 0;
362         sp->stype = p->n_type;
363         sp->squal = (CON >> TSHIFT);
364
365         defloc(sp);
ragge
1.31
366         ninval(0tsize(sp->stypesp->sdfsp->sap), p);
ragge
1.14
367
ragge
1.11
368         p->n_op = NAME;
ragge
1.14
369         p->n_lval = 0;
370         p->n_sp = sp;
ragge
1.11
371
ragge
1.1
372 }
373
374 /*ARGSUSED*/
375 int
376 andable(NODE *p)
377 {
378         return(1);  /* all names can have & taken on them */
379 }
380
381 /*
382  * is an automatic variable of type t OK for a register variable
383  */
384 int
385 cisreg(TWORD t)
386 {
387         if (t == INT || t == UNSIGNED || t == LONG || t == ULONG)
388                 return(1);
389         return 0/* XXX - fix reg assignment in pftn.c */
390 }
391
392 /*
393  * Allocate off bits on the stack.  p is a tree that when evaluated
394  * is the multiply count for off, t is a NAME node where to write
395  * the allocated address.
396  */
397 void
398 spalloc(NODE *tNODE *pOFFSZ off)
399 {
400         NODE *sp;
gmcgarry
1.10
401         int nbytes = off / SZCHAR;
ragge
1.1
402
gmcgarry
1.10
403         p = buildtree(MULpbcon(nbytes));
404         p = buildtree(PLUSpbcon(7));
405         p = buildtree(ANDpbcon(~7));
406
407         /* subtract the size from sp */
408         sp = block(REGNILNILp->n_type00);
409         sp->n_lval = 0;
410         sp->n_rval = SP;
411         ecomp(buildtree(MINUSEQspp));
ragge
1.1
412
413         /* save the address of sp */
ragge
1.22
414         sp = block(REGNILNILPTR+INTt->n_dft->n_ap);
gmcgarry
1.6
415         sp->n_rval = SP;
ragge
1.1
416         t->n_type = sp->n_type;
417         ecomp(buildtree(ASSIGNtsp)); /* Emit! */
418 }
419
420 /*
421  * print out a constant node
422  * mat be associated with a label
423  */
ragge
1.28
424 int
gmcgarry
1.2
425 ninval(CONSZ offint fszNODE *p)
ragge
1.1
426 {
gmcgarry
1.10
427         union { float fdouble dint i[2]; } u;
gmcgarry
1.3
428         struct symtab *q;
429         TWORD t;
430 #ifndef USE_GAS
gmcgarry
1.5
431         int ij;
gmcgarry
1.3
432 #endif
ragge
1.1
433
gmcgarry
1.3
434         t = p->n_type;
435         if (t > BTMASK)
ragge
1.28
436                 p->n_type = t = INT/* pointer */
gmcgarry
1.3
437
438         if (p->n_op == ICON && p->n_sp != NULL && DEUNSIGN(t) != INT)
439                 uerror("element not constant");
440
441         switch (t) {
442         case LONGLONG:
443         case ULONGLONG:
444 #ifdef USE_GAS
gmcgarry
1.10
445                 printf("\t.dword %lld\n", (long long)p->n_lval);
gmcgarry
1.3
446 #else
gmcgarry
1.5
447                 i = p->n_lval >> 32;
448                 j = p->n_lval & 0xffffffff;
gmcgarry
1.3
449                 p->n_type = INT;
gmcgarry
1.5
450                 if (bigendian) {
451                         p->n_lval = j;
452                         ninval(off32p);
453                         p->n_lval = i;
454                         ninval(off+3232p);
455                 } else {
456                         p->n_lval = i;
457                         ninval(off32p);
458                         p->n_lval = j;
459                         ninval(off+3232p);
460                 }
gmcgarry
1.3
461 #endif
462                 break;
463         case INT:
464         case UNSIGNED:
gmcgarry
1.10
465                 printf("\t.word " CONFMT, (CONSZ)p->n_lval);
gmcgarry
1.3
466                 if ((q = p->n_sp) != NULL) {
ragge
1.18
467                         if ((q->sclass == STATIC && q->slevel > 0)) {
gmcgarry
1.3
468                                 printf("+" LABFMTq->soffset);
469                         } else
ragge
1.19
470                                 printf("+%s",
471                                     q->soname ? q->soname : exname(q->sname));
gmcgarry
1.3
472                 }
473                 printf("\n");
474                 break;
475         case SHORT:
476         case USHORT:
ragge
1.28
477                 astypnames[SHORT] = astypnames[USHORT] = "\t.half";
478                 return 0;
gmcgarry
1.3
479         case LDOUBLE:
480         case DOUBLE:
481                 u.d = (double)p->n_dcon;
gmcgarry
1.9
482                 if (bigendian) {
gmcgarry
1.10
483                         printf("\t.word\t%d\n"u.i[0]);
484                         printf("\t.word\t%d\n"u.i[1]);
gmcgarry
1.9
485                 } else {
gmcgarry
1.10
486                         printf("\t.word\t%d\n"u.i[1]);
487                         printf("\t.word\t%d\n"u.i[0]);
gmcgarry
1.9
488                 }
gmcgarry
1.3
489                 break;
490         case FLOAT:
491                 u.f = (float)p->n_dcon;
492                 printf("\t.word\t0x%x\n"u.i[0]);
493                 break;
494         default:
ragge
1.28
495                 return 0;
gmcgarry
1.3
496         }
ragge
1.28
497         return 1;
ragge
1.1
498 }
499
500 /* make a name look like an external name in the local machine */
501 char *
502 exname(char *p)
503 {
504         if (p == NULL)
505                 return "";
506         return p;
507 }
508
509 /*
510  * map types which are not defined on the local machine
511  */
512 TWORD
513 ctype(TWORD type)
514 {
515         switch (BTYPE(type)) {
516         case LONG:
517                 MODTYPE(type,INT);
518                 break;
519
520         case ULONG:
521                 MODTYPE(type,UNSIGNED);
522
523         }
524         return (type);
525 }
526
527 void
528 calldec(NODE *pNODE *q
529 {
530 }
531
532 void
533 extdec(struct symtab *q)
534 {
535 }
536
ragge
1.14
537 /* make a common declaration for id, if reasonable */
538 void
539 defzero(struct symtab *sp)
540 {
541         int off;
542
ragge
1.22
543         off = tsize(sp->stypesp->sdfsp->sap);
ragge
1.14
544         off = (off+(SZCHAR-1))/SZCHAR;
545         printf("        .%scomm "sp->sclass == STATIC ? "l" : "");
546         if (sp->slevel == 0)
ragge
1.19
547                 printf("%s,0%o\n"sp->soname ? sp->soname : exname(sp->sname), off);
ragge
1.14
548         else
549                 printf(LABFMT ",0%o\n"sp->soffsetoff);
550 }
551
552
553 #ifdef notdef
ragge
1.1
554 /* make a common declaration for id, if reasonable */
555 void
556 commdec(struct symtab *q)
557 {
558         int off;
559
560         off = tsize(q->stypeq->sdfq->ssue);
561         off = (off+(SZCHAR-1))/SZCHAR;
562
ragge
1.13
563         printf("        .comm %s,%d\n"exname(q->soname), off);
ragge
1.1
564 }
565
566 /* make a local common declaration for id, if reasonable */
567 void
568 lcommdec(struct symtab *q)
569 {
570         int off;
571
572         off = tsize(q->stypeq->sdfq->ssue);
573         off = (off+(SZCHAR-1))/SZCHAR;
574         if (q->slevel == 0)
ragge
1.13
575                 printf("\t.lcomm %s,%d\n"exname(q->soname), off);
ragge
1.1
576         else
gmcgarry
1.9
577                 printf("\t.lcomm " LABFMT ",%d\n"q->soffsetoff);
ragge
1.1
578 }
579
580 /*
581  * print a (non-prog) label.
582  */
583 void
584 deflab1(int label)
585 {
586         printf(LABFMT ":\n"label);
587 }
588
gmcgarry
1.9
589 /* ro-text, rw-data, ro-data, ro-strings */
590 static char *loctbl[] = { "text""data""rdata""rdata" };
ragge
1.1
591
592 void
593 setloc1(int locc)
594 {
gmcgarry
1.10
595         if (locc == lastloc && locc != STRNG)
ragge
1.1
596                 return;
gmcgarry
1.15
597         if (locc == RDATA && lastloc == STRNG)
gmcgarry
1.10
598                 return;
599
600         if (locc != lastloc) {
601                 lastloc = locc;
602                 printf("\t.%s\n"loctbl[locc]);
603         }
604
605         if (locc == STRNG)
606                 printf("\t.align 2\n");
ragge
1.1
607 }
ragge
1.14
608 #endif
gmcgarry
1.2
609
610 /*
gmcgarry
1.6
611  * va_start(ap, last) implementation.
612  *
613  * f is the NAME node for this builtin function.
614  * a is the argument list containing:
615  *         CM
616  *      ap   last
gmcgarry
1.7
617  *
618  * It turns out that this is easy on MIPS.  Just write the
619  * argument registers to the stack in va_arg_start() and
620  * use the traditional method of walking the stackframe.
gmcgarry
1.6
621  */
622 NODE *
ragge
1.33
623 mips_builtin_stdarg_start(const struct bitable *btNODE *a)
gmcgarry
1.6
624 {
gmcgarry
1.7
625         NODE *p, *q;
gmcgarry
1.6
626         int sz = 1;
627
628         /* check num args and type */
629         if (a == NULL || a->n_op != CM || a->n_left->n_op == CM ||
630             !ISPTR(a->n_left->n_type))
631                 goto bad;
632
633         /* must first deal with argument size; use int size */
634         p = a->n_right;
gmcgarry
1.7
635         if (p->n_type < INT) {
636                 /* round up to word */
ragge
1.22
637                 sz = SZINT / tsize(p->n_typep->n_dfp->n_ap);
gmcgarry
1.7
638         }
639
640         p = buildtree(ADDROFpNIL);  /* address of last arg */
641         p = optim(buildtree(PLUSpbcon(sz)));
642         q = block(NAMENILNILPTR+VOID00);
643         q = buildtree(CASTqp);
644         p = q->n_right;
645         nfree(q->n_left);
646         nfree(q);
647         p = buildtree(ASSIGNa->n_leftp);
648         nfree(a);
649
650         return p;
651
gmcgarry
1.6
652 bad:
gmcgarry
1.7
653         uerror("bad argument to __builtin_stdarg_start");
654         return bcon(0);
gmcgarry
1.6
655 }
656
657 NODE *
ragge
1.33
658 mips_builtin_va_arg(const struct bitable *btNODE *a)
gmcgarry
1.6
659 {
gmcgarry
1.7
660         NODE *p, *q, *r;
661         int sztmpnr;
662
663         /* check num args and type */
664         if (a == NULL || a->n_op != CM || a->n_left->n_op == CM ||
665             !ISPTR(a->n_left->n_type) || a->n_right->n_op != TYPE)
666                 goto bad;
667
gmcgarry
1.15
668         r = a->n_right;
gmcgarry
1.7
669
gmcgarry
1.15
670         /* get type size */
ragge
1.22
671         sz = tsize(r->n_typer->n_dfr->n_ap) / SZCHAR;
gmcgarry
1.9
672         if (sz < SZINT/SZCHAR) {
673                 werror("%s%s promoted to int when passed through ...",
674                         r->n_type & 1 ? "unsigned " : "",
675                         DEUNSIGN(r->n_type) == SHORT ? "short" : "char");
676                 sz = SZINT/SZCHAR;
677         }
gmcgarry
1.15
678
679         /* alignment */
680         p = tcopy(a->n_left);
681         if (sz > SZINT/SZCHAR && r->n_type != UNIONTY && r->n_type != STRTY) {
682                 p = buildtree(PLUSpbcon(7));
ragge
1.22
683                 p = block(ANDpbcon(-8), p->n_typep->n_dfp->n_ap);
gmcgarry
1.15
684         }
685
686         /* create a copy to a temp node */
ragge
1.22
687         q = tempnode(0p->n_typep->n_dfp->n_ap);
gmcgarry
1.15
688         tmpnr = regno(q);
689         p = buildtree(ASSIGNqp);
690
ragge
1.22
691         q = tempnode(tmpnrp->n_typep->n_df,p->n_ap);
gmcgarry
1.15
692         q = buildtree(PLUSqbcon(sz));
693         q = buildtree(ASSIGNa->n_leftq);
694
gmcgarry
1.7
695         q = buildtree(COMOPpq);
696
697         nfree(a->n_right);
698         nfree(a);
699
ragge
1.22
700         p = tempnode(tmpnrINCREF(r->n_type), r->n_dfr->n_ap);
gmcgarry
1.7
701         p = buildtree(UMULpNIL);
702         p = buildtree(COMOPqp);
703
704         return p;
705
706 bad:
707         uerror("bad argument to __builtin_va_arg");
708         return bcon(0);
gmcgarry
1.6
709 }
710
711 NODE *
ragge
1.33
712 mips_builtin_va_end(const struct bitable *btNODE *a)
gmcgarry
1.6
713 {
gmcgarry
1.7
714         tfree(a);
715         return bcon(0);
gmcgarry
1.6
716 }
717
718 NODE *
ragge
1.33
719 mips_builtin_va_copy(const struct bitable *btNODE *a)
gmcgarry
1.6
720 {
ragge
1.33
721         NODE *f;
722
gmcgarry
1.7
723         if (a == NULL || a->n_op != CM || a->n_left->n_op == CM)
724                 goto bad;
725         f = buildtree(ASSIGNa->n_lefta->n_right);
726         nfree(a);
gmcgarry
1.6
727         return f;
gmcgarry
1.7
728
729 bad:
730         uerror("bad argument to __buildtin_va_copy");
731         return bcon(0);
gmcgarry
1.6
732 }
gmcgarry
1.15
733
gmcgarry
1.17
734 static int constructor;
735 static int destructor;
736
ragge
1.13
737 /*
738  * Give target the opportunity of handling pragmas.
739  */
740 int
ragge
1.24
741 mypragma(char *str)
ragge
1.13
742 {
ragge
1.24
743
744         if (strcmp(str"tls") == 0) { 
gmcgarry
1.17
745                 uerror("thread-local storage not supported for this target");
746                 return 1;
747         } 
ragge
1.24
748         if (strcmp(str"constructor") == 0 || strcmp(str"init") == 0) {
gmcgarry
1.17
749                 constructor = 1;
750                 return 1;
751         }
ragge
1.24
752         if (strcmp(str"destructor") == 0 || strcmp(str"fini") == 0) {
gmcgarry
1.17
753                 destructor = 1;
754                 return 1;
755         }
756
gmcgarry
1.15
757         return 0;
758 }
ragge
1.13
759
760 /*
761  * Called when a identifier has been declared, to give target last word.
762  */
763 void
764 fixdef(struct symtab *sp)
765 {
gmcgarry
1.17
766         if ((constructor || destructor) && (sp->sclass != PARAM)) {
767                 printf("\t.section .%ctors,\"aw\",@progbits\n",
768                     constructor ? 'c' : 'd');
769                 printf("\t.p2align 2\n");
770                 printf("\t.long %s\n"exname(sp->sname));
gmcgarry
1.21
771                 printf("\t.previous\n");
gmcgarry
1.17
772                 constructor = destructor = 0;
773         }
774 }
775
776 void
777 pass1_lastchance(struct interpass *ip)
778 {
ragge
1.13
779 }
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-23 04:02 +0100