Make c0 allocate augmented struct (x)tname instead of struct tnode in nblock()
authorNick Downing <downing.nick@gmail.com>
Fri, 10 Feb 2017 10:09:41 +0000 (21:09 +1100)
committerNick Downing <downing.nick@gmail.com>
Fri, 10 Feb 2017 10:09:41 +0000 (21:09 +1100)
c01.c
c10.c
ccom.h

diff --git a/c01.c b/c01.c
index a5bc765..d29dca3 100644 (file)
--- a/c01.c
+++ b/c01.c
@@ -601,7 +601,49 @@ union tree *block(op, t, subs, str, p1,p2) int op; int t; int *subs; union str *
 }
 
 union tree *nblock(ds) register struct nmlist *ds; {
-       return(block(NAME, ds->htype, ds->hsubsp, ds->hstrp, (union tree *)ds, TNULL));
+ /*    return(block(NAME, ds->htype, ds->hsubsp, ds->hstrp, (union tree *)ds, TNULL));*/
+ /* XXX compatibility: */
+ /* formerly c0 would output a NAME node as follows: */
+ /*   hp = (struct nmlist *)tp->t.tr1; */
+ /*   if (hp->hclass==EXTERN) */
+ /*     outcode("BNNS", NAME, EXTERN, tp->t.type, hp->name); */
+ /*   else */
+ /*     outcode("BNNN", NAME, hp->hclass==0?STATIC:hp->hclass, tp->t.type, hp->hoffset); */
+ /* this would then be decoded by c1 as follows: */
+ /*   t = geti(); */
+ /*   if (t==EXTERN) { */
+ /*     tp = getblk(sizeof(struct xtname)); */
+ /*     tp->t.type = geti(); */
+ /*     outname(s); */
+ /*     tp->x.name = (char *)getblk(strlen(s) + 1); */
+ /*     strcpy(tp->x.name, s); */
+ /*   } else { */
+ /*     tp = getblk(sizeof(struct tname)); */
+ /*     tp->t.type = geti(); */
+ /*     tp->n.nloc = geti(); */
+ /*   } */
+ /*   tp->t.op = NAME; */
+ /*   tp->n.class = t; */
+ /*   tp->n.regno = 0; */
+ /*   tp->n.offset = 0; */
+       union tree *tp;
+       if (ds->hclass == EXTERN) {
+               tp = (union tree *)Tblock(sizeof(struct xtname));
+               tp->x.name = ds->name;
+       }
+       else {
+               tp = (union tree *)Tblock(sizeof(struct tname));
+               tp->n.nloc = ds->hoffset;
+       }
+       tp->n.op = NAME;
+       tp->n.type = ds->htype;
+       tp->n.subsp = ds->hsubsp;
+       tp->n.strp = ds->hstrp;
+       tp->n.tr1 = (union tree *)ds;
+       tp->n.class = ds->hclass==0?STATIC:ds->hclass;
+       tp->n.regno = 0;
+       tp->n.offset = 0;
+       return tp;
 }
 
 /*
diff --git a/c10.c b/c10.c
index 06c39c0..35beb6f 100644 (file)
--- a/c10.c
+++ b/c10.c
@@ -30,8 +30,7 @@ char  notrel[] = {    NEQUAL, EQUAL, GREAT, GREATEQ, LESS,
 struct tconst czero = { CON, INT, 0/*subsp*/, 0/*strp*/, 0};
 struct tconst cone  = { CON, INT, 0/*subsp*/, 0/*strp*/, 1};
 
-struct tname sfuncr = { NAME, STRUCT, STATIC, 0, 0, 0 };
-
+struct tname sfuncr = { NAME, STRUCT, 0/*subsp*/, 0/*strp*/, 0/*tr1*/, STATIC, 0, 0, 0 }; 
 struct table   *cregtab;
 
 int    nreg    = 3;
diff --git a/ccom.h b/ccom.h
index f6ef2b5..1d012ab 100644 (file)
--- a/ccom.h
+++ b/ccom.h
@@ -33,33 +33,39 @@ struct      tnode {
        int     type;
        int     *subsp;         /* subscript list for arrays; pass 0 only */
        union   str *strp;      /* structure descr for structs; pass 0 only */
-       int     degree;         /* pass 1 only */
        union   tree *tr1;
        union   tree *tr2;
+       int     degree;         /* pass 1 only */
 };
 
 /*
- * tree1 names for locals
+ * tree names for locals
  */
 struct tname {
        int     op;
        int     type;
-       char    class;
-       char    regno;
-       int     offset;
-       int     nloc;
+       int     *subsp;         /* subscript list for arrays; pass 0 only */
+       union   str *strp;      /* structure descr for structs; pass 0 only */
+       union   tree *tr1;      /* really struct nmlist pointer; pass 0 only */
+       char    class;          /* pass 1 only */
+       char    regno;          /* pass 1 only */
+       int     offset;         /* pass 1 only */
+       int     nloc;           /* pass 1 only */
 };
 
 /*
- * tree1 names for externals
+ * tree names for externals
  */
 struct xtname {
        int     op;
        int     type;
-       char    class;
-       char    regno;
-       int     offset;
-       char    *name;
+       int     *subsp;         /* subscript list for arrays; pass 0 only */
+       union   str *strp;      /* structure descr for structs; pass 0 only */
+       union   tree *tr1;      /* really struct nmlist pointer; pass 0 only */
+       char    class;          /* pass 1 only */
+       char    regno;          /* pass 1 only */
+       int     offset;         /* pass 1 only */
+       char    *name;          /* pass 1 only */
 };
 
 /*
@@ -105,9 +111,9 @@ struct      fasgn {
        int     type;
        int     *subsp;         /* subscript list for arrays; pass 0 only */
        union   str *strp;      /* structure descr for structs; pass 0 only */
-       int     degree;         /* pass 1 only */
        union   tree *tr1;
        union   tree *tr2;
+       int     degree;         /* pass 1 only */
        int     mask;
 };