extern char symbuf[MAXCPS+2];
extern struct nmlist *hshtab[HSHSIZ];
extern int kwhash[(HSHSIZ+LNBPW-1)/LNBPW];
-extern struct tree **cp;
+extern struct node **cp;
extern int isn0;
extern struct swtab swtab[SWSIZ];
extern int unscflg;
#endif
extern int regvar;
extern int bitoffs;
-extern struct nnode funcblk;
+extern struct locnnode funcblk;
extern char cvntab[];
extern char numbuf[64];
extern struct nmlist **memlist;
void cntstr __P((void));
int getcc __P((void));
int mapch __P((int ac));
-struct tree *tree __P((/*int eflag*/));
+struct node *tree __P((/*int eflag*/));
struct tnode *xprtype __P((void));
char *copnum __P((int len));
/* c01.c */
void build __P((int op));
-void structident __P((register struct tree *p1, register struct nnode *p2));
-struct tree *convert __P((struct tree *p, int t, int cvn, int len));
-void setype __P((register struct tree *p, register int t, register struct tree *newp));
-struct tree *chkfun __P((register struct tree *p));
-struct tree *disarray __P((register struct tree *p));
-void chkw __P((struct tree *p, int okt));
+void structident __P((register struct node *p1, register struct nnode *p2));
+struct node *convert __P((struct node *p, int t, int cvn, int len));
+void setype __P((register struct node *p, register int t, register struct node *newp));
+struct node *chkfun __P((register struct node *p));
+struct node *disarray __P((register struct node *p));
+void chkw __P((struct node *p, int okt));
int lintyp __P((int t));
void werror0 __P((char *s, ...));
void error0 __P((char *s, ...));
-struct tnode *block __P((int op, int t, int *subs, union str *str, struct tree *p1, struct tree *p2));
+struct tnode *block __P((int op, int t, int *subs, union str *str, struct node *p1, struct node *p2));
struct nnode *nblock __P((register struct nmlist *ds));
struct cnode *cblock __P((_INT value));
struct lnode *lblock __P((_LONG lvalue));
char *starttree __P((void));
void endtree __P((char *tp));
char *Dblock __P((int n));
-void chklval __P((register struct tree *p));
-int fold __P((int op, register struct tree *p1, struct tree *p2));
+void chklval __P((register struct node *p));
+int fold __P((int op, register struct node *p1, struct node *p2));
int conexp __P((void));
-void assignop __P((int op, register struct tree *p1, register struct tree *p2));
+void assignop __P((int op, register struct node *p1, register struct node *p2));
struct nmlist *gentemp __P((int type));
/* c02.c */
void setinit __P((register struct nmlist *np));
void statement __P((void));
int forstmt __P((void));
-struct tree *pexpr __P((/*int eflag*/));
+struct node *pexpr __P((/*int eflag*/));
void pswitch0 __P((void));
void funchead __P((void));
void blockhead __P((void));
/* c04.c */
int decref0 __P((register int t));
int incref0 __P((register int t));
-void cbranch0 __P((struct tree *t, int lbl, int cond));
-void rcexpr0 __P((register struct tree *tp));
-void treeout __P((register struct tree *tp, int isstruct));
+void cbranch0 __P((struct node *t, int lbl, int cond));
+void rcexpr0 __P((register struct node *tp));
+void treeout __P((register struct node *tp, int isstruct));
void branch0 __P((int lab));
void label0 __P((int l));
-int plength __P((register struct tree *p));
-int length __P((struct tree *cs));
-int rlength __P((struct tree *cs));
+int plength __P((register struct node *p));
+int length __P((struct node *cs));
+int rlength __P((struct node *cs));
int simplegoto __P((void));
int nextchar __P((void));
int spnextchar __P((void));
int isn0 = 1;
int peeksym = -1;
int line = 1;
-struct nnode funcblk = { { NAME, 0, (int *)NULL, (union str *)NULL }, (struct nmlist *)NULL, 0/*nn_class*/, 0/*nn_regno*/, 0/*nn_offset*/, 0/*nn_nloc*/ };
+struct locnnode funcblk = { { { NAME, 0, (int *)NULL, (union str *)NULL }, (struct nmlist *)NULL, 0/*nn_class*/, 0/*nn_regno*/, 0/*nn_offset*/}, 0/*locnn_nloc*/ };
struct kwtab kwtab[] = {
{"int", INT},
{0, 0}
};
-struct tree *cmst[CMSIZ];
-struct tree **cp = cmst;
+struct node *cmst[CMSIZ];
+struct node **cp = cmst;
int Wflag; /* print warning messages */
#if 0
* "," or ":" because those delimiters are special
* in initializer (and some other) expressions.
*/
-struct tree *tree(/*eflag*/) /*int eflag;*/ {
+struct node *tree(/*eflag*/) /*int eflag;*/ {
int *op, opst[SSIZE], *pp, prst[SSIZE];
register int andflg, o;
register struct nmlist *cs;
if (cs->hclass==TYPEDEF)
goto atype;
if (cs->hclass==ENUMCON) {
- *cp++ = (struct tree *)cblock(cs->hoffset);
+ *cp++ = (struct node *)cblock(cs->hoffset);
goto tand;
}
if (cs->hclass==0 && cs->htype==0)
error0("%s undefined; func. %s", cs->name,
funcsym ? funcsym->name : "(none)");
}
- *cp++ = (struct tree *)nblock(cs);
+ *cp++ = (struct node *)nblock(cs);
goto tand;
case FCON:
/* *cp++ = fblock(DOUBLE, copnum(cval));*/
- *cp++ = (struct tree *)fblock(isn1++, fcval);
+ *cp++ = (struct node *)fblock(isn1++, fcval);
goto tand;
case LCON:
- *cp++ = (struct tree *)lblock(lcval);
+ *cp++ = (struct node *)lblock(lcval);
goto tand;
case CON:
- *cp++ = (struct tree *)cblock(cval);
+ *cp++ = (struct node *)cblock(cval);
goto tand;
/* fake a static char array */
cs->hclass = STATIC;
/* cs->hoffset = cval;
*cp++ = block(NAME, unscflg? ARRAY+UNCHAR:ARRAY+CHAR, &nchstr,
- (union str *)NULL, (struct tree *)cs, TNULL);*/
+ (union str *)NULL, (struct node *)cs, (struct node *)NULL);*/
cs->hflag = 0;
cs->htype = unscflg? ARRAY+UNCHAR:ARRAY+CHAR;
cs->hstrp = (union str *)&nchstr;
cs->sparent = 0;
cs->hblklev = 0;
cs->name = 0;
- *cp++ = (struct tree *)nblock(cs);
+ *cp++ = (struct node *)nblock(cs);
tand:
if(cp>=cmst+CMSIZ) {
if (*op != LPARN || andflg)
goto syntax;
peeksym = o;
- *cp++ = (struct tree *)xprtype();
+ *cp++ = (struct node *)xprtype();
if ((o=symbol()) != RPARN)
goto syntax;
o = CAST;
goto advanc;
case MCALL:
- *cp++ = (struct tree *)block(NULLOP0, INT, (int *)NULL,
- (union str *)NULL, TNULL, TNULL);
+ *cp++ = (struct node *)block(NULLOP0, INT, (int *)NULL,
+ (union str *)NULL, (struct node *)NULL, (struct node *)NULL);
os = CALL;
break;
case INCAFT:
case DECBEF:
case DECAFT:
- *cp++ = (struct tree *)cblock(1);
+ *cp++ = (struct node *)cblock(1);
break;
case LPARN:
errflush(o);
/*if (eflag)
endtree(svtree);*/
- return((struct tree *) &garbage);
+ return((struct node *) &garbage);
}
struct tnode *xprtype() {
struct nmlist typer, absname;
int sc;
- register struct tree **scp;
+ register struct node **scp;
scp = cp;
sc = DEFXTRN; /* will cause error if class mentioned */
decl1(sc, &typer, 0, &absname);
cp = scp;
return(block(ETYPE, absname.htype, absname.hsubsp,
- absname.hstrp, TNULL, TNULL));
+ absname.hstrp, (struct node *)NULL, (struct node *)NULL));
}
/*char *copnum(len) int len; {
void build(op) int op; {
register int t1;
int t2, t;
- register struct tree *p1, *p2, *p3;
+ register struct node *p1, *p2, *p3;
int dope, leftc, cvn, pcvn;
/*
if ((dope&BINARY)!=0) {
p2 = chkfun(disarray(*--cp));
if (p2)
- t2 = p2->t_type;
+ t2 = p2->n_type;
}
p1 = *--cp;
/*
if (op==SIZEOF) {
struct cnode *p = cblock(length(p1));
p->cn_type = UNSIGN;
- *cp++ = (struct tree *)p;
+ *cp++ = (struct node *)p;
return;
}
if (op!=AMPER) {
if (op!=CALL)
p1 = chkfun(p1);
}
- t1 = p1->t_type;
+ t1 = p1->n_type;
if (t1==CHAR)
t1 = INT;
else if (t1==UNCHAR)
case CAST:
if ((t1&XTYPE)==FUNC || (t1&XTYPE)==ARRAY)
error0("Disallowed conversion");
- if (p1->t_type==UNCHAR) {
- *cp++ = (struct tree *)block(ETYPE, UNSIGN, (int *)NULL, (union str *)NULL,
- TNULL, TNULL);
+ if (p1->n_type==UNCHAR) {
+ *cp++ = (struct node *)block(ETYPE, UNSIGN, (int *)NULL, (union str *)NULL,
+ (struct node *)NULL, (struct node *)NULL);
*cp++ = p2;
build(CAST);
- *cp++ = (struct tree *)cblock(0377);
+ *cp++ = (struct node *)cblock(0377);
build(AND);
return;
}
- if (p2->t_type==CHAR || p2->t_type==UNCHAR)
- p2 = (struct tree *)block(PLUS, t2, (int *)NULL, (union str *)NULL,
- p2, (struct tree *)cblock(0));
+ if (p2->n_type==CHAR || p2->n_type==UNCHAR)
+ p2 = (struct node *)block(PLUS, t2, (int *)NULL, (union str *)NULL,
+ p2, (struct node *)cblock(0));
break;
/* end of expression */
/* no-conversion operators */
case QUEST:
- if (p2->t_op!=COLON)
+ if (p2->n_op!=COLON)
error0("Illegal conditional");
else
if (fold(QUEST, p1, p2))
* case COMMA:
*/
case SEQNC:
- *cp++ = (struct tree *)block(op, t2, p2->t_subsp, p2->t_strp, p1, p2);
+ *cp++ = (struct node *)block(op, t2, p2->n_subsp, p2->n_strp, p1, p2);
return;
case COMMA:
case LOGAND:
case LOGOR:
- *cp++ = (struct tree *)block(op, t, p2->t_subsp, p2->t_strp, p1, p2);
+ *cp++ = (struct node *)block(op, t, p2->n_subsp, p2->n_strp, p1, p2);
return;
case EXCLA:
}
if ((t1&XTYPE) != FUNC)
error0("Call of non-function");
- *cp++ = (struct tree *)block(CALL,decref0(t1),p1->t_subsp,p1->t_strp,p1,p2);
+ *cp++ = (struct node *)block(CALL,decref0(t1),p1->n_subsp,p1->n_strp,p1,p2);
return;
case STAR:
if ((t1&XTYPE) == FUNC)
error0("Illegal indirection");
- *cp++ = (struct tree *)block(STAR, decref0(t1), p1->t_subsp, p1->t_strp, p1, TNULL);
+ *cp++ = (struct node *)block(STAR, decref0(t1), p1->n_subsp, p1->n_strp, p1, (struct node *)NULL);
return;
case AMPER:
- if (p1->t_op==NAME || p1->t_op==STAR) {
- *cp++ = (struct tree *)block(op,incref0(p1->t_type),p1->t_subsp,p1->t_strp,p1,TNULL);
+ if (p1->n_op==NAME || p1->n_op==STAR) {
+ *cp++ = (struct node *)block(op,incref0(p1->n_type),p1->n_subsp,p1->n_strp,p1,(struct node *)NULL);
return;
}
error0("Illegal lvalue");
* a.b goes to (&a)->b
*/
case DOT:
- if (p1->t_op==CALL && t1==STRUCT) {
+ if (p1->n_op==CALL && t1==STRUCT) {
t1 = incref0(t1);
setype(p1, t1, p1);
} else {
* then * is tacked on to access the member.
*/
case ARROW:
- if (p2->t_op!=NAME || ((struct nnode *)p2)->nn_tr1->hclass!=MOS) {
+ if (p2->n_op!=NAME || ((struct nnode *)p2)->nn_nmlist->hclass!=MOS) {
error0("Illegal structure ref");
*cp++ = p1;
return;
#define np2 ((struct nnode *)p2)
structident(p1, np2);
t2 = np2->nn_type;
- if (t2==INT && np2->nn_tr1->hflag&FFIELD)
+ if (t2==INT && np2->nn_nmlist->hflag&FFIELD)
t2 = UNSIGN;
t = incref0(t2);
chkw(p1, -1);
- setype(p1, t, (struct tree *)np2);
- *cp++ = (struct tree *)block(PLUS, t, np2->nn_subsp, np2->nn_strp,
- p1, (struct tree *)cblock(np2->nn_tr1->hoffset));
+ setype(p1, t, (struct node *)np2);
+ *cp++ = (struct node *)block(PLUS, t, np2->nn_subsp, np2->nn_strp,
+ p1, (struct node *)cblock(np2->nn_nmlist->hoffset));
build(STAR);
- if (np2->nn_tr1->hflag&FFIELD)
+ if (np2->nn_nmlist->hflag&FFIELD)
#if 1
- cp[-1] = (struct tree *)block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL,
- cp[-1], (struct tree *)np2->nn_tr1->hstrp);
+ cp[-1] = (struct node *)block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL,
+ cp[-1], (struct node *)np2->nn_nmlist->hstrp);
#else
- *cp++ = (struct tree *)block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL,
- *--cp, (struct tree *)np2->nn_tr1->hstrp);
+ *cp++ = (struct node *)block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL,
+ *--cp, (struct node *)np2->nn_nmlist->hstrp);
#endif
return;
#undef np2
t1 = DOUBLE;
else if (op==FTOI)
t1 = INT;
- if (!fold(op, p1, (struct tree *)NULL))
- *cp++ = (struct tree *)block(op, t1, p1->t_subsp, p1->t_strp, p1,TNULL);
+ if (!fold(op, p1, (struct node *)NULL))
+ *cp++ = (struct node *)block(op, t1, p1->n_subsp, p1->n_strp, p1,(struct node *)NULL);
return;
}
cvn = 0;
if (t1==STRUCT || t2==STRUCT) {
- if (t1!=t2 || p1->t_strp != p2->t_strp)
+ if (t1!=t2 || p1->n_strp != p2->n_strp)
error0("Incompatible structures");
cvn = 0;
} else
t = t1;
if (op==ASSIGN) {
if (cvn==PTI) {
- if (t1!=t2 || ((t1&TYPE)==STRUCT && p1->t_strp!=p2->t_strp))
+ if (t1!=t2 || ((t1&TYPE)==STRUCT && p1->n_strp!=p2->n_strp))
werror0("mixed pointer assignment");
cvn = leftc = 0;
} if ((cvn==ITP || cvn==LTP)
- && (p2->t_op!=CON || ((struct cnode *)p2)->cn_value!=0)
- && (p2->t_op!=LCON || ((struct lnode *)p2)->ln_lvalue!=0)) {
+ && (p2->n_op!=CON || ((struct cnode *)p2)->cn_value!=0)
+ && (p2->n_op!=LCON || ((struct lnode *)p2)->ln_lvalue!=0)) {
/*
* Allow "i = p" and "p = i" with a warning, where
* i is some form of integer (not 0) and p is a
*/
if (op==COLON && (cvn==ITP || cvn==LTP)) {
p3 = leftc? p1: p2;
- if ((p3->t_op!=CON || ((struct cnode *)p3)->cn_value!=0)
- && (p3->t_op!=LCON || ((struct lnode *)p3)->ln_lvalue!=0)) {
+ if ((p3->n_op!=CON || ((struct cnode *)p3)->cn_value!=0)
+ && (p3->n_op!=LCON || ((struct lnode *)p3)->ln_lvalue!=0)) {
werror0("illegal combination of pointer and integer, op :");
if (cvn==ITP)
cvn = leftc = 0;
cvn = 0;
if (op==MINUS) {
pcvn++;
- p1 = (struct tree *)block(ITOL, LONG, (int *)NULL, (union str *)NULL, p1, TNULL);
- p2 = (struct tree *)block(ITOL, LONG, (int *)NULL, (union str *)NULL, p2, TNULL);
+ p1 = (struct node *)block(ITOL, LONG, (int *)NULL, (union str *)NULL, p1, (struct node *)NULL);
+ p2 = (struct node *)block(ITOL, LONG, (int *)NULL, (union str *)NULL, p2, (struct node *)NULL);
t = LONG;
} else {
if (t1!=t2 || (t1!=(PTR+CHAR) && t1!=(PTR+UNCHAR)))
if (cvn) {
if ((cvn==ITP || cvn==LTP) && (opdope0[op]&PCVOK)==0) {
p3 = leftc? p1: p2;
- if ((p3->t_op!=CON || ((struct cnode *)p3)->cn_value!=0)
- && (p3->t_op!=LCON || ((struct lnode *)p3)->ln_lvalue!=0))
+ if ((p3->n_op!=CON || ((struct cnode *)p3)->cn_value!=0)
+ && (p3->n_op!=LCON || ((struct lnode *)p3)->ln_lvalue!=0))
cvn = XX;
else
cvn = 0;
t = INT;
if (op==CAST) {
/* could the below be an oversight? gcc notes rhs always true */
- if (t!=DOUBLE /*&& (t!=INT || p2->t_type!=CHAR || p2->t_type!=UNCHAR)*/) {
- p2->t_type = t;
- p2->t_subsp = p1->t_subsp;
- p2->t_strp = p1->t_strp;
+ if (t!=DOUBLE /*&& (t!=INT || p2->n_type!=CHAR || p2->n_type!=UNCHAR)*/) {
+ p2->n_type = t;
+ p2->n_subsp = p1->n_subsp;
+ p2->n_strp = p1->n_strp;
}
- if (t==INT && p1->t_type==CHAR)
- p2 = (struct tree *)block(ITOC, INT, (int *)NULL, (union str *)NULL, p2, TNULL);
+ if (t==INT && p1->n_type==CHAR)
+ p2 = (struct node *)block(ITOC, INT, (int *)NULL, (union str *)NULL, p2, (struct node *)NULL);
*cp++ = p2;
return;
}
t2 = plength(((struct tnode *)p1)->tn_tr1);
if (fold(op, p1, p2)==0) {
p3 = leftc?p2:p1;
- *cp++ = (struct tree *)block(op, t, p3->t_subsp, p3->t_strp, p1, p2);
+ *cp++ = (struct node *)block(op, t, p3->n_subsp, p3->n_strp, p1, p2);
}
if (pcvn) {
p1 = *--cp;
}
}
-void structident(p1, p2) register struct tree *p1; register struct nnode *p2; {
+void structident(p1, p2) register struct node *p1; register struct nnode *p2; {
register struct nmlist *np, *nporig;
int vartypes = 0, namesame = 1;
- np = nporig = p2->nn_tr1;
+ np = nporig = p2->nn_nmlist;
for (;;) {
- if (namesame && p1->t_type==STRUCT+PTR && p1->t_strp == np->sparent) {
+ if (namesame && p1->n_type==STRUCT+PTR && p1->n_strp == np->sparent) {
p2->nn_type = np->htype;
p2->nn_strp = np->hstrp;
p2->nn_subsp = np->hsubsp;
- p2->nn_tr1 = np;
+ p2->nn_nmlist = np;
return;
}
np = np->nextnm;
/*
* Generate the appropriate conversion operator.
*/
-struct tree *convert(p, t, cvn, len) struct tree *p; int t; int cvn; int len; {
+struct node *convert(p, t, cvn, len) struct node *p; int t; int cvn; int len; {
register int op;
if (cvn==0)
if (opdope0[op]&BINARY) {
if (len==0)
error0("Illegal conversion");
- return((struct tree *)block(op, t, (int *)NULL, (union str *)NULL, p, (struct tree *)cblock(len)));
+ return((struct node *)block(op, t, (int *)NULL, (union str *)NULL, p, (struct node *)cblock(len)));
}
- return((struct tree *)block(op, t, (int *)NULL, (union str *)NULL, p, TNULL));
+ return((struct node *)block(op, t, (int *)NULL, (union str *)NULL, p, (struct node *)NULL));
}
/*
* type at.
* Used with structure references.
*/
-void setype(p, t, newp) register struct tree *p; register int t; register struct tree *newp; {
+void setype(p, t, newp) register struct node *p; register int t; register struct node *newp; {
for (;; p = ((struct tnode *)p)->tn_tr1) {
- p->t_subsp = newp->t_subsp;
- p->t_strp = newp->t_strp;
- p->t_type = t;
- if (p->t_op==AMPER)
+ p->n_subsp = newp->n_subsp;
+ p->n_strp = newp->n_strp;
+ p->n_type = t;
+ if (p->n_op==AMPER)
t = decref0(t);
- else if (p->t_op==STAR)
+ else if (p->n_op==STAR)
t = incref0(t);
- else if (p->t_op!=PLUS)
+ else if (p->n_op!=PLUS)
break;
}
}
* A mention of a function name is turned into
* a pointer to that function.
*/
-struct tree *chkfun(p) register struct tree *p; {
+struct node *chkfun(p) register struct node *p; {
register int t;
- if (((t = p->t_type)&XTYPE)==FUNC && p->t_op!=ETYPE)
- return((struct tree *)block(AMPER,incref0(t),p->t_subsp,p->t_strp,p,TNULL));
+ if (((t = p->n_type)&XTYPE)==FUNC && p->n_op!=ETYPE)
+ return((struct node *)block(AMPER,incref0(t),p->n_subsp,p->n_strp,p,(struct node *)NULL));
return(p);
}
* A mention of an array is turned into
* a pointer to the base of the array.
*/
-struct tree *disarray(p) register struct tree *p; {
+struct node *disarray(p) register struct node *p; {
register int t;
if (p==NULL)
return(p);
/* check array & not MOS and not typer */
- if (((t = p->t_type)&XTYPE)!=ARRAY
- || p->t_op==NAME && ((struct nnode *)p)->nn_tr1->hclass==MOS
- || p->t_op==ETYPE)
+ if (((t = p->n_type)&XTYPE)!=ARRAY
+ || p->n_op==NAME && ((struct nnode *)p)->nn_nmlist->hclass==MOS
+ || p->n_op==ETYPE)
return(p);
- p->t_subsp++;
+ p->n_subsp++;
*cp++ = p;
setype(p, decref0(t), p);
build(AMPER);
* okt might be nonexistent or 'long'
* (e.g. for <<).
*/
-void chkw(p, okt) struct tree *p; int okt; {
- register int t = p->t_type;
+void chkw(p, okt) struct node *p; int okt; {
+ register int t = p->n_type;
if (t == UNLONG)
t = LONG;
* setting the operator, type, dimen/struct table ptrs,
* and the operands.
*/
-struct tnode *block(op, t, subs, str, p1, p2) int op; int t; int *subs; union str *str; struct tree *p1; struct tree *p2; {
+struct tnode *block(op, t, subs, str, p1, p2) int op; int t; int *subs; union str *str; struct node *p1; struct node *p2; {
register struct tnode *p;
p = (struct tnode *)Tblock(sizeof(struct tnode));
}
struct nnode *nblock(ds) register struct nmlist *ds; {
- /* return(block(NAME, ds->htype, ds->hsubsp, ds->hstrp, (struct tree *)ds, TNULL));*/
+ /* return(block(NAME, ds->htype, ds->hsubsp, ds->hstrp, (struct node *)ds, (struct node *)NULL));*/
struct nnode *p;
if (ds->hclass == EXTERN) {
-#define xp (*(struct xnode **)&p)
- xp = (struct xnode *)Tblock(sizeof(struct xnode));
- xp->xn_name = Tblock((strlen(ds->name)+2+LNCPW-1) & ~(LNCPW-1));
- xp->xn_name[0] = '_';
- strcpy(xp->xn_name + 1, ds->name);
-#undef xp
+#define extp (*(struct extnnode **)&p)
+ extp = (struct extnnode *)Tblock(sizeof(struct extnnode));
+ extp->extnn_name = Tblock((strlen(ds->name)+2+LNCPW-1) & ~(LNCPW-1));
+ extp->extnn_name[0] = '_';
+ strcpy(extp->extnn_name + 1, ds->name);
+#undef extp
}
else {
- p = (struct nnode *)Tblock(sizeof(struct nnode));
- p->nn_nloc = ds->hoffset;
+#define locp (*(struct locnnode **)&p)
+ locp = (struct locnnode *)Tblock(sizeof(struct locnnode));
+ locp->locnn_nloc = ds->hoffset;
+#undef locp
}
p->nn_op = NAME;
p->nn_type = ds->htype;
p->nn_subsp = ds->hsubsp;
p->nn_strp = ds->hstrp;
- p->nn_tr1 = ds;
+ p->nn_nmlist = ds;
p->nn_class = ds->hclass==0?STATIC:ds->hclass;
p->nn_regno = 0;
p->nn_offset = 0;
/*
* Check that a tree can be used as an lvalue.
*/
-void chklval(p) register struct tree *p; {
- if (p->t_op==FSEL)
+void chklval(p) register struct node *p; {
+ if (p->n_op==FSEL)
p = ((struct tnode *)p)->tn_tr1;
- if (p->t_op!=NAME && p->t_op!=STAR)
+ if (p->n_op!=NAME && p->n_op!=STAR)
error0("Lvalue required");
}
* but this is used to allow constant expressions
* to be used in switches and array bounds.
*/
-int fold(op, p1, p2) int op; register struct tree *p1; struct tree *p2; {
+int fold(op, p1, p2) int op; register struct node *p1; struct node *p2; {
register int v1, v2;
int unsignf;
- if (p1->t_op!=CON)
+ if (p1->n_op!=CON)
return(0);
#define cp1 ((struct cnode *)p1)
unsignf = cp1->cn_type==UNSIGN;
unsignf |= cp1->cn_type==UNLONG;
if (op==QUEST) {
#define tp2 ((struct tnode *)p2)
- if (tp2->tn_tr1->t_op==CON && tp2->tn_tr2->t_op==CON) {
+ if (tp2->tn_tr1->n_op==CON && tp2->tn_tr2->n_op==CON) {
cp1->cn_value = cp1->cn_value? ((struct cnode *)tp2->tn_tr1)->cn_value: ((struct cnode *)tp2->tn_tr2)->cn_value;
- *cp++ = (struct tree *)cp1;
+ *cp++ = (struct node *)cp1;
cp1->cn_type = tp2->tn_type;
return(1);
}
#undef tp2
}
if (p2) {
- if (p2->t_op!=CON)
+ if (p2->n_op!=CON)
return(0);
#define cp2 ((struct cnode *)p2)
v2 = cp2->cn_value;
return(0);
}
cp1->cn_value = v1;
- *cp++ = (struct tree *)cp1;
+ *cp++ = (struct node *)cp1;
if (unsignf)
cp1->cn_type = UNSIGN;
return(1);
* for example an array bound or a case value.
*/
int conexp() {
- register struct tree *t;
+ register struct node *t;
char *st = starttree();
initflg++;
if (t = tree(/*1*/))
- if (t->t_op != CON)
+ if (t->n_op != CON)
error0("Constant required");
if (!t) abort(); /* don't think this can ever happen */
initflg--;
/*
* Handle peculiar assignment ops that need a temporary.
*/
-void assignop(op, p1, p2) int op; register struct tree *p1; register struct tree *p2; {
+void assignop(op, p1, p2) int op; register struct node *p1; register struct node *p2; {
register struct nmlist *np;
op += PLUS - ASPLUS;
- if (p1->t_op==NAME) {
+ if (p1->n_op==NAME) {
*cp++ = p1;
*cp++ = p1;
*cp++ = p2;
build(ASSIGN);
return;
}
- np = gentemp(incref0(p1->t_type));
- *cp++ = (struct tree *)nblock(np);
+ np = gentemp(incref0(p1->n_type));
+ *cp++ = (struct node *)nblock(np);
*cp++ = p1;
build(AMPER);
build(ASSIGN);
- *cp++ = (struct tree *)nblock(np);
+ *cp++ = (struct node *)nblock(np);
build(STAR);
- *cp++ = (struct tree *)nblock(np);
+ *cp++ = (struct node *)nblock(np);
build(STAR);
*cp++ = p2;
build(op);
tp->hsubsp = NULL;
tp->hstrp = NULL;
tp->hblklev = blklev;
- autolen -= rlength((struct tree *)tp);
+ autolen -= rlength((struct node *)tp);
tp->hoffset = autolen;
if (autolen < maxauto)
maxauto = autolen;
if ((ds->htype&XTYPE)==FUNC) {
if ((peeksym=symbol())==LBRACE || peeksym==KEYW
|| (peeksym==NAME && csym->hclass==TYPEDEF)) {
- funcblk.nn_type = decref0(ds->htype);
- funcblk.nn_strp = ds->hstrp;
+ /* create a fake local variable of same type as function's return type */
+ funcblk.locnn_type = decref0(ds->htype);
+ funcblk.locnn_strp = ds->hstrp;
setinit(ds);
outcode("BS", SYMDEF, sclass==EXTERN?ds->name:"");
cfunc();
error0("Inappropriate parameters");
} else if ((o=symbol())==COMMA || o==SEMI) {
peeksym = o;
- o = (length((struct tree *)ds)+ALIGN) & ~ALIGN;
+ o = (length((struct node *)ds)+ALIGN) & ~ALIGN;
if (sclass==STATIC) {
setinit(ds);
outcode("BSBBSBN", SYMDEF, "", BSS, NLABEL, ds->name, SSPACE, o);
struct nmlist np;
register int nel, ninit;
int width, isarray, o, brace, realtype;
- struct tree *s;
+ struct node *s;
np = *anp;
realtype = np.htype;
isarray++;
else
flex = 0;
- width = length((struct tree *)&np);
+ width = length((struct node *)&np);
nel = 1;
/*
* If it's an array, find the number of elements.
np.hsubsp++;
if (width==0 && flex==0)
error0("0-length row: %s", anp->name);
- o = length((struct tree *)&np);
+ o = length((struct node *)&np);
nel = (unsigned)width/o;
width = o;
}
initflg = 0;
if (np.hflag&FFIELD)
error0("No field initialization");
- *cp++ = (struct tree *)nblock(&np);
+ *cp++ = (struct node *)nblock(&np);
*cp++ = s;
build(ASSIGN);
if (sclass==AUTO||sclass==REG)
rcexpr0(*--cp);
else if (sclass==ENUMCON) {
- if (s->t_op!=CON)
+ if (s->n_op!=CON)
error0("Illegal enum constant for %s", anp->name);
anp->hoffset = ((struct cnode *)s)->cn_value;
} else
- rcexpr0((struct tree *)block(INIT,np.htype,(int *)NULL,
- (union str *)NULL, ((struct tnode *)(*--cp))->tn_tr2, TNULL));
+ rcexpr0((struct node *)block(INIT,np.htype,(int *)NULL,
+ (union str *)NULL, ((struct tnode *)(*--cp))->tn_tr2, (struct node *)NULL));
endtree(st);
}
ninit++;
case IF: {
register int o2;
- register struct tree *np;
+ register struct node *np;
char *st = starttree();
np = pexpr(/*1*/);
goto stmt;
case SWITCH: {
- register struct tree *np;
+ register struct node *np;
register char *st;
o1 = brklab;
st = starttree();
np = pexpr(/*0*/);
chkw(np, -1);
- rcexpr0((struct tree *)block(RFORCE,0,(int *)NULL,(union str *)NULL,np,TNULL));
+ rcexpr0((struct node *)block(RFORCE,0,(int *)NULL,(union str *)NULL,np,(struct node *)NULL));
endtree(st);
pswitch0();
brklab = o1;
*/
int forstmt() {
register int o;
- register struct tree *st;
+ register struct node *st;
register int l;
char *ss;
* A parenthesized expression,
* as after "if".
*/
-struct tree *pexpr(/*eflag*/) /*int eflag;*/ {
+struct node *pexpr(/*eflag*/) /*int eflag;*/ {
register int o;
- register struct tree *t;
+ register struct node *t;
if ((o=symbol())!=LPARN)
goto syntax;
t = tree(/*eflag*/);
if ((o=symbol())!=RPARN)
goto syntax;
- if (t->t_type==VOID)
+ if (t->n_type==VOID)
error0("Illegal use of void");
return(t);
syntax:
* Structure resembling a block for a register variable.
*/
struct nmlist hreg = { REG, 0, 0, NULL, NULL, 0 };
-struct nnode areg = { { NAME, 0, (int *)NULL, (union str *)NULL }, &hreg, 0/*nn_class*/, 0/*nn_regno*/, 0/*nn_offset*/, 0/*nn_nlock*/ };
+struct locnnode areg = { { { NAME, 0, (int *)NULL, (union str *)NULL }, &hreg, 0/*nn_class*/, 0/*nn_regno*/, 0/*nn_offset*/}, 0/*locnn_nloc*/ };
void funchead() {
register int pl;
register struct nmlist *cs;
cs->htype -= (ARRAY-PTR); /* set ptr */
cs->hsubsp++; /* pop dims */
}
- pl += rlength((struct tree *)cs);
+ pl += rlength((struct node *)cs);
if (cs->hclass==AREG && (hreg.hoffset=goodreg(cs))>=0) {
st = starttree();
- *cp++ = (struct tree *)&areg;
- *cp++ = (struct tree *)nblock(cs);
- areg.nn_type = cs->htype;
- areg.nn_strp = cs->hstrp;
+ *cp++ = (struct node *)&areg;
+ *cp++ = (struct node *)nblock(cs);
+ areg.locnn_type = cs->htype;
+ areg.locnn_strp = cs->hstrp;
cs->hclass = AUTO;
build(ASSIGN);
rcexpr0(*--cp);
isunion++;
mosflg = FMOS;
if ((peeksym=symbol()) == SEMI) {
- o = length((struct tree *)tptr);
+ o = length((struct node *)tptr);
if (o>offset)
offset = o;
}
}
elsize = 0;
if (skw==MOS) {
- elsize = length((struct tree *)dsym);
+ elsize = length((struct node *)dsym);
if ((peeksym = symbol())==COLON) {
elsize = 0;
peeksym = -1;
if (skw==AUTO) {
/* if (STAUTO < 0) { */
/*fprintf(stderr, "%s autolen %d -> ", dsym->name, autolen);*/
- autolen -= rlength((struct tree *)dsym);
+ autolen -= rlength((struct node *)dsym);
dsym->hoffset = autolen;
if (autolen < maxauto)
maxauto = autolen;
outcode("B", EVEN);
} else
outcode("BBNBN", BSS, LABEL, isn0++, SSPACE,
- rlength((struct tree *)dsym));
+ rlength((struct node *)dsym));
outcode("B", PROG);
isinit = 0;
} else if (skw==REG && isinit) {
* Make a tree that causes a branch to lbl
* if the tree's value is non-zero together with the cond.
*/
-void cbranch0(t, lbl, cond) struct tree *t; int lbl; int cond; {
+void cbranch0(t, lbl, cond) struct node *t; int lbl; int cond; {
#if 1 /* one-pass version */
long outloc;
/*
* Write out a tree.
*/
-void rcexpr0(tp) register struct tree *tp; {
+void rcexpr0(tp) register struct node *tp; {
#if 1 /* one-pass version */
long outloc;
#endif
/*
* Special optimization
*/
- if (tp->t_op==INIT && ((struct tnode *)tp)->tn_tr1->t_op==CON) {
+ if (tp->n_op==INIT && ((struct tnode *)tp)->tn_tr1->n_op==CON) {
#define ttp ((struct tnode *)tp)
if (ttp->tn_type==CHAR || ttp->tn_type==UNCHAR) {
outcode("B1N0", BDATA, ((struct cnode *)ttp->tn_tr1)->cn_value);
}
#if 0
-void treeout(tp, isstruct) register struct tree *tp; int isstruct; {
+void treeout(tp, isstruct) register struct node *tp; int isstruct; {
register struct nmlist *hp;
register int nextisstruct;
* is some kind of pointer; return the size of the object
* to which the pointer points.
*/
-int plength(p) register struct tree *p; {
+int plength(p) register struct node *p; {
register int t, l;
- if (p==0 || ((t=p->t_type)&~TYPE) == 0) /* not a reference */
+ if (p==0 || ((t=p->n_type)&~TYPE) == 0) /* not a reference */
return(1);
- p->t_type = decref0(t);
+ p->n_type = decref0(t);
l = length(p);
- p->t_type = t;
+ p->n_type = t;
return(l);
}
* return the number of bytes in the object
* whose tree node is acs.
*/
-int length(cs) struct tree *cs; {
+int length(cs) struct node *cs; {
register int t, elsz;
long n;
int nd;
- t = cs->t_type;
+ t = cs->n_type;
n = 1;
nd = 0;
while ((t&XTYPE) == ARRAY) {
t = decref0(t);
- n *= cs->t_subsp[nd++];
+ n *= cs->n_subsp[nd++];
}
if ((t&~TYPE)==FUNC)
return(0);
break;
case STRUCT:
- if ((elsz = cs->t_strp->S.ssize) == 0)
+ if ((elsz = cs->n_strp->S.ssize) == 0)
error0("Undefined structure");
break;
default:
/*
* The number of bytes in an object, rounded up to a word.
*/
-int rlength(cs) struct tree *cs; {
+int rlength(cs) struct node *cs; {
return((length(cs)+ALIGN) & ~ALIGN);
}
* The goto statement.
*/
void dogoto() {
- register struct tree *np;
+ register struct node *np;
register char *st;
st = starttree();
*cp++ = tree(/*0*/);
build(STAR);
chkw(np = *--cp, -1);
- rcexpr0((struct tree *)block(JUMP, 0, (int *)NULL, (union str *)NULL, np, TNULL));
+ rcexpr0((struct node *)block(JUMP, 0, (int *)NULL, (union str *)NULL, np, (struct node *)NULL));
endtree(st);
}
register char *st;
st = starttree();
- *cp++ = (struct tree *)&funcblk;
+ *cp++ = (struct node *)&funcblk;
*cp++ = tree(/*0*/);
build(ASSIGN);
cp[-1] = ((struct tnode *)cp[-1])->tn_tr2;
extern char *opntab[];
extern int nstack;
extern int nfloat;
-extern struct nnode sfuncr;
+extern struct locnnode sfuncr;
extern char *funcbase;
extern char *curbase;
extern char *coremax;
/*long ftell();*/
/*char *sbrk();*/
/*struct optab *match();*/
-/*struct tree *optim();*/
-/*struct tree *unoptim();*/
-/*struct tree *pow2();*/
-/*struct tree *tnode();*/
-/*struct tree *sdelay();*/
-/*struct tree *ncopy();*/
-/*struct tree *getblk();*/
-/*struct tree *strfunc();*/
-/*struct tree *isconstant();*/
-/*struct tree *tconst();*/
-/*struct tree *hardlongs();*/
-/*struct tree *lconst();*/
-/*struct tree *acommute();*/
-/*struct tree *lvfield();*/
-/*struct tree *paint();*/
+/*struct node *optim();*/
+/*struct node *unoptim();*/
+/*struct node *pow2();*/
+/*struct node *tnode();*/
+/*struct node *sdelay();*/
+/*struct node *ncopy();*/
+/*struct node *getblk();*/
+/*struct node *strfunc();*/
+/*struct node *isconstant();*/
+/*struct node *tconst();*/
+/*struct node *hardlongs();*/
+/*struct node *lconst();*/
+/*struct node *acommute();*/
+/*struct node *lvfield();*/
+/*struct node *paint();*/
/*long ftell();*/
/*
int nextl;
int nextn;
struct tnode *nlist[LSTSIZ];
- struct tree *llist[LSTSIZ+1];
+ struct node *llist[LSTSIZ+1];
};
#endif
/* c10.c */
int main __P((int argc, char *argv[]));
-struct optab *match __P((struct tree *tree, struct table *table, int nrleft, int nocvt));
-int rcexpr1 __P((struct tree *atree, struct table *atable, int reg));
-int cexpr __P((register struct tree *tree, struct table *table, int areg));
-int reorder __P((struct tree **treep, struct table *table, int reg));
-int sreorder __P((struct tree **treep, struct table *table, int reg, int recurf));
-int delay __P((struct tree **treep, struct table *table, int reg));
-struct tree *sdelay __P((struct tree **ap));
-struct tree *paint __P((register struct tree *tp, register int type));
+struct optab *match __P((struct node *tree, struct table *table, int nrleft, int nocvt));
+int rcexpr1 __P((struct node *atree, struct table *atable, int reg));
+int cexpr __P((register struct node *tree, struct table *table, int areg));
+int reorder __P((struct node **treep, struct table *table, int reg));
+int sreorder __P((struct node **treep, struct table *table, int reg, int recurf));
+int delay __P((struct node **treep, struct table *table, int reg));
+struct node *sdelay __P((struct node **ap));
+struct node *paint __P((register struct node *tp, register int type));
struct nnode *ncopy __P((register struct nnode *p));
-int chkleaf __P((register struct tree *tree, struct table *table, int reg));
-int comarg __P((register struct tree *tree, int *flagp));
-struct tree *strfunc __P((register struct tree *tp));
-void doinit __P((register int type, register struct tree *tree));
-void movreg __P((int r0, int r1, struct tree *tree));
+int chkleaf __P((register struct node *tree, struct table *table, int reg));
+int comarg __P((register struct node *tree, int *flagp));
+struct node *strfunc __P((register struct node *tp));
+void doinit __P((register int type, register struct node *tree));
+void movreg __P((int r0, int r1, struct node *tree));
/* c11.c */
-int degree __P((register struct tree *t));
-void pname __P((register struct tree *p, int flag));
+int degree __P((register struct node *t));
+void pname __P((register struct node *p, int flag));
void pbase __P((register struct nnode *p));
-int xdcalc __P((register struct tree *p, int nrleft));
-int dcalc __P((register struct tree *p, int nrleft));
-int notcompat __P((register struct tree *p, int ast, int deg, int op));
+int xdcalc __P((register struct node *p, int nrleft));
+int dcalc __P((register struct node *p, int nrleft));
+int notcompat __P((register struct node *p, int ast, int deg, int op));
int prins __P((int op, int c, struct instab *itable, int lbl));
-int collcon __P((register struct tree *p));
-int isfloat __P((register struct tree *t));
-int oddreg __P((register struct tree *t, register int reg));
+int collcon __P((register struct node *p));
+int isfloat __P((register struct node *t));
+int oddreg __P((register struct node *t, register int reg));
int arlength __P((int t));
void pswitch1 __P((struct swtab *afp, struct swtab *alp, int deflab));
void breq __P((int v, int l));
int sort __P((struct swtab *afp, struct swtab *alp));
int ispow2 __P((register struct tnode *tree));
struct tnode *pow2 __P((register struct tnode *tree));
-void cbranch1 __P((struct tree *atree, register int lbl, int cond, register int reg));
+void cbranch1 __P((struct node *atree, register int lbl, int cond, register int reg));
void branch1 __P((int lbl, int aop, int c));
void longrel __P((struct tnode *atree, int lbl, int cond, int reg));
int xlongrel __P((int f));
int incref1 __P((register int t));
/* c12.c */
-struct tree *optim __P((register struct tree *tree));
-struct tree *binoptim __P((register struct tree *tree));
-struct tree *unoptim __P((register struct tree *tree));
-struct tree *lvfield __P((register struct tnode *t));
-struct tree *acommute __P((register struct tree *tree));
-int sideeffects __P((register struct tree *tp));
+struct node *optim __P((register struct node *tree));
+struct node *binoptim __P((register struct node *tree));
+struct node *unoptim __P((register struct node *tree));
+struct node *lvfield __P((register struct tnode *t));
+struct node *acommute __P((register struct node *tree));
+int sideeffects __P((register struct node *tp));
void distrib __P((struct acl *list));
-void squash __P((struct tree **p, struct tree **maxp));
+void squash __P((struct node **p, struct node **maxp));
void _const __P((int op, register _INT *vp, _INT v, int type));
-struct lnode *lconst __P((int op, register struct tree *lp, register struct tree *rp));
-void insert __P((int op, register struct tree *tree, register struct acl *list));
-struct tnode *tnode __P((int op, int type, struct tree *tr1, struct tree *tr2));
+struct lnode *lconst __P((int op, register struct node *lp, register struct node *rp));
+void insert __P((int op, register struct node *tree, register struct acl *list));
+struct tnode *tnode __P((int op, int type, struct node *tr1, struct node *tr2));
struct cnode *tconst __P((int val, int type));
-struct tree *getblk __P((int size));
+struct node *getblk __P((int size));
int islong __P((int t));
-struct tree *isconstant __P((register struct tree *t));
-struct tree *hardlongs __P((register struct tree *t));
-int uns __P((struct tree *tp));
+struct cnode *isconstant __P((register struct node *t));
+struct node *hardlongs __P((register struct node *t));
+int uns __P((struct node *tp));
#endif
#include "c1.h"
#ifdef DEBUG
-#define dbprint(op) fprintf(temp_fp[temp_fi], /*printf(*/" / %s", opntab[op])
+#define dbprint(op) fprintf(temp_fp[temp_fi], " / %s", opntab[op])
#else
#define dbprint(op) /* */
#endif
struct cnode czero = { { CON, INT, (int *)NULL, (union str *)NULL }, 0};
struct cnode cone = { { CON, INT, (int *)NULL, (union str *)NULL }, 1};
-struct nnode sfuncr = { { NAME, STRUCT, (int *)NULL, (union str *)NULL }, (struct nmlist *)NULL, STATIC, 0, 0, 0 };
+struct locnnode sfuncr = { { { NAME, STRUCT, (int *)NULL, (union str *)NULL }, (struct nmlist *)NULL, STATIC/*nn_class*/, 0/*nn_regno*/, 0/*nn_offset*/ }, 0/*locnn_nloc*/ };
struct table *cregtab;
int nreg = 3;
* pulls in the floating-point part of printf.
*/
if (nfloat)
- fprintf(temp_fp[temp_fi], /*printf(*/".globl fltused\n");
+ fprintf(temp_fp[temp_fi], ".globl fltused\n");
/*
* tack on the string file.
*/
- fprintf(temp_fp[temp_fi], /*printf(*/".globl\n.data\n");
+ fprintf(temp_fp[temp_fi], ".globl\n.data\n");
if (*argv[2] != '-') {
if (freopen(argv[2], "r", stdin)==NULL) {
error1("Missing temp file");
* required is not too large.
* Return a ptr to the table entry or 0 if none found.
*/
-struct optab *match(tree, table, nrleft, nocvt) struct tree *tree; struct table *table; int nrleft; int nocvt; {
+struct optab *match(tree, table, nrleft, nocvt) struct node *tree; struct table *table; int nrleft; int nocvt; {
#define NOCVL 1
#define NOCVR 2
int op, d1, d2, dope;
- struct tree *p2;
- register struct tree *p1;
+ struct node *p2;
+ register struct node *p1;
register struct optab *opt;
if (tree==NULL)
return(NULL);
if (table==lsptab)
table = sptab;
- if ((op = tree->t_op)==0)
+ if ((op = tree->n_op)==0)
return(0);
dope = opdope1[op];
if ((dope&LEAF) == 0)
* the converted int in a register by
* movf double,fr0; movfi fr0,int .
*/
- if (opdope1[p2->t_op]&CNVRT && (nocvt&NOCVR)==0
- && (opdope1[((struct tnode *)p2)->tn_tr1->t_op]&CNVRT)==0) {
+ if (opdope1[p2->n_op]&CNVRT && (nocvt&NOCVR)==0
+ && (opdope1[((struct tnode *)p2)->tn_tr1->n_op]&CNVRT)==0) {
ttree->tn_tr2 = ((struct tnode *)p2)->tn_tr1;
- if (opt = match((struct tree *)ttree, table, nrleft, NOCVL))
+ if (opt = match((struct node *)ttree, table, nrleft, NOCVL))
return(opt);
ttree->tn_tr2 = p2;
- } else if (opdope1[p1->t_op]&CNVRT && (nocvt&NOCVL)==0
- && (opdope1[((struct tnode *)p1)->tn_tr1->t_op]&CNVRT)==0) {
+ } else if (opdope1[p1->n_op]&CNVRT && (nocvt&NOCVL)==0
+ && (opdope1[((struct tnode *)p1)->tn_tr1->n_op]&CNVRT)==0) {
ttree->tn_tr1 = ((struct tnode *)p1)->tn_tr1;
- if (opt = match((struct tree *)ttree, table, nrleft, NOCVR))
+ if (opt = match((struct node *)ttree, table, nrleft, NOCVR))
return(opt);
ttree->tn_tr1 = p1;
}
return(0);
for (opt = table->tabp; opt->tabdeg1!=0; opt++) {
if (d1 > (opt->tabdeg1&077)
- || (opt->tabdeg1 >= 0100 && (p1->t_op != STAR)))
+ || (opt->tabdeg1 >= 0100 && (p1->n_op != STAR)))
continue;
if (notcompat(p1, opt->tabtyp1, opt->tabdeg1, op))
continue;
if ((opdope1[op]&BINARY)!=0 && p2!=0) {
if (d2 > (opt->tabdeg2&077)
- || (opt->tabdeg2 >= 0100) && (p2->t_op != STAR) )
+ || (opt->tabdeg2 >= 0100) && (p2->n_op != STAR) )
continue;
if (notcompat(p2,opt->tabtyp2, opt->tabdeg2, 0))
continue;
* A number of special cases are recognized, and
* there is an interaction with the optimizer routines.
*/
-int rcexpr1(atree, atable, reg) struct tree *atree; struct table *atable; int reg; {
+int rcexpr1(atree, atable, reg) struct node *atree; struct table *atable; int reg; {
register int r;
int modf, nargs, recurf;
- register struct tree *tree;
+ register struct node *tree;
register struct table *table;
/*fprintf(stderr, "rcexpr1(0x%08x, 0x%08x, 0x%08x)\n", atree, atable, reg);*/
again:
if((tree=atree)==0)
return(0);
- if (tree->t_type==VOID) {
+ if (tree->n_type==VOID) {
if (table!=efftab)
error1("Illegal use of void");
- tree->t_type = INT;
+ tree->n_type = INT;
}
- if (opdope1[tree->t_op]&RELAT && ((struct tnode *)tree)->tn_tr2->t_op==CON
+ if (opdope1[tree->n_op]&RELAT && ((struct tnode *)tree)->tn_tr2->n_op==CON
&& ((struct cnode *)((struct tnode *)tree)->tn_tr2)->cn_value==0
&& table==cctab)
tree = atree = ((struct tnode *)tree)->tn_tr1;
* ignore the select, otherwise
* do the shift and mask.
*/
- if (tree->t_op == FSELT) {
+ if (tree->n_op == FSELT) {
if (table==efftab)
atree = tree = ((struct tnode *)tree)->tn_tr1;
else {
- tree->t_op = FSEL;
+ tree->n_op = FSEL;
atree = tree = optim(tree);
}
}
- switch (tree->t_op) {
+ switch (tree->n_op) {
/*
* Structure assignments
#define ttree ((struct tnode *)tree)
if (table==cctab) {
ttree->tn_op = TAND;
- ttree->tn_tr2 = optim((struct tree *)tnode(COMPL, ttree->tn_type, ttree->tn_tr2, TNULL));
+ ttree->tn_tr2 = optim((struct node *)tnode(COMPL, ttree->tn_type, ttree->tn_tr2, (struct node *)NULL));
}
break;
#undef ttree
}
#endif
tree = ((struct tnode *)tree)->tn_tr2;
- if(tree->t_op) {
- while (tree->t_op==COMMA) {
+ if(tree->n_op) {
+ while (tree->n_op==COMMA) {
r += comarg(((struct tnode *)tree)->tn_tr2, &modf);
tree = ((struct tnode *)tree)->tn_tr1;
nargs++;
tree = atree;
#define ttree ((struct tnode *)tree)
ttree->tn_op = CALL2;
- if (modf && ttree->tn_tr1->t_op==NAME
+ if (modf && ttree->tn_tr1->n_op==NAME
&& ((struct nnode *)ttree->tn_tr1)->nn_class==EXTERN)
ttree->tn_op = CALL1;
- if (cexpr((struct tree *)ttree, regtab, reg)<0)
+ if (cexpr((struct node *)ttree, regtab, reg)<0)
error1("compiler botch: call");
popstk(r);
nstack -= nargs;
#define ttree ((struct tnode *)tree)
if (ttree->tn_type != LONG && ttree->tn_type != UNLONG)
break;
- if (ttree->tn_tr2->t_op==ITOL)
+ if (ttree->tn_tr2->n_op==ITOL)
ttree->tn_tr2 = ((struct tnode *)ttree->tn_tr2)->tn_tr1;
else
- ttree->tn_tr2 = optim((struct tree *)tnode(LTOI,INT,ttree->tn_tr2,TNULL));
+ ttree->tn_tr2 = optim((struct node *)tnode(LTOI,INT,ttree->tn_tr2,(struct node *)NULL));
if (ttree->tn_op==ASULSH)
{
ttree->tn_op = UASLSHL;
- ttree->tn_tr1 = (struct tree *)tnode(AMPER, LONG+PTR, ttree->tn_tr1, TNULL);
+ ttree->tn_tr1 = (struct node *)tnode(AMPER, LONG+PTR, ttree->tn_tr1, (struct node *)NULL);
}
else
ttree->tn_op = ULLSHIFT;
case LSHIFT:
#define ttree ((struct tnode *)tree)
if (ttree->tn_type==LONG || ttree->tn_type==UNLONG) {
- if (ttree->tn_tr2->t_op==ITOL)
+ if (ttree->tn_tr2->n_op==ITOL)
ttree->tn_tr2 = ((struct tnode *)ttree->tn_tr2)->tn_tr1;
else
- ttree->tn_tr2 = optim((struct tree *)tnode(LTOI,INT,ttree->tn_tr2,TNULL));
+ ttree->tn_tr2 = optim((struct node *)tnode(LTOI,INT,ttree->tn_tr2,(struct node *)NULL));
if (ttree->tn_op==ASLSH)
ttree->tn_op = ASLSHL;
else
*/
case TIMES:
case ASTIMES:
- tree = (struct tree *)pow2((struct tnode *)tree);
+ tree = (struct node *)pow2((struct tnode *)tree);
}
/*
* Try to find postfix ++ and -- operators that can be
/* delay() has to be able to assume input pointer is a tnode */
if (tree != atree) abort();
if (table!=cctab && table!=cregtab && recurf<2
- && (opdope1[tree->t_op]&LEAF)==0) {
+ && (opdope1[tree->n_op]&LEAF)==0) {
if (r=delay(&atree, table, reg)) {
tree = atree;
table = efftab;
* so reg = x+y is done as reg = x; reg += y
*/
if (recurf==0 && reorder(&atree, table, reg)) {
- if (table==cctab && atree->t_op==NAME)
+ if (table==cctab && atree->n_op==NAME)
return(reg);
}
tree = atree;
- if (table==efftab && tree->t_op==NAME)
+ if (table==efftab && tree->n_op==NAME)
return(reg);
if ((r=cexpr(tree, table, reg))>=0) {
- if (table==cregtab && (tree->t_op==INCAFT
- || tree->t_op==DECAFT || tree->t_op==TIMES))
+ if (table==cregtab && (tree->n_op==INCAFT
+ || tree->n_op==DECAFT || tree->n_op==TIMES))
goto fixup;
return(r);
}
- if (table!=regtab && (table!=cctab||(opdope1[tree->t_op]&RELAT)==0)) {
+ if (table!=regtab && (table!=cctab||(opdope1[tree->n_op]&RELAT)==0)) {
if((r=cexpr(tree, regtab, reg))>=0) {
fixup:
modf = isfloat(tree);
- dbprint(tree->t_op);
+ dbprint(tree->n_op);
if (table==sptab || table==lsptab) {
- if (tree->t_type==LONG || tree->t_type==UNLONG){
- fprintf(temp_fp[temp_fi], /*printf(*/"mov\tr%d,-(sp)\n",r+1);
+ if (tree->n_type==LONG || tree->n_type==UNLONG){
+ fprintf(temp_fp[temp_fi], "mov\tr%d,-(sp)\n",r+1);
nstack++;
}
- fprintf(temp_fp[temp_fi], /*printf(*/"mov%s r%d,%s(sp)\n", modf=='f'?"f":"", r,
+ fprintf(temp_fp[temp_fi], "mov%s r%d,%s(sp)\n", modf=='f'?"f":"", r,
table==sptab? "-":"");
nstack++;
}
if (table==cctab || table==cregtab)
- fprintf(temp_fp[temp_fi], /*printf(*/"tst%s r%d\n", modf=='f'?"f":"", r);
+ fprintf(temp_fp[temp_fi], "tst%s r%d\n", modf=='f'?"f":"", r);
return(r);
}
}
/*
* Special grace for unsigned chars as right operands
*/
- if (opdope1[tree->t_op]&BINARY && ((struct tnode *)tree)->tn_tr2->t_type==UNCHAR) {
+ if (opdope1[tree->n_op]&BINARY && ((struct tnode *)tree)->tn_tr2->n_type==UNCHAR) {
#define ttree ((struct tnode *)tree)
- ttree->tn_tr2 = (struct tree *)tnode(LOAD, UNSIGN, ttree->tn_tr2, TNULL);
- return(rcexpr1((struct tree *)ttree, table, reg));
+ ttree->tn_tr2 = (struct node *)tnode(LOAD, UNSIGN, ttree->tn_tr2, (struct node *)NULL);
+ return(rcexpr1((struct node *)ttree, table, reg));
#undef ttree
}
/*
* There's a last chance for this operator
*/
- if (tree->t_op==LTOI) {
+ if (tree->n_op==LTOI) {
#define ttree ((struct tnode *)tree)
r = rcexpr1(ttree->tn_tr1, regtab, reg);
if (r >= 0) {
#undef ttree
}
- r = tree->t_op;
- if (tree->t_type == STRUCT)
+ r = tree->n_op;
+ if (tree->n_type == STRUCT)
error1("Illegal operation on structure");
else if (r > 0 && r < UASLSHL && opntab[r])
error1("No code table for op: %s(%d) type: %d", opntab[r], r,
- tree->t_type);
+ tree->n_type);
else
error1("No code table for op %d", r);
return(reg);
* Most of the work is the macro-expansion of the
* code table.
*/
-int cexpr(tree, table, areg) register struct tree *tree; struct table *table; int areg; {
+int cexpr(tree, table, areg) register struct node *tree; struct table *table; int areg; {
int c, r;
- register struct tree *p, *p1;
+ register struct node *p, *p1;
struct table *ctable;
- struct tree *p2;
+ struct node *p2;
char *string;
int reg, reg1, rreg, flag, opd;
struct optab *opt;
reg = areg;
- c = tree->t_op;
+ c = tree->n_op;
opd = opdope1[c];
/*
* When the value of a relational or a logical expression is
*/
if ((opd&RELAT||c==LOGAND||c==LOGOR||c==EXCLA) && table!=cctab) {
cbranch1(tree, c=isn1++, 1, reg);
- rcexpr1((struct tree *)&czero, table, reg);
+ rcexpr1((struct node *)&czero, table, reg);
branch1(isn1, 0, 0);
label1(c);
- rcexpr1((struct tree *)&cone, table, reg);
+ rcexpr1((struct node *)&cone, table, reg);
label1(isn1++);
return(reg);
}
/*
* long values take 2 registers.
*/
- if ((tree->t_type==LONG||tree->t_type==UNLONG||opd&RELAT&&(((struct tnode *)tree)->tn_tr1->t_type==LONG||((struct tnode *)tree)->tn_tr1->t_type==UNLONG))
- && tree->t_op!=ITOL)
+ if ((tree->n_type==LONG||tree->n_type==UNLONG||opd&RELAT&&(((struct tnode *)tree)->tn_tr1->n_type==LONG||((struct tnode *)tree)->tn_tr1->n_type==UNLONG))
+ && tree->n_op!=ITOL)
reg1++;
/*
* Leaves of the expression tree
* x + (-1) is better done as x-1.
*/
if (ttree->tn_op==PLUS||ttree->tn_op==ASPLUS) {
- if ((p1=ttree->tn_tr2)->t_op==CON && ((struct cnode *)p1)->cn_value==-1) {
+ if ((p1=ttree->tn_tr2)->n_op==CON && ((struct cnode *)p1)->cn_value==-1) {
#define cp1 ((struct cnode *)p1)
cp1->cn_value = -cp1->cn_value;
ttree->tn_op += (MINUS-PLUS);
* Because of a peculiarity of the PDP11 table
* char = *intreg++ and *--intreg cannot go through.
*/
- if (ttree->tn_tr2 && (ttree->tn_tr2->t_op==AUTOI||ttree->tn_tr2->t_op==AUTOD)
- && (ttree->tn_tr1->t_type==CHAR || ttree->tn_tr1->t_type==UNCHAR)
- && ttree->tn_tr2->t_type!=CHAR && ttree->tn_tr2->t_type!=UNCHAR)
- ttree->tn_tr2 = (struct tree *)tnode(LOAD, ttree->tn_tr2->t_type, ttree->tn_tr2, TNULL);
+ if (ttree->tn_tr2 && (ttree->tn_tr2->n_op==AUTOI||ttree->tn_tr2->n_op==AUTOD)
+ && (ttree->tn_tr1->n_type==CHAR || ttree->tn_tr1->n_type==UNCHAR)
+ && ttree->tn_tr2->n_type!=CHAR && ttree->tn_tr2->n_type!=UNCHAR)
+ ttree->tn_tr2 = (struct node *)tnode(LOAD, ttree->tn_tr2->n_type, ttree->tn_tr2, (struct node *)NULL);
/*
* Another peculiarity of the PDP11 table manifested itself when
* amplifying the move3: table. The same case which optimizes
* u_char handling in the compiler is a bit awkward, it would be nice
* if %aub in the tables had a more unique meaning.
*/
- if (ttree->tn_tr2 && ttree->tn_tr1->t_op == NAME
+ if (ttree->tn_tr2 && ttree->tn_tr1->n_op == NAME
&& ((struct nnode *)ttree->tn_tr1)->nn_class == REG && ttree->tn_op == ASSIGN
- && ttree->tn_tr2->t_type == UNCHAR)
- ttree->tn_tr2 = (struct tree *)tnode(LOAD, UNSIGN, ttree->tn_tr2, TNULL);
+ && ttree->tn_tr2->n_type == UNCHAR)
+ ttree->tn_tr2 = (struct node *)tnode(LOAD, UNSIGN, ttree->tn_tr2, (struct node *)NULL);
if (table==cregtab)
table = regtab;
/*
if (table!=cctab || c==INCAFT || c==DECAFT || ttree->tn_type==LONG || ttree->tn_type==UNLONG
/* || c==ASRSH || c==ASLSH || c==ASULSH || ttree->tn_tr1->tn_type==UNCHAR */
|| c==ASRSH || c==ASLSH || c==ASULSH
- || (opt = match((struct tree *)ttree, efftab, r, 0)) == 0)
- if ((opt=match((struct tree *)ttree, table, r, 0))==0)
+ || (opt = match((struct node *)ttree, efftab, r, 0)) == 0)
+ if ((opt=match((struct node *)ttree, table, r, 0))==0)
return(-1);
string = opt->tabstring;
p1 = ttree->tn_tr1;
- if (p1->t_op==FCON && ((struct fnode *)p1)->fn_value>0) {
+ if (p1->n_op==FCON && ((struct fnode *)p1)->fn_value>0) {
#define fp1 ((struct fnode *)p1)
#ifdef pdfp11
/* nonportable */
- fprintf(temp_fp[temp_fi], /*printf(*/".data\nL%d:%o;%o;%o;%o\n.text\n", fp1->fn_value,
+ fprintf(temp_fp[temp_fi], ".data\nL%d:%o;%o;%o;%o\n.text\n", fp1->fn_value,
((_UNSIGNED_INT *)&(fp1->fn_fvalue))[0],
((_UNSIGNED_INT *)&(fp1->fn_fvalue))[1],
((_UNSIGNED_INT *)&(fp1->fn_fvalue))[2],
((_UNSIGNED_INT *)&(fp1->fn_fvalue))[3] );
#else
- fprintf(temp_fp[temp_fi], /*printf(*/".data\nL%d:%o;%o;%o;%o\n.text\n", fp1->fn_value,
+ fprintf(temp_fp[temp_fi], ".data\nL%d:%o;%o;%o;%o\n.text\n", fp1->fn_value,
(int)(fp1->fn_fvalue.h >> 16) & 0xffff,
(int)fp1->fn_fvalue.h & 0xffff,
(int)(fp1->fn_fvalue.l >> 16) & 0xffff,
p2 = 0;
if (opdope1[ttree->tn_op]&BINARY) {
p2 = ttree->tn_tr2;
- if (p2->t_op==FCON && ((struct fnode *)p2)->fn_value>0) {
+ if (p2->n_op==FCON && ((struct fnode *)p2)->fn_value>0) {
#define fp2 ((struct fnode *)p2)
#ifdef pdp11
/* nonportable */
- fprintf(temp_fp[temp_fi], /*printf(*/".data\nL%d:%o;%o;%o;%o\n.text\n", fp2->fn_value,
+ fprintf(temp_fp[temp_fi], ".data\nL%d:%o;%o;%o;%o\n.text\n", fp2->fn_value,
((_UNSIGNED_INT *)&(fp2->fn_fvalue))[0],
((_UNSIGNED_INT *)&(fp2->fn_fvalue))[1],
((_UNSIGNED_INT *)&(fp2->fn_fvalue))[2],
((_UNSIGNED_INT *)&(fp2->fn_fvalue))[3] );
#else
- fprintf(temp_fp[temp_fi], /*printf(*/".data\nL%d:%o;%o;%o;%o\n.text\n", fp2->fn_value,
+ fprintf(temp_fp[temp_fi], ".data\nL%d:%o;%o;%o;%o\n.text\n", fp2->fn_value,
(int)(fp2->fn_fvalue.h >> 16) & 0xffff,
(int)fp2->fn_fvalue.h & 0xffff,
(int)(fp2->fn_fvalue.l >> 16) & 0xffff,
break;
case '\0':
- if (!isfloat((struct tree *)ttree))
+ if (!isfloat((struct node *)ttree))
if (ttree->tn_op==DIVIDE||ttree->tn_op==ASDIV)
reg--;
if (table==regtab && (opdope1[ttree->tn_op]&ASSGOP)) {
- if (ttree->tn_tr1->t_type==CHAR)
- fprintf(temp_fp[temp_fi], /*printf(*/"movb r%d,r%d\n", reg, reg);
+ if (ttree->tn_tr1->n_type==CHAR)
+ fprintf(temp_fp[temp_fi], "movb r%d,r%d\n", reg, reg);
}
return(reg);
/* B1 */
case 'C':
if ((opd&LEAF) != 0)
- p = (struct tree *)ttree;
+ p = (struct node *)ttree;
else
p = p1;
goto pbyte;
/* BF */
case 'P':
- p = (struct tree *)ttree;
+ p = (struct node *)ttree;
goto pb1;
/* B2 */
case 'D':
p = p2;
pbyte:
- if (p->t_type==CHAR || p->t_type==UNCHAR)
- fputc('b', temp_fp[temp_fi]) /*putchar('b')*/;
+ if (p->n_type==CHAR || p->n_type==UNCHAR)
+ fputc('b', temp_fp[temp_fi]);
pb1:
if (isfloat(p))
- fputc('f', temp_fp[temp_fi]) /*putchar('f')*/;
+ fputc('f', temp_fp[temp_fi]);
goto loop;
/* BE */
case 'L':
- if (p1->t_type==CHAR || p2->t_type==CHAR
- || p1->t_type==UNCHAR || p2->t_type==UNCHAR)
- fputc('b', temp_fp[temp_fi]) /*putchar('b')*/;
- p = (struct tree *)ttree;
+ if (p1->n_type==CHAR || p2->n_type==CHAR
+ || p1->n_type==UNCHAR || p2->n_type==UNCHAR)
+ fputc('b', temp_fp[temp_fi]);
+ p = (struct node *)ttree;
goto pb1;
/* F */
/* H */
case 'H':
- p = (struct tree *)ttree;
+ p = (struct node *)ttree;
flag = 04;
subtre:
ctable = cregtab;
if ((c&01)!=0) {
/* previous code was accessing tn_tr1 without a type check */
- if (opdope1[p->t_op] & LEAF) abort();
+ if (opdope1[p->n_op] & LEAF) abort();
p = ((struct tnode *)p)->tn_tr1;
if(collcon(p) && ctable!=sptab) {
- if (p->t_op==STAR)
+ if (p->n_op==STAR)
p = ((struct tnode *)p)->tn_tr1;
p = ((struct tnode *)p)->tn_tr1;
}
if (c&010)
r = reg1;
else
- if (opdope1[p->t_op]&LEAF || ((struct tnode *)p)->tn_degree < 2)
+ if (opdope1[p->n_op]&LEAF || ((struct tnode *)p)->tn_degree < 2)
r = reg;
else
r = areg;
else
reg1 = rreg;
} else if (rreg!=reg)
- if ((c&020)==0 && oddreg((struct tree *)ttree, 0)==0 && ttree->tn_type!=LONG
+ if ((c&020)==0 && oddreg((struct node *)ttree, 0)==0 && ttree->tn_type!=LONG
&& ttree->tn_type!=UNLONG
&& (flag&04
|| flag&01&&xdcalc(p2,nreg-rreg-1)<=(opt->tabdeg2&077)
else
longjmp(jmpbuf, 1);
}
- fprintf(temp_fp[temp_fi], /*printf(*/"r%d", r);
+ fprintf(temp_fp[temp_fi], "r%d", r);
goto loop;
case '-': /* check -(sp) */
if (*string=='(') {
nstack++;
if (table!=lsptab)
- fputc('-', temp_fp[temp_fi]) /*putchar('-')*/;
+ fputc('-', temp_fp[temp_fi]);
goto loop;
}
break;
case ')': /* check (sp)+ */
- fputc(')', temp_fp[temp_fi]) /*putchar(')')*/;
+ fputc(')', temp_fp[temp_fi]);
if (*string=='+')
nstack--;
goto loop;
/* #1 */
case '#':
/* previous code was accessing tn_tr1 without a type check */
- if (opdope1[p1->t_op] & LEAF) abort();
+ if (opdope1[p1->n_op] & LEAF) abort();
p = ((struct tnode *)p1)->tn_tr1;
goto nmbr;
/* #2 */
case '"':
/* previous code was accessing tn_tr1 without a type check */
- if (opdope1[p2->t_op] & LEAF) abort();
+ if (opdope1[p2->n_op] & LEAF) abort();
p = ((struct tnode *)p2)->tn_tr1;
nmbr:
if(collcon(p)) {
- if (p->t_op==STAR) {
- fprintf(temp_fp[temp_fi], /*printf(*/"*");
+ if (p->n_op==STAR) {
+ fprintf(temp_fp[temp_fi], "*");
p = ((struct tnode *)p)->tn_tr1;
}
- if ((p = ((struct tnode *)p)->tn_tr2)->t_op == CON) {
+ if ((p = ((struct tnode *)p)->tn_tr2)->n_op == CON) {
#define cp ((struct cnode *)p)
if (cp->cn_value)
psoct(cp->cn_value);
#undef cp
- } else if (p->t_op==AMPER)
+ } else if (p->n_op==AMPER)
pname(((struct tnode *)p)->tn_tr1, 0);
}
goto loop;
case 'T':
c = reg-1;
if (uns(p1) || uns(p2)) {
- fprintf(temp_fp[temp_fi], /*printf(*/"clr r%d\n", c);
+ fprintf(temp_fp[temp_fi], "clr r%d\n", c);
goto loop;
}
if (dcalc(p1, 5)>12 && !match(p1, cctab, 10, 0))
- fprintf(temp_fp[temp_fi], /*printf(*/"tst r%d\n", reg);
- fprintf(temp_fp[temp_fi], /*printf(*/"sxt r%d\n", c);
+ fprintf(temp_fp[temp_fi], "tst r%d\n", reg);
+ fprintf(temp_fp[temp_fi], "sxt r%d\n", c);
goto loop;
case 'V': /* adc sbc, clr, or sxt as required for longs */
case ASPLUS:
case INCBEF:
case INCAFT:
- fprintf(temp_fp[temp_fi], /*printf(*/"adc");
+ fprintf(temp_fp[temp_fi], "adc");
break;
case MINUS:
case NEG:
case DECBEF:
case DECAFT:
- fprintf(temp_fp[temp_fi], /*printf(*/"sbc");
+ fprintf(temp_fp[temp_fi], "sbc");
break;
case ASSIGN:
case ASULSH:
p = ttree->tn_tr1;
lcasev:
- if (p->t_type!=LONG && p->t_type!=UNLONG) {
+ if (p->n_type!=LONG && p->n_type!=UNLONG) {
if (uns(p) || uns(ttree->tn_tr2))
- fprintf(temp_fp[temp_fi], /*printf(*/"clr");
+ fprintf(temp_fp[temp_fi], "clr");
else
- fprintf(temp_fp[temp_fi], /*printf(*/"sxt");
+ fprintf(temp_fp[temp_fi], "sxt");
goto loop;
}
default:
case 'Z':
/* previous code was accessing fa_mask without a type check */
if (ttree->tn_op != FSELA) abort();
- fprintf(temp_fp[temp_fi], /*printf(*/"$%o", UNS(((struct fasgn *)ttree)->fa_mask));
+ fprintf(temp_fp[temp_fi], "$%o", UNS(((struct fasgn *)ttree)->fa_mask));
goto loop;
/*
return(reg);
goto loop;
}
- fputc(c, temp_fp[temp_fi]) /*putchar(c)*/;
+ fputc(c, temp_fp[temp_fi]);
goto loop;
#undef ttree
}
* on the subtrees and then on the tree itself.
* It returns non-zero if anything changed.
*/
-int reorder(treep, table, reg) struct tree **treep; struct table *table; int reg; {
+int reorder(treep, table, reg) struct node **treep; struct table *table; int reg; {
register int r, o;
- register struct tree *p;
+ register struct node *p;
p = *treep;
- o = p->t_op;
+ o = p->n_op;
if (opdope1[o]&LEAF||o==LOGOR||o==LOGAND||o==SEQNC||o==QUEST||o==COLON)
return(0);
#define tp ((struct tnode *)p)
* Moreover, expressions like "reg = x+y" are best done as
* "reg = x; reg += y" (so long as "reg" and "y" are not the same!).
*/
-int sreorder(treep, table, reg, recurf) struct tree **treep; struct table *table; int reg; int recurf; {
- register struct tree *p, *p1;
+int sreorder(treep, table, reg, recurf) struct node **treep; struct table *table; int reg; int recurf; {
+ register struct node *p, *p1;
p = *treep;
- if (opdope1[p->t_op]&LEAF)
+ if (opdope1[p->n_op]&LEAF)
return(0);
#define tp ((struct tnode *)p)
if (tp->tn_op==PLUS && recurf)
if (reorder(&tp->tn_tr2, table, reg))
/* in this case optim() is guaranteed to return a struct tnode */
{
- *treep = p = optim((struct tree *)tp);
- if (opdope1[p->t_op] & LEAF) abort();
+ *treep = p = optim((struct node *)tp);
+ if (opdope1[p->n_op] & LEAF) abort();
}
- if ((p1 = tp->tn_tr1)==TNULL)
+ if ((p1 = tp->tn_tr1)==(struct node *)NULL)
return(0);
if (tp->tn_op==STAR || tp->tn_op==PLUS) {
if (recurf && reorder(&tp->tn_tr1, table, reg)) {
/* in this case optim() might not return a struct tnode */
- *treep = p = optim((struct tree *)tp);
- if (opdope1[p->t_op]&LEAF)
+ *treep = p = optim((struct node *)tp);
+ if (opdope1[p->n_op]&LEAF)
return(0);
/* but it's a struct tnode, so continue accessing via tp */
}
p1 = tp->tn_tr1;
}
- if (p1->t_op==NAME) switch(tp->tn_op) {
+ if (p1->n_op==NAME) switch(tp->tn_op) {
case ASLSH:
case ASRSH:
case ASSIGN:
if (((struct nnode *)p1)->nn_class != REG || ((struct nnode *)p1)->nn_type==CHAR
|| isfloat(tp->tn_tr2))
return(0);
- if (tp->tn_op==ASSIGN) switch (tp->tn_tr2->t_op) {
+ if (tp->tn_op==ASSIGN) switch (tp->tn_tr2->n_op) {
case RSHIFT:
if (tp->tn_type==UNSIGN)
return(0);
case TIMES:
if (!ispow2((struct tnode *)tp->tn_tr2))
break;
- tp->tn_tr2 = (struct tree *)pow2((struct tnode *)tp->tn_tr2);
+ tp->tn_tr2 = (struct node *)pow2((struct tnode *)tp->tn_tr2);
case PLUS:
case MINUS:
case AND:
case LSHIFT:
caseGEN:
p1 = ((struct tnode *)tp->tn_tr2)->tn_tr2;
+ /* here tp->tn_tr1 (former p1) is a locnnode of class REG, checked above */
+ /* XXX formerly nn_class was not checked in the below, so random values of */
+ /* nloc/name could (rarely) have caused the optimization not to be applied */
if (xdcalc(p1, 16) > 12
- || p1->t_op==NAME
- &&(((struct nnode *)p1)->nn_nloc==((struct nnode *)tp->tn_tr1)->nn_nloc
- || ((struct nnode *)p1)->nn_regno==((struct nnode *)tp->tn_tr1)->nn_nloc))
+ || p1->n_op==NAME
+ &&(((struct nnode *)p1)->nn_class == REG && ((struct locnnode *)p1)->locnn_nloc==((struct locnnode *)tp->tn_tr1)->locnn_nloc
+ || (((struct nnode *)p1)->nn_class == OFFS || ((struct nnode *)p1)->nn_class == SOFFS || ((struct nnode *)p1)->nn_class == XOFFS) && ((struct nnode *)p1)->nn_regno==((struct locnnode *)tp->tn_tr1)->locnn_nloc))
return(0);
p1 = tp->tn_tr2;
#define tp1 ((struct tnode *)p1)
tp->tn_tr2 = tp1->tn_tr1;
- if (tp1->tn_tr1->t_op!=NAME
+ if (tp1->tn_tr1->n_op!=NAME
|| ((struct nnode *)tp1->tn_tr1)->nn_class!=REG
- || ((struct nnode *)tp1->tn_tr1)->nn_nloc!=((struct nnode *)tp->tn_tr1)->nn_nloc)
- rcexpr1((struct tree *)tp, efftab, reg);
+ || ((struct locnnode *)tp1->tn_tr1)->locnn_nloc!=((struct locnnode *)tp->tn_tr1)->locnn_nloc)
+ rcexpr1((struct node *)tp, efftab, reg);
tp->tn_tr2 = tp1->tn_tr2;
tp->tn_op = tp1->tn_op + ASPLUS - PLUS;
- *treep = (struct tree *)tp;
+ *treep = (struct node *)tp;
return(1);
#undef tp1
}
OK:
if (table==cctab||table==cregtab)
reg += 020;
- rcexpr1(optim((struct tree *)tp), efftab, ~reg);
+ rcexpr1(optim((struct node *)tp), efftab, ~reg);
*treep = p1;
return(1);
}
* Otherwise it uses sdelay to search for inc/dec
* among the operands.
*/
-int delay(treep, table, reg) struct tree **treep; struct table *table; int reg; {
+int delay(treep, table, reg) struct node **treep; struct table *table; int reg; {
register struct tnode *p;
- register struct tree *p1;
+ register struct node *p1;
register int r;
p = (struct tnode *)*treep;
if ((p->tn_op==INCAFT||p->tn_op==DECAFT)
- && p->tn_tr1->t_op==NAME) {
+ && p->tn_tr1->n_op==NAME) {
r = ((struct nnode *)p->tn_tr1)->nn_class;
if (r == EXTERN || r == OFFS || r == STATIC &&
- p->tn_tr1->t_type == UNCHAR)
+ p->tn_tr1->n_type == UNCHAR)
return(1+rcexpr1(p->tn_tr1, table, reg));
else
return(1+rcexpr1(paint(p->tn_tr1, p->tn_type), table,reg));
if (p1==0)
p1 = sdelay(&p->tn_tr1);
if (p1) {
- r = rcexpr1(optim((struct tree *)p), table, reg);
+ r = rcexpr1(optim((struct node *)p), table, reg);
*treep = p1;
return(r+1);
}
return(0);
}
-struct tree *sdelay(ap) struct tree **ap; {
- register struct tree *p, *p1;
+struct node *sdelay(ap) struct node **ap; {
+ register struct node *p, *p1;
- if ((p = *ap)==TNULL)
- return(TNULL);
- if ((p->t_op==INCAFT||p->t_op==DECAFT) && ((struct tnode *)p)->tn_tr1->t_op==NAME) {
+ if ((p = *ap)==(struct node *)NULL)
+ return((struct node *)NULL);
+ if ((p->n_op==INCAFT||p->n_op==DECAFT) && ((struct tnode *)p)->tn_tr1->n_op==NAME) {
#define tp ((struct tnode *)p)
- *ap = paint((struct tree *)ncopy((struct nnode *)tp->tn_tr1), tp->tn_type);
- return((struct tree *)tp);
+ *ap = paint((struct node *)ncopy((struct nnode *)tp->tn_tr1), tp->tn_type);
+ return((struct node *)tp);
#undef tp
}
- if (p->t_op==STAR || p->t_op==PLUS)
+ if (p->n_op==STAR || p->n_op==PLUS)
if (p1=sdelay(&((struct tnode *)p)->tn_tr1))
return(p1);
- if (p->t_op==PLUS)
+ if (p->n_op==PLUS)
return(sdelay(&((struct tnode *)p)->tn_tr2));
return(0);
}
/*
* Propagate possible implicit type-changing operation
*/
-struct tree *paint(tp, type) register struct tree *tp; register int type; {
+struct node *paint(tp, type) register struct node *tp; register int type; {
- if (tp->t_type==type)
+ if (tp->n_type==type)
return(tp);
- if (tp->t_type==CHAR && type==INT)
+ if (tp->n_type==CHAR && type==INT)
return(tp);
- if (tp->t_type==CHAR || tp->t_type==UNCHAR)
- return(optim((struct tree *)tnode(LOAD, type, tp, TNULL)));
- tp->t_type = type;
- if (tp->t_op==AMPER && type&XTYPE)
+ if (tp->n_type==CHAR || tp->n_type==UNCHAR)
+ return(optim((struct node *)tnode(LOAD, type, tp, (struct node *)NULL)));
+ tp->n_type = type;
+ if (tp->n_op==AMPER && type&XTYPE)
#define ttp ((struct tnode *)tp)
ttp->tn_tr1 = paint(ttp->tn_tr1, decref1(type));
#undef ttp
- else if (tp->t_op==STAR)
+ else if (tp->n_op==STAR)
#define ttp ((struct tnode *)tp)
ttp->tn_tr1 = paint(ttp->tn_tr1, incref1(type));
#undef ttp
- else if (tp->t_op==ASSIGN) {
+ else if (tp->n_op==ASSIGN) {
#define ttp ((struct tnode *)tp)
/* previous code was not saving back return value from paint() ??? */
- struct tree *temp =
+ struct node *temp =
paint(ttp->tn_tr1, type);
if (temp != ttp->tn_tr1) abort();
temp =
struct nnode *q;
if (p->nn_class==EXTERN || p->nn_class==XOFFS) {
-#define xp ((struct xnode *)p)
-#define xq (*(struct xnode **)&q)
- xq = (struct xnode *)getblk(sizeof(struct xnode));
- xq->xn_name = xp->xn_name;
-#undef xp
-#undef xq
+#define extp ((struct extnnode *)p)
+#define extq (*(struct extnnode **)&q)
+ extq = (struct extnnode *)getblk(sizeof(struct extnnode));
+ extq->extnn_name = extp->extnn_name;
+#undef extp
+#undef extq
}
else {
- q = (struct nnode *)getblk(sizeof(struct nnode));
- q->nn_nloc = p->nn_nloc;
+#define locp ((struct locnnode *)p)
+#define locq (*(struct locnnode **)&q)
+ locq = (struct locnnode *)getblk(sizeof(struct locnnode));
+ locq->locnn_nloc = locp->locnn_nloc;
+#undef locp
+#undef locq
}
q->nn_op = p->nn_op;
q->nn_type = p->nn_type;
* If the tree can be immediately loaded into a register,
* produce code to do so and return success.
*/
-int chkleaf(tree, table, reg) register struct tree *tree; struct table *table; int reg; {
+int chkleaf(tree, table, reg) register struct node *tree; struct table *table; int reg; {
struct tnode lbuf;
- if (tree->t_op!=STAR && dcalc(tree, nreg-reg) > 12)
+ if (tree->n_op!=STAR && dcalc(tree, nreg-reg) > 12)
return(-1);
/* if dcalc() returns 0 then either tree == NULL or tree is a struct tnode */
#define ttree ((struct tnode *)tree)
lbuf.tn_degree = ttree->tn_degree;
lbuf.tn_tr1 = tree;
/* can't have garbage in lbuf.tr2, cexpr() will deref it if non-NULL */
- lbuf.tn_tr2 = TNULL;
- return(rcexpr1((struct tree *)&lbuf, table, reg));
+ lbuf.tn_tr2 = (struct node *)NULL;
+ return(rcexpr1((struct node *)&lbuf, table, reg));
}
/*
* Return the number of bytes pushed,
* for future popping.
*/
-int comarg(tree, flagp) register struct tree *tree; int *flagp; {
+int comarg(tree, flagp) register struct node *tree; int *flagp; {
register int retval;
int i;
int size;
- if (/*tree->t_op==STRASG*/tree->t_type==STRUCT) {
+ if (/*tree->n_op==STRASG*/tree->n_type==STRUCT) {
/* size = tree->fa_mask;
tree = tree->tn_tr1;*/
- size = tree->t_strp->S.ssize;
+ size = tree->n_strp->S.ssize;
tree = strfunc(tree);
if (size <= sizeof(_INT)) {
paint(tree, INT);
paint(tree, LONG);
goto normal;
}
- if (tree->t_op!=NAME && tree->t_op!=STAR) {
+ if (tree->n_op!=NAME && tree->n_op!=STAR) {
error1("Unimplemented structure assignment");
return(0);
}
- tree = (struct tree *)tnode(AMPER, STRUCT+PTR, tree, TNULL);
- tree = (struct tree *)tnode(PLUS, STRUCT+PTR, tree, (struct tree *)tconst(size, INT));
+ tree = (struct node *)tnode(AMPER, STRUCT+PTR, tree, (struct node *)NULL);
+ tree = (struct node *)tnode(PLUS, STRUCT+PTR, tree, (struct node *)tconst(size, INT));
tree = optim(tree);
retval = rcexpr1(tree, regtab, 0);
size >>= 1;
if (size <= 5) {
for (i=0; i<size; i++)
- fprintf(temp_fp[temp_fi], /*printf(*/"mov -(r%d),-(sp)\n", retval);
+ fprintf(temp_fp[temp_fi], "mov -(r%d),-(sp)\n", retval);
} else {
if (retval!=0)
- fprintf(temp_fp[temp_fi], /*printf(*/"mov r%d,r0\n", retval);
- fprintf(temp_fp[temp_fi], /*printf(*/"mov $%o,r1\n", UNS(size));
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d:mov -(r0),-(sp)\ndec\tr1\njne\tL%d\n", isn1, isn1);
+ fprintf(temp_fp[temp_fi], "mov r%d,r0\n", retval);
+ fprintf(temp_fp[temp_fi], "mov $%o,r1\n", UNS(size));
+ fprintf(temp_fp[temp_fi], "L%d:mov -(r0),-(sp)\ndec\tr1\njne\tL%d\n", isn1, isn1);
isn1++;
}
nstack++;
return(size*2);
}
normal:
- if (nstack || isfloat(tree) || tree->t_type==LONG || tree->t_type==UNLONG) {
+ if (nstack || isfloat(tree) || tree->n_type==LONG || tree->n_type==UNLONG) {
rcexpr1(tree, sptab, 0);
- retval = arlength(tree->t_type);
+ retval = arlength(tree->n_type);
} else {
(*flagp)++;
rcexpr1(tree, lsptab, 0);
return(retval);
}
-struct tree *strfunc(tp) register struct tree *tp; {
- if (tp->t_op != CALL)
+struct node *strfunc(tp) register struct node *tp; {
+ if (tp->n_op != CALL)
return(tp);
paint(tp, STRUCT+PTR);
- return((struct tree *)tnode(STAR, STRUCT, tp, TNULL));
+ return((struct node *)tnode(STAR, STRUCT, tp, (struct node *)NULL));
}
/*
* Compile an initializing expression
*/
-void doinit(type, tree) register int type; register struct tree *tree; {
+void doinit(type, tree) register int type; register struct node *tree; {
_FLOAT sfval;
_DOUBLE fval;
_LONG lval;
if (type==CHAR || type==UNCHAR) {
- fprintf(temp_fp[temp_fi], /*printf(*/".byte ");
- if (tree->t_type&XTYPE)
+ fprintf(temp_fp[temp_fi], ".byte ");
+ if (tree->n_type&XTYPE)
goto illinit;
type = INT;
}
switch (type) {
case INT:
case UNSIGN:
- if (tree->t_op==FTOI) {
- if (((struct tnode *)tree)->tn_tr1->t_op!=FCON && ((struct tnode *)tree)->tn_tr1->t_op!=SFCON)
+ if (tree->n_op==FTOI) {
+ if (((struct tnode *)tree)->tn_tr1->n_op!=FCON && ((struct tnode *)tree)->tn_tr1->n_op!=SFCON)
goto illinit;
tree = ((struct tnode *)tree)->tn_tr1;
fval = ((struct fnode *)tree)->fn_fvalue;
#else
((struct cnode *)tree)->cn_value = fp_double_to_int(fval);
#endif
- } else if (tree->t_op==LTOI) {
- if (((struct tnode *)tree)->tn_tr1->t_op!=LCON)
+ } else if (tree->n_op==LTOI) {
+ if (((struct tnode *)tree)->tn_tr1->n_op!=LCON)
goto illinit;
tree = ((struct tnode *)tree)->tn_tr1;
lval = ((struct lnode *)tree)->ln_lvalue;
((struct cnode *)tree)->cn_op = CON;
((struct cnode *)tree)->cn_value = lval;
}
- if (tree->t_op == CON)
- fprintf(temp_fp[temp_fi], /*printf(*/"%o\n", UNS(((struct cnode *)tree)->cn_value));
- else if (tree->t_op==AMPER) {
+ if (tree->n_op == CON)
+ fprintf(temp_fp[temp_fi], "%o\n", UNS(((struct cnode *)tree)->cn_value));
+ else if (tree->n_op==AMPER) {
pname(((struct tnode *)tree)->tn_tr1, 0);
fputc('\n', temp_fp[temp_fi]) /*putchar('\n')*/;
} else
case DOUBLE:
case FLOAT:
- if (tree->t_op==ITOF) {
+ if (tree->n_op==ITOF) {
#define ttree ((struct tnode *)tree)
- if (ttree->tn_tr1->t_op==CON) {
+ if (ttree->tn_tr1->n_op==CON) {
/* note: this should be changed to respect the signedness of the int */
#ifdef pdp11
fval = ((struct cnode *)ttree->tn_tr1)->cn_value;
} else
goto illinit;
#undef ttree
- } else if (tree->t_op==FCON || tree->t_op==SFCON) {
+ } else if (tree->n_op==FCON || tree->n_op==SFCON) {
fval = ((struct fnode *)tree)->fn_fvalue;
- } else if (tree->t_op==LTOF) {
+ } else if (tree->n_op==LTOF) {
#define ttree ((struct tnode *)tree)
- if (ttree->tn_tr1->t_op!=LCON)
+ if (ttree->tn_tr1->n_op!=LCON)
goto illinit;
/* note: this should be changed to respect the signedness of the long */
#ifdef pdp11
#ifdef pdp11
sfval = fval;
/*nonportable*/
- fprintf(temp_fp[temp_fi], /*printf(*/"%o; %o\n",
+ fprintf(temp_fp[temp_fi], "%o; %o\n",
((_UNSIGNED_INT *)&sfval)[0],
((_UNSIGNED_INT *)&sfval)[1]);
#else
sfval = fp_double_to_float(fval);
- fprintf(temp_fp[temp_fi], /*printf(*/"%o; %o\n",
+ fprintf(temp_fp[temp_fi], "%o; %o\n",
(int)(sfval.h >> 16) & 0xffff,
(int)sfval.h & 0xffff);
#endif
} else {
#ifdef pdp11
/* nonportable */
- fprintf(temp_fp[temp_fi], /*printf(*/"%o; %o; %o; %o\n",
+ fprintf(temp_fp[temp_fi], "%o; %o; %o; %o\n",
((_UNSIGNED_INT *)&fval)[0],
((_UNSIGNED_INT *)&fval)[1],
((_UNSIGNED_INT *)&fval)[2],
((_UNSIGNED_INT *)&fval)[3]);
#else
- fprintf(temp_fp[temp_fi], /*printf(*/"%o; %o; %o; %o\n",
+ fprintf(temp_fp[temp_fi], "%o; %o; %o; %o\n",
(int)(fval.h >> 16) & 0xffff,
(int)fval.h & 0xffff,
(int)(fval.l >> 16) & 0xffff,
case UNLONG:
case LONG:
- if (tree->t_op==FTOL) {
+ if (tree->n_op==FTOL) {
tree = ((struct tnode *)tree)->tn_tr1;
- if (tree->t_op==SFCON)
- tree->t_op = FCON;
- if (tree->t_op!= FCON)
+ if (tree->n_op==SFCON)
+ tree->n_op = FCON;
+ if (tree->n_op!= FCON)
goto illinit;
#ifdef pdp11
lval = ((struct fnode *)tree)->fn_fvalue;
#else
lval = fp_double_to_long(((struct fnode *)tree)->fn_fvalue);
#endif
- } else if (tree->t_op==ITOL) {
+ } else if (tree->n_op==ITOL) {
#define ttree ((struct tnode *)tree)
- if (ttree->tn_tr1->t_op != CON)
+ if (ttree->tn_tr1->n_op != CON)
goto illinit;
if (uns(ttree->tn_tr1))
lval = (_UNSIGNED_INT)((struct cnode *)ttree->tn_tr1)->cn_value;
else
lval = ((struct cnode *)ttree->tn_tr1)->cn_value;
#undef ttree
- } else if (tree->t_op==LCON) {
+ } else if (tree->n_op==LCON) {
lval = ((struct lnode *)tree)->ln_lvalue;
} else
goto illinit;
/* nonportable */
- fprintf(temp_fp[temp_fi], /*printf(*/"%o; %o\n", UNS((lval>>16)), UNS(lval));
+ fprintf(temp_fp[temp_fi], "%o; %o\n", UNS((lval>>16)), UNS(lval));
return;
}
illinit:
error1("Illegal initialization");
}
-void movreg(r0, r1, tree) int r0; int r1; struct tree *tree; {
+void movreg(r0, r1, tree) int r0; int r1; struct node *tree; {
register char *s;
char c;
if (r0==r1)
return;
- if (tree->t_type==LONG || tree->t_type == UNLONG) {
+ if (tree->n_type==LONG || tree->n_type == UNLONG) {
if (r0>=nreg || r1>=nreg) {
error1("register overflow: compiler error");
}
s = "mov r%d,r%d\nmov r%d,r%d\n";
if (r0 < r1)
- fprintf(temp_fp[temp_fi], /*printf(*/s, r0+1,r1+1,r0,r1);
+ fprintf(temp_fp[temp_fi], s, r0+1,r1+1,r0,r1);
else
- fprintf(temp_fp[temp_fi], /*printf(*/s, r0,r1,r0+1,r1+1);
+ fprintf(temp_fp[temp_fi], s, r0,r1,r0+1,r1+1);
return;
}
c = isfloat(tree);
- fprintf(temp_fp[temp_fi], /*printf(*/"mov%.1s r%d,r%d\n", &c, r0, r1);
+ fprintf(temp_fp[temp_fi], "mov%.1s r%d,r%d\n", &c, r0, r1);
}
/*static void outname __P((char *s));*/
static void outname __P((char *buf, char *str));
-int degree(t) register struct tree *t; {
- register struct tree *t1;
+int degree(t) register struct node *t; {
+ register struct node *t1;
- if (t==NULL || t->t_op==0)
+ if (t==NULL || t->n_op==0)
return(0);
- if (t->t_op == CON)
+ if (t->n_op == CON)
return(-3);
- if (t->t_op == AMPER)
+ if (t->n_op == AMPER)
return(-2);
- if (t->t_op==ITOL) {
+ if (t->n_op==ITOL) {
/* assume isconstant() does not return an SFCON since it's ITOL not FTOL */
- if ((t1 = isconstant(t)) && (((struct cnode *)t1)->cn_value>=0 || uns(t1)))
+ if ((t1 = (struct node *)isconstant(t)) && (((struct cnode *)t1)->cn_value>=0 || uns(t1)))
return(-2);
- if (uns(t1 = ((struct tnode *)t)->tn_tr1) && opdope1[t1->t_op]&LEAF)
+ if (uns(t1 = ((struct tnode *)t)->tn_tr1) && opdope1[t1->n_op]&LEAF)
return(-1);
}
- if ((opdope1[t->t_op] & LEAF) != 0) {
- if (t->t_type==CHAR || t->t_type==UNCHAR || t->t_type==FLOAT)
+ if ((opdope1[t->n_op] & LEAF) != 0) {
+ if (t->n_type==CHAR || t->n_type==UNCHAR || t->n_type==FLOAT)
return(1);
return(0);
}
return(((struct tnode *)t)->tn_degree);
}
-void pname(p, flag) register struct tree *p; int flag; {
+void pname(p, flag) register struct node *p; int flag; {
register int i;
loop:
- switch(p->t_op) {
+ switch(p->n_op) {
case LCON:
#define lp ((struct lnode *)p)
- fprintf(temp_fp[temp_fi], /*printf(*/"$%o", flag<=10? UNS(lp->ln_lvalue>>16):
+ fprintf(temp_fp[temp_fi], "$%o", flag<=10? UNS(lp->ln_lvalue>>16):
UNS(lp->ln_lvalue));
return;
#undef lp
case SFCON:
case CON:
#define cp ((struct cnode *)p)
- fprintf(temp_fp[temp_fi], /*printf(*/"$");
+ fprintf(temp_fp[temp_fi], "$");
psoct(cp->cn_value);
return;
#undef cp
case FCON:
#define fp ((struct fnode *)p)
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d", (fp->fn_value>0? fp->fn_value: -fp->fn_value));
+ fprintf(temp_fp[temp_fi], "L%d", (fp->fn_value>0? fp->fn_value: -fp->fn_value));
return;
#undef fp
if (i) {
psoct(i);
if (np->nn_class!=OFFS)
- fputc('+', temp_fp[temp_fi]) /*putchar('+')*/;
+ fputc('+', temp_fp[temp_fi]);
if (np->nn_class==REG)
error1("Illegal use of register");
}
switch(np->nn_class) {
case SOFFS:
+#define locnp ((struct locnnode *)np)
+ fprintf(temp_fp[temp_fi], "L%d(r%d)", locnp->locnn_nloc, locnp->locnn_regno);
+ break;
+#undef locnp
+
case XOFFS:
- pbase(np);
+#define extnp ((struct extnnode *)np)
+ fprintf(temp_fp[temp_fi], "%s(r%d)", extnp->extnn_name, extnp->extnn_regno);
+ break;
+#undef extnp
case OFFS:
- fprintf(temp_fp[temp_fi], /*printf(*/"(r%d)", np->nn_regno);
- return;
+ /* considered to be a locnnode even though locnn_nloc is wasted space */
+#define locnp ((struct locnnode *)np)
+ fprintf(temp_fp[temp_fi], "(r%d)", locnp->locnn_regno);
+ break;
+#undef locnp
case EXTERN:
+#define extnp ((struct extnnode *)np)
+ fprintf(temp_fp[temp_fi], "%s", extnp->extnn_name);
+ break;
+#undef extnp
+
case STATIC:
- pbase(np);
- return;
+#define locnp ((struct locnnode *)np)
+ fprintf(temp_fp[temp_fi], "L%d", locnp->locnn_nloc);
+ break;
+#undef locnp
case REG:
- fprintf(temp_fp[temp_fi], /*printf(*/"r%d", np->nn_nloc);
- return;
+#define locnp ((struct locnnode *)np)
+ fprintf(temp_fp[temp_fi], "r%d", locnp->locnn_nloc);
+ break;
+#undef locnp
+
+ default:
+ error1("Compiler error: pname");
+ break;
}
- error1("Compiler error: pname");
return;
#undef np
case AMPER:
- fputc('$', temp_fp[temp_fi]) /*putchar('$')*/;
+ fputc('$', temp_fp[temp_fi]);
p = ((struct tnode *)p)->tn_tr1;
- if (p->t_op==NAME && ((struct nnode *)p)->nn_class==REG)
+ if (p->n_op==NAME && ((struct nnode *)p)->nn_class==REG)
error1("Illegal use of register");
goto loop;
case AUTOI:
-#define np ((struct nnode *)p)
- fprintf(temp_fp[temp_fi], /*printf(*/"(r%d)%s", np->nn_nloc, flag==1?"":"+");
+#define locnp ((struct locnnode *)p)
+ fprintf(temp_fp[temp_fi], "(r%d)%s", locnp->locnn_nloc, flag==1?"":"+");
return;
-#undef np
+#undef locnp
case AUTOD:
-#define np ((struct nnode *)p)
- fprintf(temp_fp[temp_fi], /*printf(*/"%s(r%d)", flag==2?"":"-", np->nn_nloc);
+#define locnp ((struct locnnode *)p)
+ fprintf(temp_fp[temp_fi], "%s(r%d)", flag==2?"":"-", locnp->locnn_nloc);
return;
-#undef np
+#undef locnp
case STAR:
p = ((struct tnode *)p)->tn_tr1;
- fputc('*', temp_fp[temp_fi]) /*putchar('*')*/;
+ fputc('*', temp_fp[temp_fi]);
goto loop;
}
error1("compiler error: bad pname");
}
-void pbase(p) register struct nnode *p; {
-
- if (p->nn_class==SOFFS || p->nn_class==STATIC)
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d", p->nn_nloc);
- else
- fprintf(temp_fp[temp_fi], /*printf(*/"%s", ((struct xnode *)p)->xn_name);
-}
-
-int xdcalc(p, nrleft) register struct tree *p; int nrleft; {
+int xdcalc(p, nrleft) register struct node *p; int nrleft; {
register int d;
if (p==NULL)
return(0);
d = dcalc(p, nrleft);
- if (d<20 && (p->t_type==CHAR || p->t_type==UNCHAR)) {
+ if (d<20 && (p->n_type==CHAR || p->n_type==UNCHAR)) {
if (nrleft>=1)
d = 20;
else
}
/* if dcalc() returns 0 then either p == NULL or p is a struct tnode */
-int dcalc(p, nrleft) register struct tree *p; int nrleft; {
- register struct tree *p1;
+int dcalc(p, nrleft) register struct node *p; int nrleft; {
+ register struct node *p1;
if (p==NULL)
return(0);
- switch (p->t_op) {
+ switch (p->n_op) {
case NAME:
#define np ((struct nnode *)p)
case STAR:
#define tp ((struct tnode *)p)
p1 = tp->tn_tr1;
- if (p1->t_op==NAME||p1->t_op==CON||p1->t_op==AUTOI||p1->t_op==AUTOD)
+ if (p1->n_op==NAME||p1->n_op==CON||p1->n_op==AUTOI||p1->n_op==AUTOD)
if (tp->tn_type!=LONG && tp->tn_type!=UNLONG)
return(12);
break;
#undef tp
}
/* above should have eliminated all of the leaf cases */
- if (opdope1[p->t_op] & LEAF) abort();
+ if (opdope1[p->n_op] & LEAF) abort();
#define tp ((struct tnode *)p)
if (tp->tn_type==LONG || tp->tn_type==UNLONG)
nrleft--;
#undef tp
}
-int notcompat(p, ast, deg, op) register struct tree *p; int ast; int deg; int op; {
+int notcompat(p, ast, deg, op) register struct node *p; int ast; int deg; int op; {
unsigned register at, st;
- at = p->t_type;
+ at = p->n_type;
/*
* an e or n UNCHAR is to be considered an UNSIGNED,
* as long as it is not pointed to.
at = at&TYPE | 020;
if (st==FLOAT && at==DOUBLE)
at = FLOAT;
- if (p->t_op==NAME && ((struct nnode *)p)->nn_class==REG && op==ASSIGN && st==CHAR)
+ if (p->n_op==NAME && ((struct nnode *)p)->nn_class==REG && op==ASSIGN && st==CHAR)
return(0);
return(st != at);
}
if (!ip)
break;
if (ip != jmijne) {
- fprintf(temp_fp[temp_fi], /*printf(*/ip, lbl);
+ fprintf(temp_fp[temp_fi], ip, lbl);
}
else {
skip = isn1++;
- fprintf(temp_fp[temp_fi], /*printf(*/ip, skip);
+ fprintf(temp_fp[temp_fi], ip, skip);
}
return(skip);
}
return(skip);
}
-int collcon(p) register struct tree *p; {
+int collcon(p) register struct node *p; {
register int op;
if (p==NULL)
return(0);
- if (p->t_op==STAR) {
- if (p->t_type==LONG+PTR || p->t_type==UNLONG+PTR) /* avoid *x(r); *x+2(r) */
+ if (p->n_op==STAR) {
+ if (p->n_type==LONG+PTR || p->n_type==UNLONG+PTR) /* avoid *x(r); *x+2(r) */
return(0);
p = ((struct tnode *)p)->tn_tr1;
}
- if (p->t_op==PLUS) {
- op = ((struct tnode *)p)->tn_tr2->t_op;
+ if (p->n_op==PLUS) {
+ op = ((struct tnode *)p)->tn_tr2->n_op;
if (op==CON || op==AMPER)
return(1);
}
return(0);
}
-int isfloat(t) register struct tree *t; {
+int isfloat(t) register struct node *t; {
- if ((opdope1[t->t_op]&RELAT)!=0)
+ if ((opdope1[t->n_op]&RELAT)!=0)
t = ((struct tnode *)t)->tn_tr1;
- if (t->t_type==FLOAT || t->t_type==DOUBLE) {
+ if (t->n_type==FLOAT || t->n_type==DOUBLE) {
nfloat = 1;
return('f');
}
return(0);
}
-int oddreg(t, reg) register struct tree *t; register int reg; {
+int oddreg(t, reg) register struct node *t; register int reg; {
if (!isfloat(t)) {
- if (opdope1[t->t_op]&RELAT) {
+ if (opdope1[t->n_op]&RELAT) {
#define tt ((struct tnode *)t)
- if (tt->tn_tr1->t_type==LONG || tt->tn_tr1->t_type==UNLONG)
+ if (tt->tn_tr1->n_type==LONG || tt->tn_tr1->n_type==UNLONG)
return((reg+1) & ~01);
return(reg);
#undef tt
}
- switch(t->t_op) {
+ switch(t->n_op) {
case ULLSHIFT:
case UASLSHL:
case LLSHIFT:
fp = afp;
lp = alp;
if (fp==lp) {
- fprintf(temp_fp[temp_fi], /*printf(*/"jbr L%d\n", deflab);
+ fprintf(temp_fp[temp_fi], "jbr L%d\n", deflab);
return;
}
isn1++;
/* direct switch */
if (range>0 && range <= 3*ncase) {
if (fp->swval)
- fprintf(temp_fp[temp_fi], /*printf(*/"sub $%o,r0\n", UNS(fp->swval));
- fprintf(temp_fp[temp_fi], /*printf(*/dirsw, UNS(range), deflab, isn1, isn1);
+ fprintf(temp_fp[temp_fi], "sub $%o,r0\n", UNS(fp->swval));
+ fprintf(temp_fp[temp_fi], dirsw, UNS(range), deflab, isn1, isn1);
isn1++;
for (i=fp->swval; ; i++) {
if (i==fp->swval) {
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d\n", fp->swlab);
+ fprintf(temp_fp[temp_fi], "L%d\n", fp->swlab);
if (fp==lp)
break;
fp++;
} else
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d\n", deflab);
+ fprintf(temp_fp[temp_fi], "L%d\n", deflab);
}
- fprintf(temp_fp[temp_fi], /*printf(*/".text\n");
+ fprintf(temp_fp[temp_fi], ".text\n");
return;
}
/* simple switch */
if (ncase<10) {
for (fp = afp; fp<=lp; fp++)
breq(fp->swval, fp->swlab);
- fprintf(temp_fp[temp_fi], /*printf(*/"jbr L%d\n", deflab);
+ fprintf(temp_fp[temp_fi], "jbr L%d\n", deflab);
return;
}
/* hash switch */
}
}
i = isn1++;
- fprintf(temp_fp[temp_fi], /*printf(*/hashsw, UNS(tabs), i, i);
+ fprintf(temp_fp[temp_fi], hashsw, UNS(tabs), i, i);
isn1++;
for (i=0; i<tabs; i++)
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d\n", isn1+i);
- fprintf(temp_fp[temp_fi], /*printf(*/".text\n");
+ fprintf(temp_fp[temp_fi], "L%d\n", isn1+i);
+ fprintf(temp_fp[temp_fi], ".text\n");
for (i=0; i<tabs; i++) {
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d:", isn1++);
+ fprintf(temp_fp[temp_fi], "L%d:", isn1++);
for (swp=fp; swp<=lp; swp++) {
/* lrem(0, swp->swval, tabs) */
if ((_UNSIGNED_INT)swp->swval%tabs == i) {
breq((int)((_UNSIGNED_INT)swp->swval/tabs), swp->swlab);
}
}
- fprintf(temp_fp[temp_fi], /*printf(*/"jbr L%d\n", deflab);
+ fprintf(temp_fp[temp_fi], "jbr L%d\n", deflab);
}
}
void breq(v, l) int v; int l; {
if (v==0)
- fprintf(temp_fp[temp_fi], /*printf(*/"tst r0\n");
+ fprintf(temp_fp[temp_fi], "tst r0\n");
else
- fprintf(temp_fp[temp_fi], /*printf(*/"cmp r0,$%o\n", UNS(v));
- fprintf(temp_fp[temp_fi], /*printf(*/"jeq L%d\n", l);
+ fprintf(temp_fp[temp_fi], "cmp r0,$%o\n", UNS(v));
+ fprintf(temp_fp[temp_fi], "jeq L%d\n", l);
}
int sort(afp, alp) struct swtab *afp; struct swtab *alp; {
int ispow2(tree) register struct tnode *tree; {
register int d;
- if (!isfloat((struct tree *)tree) && tree->tn_tr2->t_op==CON) {
+ if (!isfloat((struct node *)tree) && tree->tn_tr2->n_op==CON) {
d = ((struct cnode *)tree->tn_tr2)->cn_value;
if (d>1 && (d&(d-1))==0)
return(d);
break;
case PTOI:
- if (i==1 && tree->tn_tr1->t_op==MINUS && !isconstant(((struct tnode *)tree->tn_tr1)->tn_tr2)) {
+ if (i==1 && tree->tn_tr1->n_op==MINUS && !isconstant(((struct tnode *)tree->tn_tr1)->tn_tr2)) {
tree->tn_op = PTOI1;
- tree->tn_tr1 = (struct tree *)tnode(LTOI, INT, tree->tn_tr1, TNULL);
+ tree->tn_tr1 = (struct node *)tnode(LTOI, INT, tree->tn_tr1, (struct node *)NULL);
/* in this case optim() is guaranteed to return a struct tnode */
- /* return((struct tnode *)optim((struct tree *)tree));*/
- tree = (struct tnode *)optim((struct tree *)tree);
+ /* return((struct tnode *)optim((struct node *)tree));*/
+ tree = (struct tnode *)optim((struct node *)tree);
if (opdope1[tree->tn_op] & LEAF) abort();
return tree;
}
((struct cnode *)tree->tn_tr2)->cn_value = -i;
i = tree->tn_type;
tree->tn_type = LONG;
- tree = tnode(LTOI, i, (struct tree *)tree, TNULL);
+ tree = tnode(LTOI, i, (struct node *)tree, (struct node *)NULL);
break;
case DIVIDE:
error1("pow2 botch");
}
/* in this case optim() is guaranteed to return a struct tnode */
- tree = (struct tnode *)optim((struct tree *)tree);
+ tree = (struct tnode *)optim((struct node *)tree);
if (opdope1[tree->tn_op] & LEAF) abort();
}
return(tree);
}
-void cbranch1(atree, lbl, cond, reg) struct tree *atree; register int lbl; int cond; register int reg; {
+void cbranch1(atree, lbl, cond, reg) struct node *atree; register int lbl; int cond; register int reg; {
int l1, op;
- register struct tree *tree;
+ register struct node *tree;
again:
if ((tree=atree)==NULL)
return;
- switch(tree->t_op) {
+ switch(tree->n_op) {
case LOGAND:
#define ttree ((struct tnode *)tree)
#undef ttree
}
- op = tree->t_op;
+ op = tree->n_op;
if (opdope1[op]&RELAT
- && ((struct tnode *)tree)->tn_tr1->t_op==ITOL && ((struct tnode *)tree)->tn_tr2->t_op==ITOL
+ && ((struct tnode *)tree)->tn_tr1->n_op==ITOL && ((struct tnode *)tree)->tn_tr2->n_op==ITOL
&& uns(((struct tnode *)((struct tnode *)tree)->tn_tr1)->tn_tr1) == uns(((struct tnode *)((struct tnode *)tree)->tn_tr2)->tn_tr1)) {
#define ttree ((struct tnode *)tree)
ttree->tn_tr1 = ((struct tnode *)ttree->tn_tr1)->tn_tr1;
ttree->tn_op = op = op+LESSEQP-LESSEQ;
#undef ttree
}
- if (tree->t_type==LONG || tree->t_type==UNLONG
- || opdope1[op]&RELAT&&(((struct tnode *)tree)->tn_tr1->t_type==LONG || ((struct tnode *)tree)->tn_tr1->t_type==UNLONG)) {
+ if (tree->n_type==LONG || tree->n_type==UNLONG
+ || opdope1[op]&RELAT&&(((struct tnode *)tree)->tn_tr1->n_type==LONG || ((struct tnode *)tree)->tn_tr1->n_type==UNLONG)) {
#define ttree ((struct tnode *)tree)
longrel(ttree, lbl, cond, reg);
return;
#undef ttree
}
rcexpr1(tree, cctab, reg);
- op = tree->t_op;
+ op = tree->n_op;
if ((opdope1[op]&RELAT)==0)
op = NEQUAL;
else {
#define ttree ((struct tnode *)tree)
- l1 = ttree->tn_tr2->t_op;
+ l1 = ttree->tn_tr2->n_op;
if ((l1==CON || l1==SFCON) && ((struct cnode *)ttree->tn_tr2)->cn_value==0)
op += 200; /* special for ptr tests */
else
#undef ttree
}
if (isfloat(tree))
- fprintf(temp_fp[temp_fi], /*printf(*/"cfcc\n");
+ fprintf(temp_fp[temp_fi], "cfcc\n");
branch1(lbl, op, !cond);
}
if(op = aop) {
skip = prins(op, c, branchtab, lbl);
} else {
- fprintf(temp_fp[temp_fi], /*printf(*/"jbr");
+ fprintf(temp_fp[temp_fi], "jbr");
skip = 0;
}
if (skip)
- fprintf(temp_fp[temp_fi], /*printf(*/"\tL%d\nL%d:", lbl, skip);
+ fprintf(temp_fp[temp_fi], "\tL%d\nL%d:", lbl, skip);
else
- fprintf(temp_fp[temp_fi], /*printf(*/"\tL%d\n", lbl);
+ fprintf(temp_fp[temp_fi], "\tL%d\n", lbl);
}
void longrel(atree, lbl, cond, reg) struct tnode *atree; int lbl; int cond; int reg; {
if (reg&01)
reg++;
- reorder((struct tree **)&atree, cctab, reg);
+ reorder((struct node **)&atree, cctab, reg);
/* in this case reorder is guaranteed to return a struct tnode */
if (opdope1[atree->tn_op] & LEAF) abort();
tree = atree;
xlab2 = 0;
xop = op;
xz = xzero;
- xzero = !isrel || (tree->tn_tr2->t_op==ITOL && ((struct tnode *)tree->tn_tr2)->tn_tr1->t_op==CON
+ xzero = !isrel || (tree->tn_tr2->n_op==ITOL && ((struct tnode *)tree->tn_tr2)->tn_tr1->n_op==CON
&& ((struct cnode *)((struct tnode *)tree->tn_tr2)->tn_tr1)->cn_value==0);
if (tree->tn_op==ANDN) {
tree->tn_op = TAND;
- tree->tn_tr2 = optim((struct tree *)tnode(COMPL, LONG, tree->tn_tr2, TNULL));
+ tree->tn_tr2 = optim((struct node *)tnode(COMPL, LONG, tree->tn_tr2, (struct node *)NULL));
}
- if (cexpr((struct tree *)tree, cctab, reg) < 0) {
- reg = rcexpr1((struct tree *)tree, regtab, reg);
- fprintf(temp_fp[temp_fi], /*printf(*/"ashc $0,r%d\n", reg);
+ if (cexpr((struct node *)tree, cctab, reg) < 0) {
+ reg = rcexpr1((struct node *)tree, regtab, reg);
+ fprintf(temp_fp[temp_fi], "ashc $0,r%d\n", reg);
branch1(xlab1, op, 0);
}
xlab1 = xl1;
}
void label1(l) int l; {
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d:", l);
+ fprintf(temp_fp[temp_fi], "L%d:", l);
}
void popstk(a) int a; {
return;
case 2:
- fprintf(temp_fp[temp_fi], /*printf(*/"tst (sp)+\n");
+ fprintf(temp_fp[temp_fi], "tst (sp)+\n");
return;
case 4:
- fprintf(temp_fp[temp_fi], /*printf(*/"cmp (sp)+,(sp)+\n");
+ fprintf(temp_fp[temp_fi], "cmp (sp)+,(sp)+\n");
return;
}
- fprintf(temp_fp[temp_fi], /*printf(*/"add $%o,sp\n", UNS(a));
+ fprintf(temp_fp[temp_fi], "add $%o,sp\n", UNS(a));
}
void werror1(s) char *s; {
n = -n;
sign = "-";
}
- fprintf(temp_fp[temp_fi], /*printf(*/"%s%o", sign, n);
+ fprintf(temp_fp[temp_fi], "%s%o", sign, n);
}
/*
#endif
{
va_list argp;
- /* struct tree *expstack[STKS], **sp;*/
- static struct tree *expstack[STKS], **sp = expstack;
+ /* struct node *expstack[STKS], **sp;*/
+ static struct node *expstack[STKS], **sp = expstack;
#if 0 /* bitrot */
- register struct tree *tp;
+ register struct node *tp;
#endif
register int t, op;
char s[80]; /* big for asm() stuff & long variable names */
switch(op &= 0377) {
case SINIT:
- fprintf(temp_fp[temp_fi], /*printf(*/"%o\n", UNS(va_arg(argp, int) /*geti()*/));
+ fprintf(temp_fp[temp_fi], "%o\n", UNS(va_arg(argp, int) /*geti()*/));
break;
case EOFC:
case BDATA:
if (va_arg(argp, int) /*geti()*/ == 1) {
- fprintf(temp_fp[temp_fi], /*printf(*/".byte ");
+ fprintf(temp_fp[temp_fi], ".byte ");
for (;;) {
- fprintf(temp_fp[temp_fi], /*printf(*/"%o", UNS(va_arg(argp, int) /*geti()*/));
+ fprintf(temp_fp[temp_fi], "%o", UNS(va_arg(argp, int) /*geti()*/));
if (va_arg(argp, int) /*geti()*/ != 1)
break;
- fprintf(temp_fp[temp_fi], /*printf(*/",");
+ fprintf(temp_fp[temp_fi], ",");
}
- fprintf(temp_fp[temp_fi], /*printf(*/"\n");
+ fprintf(temp_fp[temp_fi], "\n");
}
break;
case PROG:
- fprintf(temp_fp[temp_fi], /*printf(*/".text\n");
+ fprintf(temp_fp[temp_fi], ".text\n");
break;
case DATA:
- fprintf(temp_fp[temp_fi], /*printf(*/".data\n");
+ fprintf(temp_fp[temp_fi], ".data\n");
break;
case BSS:
- fprintf(temp_fp[temp_fi], /*printf(*/".bss\n");
+ fprintf(temp_fp[temp_fi], ".bss\n");
break;
case SYMDEF:
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/".globl\t%s\n", s);
- sfuncr.nn_nloc = 0;
+ fprintf(temp_fp[temp_fi], ".globl\t%s\n", s);
+ sfuncr.locnn_nloc = 0;
break;
case RETRN:
- fprintf(temp_fp[temp_fi], /*printf(*/"jmp\tcret\n");
+ fprintf(temp_fp[temp_fi], "jmp\tcret\n");
break;
case CSPACE:
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/".comm\t%s,%o\n", s, UNS(va_arg(argp, int) /*geti()*/));
+ fprintf(temp_fp[temp_fi], ".comm\t%s,%o\n", s, UNS(va_arg(argp, int) /*geti()*/));
break;
case SSPACE:
- fprintf(temp_fp[temp_fi], /*printf(*/".=.+%o\n", UNS(t=va_arg(argp, int) /*geti()*/));
+ fprintf(temp_fp[temp_fi], ".=.+%o\n", UNS(t=va_arg(argp, int) /*geti()*/));
totspace += (_UNSIGNED_INT)t;
break;
case EVEN:
- fprintf(temp_fp[temp_fi], /*printf(*/".even\n");
+ fprintf(temp_fp[temp_fi], ".even\n");
break;
case SAVE:
- fprintf(temp_fp[temp_fi], /*printf(*/"jsr r5,csv\n");
+ fprintf(temp_fp[temp_fi], "jsr r5,csv\n");
break;
case SETSTK:
t = va_arg(argp, int) /*geti()*/;
if (t==2)
- fprintf(temp_fp[temp_fi], /*printf(*/"tst -(sp)\n");
+ fprintf(temp_fp[temp_fi], "tst -(sp)\n");
else if (t != 0)
- fprintf(temp_fp[temp_fi], /*printf(*/"sub $%o,sp\n", UNS(t));
+ fprintf(temp_fp[temp_fi], "sub $%o,sp\n", UNS(t));
break;
case PROFIL:
t = va_arg(argp, int) /*geti()*/;
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/"mov $L%d,r0\njsr pc,mcount\n", t);
- fprintf(temp_fp[temp_fi], /*printf(*/".data\nL%d:%s+1\n.text\n", t, s);
+ fprintf(temp_fp[temp_fi], "mov $L%d,r0\njsr pc,mcount\n", t);
+ fprintf(temp_fp[temp_fi], ".data\nL%d:%s+1\n.text\n", t, s);
break;
case ASSEM:
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/"%s\n", s);
+ fprintf(temp_fp[temp_fi], "%s\n", s);
break;
case SNAME:
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/"~%s=L%d\n", s+1, va_arg(argp, int) /*geti()*/);
+ fprintf(temp_fp[temp_fi], "~%s=L%d\n", s+1, va_arg(argp, int) /*geti()*/);
break;
case ANAME:
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/"~%s=%o\n", s+1, UNS(va_arg(argp, int) /*geti()*/));
+ fprintf(temp_fp[temp_fi], "~%s=%o\n", s+1, UNS(va_arg(argp, int) /*geti()*/));
break;
case RNAME:
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/"~%s=r%d\n", s+1, va_arg(argp, int) /*geti()*/);
+ fprintf(temp_fp[temp_fi], "~%s=r%d\n", s+1, va_arg(argp, int) /*geti()*/);
break;
case SWIT:
rcexpr1(tp, efftab, 0);
else {
if (tp->tn_type==LONG || tp->tn_type==UNLONG) {
- rcexpr1(tnode(RFORCE, tp->tn_type, tp, TNULL), efftab, 0);
- fprintf(temp_fp[temp_fi], /*printf(*/"ashc $0,r0\n");
+ rcexpr1(tnode(RFORCE, tp->tn_type, tp, (struct node *)NULL), efftab, 0);
+ fprintf(temp_fp[temp_fi], "ashc $0,r0\n");
} else {
rcexpr1(tp, cctab, 0);
if (isfloat(tp))
- fprintf(temp_fp[temp_fi], /*printf(*/"cfcc\n");
+ fprintf(temp_fp[temp_fi], "cfcc\n");
}
- fprintf(temp_fp[temp_fi], /*printf(*/"jgt L%d\n", lbl3);
- fprintf(temp_fp[temp_fi], /*printf(*/"jlt L%d\njbr L%d\n", lbl, lbl2);
+ fprintf(temp_fp[temp_fi], "jgt L%d\n", lbl3);
+ fprintf(temp_fp[temp_fi], "jlt L%d\njbr L%d\n", lbl, lbl2);
}
/* curbase = funcbase;*/
break;
t = va_arg(argp, int) /*geti()*/;
op = va_arg(argp, int) /*geti()*/;
if (t==0 && op>=0 || t == -1 && op<0) {
- *sp++ = (struct tree *)tnode(ITOL, LONG, tconst(op, INT), TNULL);
+ *sp++ = (struct node *)tnode(ITOL, LONG, tconst(op, INT), (struct node *)NULL);
break;
}
tp = getblk(sizeof(struct lnode));
break;
case FSEL:
- tp = tnode(FSEL, va_arg(argp, int) /*geti()*/, *--sp, TNULL);
+ tp = tnode(FSEL, va_arg(argp, int) /*geti()*/, *--sp, (struct node *)NULL);
t = va_arg(argp, int) /*geti()*/;
- tp->tn_tr2 = (struct tree *)tnode(COMMA, INT, tconst(va_arg(argp, int) /*geti()*/, INT), tconst(t, INT));
+ tp->tn_tr2 = (struct node *)tnode(COMMA, INT, tconst(va_arg(argp, int) /*geti()*/, INT), tconst(t, INT));
if (tp->tn_tr2->tn_tr1->cn_value==16)
tp = paint(tp->tn_tr1, tp->tn_type);
*sp++ = tp;
break;
case NULLOP:
- *sp++ = tnode(0, 0, TNULL, TNULL);
+ *sp++ = tnode(0, 0, (struct node *)NULL, (struct node *)NULL);
break;
#endif
case NLABEL:
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/"%s:\n", s);
+ fprintf(temp_fp[temp_fi], "%s:\n", s);
break;
case RLABEL:
outname(s/*)*/, va_arg(argp, char *));
- fprintf(temp_fp[temp_fi], /*printf(*/"%s:\n~~%s:\n", s, s+1);
+ fprintf(temp_fp[temp_fi], "%s:\n~~%s:\n", s, s+1);
break;
case BRANCH:
*sp++ = tnode(op, va_arg(argp, int) /*geti()*/, *--sp, tp);
#endif
} else
- sp[-1] = tnode(op, va_arg(argp, int) /*geti()*/, sp[-1], TNULL);
+ sp[-1] = tnode(op, va_arg(argp, int) /*geti()*/, sp[-1], (struct node *)NULL);
break;
#endif
}
}
if (tp->tn_op != ASSIGN) {*/
if (tp->tn_op==RFORCE) { /* function return */
- if (sfuncr.nn_nloc==0) {
- sfuncr.nn_nloc = isn1++;
- fprintf(temp_fp[temp_fi], /*printf(*/".bss\nL%d:.=.+%o\n.text\n", sfuncr.nn_nloc,
+ if (sfuncr.locnn_nloc==0) {
+ sfuncr.locnn_nloc = isn1++;
+ fprintf(temp_fp[temp_fi], ".bss\nL%d:.=.+%o\n.text\n", sfuncr.locnn_nloc,
UNS(nwords*sizeof(_INT)));
}
- atp/*->tn_tr1*/ = tnode(ASSIGN, STRUCT, (struct tree *)&sfuncr, tp->tn_tr1);
+ atp/*->tn_tr1*/ = tnode(ASSIGN, STRUCT, (struct node *)&sfuncr, tp->tn_tr1);
atp->tn_strp = tp->tn_strp;
strasg(atp);
- fprintf(temp_fp[temp_fi], /*printf(*/"mov $L%d,r0\n", sfuncr.nn_nloc);
+ fprintf(temp_fp[temp_fi], "mov $L%d,r0\n", sfuncr.locnn_nloc);
return;
}
/* if (tp->tn_op==CALL) {
}*/
tp->tn_tr2 = strfunc(tp->tn_tr2);
if (nwords==1)
- paint((struct tree *)tp, INT);
+ paint((struct node *)tp, INT);
else if (nwords==sizeof(_INT))
- paint((struct tree *)tp, LONG);
+ paint((struct node *)tp, LONG);
else {
- if (tp->tn_tr1->t_op!=NAME && tp->tn_tr1->t_op!=STAR
- || tp->tn_tr2->t_op!=NAME && tp->tn_tr2->t_op!=STAR) {
+ if (tp->tn_tr1->n_op!=NAME && tp->tn_tr1->n_op!=STAR
+ || tp->tn_tr2->n_op!=NAME && tp->tn_tr2->n_op!=STAR) {
error1("unimplemented structure assignment");
return;
}
- tp->tn_tr1 = (struct tree *)tnode(AMPER, STRUCT+PTR, tp->tn_tr1, TNULL);
- tp->tn_tr2 = (struct tree *)tnode(AMPER, STRUCT+PTR, tp->tn_tr2, TNULL);
+ tp->tn_tr1 = (struct node *)tnode(AMPER, STRUCT+PTR, tp->tn_tr1, (struct node *)NULL);
+ tp->tn_tr2 = (struct node *)tnode(AMPER, STRUCT+PTR, tp->tn_tr2, (struct node *)NULL);
tp->tn_op = STRSET;
tp->tn_type = STRUCT+PTR;
- rcexpr1(optim((struct tree *)tp), efftab, 0);
+ rcexpr1(optim((struct node *)tp), efftab, 0);
if (nwords < 7) {
for (i=0; i<nwords; i++)
- fprintf(temp_fp[temp_fi], /*printf(*/"mov (r1)+,(r0)+\n");
+ fprintf(temp_fp[temp_fi], "mov (r1)+,(r0)+\n");
return;
}
if (nreg<=1)
- fprintf(temp_fp[temp_fi], /*printf(*/"mov r2,-(sp)\n");
- fprintf(temp_fp[temp_fi], /*printf(*/"mov $%o,r2\n", UNS(nwords));
- fprintf(temp_fp[temp_fi], /*printf(*/"L%d:mov (r1)+,(r0)+\ndec\tr2\njne\tL%d\n", isn1, isn1);
+ fprintf(temp_fp[temp_fi], "mov r2,-(sp)\n");
+ fprintf(temp_fp[temp_fi], "mov $%o,r2\n", UNS(nwords));
+ fprintf(temp_fp[temp_fi], "L%d:mov (r1)+,(r0)+\ndec\tr2\njne\tL%d\n", isn1, isn1);
isn1++;
if (nreg<=1)
- fprintf(temp_fp[temp_fi], /*printf(*/"mov (sp)+,r2\n");
+ fprintf(temp_fp[temp_fi], "mov (sp)+,r2\n");
return;
}
- rcexpr1((struct tree *)tp, efftab, 0);
+ rcexpr1((struct node *)tp, efftab, 0);
}
/*
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
-struct tree *optim(tree) register struct tree *tree; {
+struct node *optim(tree) register struct node *tree; {
register int op, dope;
#ifdef pdp11
union { double dv; _INT iv[4];} fp11;
if (tree==NULL)
return(NULL);
- if ((op = tree->t_op)==0)
+ if ((op = tree->n_op)==0)
return(tree);
if (op==NAME && ((struct nnode *)tree)->nn_class==AUTO) {
-#define ntree ((struct nnode *)tree)
- ntree->nn_class = OFFS;
- ntree->nn_regno = 5;
- ntree->nn_offset = ntree->nn_nloc;
-#undef ntree
+#define locntree ((struct locnnode *)tree)
+ locntree->locnn_class = OFFS;
+ locntree->locnn_regno = 5;
+ locntree->locnn_offset = locntree->locnn_nloc;
+#undef locntree
}
dope = opdope1[op];
if ((dope&LEAF) != 0) {
}
/* in reality this can only be called with a struct tnode argument */
-struct tree *binoptim(tree) register struct tree *tree; {
+struct node *binoptim(tree) register struct node *tree; {
register int op, dope;
int d1, d2;
- struct tree *t;
+ struct node *t;
#define ttree ((struct tnode *)tree)
if (ttree->tn_type==CHAR)
*/
case ASAND:
ttree->tn_op = ASANDN;
- ttree->tn_tr2 = (struct tree *)tnode(COMPL, ttree->tn_tr2->t_type, ttree->tn_tr2, TNULL);
+ ttree->tn_tr2 = (struct node *)tnode(COMPL, ttree->tn_tr2->n_type, ttree->tn_tr2, (struct node *)NULL);
break;
/*
*/
case LTOP:
ttree->tn_op = ITOP;
- ttree->tn_tr1 = unoptim((struct tree *)tnode(LTOI,INT,ttree->tn_tr1, TNULL));
+ ttree->tn_tr1 = unoptim((struct node *)tnode(LTOI,INT,ttree->tn_tr1, (struct node *)NULL));
case ITOP:
ttree->tn_op = TIMES;
break;
case MINUS:
- if ((t = isconstant(ttree->tn_tr2)) && (!uns(t) || ttree->tn_type!=LONG)
+ if ((t = (struct node *)isconstant(ttree->tn_tr2)) && (!uns(t) || ttree->tn_type!=LONG)
/* I don't think the following test matters since -0100000 == 0100000 */
- && (t->t_type!=INT || ((struct cnode *)t)->cn_value!=(_INT)0100000)) {
+ && (((struct cnode *)t)->cn_type!=INT || ((struct cnode *)t)->cn_value!=(_INT)0100000)) {
ttree->tn_op = PLUS;
- if (t->t_type==DOUBLE) {
+ if (t->n_type==DOUBLE) {
/* here it's an SFCON, so fn_value is filled in instead of fn_fvalue */
/* PDP-11 FP representation */
((struct fnode *)t)->fn_value ^= 0100000;
}
op = ttree->tn_op;
dope = opdope1[op];
- if (dope&LVALUE && ttree->tn_tr1->t_op==FSEL)
+ if (dope&LVALUE && ttree->tn_tr1->n_op==FSEL)
return(lvfield(ttree));
if ((dope&COMMUTE)!=0) {
d1 = ttree->tn_type;
#undef ttree
tree = acommute(tree);
- if (tree->t_op == op)
- tree->t_type = d1;
+ if (tree->n_op == op)
+ tree->n_type = d1;
/*
* PDP-11 special:
* replace a&b by a ANDN ~ b.
* This will be undone when in
* truth-value context.
*/
- if (tree->t_op!=AND)
+ if (tree->n_op!=AND)
return(tree);
#define ttree ((struct tnode *)tree)
/*
* long & pos-int is simpler
*/
- if ((ttree->tn_type==LONG || ttree->tn_type==UNLONG) && ttree->tn_tr2->t_op==ITOL
- && (((struct tnode *)ttree->tn_tr2)->tn_tr1->t_op==CON && ((struct cnode *)((struct tnode *)ttree->tn_tr2)->tn_tr1)->cn_value>=0
+ if ((ttree->tn_type==LONG || ttree->tn_type==UNLONG) && ttree->tn_tr2->n_op==ITOL
+ && (((struct tnode *)ttree->tn_tr2)->tn_tr1->n_op==CON && ((struct cnode *)((struct tnode *)ttree->tn_tr2)->tn_tr1)->cn_value>=0
|| uns(((struct tnode *)ttree->tn_tr2)->tn_tr1))) {
ttree->tn_type = UNSIGN;
t = ttree->tn_tr2;
ttree->tn_tr2 = ((struct tnode *)ttree->tn_tr2)->tn_tr1;
- ((struct tnode *)t)->tn_tr1 = (struct tree *)ttree;
- ttree->tn_tr1 = (struct tree *)tnode(LTOI, UNSIGN, ttree->tn_tr1, TNULL);
+ ((struct tnode *)t)->tn_tr1 = (struct node *)ttree;
+ ttree->tn_tr1 = (struct node *)tnode(LTOI, UNSIGN, ttree->tn_tr1, (struct node *)NULL);
return(optim(t));
}
/*
* Keep constants to the right
*/
- if ((ttree->tn_tr1->t_op==ITOL && ((struct tnode *)ttree->tn_tr1)->tn_tr1->t_op==CON)
- || ttree->tn_tr1->t_op==LCON) {
+ if ((ttree->tn_tr1->n_op==ITOL && ((struct tnode *)ttree->tn_tr1)->tn_tr1->n_op==CON)
+ || ttree->tn_tr1->n_op==LCON) {
t = ttree->tn_tr1;
ttree->tn_tr1 = ttree->tn_tr2;
ttree->tn_tr2 = t;
}
ttree->tn_op = ANDN;
op = ANDN;
- ttree->tn_tr2 = (struct tree *)tnode(COMPL, ttree->tn_tr2->t_type, ttree->tn_tr2, TNULL);
+ ttree->tn_tr2 = (struct node *)tnode(COMPL, ttree->tn_tr2->n_type, ttree->tn_tr2, (struct node *)NULL);
}
again:
ttree->tn_tr1 = optim(ttree->tn_tr1);
ttree->tn_tr2 = optim(ttree->tn_tr2);
if (ttree->tn_type == LONG || ttree->tn_type==UNLONG) {
- t = (struct tree *)lconst(ttree->tn_op, ttree->tn_tr1, ttree->tn_tr2);
+ t = (struct node *)lconst(ttree->tn_op, ttree->tn_tr1, ttree->tn_tr2);
if (t)
return(t);
}
if ((dope&RELAT) != 0) {
if ((d1=degree(ttree->tn_tr1)) < (d2=degree(ttree->tn_tr2))
- || d1==d2 && ttree->tn_tr1->t_op==NAME && ttree->tn_tr2->t_op!=NAME) {
+ || d1==d2 && ttree->tn_tr1->n_op==NAME && ttree->tn_tr2->n_op!=NAME) {
t = ttree->tn_tr1;
ttree->tn_tr1 = ttree->tn_tr2;
ttree->tn_tr2 = t;
ttree->tn_op = maprel[op-EQUAL];
}
- if (ttree->tn_tr1->t_type==CHAR && ttree->tn_tr2->t_op==CON
- && (dcalc(ttree->tn_tr1, 0) <= 12 || ttree->tn_tr1->t_op==STAR)
+ if (ttree->tn_tr1->n_type==CHAR && ttree->tn_tr2->n_op==CON
+ && (dcalc(ttree->tn_tr1, 0) <= 12 || ttree->tn_tr1->n_op==STAR)
&& ((struct cnode *)ttree->tn_tr2)->cn_value <= 127 && ((struct cnode *)ttree->tn_tr2)->cn_value >= 0)
- ttree->tn_tr2->t_type = CHAR;
+ ttree->tn_tr2->n_type = CHAR;
}
d1 = max(degree(ttree->tn_tr1), islong(ttree->tn_type));
d2 = max(degree(ttree->tn_tr2), 0);
*/
case FSELA:
#define Ftree ((struct fasgn *)ttree)
- if (Ftree->fa_tr2->t_op==CON && ((struct cnode *)Ftree->fa_tr2)->cn_value==0) {
+ if (Ftree->fa_tr2->n_op==CON && ((struct cnode *)Ftree->fa_tr2)->cn_value==0) {
Ftree->fa_op = ASAND;
((struct cnode *)Ftree->fa_tr2)->cn_value = ~Ftree->fa_mask;
- return(optim((struct tree *)Ftree));
+ return(optim((struct node *)Ftree));
}
- if (Ftree->fa_tr2->t_op==CON && Ftree->fa_mask==((struct cnode *)Ftree->fa_tr2)->cn_value) {
+ if (Ftree->fa_tr2->n_op==CON && Ftree->fa_mask==((struct cnode *)Ftree->fa_tr2)->cn_value) {
Ftree->fa_op = ASOR;
- return(optim((struct tree *)Ftree));
+ return(optim((struct node *)Ftree));
}
#undef Ftree
case DIVIDE:
case ASDIV:
case ASTIMES:
- if (ttree->tn_tr2->t_op==CON && ((struct cnode *)ttree->tn_tr2)->cn_value==1) {
+ if (ttree->tn_tr2->n_op==CON && ((struct cnode *)ttree->tn_tr2)->cn_value==1) {
if (op==PTOI)
- return(optim((struct tree *)tnode(LTOI,INT,paint(ttree->tn_tr1,LONG), TNULL)));
+ return(optim((struct node *)tnode(LTOI,INT,paint(ttree->tn_tr1,LONG), (struct node *)NULL)));
return(paint(ttree->tn_tr1, ttree->tn_type));
}
case MOD:
case ASMOD:
if ((uns(ttree->tn_tr1) || ttree->tn_op==PTOI) && ispow2(ttree))
- return((struct tree *)pow2(ttree));
+ return((struct node *)pow2(ttree));
if ((op==MOD||op==ASMOD) && ttree->tn_type==DOUBLE) {
error1("Floating %% not defined");
ttree->tn_type = INT;
d2 += 2 + regpanic;
panicposs++;
if (ttree->tn_type==LONG || ttree->tn_type==UNLONG)
- return(hardlongs((struct tree *)ttree));
+ return(hardlongs((struct node *)ttree));
if ((op==MOD || op==DIVIDE || op==ASMOD || op==ASDIV)
&& (uns(ttree->tn_tr1) || uns(ttree->tn_tr2))
- && (ttree->tn_tr2->t_op!=CON || ((struct cnode *)ttree->tn_tr2)->cn_value<=1)) {
+ && (ttree->tn_tr2->n_op!=CON || ((struct cnode *)ttree->tn_tr2)->cn_value<=1)) {
if (op>=ASDIV) {
ttree->tn_op += ASUDIV - ASDIV;
} else
case ASPLUS:
case ASMINUS:
- if (ttree->tn_tr2->t_op==CON && ((struct cnode *)ttree->tn_tr2)->cn_value==0)
+ if (ttree->tn_tr2->n_op==CON && ((struct cnode *)ttree->tn_tr2)->cn_value==0)
return(ttree->tn_tr1);
goto def;
case RSHIFT:
case ASRSH:
case ASLSH:
- if (ttree->tn_tr2->t_op==CON && ((struct cnode *)ttree->tn_tr2)->cn_value==0)
+ if (ttree->tn_tr2->n_op==CON && ((struct cnode *)ttree->tn_tr2)->cn_value==0)
return(paint(ttree->tn_tr1, ttree->tn_type));
/*
* PDP-11 special: turn right shifts into negative
}
if (op==LSHIFT||op==ASLSH)
goto constant;
- if (ttree->tn_tr2->t_op==CON && ((struct cnode *)ttree->tn_tr2)->cn_value==1
+ if (ttree->tn_tr2->n_op==CON && ((struct cnode *)ttree->tn_tr2)->cn_value==1
&& !uns(ttree->tn_tr1) && !uns(ttree->tn_tr2))
goto constant;
op += (LSHIFT-RSHIFT);
ttree->tn_op = op;
- ttree->tn_tr2 = (struct tree *)tnode(NEG, ttree->tn_tr2->t_type, ttree->tn_tr2, TNULL);
+ ttree->tn_tr2 = (struct node *)tnode(NEG, ttree->tn_tr2->n_type, ttree->tn_tr2, (struct node *)NULL);
if (uns(ttree->tn_tr1) || uns(ttree->tn_tr2)) {
if (ttree->tn_op==LSHIFT)
ttree->tn_op = ULSH;
goto again;
constant:
- if (ttree->tn_tr1->t_op==CON && ttree->tn_tr2->t_op==CON) {
+ if (ttree->tn_tr1->n_op==CON && ttree->tn_tr2->n_op==CON) {
_const(op, &((struct cnode *)ttree->tn_tr1)->cn_value, ((struct cnode *)ttree->tn_tr2)->cn_value, ttree->tn_type);
return(ttree->tn_tr1);
}
def:
default:
if (dope&RELAT) {
- if (ttree->tn_tr1->t_type==LONG || ttree->tn_tr1->t_type==UNLONG) /* long relations are a mess */
+ if (ttree->tn_tr1->n_type==LONG || ttree->tn_tr1->n_type==UNLONG) /* long relations are a mess */
d1 = 10;
- if (opdope1[ttree->tn_tr1->t_op]&RELAT && ttree->tn_tr2->t_op==CON
+ if (opdope1[ttree->tn_tr1->n_op]&RELAT && ttree->tn_tr2->n_op==CON
&& ((struct cnode *)ttree->tn_tr2)->cn_value==0) {
switch(op) {
case GREATEQ:
- return((struct tree *)&cone);
+ return((struct node *)&cone);
case LESS:
- return((struct tree *)&czero);
+ return((struct node *)&czero);
case LESSEQ:
case EQUAL:
- ttree->tn_tr1->t_op = notrel[ttree->tn_tr1->t_op-EQUAL];
+ ttree->tn_tr1->n_op = notrel[ttree->tn_tr1->n_op-EQUAL];
}
return(ttree->tn_tr1);
}
ttree->tn_degree = d1==d2? d1+islong(ttree->tn_type): max(d1, d2);
break;
}
- return((struct tree *)ttree);
+ return((struct node *)ttree);
}
/* in reality this can only be called with a struct tnode argument */
-struct tree *unoptim(tree) register struct tree *tree; {
- register struct tree *subtre, *p;
+struct node *unoptim(tree) register struct node *tree; {
+ register struct node *subtre, *p;
#define ttree ((struct tnode *)tree)
if (ttree==NULL)
return(NULL);
again:
- if (ttree->tn_op==AMPER && ttree->tn_tr1->t_op==STAR) {
+ if (ttree->tn_op==AMPER && ttree->tn_tr1->n_op==STAR) {
subtre = ((struct tnode *)ttree->tn_tr1)->tn_tr1;
- subtre->t_type = ttree->tn_type;
+ subtre->n_type = ttree->tn_type;
return(optim(subtre));
}
subtre = ttree->tn_tr1 = optim(ttree->tn_tr1);
case INCAFT:
case DECAFT:
- if (ttree->tn_type!=subtre->t_type)
+ if (ttree->tn_type!=subtre->n_type)
paint(subtre, ttree->tn_type);
break;
case ITOL:
- if (subtre->t_op==CON && subtre->t_type==INT && ((struct cnode *)subtre)->cn_value<0) {
+ if (subtre->n_op==CON && subtre->n_type==INT && ((struct cnode *)subtre)->cn_value<0) {
#undef ttree
#define csubtre ((struct cnode *)subtre)
tree = getblk(sizeof(struct lnode));
ltree->ln_op = LCON;
ltree->ln_type = LONG;
ltree->ln_lvalue = csubtre->cn_value;
- return((struct tree *)ltree);
+ return((struct node *)ltree);
#define ttree ((struct tnode *)tree)
#undef csubtre
#undef ltree
break;
case FTOI:
- if (uns((struct tree *)ttree)) {
+ if (uns((struct node *)ttree)) {
ttree->tn_op = FTOL;
ttree->tn_type = LONG;
- /*t*/tree = (struct tree *)tnode(LTOI, UNSIGN, (struct tree *)ttree, TNULL);
+ /*t*/tree = (struct node *)tnode(LTOI, UNSIGN, (struct node *)ttree, (struct node *)NULL);
}
break;
case LTOF:
- if (subtre->t_op==LCON) {
+ if (subtre->n_op==LCON) {
#undef ttree
#define lsubtre ((struct lnode *)subtre)
tree = getblk(sizeof(struct fnode));
#else
ftree->fn_fvalue = fp_long_to_double(lsubtre->ln_lvalue);
#endif
- return(optim((struct tree *)ftree));
+ return(optim((struct node *)ftree));
#define ttree ((struct tnode *)tree)
#undef lsubtre
#undef ftree
}
- if (subtre->t_type==UNLONG)
+ if (subtre->n_type==UNLONG)
ttree->tn_op = ULTOF;
break;
case ITOF:
- if (subtre->t_op==CON) {
+ if (subtre->n_op==CON) {
#undef ttree
#define csubtre ((struct cnode *)subtre)
tree = getblk(sizeof(struct fnode));
ftree->fn_type = DOUBLE;
ftree->fn_value = isn1++;
#ifdef pdp11
- if (uns((struct tree *)subtre))
+ if (uns((struct node *)subtre))
ftree->fn_fvalue = (_UNSIGNED_INT)csubtre->cn_value;
else
ftree->fn_fvalue = csubtre->cn_value;
#else
/* revisit the unsigned case */
- if (uns((struct tree *)subtre))
+ if (uns((struct node *)subtre))
ftree->fn_fvalue = fp_long_to_double((_LONG)(_UNSIGNED_INT)csubtre->cn_value);
else
ftree->fn_fvalue = fp_int_to_double(csubtre->cn_value);
#endif
- return(optim((struct tree *)ftree));
+ return(optim((struct node *)ftree));
#define ttree ((struct tnode *)tree)
#undef csubtre
#undef ftree
}
if (uns(subtre)) {
- ttree->tn_tr1 = (struct tree *)tnode(ITOL, LONG, subtre, TNULL);
+ ttree->tn_tr1 = (struct node *)tnode(ITOL, LONG, subtre, (struct node *)NULL);
ttree->tn_op = LTOF;
- return(optim((struct tree *)ttree));
+ return(optim((struct node *)ttree));
}
break;
/*
* Sign-extend PDP-11 characters
*/
- if (subtre->t_op==CON) {
+ if (subtre->n_op==CON) {
#define csubtre ((struct cnode *)subtre)
csubtre->cn_type = ttree->tn_type;
csubtre->cn_value = (char)csubtre->cn_value;
- return((struct tree *)csubtre);
+ return((struct node *)csubtre);
#undef csubtre
- } else if (subtre->t_op==NAME && ttree->tn_type==INT) {
- subtre->t_type = CHAR;
+ } else if (subtre->n_op==NAME && ttree->tn_type==INT) {
+ subtre->n_type = CHAR;
return(subtre);
}
break;
case LTOI:
- switch (subtre->t_op) {
+ switch (subtre->n_op) {
case LCON:
#define csubtre ((struct cnode *)subtre)
csubtre->cn_op = CON;
csubtre->cn_type = ttree->tn_type;
csubtre->cn_value = ((struct lnode *)csubtre)->ln_lvalue;
- return((struct tree *)csubtre);
+ return((struct node *)csubtre);
#undef csubtre
case NAME:
#define nsubtre ((struct nnode *)subtre)
nsubtre->nn_offset += 2;
nsubtre->nn_type = ttree->tn_type;
- return((struct tree *)nsubtre);
+ return((struct node *)nsubtre);
#undef nsubtre
case STAR:
#define tsubtre ((struct tnode *)subtre)
tsubtre->tn_type = ttree->tn_type;
- tsubtre->tn_tr1->t_type = ttree->tn_type+PTR;
- tsubtre->tn_tr1 = (struct tree *)tnode(PLUS, ttree->tn_type, tsubtre->tn_tr1, (struct tree *)tconst(2, INT));
- return(optim((struct tree *)tsubtre));
+ tsubtre->tn_tr1->n_type = ttree->tn_type+PTR;
+ tsubtre->tn_tr1 = (struct node *)tnode(PLUS, ttree->tn_type, tsubtre->tn_tr1, (struct node *)tconst(2, INT));
+ return(optim((struct node *)tsubtre));
#undef tsubtre
case ITOL:
case OR:
case EXOR:
#define tsubtre ((struct tnode *)subtre)
- tsubtre->tn_tr2 = (struct tree *)tnode(LTOI, ttree->tn_type, tsubtre->tn_tr2, TNULL);
+ tsubtre->tn_tr2 = (struct node *)tnode(LTOI, ttree->tn_type, tsubtre->tn_tr2, (struct node *)NULL);
case NEG:
case COMPL:
- tsubtre->tn_tr1 = (struct tree *)tnode(LTOI, ttree->tn_type, tsubtre->tn_tr1, TNULL);
+ tsubtre->tn_tr1 = (struct node *)tnode(LTOI, ttree->tn_type, tsubtre->tn_tr1, (struct node *)NULL);
tsubtre->tn_type = ttree->tn_type;
- return(optim((struct tree *)tsubtre));
+ return(optim((struct node *)tsubtre));
#undef tsubtre
}
break;
ttree->tn_tr2->tn_tr1 = subtre;
ttree->tn_tr2->tn_op = RSHIFT;
ttree->tn_tr1->cn_value = (1 << ttree->tn_tr1->cn_value) - 1;*/
- ttree->tn_tr1 = (struct tree *)tconst((1 << ((struct FS *)ttree->tn_tr2)->flen) - 1, INT);
- ttree->tn_tr2 = (struct tree *)tnode(RSHIFT, INT, subtre, (struct tree *)tconst(((struct FS *)ttree->tn_tr2)->bitoffs, INT));
- return(optim((struct tree *)ttree));
+ ttree->tn_tr1 = (struct node *)tconst((1 << ((struct FS *)ttree->tn_tr2)->flen) - 1, INT);
+ ttree->tn_tr2 = (struct node *)tnode(RSHIFT, INT, subtre, (struct node *)tconst(((struct FS *)ttree->tn_tr2)->bitoffs, INT));
+ return(optim((struct node *)ttree));
case FSELR:
ttree->tn_op = LSHIFT;
ttree->tn_tr2 = ttree->tn_tr2->tn_tr2;
ttree->tn_tr1->tn_tr2 = subtre;
ttree->tn_tr1->tn_tr1->cn_value = (1 << ttree->tn_tr1->tn_tr1->cn_value) -1;*/
- ttree->tn_tr1 = (struct tree *)tnode(AND, INT, (struct tree *)tconst((1 << ((struct FS *)ttree->tn_tr2)->flen) - 1, INT), subtre);
- ttree->tn_tr2 = (struct tree *)tconst(((struct FS *)ttree->tn_tr2)->bitoffs, INT);
- return(optim((struct tree *)ttree));
+ ttree->tn_tr1 = (struct node *)tnode(AND, INT, (struct node *)tconst((1 << ((struct FS *)ttree->tn_tr2)->flen) - 1, INT), subtre);
+ ttree->tn_tr2 = (struct node *)tconst(((struct FS *)ttree->tn_tr2)->bitoffs, INT);
+ return(optim((struct node *)ttree));
case AMPER:
- if (subtre->t_op==STAR)
+ if (subtre->n_op==STAR)
return(((struct tnode *)subtre)->tn_tr1);
- if (subtre->t_op==NAME && ((struct nnode *)subtre)->nn_class == OFFS) {
-#define nsubtre ((struct nnode *)subtre)
- nsubtre->nn_type = ttree->tn_type;
+ if (subtre->n_op==NAME && ((struct nnode *)subtre)->nn_class == OFFS) {
+#define locnsubtre ((struct locnnode *)subtre)
+ locnsubtre->locnn_type = ttree->tn_type;
#undef ttree
#define ctree ((struct cnode *)tree)
ctree->cn_op = CON;
ctree->cn_type = INT;
/* the below seems to have been an oversight, probably a harmless one */
/* ctree->cn_degree = 0;*/
- ctree->cn_value = nsubtre->nn_offset;
- nsubtre->nn_class = REG;
- nsubtre->nn_nloc = nsubtre->nn_regno;
- nsubtre->nn_offset = 0;
- return(optim((struct tree *)tnode(PLUS, nsubtre->nn_type, (struct tree *)nsubtre, (struct tree *)ctree)));
+ ctree->cn_value = locnsubtre->locnn_offset;
+ locnsubtre->locnn_class = REG;
+ locnsubtre->locnn_nloc = locnsubtre->locnn_regno;
+ locnsubtre->locnn_offset = 0;
+ return(optim((struct node *)tnode(PLUS, locnsubtre->locnn_type, (struct node *)locnsubtre, (struct node *)ctree)));
#undef nsubtre
#define ttree ((struct tnode *)tree)
#undef ctree
}
- if (subtre->t_op==LOAD) {
+ if (subtre->n_op==LOAD) {
ttree->tn_tr1 = ((struct tnode *)subtre)->tn_tr1;
goto again;
}
break;
case STAR:
- if (subtre->t_op==AMPER) {
+ if (subtre->n_op==AMPER) {
#define tsubtre ((struct tnode *)subtre)
- tsubtre->tn_tr1->t_type = ttree->tn_type;
+ tsubtre->tn_tr1->n_type = ttree->tn_type;
return(tsubtre->tn_tr1);
#undef tsubtre
}
if (ttree->tn_type==STRUCT)
break;
- if (subtre->t_op==NAME && ((struct nnode *)subtre)->nn_class==REG) {
-#define nsubtre ((struct nnode *)subtre)
- nsubtre->nn_type = ttree->tn_type;
- nsubtre->nn_class = OFFS;
- nsubtre->nn_regno = nsubtre->nn_nloc;
- return((struct tree *)nsubtre);
-#undef nsubtre
+ if (subtre->n_op==NAME && ((struct nnode *)subtre)->nn_class==REG) {
+#define locnsubtre ((struct locnnode *)subtre)
+ locnsubtre->locnn_type = ttree->tn_type;
+ locnsubtre->locnn_class = OFFS;
+ locnsubtre->locnn_regno = locnsubtre->locnn_nloc;
+ return((struct node *)locnsubtre);
+#undef locnsubtre
}
- if ((subtre->t_op==INCAFT||subtre->t_op==DECBEF)
+ if ((subtre->n_op==INCAFT||subtre->n_op==DECBEF)
&& ttree->tn_type!=LONG && ttree->tn_type!=UNLONG
- && (p = ((struct tnode *)subtre)->tn_tr1)->t_op==NAME && ((struct nnode *)p)->nn_class==REG && ((struct nnode *)p)->nn_type==((struct tnode *)subtre)->tn_type) {
+ && (p = ((struct tnode *)subtre)->tn_tr1)->n_op==NAME && ((struct nnode *)p)->nn_class==REG && ((struct nnode *)p)->nn_type==((struct tnode *)subtre)->tn_type) {
#define tsubtre ((struct tnode *)subtre)
#define np ((struct nnode *)p)
np->nn_type = ttree->tn_type;
np->nn_op = tsubtre->tn_op==INCAFT? AUTOI: AUTOD;
- return((struct tree *)p);
+ return((struct node *)p);
#undef tsubtre
#undef np
}
- if (subtre->t_op==PLUS && (p = ((struct tnode *)subtre)->tn_tr1)->t_op==NAME && ((struct nnode *)p)->nn_class==REG) {
+ if (subtre->n_op==PLUS && (p = ((struct tnode *)subtre)->tn_tr1)->n_op==NAME && ((struct nnode *)p)->nn_class==REG) {
#define tsubtre ((struct tnode *)subtre)
-#define np ((struct nnode *)p)
- if (tsubtre->tn_tr2->t_op==CON) {
- np->nn_offset += ((struct cnode *)tsubtre->tn_tr2)->cn_value;
- np->nn_class = OFFS;
- np->nn_type = ttree->tn_type;
- np->nn_regno = np->nn_nloc;
- return((struct tree *)np);
+#define locnp ((struct locnnode *)p)
+ if (tsubtre->tn_tr2->n_op==CON) {
+ locnp->locnn_offset += ((struct cnode *)tsubtre->tn_tr2)->cn_value;
+ locnp->locnn_class = OFFS;
+ locnp->locnn_type = ttree->tn_type;
+ locnp->locnn_regno = locnp->locnn_nloc;
+ return((struct node *)locnp);
}
- if (tsubtre->tn_tr2->t_op==AMPER) {
+ if (tsubtre->tn_tr2->n_op==AMPER) {
#undef tsubtre
subtre = ((struct tnode *)((struct tnode *)subtre)->tn_tr2)->tn_tr1;
- if (subtre->t_op != NAME) abort();
+ if (subtre->n_op != NAME) abort();
#define nsubtre ((struct nnode *)subtre)
nsubtre->nn_class += XOFFS-EXTERN;
- nsubtre->nn_regno = np->nn_nloc;
+ nsubtre->nn_regno = locnp->locnn_nloc;
nsubtre->nn_type = ttree->tn_type;
- return((struct tree *)nsubtre);
+ return((struct node *)nsubtre);
#define tsubtre ((struct tnode *)subtre)
#undef nsubtre
}
#undef tsubtre
-#undef np
+#undef locnp
}
- if (subtre->t_op==MINUS && (p = ((struct tnode *)subtre)->tn_tr1)->t_op==NAME && ((struct nnode *)p)->nn_class==REG
- && ((struct tnode *)subtre)->tn_tr2->t_op==CON) {
+ if (subtre->n_op==MINUS && (p = ((struct tnode *)subtre)->tn_tr1)->n_op==NAME && ((struct nnode *)p)->nn_class==REG
+ && ((struct tnode *)subtre)->tn_tr2->n_op==CON) {
#define tsubtre ((struct tnode *)subtre)
-#define np ((struct nnode *)p)
- np->nn_offset -= ((struct cnode *)tsubtre->tn_tr2)->cn_value;
- np->nn_class = OFFS;
- np->nn_type = ttree->tn_type;
- np->nn_regno = np->nn_nloc;
- return((struct tree *)np);
+#define locnp ((struct locnnode *)p)
+ locnp->locnn_offset -= ((struct cnode *)tsubtre->tn_tr2)->cn_value;
+ locnp->locnn_class = OFFS;
+ locnp->locnn_type = ttree->tn_type;
+ locnp->locnn_regno = locnp->locnn_nloc;
+ return((struct node *)locnp);
#undef tsubtre
-#undef np
+#undef locnp
}
break;
case EXCLA:
#undef ttree
- if ((opdope1[subtre->t_op]&RELAT)==0)
+ if ((opdope1[subtre->n_op]&RELAT)==0)
break;
tree = subtre;
- tree->t_op = notrel[tree->t_op-EQUAL];
+ tree->n_op = notrel[tree->n_op-EQUAL];
break;
#define ttree ((struct tnode *)tree)
case COMPL:
if (ttree->tn_type==CHAR)
ttree->tn_type = INT;
- if (subtre->t_op == COMPL)
+ if (subtre->n_op == COMPL)
return(paint(((struct tnode *)subtre)->tn_tr1, ttree->tn_type));
- if (subtre->t_op==CON) {
+ if (subtre->n_op==CON) {
#define csubtre ((struct cnode *)subtre)
csubtre->cn_value = ~csubtre->cn_value;
- return(paint((struct tree *)csubtre, ttree->tn_type));
+ return(paint((struct node *)csubtre, ttree->tn_type));
#undef csubtre
}
- if (subtre->t_op==LCON) {
+ if (subtre->n_op==LCON) {
#define lsubtre ((struct lnode *)subtre)
lsubtre->ln_lvalue = ~lsubtre->ln_lvalue;
- return((struct tree *)lsubtre);
+ return((struct node *)lsubtre);
#undef lsubtre
}
- if (subtre->t_op==ITOL) {
+ if (subtre->n_op==ITOL) {
#define tsubtre ((struct tnode *)subtre)
- if (tsubtre->tn_tr1->t_op==CON) {
+ if (tsubtre->tn_tr1->n_op==CON) {
#undef ttree
tree = getblk(sizeof(struct lnode));
#define ltree ((struct lnode *)tree)
else
ltree->ln_lvalue =
~((struct cnode *)tsubtre->tn_tr1)->cn_value;
- return((struct tree *)ltree);
+ return((struct node *)ltree);
#define ttree ((struct tnode *)tree)
#undef ltree
}
if (uns(tsubtre->tn_tr1))
break;
tsubtre->tn_op = ttree->tn_op;
- tsubtre->tn_type = tsubtre->tn_tr1->t_type;
+ tsubtre->tn_type = tsubtre->tn_tr1->n_type;
ttree->tn_op = ITOL;
ttree->tn_type = LONG;
goto again;
case NEG:
if (ttree->tn_type==CHAR)
ttree->tn_type = INT;
- if (subtre->t_op == NEG)
+ if (subtre->n_op == NEG)
return(paint(((struct tnode *)subtre)->tn_tr1, ttree->tn_type));
- if (subtre->t_op==CON) {
+ if (subtre->n_op==CON) {
#define csubtre ((struct cnode *)subtre)
csubtre->cn_value = -csubtre->cn_value;
- return(paint((struct tree *)csubtre, ttree->tn_type));
+ return(paint((struct node *)csubtre, ttree->tn_type));
#undef csubtre
}
- if (subtre->t_op==LCON) {
+ if (subtre->n_op==LCON) {
#define lsubtre ((struct lnode *)subtre)
lsubtre->ln_lvalue = -lsubtre->ln_lvalue;
- return((struct tree *)lsubtre);
+ return((struct node *)lsubtre);
#undef lsubtre
}
- if (subtre->t_op==ITOL && ((struct tnode *)subtre)->tn_tr1->t_op==CON) {
+ if (subtre->n_op==ITOL && ((struct tnode *)subtre)->tn_tr1->n_op==CON) {
#define tsubtre ((struct tnode *)subtre)
#undef ttree
tree = getblk(sizeof(struct lnode));
((struct cnode *)tsubtre->tn_tr1)->cn_value;
else
ltree->ln_lvalue = -((struct cnode *)tsubtre->tn_tr1)->cn_value;
- return((struct tree *)ltree);
+ return((struct node *)ltree);
#undef tsubtre
#define ttree ((struct tnode *)tree)
#undef ltree
/*
* PDP-11 FP negation
*/
- if (subtre->t_op==SFCON) {
+ if (subtre->n_op==SFCON) {
#define fsubtre ((struct fnode *)subtre)
fsubtre->fn_value ^= 0100000;
#ifdef pdp11
#else
fsubtre->fn_fvalue = fp_neg(fsubtre->fn_fvalue);
#endif
- return((struct tree *)fsubtre);
+ return((struct node *)fsubtre);
#undef fsubtre
}
- if (subtre->t_op==FCON) {
+ if (subtre->n_op==FCON) {
#define fsubtre ((struct fnode *)subtre)
#ifdef pdp11
fsubtre->fn_fvalue = -fsubtre->fn_fvalue;
#else
fsubtre->fn_fvalue = fp_neg(fsubtre->fn_fvalue);
#endif
- return((struct tree *)fsubtre);
+ return((struct node *)fsubtre);
#undef fsubtre
}
break;
}
#undef ttree
- if ((opdope1[tree->t_op]&LEAF)==0)
+ if ((opdope1[tree->n_op]&LEAF)==0)
#define ttree ((struct tnode *)tree)
ttree->tn_degree = max(islong(ttree->tn_type), degree(subtre));
#undef ttree
- return((struct tree *)tree);
+ return((struct node *)tree);
}
/*
* Pure assignment is handled specially.
*/
-/* note that t->tn_tr1->t_op == FSEL */
-struct tree *lvfield(t) register struct tnode *t; {
+/* note that t->tn_tr1->n_op == FSEL */
+struct node *lvfield(t) register struct tnode *t; {
register struct tnode *t1;
register struct fasgn *t2;
/*t=ASANDN(mos,arg)*/
t1->tn_tr1 = t->tn_tr2;
/*t1=FSELR(arg,COMMA(flen,bitoffs))*/
- t->tn_tr2 = (struct tree *)t1;
+ t->tn_tr2 = (struct node *)t1;
/*t=ASANDN(mos,FSELR(arg,COMMA(flen,bitoffs)))*/
t1 = (struct tnode *)t1->tn_tr2;
/*t1=COMMA(flen,bitoffs)*/
- /*t1 = (struct tree *)tnode(COMMA, INT, (struct tree *)tconst(t1->tn_tr1->cn_value, INT),
- (struct tree *)tconst(t1->tn_tr2->cn_value, INT));*/
+ /*t1 = (struct node *)tnode(COMMA, INT, (struct node *)tconst(t1->tn_tr1->cn_value, INT),
+ (struct node *)tconst(t1->tn_tr2->cn_value, INT));*/
/* t1 formerly pointed to a COMMA node holding 2 constants */
/* now it contains its pass 0 value which is the field descriptor */
#define FSt1 ((struct FS *)t1)
- return(optim((struct tree *)tnode(FSELT, UNSIGN, (struct tree *)t, (struct tree *)FSt1)));
+ return(optim((struct node *)tnode(FSELT, UNSIGN, (struct node *)t, (struct node *)FSt1)));
#undef FSt1
}
error1("Unimplemented field operator");
- return((struct tree *)t);
+ return((struct node *)t);
}
#if 0 /* now moved to c1.h */
int nextl;
int nextn;
struct tnode *nlist[LSTSIZ];
- struct tree *llist[LSTSIZ+1];
+ struct node *llist[LSTSIZ+1];
};
#endif
/* in reality this can only be called with a struct tnode argument */
-struct tree *acommute(tree) register struct tree *tree; {
+struct node *acommute(tree) register struct node *tree; {
struct acl acl;
int d, i, op, flt, d1, type;
- register struct tree *t1, **t2;
- struct tree *t;
+ register struct node *t1, **t2;
+ struct node *t;
#define ttree ((struct tnode *)tree)
acl.nextl = 0;
acl.nextn = 0;
op = ttree->tn_op;
type = ttree->tn_type;
- flt = isfloat((struct tree *)ttree);
- insert(op, (struct tree *)ttree, &acl);
+ flt = isfloat((struct node *)ttree);
+ insert(op, (struct node *)ttree, &acl);
acl.nextl--;
t2 = &acl.llist[acl.nextl];
if (!flt) {
/* put constants together */
for (i=acl.nextl; i>0; i--) {
- d = t2[-1]->t_type==UNSIGN||t2[0]->t_type==UNSIGN?UNSIGN:INT;
- if (t2[0]->t_op==CON && t2[-1]->t_op==CON) {
+ d = t2[-1]->n_type==UNSIGN||t2[0]->n_type==UNSIGN?UNSIGN:INT;
+ if (t2[0]->n_op==CON && t2[-1]->n_op==CON) {
acl.nextl--;
t2--;
_const(op, &((struct cnode *)t2[0])->cn_value, ((struct cnode *)t2[1])->cn_value, d);
- t2[0]->t_type = d;
- } else if (t = (struct tree *)lconst(op, t2[-1], t2[0])) {
+ t2[0]->n_type = d;
+ } else if (t = (struct node *)lconst(op, t2[-1], t2[0])) {
acl.nextl--;
t2--;
t2[0] = t;
}
if (op==PLUS || op==OR) {
/* toss out "+0" */
- /* isconstant() may return fnode, so need cn_value compatible with fn_value */
- if (acl.nextl>0 && ((t1 = isconstant(*t2)) && ((struct cnode *)t1)->cn_value==0
- || (*t2)->t_op==LCON && ((struct lnode *)*t2)->ln_lvalue==0)) {
+ /* note: cn_value == 0 means a constant value of 0 (CON) or 0. (SFCON) */
+ if (acl.nextl>0 && ((t1 = (struct node *)isconstant(*t2)) && ((struct cnode *)t1)->cn_value==0
+ || (*t2)->n_op==LCON && ((struct lnode *)*t2)->ln_lvalue==0)) {
acl.nextl--;
t2--;
}
if (acl.nextl <= 0) {
- if ((*t2)->t_type==CHAR || (*t2)->t_type==UNCHAR)
- *t2 = (struct tree *)tnode(LOAD, ttree->tn_type, *t2, TNULL);
- (*t2)->t_type = ttree->tn_type;
+ if ((*t2)->n_type==CHAR || (*t2)->n_type==UNCHAR)
+ *t2 = (struct node *)tnode(LOAD, ttree->tn_type, *t2, (struct node *)NULL);
+ (*t2)->n_type = ttree->tn_type;
return(*t2);
}
/* subsume constant in "&x+c" */
- if (op==PLUS && t2[0]->t_op==CON && t2[-1]->t_op==AMPER) {
+ if (op==PLUS && t2[0]->n_op==CON && t2[-1]->n_op==AMPER) {
t2--;
((struct nnode *)((struct tnode *)t2[0])->tn_tr1)->nn_offset += ((struct cnode *)t2[1])->cn_value;
acl.nextl--;
}
} else if (op==TIMES || op==AND) {
t1 = acl.llist[acl.nextl];
- if (t1->t_op==CON) {
+ if (t1->n_op==CON) {
#define ct1 ((struct cnode *)t1)
if (ct1->cn_value==0) {
for (i=0; i<acl.nextl; i++)
if (sideeffects(acl.llist[i]))
break;
if (i==acl.nextl)
- return((struct tree *)ct1);
+ return((struct node *)ct1);
}
if (op==TIMES && ct1->cn_value==1 && acl.nextl>0)
if (--acl.nextl <= 0) {
t1 = acl.llist[0];
- if (uns((struct tree *)ttree))
+ if (uns((struct node *)ttree))
paint(t1, ttree->tn_type);
return(t1);
}
if (op==PLUS && !flt)
distrib(&acl);
tree = *(t2 = &acl.llist[0]);
- d = max(degree(tree), islong(tree->t_type));
+ d = max(degree(tree), islong(tree->n_type));
if (op==TIMES && !flt) {
d += regpanic+1;
panicposs++;
}
for (i=0; i<acl.nextl; i++) {
- t1 = (struct tree *)acl.nlist[i];
+ t1 = (struct node *)acl.nlist[i];
#define tt1 ((struct tnode *)t1)
tt1->tn_tr2 = t = *++t2;
d1 = degree(t);
* rt. op of ^ must be in a register.
*/
if (op==EXOR && dcalc(t, 0)<=12) {
- tt1->tn_tr2 = t = optim((struct tree *)tnode(LOAD, t->t_type, t, TNULL));
+ tt1->tn_tr2 = t = optim((struct node *)tnode(LOAD, t->n_type, t, (struct node *)NULL));
/* in this case optim() is guaranteed to return a struct tnode */
- if (opdope1[t->t_op] & LEAF) abort();
+ if (opdope1[t->n_op] & LEAF) abort();
d1 = ((struct tnode *)t)->tn_degree;
}
tt1->tn_degree = d = d==d1? d+islong(tt1->tn_type): max(d, d1);
tt1->tn_tr1 = tree;
- tree = (struct tree *)tt1;
- if (tree->t_type==LONG || tree->t_type==UNLONG) {
- if (tree->t_op==TIMES)
+ tree = (struct node *)tt1;
+ if (tree->n_type==LONG || tree->n_type==UNLONG) {
+ if (tree->n_op==TIMES)
tree = hardlongs(tree);
/* assume isconstant() returns cnode (CON) not fnode (SFCON) since long */
- else if (tree->t_op==PLUS && (t = isconstant(((struct tnode *)tree)->tn_tr1))
+ else if (tree->n_op==PLUS && (t = (struct node *)isconstant(((struct tnode *)tree)->tn_tr1))
&& ((struct cnode *)t)->cn_value < 0 && !uns(t)) {
#define ttree ((struct tnode *)tree)
ttree->tn_op = MINUS;
}
#undef tt1
}
- if (tree->t_op==TIMES && ispow2((struct tnode *)tree))
+ if (tree->n_op==TIMES && ispow2((struct tnode *)tree))
#define ttree ((struct tnode *)tree)
ttree->tn_degree = max(degree(ttree->tn_tr1), islong(ttree->tn_type));
#undef ttree
return(tree);
}
-int sideeffects(tp) register struct tree *tp; {
+int sideeffects(tp) register struct node *tp; {
register int dope;
if (tp==NULL)
return(0);
- dope = opdope1[tp->t_op];
+ dope = opdope1[tp->n_op];
if (dope&LEAF) {
- if (tp->t_op==AUTOI || tp->t_op==AUTOD)
+ if (tp->n_op==AUTOI || tp->n_op==AUTOD)
return(1);
return(0);
}
* fewest divisors. Reduce this pair to c1*(y+c2*x)
* and iterate until no reductions occur.
*/
- register struct tree **p1, **p2;
- struct tree *t;
+ register struct node **p1, **p2;
+ struct node *t;
int ndmaj, ndmin;
- struct tree **dividend, **divisor;
- struct tree **maxnod, **mindiv;
+ struct node **dividend, **divisor;
+ struct node **maxnod, **mindiv;
loop:
maxnod = &list->llist[list->nextl];
ndmaj = 1000;
dividend = 0;
for (p1 = list->llist; p1 <= maxnod; p1++) {
- if ((*p1)->t_op!=TIMES || ((struct tnode *)*p1)->tn_tr2->t_op!=CON)
+ if ((*p1)->n_op!=TIMES || ((struct tnode *)*p1)->tn_tr2->n_op!=CON)
continue;
ndmin = 0;
for (p2 = list->llist; p2 <= maxnod; p2++) {
- if (p1==p2 || (*p2)->t_op!=TIMES || ((struct tnode *)*p2)->tn_tr2->t_op!=CON)
+ if (p1==p2 || (*p2)->n_op!=TIMES || ((struct tnode *)*p2)->tn_tr2->n_op!=CON)
continue;
if (((struct cnode *)((struct tnode *)*p1)->tn_tr2)->cn_value == ((struct cnode *)((struct tnode *)*p2)->tn_tr2)->cn_value) {
((struct tnode *)*p2)->tn_tr2 = ((struct tnode *)*p1)->tn_tr1;
((struct tnode *)*p2)->tn_op = PLUS;
- ((struct tnode *)*p1)->tn_tr1 = (struct tree *)((struct tnode *)*p2);
+ ((struct tnode *)*p1)->tn_tr1 = (struct node *)((struct tnode *)*p2);
*p1 = optim(*p1);
squash(p2, maxnod);
list->nextl--;
p2 = divisor;
tt->tn_op = PLUS;
tt->tn_type = ((struct tnode *)*p1)->tn_type;
- tt->tn_tr1 = (struct tree *)((struct tnode *)*p1);
+ tt->tn_tr1 = (struct node *)((struct tnode *)*p1);
tt->tn_tr2 = ((struct tnode *)*p2)->tn_tr1;
((struct cnode *)((struct tnode *)*p1)->tn_tr2)->cn_value /= ((struct cnode *)((struct tnode *)*p2)->tn_tr2)->cn_value;
- ((struct tnode *)*p2)->tn_tr1 = (struct tree *)tt;
+ ((struct tnode *)*p2)->tn_tr1 = (struct node *)tt;
#undef tt
t = optim(*p2);
if (p1 < p2) {
goto loop;
}
-void squash(p, maxp) struct tree **p; struct tree **maxp; {
- register struct tree **np;
+void squash(p, maxp) struct node **p; struct node **maxp; {
+ register struct node **np;
for (np = p; np < maxp; np++)
*np = *(np+1);
error1("C error: const");
}
-struct lnode *lconst(op, lp, rp) int op; register struct tree *lp; register struct tree *rp; {
+struct lnode *lconst(op, lp, rp) int op; register struct node *lp; register struct node *rp; {
_UNSIGNED_LONG l, r;
- if (lp->t_op==LCON)
+ if (lp->n_op==LCON)
l = ((struct lnode *)lp)->ln_lvalue;
- else if (lp->t_op==ITOL && ((struct tnode *)lp)->tn_tr1->t_op==CON) {
+ else if (lp->n_op==ITOL && ((struct tnode *)lp)->tn_tr1->n_op==CON) {
#define tlp ((struct tnode *)lp)
- if (tlp->tn_tr1->t_type==INT)
+ if (tlp->tn_tr1->n_type==INT)
l = ((struct cnode *)tlp->tn_tr1)->cn_value;
else
l = (_UNSIGNED_INT)((struct cnode *)tlp->tn_tr1)->cn_value;
#undef tlp
} else
return(0);
- if (rp->t_op==LCON)
+ if (rp->n_op==LCON)
r = ((struct lnode *)rp)->ln_lvalue;
- else if (rp->t_op==ITOL && ((struct tnode *)rp)->tn_tr1->t_op==CON) {
+ else if (rp->n_op==ITOL && ((struct tnode *)rp)->tn_tr1->n_op==CON) {
#define trp ((struct tnode *)rp)
- if (trp->tn_tr1->t_type==INT)
+ if (trp->tn_tr1->n_type==INT)
r = ((struct cnode *)trp->tn_tr1)->cn_value;
else
r = (_UNSIGNED_INT)((struct cnode *)trp->tn_tr1)->cn_value;
default:
return(0);
}
- if (lp->t_op==LCON) {
+ if (lp->n_op==LCON) {
#define llp ((struct lnode *)lp)
llp->ln_lvalue = l;
return(llp);
#undef llp
}
-void insert(op, tree, list) int op; register struct tree *tree; register struct acl *list; {
+void insert(op, tree, list) int op; register struct node *tree; register struct acl *list; {
register int d;
int d1, i;
- struct tree *t;
+ struct node *t;
ins:
- if (tree->t_op != op)
+ if (tree->n_op != op)
tree = optim(tree);
- if (tree->t_op == op && list->nextn < LSTSIZ-2) {
+ if (tree->n_op == op && list->nextn < LSTSIZ-2) {
#define ttree ((struct tnode *)tree)
list->nlist[list->nextn++] = ttree;
insert(op, ttree->tn_tr1, list);
}
if (!isfloat(tree)) {
/* c1*(x+c2) -> c1*x+c1*c2 */
- if ((tree->t_op==TIMES||tree->t_op==LSHIFT)
- && ((struct tnode *)tree)->tn_tr2->t_op==CON && ((struct cnode *)((struct tnode *)tree)->tn_tr2)->cn_value>0
- && ((struct tnode *)tree)->tn_tr1->t_op==PLUS && ((struct tnode *)((struct tnode *)tree)->tn_tr1)->tn_tr2->t_op==CON) {
+ if ((tree->n_op==TIMES||tree->n_op==LSHIFT)
+ && ((struct tnode *)tree)->tn_tr2->n_op==CON && ((struct cnode *)((struct tnode *)tree)->tn_tr2)->cn_value>0
+ && ((struct tnode *)tree)->tn_tr1->n_op==PLUS && ((struct tnode *)((struct tnode *)tree)->tn_tr1)->tn_tr2->n_op==CON) {
#define ttree ((struct tnode *)tree)
d = ((struct cnode *)ttree->tn_tr2)->cn_value;
if (ttree->tn_op==TIMES)
list->llist[list->nextl++] = tree;
}
-struct tnode *tnode(op, type, tr1, tr2) int op; int type; struct tree *tr1; struct tree *tr2; {
+struct tnode *tnode(op, type, tr1, tr2) int op; int type; struct node *tr1; struct node *tr2; {
register struct tnode *p;
p = (struct tnode *)getblk(sizeof(struct tnode));
return(p);
}
-struct tree *getblk(size) int size; {
+struct node *getblk(size) int size; {
#if 1
- return (struct tree *)Tblock(size);
+ return (struct node *)Tblock(size);
#else
- register struct tree *p;
+ register struct node *p;
if (size&01)
size++;
- p = (struct tree *)curbase;
+ p = (struct node *)curbase;
if ((curbase += size) >= coremax) {
#ifdef pdp11
if (sbrk(1024) == (char *)-1) {
return(1);
}
-struct tree *isconstant(t) register struct tree *t; {
- if (t->t_op==CON || t->t_op==SFCON)
- return(t);
- if (t->t_op==ITOL && ((struct tnode *)t)->tn_tr1->t_op==CON)
- return(((struct tnode *)t)->tn_tr1);
+/* returns a struct cnode, may be a struct fnode containing struct cnode */
+struct cnode *isconstant(t) register struct node *t; {
+ if (t->n_op==CON || t->n_op==SFCON)
+ return((struct cnode *)t);
+ if (t->n_op==ITOL && ((struct tnode *)t)->tn_tr1->n_op==CON)
+ return((struct cnode *)((struct tnode *)t)->tn_tr1);
return(NULL);
}
-struct tree *hardlongs(t) register struct tree *t; {
- switch(t->t_op) {
+struct node *hardlongs(t) register struct node *t; {
+ switch(t->n_op) {
case TIMES:
case DIVIDE:
tt->tn_op += ULASTIMES-ASTIMES;
else
tt->tn_op += LASTIMES-ASTIMES;
- tt->tn_tr1 = (struct tree *)tnode(AMPER, LONG+PTR, tt->tn_tr1, TNULL);
+ tt->tn_tr1 = (struct node *)tnode(AMPER, LONG+PTR, tt->tn_tr1, (struct node *)NULL);
break;
#undef tt
/*
* Is tree of unsigned type?
*/
-int uns(tp) struct tree *tp; {
+int uns(tp) struct node *tp; {
register int t;
- t = tp->t_type;
+ t = tp->n_type;
if (t==UNSIGN || t==UNCHAR || t==UNLONG || t&XTYPE)
return(1);
return(0);
#ifndef NULL
#define NULL 0
#endif
-#define TNULL (struct tree *)NULL
/*
* Structure of namelist
*/
struct nmlist {
- /* note: this must be compatible with struct tree in respect of the */
+ /* note: this must be compatible with struct node in respect of the */
/* htype and hsubsp fields, because of length(), rlength() computations */
char hclass; /* storage class */
char hflag; /* various flags */
/*
* Tree node for unary and binary
*/
-struct tree {
- int t_op;
- int t_type;
- int *t_subsp; /* subscript list for arrays; pass 0 only */
- union str *t_strp; /* structure descr for structs; pass 0 only */
+struct node {
+ int n_op;
+ int n_type;
+ int *n_subsp; /* subscript list for arrays; pass 0 only */
+ union str *n_strp; /* structure descr for structs; pass 0 only */
};
struct tnode {
- struct tree tn_tree;
-#define tn_op tn_tree.t_op
-#define tn_type tn_tree.t_type
-#define tn_subsp tn_tree.t_subsp
-#define tn_strp tn_tree.t_strp
- struct tree *tn_tr1;
- struct tree *tn_tr2;
+ struct node tn_node;
+#define tn_op tn_node.n_op
+#define tn_type tn_node.n_type
+#define tn_subsp tn_node.n_subsp
+#define tn_strp tn_node.n_strp
+ struct node *tn_tr1;
+ struct node *tn_tr2;
int tn_degree; /* pass 1 only */
};
/*
- * tree names for locals
+ * node names
*/
struct nnode {
- struct tree nn_tree;
-#define nn_op nn_tree.t_op
-#define nn_type nn_tree.t_type
-#define nn_subsp nn_tree.t_subsp
-#define nn_strp nn_tree.t_strp
- struct nmlist *nn_tr1; /* pass 0 only */
+ struct node nn_node;
+#define nn_op nn_node.n_op
+#define nn_type nn_node.n_type
+#define nn_subsp nn_node.n_subsp
+#define nn_strp nn_node.n_strp
+ struct nmlist *nn_nmlist; /* pass 0 only */
char nn_class; /* pass 1 only */
char nn_regno; /* pass 1 only */
int nn_offset; /* pass 1 only */
- int nn_nloc; /* pass 1 only */
};
/*
- * tree names for externals
+ * node names for locals
+ *
+ * locnn_class can be:
+ * SOFFS: %offset+L%nloc(r%regno)
+ * OFFS: %offset(r%regno) XXX this does not use nloc
+ * STATIC: %offset+L%nloc
+ * REG: r%nloc
*/
-struct xnode {
- struct tree xn_tree;
-#define xn_op xn_tree.t_op
-#define xn_type xn_tree.t_type
-#define xn_subsp xn_tree.t_subsp
-#define xn_strp xn_tree.t_strp
- struct nmlist *xn_tr1; /* pass 0 only */
- char xn_class; /* pass 1 only */
- char xn_regno; /* pass 1 only */
- int xn_offset; /* pass 1 only */
- char *xn_name; /* pass 1 only */
+struct locnnode {
+ struct nnode locnn_nnode;
+#define locnn_op locnn_nnode.nn_op
+#define locnn_type locnn_nnode.nn_type
+#define locnn_subsp locnn_nnode.nn_subsp
+#define locnn_strp locnn_nnode.nn_strp
+#define locnn_nmlist locnn_nnode.nn_nmlist
+#define locnn_class locnn_nnode.nn_class
+#define locnn_regno locnn_nnode.nn_regno
+#define locnn_offset locnn_nnode.nn_offset
+ int locnn_nloc; /* pass 1 only */
+};
+
+/*
+ * node names for externals
+ *
+ * extnn_class can be:
+ * XOFFS: %offset+%name(r%regno)
+ * EXTERN: %offset+%name
+ */
+struct extnnode {
+ struct nnode extnn_nnode;
+#define extnn_op extnn_nnode.nn_op
+#define extnn_type extnn_nnode.nn_type
+#define extnn_subsp extnn_nnode.nn_subsp
+#define extnn_strp extnn_nnode.nn_strp
+#define extnn_nmlist extnn_nnode.nn_nmlist
+#define extnn_class extnn_nnode.nn_class
+#define extnn_regno extnn_nnode.nn_regno
+#define extnn_offset extnn_nnode.nn_offset
+ char *extnn_name; /* pass 1 only */
};
/*
* short constants
*/
struct cnode {
- struct tree cn_tree;
-#define cn_op cn_tree.t_op
-#define cn_type cn_tree.t_type
-#define cn_subsp cn_tree.t_subsp
-#define cn_strp cn_tree.t_strp
+ struct node cn_node;
+#define cn_op cn_node.n_op
+#define cn_type cn_node.n_type
+#define cn_subsp cn_node.n_subsp
+#define cn_strp cn_node.n_strp
_INT cn_value;
};
* long constants
*/
struct lnode {
- struct tree ln_tree;
-#define ln_op ln_tree.t_op
-#define ln_type ln_tree.t_type
-#define ln_subsp ln_tree.t_subsp
-#define ln_strp ln_tree.t_strp
+ struct node ln_node;
+#define ln_op ln_node.n_op
+#define ln_type ln_node.n_type
+#define ln_subsp ln_node.n_subsp
+#define ln_strp ln_node.n_strp
_LONG ln_lvalue;
};
* Floating constants
*/
struct fnode {
- struct tree fn_tree;
-#define fn_op fn_tree.t_op
-#define fn_type fn_tree.t_type
-#define fn_subsp fn_tree.t_subsp
-#define fn_strp fn_tree.t_strp
- int fn_value;
+ struct cnode fn_cnode;
+#define fn_op fn_cnode.cn_op
+#define fn_type fn_cnode.cn_type
+#define fn_subsp fn_cnode.cn_subsp
+#define fn_strp fn_cnode.cn_strp
+#define fn_value fn_cnode.cn_value
_DOUBLE fn_fvalue;
};
* Node used for field assignments
*/
struct fasgn {
- struct tree fa_tree;
-#define fa_op fa_tree.t_op
-#define fa_type fa_tree.t_type
-#define fa_subsp fa_tree.t_subsp
-#define fa_strp fa_tree.t_strp
- struct tree *fa_tr1;
- struct tree *fa_tr2;
- int fa_degree; /* pass 1 only */
+ struct tnode fa_tnode;
+#define fa_op fa_tnode.tn_op
+#define fa_type fa_tnode.tn_type
+#define fa_subsp fa_tnode.tn_subsp
+#define fa_strp fa_tnode.tn_strp
+#define fa_tr1 fa_tnode.tn_tr1
+#define fa_tr2 fa_tnode.tn_tr2
+#define fa_degree fa_tnode.tn_degree
int fa_mask; /* pass 1 only */
};
s/[^A-Za-z0-9_]\+/@&@/g
# types
-s/@union\(@[ ]*@tree\)@/@struct\1@/g
+s/@union\(@[ ]*@\)tree@/@struct\1node@/g
+
+# values
+s/@TNULL@/@(struct node *)NULL@/g
# tnode
s/@t@\.@op@/@tn_op@/g
s/@n@\.@type@/@nn_type@/g
s/@n@\.@subsp@/@nn_subsp@/g
s/@n@\.@strp@/@nn_strp@/g
-s/@n@\.@tr1@/@nn_tr1@/g
+s/@n@\.@tr1@/@nn_nmlist@/g
s/@n@\.@class@/@nn_class@/g
s/@n@\.@regno@/@nn_regno@/g
s/@n@\.@offset@/@nn_offset@/g