[prev in list] [next in list] [prev in thread] [next in thread]
List: pcc-list
Subject: Re: Extended bcon
From: Anders Magnusson <ragge () ludd ! ltu ! se>
Date: 2007-12-24 19:53:32
Message-ID: 200712241953.lBOJrWs0009216 () mother ! ludd ! ltu ! se
[Download RAW message or body]
>
> Hi,
>
> there are a few places that use something like
>
> p = block(ICON, ...); p->n_lval = v; p->n_sp = sp;
>
> or
>
> p = bcon(); p->n_lval = v; p->n_sp = sp;
>
> to construct ICON nodes.
>
> The diff introduces a function xbcon() that does that.
>
Good, simplifies code and avoids confusion.
bcon() should do integer propagation, but that's a larger task.
Also, the places that looks like
> - p = bcon(0);
> - p->n_lval = off/SZCHAR; /* Default */
> - return(p);
> + return xbcon(off/SZCHAR, NULL, INT); /* Default */
should call bcon(), not xbcon().
-- Ragge
> Index: arch/hppa/local.c
> ===================================================================
> RCS file: /cvsroot/pcc/arch/hppa/local.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 local.c
> --- arch/hppa/local.c 14 Dec 2007 17:57:47 -0000 1.11
> +++ arch/hppa/local.c 23 Dec 2007 23:23:33 -0000
> @@ -117,9 +117,7 @@ clocal(NODE *p)
> l->n_lval = 0;
> l->n_rval = R1;
> l = block(ASSIGN, l, p, INT, 0, 0);
> - r = block(ICON, NIL, NIL, INT, 0, 0);
> - r->n_sp = p->n_sp;
> - r->n_lval = 0;
> + r = xbcon(0, p->n_sp, INT);
> p = block(UMUL,
> block(PLUS, l, r, INT, 0, 0),
> NIL, p->n_type, p->n_df, p->n_sue);
> @@ -135,9 +133,7 @@ clocal(NODE *p)
> l->n_lval = 0;
> l->n_rval = R1;
> l = block(ASSIGN, l, p->n_left, INT, 0, 0);
> - r = block(ICON, NIL, NIL, INT, 0, 0);
> - r->n_sp = p->n_left->n_sp;
> - r->n_lval = 0;
> + r = xbcon(0, p->n_left->n_sp, INT);
> l = block(PLUS, l, r, p->n_type, p->n_df, p->n_sue);
> nfree(p);
> p = l;
> @@ -472,15 +468,11 @@ cisreg(TWORD t)
> NODE *
> offcon(OFFSZ off, TWORD t, union dimfun *d, struct suedef *sue)
> {
> - register NODE *p;
> -
> if (xdebug)
> printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
> off, t, d, sue->suesize);
>
> - p = bcon(0);
> - p->n_lval = off/SZCHAR; /* Default */
> - return(p);
> + return xbcon(off/SZCHAR, NULL, INT); /* Default */
> }
>
> /*
> Index: arch/i386/local.c
> ===================================================================
> RCS file: /cvsroot/pcc/arch/i386/local.c,v
> retrieving revision 1.65
> diff -u -p -r1.65 local.c
> --- arch/i386/local.c 9 Dec 2007 18:00:57 -0000 1.65
> +++ arch/i386/local.c 23 Dec 2007 23:23:33 -0000
> @@ -84,10 +84,11 @@ static NODE *
> picext(NODE *p)
> {
> NODE *q, *r;
> + struct symtab *sp;
>
> q = tempnode(gotnr, PTR|VOID, 0, MKSUE(VOID));
> - r = bcon(0);
> - r->n_sp = picsymtab(gcc_findname(p->n_sp), "@GOT");
> + sp = picsymtab(gcc_findname(p->n_sp), "@GOT");
> + r = xbcon(0, sp, INT);
> q = buildtree(PLUS, q, r);
> q = block(UMUL, q, 0, PTR|VOID, 0, MKSUE(VOID));
> q = block(UMUL, q, 0, p->n_type, p->n_df, p->n_sue);
> @@ -103,17 +104,18 @@ static NODE *
> picstatic(NODE *p)
> {
> NODE *q, *r;
> + struct symtab *sp;
>
> q = tempnode(gotnr, PTR|VOID, 0, MKSUE(VOID));
> - r = bcon(0);
> if (p->n_sp->slevel > 0 || p->n_sp->sclass == ILABEL) {
> char buf[32];
> snprintf(buf, 32, LABFMT, (int)p->n_sp->soffset);
> - r->n_sp = picsymtab(buf, "@GOTOFF");
> + sp = picsymtab(buf, "@GOTOFF");
> } else
> - r->n_sp = picsymtab(gcc_findname(p->n_sp), "@GOTOFF");
> - r->n_sp->sclass = STATIC;
> - r->n_sp->stype = p->n_sp->stype;
> + sp = picsymtab(gcc_findname(p->n_sp), "@GOTOFF");
> + sp->sclass = STATIC;
> + sp->stype = p->n_sp->stype;
> + r = xbcon(0, sp, INT);
> q = buildtree(PLUS, q, r);
> q = block(UMUL, q, 0, p->n_type, p->n_df, p->n_sue);
> q->n_sp = p->n_sp; /* for init */
> @@ -538,15 +540,11 @@ cisreg(TWORD t)
> NODE *
> offcon(OFFSZ off, TWORD t, union dimfun *d, struct suedef *sue)
> {
> - register NODE *p;
> -
> if (xdebug)
> printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
> off, t, d, sue->suesize);
>
> - p = bcon(0);
> - p->n_lval = off/SZCHAR; /* Default */
> - return(p);
> + return xbcon(off/SZCHAR, NULL, INT);
> }
>
> /*
> Index: arch/m16c/local.c
> ===================================================================
> RCS file: /cvsroot/pcc/arch/m16c/local.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 local.c
> --- arch/m16c/local.c 6 Feb 2006 09:33:09 -0000 1.11
> +++ arch/m16c/local.c 23 Dec 2007 23:23:33 -0000
> @@ -198,15 +198,11 @@ cisreg(TWORD t)
> NODE *
> offcon(OFFSZ off, TWORD t, union dimfun *d, struct suedef *sue)
> {
> - register NODE *p;
> -
> if (xdebug)
> printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
> off, t, d, sue->suesize);
>
> - p = bcon(0);
> - p->n_lval = off/SZCHAR; /* Default */
> - return(p);
> + return xbcon(off/SZCHAR, NULL, INT); /* Default */
> }
>
> /*
> Index: arch/nova/local.c
> ===================================================================
> RCS file: /cvsroot/pcc/arch/nova/local.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 local.c
> --- arch/nova/local.c 18 Nov 2007 17:28:36 -0000 1.2
> +++ arch/nova/local.c 23 Dec 2007 23:23:34 -0000
> @@ -386,8 +386,7 @@ offcon(OFFSZ off, TWORD t, union dimfun
> printf("offcon: OFFSZ %ld type %x dim %p siz %d\n",
> off, t, d, sue->suesize);
>
> - p = bcon(0);
> - p->n_lval = off/SZINT; /* Default */
> + p = xbcon(off/SZINT, NULL, INT); /* Default */
> if (ISPTR(DECREF(t)))
> return p;
> if (t == VOID || t == CHAR || t == UCHAR)
> Index: arch/pdp10/local.c
> ===================================================================
> RCS file: /cvsroot/pcc/arch/pdp10/local.c,v
> retrieving revision 1.65
> diff -u -p -r1.65 local.c
> --- arch/pdp10/local.c 18 Nov 2007 17:28:36 -0000 1.65
> +++ arch/pdp10/local.c 23 Dec 2007 23:23:34 -0000
> @@ -225,11 +225,9 @@ rmpc: l->n_type = p->n_type;
> if (o != FCON)
> break;
> ml = ISUNSIGNED(m) ? UNSIGNED : INT; /* LONG? */
> - r = block(ICON, (NODE *)NULL, (NODE *)NULL, ml, 0, 0);
> - r->n_lval = ml == INT ?
> - (int) p->n_left->n_dcon :
> - (unsigned) p->n_left->n_dcon;
> - r->n_sp = NULL;
> + r = xbcon(ml == INT ? (int)p->n_left->n_dcon :
> + (unsigned)p->n_left->n_dcon,
> + NULL, ml);
> nfree(p->n_left);
> p->n_left = r;
> o = ICON;
> @@ -352,8 +350,7 @@ rmpc: l->n_type = p->n_type;
> /* Size block */
> r = block(CM, l, bcon(siz), INT, 0, MKSUE(INT));
>
> - l = block(ICON, NIL, NIL, q->stype, 0, MKSUE(INT));
> - l->n_sp = q;
> + l = xbcon(0, q, q->stype);
> p->n_left = l;
> p->n_right = r;
> p->n_op = CALL;
> @@ -383,25 +380,19 @@ myp2tree(NODE *p)
> case UGT:
> case UGE:
> if (ISLONGLONG(p->n_left->n_type)) {
> - r = block(ICON, NIL, NIL, LONGLONG, 0, MKSUE(LONGLONG));
> - r->n_lval = 0x8000000000000000ULL; /* XXX */
> - } else {
> - r = block(ICON, NIL, NIL, INT, 0, MKSUE(INT));
> - r->n_lval = 0400000000000LL;
> - }
> - r->n_sp = NULL;
> + /* XXX */
> + r = xbcon(0x8000000000000000ULL, NULL, LONGLONG);
> + } else
> + r = xbcon(0400000000000LL, NULL, INT);
> p->n_left = buildtree(ER, p->n_left, r);
> if (ISUNSIGNED(p->n_left->n_type))
> p->n_left->n_type = DEUNSIGN(p->n_left->n_type);
>
> if (ISLONGLONG(p->n_right->n_type)) {
> - r = block(ICON, NIL, NIL, LONGLONG, 0, MKSUE(LONGLONG));
> - r->n_lval = 0x8000000000000000ULL; /* XXX */
> - } else {
> - r = block(ICON, NIL, NIL, INT, 0, MKSUE(INT));
> - r->n_lval = 0400000000000LL;
> - }
> - r->n_sp = NULL;
> + /* XXX */
> + r = xbcon(0x8000000000000000ULL, NULL, LONGLONG);
> + } else
> + r = xbcon(0400000000000LL, NULL, INT);
> p->n_right = buildtree(ER, p->n_right, r);
> if (ISUNSIGNED(p->n_right->n_type))
> p->n_right->n_type = DEUNSIGN(p->n_right->n_type);
> @@ -544,8 +535,7 @@ offcon(OFFSZ off, TWORD t, union dimfun
> printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
> off, t, d, sue->suesize);
>
> - p = bcon(0);
> - p->n_lval = off/SZINT; /* Default */
> + p = xbcon(off/SZINT, NULL, INT); /* Default */
> if (ISPTR(DECREF(t)))
> return p; /* Pointer/pointer reference */
> switch (BTMASK & t) {
> Index: arch/powerpc/local.c
> ===================================================================
> RCS file: /cvsroot/pcc/arch/powerpc/local.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 local.c
> --- arch/powerpc/local.c 22 Nov 2007 17:00:19 -0000 1.5
> +++ arch/powerpc/local.c 23 Dec 2007 23:23:34 -0000
> @@ -564,17 +564,13 @@ cisreg(TWORD t)
> NODE *
> offcon(OFFSZ off, TWORD t, union dimfun *d, struct suedef *sue)
> {
> - register NODE *p;
> -
> #ifdef PCC_DEBUG
> if (xdebug)
> printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
> off, t, d, sue->suesize);
> #endif
>
> - p = bcon(0);
> - p->n_lval = off/SZCHAR; /* Default */
> - return(p);
> + return xbcon(off/SZCHAR, NULL, NULL, INT); /* Default */
> }
>
> /*
> Index: arch/vax/local.c
> ===================================================================
> RCS file: /cvsroot/pcc/arch/vax/local.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 local.c
> --- arch/vax/local.c 16 Nov 2007 22:35:32 -0000 1.4
> +++ arch/vax/local.c 23 Dec 2007 23:23:34 -0000
> @@ -248,16 +248,11 @@ offcon(OFFSZ off, TWORD t, union dimfun
> being added to a pointer of type t, in order to be off bits offset
> into a structure */
>
> - register NODE *p;
> -
> /* t, d, and s are the type, dimension offset, and sizeoffset */
> /* in general they are necessary for offcon, but not on H'well */
>
> - p = bcon(0);
> - p->n_lval = off/SZCHAR;
> - return(p);
> -
> - }
> + return xbcon(off/SZCHAR, NULL, INT);
> +}
>
> void
> spalloc(NODE *t, NODE *p, OFFSZ off)
> Index: cc/ccom/cgram.y
> ===================================================================
> RCS file: /cvsroot/pcc/cc/ccom/cgram.y,v
> retrieving revision 1.178
> diff -u -p -r1.178 cgram.y
> --- cc/ccom/cgram.y 25 Nov 2007 10:23:53 -0000 1.178
> +++ cc/ccom/cgram.y 23 Dec 2007 23:23:35 -0000
> @@ -1279,9 +1279,7 @@ genswitch(int num, TWORD type, struct sw
> for (i = 1; i <= n; ++i) {
> /* already in 1 */
> r = tempnode(num, type, 0, MKSUE(type));
> - q = block(ICON, NIL, NIL, type, 0, MKSUE(type));
> - q->n_sp = NULL;
> - q->n_lval = p[i]->sval;
> + q = xbcon(p[i]->sval, NULL, type);
> r = buildtree(NE, r, clocal(q));
> cbranch(buildtree(NOT, r, NIL), bcon(p[i]->slab));
> }
> Index: cc/ccom/init.c
> ===================================================================
> RCS file: /cvsroot/pcc/cc/ccom/init.c,v
> retrieving revision 1.38
> diff -u -p -r1.38 init.c
> --- cc/ccom/init.c 20 Dec 2007 16:43:25 -0000 1.38
> +++ cc/ccom/init.c 23 Dec 2007 23:23:35 -0000
> @@ -567,14 +567,13 @@ insbf(OFFSZ off, int fsz, int val)
> spname = csym;
> p = buildtree(ADDROF,
> buildtree(NAME, NIL, NIL), NIL);
> - r = block(ICON, NIL, NIL, typ, 0, MKSUE(typ));
> sym.stype = typ;
> sym.squal = 0;
> sym.sdf = 0;
> sym.ssue = MKSUE(typ);
> sym.soffset = off;
> sym.sclass = typ == INT ? FIELD | fsz : MOU;
> - r->n_sp = &sym;
> + r = xbcon(0, &sym, typ);
> p = block(STREF, p, r, INT, 0, MKSUE(INT));
> ecode(buildtree(ASSIGN, stref(p), bcon(val)));
> }
> @@ -660,14 +659,13 @@ endinit(void)
> p = buildtree(ADDROF,
> buildtree(NAME, NIL, NIL), NIL);
> n = il->n;
> - r = block(ICON, NIL, NIL, INT, 0, MKSUE(INT));
> sym.stype = n->n_type;
> sym.squal = n->n_qual;
> sym.sdf = n->n_df;
> sym.ssue = n->n_sue;
> sym.soffset = ll->begsz + il->off;
> sym.sclass = fsz < 0 ? FIELD | -fsz : 0;
> - r->n_sp = &sym;
> + r = xbcon(0, &sym, INT);
> p = block(STREF, p, r, INT, 0, MKSUE(INT));
> ecode(buildtree(ASSIGN, stref(p), il->n));
> if (fsz < 0)
> Index: cc/ccom/pass1.h
> ===================================================================
> RCS file: /cvsroot/pcc/cc/ccom/pass1.h,v
> retrieving revision 1.130
> diff -u -p -r1.130 pass1.h
> --- cc/ccom/pass1.h 20 Dec 2007 16:44:48 -0000 1.130
> +++ cc/ccom/pass1.h 23 Dec 2007 23:23:35 -0000
> @@ -238,6 +238,7 @@ extern NODE
> *stref(NODE *),
> *offcon(OFFSZ, TWORD, union dimfun *, struct suedef *),
> *bcon(int),
> + *xbcon(CONSZ, struct symtab *, TWORD),
> *bpsize(NODE *),
> *convert(NODE *, int),
> *pconvert(NODE *),
> Index: cc/ccom/scan.l
> ===================================================================
> RCS file: /cvsroot/pcc/cc/ccom/scan.l,v
> retrieving revision 1.63
> diff -u -p -r1.63 scan.l
> --- cc/ccom/scan.l 10 Oct 2007 16:22:39 -0000 1.63
> +++ cc/ccom/scan.l 23 Dec 2007 23:23:36 -0000
> @@ -388,8 +388,7 @@ cvtdig(int radix)
> ntype = UNSIGNED;
> }
> ntype = ctype(ntype);
> - p = block(ICON, NIL, NIL, ntype, 0, MKSUE(ntype));
> - p->n_lval = v;
> + p = xbcon(v, NULL, ntype);
> ASGLVAL(p->n_slval, v);
>
> return p;
> Index: cc/ccom/trees.c
> ===================================================================
> RCS file: /cvsroot/pcc/cc/ccom/trees.c,v
> retrieving revision 1.178
> diff -u -p -r1.178 trees.c
> --- cc/ccom/trees.c 20 Dec 2007 16:44:48 -0000 1.178
> +++ cc/ccom/trees.c 23 Dec 2007 23:23:36 -0000
> @@ -909,12 +909,18 @@ notlval(p) register NODE *p; {
> NODE *
> bcon(int i)
> {
> - register NODE *p;
> + return xbcon(i, NULL, INT);
> +}
>
> - p = block(ICON, NIL, NIL, INT, 0, MKSUE(INT));
> - p->n_lval = i;
> - p->n_sp = NULL;
> - return(clocal(p));
> +NODE *
> +xbcon(CONSZ val, struct symtab *sp, TWORD type)
> +{
> + NODE *p;
> +
> + p = block(ICON, NIL, NIL, type, 0, MKSUE(type));
> + p->n_lval = val;
> + p->n_sp = sp;
> + return clocal(p);
> }
>
> NODE *
>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic