Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.259
 
1.260
 
MAIN:ragge:20090516121114
 
pftn.c
_>17011701 NODE *
 17021702 typenode(NODE *p)
 17031703 {
<> 1704+        struct symtab *sp;
17041705         struct typctx tc;
 17051706         NODE *q;
<> 1707+        char *c;
17061708 
 17071709         memset(&tc, 0, sizeof(struct typctx));
 17081710 
     
 !
17181720                 if ((tc.cmplx && tc.imag) || tc.sig || tc.uns ||
 17191721                     !ISFTY(tc.type))
 17201722                         goto bad;
<>1721 -                if (tc.cmplx)
 1722 -                        tc.type += (FCOMPLEX-FLOAT);
 1723 -                else
  1723+                if (tc.cmplx) {
  1724+                        c = tc.type == DOUBLE ? "0d" :
  1725+                            tc.type == FLOAT ? "0f" : "0l";
  1726+                        sp = lookup(addname(c), 0);
  1727+                        tc.type = STRTY;
  1728+                        tc.saved = mkty(tc.type, sp->sdf, sp->ssue);
  1729+                        tc.saved->n_sp = sp;
  1730+                        tc.type = 0;
  1731+                } else
17241732                         tc.type += (FIMAG-FLOAT);
 17251733         }
 17261734 
     
 !
29963004 {
 29973005         return isinliningpermalloc(size) : tmpalloc(size);
 29983006 }
