Quick Search:

Mode

Context

Displaying the whole file. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.27
 
1.28
 
MAIN:ragge:20121213160125
 
local.c
_>11 /*      $Id$    */
 22 /*
 33  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
 44  *
 55  * Redistribution and use in source and binary forms, with or without
 66  * modification, are permitted provided that the following conditions
 77  * are met:
 88  *
 99  * Redistributions of source code and documentation must retain the above
 1010  * copyright notice, this list of conditions and the following disclaimer.
 1111  * Redistributions in binary form must reproduce the above copyright
 1212  * notice, this list of conditionsand the following disclaimer in the
 1313  * documentation and/or other materials provided with the distribution.
 1414  * All advertising materials mentioning features or use of this software
 1515  * must display the following acknowledgement:
 1616  *      This product includes software developed or owned by Caldera
 1717  *      International, Inc.
 1818  * Neither the name of Caldera International, Inc. nor the names of other
 1919  * contributors may be used to endorse or promote products derived from
 2020  * this software without specific prior written permission.
 2121  *
 2222  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
 2323  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
 2424  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 2525  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 2626  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
 2727  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 2828  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 2929  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 3030  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
 3131  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 3232  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 3333  * POSSIBILITY OF SUCH DAMAGE.
 3434  */
 3535 
 3636 # include "pass1.h"
 3737 
 3838 static void r1arg(NODE *p, NODE *q);
 3939 
 4040 
 4141 /*      this file contains code which is dependent on the target machine */
 4242 
 4343 NODE *
 4444 clocal(p) NODE *p; {
 4545 
 4646         /* this is called to do local transformations on
 4747            an expression tree preparitory to its being
 4848            written out in intermediate code.
 4949         */
 5050 
 5151         /* the major essential job is rewriting the
 5252            automatic variables and arguments in terms of
 5353            REG and OREG nodes */
 5454         /* conversion ops which are not necessary are also clobbered here */
 5555         /* in addition, any special features (such as rewriting
 5656            exclusive or) are easily handled here as well */
 5757 
 5858         register struct symtab *q;
 5959         register NODE *r, *l;
 6060         register int o;
 6161         register int ml;
 6262 
 6363 
 6464 #ifdef PCC_DEBUG
 6565         if (xdebug) {
 6666                 printf("clocal(%p)\n", p);
 6767                 if (xdebug>1)
 6868                         fwalk(p, eprint, 0);
 6969         }
 7070 #endif
 7171 
 7272         switch( o = p->n_op ){
 7373 
 7474         case NAME:
 7575                 if((q = p->n_sp) == 0 ) { /* already processed; ignore... */
 7676                         return(p);
 7777                         }
 7878                 switch( q->sclass ){
 7979 
 8080                 case REGISTER:
 8181                 case AUTO:
 8282                 case PARAM:
 8383                         /* fake up a structure reference */
 8484                         r = block( REG, NIL, NIL, PTR+STRTY, 0, 0 );
 8585                         r->n_lval = 0;
 8686                         r->n_rval = (q->sclass==PARAM?ARGREG:FPREG);
 8787                         p = stref( block( STREF, r, p, 0, 0, 0 ) );
 8888                         break;
 8989                 }
 9090                 break;
 9191 
 9292         case FORCE:
 9393                 p->n_op = ASSIGN;
 9494                 p->n_right = p->n_left;
 9595                 p->n_left = block(REG, NIL, NIL, p->n_type, 0, 0);
 9696                 p->n_left->n_rval = p->n_left->n_type == BOOL ?
 9797                     RETREG(CHAR) : RETREG(p->n_type);
 9898                 break;
 9999 
 100100         case SCONV:
 101101                 l = p->n_left;
 102102                 ml = p->n_type;
<> 103+#if 0
103104                 if (ml == INT && l->n_type == UNSIGNED) {
 104105                         p = nfree(p);
 105106                         break;
 106107                 }
<> 108+#endif
<_107109                 if (l->n_op == ICON) {
 108110                         if (l->n_sp == 0) {
 109111                                 p->n_type = UNSIGNED;
 110112                                 concast(l, p->n_type);
 111113                         } else if (ml != INT && ml != UNSIGNED)
 112114                                 break;
 113115                         l->n_type = ml;
 114116                         l->n_ap = 0;
 115117                         p = nfree(p);
 116118                         break;
 117119                 }
 118120                 break;
 119121 
 120122         case STCALL:
 121123                 /* see if we have been here before */
 122124                 for (r = p->n_right; r->n_op == CM; r = r->n_left)
 123125                         ;
 124126                 if (r->n_op == ASSIGN)
 125127                         break;
 126128 
 127129                 /* FALLTHROUGH */
 128130         case USTCALL:
 129131                 /* Allocate buffer on stack to bounce via */
 130132                 /* create fake symtab here */
 131133                 q = getsymtab("77fake", STEMP);
 132134                 q->stype = BTYPE(p->n_type);
 133135                 q->sdf = p->n_df;
 134136                 q->sap = p->n_ap;
 135137                 q->soffset = NOOFFSET;
 136138                 q->sclass = AUTO;
 137139                 oalloc(q, &autooff);
 138140                 r1arg(p, buildtree(ADDROF, nametree(q), 0));
 139141                 break;
 140142         }
 141143 #ifdef PCC_DEBUG
 142144         if (xdebug) {
 143145                 printf("clocal end(%p)\n", p);
 144146                 if (xdebug>1)
 145147                         fwalk(p, eprint, 0);
 146148         }
 147149 #endif
 148150 
 149151         return(p);
 150152 }
 151153 
 152154 /*
 153155  * Add R1 with the dest address as arg to a struct return call.
 154156  */
 155157 static void
 156158 r1arg(NODE *p, NODE *q)
 157159 {
 158160         NODE *r;
 159161 
 160162         r = block(REG, NIL, NIL, PTR|VOID, 0, 0);
 161163         regno(r) = R1;
 162164         r = buildtree(ASSIGN, r, q);
 163165         if (p->n_op == USTCALL) {
 164166                 p->n_op = STCALL;
 165167                 p->n_right = r;
 166168         } else if (p->n_right->n_op != CM) {
 167169                 p->n_right = block(CM, r, p->n_right, INT, 0, 0);
 168170         } else {
 169171                 for (q = p->n_right; q->n_left->n_op == CM; q = q->n_left)
 170172                         ;
 171173                 q->n_left = block(CM, r, q->n_left, INT, 0, 0);
 172174         }
 173175 }
 174176 
 175177 void
 176178 myp2tree(NODE *p)
 177179 {
 178180         struct symtab *sp;
 179181 
 180182         if ((cdope(p->n_op) & CALLFLG) && p->n_left->n_op == ADDROF &&
 181183             p->n_left->n_left->n_op == NAME) {
 182184                 NODE *q = p->n_left->n_left;
 183185                 nfree(p->n_left);
 184186                 p->n_left = q;
 185187                 q->n_op = ICON;
 186188         }
 187189 
 188190         if (p->n_op != FCON)
 189191                 return;
 190192 
 191193         sp = inlalloc(sizeof(struct symtab));
 192194         sp->sclass = STATIC;
 193195         sp->sap = 0;
 194196         sp->slevel = 1; /* fake numeric label */
 195197         sp->soffset = getlab();
 196198         sp->sflags = 0;
 197199         sp->stype = p->n_type;
 198200         sp->squal = (CON >> TSHIFT);
 199201 
 200202         defloc(sp);
 201203         inval(0, tsize(sp->stype, sp->sdf, sp->sap), p);
 202204 
 203205         p->n_op = NAME;
 204206         p->n_lval = 0;
 205207         p->n_sp = sp;
 206208 
 207209 }
 208210 
 209211 /*
 210212  * Can we take & of a NAME?
 211213  */
 212214 int
 213215 andable(NODE *p)
 214216 {
 215217         /* for now, delay name reference to table, for PIC code generation */
 216218         /* functions are called by name, convert they in myp2tree */
 217219         return 0;
 218220 }
 219221 
 220222 /* is an automatic variable of type t OK for a register variable */
 221223 int
 222224 cisreg(TWORD t)
 223225 {
 224226         return(1);      /* all are now */
 225227 }
 226228 
 227229 /*
 228230  * Allocate off bits on the stack.  p is a tree that when evaluated
 229231  * is the multiply count for off, t is a storeable node where to write
 230232  * the allocated address.
 231233  */
 232234 void
 233235 spalloc(NODE *t, NODE *p, OFFSZ off)
 234236 {
 235237         NODE *sp;
 236238 
 237239         p = buildtree(MUL, p, bcon(off/SZCHAR)); /* XXX word alignment? */
 238240 
 239241         /* sub the size from sp */
 240242         sp = block(REG, NIL, NIL, p->n_type, 0, 0);
 241243         sp->n_lval = 0;
 242244         sp->n_rval = STKREG;
 243245         ecomp(buildtree(MINUSEQ, sp, p));
 244246 
 245247         /* save the address of sp */
 246248         sp = block(REG, NIL, NIL, PTR+INT, t->n_df, t->n_ap);
 247249         sp->n_lval = 0;
 248250         sp->n_rval = STKREG;
 249251         t->n_type = sp->n_type;
 250252         ecomp(buildtree(ASSIGN, t, sp)); /* Emit! */
 251253 
 252254 }
 253255 
 254256 char *
 255257 exname( p ) char *p; {
 256258         /* make a name look like an external name in the local machine */
 257259         /* vad is elf now */
 258260         if (p == NULL)
 259261                 return "";
 260262         return( p );
 261263         }
 262264 
 263265 /* map types which are not defined on the local machine */
 264266 TWORD
 265267 ctype(TWORD type) {
 266268         switch( BTYPE(type) ){
 267269 
 268270         case LONG:
 269271                 MODTYPE(type,INT);
 270272                 break;
 271273 
 272274         case ULONG:
 273275                 MODTYPE(type,UNSIGNED);
 274276                 break;
 275277 
 276278         case LDOUBLE:   /* for now */
 277279                 MODTYPE(type,DOUBLE);
 278280                 }
 279281         return( type );
 280282         }
 281283 
 282284 void
 283285 calldec(NODE *p, NODE *q)
 284286 {
 285287 }
 286288 
 287289 void
 288290 extdec(struct symtab *q)
 289291 {
 290292 }
 291293 
 292294 /* make a common declaration for id, if reasonable */
 293295 void
 294296 defzero(struct symtab *sp)
 295297 {
 296298         int off, al;
 297299         char *name;
 298300 
 299301         if ((name = sp->soname) == NULL)
 300302                 name = exname(sp->sname);
 301303         off = tsize(sp->stype, sp->sdf, sp->sap);
 302304         SETOFF(off,SZCHAR);
 303305         off /= SZCHAR;
 304306         al = talign(sp->stype, sp->sap)/SZCHAR;
 305307 
 306308         if (sp->sclass == STATIC) {
 307309                 if (sp->slevel == 0)
 308310                         printf("\t.local %s\n", name);
 309311                 else
 310312                         printf("\t.local " LABFMT "\n", sp->soffset);
 311313         }
 312314         if (sp->slevel == 0) {
 313315                 printf("\t.comm %s,0%o,%d\n", name, off, al);
 314316         } else
 315317                 printf("\t.comm " LABFMT ",0%o,%d\n", sp->soffset, off, al);
 316318 }
 317319 
 318320 /*
 319321  * print out a constant node, may be associated with a label.
 320322  * Do not free the node after use.
 321323  * off is bit offset from the beginning of the aggregate
 322324  * fsz is the number of bits this is referring to
 323325  * XXX - floating point constants may be wrong if cross-compiling.
 324326  */
 325327 int
 326328 ninval(CONSZ off, int fsz, NODE *p)
 327329 {
 328330         union { float f; double d; long double l; int i[3]; } u;
 329331 
 330332         switch (p->n_type) {
 331333         case LDOUBLE:
 332334                 u.i[2] = 0;
 333335                 u.l = (long double)p->n_dcon;
 334336                 printf("\t.long\t0x%x,0x%x,0x%x\n", u.i[0], u.i[1], u.i[2]);
 335337                 break;
 336338         case DOUBLE:
 337339                 u.d = (double)p->n_dcon;
 338340                 printf("\t.long\t0x%x,0x%x\n", u.i[0], u.i[1]);
 339341                 break;
 340342         case FLOAT:
 341343                 u.f = (float)p->n_dcon;
 342344                 printf("\t.long\t0x%x\n", u.i[0]);
 343345                 break;
 344346         default:
 345347                 return 0;
 346348         }
 347349         return 1;
 348350 
 349351 }
 350352 /*
 351353  * Give target the opportunity of handling pragmas.
 352354  */
 353355 int
 354356 mypragma(char *str)
 355357 {
 356358         return 0;
 357359 }
 358360 
 359361 /*
 360362  * Called when a identifier has been declared, to give target last word.
 361363  */
 362364 void
 363365 fixdef(struct symtab *sp)
 364366 {
 365367 }
 366368 
 367369 void
 368370 pass1_lastchance(struct interpass *ip)
 369371 {
 370372 }
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 14:23 +0200