Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20041220182709

Diff

Diff from 1.22 to:

Annotations

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

Annotated File View

ragge
1.22
1 /*      $Id: local.c,v 1.22 2004/12/20 18:27:09 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  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29
30 # include "pass1.h"
31
32 /*      this file contains code which is dependent on the target machine */
33
34 NODE *
35 clocal(NODE *p)
36 {
37         /* this is called to do local transformations on
38            an expression tree preparitory to its being
39            written out in intermediate code.
40         */
41
42         /* the major essential job is rewriting the
43            automatic variables and arguments in terms of
44            REG and OREG nodes */
45         /* conversion ops which are not necessary are also clobbered here */
46         /* in addition, any special features (such as rewriting
47            exclusive or) are easily handled here as well */
48
49         register struct symtab *q;
ragge
1.2
50         register NODE *r, *l;
ragge
1.1
51         register int o;
52         register int mml;
ragge
1.19
53         TWORD t;
ragge
1.1
54
55         switcho = p->n_op ){
56
57         case NAME:
58                 if ((q = p->n_sp) == NULL)
59                         return p/* Nothing to care about */
60
61                 switch (q->sclass) {
62
63                 case PARAM:
64                 case AUTO:
65                         /* fake up a structure reference */
66                         r = block(REGNILNILPTR+STRTY00);
67                         r->n_lval = 0;
68                         r->n_rval = FPREG;
69                         p = stref(block(STREFrp000));
70                         break;
71
72                 case STATIC:
73                         if (q->slevel == 0)
74                                 break;
75                         p->n_lval = 0;
76                         p->n_sp = q;
77                         if ((q->sflags & SLABEL) == 0)
78                                 cerror("STATIC");
79                         break;
80
81                 case REGISTER:
82                         p->n_op = REG;
83                         p->n_lval = 0;
84                         p->n_rval = q->soffset;
85                         break;
86
87                         }
88                 break;
89
ragge
1.10
90         case FUNARG:
91                 /* Args smaller than int are given as int */
92                 if (p->n_type != CHAR && p->n_type != UCHAR && 
93                     p->n_type != SHORT && p->n_type != USHORT)
94                         break;
95                 p->n_left = block(SCONVp->n_leftNILINT0MKSUE(INT));
96                 p->n_type = INT;
97                 p->n_sue = MKSUE(INT);
98                 p->n_rval = SZINT;
99                 break;
100
ragge
1.8
101         case CBRANCH:
102                 l = p->n_left;
103
104                 /*
105                  * Remove unneccessary conversion ops.
106                  */
ragge
1.10
107                 if (clogop(l->n_op) && l->n_left->n_op == SCONV) {
ragge
1.12
108                         if (coptype(l->n_op) != BITYPE)
109                                 break;
ragge
1.8
110                         if (l->n_right->n_op == ICON) {
111                                 r = l->n_left->n_left;
ragge
1.18
112                                 /* Type must be correct */
ragge
1.19
113                                 t = r->n_type;
ragge
1.8
114                                 nfree(l->n_left);
115                                 l->n_left = r;
ragge
1.19
116                                 l->n_type = t;
117                                 l->n_right->n_type = t;
ragge
1.17
118                         }
119 #if 0
120                           else if (l->n_right->n_op == SCONV &&
ragge
1.8
121                             l->n_left->n_type == l->n_right->n_type) {
122                                 r = l->n_left->n_left;
123                                 nfree(l->n_left);
124                                 l->n_left = r;
125                                 r = l->n_right->n_left;
126                                 nfree(l->n_right);
127                                 l->n_right = r;
128                         }
ragge
1.17
129 #endif
ragge
1.8
130                 }
131                 break;
132
ragge
1.1
133         case PCONV:
ragge
1.2
134                 ml = p->n_left->n_type;
ragge
1.1
135                 l = p->n_left;
136                 if ((ml == CHAR || ml == UCHAR || ml == SHORT || ml == USHORT)
137                     && l->n_op != ICON)
138                         break;
139                 l->n_type = p->n_type;
140                 l->n_qual = p->n_qual;
141                 l->n_df = p->n_df;
142                 l->n_sue = p->n_sue;
143                 nfree(p);
144                 p = l;
145                 break;
146
147         case SCONV:
148                 l = p->n_left;
ragge
1.4
149
150                 if ((p->n_type & TMASK) == 0 && (l->n_type & TMASK) == 0 &&
151                     btdim[p->n_type] == btdim[l->n_type]) {
152                         if (p->n_type != FLOAT && p->n_type != DOUBLE &&
ragge
1.15
153                             l->n_type != FLOAT && l->n_type != DOUBLE &&
154                             l->n_type != LDOUBLE && p->n_type != LDOUBLE) {
155                                 if (l->n_op == NAME || l->n_op == UMUL) {
156                                         l->n_type = p->n_type;
157                                         nfree(p);
158                                         return l;
159                                 }
ragge
1.4
160                         }
ragge
1.6
161                 }
162
ragge
1.11
163 #if 0
ragge
1.6
164                 if ((p->n_type == INT || p->n_type == UNSIGNED) &&
165                     ISPTR(l->n_type)) {
166                         nfree(p);
167                         return l;
ragge
1.4
168                 }
ragge
1.11
169 #endif
ragge
1.4
170
ragge
1.3
171                 o = l->n_op;
ragge
1.4
172                 m = p->n_type;
ragge
1.1
173
174                 if (o == ICON) {
175                         CONSZ val = l->n_lval;
176
177                         switch (m) {
178                         case CHAR:
179                                 l->n_lval = (char)val;
180                                 break;
181                         case UCHAR:
182                                 l->n_lval = val & 0377;
183                                 break;
ragge
1.15
184                         case SHORT:
ragge
1.1
185                                 l->n_lval = (short)val;
186                                 break;
ragge
1.15
187                         case USHORT:
ragge
1.1
188                                 l->n_lval = val & 0177777;
189                                 break;
ragge
1.15
190                         case ULONG:
ragge
1.1
191                         case UNSIGNED:
192                                 l->n_lval = val & 0xffffffff;
193                                 break;
194                         case ENUMTY:
195                         case MOETY:
ragge
1.15
196                         case LONG:
ragge
1.1
197                         case INT:
198                                 l->n_lval = (int)val;
199                                 break;
200                         case LONGLONG:
201                                 l->n_lval = (long long)val;
ragge
1.15
202                                 break;
ragge
1.1
203                         case ULONGLONG:
204                                 l->n_lval = val;
205                                 break;
206                         case VOID:
207                                 break;
ragge
1.14
208                         case LDOUBLE:
ragge
1.1
209                         case DOUBLE:
210                         case FLOAT:
211                                 l->n_op = FCON;
212                                 l->n_dcon = val;
213                                 break;
214                         default:
215                                 cerror("unknown type %d"m);
216                         }
217                         l->n_type = m;
218                         nfree(p);
219                         return l;
220                 }
ragge
1.17
221                 if (DEUNSIGN(p->n_type) == SHORT &&
222                     DEUNSIGN(l->n_type) == SHORT) {
223                         nfree(p);
224                         p = l;
225                 }
ragge
1.1
226                 break;
227
ragge
1.15
228         case MOD:
229         case DIV:
230                 if (o == DIV && p->n_type != CHAR && p->n_type != SHORT)
231                         break;
ragge
1.16
232                 if (o == MOD && p->n_type != CHAR && p->n_type != SHORT)
ragge
1.15
233                         break;
234                 /* make it an int division by inserting conversions */
235                 p->n_left = block(SCONVp->n_leftNILINT0MKSUE(INT));
236                 p->n_right = block(SCONVp->n_rightNILINT0MKSUE(INT));
237                 p = block(SCONVpNILp->n_type0MKSUE(p->n_type));
238                 p->n_left->n_type = INT;
239                 break;
240
ragge
1.1
241         case PMCONV:
242         case PVCONV:
243                 ifp->n_right->n_op != ICON ) cerror"bad conversion"0);
244                 nfree(p);
245                 return(buildtree(o==PMCONV?MUL:DIVp->n_leftp->n_right));
246
247         }
248
249         return(p);
250 }
251
252 void
253 myp2tree(NODE *p)
254 {
255 }
256
257 /*ARGSUSED*/
258 int
259 andable(NODE *p)
260 {
261         return(1);  /* all names can have & taken on them */
262 }
263
264 /*
265  * at the end of the arguments of a ftn, set the automatic offset
266  */
267 void
268 cendarg()
269 {
270         autooff = AUTOINIT;
271 }
272
273 /*
274  * is an automatic variable of type t OK for a register variable
275  */
276 int
277 cisreg(TWORD t)
278 {
ragge
1.13
279         if (t == INT || t == UNSIGNED || t == LONG || t == ULONG)
280                 return(1);
281         return 0/* XXX - fix reg assignment in pftn.c */
ragge
1.1
282 }
283
284 /*
285  * return a node, for structure references, which is suitable for
286  * being added to a pointer of type t, in order to be off bits offset
287  * into a structure
288  * t, d, and s are the type, dimension offset, and sizeoffset
289  * For pdp10, return the type-specific index number which calculation
290  * is based on its size. For example, short a[3] would return 3.
291  * Be careful about only handling first-level pointers, the following
292  * indirections must be fullword.
293  */
294 NODE *
295 offcon(OFFSZ offTWORD tunion dimfun *dstruct suedef *sue)
296 {
297         register NODE *p;
298
299         if (xdebug)
300                 printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
301                     offtdsue->suesize);
302
303         p = bcon(0);
304         p->n_lval = off/SZCHAR/* Default */
305         return(p);
306 }
307
308 /*
309  * Allocate off bits on the stack.  p is a tree that when evaluated
310  * is the multiply count for off, t is a NAME node where to write
311  * the allocated address.
312  */
313 void
314 spalloc(NODE *tNODE *pOFFSZ off)
315 {
316         NODE *sp;
317
318         if ((off % SZINT) == 0)
319                 p =  buildtree(MULpbcon(off/SZINT));
320         else if ((off % SZSHORT) == 0) {
321                 p = buildtree(MULpbcon(off/SZSHORT));
322                 p = buildtree(PLUSpbcon(1));
323                 p = buildtree(RSpbcon(1));
324         } else if ((off % SZCHAR) == 0) {
325                 p = buildtree(MULpbcon(off/SZCHAR));
326                 p = buildtree(PLUSpbcon(3));
327                 p = buildtree(RSpbcon(2));
328         } else
329                 cerror("roundsp");
330
331         /* save the address of sp */
332         sp = block(REGNILNILPTR+INTt->n_dft->n_sue);
333         sp->n_lval = 0;
334         sp->n_rval = STKREG;
335         t->n_type = sp->n_type;
336         ecomp(buildtree(ASSIGNtsp)); /* Emit! */
337
338         /* add the size to sp */
339         sp = block(REGNILNILp->n_type00);
340         sp->n_lval = 0;
341         sp->n_rval = STKREG;
342         ecomp(buildtree(PLUSEQspp));
343 }
344
345 /*
ragge
1.21
346  * print out a constant node
347  * mat be associated with a label
348  */
349 void
350 ninval(NODE *p)
351 {
352         p = p->n_left;
353         switch (p->n_type) {
354         case LONGLONG:
355         case ULONGLONG:
356                 inval(p->n_lval & 0xffffffff);
357                 inval(p->n_lval >> 32);
358                 break;
359         case INT:
360         case UNSIGNED:
361                 printf("\t.long 0x%x", (int)p->n_lval);
362                 if (p->n_sp != NULL) {
363                         if (p->n_sp->sflags & SLABEL ||
364                             p->n_sp->sclass == ILABEL) {
365                                 printf("+" LABFMTp->n_sp->soffset);
366                         } else
367                                 printf("+%s"exname(p->n_sp->sname));
368                 }
369                 printf("\n");
370                 break;
371         default:
372                 cerror("ninval");
373         }
374 }
375
376 /*
ragge
1.17
377  * print out an integer.
ragge
1.1
378  */
379 void
ragge
1.17
380 inval(CONSZ word)
ragge
1.1
381 {
ragge
1.17
382         word &= 0xffffffff;
383         printf("        .long 0x%llx\n"word);
ragge
1.1
384 }
385
ragge
1.17
386 /* output code to initialize a floating point value */
ragge
1.1
387 /* the proper alignment has been obtained */
388 void
ragge
1.17
389 finval(NODE *p)
ragge
1.1
390 {
ragge
1.17
391         switch (p->n_type) {
392         case LDOUBLE:
393                 printf("\t.tfloat\t0t%.20Le\n"p->n_dcon);
ragge
1.14
394                 break;
ragge
1.17
395         case DOUBLE:
396                 printf("\t.dfloat\t0d%.20e\n", (double)p->n_dcon);
ragge
1.14
397                 break;
ragge
1.17
398         case FLOAT:
399                 printf("\t.ffloat\t0f%.20e\n", (float)p->n_dcon);
ragge
1.14
400                 break;
401         }
ragge
1.1
402 }
403
404 /* make a name look like an external name in the local machine */
405 char *
406 exname(char *p)
407 {
408         if (p == NULL)
409                 return "";
410         return p;
411 }
412
413 /*
414  * map types which are not defined on the local machine
415  */
ragge
1.15
416 TWORD
ragge
1.1
417 ctype(TWORD type)
418 {
419         switch (BTYPE(type)) {
420         case LONG:
421                 MODTYPE(type,INT);
422                 break;
423
424         case ULONG:
425                 MODTYPE(type,UNSIGNED);
ragge
1.13
426
ragge
1.1
427         }
428         return (type);
429 }
430
431 /* curid is a variable which is defined but
432  * is not initialized (and not a function );
ragge
1.17
433  * This routine returns the storage class for an uninitialized declaration
ragge
1.1
434  */
435 int
436 noinit()
437 {
438         return(EXTERN);
439 }
440
441 /* make a common declaration for id, if reasonable */
442 void
443 commdec(struct symtab *q)
444 {
445         int off;
446
447         off = tsize(q->stypeq->sdfq->ssue);
ragge
1.8
448         off = (off+(SZCHAR-1))/SZCHAR;
ragge
1.7
449 #ifdef GCC_COMPAT
450         printf("        .comm %s,0%o\n"gcc_findname(q), off);
451 #else
ragge
1.1
452         printf("        .comm %s,0%o\n"exname(q->sname), off);
ragge
1.7
453 #endif
ragge
1.1
454 }
455
456 /* make a local common declaration for id, if reasonable */
457 void
458 lcommdec(struct symtab *q)
459 {
460         int off;
461
462         off = tsize(q->stypeq->sdfq->ssue);
ragge
1.8
463         off = (off+(SZCHAR-1))/SZCHAR;
ragge
1.1
464         if (q->slevel == 0)
ragge
1.7
465 #ifdef GCC_COMPAT
466                 printf("        .lcomm %s,0%o\n"gcc_findname(q), off);
467 #else
ragge
1.1
468                 printf("        .lcomm %s,0%o\n"exname(q->sname), off);
ragge
1.7
469 #endif
ragge
1.1
470         else
471                 printf("        .lcomm " LABFMT ",0%o\n"q->soffsetoff);
472 }
ragge
1.22
473
474 /*
475  * print a (non-prog) label.
476  */
477 void
478 deflab1(int label)
479 {
480         printf(LABFMT ":\n"label);
481 }
482
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-23 01:36 +0200