Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.291
 
1.292
 
MAIN:ragge:20110727175131
 
trees.c
_>436436                 case UMUL:
 437437                         if (l->n_op == ADDROF) {
 438438                                 nfree(p);
<>439 -                                p = l->n_left;
 440 -                                nfree(l);
  439+                                p = nfree(l);
441440                         }
 442441                         if( !ISPTR(l->n_type))uerror("illegal indirection");
 443442                         p->n_type = DECREF(l->n_type);
     
 !
451450 
 452451                         case UMUL:
 453452                                 nfree(p);
<>454 -                                p = l->n_left;
 455 -                                nfree(l);
  453+                                p = nfree(l);
  454+                                /* FALLTHROUGH */
456455                         case TEMP:
 457456                         case NAME:
 458457                                 p->n_type = INCREF(l->n_type);
     
 !
11231122 
 11241123         s = p->n_right->n_sp;
 11251124         nfree(p->n_right);
<>1126 -        r = p->n_left;
 1127 -        nfree(p);
  1125+        r = nfree(p);
11281126         xap = attr_find(r->n_ap, GCC_ATYP_PACKED);
 11291127 
 11301128         p = pconvert(r);
     
 !
23492347         return p;
 23502348 }
 23512349 
<> 2350+#ifndef FIELDOPS
  2351+
23522352 /* avoid promotion to int */
<>2353 -#define TYPLS(p, n, t)  clocal(block(LS, p, bcon(n), t, 0, 0))
 2354 -#define TYPRS(p, n, t)  clocal(block(RS, p, bcon(n), t, 0, 0))
 2355 -#define TYPOR(p, q, t)  clocal(block(OR, p, q, t, 0, 0))
  2353+#define TYPMOD(o, p, n, t)      clocal(block(o, p, n, t, 0, 0))
  2354+#define TYPLS(p, n, t)  TYPMOD(LS, p, n, t)
  2355+#define TYPRS(p, n, t)  TYPMOD(RS, p, n, t)
  2356+#define TYPOR(p, q, t)  TYPMOD(OR, p, q, t)
  2357+#define TYPAND(p, q, tTYPMOD(AND, p, q, t)
23562358 
<>2357 -#ifndef UNALIGNED_ACCESS
23582359 /*
 23592360  * Read an unaligned bitfield from position pointed to by p starting at
 23602361  * off and size fsz and return a tree of type t with resulting data.
 23612362  */
 23622363 static NODE *
<>2363 -rdualfld(NODE *p, TWORD t, int off, int fsz)
  2364+rdualfld(NODE *p, TWORD t, TWORD ct, int off, int fsz)
