Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20041002080115

Diff

Diff from 1.17 to:

Annotations

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

Annotated File View

ragge
1.17
1 /*      $Id: local.c,v 1.17 2004/10/02 08:01:15 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;
53
54         switcho = p->n_op ){
55
56         case NAME:
57                 if ((q = p->n_sp) == NULL)
58                         return p/* Nothing to care about */
59
60                 switch (q->sclass) {
61
62                 case PARAM:
63                 case AUTO:
64                         /* fake up a structure reference */
65                         r = block(REGNILNILPTR+STRTY00);
66                         r->n_lval = 0;
67                         r->n_rval = FPREG;
68                         p = stref(block(STREFrp000));
69                         break;
70
71                 case STATIC:
72                         if (q->slevel == 0)
73                                 break;
74                         p->n_lval = 0;
75                         p->n_sp = q;
76                         if ((q->sflags & SLABEL) == 0)
77                                 cerror("STATIC");
78                         break;
79
80                 case REGISTER:
81                         p->n_op = REG;
82                         p->n_lval = 0;
83                         p->n_rval = q->soffset;
84                         break;
85
86                         }
87                 break;
88
ragge
1.10
89         case FUNARG:
90                 /* Args smaller than int are given as int */
91                 if (p->n_type != CHAR && p->n_type != UCHAR && 
92                     p->n_type != SHORT && p->n_type != USHORT)
93                         break;
94                 p->n_left = block(SCONVp->n_leftNILINT0MKSUE(INT));
95                 p->n_type = INT;
96                 p->n_sue = MKSUE(INT);
97                 p->n_rval = SZINT;
98                 break;
99
ragge
1.8
100         case CBRANCH:
101                 l = p->n_left;
102
103                 /*
104                  * Remove unneccessary conversion ops.
105                  */
ragge
1.10
106                 if (clogop(l->n_op) && l->n_left->n_op == SCONV) {
ragge
1.12
107                         if (coptype(l->n_op) != BITYPE)
108                                 break;
ragge
1.8
109                         if (l->n_right->n_op == ICON) {
110                                 r = l->n_left->n_left;
111                                 nfree(l->n_left);
112                                 l->n_left = r;
ragge
1.17
113                         }
114 #if 0
115                           else if (l->n_right->n_op == SCONV &&
ragge
1.8
116                             l->n_left->n_type == l->n_right->n_type) {
117                                 r = l->n_left->n_left;
118                                 nfree(l->n_left);
119                                 l->n_left = r;
120                                 r = l->n_right->n_left;
121                                 nfree(l->n_right);
122                                 l->n_right = r;
123                         }
ragge
1.17
124 #endif
ragge
1.8
125                 }
126                 break;
127
ragge
1.1
128         case PCONV:
ragge
1.2
129                 ml = p->n_left->n_type;
ragge
1.1
130                 l = p->n_left;
131                 if ((ml == CHAR || ml == UCHAR || ml == SHORT || ml == USHORT)
132                     && l->n_op != ICON)
133                         break;
134                 l->n_type = p->n_type;
135                 l->n_qual = p->n_qual;
136                 l->n_df = p->n_df;
137                 l->n_sue = p->n_sue;
138                 nfree(p);
139                 p = l;
140                 break;
141
142         case SCONV:
143                 l = p->n_left;
ragge
1.4
144
145                 if ((p->n_type & TMASK) == 0 && (l->n_type & TMASK) == 0 &&
146                     btdim[p->n_type] == btdim[l->n_type]) {
147                         if (p->n_type != FLOAT && p->n_type != DOUBLE &&
ragge
1.15
148                             l->n_type != FLOAT && l->n_type != DOUBLE &&
149                             l->n_type != LDOUBLE && p->n_type != LDOUBLE) {
150                                 if (l->n_op == NAME || l->n_op == UMUL) {
151                                         l->n_type = p->n_type;
152                                         nfree(p);
153                                         return l;
154                                 }
ragge
1.4
155                         }
ragge
1.6
156                 }
157
ragge
1.11
158 #if 0
ragge
1.6
159                 if ((p->n_type == INT || p->n_type == UNSIGNED) &&
160                     ISPTR(l->n_type)) {
161                         nfree(p);
162                         return l;
ragge
1.4
163                 }
ragge
1.11
164 #endif
ragge
1.4
165
ragge
1.3
166                 o = l->n_op;
ragge
1.4
167                 m = p->n_type;
ragge
1.1
168
169                 if (o == ICON) {
170                         CONSZ val = l->n_lval;
171
172                         switch (m) {
173                         case CHAR:
174                                 l->n_lval = (char)val;
175                                 break;
176                         case UCHAR:
177                                 l->n_lval = val & 0377;
178                                 break;
ragge
1.15
179                         case SHORT:
ragge
1.1
180                                 l->n_lval = (short)val;
181                                 break;
ragge
1.15
182                         case USHORT:
ragge
1.1
183                                 l->n_lval = val & 0177777;
184                                 break;
ragge
1.15
185                         case ULONG:
ragge
1.1
186                         case UNSIGNED:
187                                 l->n_lval = val & 0xffffffff;
188                                 break;
189                         case ENUMTY:
190                         case MOETY:
ragge
1.15
191                         case LONG:
ragge
1.1
192                         case INT:
193                                 l->n_lval = (int)val;
194                                 break;
195                         case LONGLONG:
196                                 l->n_lval = (long long)val;
ragge
1.15
197                                 break;
ragge
1.1
198                         case ULONGLONG:
199                                 l->n_lval = val;
200                                 break;
201                         case VOID:
202                                 break;
ragge
1.14
203                         case LDOUBLE:
ragge
1.1
204                         case DOUBLE:
205                         case FLOAT:
206                                 l->n_op = FCON;
207                                 l->n_dcon = val;
208                                 break;
209                         default:
210                                 cerror("unknown type %d"m);
211                         }
212                         l->n_type = m;
213                         nfree(p);
214                         return l;
215                 }
ragge
1.17
216                 if (DEUNSIGN(p->n_type) == SHORT &&
217                     DEUNSIGN(l->n_type) == SHORT) {
218                         nfree(p);
219                         p = l;
220                 }
ragge
1.1
221                 break;
222
ragge
1.15
223         case MOD:
224         case DIV:
225                 if (o == DIV && p->n_type != CHAR && p->n_type != SHORT)
226                         break;
ragge
1.16
227                 if (o == MOD && p->n_type != CHAR && p->n_type != SHORT)
ragge
1.15
228                         break;
229                 /* make it an int division by inserting conversions */
230                 p->n_left = block(SCONVp->n_leftNILINT0MKSUE(INT));
231                 p->n_right = block(SCONVp->n_rightNILINT0MKSUE(INT));
232                 p = block(SCONVpNILp->n_type0MKSUE(p->n_type));
233                 p->n_left->n_type = INT;
234                 break;
235
ragge
1.1
236         case PMCONV:
237         case PVCONV:
238                 ifp->n_right->n_op != ICON ) cerror"bad conversion"0);
239                 nfree(p);
240                 return(buildtree(o==PMCONV?MUL:DIVp->n_leftp->n_right));
241
242         }
243
244         return(p);
245 }
246
247 void
248 myp2tree(NODE *p)
249 {
250 }
251
252 /*ARGSUSED*/
253 int
254 andable(NODE *p)
255 {
256         return(1);  /* all names can have & taken on them */
257 }
258
259 /*
260  * at the end of the arguments of a ftn, set the automatic offset
261  */
262 void
263 cendarg()
264 {
265         autooff = AUTOINIT;
266 }
267
268 /*
269  * is an automatic variable of type t OK for a register variable
270  */
271 int
272 cisreg(TWORD t)
273 {
ragge
1.13
274         if (t == INT || t == UNSIGNED || t == LONG || t == ULONG)
275                 return(1);
276         return 0/* XXX - fix reg assignment in pftn.c */
ragge
1.1
277 }
278
279 /*
280  * return a node, for structure references, which is suitable for
281  * being added to a pointer of type t, in order to be off bits offset
282  * into a structure
283  * t, d, and s are the type, dimension offset, and sizeoffset
284  * For pdp10, return the type-specific index number which calculation
285  * is based on its size. For example, short a[3] would return 3.
286  * Be careful about only handling first-level pointers, the following
287  * indirections must be fullword.
288  */
289 NODE *
290 offcon(OFFSZ offTWORD tunion dimfun *dstruct suedef *sue)
291 {
292         register NODE *p;
293
294         if (xdebug)
295                 printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
296                     offtdsue->suesize);
297
298         p = bcon(0);
299         p->n_lval = off/SZCHAR/* Default */
300         return(p);
301 }
302
303 /*
304  * Allocate off bits on the stack.  p is a tree that when evaluated
305  * is the multiply count for off, t is a NAME node where to write
306  * the allocated address.
307  */
308 void
309 spalloc(NODE *tNODE *pOFFSZ off)
310 {
311         NODE *sp;
312
313         if ((off % SZINT) == 0)
314                 p =  buildtree(MULpbcon(off/SZINT));
315         else if ((off % SZSHORT) == 0) {
316                 p = buildtree(MULpbcon(off/SZSHORT));
317                 p = buildtree(PLUSpbcon(1));
318                 p = buildtree(RSpbcon(1));
319         } else if ((off % SZCHAR) == 0) {
320                 p = buildtree(MULpbcon(off/SZCHAR));
321                 p = buildtree(PLUSpbcon(3));
322                 p = buildtree(RSpbcon(2));
323         } else
324                 cerror("roundsp");
325
326         /* save the address of sp */
327         sp = block(REGNILNILPTR+INTt->n_dft->n_sue);
328         sp->n_lval = 0;
329         sp->n_rval = STKREG;
330         t->n_type = sp->n_type;
331         ecomp(buildtree(ASSIGNtsp)); /* Emit! */
332
333         /* add the size to sp */
334         sp = block(REGNILNILp->n_type00);
335         sp->n_lval = 0;
336         sp->n_rval = STKREG;
337         ecomp(buildtree(PLUSEQspp));
338 }
339
340 /*
ragge
1.17
341  * print out an integer.
ragge
1.1
342  */
343 void
ragge
1.17
344 inval(CONSZ word)
ragge
1.1
345 {
ragge
1.17
346         word &= 0xffffffff;
347         printf("        .long 0x%llx\n"word);
ragge
1.1
348 }
349
ragge
1.17
350 /* output code to initialize a floating point value */
ragge
1.1
351 /* the proper alignment has been obtained */
352 void
ragge
1.17
353 finval(NODE *p)
ragge
1.1
354 {
ragge
1.17
355         switch (p->n_type) {
356         case LDOUBLE:
357                 printf("\t.tfloat\t0t%.20Le\n"p->n_dcon);
ragge
1.14
358                 break;
ragge
1.17
359         case DOUBLE:
360                 printf("\t.dfloat\t0d%.20e\n", (double)p->n_dcon);
ragge
1.14
361                 break;
ragge
1.17
362         case FLOAT:
363                 printf("\t.ffloat\t0f%.20e\n", (float)p->n_dcon);
ragge
1.14
364                 break;
365         }
ragge
1.1
366 }
367
368 /* make a name look like an external name in the local machine */
369 char *
370 exname(char *p)
371 {
372         if (p == NULL)
373                 return "";
374         return p;
375 }
376
377 /*
378  * map types which are not defined on the local machine
379  */
ragge
1.15
380 TWORD
ragge
1.1
381 ctype(TWORD type)
382 {
383         switch (BTYPE(type)) {
384         case LONG:
385                 MODTYPE(type,INT);
386                 break;
387
388         case ULONG:
389                 MODTYPE(type,UNSIGNED);
ragge
1.13
390
ragge
1.1
391         }
392         return (type);
393 }
394
395 /* curid is a variable which is defined but
396  * is not initialized (and not a function );
ragge
1.17
397  * This routine returns the storage class for an uninitialized declaration
ragge
1.1
398  */
399 int
400 noinit()
401 {
402         return(EXTERN);
403 }
404
405 /* make a common declaration for id, if reasonable */
406 void
407 commdec(struct symtab *q)
408 {
409         int off;
410
411         off = tsize(q->stypeq->sdfq->ssue);
ragge
1.8
412         off = (off+(SZCHAR-1))/SZCHAR;
ragge
1.7
413 #ifdef GCC_COMPAT
414         printf("        .comm %s,0%o\n"gcc_findname(q), off);
415 #else
ragge
1.1
416         printf("        .comm %s,0%o\n"exname(q->sname), off);
ragge
1.7
417 #endif
ragge
1.1
418 }
419
420 /* make a local common declaration for id, if reasonable */
421 void
422 lcommdec(struct symtab *q)
423 {
424         int off;
425
426         off = tsize(q->stypeq->sdfq->ssue);
ragge
1.8
427         off = (off+(SZCHAR-1))/SZCHAR;
ragge
1.1
428         if (q->slevel == 0)
ragge
1.7
429 #ifdef GCC_COMPAT
430                 printf("        .lcomm %s,0%o\n"gcc_findname(q), off);
431 #else
ragge
1.1
432                 printf("        .lcomm %s,0%o\n"exname(q->sname), off);
ragge
1.7
433 #endif
ragge
1.1
434         else
435                 printf("        .lcomm " LABFMT ",0%o\n"q->soffsetoff);
436 }
437
438 /*
439  * Debugger code - ignore.
440  */
441 void
442 prcstab(int a)
443 {
444 }
445
446 void
447 pfstab(char *a)
448 {
449 }
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-23 18:26 +0200