<_ 3007+
  3008+#ifndef NO_COMPLEX
  3009+
  3010+static char *real, *imag;
  3011+static struct symtab *cxsp[3];
  3012+/*
  3013+ * As complex numbers internally are handled as structs, create
  3014+ * these by hand-crafting them.
  3015+ */
  3016+void
  3017+complinit()
  3018+{
  3019+        struct rstack *rp;
  3020+        NODE *p, *q;
  3021+        char *n[] = { "0f", "0d", "0l" };
  3022+        int i, odebug;
  3023+
  3024+        odebug = ddebug;
  3025+        ddebug = 0;
  3026+        real = addname("__real");
  3027+        imag = addname("__imag");
  3028+        p = block(NAME, NIL, NIL, FLOAT, 0, MKSUE(FLOAT));
  3029+        for (i = 0; i < 3; i++) {
  3030+                p->n_type = FLOAT+i;
  3031+                p->n_sue = MKSUE(FLOAT+i);
  3032+                rp = bstruct(NULL, STNAME, NULL);
  3033+                soumemb(p, real, 0);
  3034+                soumemb(p, imag, 0);
  3035+                q = dclstruct(rp);
  3036+                cxsp[i] = q->n_sp = lookup(addname(n[i]), 0);
  3037+                defid(q, TYPEDEF);
  3038+                q->n_sp->ssue->suega = permalloc(sizeof(struct gcc_attr_pack) +
  3039+                    sizeof(struct gcc_attrib));
  3040+                q->n_sp->ssue->suega->num = 1;
  3041+                q->n_sp->ssue->suega->ga[0].atype = ATTR_COMPLEX;
  3042+                nfree(q);
  3043+        }
  3044+        nfree(p);
  3045+        ddebug = odebug;
  3046+}
  3047+
  3048+/*
  3049+ * Fixup complex operations.
  3050+ */
  3051+NODE *
  3052+cxop(int op, NODE *l, NODE *r)
  3053+{
  3054+        struct symtab s;
  3055+//      TWORD mxtyp = 0;
  3056+//      struct glaha f;
  3057+        NODE *p, *q;
  3058+        NODE *ltemp, *rtemp;
  3059+        NODE *real_l, *imag_l;
  3060+        NODE *real_r, *imag_r;
  3061+
  3062+#if 0
  3063+        mxtyp = maxcx(l, r);
  3064+        /* Enxure that both sides are complex */
  3065+#define ANYCX(p) (p->n_type == STRTY && gcc_get_attr(p->n_sue, ATTR_COMPLEX))
  3066+        if (!ANYCX(l)) {
  3067+                /* fixa plats p} stacken f|r en complex */
  3068+                oalloc(...);
  3069+                p1 = buildtree(CAST, TYPE(mxtyp), p2);
  3070+        }
  3071+        if (!ANYCX(r)) {
  3072+                /* fixa plats p} stacken f|r en complex */
  3073+                oalloc(...);
  3074+                p1 = buildtree(CAST, TYPE(mxtyp), p2);
  3075+        }
  3076+#endif
  3077+#define comop(x,y) buildtree(COMOP, x, y)
  3078+        /* put a pointer to left and right elements in a TEMP */
  3079+        l = buildtree(ADDROF, l, NIL);
  3080+        ltemp = tempnode(0, l->n_type, l->n_df, l->n_sue);
  3081+        l = buildtree(ASSIGN, ccopy(ltemp), l);
  3082+
  3083+        r = buildtree(ADDROF, r, NIL);
  3084+        rtemp = tempnode(0, r->n_type, r->n_df, r->n_sue);
  3085+        r = buildtree(ASSIGN, ccopy(rtemp), r);
  3086+
  3087+        p = comop(l, r);
  3088+
  3089+        /* create the four trees needed for calculation */
  3090+        real_l = structref(ccopy(ltemp), STREF, real);
  3091+//printf("real_l\n"); fwalk(real_l, eprint, 0);
  3092+        real_r = structref(ccopy(rtemp), STREF, real);
  3093+//printf("real_r\n"); fwalk(real_r, eprint, 0);
  3094+        imag_l = structref(ltemp, STREF, imag);
  3095+//printf("imag_l\n"); fwalk(imag_l, eprint, 0);
  3096+        imag_r = structref(rtemp, STREF, imag);
  3097+//printf("imag_r\n"); fwalk(imag_r, eprint, 0);
  3098+
  3099+        /* get storage on stack for the result */
  3100+        s = *cxsp[1];
  3101+        s.sclass = AUTO;
  3102+        s.soffset = NOOFFSET;
  3103+        oalloc(&s, &autooff);
  3104+        q = nametree(&s);
  3105+
  3106+        switch (op) {
  3107+        case PLUS:
  3108+        case MINUS:
  3109+                p = comop(p, buildtree(ASSIGN, structref(ccopy(q), DOT, real),
  3110+                    buildtree(op, real_l, real_r)));
  3111+                p = comop(p, buildtree(ASSIGN, structref(ccopy(q), DOT, imag),
  3112+                    buildtree(op, imag_l, imag_r)));
  3113+                break;
  3114+
  3115+        case MUL:
  3116+                /* Complex mul is "complex" */
  3117+                /* (u+iv)*(x*iy)=((u*x)-(v*y))+i(v*x+y*u) */
  3118+                p = comop(p, buildtree(ASSIGN, structref(ccopy(q), DOT, real),
  3119+                    buildtree(MINUS,
  3120+                    buildtree(MUL, ccopy(real_r), ccopy(real_l)),
  3121+                    buildtree(MUL, ccopy(imag_r), ccopy(imag_l)))));
  3122+                p = comop(p, buildtree(ASSIGN, structref(ccopy(q), DOT, imag),
  3123+                    buildtree(PLUS,
  3124+                    buildtree(MUL, real_r, imag_l),
  3125+                    buildtree(MUL, imag_r, real_l))));
  3126+                break;
  3127+
  3128+#if 0
  3129+        case DIV:
  3130+                ...
  3131+                break;
  3132+#endif
  3133+        }
  3134+        p = comop(p, q);
  3135+printf("XXX\n");
  3136+fwalk(p, eprint, 0);
  3137+printf("YYY\n");
  3138+return p;
  3139+}
  3140+
  3141+#endif
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-19 01:36 +0100