Start to unify union tree0 with union tree1 (change cnode to tconst0 and so on)
authorNick Downing <downing.nick@gmail.com>
Fri, 10 Feb 2017 09:08:09 +0000 (20:08 +1100)
committerNick Downing <downing.nick@gmail.com>
Fri, 10 Feb 2017 09:33:33 +0000 (20:33 +1100)
c0.h
c00.c
c01.c
c04.c
c1.h
c10.c
c11.c
c12.c
uniqify0.sed
uniqify1.sed

diff --git a/c0.h b/c0.h
index b48839b..497f36b 100644 (file)
--- a/c0.h
+++ b/c0.h
@@ -107,30 +107,30 @@ struct tnode0 {
 /*
  * Tree node for constants
  */
-struct cnode {
+struct tconst0 {
        int     op;
        int     type;
        int     *subsp;
        union   str *strp;
-       int     value;
+       _INT    value;
 };
 
 /*
  * Tree node for long constants
  */
-struct lnode {
+struct lconst0 {
        int     op;
        int     type;
        int     *subsp;
        union   str *strp;
-       long    lvalue;
+       _LONG   lvalue;
 };
 
 /*
  * tree0 node for floating
  * constants
  */
-struct fnode {
+struct ftconst0 {
        int     op;
        int     type;
        int     *subsp;
@@ -143,11 +143,15 @@ struct    fnode {
  */
 union tree0 {
        struct  tnode0 t;
-       struct  cnode c;
-       struct  lnode l;
-       struct  fnode f;
-       struct  nmlist n;
-       struct  FS fld;
+       struct  tconst0 c;
+       struct  lconst0 l;
+       struct  ftconst0 f;
+ /*    struct  nmlist n;*/
+ /* n occurs as tr1 of a NAME node, points into symbol table */
+ /* we will just cast tr1 to "struct nmlist *" in that particular case */
+ /*    struct  FS fld;*/
+ /* fld occurs as tr2 of an FSEL node, points into structure description */
+ /* we will just cast tr2 to "struct FS *" in that particular case */
 };
 
 
@@ -310,7 +314,7 @@ char *copnum __P((int len));
 
 /* c01.c */
 void build __P((int op));
-union tree0 *structident __P((register union tree0 *p1, register union tree0 *p2));
+void structident __P((register union tree0 *p1, register union tree0 *p2));
 union tree0 *convert __P((union tree0 *p, int t, int cvn, int len));
 void setype __P((register union tree0 *p, register int t, register union tree0 *newp));
 union tree0 *chkfun __P((register union tree0 *p));
diff --git a/c00.c b/c00.c
index 09d3c3e..7d51cb1 100644 (file)
--- a/c00.c
+++ b/c00.c
@@ -620,7 +620,7 @@ union tree0 *tree0(/*eflag*/) /*int eflag;*/ {
        register struct nmlist *cs;
        int p, ps, os, xo = 0, *xop;
        /*char *svtree;*/
-       static struct cnode garbage = { CON, INT, (int *)NULL, (union str *)NULL, 0 };
+       static struct tconst0 garbage = { CON, INT, (int *)NULL, (union str *)NULL, 0 };
 
        /*svtree = starttree();*/
        op = opst;
@@ -658,7 +658,7 @@ advanc:
                goto tand;
 
        case LCON:
-               *cp0 = (union tree0 *)Tblock(sizeof(struct lnode));
+               *cp0 = (union tree0 *)Tblock(sizeof(struct lconst0));
                (*cp0)->l.op = LCON;
                (*cp0)->l.type = LONG;
                (*cp0)->l.lvalue = lcval;
diff --git a/c01.c b/c01.c
index aba6a32..6defe60 100644 (file)
--- a/c01.c
+++ b/c01.c
@@ -180,28 +180,28 @@ void build(op) int op; {
         * then * is tacked on to access the member.
         */
        case ARROW:
-               if (p2->t.op!=NAME || p2->t.tr1->n.hclass!=MOS) {
+               if (p2->t.op!=NAME || ((struct nmlist *)p2->t.tr1)->hclass!=MOS) {
                        error0("Illegal structure ref");
                        *cp0++ = p1;
                        return;
                }
-               p2 = structident(p1, p2);
-               t2 = p2->n.htype;
-               if (t2==INT && p2->t.tr1->n.hflag&FFIELD)
+               structident(p1, p2);
+               t2 = p2->t.type;
+               if (t2==INT && ((struct nmlist *)p2->t.tr1)->hflag&FFIELD)
                        t2 = UNSIGN;
                t = incref0(t2);
                chkw(p1, -1);
                setype(p1, t, p2);
                *cp0++ = block(PLUS, t, p2->t.subsp, p2->t.strp,
-                  p1, cblock(p2->t.tr1->n.hoffset));
+                  p1, cblock(((struct nmlist *)p2->t.tr1)->hoffset));
                build(STAR);
-               if (p2->t.tr1->n.hflag&FFIELD)
+               if (((struct nmlist *)p2->t.tr1)->hflag&FFIELD)
 #if 1
                        cp0[-1] = block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL, 
-                           cp0[-1], (union tree0 *)p2->t.tr1->n.hstrp);
+                           cp0[-1], (union tree0 *)((struct nmlist *)p2->t.tr1)->hstrp);
 #else
                        *cp0++ = block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL, 
-                           *--cp0, (union tree0 *)p2->t.tr1->n.hstrp);
+                           *--cp0, (union tree0 *)((struct nmlist *)p2->t.tr1)->hstrp);
 #endif
                return;
        }
@@ -386,37 +386,36 @@ void build(op) int op; {
        }
 }
 
-union tree0 *structident(p1, p2) register union tree0 *p1; register union tree0 *p2; {
-       register struct nmlist *np;
+void structident(p1, p2) register union tree0 *p1; register union tree0 *p2; {
+       register struct nmlist *np, *nporig;
        int vartypes = 0, namesame = 1;
 
-       np = (struct nmlist *)p2->t.tr1;
+       np = nporig = (struct nmlist *)p2->t.tr1;
        for (;;) {
                if (namesame && p1->t.type==STRUCT+PTR && p1->t.strp == np->sparent) {
                        p2->t.type = np->htype;
                        p2->t.strp = np->hstrp;
                        p2->t.subsp = np->hsubsp;
                        p2->t.tr1 = (union tree0 *)np;
-                       return(p2);
+                       return;
                }
                np = np->nextnm;
                if (np==NULL)
                        break;
                namesame = 0;
-               if (strcmp(p2->t.tr1->n.name, np->name) != 0)
+               if (strcmp(nporig->name, np->name) != 0)
                        continue;
-               if ((p2->t.tr1->n.hflag&FKIND) != (np->hflag&FMOS))
+               if ((nporig->hflag&FKIND) != (np->hflag&FMOS))
                        continue;
                namesame = 1;
-               if (p2->t.tr1->n.htype==np->htype && p2->t.tr1->n.hoffset==np->hoffset)
+               if (nporig->htype==np->htype && nporig->hoffset==np->hoffset)
                        continue;
                vartypes++;
        }
        if (vartypes)
-               error0("Ambiguous structure reference for %s",p2->t.tr1->n.name);
+               error0("Ambiguous structure reference for %s",nporig->name);
        else
-               werror0("%s not member of cited struct/union",p2->t.tr1->n.name);
-       return(p2);
+               werror0("%s not member of cited struct/union",nporig->name);
 }
 
 /*
@@ -480,7 +479,7 @@ union tree0 *disarray(p) register union tree0 *p; {
                return(p);
        /* check array & not MOS and not typer */
        if (((t = p->t.type)&XTYPE)!=ARRAY
-        || p->t.op==NAME && p->t.tr1->n.hclass==MOS
+        || p->t.op==NAME && ((struct nmlist *)p->t.tr1)->hclass==MOS
         || p->t.op==ETYPE)
                return(p);
        p->t.subsp++;
@@ -612,7 +611,7 @@ union tree0 *cblock(v) int v; {
        register union tree0 *p;
 
  /*fprintf(stderr, "cblock(0%06o)\n", v & 0177777);*/
-       p = (union tree0 *)Tblock(sizeof(struct cnode));
+       p = (union tree0 *)Tblock(sizeof(struct tconst0));
        p->c.op = CON;
        p->c.type = INT;
        p->c.subsp = NULL;
@@ -628,7 +627,7 @@ union tree0 *fblock(t, string) int t; char *string; {
        register union tree0 *p;
 
  /*fprintf(stderr, "fblock(%d, \"%s\")\n", t, string);*/
-       p = (union tree0 *)Tblock(sizeof(struct fnode));
+       p = (union tree0 *)Tblock(sizeof(struct ftconst0));
        p->f.op = FCON;
        p->f.type = t;
        p->f.subsp = NULL;
diff --git a/c04.c b/c04.c
index 0fb5853..a36b23a 100644 (file)
--- a/c04.c
+++ b/c04.c
@@ -73,7 +73,7 @@ void treeout(tp, isstruct) register union tree0 *tp; int isstruct; {
        switch(tp->t.op) {
 
        case NAME:
-               hp = &tp->t.tr1->n;
+               hp = (struct nmlist *)tp->t.tr1;
                if (hp->hclass==TYPEDEF)
                        error0("Illegal use of type name");
 #if 1
@@ -110,7 +110,7 @@ void treeout(tp, isstruct) register union tree0 *tp; int isstruct; {
        case FSEL:
                treeout(tp->t.tr1, nextisstruct);
                outcode("BNNN", tp->t.op, tp->t.type,
-                  tp->t.tr2->fld.bitoffs, tp->t.tr2->fld.flen);
+                  ((struct FS *)tp->t.tr2)->bitoffs, ((struct FS *)tp->t.tr2)->flen);
                break;
 
        case ETYPE:
diff --git a/c1.h b/c1.h
index 1c14e7c..9230d57 100644 (file)
--- a/c1.h
+++ b/c1.h
@@ -52,7 +52,7 @@ struct        xtname {
 /*
  * short constants
  */
-struct tconst {
+struct tconst1 {
        int     op;
        int     type;
        _INT    value;
@@ -61,7 +61,7 @@ struct        tconst {
 /*
  * long constants
  */
-struct lconst {
+struct lconst1 {
        int     op;
        int     type;
        _LONG   lvalue;
@@ -70,7 +70,7 @@ struct        lconst {
 /*
  * Floating constants
  */
-struct ftconst {
+struct ftconst1 {
        int     op;
        int     type;
        int     value;
@@ -93,9 +93,9 @@ union tree1 {
        struct  tnode1 t;
        struct tname n;
        struct  xtname x;
-       struct  tconst c;
-       struct  lconst l;
-       struct  ftconst f;
+       struct  tconst1 c;
+       struct  lconst1 l;
+       struct  ftconst1 f;
        struct  fasgn F;
 };
 
@@ -194,7 +194,7 @@ extern struct tname sfuncr;
 extern char *funcbase;
 extern char *curbase;
 extern char *coremax;
-extern struct tconst czero, cone;
+extern struct tconst1 czero, cone;
 extern long totspace;
 extern int regpanic;           /* set when SU register alg. fails */
 extern int panicposs;          /* set when there might be need for regpanic */
@@ -211,9 +211,9 @@ extern union tree1 *ncopy();
 extern union tree1 *getblk();
 extern union tree1 *strfunc();
 extern union tree1 *isconstant();
-extern union tree1 *tconst();
+extern union tree1 *tconst1();
 extern union tree1 *hardlongs();
-extern union tree1 *lconst();
+extern union tree1 *lconst1();
 extern union tree1 *acommute();
 extern union tree1 *lvfield();
 extern union tree1 *paint();
@@ -300,10 +300,10 @@ int sideeffects __P((register union tree1 *tp));
 void distrib __P((struct acl *list));
 void squash __P((union tree1 **p, union tree1 **maxp));
 void _const __P((int op, register _INT *vp, _INT v, int type));
-union tree1 *lconst __P((int op, register union tree1 *lp, register union tree1 *rp));
+union tree1 *lconst1 __P((int op, register union tree1 *lp, register union tree1 *rp));
 void insert __P((int op, register union tree1 *tree1, register struct acl *list));
 union tree1 *tnode1 __P((int op, int type, union tree1 *tr1, union tree1 *tr2));
-union tree1 *tconst __P((int val, int type));
+union tree1 *tconst1 __P((int val, int type));
 union tree1 *getblk __P((int size));
 int islong __P((int t));
 union tree1 *isconstant __P((register union tree1 *t));
diff --git a/c10.c b/c10.c
index 8ce4976..cdd52cd 100644 (file)
--- a/c10.c
+++ b/c10.c
@@ -27,8 +27,8 @@ char  notrel[] = {    NEQUAL, EQUAL, GREAT, GREATEQ, LESS,
                        LESSEQ, GREATP, GREATQP, LESSP, LESSEQP
 };
 
-struct tconst czero = { CON, INT, 0};
-struct tconst cone  = { CON, INT, 1};
+struct tconst1 czero = { CON, INT, 0};
+struct tconst1 cone  = { CON, INT, 1};
 
 struct tname sfuncr = { NAME, STRUCT, STATIC, 0, 0, 0 };
 
@@ -1192,7 +1192,7 @@ int comarg(tree1, flagp) register union tree1 *tree1; int *flagp; {
                        return(0);
                }
                tree1 = tnode1(AMPER, STRUCT+PTR, tree1, TNULL1);
-               tree1 = tnode1(PLUS, STRUCT+PTR, tree1, tconst(size, INT));
+               tree1 = tnode1(PLUS, STRUCT+PTR, tree1, tconst1(size, INT));
                tree1 = optim(tree1);
                retval = rcexpr1(tree1, regtab, 0);
                size >>= 1;
diff --git a/c11.c b/c11.c
index d6a6da3..e25474d 100644 (file)
--- a/c11.c
+++ b/c11.c
@@ -1013,7 +1013,7 @@ void outcode(fmt, va_alist) char *fmt; va_dcl
 
        case CON:
                t = va_arg(argp, int) /*geti()*/;
-               *sp++ = tconst(va_arg(argp, int) /*geti()*/, t);
+               *sp++ = tconst1(va_arg(argp, int) /*geti()*/, t);
                break;
 
        case LCON:
@@ -1021,10 +1021,10 @@ void outcode(fmt, va_alist) char *fmt; va_dcl
                t = va_arg(argp, int) /*geti()*/;
                op = va_arg(argp, int) /*geti()*/;
                if (t==0 && op>=0 || t == -1 && op<0) {
-                       *sp++ = tnode1(ITOL, LONG, tconst(op, INT), TNULL1);
+                       *sp++ = tnode1(ITOL, LONG, tconst1(op, INT), TNULL1);
                        break;
                }
-               tp = getblk(sizeof(struct lconst));
+               tp = getblk(sizeof(struct lconst1));
                tp->t.op = LCON;
                tp->t.type = LONG;
                tp->l.lvalue = ((_LONG)t<<16) + UNS(op); /* nonportable */
@@ -1034,7 +1034,7 @@ void outcode(fmt, va_alist) char *fmt; va_dcl
        case FCON:
                t = va_arg(argp, int) /*geti()*/;
                outname(s/*)*/, va_arg(argp, char *));
-               tp = getblk(sizeof(struct ftconst));
+               tp = getblk(sizeof(struct ftconst1));
                tp->t.op = FCON;
                tp->t.type = t;
                tp->f.value = isn1++;
@@ -1049,7 +1049,7 @@ void outcode(fmt, va_alist) char *fmt; va_dcl
        case FSEL:
                tp = tnode1(FSEL, va_arg(argp, int) /*geti()*/, *--sp, TNULL1);
                t = va_arg(argp, int) /*geti()*/;
-               tp->t.tr2 = tnode1(COMMA, INT, tconst(va_arg(argp, int) /*geti()*/, INT), tconst(t, INT));
+               tp->t.tr2 = tnode1(COMMA, INT, tconst1(va_arg(argp, int) /*geti()*/, INT), tconst1(t, INT));
                if (tp->t.tr2->t.tr1->c.value==16)
                        tp = paint(tp->t.tr1, tp->t.type);
                *sp++ = tp;
diff --git a/c12.c b/c12.c
index f57613c..520eb8b 100644 (file)
--- a/c12.c
+++ b/c12.c
@@ -137,7 +137,7 @@ union tree1 *optim(tree1) register union tree1 *tree1; {
        tree1->t.tr1 = optim(tree1->t.tr1);
        tree1->t.tr2 = optim(tree1->t.tr2);
        if (tree1->t.type == LONG || tree1->t.type==UNLONG) {
-               t = lconst(tree1->t.op, tree1->t.tr1, tree1->t.tr2);
+               t = lconst1(tree1->t.op, tree1->t.tr1, tree1->t.tr2);
                if (t)
                        return(t);
        }
@@ -332,7 +332,7 @@ union tree1 *unoptim(tree1) register union tree1 *tree1; {
 
        case ITOL:
                if (subtre->t.op==CON && subtre->t.type==INT && subtre->c.value<0) {
-                       subtre = getblk(sizeof(struct lconst));
+                       subtre = getblk(sizeof(struct lconst1));
                        subtre->t.op = LCON;
                        subtre->t.type = LONG;
                        subtre->l.lvalue = tree1->t.tr1->c.value;
@@ -350,7 +350,7 @@ union tree1 *unoptim(tree1) register union tree1 *tree1; {
 
        case LTOF:
                if (subtre->t.op==LCON) {
-                       tree1 = getblk(sizeof(struct ftconst));
+                       tree1 = getblk(sizeof(struct ftconst1));
                        tree1->t.op = FCON;
                        tree1->t.type = DOUBLE;
                        tree1->f/*c*/.value = isn1++;
@@ -367,7 +367,7 @@ union tree1 *unoptim(tree1) register union tree1 *tree1; {
 
        case ITOF:
                if (subtre->t.op==CON) {
-                       tree1 = getblk(sizeof(struct ftconst));
+                       tree1 = getblk(sizeof(struct ftconst1));
                        tree1->t.op = FCON;
                        tree1->t.type = DOUBLE;
                        tree1->f.value = isn1++;
@@ -425,7 +425,7 @@ union tree1 *unoptim(tree1) register union tree1 *tree1; {
                case STAR:
                        subtre->t.type = tree1->t.type;
                        subtre->t.tr1->t.type = tree1->t.type+PTR;
-                       subtre->t.tr1 = tnode1(PLUS, tree1->t.type, subtre->t.tr1, tconst(2, INT));
+                       subtre->t.tr1 = tnode1(PLUS, tree1->t.type, subtre->t.tr1, tconst1(2, INT));
                        return(optim(subtre));
 
                case ITOL:
@@ -553,7 +553,7 @@ union tree1 *unoptim(tree1) register union tree1 *tree1; {
                }
                if (subtre->t.op==ITOL) {
                        if (subtre->t.tr1->t.op==CON) {
-                               tree1 = getblk(sizeof(struct lconst));
+                               tree1 = getblk(sizeof(struct lconst1));
                                tree1->t.op = LCON;
                                tree1->t.type = LONG;
                                if (uns(subtre->t.tr1))
@@ -587,7 +587,7 @@ union tree1 *unoptim(tree1) register union tree1 *tree1; {
                        return(subtre);
                }
                if (subtre->t.op==ITOL && subtre->t.tr1->t.op==CON) {
-                       tree1 = getblk(sizeof(struct lconst));
+                       tree1 = getblk(sizeof(struct lconst1));
                        tree1->t.op = LCON;
                        tree1->t.type = LONG;
                        if (uns(subtre->t.tr1))
@@ -663,8 +663,8 @@ union tree1 *lvfield(t) register union tree1 *t; {
                t1->t.tr1 = t->t.tr2;
                t->t.tr2 = t1;
                t1 = t1->t.tr2;
-               t1 = tnode1(COMMA, INT, tconst(t1->t.tr1->c.value, INT),
-                       tconst(t1->t.tr2->c.value, INT));
+               t1 = tnode1(COMMA, INT, tconst1(t1->t.tr1->c.value, INT),
+                       tconst1(t1->t.tr2->c.value, INT));
                return(optim(tnode1(FSELT, UNSIGN, t, t1)));
 
        }
@@ -705,7 +705,7 @@ union tree1 *acommute(tree1) register union tree1 *tree1; {
                                t2--;
                                _const(op, &t2[0]->c.value, t2[1]->c.value, d);
                                t2[0]->t.type = d;
-                       } else if (t = lconst(op, t2[-1], t2[0])) {
+                       } else if (t = lconst1(op, t2[-1], t2[0])) {
                                acl.nextl--;
                                t2--;
                                t2[0] = t;
@@ -993,7 +993,7 @@ void _const(op, vp, v, type) int op; register _INT *vp; register _INT v; int typ
        error1("C error1: const");
 }
 
-union tree1 *lconst(op, lp, rp) int op; register union tree1 *lp; register union tree1 *rp; {
+union tree1 *lconst1(op, lp, rp) int op; register union tree1 *lp; register union tree1 *rp; {
        _UNSIGNED_LONG l, r;
 
        if (lp->t.op==LCON)
@@ -1076,7 +1076,7 @@ union tree1 *lconst(op, lp, rp) int op; register union tree1 *lp; register union
                lp->l.lvalue = l;
                return(lp);
        }
-       lp = getblk(sizeof(struct lconst));
+       lp = getblk(sizeof(struct lconst1));
        lp->t.op = LCON;
        lp->t.type = LONG;
        lp->l.lvalue = l;
@@ -1139,10 +1139,10 @@ union tree1 *tnode1(op, type, tr1, tr2) int op; int type; union tree1 *tr1; unio
        return(p);
 }
 
-union tree1 *tconst(val, type) int val; int type; {
+union tree1 *tconst1(val, type) int val; int type; {
        register union tree1 *p;
 
-       p = getblk(sizeof(struct tconst));
+       p = getblk(sizeof(struct tconst1));
        p->t.op = CON;
        p->t.type = type;
        p->c.value = val;
index 5ce857f..fbfbb3b 100644 (file)
@@ -20,6 +20,11 @@ s/@cp@/@cp0@/g
 s/@tree@/@tree0@/g
 s/@xprtype@/@xprtype0@/g
 s/@TNULL@/@TNULL0@/g
+s/@cnode@/@tconst0@/g
+s/@lnode@/@lconst0@/g
+s/@fnode@/@ftconst0@/g
+
+
 
 s/@//g
 s/ATSIGN/@/g
index 1aa5704..de7c3af 100644 (file)
@@ -20,6 +20,9 @@ s/@cp@/@cp1@/g
 s/@tree@/@tree1@/g
 s/@xprtype@/@xprtype1@/g
 s/@TNULL@/@TNULL1@/g
+s/@tconst@/@tconst1@/g
+s/@lconst@/@lconst1@/g
+s/@ftconst@/@ftconst1@/g
 
 s/@//g
 s/ATSIGN/@/g