23642365 {
<>2365 -        int t2f, inbits, tsz;
  2366+        int t2f, inbits, tsz, ctsz;
23662367         NODE *q, *r;
 23672368 
<>2368 -        p = makety(p, PTR|UCHAR, 0, 0, 0);
  2369+        ct = ENUNSIGN(ct);
  2370+        ctsz = (int)tsize(ct, 0, 0);
23692371 
 23702372         /* traverse until first data byte */
<>2371 -        for (t2f = 0; off > SZCHAR; t2f++, off -= SZCHAR)
  2373+        for (t2f = 0; off > ctsz; t2f++, off -= ctsz)
23722374                 ;
<>2373 -        q = buildtree(UMUL, buildtree(PLUS, ccopy(p), bcon(t2f)), 0);
 2374 -        q = makety(TYPRS(q, off, UCHAR), t, 0, 0, 0);
 2375 -        inbits = SZCHAR - off;
 2376 -        t2f++;
 2377 -
 2378 -        while (fsz > inbits) {
 2379 -                r = buildtree(UMUL, buildtree(PLUS, ccopy(p), bcon(t2f)), 0);
 2380 -                r = makety(r, t, 0, 0, 0);
 2381 -                r = TYPLS(r, inbits, t);
 2382 -                q = TYPOR(q, r, t);
 2383 -                inbits += SZCHAR;
  2375+#ifdef UNALIGNED_ACCESS
  2376+        /* try to squeeze it into an int */
  2377+        if (off + fsz > ctsz && off + fsz <= SZINT) {
  2378+                ct = UNSIGNED;
  2379+                ctsz = SZINT;
  2380+        }
  2381+#endif
  2382+        p = makety(p, PTR|ct, 0, 0, 0);
  2383+        if (off + fsz <= ctsz) {
  2384+                /* only one operation needed */
  2385+                q = buildtree(UMUL, buildtree(PLUS, p, bcon(t2f)), 0);
  2386+                if (!ISUNSIGNED(t)) {
  2387+                        ct = DEUNSIGN(ct);
  2388+                        q = makety(q, ct, 0, 0, 0);
  2389+                }
  2390+                q = TYPLS(q, bcon(ctsz-fsz-off), ct);
  2391+                q = TYPRS(q, bcon(ctsz-fsz), ct);
  2392+                q = makety(q, t, 0, 0, 0);
  2393+        } else {
  2394+                q = buildtree(UMUL, buildtree(PLUS, ccopy(p), bcon(t2f)), 0);
  2395+                q = makety(TYPRS(q, bcon(off), ct), t, 0, 0, 0);
  2396+                inbits = ctsz - off;
23842397                 t2f++;
<> 2398+
  2399+                while (fsz > inbits) {
  2400+                        r = buildtree(UMUL,
  2401+                            buildtree(PLUS, ccopy(p), bcon(t2f)), 0);
  2402+                        r = makety(r, t, 0, 0, 0);
  2403+                        r = TYPLS(r, bcon(inbits), t);
  2404+                        q = TYPOR(q, r, t);
  2405+                        inbits += ctsz;
  2406+                        t2f++;
  2407+                }
  2408+                /* sign/zero extend XXX - RS must sign extend */
  2409+                tsz = (int)tsize(t, 0, 0);
  2410+                if (!ISUNSIGNED(t)) {
  2411+                        t = DEUNSIGN(t);
  2412+                        q = makety(q, t, 0, 0, 0);
  2413+                }
  2414+                q = TYPLS(q, bcon(tsz-fsz), t);
  2415+                q = TYPRS(q, bcon(tsz-fsz), t);
  2416+                tfree(p);
23852417         }
<>2386 -        /* fix sign/zero extend XXX - RS must sign extend */
 2387 -        tsz = (int)tsize(t, 0, 0);
 2388 -        q = TYPLS(q, (tsz-fsz), t);
 2389 -        q = TYPRS(q, (tsz-fsz), t);
 2390 -        tfree(p);
23912418 
 23922419         return q;
 23932420 }
<>2394 -#endif
23952421 
<>2396 -#ifndef FIELDOPS
23972422 /*
<> 2423+ * Write val to a (unaligned) bitfield with length fsz positioned off bits 
  2424+ * from d. Bitfield type is t, and type to use when writing is ct.
  2425+ * neither f nor d should have any side effects if copied.
  2426+ * Multiples of ct are supposed to be written without problems.
  2427+ * Both val and d are free'd after use.
  2428+ */
  2429+static NODE *
  2430+wrualfld(NODE *val, NODE *d, TWORD t, TWORD ct, int off, int fsz)
  2431+{
  2432+        NODE *p, *q, *r, *rn;
  2433+        int tsz, ctsz, t2f, inbits;
  2434+ 
  2435+        tsz = (int)tsize(t, 0, 0);
  2436+        ctsz = (int)tsize(ct, 0, 0);
  2437+ 
  2438+        ct = ENUNSIGN(ct);
  2439+        d = makety(d, PTR|ct, 0, 0, 0);
  2440+
  2441+        for (t2f = 0; off > ctsz; t2f++, off -= ctsz)
  2442+                ;
  2443+ 
  2444+        if (off + fsz <= ctsz) {
  2445+                /* only one operation needed */
  2446+                d = buildtree(UMUL, buildtree(PLUS, d, bcon(t2f)), 0);  
  2447+                p = ccopy(d);
  2448+                p = TYPAND(p, xbcon(~(SZMASK(fsz) << off), 0, ct), ct);
  2449+                q = TYPAND(val, xbcon(SZMASK(fsz), 0, ct), ct);
  2450+                q = TYPLS(q, bcon(off), ct);  
  2451+                p = TYPOR(p, q, ct);
  2452+                p = makety(p, t, 0, 0, 0);    
  2453+                rn = buildtree(ASSIGN, d, p);
  2454+        } else {
  2455+                r = buildtree(UMUL, buildtree(PLUS, ccopy(d), bcon(t2f)), 0);
  2456+                p = ccopy(r);
  2457+                p = TYPAND(p, xbcon(SZMASK(off), 0, ct), ct);
  2458+                q = ccopy(val);
  2459+                q = TYPLS(q, bcon(off), t); 
  2460+                q = makety(q, ct, 0, 0, 0);
  2461+                p = TYPOR(p, q, ct);
  2462+                rn = buildtree(ASSIGN, r, p);
  2463+                inbits = ctsz - off;
  2464+                t2f++;
  2465+
  2466+                while (fsz > inbits+ctsz) {
  2467+                        r = buildtree(UMUL,
  2468+                            buildtree(PLUS, ccopy(d), bcon(t2f)), 0);
  2469+                        q = ccopy(val);
  2470+                        q = TYPRS(q, bcon(inbits), t);
  2471+                        q = makety(q, ct, 0, 0, 0);
  2472+                        rn = buildtree(COMOP, rn, buildtree(ASSIGN, r, q));
  2473+                        t2f++;
  2474+                        inbits += ctsz;
  2475+                }
  2476+
  2477+                r = buildtree(UMUL, buildtree(PLUS, d, bcon(t2f)), 0);
  2478+                p = ccopy(r);
  2479+                p = TYPAND(p, makety(xbcon(~SZMASK(fsz-inbits), 0, ct),
  2480+                    ct, 0, 0, 0), ct);
  2481+                q = TYPRS(val, bcon(inbits), t);
  2482+                q = TYPAND(q, xbcon(SZMASK(fsz-inbits), 0, t), t);
  2483+                q = makety(q, ct, 0, 0, 0);
  2484+                p = TYPOR(p, q, ct);
  2485+                rn = buildtree(COMOP, rn, buildtree(ASSIGN, r, p));
  2486+        }
  2487+        return rn;
  2488+}
  2489+
  2490+/*
23982491  * Rewrite bitfield operations to shifts.
 23992492  */
 24002493 static NODE *
 24012494 rmfldops(NODE *p)
 24022495 {
 24032496         CONSZ msk;
<>2404 -        TWORD t;
  2497+        TWORD t, ct;
24052498         NODE *q, *r, *t1, *t2, *bt, *t3, *t4;
 24062499         int fsz, foff, tsz;
 24072500 
 24082501         if (p->n_op == FLD) {
 24092502                 /* Rewrite a field read operation */
<>2410 -                q = p->n_left;
24112503                 fsz = UPKFSZ(p->n_rval);
 24122504                 foff = UPKFOFF(p->n_rval);
<>2413 -                tsz = tsize(q->n_type, 0, 0);
 2414 -                /*
 2415 -                                can_ua          no_ua
 2416 -                normal          typeread        typeread
 2417 -                packed          typeread        charread
 2418 -                toobig (packed) dual typeread   charread
 2419 -                 */
 2420 -#ifdef UNALIGNED_ACCESS
 2421 -                /* target can do unaligned access */
 2422 -                if (fsz + foff < tsz) {
 2423 -                        /* normal access of a type */
 2424 -#if TARGET_ENDIAN == TARGET_BE
 2425 -                        foff = tsz - fsz - foff;
 2426 -#endif
 2427 -                        q = clocal(block(LS, q,
 2428 -                            bcon(tsz-fsz-foff), p->n_type, 0, 0));
 2429 -                        q = clocal(block(RS, q, /* Assumed sign-extend RS */
 2430 -                            bcon(tsz-fsz), p->n_type, 0, 0));
 2431 -                } else {
 2432 -                        int t2f;
  2505+                tsz = tsize(p->n_left->n_type, 0, 0);
  2506+                q = buildtree(ADDROF, p->n_left, NIL);
24332507 
<>2434 -                        if (TARGET_ENDIAN == TARGET_BE)
 2435 -                                uerror("no support for big-endian packed yet");
 2436 -                        /* read type twice */
 2437 -                        t1 = buildtree(ADDROF, q, NIL);
 2438 -                        t2 = tempnode(0, t1->n_type, 0, 0);
 2439 -                        t3 = ccopy(t2);
 2440 -                        t4 = ccopy(t2);
 2441 -                        t1 = buildtree(ASSIGN, t2, t1);
 2442 -
 2443 -                        /* Get first part of type */
 2444 -                        t3 = cast(buildtree(UMUL, t3, NIL),
 2445 -                             ENUNSIGN(p->n_type), 0);
 2446 -                        t3 = clocal(block(RS, t3, bcon(foff),
 2447 -                            ENUNSIGN(p->n_type), 0, 0));
 2448 -
 2449 -                        /* second part */
 2450 -                        t2f = tsz+tsz-foff-fsz;
 2451 -                        t4 = buildtree(UMUL, buildtree(PLUS, t4, bcon(1)), 0);
 2452 -                        t4 = clocal(block(LS, t4, bcon(t2f), p->n_type, 0, 0));
 2453 -                        t4 = clocal(block(RS, t4,
 2454 -                             bcon(t2f-(tsz-foff)), p->n_type, 0, 0));
 2455 -
 2456 -                        /* merge */
 2457 -                        q = buildtree(COMOP, t1,
 2458 -                            clocal(block(OR, t3, t4 , p->n_type, 0, 0)));
 2459 -                }
 2460 -#else
 2461 -                if (attr_find(p->n_ap, GCC_ATYP_PACKED) == 0) {
 2462 -                        /* normal access of a type */
 2463 -#if TARGET_ENDIAN == TARGET_BE
 2464 -                        foff = tsz - fsz - foff;
  2508+                ct = t = p->n_type;
  2509+                if (attr_find(p->n_ap, GCC_ATYP_PACKED) &&
  2510+                    coptype(q->n_op) != LTYPE) {
  2511+                        t1 = tempnode(0, q->n_type, 0, 0);
  2512+                        bt = buildtree(ASSIGN, ccopy(t1), q);
  2513+                        q = t1;
  2514+#ifndef UNALIGNED_ACCESS
  2515+                        ct = UCHAR;
24652516 #endif
<>2466 -                        q = clocal(block(LS, q,
 2467 -                            bcon(tsz-fsz-foff), p->n_type, 0, 0));
 2468 -                        q = clocal(block(RS, q, /* Assumed sign-extend RS */
 2469 -                            bcon(tsz-fsz), p->n_type, 0, 0));
 2470 -                } else {
 2471 -                        /* Create an unsigned char byte pointer */
 2472 -                        t1 = makety(buildtree(ADDROF, q, NIL),
 2473 -                            PTR|UCHAR, 0, 0, 0);
 2474 -                        t2 = tempnode(0, t1->n_type, 0, 0);
 2475 -                        t3 = ccopy(t2);
 2476 -                        t1 = buildtree(ASSIGN, t2, t1);
 2477 -
 2478 -                        q = rdualfld(t3, p->n_type, foff, fsz);
 2479 -                        q = buildtree(COMOP, t1, q);
 2480 -                }
 2481 -#endif
 2482 -                if (q->n_type != p->n_type)
 2483 -                        q = cast(q, p->n_type, p->n_qual);
 2484 -                nfree(p);
 2485 -                p = q;
  2517+                } else
  2518+                        bt = bcon(0);
  2519+                q = rdualfld(q, t, ct, foff, fsz);
  2520+                p->n_left = bt;
  2521+                p->n_right = q;
  2522+                p->n_op = COMOP;
24862523         } else if (((cdope(p->n_op)&ASGOPFLG) || p->n_op == ASSIGN ||
 24872524             p->n_op == INCR || p->n_op == DECR) && p->n_left->n_op == FLD) {
 24882525                 /*
     
 !
25062543                 } else
 25072544                         t2 = p->n_right;
 25082545 
<> 2546+                ct = t;
  2547+#ifndef UNALIGNED_ACCESS
  2548+                if (attr_find(q->n_ap, GCC_ATYP_PACKED))
  2549+                        ct = UCHAR;
  2550+#endif
  2551+                /* t2 is what we have to write (RHS of ASSIGN) */
  2552+                /* bt is (eventually) something that must be written */
  2553+
  2554+
25092555                 if (q->n_left->n_op == UMUL) {
 25102556                         /* LHS of assignment may have side effects */
 25112557                         q = q->n_left;
     
 !
25152561                         bt = bt ? block(COMOP, bt, r, INT, 0, 0) : r;
 25162562                         q->n_left = t1;
 25172563                 }
<>2518 -                t1 = p->n_left->n_left;
  2564+                t1 = buildtree(ADDROF, p->n_left->n_left, 0);
25192565 
<>2520 -                if (p->n_op == ASSIGN) {
 2521 -                        q = clocal(block(AND, ccopy(t1),
 2522 -                            xbcon(~(msk << foff), 0, t), t, 0,0));
  2566+                /* t1 is lval where to write (and read) */
25232567 
<>2524 -                        r = clocal(block(AND, ccopy(t2),
 2525 -                            xbcon(msk, 0, t), t, 0, 0));
 2526 -                        r = clocal(block(LS, r, bcon(foff), t, 0, 0));
 2527 -                        q = clocal(block(OR, q, r, t, 0, 0));
 2528 -                        q = block(ASSIGN, t1, q, t, 0, 0);
  2568+                if (p->n_op == ASSIGN) {
  2569+                        q = wrualfld(t2, t1, t, ct, foff, fsz);
25292570                         if (bt)
 25302571                                 q = block(COMOP, bt, q, t, 0, 0);
 25312572                         nfree(p->n_left);
<>2532 -                        p->n_left = q;
 2533 -                        p->n_right = t2;
  2573+                        p->n_left = bcon(0);
  2574+                        p->n_right = q;
25342575                         p->n_op = COMOP;
 25352576                 } else if ((cdope(p->n_op)&ASGOPFLG)) {
 25362577                         /* And here is the asgop-specific code */
 25372578                         t3 = tempnode(0, t, 0, 0);
<>2538 -                        q = buildtree(ASSIGN, ccopy(t3), ccopy(t1));
 2539 -                        if (bt)
 2540 -                                bt = block(COMOP, bt, q, t, 0, 0);
 2541 -                        else
 2542 -                                bt = q;
  2579+                        q = rdualfld(ccopy(t1), t, ct, foff, fsz);
  2580+                        q = buildtree(UNASG p->n_op, q, t2);
  2581+                        q = buildtree(ASSIGN, ccopy(t3), q);
  2582+                        r = wrualfld(ccopy(t3), t1, t, ct, foff, fsz);
  2583+                        q = buildtree(COMOP, q, r);
  2584+                        q = buildtree(COMOP, q, t3);
25432585 
<>2544 -                        q = clocal(block(LS, t3, bcon(tsz-fsz-foff), t, 0, 0));
 2545 -                        q = clocal(block(RS, q, bcon(tsz-fsz), t, 0, 0));
25462586                         nfree(p->n_left);
<>2547 -                        p->n_right = t2;
 2548 -                        p->n_left = q;
 2549 -                        p->n_op = UNASG p->n_op;
 2550 -
 2551 -                        p = clocal(p);
 2552 -                        q = clocal(block(AND, ccopy(t1),
 2553 -                            xbcon(~(msk << foff), 0, t), t, 0,0));
 2554 -                        r = clocal(block(AND, p, xbcon(msk, 0, t), t, 0, 0));
 2555 -                        r = clocal(block(LS, r, bcon(foff), t, 0, 0));
 2556 -                        q = clocal(block(OR, q, r, t, 0, 0));
 2557 -                        q = block(ASSIGN, ccopy(t1), q, t, 0, 0);
 2558 -                        q = block(COMOP, bt, q, t, 0, 0);
 2559 -                        p = buildtree(COMOP, q, t1);
  2587+                        p->n_left = bt ? bt : bcon(0);
  2588+                        p->n_right = q;
  2589+                        p->n_op = COMOP;
25602590                 } else {
 25612591                         t3 = tempnode(0, t, 0, 0);
<>2562 -                        q = buildtree(ASSIGN, ccopy(t3), ccopy(t1));
 2563 -                        if (bt)
 2564 -                                bt = block(COMOP, bt, q, t, 0, 0);
 2565 -                        else
 2566 -                                bt = q;
 2567 -
 2568 -                        q = clocal(block(LS, t3, bcon(tsz-fsz-foff), t, 0, 0));
 2569 -                        q = clocal(block(RS, q, bcon(tsz-fsz), t, 0, 0));
25702592                         t4 = tempnode(0, t, 0, 0);
<>2571 -                        q = buildtree(ASSIGN, ccopy(t4), q);
25722593 
<> 2594+                        q = rdualfld(ccopy(t1), t, ct, foff, fsz);
  2595+                        q = buildtree(ASSIGN, ccopy(t3), q);
  2596+                        r = buildtree(p->n_op==INCR?PLUS:MINUS, ccopy(t3), t2);
  2597+                        r = buildtree(ASSIGN, ccopy(t4), r);
  2598+                        q = buildtree(COMOP, q, r);
  2599+                        r = wrualfld(t4, t1, t, ct, foff, fsz);
  2600+                        q = buildtree(COMOP, q, r);
  2601+                
  2602+                        if (bt)
  2603+                                q = block(COMOP, bt, q, t, 0, 0);
25732604                         nfree(p->n_left);
<>2574 -                        p->n_right = t2;
25752605                         p->n_left = q;
<>2576 -                        p->n_op = p->n_op == INCR ? PLUS : MINUS;
 2577 -
 2578 -                        q = clocal(block(AND, ccopy(t1),
 2579 -                            xbcon(~(msk << foff), 0, t), t, 0,0));
 2580 -                        r = clocal(block(AND, p, xbcon(msk, 0, t), t, 0, 0));
 2581 -                        r = clocal(block(LS, r, bcon(foff), t, 0, 0));
 2582 -                        q = clocal(block(OR, q, r, t, 0, 0));
 2583 -                        q = block(ASSIGN, t1, q, t, 0, 0);
 2584 -                        q = block(COMOP, bt, q, t, 0, 0);
 2585 -                        p = buildtree(COMOP, q, t4);
  2606+                        p->n_right = t3;
  2607+                        p->n_op = COMOP;
<_25862608                 }
 25872609         }
 25882610         if (coptype(p->n_op) != LTYPE)
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