#define _C0_H 1
#include <stdio.h>
-
-#ifdef pdp11
-typedef int _INT;
-typedef long _LONG;
-typedef unsigned int _UNSIGNED_INT;
-typedef unsigned long _UNSIGNED_LONG;
-typedef float _FLOAT;
-typedef double _DOUBLE;
-#else
-#include <stdint.h>
-typedef int16_t _INT;
-typedef int32_t _LONG;
-typedef uint16_t _UNSIGNED_INT;
-typedef uint32_t _UNSIGNED_LONG;
-typedef struct { uint32_t h; } _FLOAT;
-typedef struct { uint32_t l; uint32_t h; } _DOUBLE;
-#endif
+#include "ccom.h"
/*
* This parameter is the _only_ one which affects the recognized length
};
/*
- * Structure of tree nodes for operators
+ * Structure of tree0 nodes for operators
*/
-struct tnode {
+struct tnode0 {
int op; /* operator */
int type; /* data type */
int *subsp; /* subscript list (for arrays) */
union str *strp; /* structure description for structs */
- union tree *tr1; /* left operand */
- union tree *tr2; /* right operand */
+ union tree0 *tr1; /* left operand */
+ union tree0 *tr2; /* right operand */
};
/*
};
/*
- * tree node for floating
+ * tree0 node for floating
* constants
*/
struct fnode {
};
/*
- * All possibilities for tree nodes
+ * All possibilities for tree0 nodes
*/
-union tree {
- struct tnode t;
+union tree0 {
+ struct tnode0 t;
struct cnode c;
struct lnode l;
struct fnode f;
int dimens[5];
};
-/*
- * Table for recording switches.
- */
-struct swtab {
- int swlab;
- int swval;
-};
-
-#define TNULL (union tree *)NULL
+#define TNULL0 (union tree0 *)NULL
extern char cvtab[4][4];
extern char filename[MAXPATHLEN]; /* Nick */
-extern int opdope[];
+extern int opdope0[];
extern char ctab[];
extern char symbuf[MAXCPS+2];
extern struct nmlist *hshtab[HSHSIZ];
extern int kwhash[(HSHSIZ+LNBPW-1)/LNBPW];
-extern union tree **cp;
-extern int isn;
+extern union tree0 **cp0;
+extern int isn0;
extern struct swtab swtab[SWSIZ];
extern int unscflg;
extern struct swtab *swp;
extern FILE *sbufp;
extern int regvar;
extern int bitoffs;
-extern struct tnode funcblk;
+extern struct tnode0 funcblk0;
extern char cvntab[];
extern char numbuf[64];
extern struct nmlist **memlist;
extern int blklev;
extern int mossym;
-/*
- operators
-*/
-#define EOFC 0
-#define SEMI 1
-#define LBRACE 2
-#define RBRACE 3
-#define LBRACK 4
-#define RBRACK 5
-#define LPARN 6
-#define RPARN 7
-#define COLON 8
-#define COMMA 9
-#define FSEL 10
-#define CAST 11
-#define ETYPE 12
-
-#define KEYW 19
-#define NAME 20
-#define CON 21
-#define STRING 22
-#define FCON 23
-#define SFCON 24
-#define LCON 25
-#define SLCON 26
-#define NULLOP 29
-#define XNULLOP 218 /* interface version */
-
-#define SIZEOF 91
-#define INCBEF 30
-#define DECBEF 31
-#define INCAFT 32
-#define DECAFT 33
-#define EXCLA 34
-#define AMPER 35
-#define STAR 36
-#define NEG 37
-#define COMPL 38
-
-#define DOT 39
-#define PLUS 40
-#define MINUS 41
-#define TIMES 42
-#define DIVIDE 43
-#define MOD 44
-#define RSHIFT 45
-#define LSHIFT 46
-#define AND 47
-#define OR 48
-#define EXOR 49
-#define ARROW 50
-#define ITOF 51
-#define FTOI 52
-#define LOGAND 53
-#define LOGOR 54
-#define FTOL 56
-#define LTOF 57
-#define ITOL 58
-#define LTOI 59
-#define ITOP 13
-#define PTOI 14
-#define LTOP 15
-
-#define EQUAL 60
-#define NEQUAL 61
-#define LESSEQ 62
-#define LESS 63
-#define GREATEQ 64
-#define GREAT 65
-#define LESSEQP 66
-#define LESSP 67
-#define GREATQP 68
-#define GREATP 69
-
-#define ASPLUS 70
-#define ASMINUS 71
-#define ASTIMES 72
-#define ASDIV 73
-#define ASMOD 74
-#define ASRSH 75
-#define ASLSH 76
-#define ASSAND 77
-#define ASOR 78
-#define ASXOR 79
-#define ASSIGN 80
-
-#define QUEST 90
-#define MAX 93
-#define MAXP 94
-#define MIN 95
-#define MINP 96
-#define SEQNC 97
-#define CALL 100
-#define MCALL 101
-#define JUMP 102
-#define CBRANCH 103
-#define INIT 104
-#define SETREG 105
-#define RFORCE 110
-#define BRANCH 111
-#define LABEL 112
-#define NLABEL 113
-#define RLABEL 114
-#define STRASG 115
-#define ITOC 109
-#define SEOF 200 /* stack EOF marker in expr compilation */
-
-/*
- types
-*/
-#define INT 0
-#define CHAR 1
-#define FLOAT 2
-#define DOUBLE 3
-#define STRUCT 4
-#define LONG 6
-#define UNSIGN 7
-#define UNCHAR 8
-#define UNLONG 9
-#define VOID 10
-#define UNION 8 /* adjusted later to struct */
-
-#define ALIGN 01
-#define TYPE 017
-#define BIGTYPE 060000
-#define TYLEN 2
-#define XTYPE (03<<4)
-#define PTR 020
-#define FUNC 040
-#define ARRAY 060
-
-/*
- storage classes
-*/
-#define KEYWC 1
-#define TYPEDEF 9
-#define MOS 10
-#define AUTO 11
-#define EXTERN 12
-#define STATIC 13
-#define REG 14
-#define STRTAG 15
-#define ARG 16
-#define ARG1 17
-#define AREG 18
-#define DEFXTRN 20
-#define MOU 21
-#define ENUMTAG 22
-#define ENUMCON 24
-
/*
keywords
*/
#define SPACE 126
#define UNKN 127
-/*
- * Special operators in intermediate code
- */
-#define BDATA 200
-#define WDATA 201
-#define PROG 202
-#define DATA 203
-#define BSS 204
-#define CSPACE 205
-#define SSPACE 206
-#define SYMDEF 207
-#define SAVE 208
-#define RETRN 209
-#define EVEN 210
-#define PROFIL 212
-#define SWIT 213
-#define EXPR 214
-#define SNAME 215
-#define RNAME 216
-#define ANAME 217
-#define SETSTK 219
-#define SINIT 220
-#define ASSEM 223
-
-/*
- Flag bits
-*/
-
-#define BINARY 01
-#define LVALUE 02
-#define RELAT 04
-#define ASSGOP 010
-#define LWORD 020
-#define RWORD 040
-#define COMMUTE 0100
-#define RASSOC 0200
-#define LEAF 0400
-#define PCVOK 040000
-
/*
* Conversion codes
*/
void cntstr __P((void));
int getcc __P((void));
int mapch __P((int ac));
-union tree *tree __P((int eflag));
-union tree *xprtype __P((void));
+union tree0 *tree0 __P((int eflag));
+union tree0 *xprtype0 __P((void));
char *copnum __P((int len));
/* c01.c */
void build __P((int op));
-union tree *structident __P((register union tree *p1, register union tree *p2));
-union tree *convert __P((union tree *p, int t, int cvn, int len));
-void setype __P((register union tree *p, register int t, register union tree *newp));
-union tree *chkfun __P((register union tree *p));
-union tree *disarray __P((register union tree *p));
-void chkw __P((union tree *p, int okt));
+union tree0 *structident __P((register union tree0 *p1, register union tree0 *p2));
+union tree0 *convert __P((union tree0 *p, int t, int cvn, int len));
+void setype __P((register union tree0 *p, register int t, register union tree0 *newp));
+union tree0 *chkfun __P((register union tree0 *p));
+union tree0 *disarray __P((register union tree0 *p));
+void chkw __P((union tree0 *p, int okt));
int lintyp __P((int t));
-void werror __P((char *s, ...));
-void error __P((char *s, ...));
-union tree *block __P((int op, int t, int *subs, union str *str, union tree *p1, union tree *p2));
-union tree *nblock __P((register struct nmlist *ds));
-union tree *cblock __P((int v));
-union tree *fblock __P((int t, char *string));
+void werror0 __P((char *s, ...));
+void error0 __P((char *s, ...));
+union tree0 *block __P((int op, int t, int *subs, union str *str, union tree0 *p1, union tree0 *p2));
+union tree0 *nblock __P((register struct nmlist *ds));
+union tree0 *cblock __P((int v));
+union tree0 *fblock __P((int t, char *string));
char *Tblock __P((int n));
char *starttree __P((void));
void endtree __P((char *tp));
char *Dblock __P((int n));
-void chklval __P((register union tree *p));
-int fold __P((int op, register union tree *p1, union tree *p2));
+void chklval __P((register union tree0 *p));
+int fold __P((int op, register union tree0 *p1, union tree0 *p2));
int conexp __P((void));
-void assignop __P((int op, register union tree *p1, register union tree *p2));
+void assignop __P((int op, register union tree0 *p1, register union tree0 *p2));
struct nmlist *gentemp __P((int type));
/* c02.c */
void setinit __P((register struct nmlist *np));
void statement __P((void));
int forstmt __P((void));
-union tree *pexpr __P((int eflag));
-void pswitch __P((void));
+union tree0 *pexpr __P((int eflag));
+void pswitch0 __P((void));
void funchead __P((void));
void blockhead __P((void));
void blkend __P((void));
int goodreg __P((struct nmlist *hp));
/* c04.c */
-int decref __P((register int t));
-int incref __P((register int t));
-void cbranch __P((union tree *t, int lbl, int cond));
-void rcexpr __P((register union tree *tp));
-void treeout __P((register union tree *tp, int isstruct));
-void branch __P((int lab));
-void label __P((int l));
-int plength __P((register union tree *p));
-int length __P((union tree *cs));
-int rlength __P((union tree *cs));
+int decref0 __P((register int t));
+int incref0 __P((register int t));
+void cbranch0 __P((union tree0 *t, int lbl, int cond));
+void rcexpr0 __P((register union tree0 *tp));
+void treeout __P((register union tree0 *tp, int isstruct));
+void branch0 __P((int lab));
+void label0 __P((int l));
+int plength __P((register union tree0 *p));
+int length __P((union tree0 *cs));
+int rlength __P((union tree0 *cs));
int simplegoto __P((void));
int nextchar __P((void));
int spnextchar __P((void));
#include <unistd.h>
#include "c0.h"
-int isn = 1;
+int isn0 = 1;
int peeksym = -1;
int line = 1;
-struct tnode funcblk = { NAME };
+struct tnode0 funcblk0 = { NAME };
struct kwtab {
char *kwname;
{0, 0}
};
-union tree *cmst[CMSIZ];
-union tree **cp = cmst;
+union tree0 *cmst[CMSIZ];
+union tree0 **cp0 = cmst;
int Wflag; /* print warning messages */
int main(argc, argv) int argc; char *argv[]; {
unscflg++;
}
if(argc<4) {
- error("Arg count");
+ error0("Arg count");
exit(1);
}
if (freopen(argv[1], "r", stdin)==NULL) {
- error("Can't find %s", argv[1]);
+ error0("Can't find %s", argv[1]);
exit(1);
}
setbuf(stdin,buf1); /* stdio sbrk problems */
if (freopen(argv[2], "w", stdout)==NULL || (sbufp=fopen(argv[3],"w"))==NULL) {
- error("Can't create temp");
+ error0("Can't create temp");
exit(1);
}
setbuf(stdout,buf2); /* stdio sbrk problems */
case SHARP:
if ((c=symbol())!=CON) {
- error("Illegal #");
+ error0("Illegal #");
return(c);
}
tline = cval;
peekc = getchar();
}
if (peekc != '\n') {
- error("Illegal #");
+ error0("Illegal #");
while (getchar()!='\n' && eof==0)
;
}
}
}
eof++;
- error("Nonterminated comment");
+ error0("Nonterminated comment");
return(0);
case PERIOD:
return(getnum());
case DQUOTE:
- cval = isn++;
+ cval = isn0++;
return(STRING);
case SQUOTE:
case UNKN:
unkn:
- error("Unknown character");
+ error0("Unknown character");
c = getchar();
goto loop;
}
if (c=='.') {
if (base==16 || sym==FCON)
- error(nsyn);
+ error0(nsyn);
sym = FCON;
base = 10;
continue;
expseen++;
sym = FCON;
if (base==16 || maxdigit>=10)
- error(nsyn);
+ error0(nsyn);
base = 10;
*np++ = c = getchar();
if (c!='+' && c!='-' && ctab[c]!=DIGIT)
break;
} else if (c=='x' || c=='X') {
if (base!=8 || lcval!=0 || sym!=CON)
- error(nsyn);
+ error0(nsyn);
base = 16;
} else if ((c=='l' || c=='L') && sym==CON) {
c = getchar();
}
peekc = c;
if (maxdigit >= base)
- error(nsyn);
+ error0(nsyn);
if (sym==FCON) {
np[-1] = 0;
cval = np-numbuf;
#endif
}
if (cc>LNCPW)
- error("Long character constant");
+ error0("Long character constant");
if (cc==1) {
#ifdef pdp11
realc = cval;
case '\n':
case '\0':
- error("Nonterminated string");
+ error0("Nonterminated string");
peekc = a;
return(-1);
}
/*
- * Read an expression and return a pointer to its tree.
+ * Read an expression and return a pointer to its tree0.
* It's the classical bottom-up, priority-driven scheme.
* The initflg prevents the parse from going past
* "," or ":" because those delimiters are special
* in initializer (and some other) expressions.
*/
-union tree *tree(eflag) int eflag; {
+union tree0 *tree0(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++ = cblock(cs->hoffset);
+ *cp0++ = cblock(cs->hoffset);
goto tand;
}
if (cs->hclass==0 && cs->htype==0)
cs->htype = FUNC;
} else {
cs->hclass = STATIC;
- error("%s undefined; func. %s", cs->name,
+ error0("%s undefined; func. %s", cs->name,
funcsym ? funcsym->name : "(none)");
}
- *cp++ = nblock(cs);
+ *cp0++ = nblock(cs);
goto tand;
case FCON:
- *cp++ = fblock(DOUBLE, copnum(cval));
+ *cp0++ = fblock(DOUBLE, copnum(cval));
goto tand;
case LCON:
- *cp = (union tree *)Tblock(sizeof(struct lnode));
- (*cp)->l.op = LCON;
- (*cp)->l.type = LONG;
- (*cp)->l.lvalue = lcval;
- cp++;
+ *cp0 = (union tree0 *)Tblock(sizeof(struct lnode));
+ (*cp0)->l.op = LCON;
+ (*cp0)->l.type = LONG;
+ (*cp0)->l.lvalue = lcval;
+ cp0++;
goto tand;
case CON:
- *cp++ = cblock(cval);
+ *cp0++ = cblock(cval);
goto tand;
/* fake a static char array */
cs = (struct nmlist *)Tblock(sizeof(struct nmlist));
cs->hclass = STATIC;
cs->hoffset = cval;
- *cp++ = block(NAME, unscflg? ARRAY+UNCHAR:ARRAY+CHAR, &nchstr,
- (union str *)NULL, (union tree *)cs, TNULL);
+ *cp0++ = block(NAME, unscflg? ARRAY+UNCHAR:ARRAY+CHAR, &nchstr,
+ (union str *)NULL, (union tree0 *)cs, TNULL0);
tand:
- if(cp>=cmst+CMSIZ) {
- error("Expression overflow");
+ if(cp0>=cmst+CMSIZ) {
+ error0("Expression overflow");
exit(1);
}
if (andflg)
if (*op != LPARN || andflg)
goto syntax;
peeksym = o;
- *cp++ = xprtype();
+ *cp0++ = xprtype0();
if ((o=symbol()) != RPARN)
goto syntax;
o = CAST;
andflg = 0;
oponst:
- p = (opdope[o]>>9) & 037;
+ p = (opdope0[o]>>9) & 037;
opon1:
if (o==COLON && op[0]==COLON && op[-1]==QUEST) {
build(*op--);
pp -= 2;
}
ps = *pp;
- if (p>ps || p==ps && (opdope[o]&RASSOC)!=0) {
+ if (p>ps || p==ps && (opdope0[o]&RASSOC)!=0) {
switch (o) {
case INCAFT:
}
}
if (op >= &opst[SSIZE-1]) {
- error("expression overflow");
+ error0("expression overflow");
exit(1);
}
*++op = o;
}
--pp;
os = *op--;
- if (andflg==0 && p>5 && ((opdope[o]&BINARY)==0 || o>=INCBEF&&o<=DECAFT) && opdope[os]&BINARY)
+ if (andflg==0 && p>5 && ((opdope0[o]&BINARY)==0 || o>=INCBEF&&o<=DECAFT) && opdope0[os]&BINARY)
goto syntax;
switch (os) {
build(0); /* flush conversions */
if (eflag)
endtree(svtree);
- return(*--cp);
+ return(*--cp0);
case COMMA:
if (*op != CALL)
goto advanc;
case MCALL:
- *cp++ = block(NULLOP, INT, (int *)NULL,
- (union str *)NULL, TNULL, TNULL);
+ *cp0++ = block(NULLOP0, INT, (int *)NULL,
+ (union str *)NULL, TNULL0, TNULL0);
os = CALL;
break;
case INCAFT:
case DECBEF:
case DECAFT:
- *cp++ = cblock(1);
+ *cp0++ = cblock(1);
break;
case LPARN:
goto opon1;
syntax:
- error("Expression syntax");
+ error0("Expression syntax");
errflush(o);
if (eflag)
endtree(svtree);
- return((union tree *) &garbage);
+ return((union tree0 *) &garbage);
}
-union tree *xprtype() {
+union tree0 *xprtype0() {
struct nmlist typer, absname;
int sc;
- register union tree **scp;
+ register union tree0 **scp;
- scp = cp;
- sc = DEFXTRN; /* will cause error if class mentioned */
+ scp = cp0;
+ sc = DEFXTRN; /* will cause error0 if class mentioned */
getkeywords(&sc, &typer);
absname.hclass = 0;
absname.hblklev = blklev;
absname.hstrp = NULL;
absname.htype = 0;
decl1(sc, &typer, 0, &absname);
- cp = scp;
+ cp0 = scp;
return(block(ETYPE, absname.htype, absname.hsubsp,
- absname.hstrp, TNULL, TNULL));
+ absname.hstrp, TNULL0, TNULL0));
}
char *copnum(len) int len; {
#include "c0.h"
/*
- * Called from tree, this routine takes the top 1, 2, or 3
+ * Called from tree0, this routine takes the top 1, 2, or 3
* operands on the expression stack, makes a new node with
* the operator op, and puts it on the stack.
* Essentially all the work is in inserting
void build(op) int op; {
register int t1;
int t2, t;
- register union tree *p1, *p2, *p3;
+ register union tree0 *p1, *p2, *p3;
int dope, leftc, cvn, pcvn;
/*
build(PLUS);
op = STAR;
}
- dope = opdope[op];
+ dope = opdope0[op];
t2 = INT;
if ((dope&BINARY)!=0) {
- p2 = chkfun(disarray(*--cp));
+ p2 = chkfun(disarray(*--cp0));
if (p2)
t2 = p2->t.type;
}
- p1 = *--cp;
+ p1 = *--cp0;
/*
* sizeof gets turned into a number here.
*/
if (op==SIZEOF) {
p1 = cblock(length(p1));
p1->c.type = UNSIGN;
- *cp++ = p1;
+ *cp0++ = p1;
return;
}
if (op!=AMPER) {
case CAST:
if ((t1&XTYPE)==FUNC || (t1&XTYPE)==ARRAY)
- error("Disallowed conversion");
+ error0("Disallowed conversion");
if (p1->t.type==UNCHAR) {
- *cp++ = block(ETYPE, UNSIGN, (int *)NULL, (union str *)NULL,
- TNULL, TNULL);
- *cp++ = p2;
+ *cp0++ = block(ETYPE, UNSIGN, (int *)NULL, (union str *)NULL,
+ TNULL0, TNULL0);
+ *cp0++ = p2;
build(CAST);
- *cp++ = cblock(0377);
+ *cp0++ = cblock(0377);
build(AND);
return;
}
/* end of expression */
case 0:
- *cp++ = p1;
+ *cp0++ = p1;
return;
/* no-conversion operators */
case QUEST:
if (p2->t.op!=COLON)
- error("Illegal conditional");
+ error0("Illegal conditional");
else
if (fold(QUEST, p1, p2))
return;
* case COMMA:
*/
case SEQNC:
- *cp++ = block(op, t2, p2->t.subsp, p2->t.strp, p1, p2);
+ *cp0++ = block(op, t2, p2->t.subsp, p2->t.strp, p1, p2);
return;
case COMMA:
case LOGAND:
case LOGOR:
- *cp++ = block(op, t, p2->t.subsp, p2->t.strp, p1, p2);
+ *cp0++ = block(op, t, p2->t.subsp, p2->t.strp, p1, p2);
return;
case EXCLA:
break;
case CALL:
- if ((t1&XTYPE) == PTR && (decref(t1)&XTYPE) == FUNC) {
+ if ((t1&XTYPE) == PTR && (decref0(t1)&XTYPE) == FUNC) {
/*
* Modification to allow calling a function via a
* pointer to a function ("f") without explicitly
* dereferencing the pointer. That is: f(...) is now
* legal as well as (*f)(...). The insistence that
- * decref(t1) be FUNC prevents pointers to pointers to
+ * decref0(t1) be FUNC prevents pointers to pointers to
* functions and so on from being automatically
* dereferenced which would be incorrect and introduce
* porting problems. Note that for purity FUNC's
* that the new notation is actually more consistent
* with the rest of C ...
*/
- *cp++ = p1;
+ *cp0++ = p1;
build(STAR);
- *cp++ = p2;
+ *cp0++ = p2;
build(CALL);
return;
}
if ((t1&XTYPE) != FUNC)
- error("Call of non-function");
- *cp++ = block(CALL,decref(t1),p1->t.subsp,p1->t.strp,p1,p2);
+ error0("Call of non-function");
+ *cp0++ = block(CALL,decref0(t1),p1->t.subsp,p1->t.strp,p1,p2);
return;
case STAR:
if ((t1&XTYPE) == FUNC)
- error("Illegal indirection");
- *cp++ = block(STAR, decref(t1), p1->t.subsp, p1->t.strp, p1, TNULL);
+ error0("Illegal indirection");
+ *cp0++ = block(STAR, decref0(t1), p1->t.subsp, p1->t.strp, p1, TNULL0);
return;
case AMPER:
if (p1->t.op==NAME || p1->t.op==STAR) {
- *cp++ = block(op,incref(p1->t.type),p1->t.subsp,p1->t.strp,p1,TNULL);
+ *cp0++ = block(op,incref0(p1->t.type),p1->t.subsp,p1->t.strp,p1,TNULL0);
return;
}
- error("Illegal lvalue");
+ error0("Illegal lvalue");
break;
/*
*/
case DOT:
if (p1->t.op==CALL && t1==STRUCT) {
- t1 = incref(t1);
+ t1 = incref0(t1);
setype(p1, t1, p1);
} else {
- *cp++ = p1;
+ *cp0++ = p1;
build(AMPER);
- p1 = *--cp;
+ p1 = *--cp0;
}
/*
*/
case ARROW:
if (p2->t.op!=NAME || p2->t.tr1->n.hclass!=MOS) {
- error("Illegal structure ref");
- *cp++ = p1;
+ error0("Illegal structure ref");
+ *cp0++ = p1;
return;
}
p2 = structident(p1, p2);
t2 = p2->n.htype;
if (t2==INT && p2->t.tr1->n.hflag&FFIELD)
t2 = UNSIGN;
- t = incref(t2);
+ t = incref0(t2);
chkw(p1, -1);
setype(p1, t, p2);
- *cp++ = block(PLUS, t, p2->t.subsp, p2->t.strp,
+ *cp0++ = block(PLUS, t, p2->t.subsp, p2->t.strp,
p1, cblock(p2->t.tr1->n.hoffset));
build(STAR);
if (p2->t.tr1->n.hflag&FFIELD)
#if 1
- cp[-1] = block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL,
- cp[-1], (union tree *)p2->t.tr1->n.hstrp);
+ cp0[-1] = block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL,
+ cp0[-1], (union tree0 *)p2->t.tr1->n.hstrp);
#else
- *cp++ = block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL,
- *--cp, (union tree *)p2->t.tr1->n.hstrp);
+ *cp0++ = block(FSEL, UNSIGN, (int *)NULL, (union str *)NULL,
+ *--cp0, (union tree0 *)p2->t.tr1->n.hstrp);
#endif
return;
}
if ((dope&RWORD)!=0)
chkw(p2, LONG);
if ((t1==VOID && op!=CAST) || (t2==VOID && (op!=CAST || t1!=VOID))) {
- error("Illegal use of void object");
+ error0("Illegal use of void object");
t = t1 = t2 = INT;
}
if ((dope&BINARY)==0) {
t1 = DOUBLE;
else if (op==FTOI)
t1 = INT;
- if (!fold(op, p1, (union tree *)NULL))
- *cp++ = block(op, t1, p1->t.subsp, p1->t.strp, p1,TNULL);
+ if (!fold(op, p1, (union tree0 *)NULL))
+ *cp0++ = block(op, t1, p1->t.subsp, p1->t.strp, p1,TNULL0);
return;
}
cvn = 0;
if (t1==STRUCT || t2==STRUCT) {
if (t1!=t2 || p1->t.strp != p2->t.strp)
- error("Incompatible structures");
+ error0("Incompatible structures");
cvn = 0;
} else
cvn = cvtab[lintyp(t1)][lintyp(t2)];
if (op==ASSIGN) {
if (cvn==PTI) {
if (t1!=t2 || ((t1&TYPE)==STRUCT && p1->t.strp!=p2->t.strp))
- werror("mixed pointer assignment");
+ werror0("mixed pointer assignment");
cvn = leftc = 0;
} if ((cvn==ITP || cvn==LTP)
&& (p2->t.op!=CON || p2->c.value!=0)
* fairly large rewrite to eliminate the
* duplication.
*/
- werror("illegal combination of pointer and integer, op =");
+ werror0("illegal combination of pointer and integer, op =");
if (cvn==ITP)
cvn = leftc = 0;
else
p3 = leftc? p1: p2;
if ((p3->t.op!=CON || p3->c.value!=0)
&& (p3->t.op!=LCON || p3->l.lvalue!=0)) {
- werror("illegal combination of pointer and integer, op :");
+ werror0("illegal combination of pointer and integer, op :");
if (cvn==ITP)
cvn = leftc = 0;
else
cvn = 0;
if (op==MINUS) {
pcvn++;
- p1 = block(ITOL, LONG, (int *)NULL, (union str *)NULL, p1, TNULL);
- p2 = block(ITOL, LONG, (int *)NULL, (union str *)NULL, p2, TNULL);
+ p1 = block(ITOL, LONG, (int *)NULL, (union str *)NULL, p1, TNULL0);
+ p2 = block(ITOL, LONG, (int *)NULL, (union str *)NULL, p2, TNULL0);
t = LONG;
} else {
if (t1!=t2 || (t1!=(PTR+CHAR) && t1!=(PTR+UNCHAR)))
}
}
if (cvn) {
- if ((cvn==ITP || cvn==LTP) && (opdope[op]&PCVOK)==0) {
+ if ((cvn==ITP || cvn==LTP) && (opdope0[op]&PCVOK)==0) {
p3 = leftc? p1: p2;
if ((p3->t.op!=CON || p3->c.value!=0)
&& (p3->t.op!=LCON || p3->l.lvalue!=0))
t1 = plength(p1);
t2 = plength(p2);
if (cvn==XX || (cvn==PTI&&t1!=t2))
- error("Illegal conversion");
+ error0("Illegal conversion");
else if (leftc)
p1 = convert(p1, t, cvn, t2);
else
p2->t.strp = p1->t.strp;
}
if (t==INT && p1->t.type==CHAR)
- p2 = block(ITOC, INT, (int *)NULL, (union str *)NULL, p2, TNULL);
- *cp++ = p2;
+ p2 = block(ITOC, INT, (int *)NULL, (union str *)NULL, p2, TNULL0);
+ *cp0++ = p2;
return;
}
if (pcvn)
t2 = plength(p1->t.tr1);
if (fold(op, p1, p2)==0) {
p3 = leftc?p2:p1;
- *cp++ = block(op, t, p3->t.subsp, p3->t.strp, p1, p2);
+ *cp0++ = block(op, t, p3->t.subsp, p3->t.strp, p1, p2);
}
if (pcvn) {
- p1 = *--cp;
- *cp++ = convert(p1, 0, PTI, t2);
+ p1 = *--cp0;
+ *cp0++ = convert(p1, 0, PTI, t2);
}
}
-union tree *structident(p1, p2) register union tree *p1; register union tree *p2; {
+union tree0 *structident(p1, p2) register union tree0 *p1; register union tree0 *p2; {
register struct nmlist *np;
int vartypes = 0, namesame = 1;
p2->t.type = np->htype;
p2->t.strp = np->hstrp;
p2->t.subsp = np->hsubsp;
- p2->t.tr1 = (union tree *)np;
+ p2->t.tr1 = (union tree0 *)np;
return(p2);
}
np = np->nextnm;
vartypes++;
}
if (vartypes)
- error("Ambiguous structure reference for %s",p2->t.tr1->n.name);
+ error0("Ambiguous structure reference for %s",p2->t.tr1->n.name);
else
- werror("%s not member of cited struct/union",p2->t.tr1->n.name);
+ werror0("%s not member of cited struct/union",p2->t.tr1->n.name);
return(p2);
}
/*
* Generate the appropriate conversion operator.
*/
-union tree *convert(p, t, cvn, len) union tree *p; int t; int cvn; int len; {
+union tree0 *convert(p, t, cvn, len) union tree0 *p; int t; int cvn; int len; {
register int op;
if (cvn==0)
return(p);
op = cvntab[cvn];
- if (opdope[op]&BINARY) {
+ if (opdope0[op]&BINARY) {
if (len==0)
- error("Illegal conversion");
+ error0("Illegal conversion");
return(block(op, t, (int *)NULL, (union str *)NULL, p, cblock(len)));
}
- return(block(op, t, (int *)NULL, (union str *)NULL, p, TNULL));
+ return(block(op, t, (int *)NULL, (union str *)NULL, p, TNULL0));
}
/*
- * Traverse an expression tree, adjust things
+ * Traverse an expression tree0, adjust things
* so the types of things in it are consistent
* with the view that its top node has
* type at.
* Used with structure references.
*/
-void setype(p, t, newp) register union tree *p; register int t; register union tree *newp; {
+void setype(p, t, newp) register union tree0 *p; register int t; register union tree0 *newp; {
for (;; p = p->t.tr1) {
p->t.subsp = newp->t.subsp;
p->t.strp = newp->t.strp;
p->t.type = t;
if (p->t.op==AMPER)
- t = decref(t);
+ t = decref0(t);
else if (p->t.op==STAR)
- t = incref(t);
+ t = incref0(t);
else if (p->t.op!=PLUS)
break;
}
* A mention of a function name is turned into
* a pointer to that function.
*/
-union tree *chkfun(p) register union tree *p; {
+union tree0 *chkfun(p) register union tree0 *p; {
register int t;
if (((t = p->t.type)&XTYPE)==FUNC && p->t.op!=ETYPE)
- return(block(AMPER,incref(t),p->t.subsp,p->t.strp,p,TNULL));
+ return(block(AMPER,incref0(t),p->t.subsp,p->t.strp,p,TNULL0));
return(p);
}
* A mention of an array is turned into
* a pointer to the base of the array.
*/
-union tree *disarray(p) register union tree *p; {
+union tree0 *disarray(p) register union tree0 *p; {
register int t;
if (p==NULL)
|| p->t.op==ETYPE)
return(p);
p->t.subsp++;
- *cp++ = p;
- setype(p, decref(t), p);
+ *cp0++ = p;
+ setype(p, decref0(t), p);
build(AMPER);
- return(*--cp);
+ return(*--cp0);
}
/*
* okt might be nonexistent or 'long'
* (e.g. for <<).
*/
-void chkw(p, okt) union tree *p; int okt; {
+void chkw(p, okt) union tree0 *p; int okt; {
register int t = p->t.type;
if (t == UNLONG)
t = LONG;
if (t!=INT && t<PTR && t!=CHAR && t!=UNCHAR && t!=UNSIGN && t!=okt)
- error("Illegal type of operand");
+ error0("Illegal type of operand");
return;
}
}
/*
- * Report an error.
+ * Report an error0.
*/
extern int Wflag; /* Non-zero means do not print warnings */
#ifdef __STDC__
-void werror(char *s, ...)
+void werror0(char *s, ...)
#else
-void werror(s, va_alist) char *s; va_dcl
+void werror0(s, va_alist) char *s; va_dcl
#endif
{
va_list ap;
}
#ifdef __STDC__
-void error(char *s, ...)
+void error0(char *s, ...)
#else
-void error(s, va_alist) char *s; va_dcl
+void error0(s, va_alist) char *s; va_dcl
#endif
{
va_list ap;
}
/*
- * Generate a node in an expression tree,
+ * Generate a node in an expression tree0,
* setting the operator, type, dimen/struct table ptrs,
* and the operands.
*/
-union tree *block(op, t, subs, str, p1,p2) int op; int t; int *subs; union str *str; union tree *p1; union tree *p2; {
- register union tree *p;
+union tree0 *block(op, t, subs, str, p1,p2) int op; int t; int *subs; union str *str; union tree0 *p1; union tree0 *p2; {
+ register union tree0 *p;
/*fprintf(stderr, "block(%d, %d, {%d, %d}, {%d, %d})\n", op, t,
(op == NAME) ? -2 : (p1 ? (int)(_INT)p1->t.op : -1),
(op == NAME) ? -2 : (p1 ? (int)(_INT)p1->t.type : -1),
(op == FSEL) ? -3 : (p2 ? (int)(_INT)p2->t.op : -1),
(op == FSEL) ? -3 : (p2 ? (int)(_INT)p2->t.type : -1));*/
- p = (union tree *)Tblock(sizeof(struct tnode));
+ p = (union tree0 *)Tblock(sizeof(struct tnode0));
p->t.op = op;
p->t.type = t;
p->t.subsp = subs;
p->t.strp = str;
p->t.tr1 = p1;
- if (opdope[op]&BINARY)
+ if (opdope0[op]&BINARY)
p->t.tr2 = p2;
else
p->t.tr2 = NULL;
return(p);
}
-union tree *nblock(ds) register struct nmlist *ds; {
- return(block(NAME, ds->htype, ds->hsubsp, ds->hstrp, (union tree *)ds, TNULL));
+union tree0 *nblock(ds) register struct nmlist *ds; {
+ return(block(NAME, ds->htype, ds->hsubsp, ds->hstrp, (union tree0 *)ds, TNULL0));
}
/*
* Generate a block for a constant
*/
-union tree *cblock(v) int v; {
- register union tree *p;
+union tree0 *cblock(v) int v; {
+ register union tree0 *p;
/*fprintf(stderr, "cblock(0%06o)\n", v & 0177777);*/
- p = (union tree *)Tblock(sizeof(struct cnode));
+ p = (union tree0 *)Tblock(sizeof(struct cnode));
p->c.op = CON;
p->c.type = INT;
p->c.subsp = NULL;
/*
* A block for a float constant
*/
-union tree *fblock(t, string) int t; char *string; {
- register union tree *p;
+union tree0 *fblock(t, string) int t; char *string; {
+ register union tree0 *p;
/*fprintf(stderr, "fblock(%d, \"%s\")\n", t, string);*/
- p = (union tree *)Tblock(sizeof(struct fnode));
+ p = (union tree0 *)Tblock(sizeof(struct fnode));
p->f.op = FCON;
p->f.type = t;
p->f.subsp = NULL;
/*
* Assign a block for use in the
- * expression tree.
+ * expression tree0.
*/
char *Tblock(n) int n; {
register char *p;
/*fprintf(stderr, "treebase=%p n=%p coremax=%p\n", treebase, n, coremax);*/
p = treebase;
if (p==NULL) {
- error("c0 internal error: Tblock");
+ error0("c0 internal error0: Tblock");
exit(1);
}
if ((treebase += n) >= coremax) {
/*fprintf(stderr, "sbrk\n");*/
if (sbrk(1024) != coremax) {
#endif
- error("Out of space");
+ error0("Out of space");
exit(1);
}
coremax += 1024;
p = locbase;
locbase += n;
if (treebot && locbase > treebot) {
- error("Too much declaring in an expression");
+ error0("Too much declaring in an expression");
exit(1);
}
if (locbase > coremax) {
/*fprintf(stderr, "sbrk\n");*/
if (sbrk(1024) != coremax) {
#endif
- error("out of space");
+ error0("out of space");
exit(1);
}
coremax += 1024;
}
/*
- * Check that a tree can be used as an lvalue.
+ * Check that a tree0 can be used as an lvalue.
*/
-void chklval(p) register union tree *p; {
+void chklval(p) register union tree0 *p; {
if (p->t.op==FSEL)
p = p->t.tr1;
if (p->t.op!=NAME && p->t.op!=STAR)
- error("Lvalue required");
+ 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 union tree *p1; union tree *p2; {
+int fold(op, p1, p2) int op; register union tree0 *p1; union tree0 *p2; {
register int v1, v2;
int unsignf;
if (op==QUEST) {
if (p2->t.tr1->t.op==CON && p2->t.tr2->t.op==CON) {
p1->c.value = p1->c.value? p2->t.tr1->c.value: p2->t.tr2->c.value;
- *cp++ = p1;
+ *cp0++ = p1;
p1->t.type = p2->t.type;
return(1);
}
break;
divchk:
- error("Divide check");
+ error0("Divide check");
nerror--;
default:
return(0);
}
p1->c.value = v1;
- *cp++ = p1;
+ *cp0++ = p1;
if (unsignf)
p1->t.type = UNSIGN;
return(1);
* for example an array bound or a case value.
*/
int conexp() {
- register union tree *t;
+ register union tree0 *t;
initflg++;
- if (t = tree(1))
+ if (t = tree0(1))
if (t->t.op != CON)
- error("Constant required");
+ error0("Constant required");
initflg--;
/*fprintf(stderr, "conexp() %d\n", t->c.value);*/
return(t->c.value);
/*
* Handle peculiar assignment ops that need a temporary.
*/
-void assignop(op, p1, p2) int op; register union tree *p1; register union tree *p2; {
+void assignop(op, p1, p2) int op; register union tree0 *p1; register union tree0 *p2; {
register struct nmlist *np;
op += PLUS - ASPLUS;
if (p1->t.op==NAME) {
- *cp++ = p1;
- *cp++ = p1;
- *cp++ = p2;
+ *cp0++ = p1;
+ *cp0++ = p1;
+ *cp0++ = p2;
build(op);
build(ASSIGN);
return;
}
- np = gentemp(incref(p1->t.type));
- *cp++ = nblock(np);
- *cp++ = p1;
+ np = gentemp(incref0(p1->t.type));
+ *cp0++ = nblock(np);
+ *cp0++ = p1;
build(AMPER);
build(ASSIGN);
- *cp++ = nblock(np);
+ *cp0++ = nblock(np);
build(STAR);
- *cp++ = nblock(np);
+ *cp0++ = nblock(np);
build(STAR);
- *cp++ = p2;
+ *cp0++ = p2;
build(op);
build(ASSIGN);
build(SEQNC);
tp->hsubsp = NULL;
tp->hstrp = NULL;
tp->hblklev = blklev;
- autolen -= rlength((union tree *)tp);
+ autolen -= rlength((union tree0 *)tp);
tp->hoffset = autolen;
if (autolen < maxauto)
maxauto = autolen;
sclass = EXTERN;
}
if (sclass!=EXTERN && sclass!=STATIC && sclass!=TYPEDEF)
- error("Illegal storage class");
+ error0("Illegal storage class");
do {
defsym = 0;
paraml = NULL;
if ((ds->htype&XTYPE)==FUNC) {
if ((peeksym=symbol())==LBRACE || peeksym==KEYW
|| (peeksym==NAME && csym->hclass==TYPEDEF)) {
- funcblk.type = decref(ds->htype);
- funcblk.strp = ds->hstrp;
+ funcblk0.type = decref0(ds->htype);
+ funcblk0.strp = ds->hstrp;
setinit(ds);
outcode("BS", SYMDEF, sclass==EXTERN?ds->name:"");
cfunc();
return;
}
if (paraml)
- error("Inappropriate parameters");
+ error0("Inappropriate parameters");
} else if ((o=symbol())==COMMA || o==SEMI) {
peeksym = o;
- o = (length((union tree *)ds)+ALIGN) & ~ALIGN;
+ o = (length((union tree0 *)ds)+ALIGN) & ~ALIGN;
if (sclass==STATIC) {
setinit(ds);
outcode("BSBBSBN", SYMDEF, "", BSS, NLABEL, ds->name, SSPACE, o);
outcode("BSN", CSPACE, ds->name, o);
} else {
if (o!=ASSIGN) {
- error("Declaration syntax");
+ error0("Declaration syntax");
peeksym = o;
}
setinit(ds);
return;
syntax:
if (o==RBRACE) {
- error("Too many }'s");
+ error0("Too many }'s");
peeksym = 0;
return;
}
- error("External definition syntax");
+ error0("External definition syntax");
errflush(o);
statement();
}
register char *cb;
register int sloc;
- sloc = isn;
- isn += 2;
+ sloc = isn0;
+ isn0 += 2;
outcode("BBS", PROG, RLABEL, funcsym->name);
regvar = 5;
autolen = STAUTO;
declist(ARG);
outcode("B", SAVE);
if (proflg)
- outcode("BNS", PROFIL, isn++, funcsym->name);
+ outcode("BNS", PROFIL, isn0++, funcsym->name);
funchead();
- branch(sloc);
- label(sloc+1);
- retlab = isn++;
+ branch0(sloc);
+ label0(sloc+1);
+ retlab = isn0++;
blklev = 0;
if ((peeksym = symbol()) != LBRACE)
- error("Compound statement required");
+ error0("Compound statement required");
statement();
outcode("BNB", LABEL, retlab, RETRN);
- label(sloc);
+ label0(sloc);
/* add STAUTO; overlay bug fix, coupled with section in c11.c */
outcode("BN", SETSTK, -maxauto+STAUTO);
- branch(sloc+1);
- /*fprintf(stderr, "cb=%p\n", cp);*/
+ branch0(sloc+1);
+ /*fprintf(stderr, "cb=%p\n", cp0);*/
locbase = cb;
}
struct nmlist np;
register int nel, ninit;
int width, isarray, o, brace, realtype;
- union tree *s;
+ union tree0 *s;
np = *anp;
realtype = np.htype;
isarray++;
else
flex = 0;
- width = length((union tree *)&np);
+ width = length((union tree0 *)&np);
nel = 1;
/*
* If it's an array, find the number of elements.
*/
if (sclass==AUTO)
if (isarray || realtype==STRUCT)
- error("No auto. aggregate initialization");
+ error0("No auto. aggregate initialization");
if (isarray) {
- np.htype = decref(realtype);
+ np.htype = decref0(realtype);
np.hsubsp++;
if (width==0 && flex==0)
- error("0-length row: %s", anp->name);
- o = length((union tree *)&np);
+ error0("0-length row: %s", anp->name);
+ o = length((union tree0 *)&np);
nel = (unsigned)width/o;
width = o;
}
peeksym = o;
if (o==STRING && (realtype==ARRAY+CHAR || realtype==ARRAY+UNCHAR)) {
if (sclass==AUTO)
- error("No strings in automatic");
+ error0("No strings in automatic");
peeksym = -1;
putstr(0, flex?10000:nel);
ninit += nchstr;
char *st;
initflg++;
st = starttree();
- s = tree(0);
+ s = tree0(0);
initflg = 0;
if (np.hflag&FFIELD)
- error("No field initialization");
- *cp++ = nblock(&np);
- *cp++ = s;
+ error0("No field initialization");
+ *cp0++ = nblock(&np);
+ *cp0++ = s;
build(ASSIGN);
if (sclass==AUTO||sclass==REG)
- rcexpr(*--cp);
+ rcexpr0(*--cp0);
else if (sclass==ENUMCON) {
if (s->t.op!=CON)
- error("Illegal enum constant for %s", anp->name);
+ error0("Illegal enum constant for %s", anp->name);
anp->hoffset = s->c.value;
} else
- rcexpr(block(INIT,np.htype,(int *)NULL,
- (union str *)NULL, (*--cp)->t.tr2, TNULL));
+ rcexpr0(block(INIT,np.htype,(int *)NULL,
+ (union str *)NULL, (*--cp0)->t.tr2, TNULL0));
endtree(st);
}
ninit++;
if (flex && nel==0) {
np.hsubsp[-1] = ninit;
} else
- error("Too many initializers: %s", anp->name);
+ error0("Too many initializers: %s", anp->name);
nel = ninit;
}
return(nel*width);
if ((mlp = np->hstrp->S.memlist)==NULL) {
mlp = &zerloc;
- error("Undefined structure initialization");
+ error0("Undefined structure initialization");
}
brace = 0;
if ((o = symbol()) == LBRACE)
break;
peeksym = o;
if (*mlp==0) {
- error("Too many structure initializers");
+ error0("Too many structure initializers");
cinit(&junk, 0, sclass);
} else
cinit(*mlp++, 0, sclass);
}
/* DAG -- union initialization bug fix */
if (*mlp && mlp[-1]->hoffset == (*mlp)->hoffset) {
- werror("union initialization non-portable");
+ werror0("union initialization non-portable");
while (*mlp) /* will NOT be &structhole */
mlp++; /* skip other members of union */
}
void setinit(np) register struct nmlist *np; {
if (np->hflag&FINIT)
- error("%s multiply defined", np->name);
+ error0("%s multiply defined", np->name);
np->hflag |= FINIT;
}
switch(o=symbol()) {
case EOFC:
- error("Unexpected EOF");
+ error0("Unexpected EOF");
case SEMI:
return;
peeksym = o;
statement();
}
- error("Missing '}'");
+ error0("Missing '}'");
return;
case KEYW:
case GOTO:
if (o1 = simplegoto())
- branch(o1);
+ branch0(o1);
else
dogoto();
goto semi;
case IF: {
register int o2;
- register union tree *np;
+ register union tree0 *np;
np = pexpr(1);
o2 = 0;
case GOTO:
if (o2=simplegoto())
goto simpif;
- cbranch(np, o2=isn++, 0);
+ cbranch0(np, o2=isn0++, 0);
dogoto();
- label(o2);
+ label0(o2);
goto hardif;
case RETURN:
o2 = retlab;
goto simpif;
}
- cbranch(np, o1=isn++, 0);
+ cbranch0(np, o1=isn0++, 0);
doret();
- label(o1);
+ label0(o1);
o2++;
goto hardif;
o2 = contlab;
simpif:
chconbrk(o2);
- cbranch(np, o2, 1);
+ cbranch0(np, o2, 1);
hardif:
if ((o=symbol())!=SEMI)
goto syntax;
return;
}
peeksym = o1;
- cbranch(np, o1=isn++, 0);
+ cbranch0(np, o1=isn0++, 0);
statement();
if ((o=symbol())==KEYW && cval==ELSE) {
- o2 = isn++;
- branch(o2);
- label(o1);
+ o2 = isn0++;
+ branch0(o2);
+ label0(o1);
statement();
- label(o2);
+ label0(o2);
return;
}
peeksym = o;
- label(o1);
+ label0(o1);
return;
}
register int o2;
o1 = contlab;
o2 = brklab;
- label(contlab = isn++);
- cbranch(pexpr(1), brklab=isn++, 0);
+ label0(contlab = isn0++);
+ cbranch0(pexpr(1), brklab=isn0++, 0);
statement();
- branch(contlab);
- label(brklab);
+ branch0(contlab);
+ label0(brklab);
contlab = o1;
brklab = o2;
return;
case BREAK:
chconbrk(brklab);
- branch(brklab);
+ branch0(brklab);
goto semi;
case CONTIN:
chconbrk(contlab);
- branch(contlab);
+ branch0(contlab);
goto semi;
case DO: {
register int o2, o3;
o1 = contlab;
o2 = brklab;
- contlab = isn++;
- brklab = isn++;
- label(o3 = isn++);
+ contlab = isn0++;
+ brklab = isn0++;
+ label0(o3 = isn0++);
statement();
- label(contlab);
+ label0(contlab);
contlab = o1;
if ((o=symbol())==KEYW && cval==WHILE) {
- cbranch(tree(1), o3, 1);
- label(brklab);
+ cbranch0(tree0(1), o3, 1);
+ label0(brklab);
brklab = o2;
goto semi;
}
if ((o=symbol())!=COLON)
goto syntax;
if (swp==0) {
- error("Case not in switch");
+ error0("Case not in switch");
goto stmt;
}
if(swp>=swtab+SWSIZ) {
- error("Switch table overflow");
+ error0("Switch table overflow");
} else {
- swp->swlab = isn;
+ swp->swlab = isn0;
(swp++)->swval = o1;
- label(isn++);
+ label0(isn0++);
}
goto stmt;
case SWITCH: {
- register union tree *np;
+ register union tree0 *np;
register char *st;
o1 = brklab;
- brklab = isn++;
+ brklab = isn0++;
st = starttree();
np = pexpr(0);
chkw(np, -1);
- rcexpr(block(RFORCE,0,(int *)NULL,(union str *)NULL,np,TNULL));
+ rcexpr0(block(RFORCE,0,(int *)NULL,(union str *)NULL,np,TNULL0));
endtree(st);
- pswitch();
+ pswitch0();
brklab = o1;
return;
}
case DEFAULT:
if (swp==0)
- error("Default not in switch");
+ error0("Default not in switch");
if (deflab)
- error("More than 1 'default'");
+ error0("More than 1 'default'");
if ((o=symbol())!=COLON)
goto syntax;
- label(deflab = isn++);
+ label0(deflab = isn0++);
goto stmt;
case FOR: {
register int o2;
o1 = contlab;
o2 = brklab;
- contlab = isn++;
- brklab = isn++;
+ contlab = isn0++;
+ brklab = isn0++;
if (o=forstmt())
goto syntax;
contlab = o1;
}
case ELSE:
- error("Inappropriate 'else'");
+ error0("Inappropriate 'else'");
statement();
return;
}
- error("Unknown keyword");
+ error0("Unknown keyword");
goto syntax;
case NAME: {
np->htype = ARRAY;
np->hflag |= FLABL;
if (np->hoffset==0)
- np->hoffset = isn++;
- label(np->hoffset);
+ np->hoffset = isn0++;
+ label0(np->hoffset);
goto stmt;
}
}
}
peeksym = o;
- rcexpr(tree(1));
+ rcexpr0(tree0(1));
semi:
if ((o=symbol())==SEMI)
return;
syntax:
- error("Statement syntax");
+ error0("Statement syntax");
errflush(o);
}
*/
int forstmt() {
register int o;
- register union tree *st;
+ register union tree0 *st;
register int l;
char *ss;
return(o);
if ((o=symbol()) != SEMI) { /* init part */
peeksym = o;
- rcexpr(tree(1));
+ rcexpr0(tree0(1));
if ((o=symbol()) != SEMI)
return(o);
}
- l = isn;
- isn += 3;
- branch(l+0);
- label(l+1);
- branch(l+2);
- label(contlab);
+ l = isn0;
+ isn0 += 3;
+ branch0(l+0);
+ label0(l+1);
+ branch0(l+2);
+ label0(contlab);
st = NULL;
if ((o=symbol()) != SEMI) { /* test part */
peeksym = o;
ss = starttree();
- st = tree(0);
+ st = tree0(0);
if ((o=symbol()) != SEMI) {
endtree(ss);
return(o);
}
if ((o=symbol()) != RPARN) { /* incr part */
peeksym = o;
- rcexpr(tree(1));
+ rcexpr0(tree0(1));
if ((o=symbol()) != RPARN) {
if (st)
endtree(ss);
return(o);
}
}
- label(l+0);
+ label0(l+0);
if (st) {
- cbranch(st, l+1, 1);
+ cbranch0(st, l+1, 1);
endtree(ss);
} else
- branch(l+1);
- branch(brklab);
- label(l+2);
+ branch0(l+1);
+ branch0(brklab);
+ label0(l+2);
statement();
- branch(contlab);
- label(brklab);
+ branch0(contlab);
+ label0(brklab);
return(0);
}
* A parenthesized expression,
* as after "if".
*/
-union tree *pexpr(eflag) int eflag; {
+union tree0 *pexpr(eflag) int eflag; {
register int o;
- register union tree *t;
+ register union tree0 *t;
if ((o=symbol())!=LPARN)
goto syntax;
- t = tree(eflag);
+ t = tree0(eflag);
if ((o=symbol())!=RPARN)
goto syntax;
if (t->t.type==VOID)
- error("Illegal use of void");
+ error0("Illegal use of void");
return(t);
syntax:
- error("Statement syntax");
+ error0("Statement syntax");
errflush(o);
return(0);
}
* The switch statement, which involves collecting the
* constants and labels for the cases.
*/
-void pswitch() {
+void pswitch0() {
register struct swtab *cswp, *sswp;
int dl, swlab;
cswp = sswp = swp;
if (swp==0)
cswp = swp = swtab;
- branch(swlab=isn++);
+ branch0(swlab=isn0++);
dl = deflab;
deflab = 0;
statement();
- branch(brklab);
- label(swlab);
+ branch0(brklab);
+ label0(swlab);
if (deflab==0)
deflab = brklab;
outcode("BNN", SWIT, deflab, line);
for (; cswp < swp; cswp++)
outcode("NN", cswp->swlab, cswp->swval);
outcode("0");
- label(brklab);
+ label0(brklab);
deflab = dl;
swp = sswp;
}
* Structure resembling a block for a register variable.
*/
struct nmlist hreg = { REG, 0, 0, NULL, NULL, 0 };
-struct tnode areg = { NAME, 0, NULL, NULL, (union tree *)&hreg};
+struct tnode0 areg = { NAME, 0, NULL, NULL, (union tree0 *)&hreg};
void funchead() {
register int pl;
register struct nmlist *cs;
cs->htype -= (ARRAY-PTR); /* set ptr */
cs->hsubsp++; /* pop dims */
}
- pl += rlength((union tree *)cs);
+ pl += rlength((union tree0 *)cs);
if (cs->hclass==AREG && (hreg.hoffset=goodreg(cs))>=0) {
st = starttree();
- *cp++ = (union tree *)&areg;
- *cp++ = nblock(cs);
+ *cp0++ = (union tree0 *)&areg;
+ *cp0++ = nblock(cs);
areg.type = cs->htype;
areg.strp = cs->hstrp;
cs->hclass = AUTO;
build(ASSIGN);
- rcexpr(*--cp);
+ rcexpr0(*--cp0);
cs->hoffset = hreg.hoffset;
cs->hclass = REG;
endtree(st);
for (pl=0; pl<HSHSIZ; pl++) {
for (cs = hshtab[pl]; cs!=NULL; cs = cs->nextnm) {
if (cs->hclass == ARG || cs->hclass==AREG)
- error("Not an argument: %s", cs->name);
+ error0("Not an argument: %s", cs->name);
}
}
outcode("BN", SETREG, regvar);
if (cs->hblklev > blklev
&& (((cs->hflag&FLABL)==0 && cs->hclass!=EXTERN) || blklev<=0)) {
if (cs->hclass==0)
- error("%s undefined", cs->name);
+ error0("%s undefined", cs->name);
if (cs->hclass==EXTERN)
nameconflict(hshtab[i], cs);
*lcs = cs->nextnm;
for (; ocs!=NULL; ocs = ocs->nextnm)
if (ocs!=cs && ocs->hclass==EXTERN &&
strncmp(cs->name, ocs->name, MAXCPS-1) == 0)
- error("names %s and %s conflict", cs->name, ocs->name);
+ error0("names %s and %s conflict", cs->name, ocs->name);
}
/*
}
/*
- * In case of error, skip to the next
+ * In case of error0, skip to the next
* statement delimiter.
*/
void errflush(ao) int ao; {
o = symbol();
if (o==NAME && csym->hclass==TYPEDEF) {
if (tkw >= 0)
- error("type clash");
+ error0("type clash");
tkw = csym->htype;
tptr->hsubsp = csym->hsubsp;
tptr->hstrp = csym->hstrp;
if (skw==ARG && cval==REG)
cval = AREG;
else
- error("Conflict in storage class");
+ error0("Conflict in storage class");
}
skw = cval;
break;
case ENUM:
if (longf || unsignf)
- error("Perverse modifier on 'enum'");
+ error0("Perverse modifier on 'enum'");
strdec(ismos, cval);
cval = INT;
goto types;
case VOID:
types:
if (tkw>=0 && (tkw!=INT || cval!=INT))
- error("Type clash");
+ error0("Type clash");
tkw = cval;
if (unscflg && cval==CHAR)
unsignf++;
else if (tkw==LONG)
tkw = UNLONG;
else
- error("Misplaced 'unsigned'");
+ error0("Misplaced 'unsigned'");
}
if (longf) {
if (tkw==FLOAT)
else if (tkw==UNSIGN)
tkw = UNLONG;
else
- error("Misplaced 'long'");
+ error0("Misplaced 'long'");
}
*scptr = skw;
tptr->htype = tkw;
if (ssym==0)
goto syntax;
if (ssym->hclass!=tagkind)
- error("Bad structure/union/enum name");
+ error0("Bad structure/union/enum name");
peeksym = o;
} else {
ds = defsym;
#else
defsym = ds;
if (strp->S.ssize)
- error("%s redeclared", ssym->name);
+ error0("%s redeclared", ssym->name);
#endif
strp->S.ssize = elsize;
*memlist++ = NULL;
isunion++;
mosflg = FMOS;
if ((peeksym=symbol()) == SEMI) {
- o = length((union tree *)tptr);
+ o = length((union tree0 *)tptr);
if (o>offset)
offset = o;
}
peeksym = -1;
t1 = conexp();
if (t1<0) {
- error("Negative field width");
+ error0("Negative field width");
t1 = 0;
}
elsize = align(tptr->htype, offset, t1);
if (skw==AUTO)
skw = EXTERN;
if ((skw!=EXTERN && skw!=TYPEDEF) && absname==NULL)
- error("Bad func. storage class");
+ error0("Bad func. storage class");
}
if (defsym)
dsym = defsym;
else if (absname)
dsym = absname;
else {
- error("Name required in declaration");
+ error0("Name required in declaration");
return(0);
}
if (defsym)
}
if (dsym->hclass && (dsym->htype&TYPE)==STRUCT && (type&TYPE)==STRUCT)
if (dsym->hstrp != tptr->hstrp) {
- error("structure redeclaration");
+ error0("structure redeclaration");
}
dsym->htype = type;
if (tptr->hstrp)
}
elsize = 0;
if (skw==MOS) {
- elsize = length((union tree *)dsym);
+ elsize = length((union tree0 *)dsym);
if ((peeksym = symbol())==COLON) {
elsize = 0;
peeksym = -1;
elsize += a;
offset += a;
if (++nmems >= NMEMS) {
- error("Too many structure members");
+ error0("Too many structure members");
nmems -= NMEMS/2;
memlist -= NMEMS/2;
}
peeksym = a;
if (skw==AUTO) {
/* if (STAUTO < 0) { */
- autolen -= rlength((union tree *)dsym);
+ autolen -= rlength((union tree0 *)dsym);
dsym->hoffset = autolen;
if (autolen < maxauto)
maxauto = autolen;
cinit(dsym, 0, AUTO);
isinit = 0;
} else if (skw==STATIC) {
- dsym->hoffset = isn;
+ dsym->hoffset = isn0;
if (isinit) {
- outcode("BBN", DATA, LABEL, isn++);
+ outcode("BBN", DATA, LABEL, isn0++);
if (cinit(dsym, 1, STATIC) & ALIGN)
outcode("B", EVEN);
} else
- outcode("BBNBN", BSS, LABEL, isn++, SSPACE,
- rlength((union tree *)dsym));
+ outcode("BBNBN", BSS, LABEL, isn0++, SSPACE,
+ rlength((union tree0 *)dsym));
outcode("B", PROG);
isinit = 0;
} else if (skw==REG && isinit) {
isinit = 0;
} else if (skw==ENUM) {
if (type!=INT)
- error("Illegal enumeration %s", dsym->name);
+ error0("Illegal enumeration %s", dsym->name);
dsym->hclass = ENUMCON;
dsym->hoffset = offset;
if (isinit)
case LBRACK:
if (dimp->rank>=5) {
- error("Rank too large");
+ error0("Rank too large");
dimp->rank = 4;
}
if ((o=symbol()) != RBRACK) {
goto syntax;
} else {
if (dimp->rank!=0)
- error("Null dimension");
+ error0("Null dimension");
cval = 0;
}
dimp->dimens[dimp->rank++] = cval;
* More bits required for type than allowed.
*/
void typov() {
- error("Type is too complicated");
+ error0("Type is too complicated");
}
/*
bitoffs = 0;
}
while ((t&XTYPE)==ARRAY)
- t = decref(t);
+ t = decref0(t);
if (t!=CHAR && t!=UNCHAR) {
a = (a+ALIGN) & ~ALIGN;
if (a>offset)
if (flen) {
if (type==INT || type==UNSIGN) {
if (flen > NBPW)
- error(ftl);
+ error0(ftl);
if (flen+bitoffs > NBPW) {
bitoffs = 0;
a += NCPW;
}
} else if (type==CHAR || type==UNCHAR) {
if (flen > NBPC)
- error(ftl);
+ error0(ftl);
if (flen+bitoffs > NBPC) {
bitoffs = 0;
a += 1;
}
} else
- error("Bad type for field");
+ error0("Bad type for field");
}
return(a-offset);
}
/*
- * Complain about syntax error in declaration
+ * Complain about syntax error0 in declaration
*/
void decsyn(o) int o; {
- error("Declaration syntax");
+ error0("Declaration syntax");
errflush(o);
}
* Complain about a redeclaration
*/
void redec() {
- error("%s redeclared", defsym->name);
+ error0("%s redeclared", defsym->name);
}
/*
* Reduce the degree-of-reference by one.
* e.g. turn "ptr-to-int" into "int".
*/
-int decref(t) register int t; {
+int decref0(t) register int t; {
if ((t & ~TYPE) == 0) {
- error("Illegal indirection");
+ error0("Illegal indirection");
return(t);
}
return((t>>TYLEN) & ~TYPE | t&TYPE);
* Increase the degree of reference by
* one; e.g. turn "int" to "ptr-to-int".
*/
-int incref(t) register int t; {
+int incref0(t) register int t; {
return(((t&~TYPE)<<TYLEN) | (t&TYPE) | PTR);
}
/*
- * Make a tree that causes a branch to lbl
- * if the tree's value is non-zero together with the cond.
+ * Make a tree0 that causes a branch0 to lbl
+ * if the tree0's value is non-zero together with the cond.
*/
-void cbranch(t, lbl, cond) union tree *t; int lbl; int cond; {
+void cbranch0(t, lbl, cond) union tree0 *t; int lbl; int cond; {
treeout(t, 0);
outcode("BNNN", CBRANCH, lbl, cond, line);
}
/*
- * Write out a tree.
+ * Write out a tree0.
*/
-void rcexpr(tp) register union tree *tp; {
+void rcexpr0(tp) register union tree0 *tp; {
/*
* Special optimization
*/
outcode("BN", EXPR, line);
}
-void treeout(tp, isstruct) register union tree *tp; int isstruct; {
+void treeout(tp, isstruct) register union tree0 *tp; int isstruct; {
register struct nmlist *hp;
register int nextisstruct;
- if (tp == NULL || tp->t.op==NULLOP) {
- outcode("B", XNULLOP);
+ if (tp == NULL || tp->t.op==NULLOP0) {
+ outcode("B", NULLOP);
return;
}
nextisstruct = tp->t.type==STRUCT;
case NAME:
hp = &tp->t.tr1->n;
if (hp->hclass==TYPEDEF)
- error("Illegal use of type name");
+ error0("Illegal use of type name");
outcode("BNN", NAME, hp->hclass==0?STATIC:hp->hclass, tp->t.type);
if (hp->hclass==EXTERN)
outcode("S", hp->name);
break;
case ETYPE:
- error("Illegal use of type");
+ error0("Illegal use of type");
break;
case AMPER:
default:
treeout(tp->t.tr1, nextisstruct);
- if (opdope[tp->t.op]&BINARY)
+ if (opdope0[tp->t.op]&BINARY)
treeout(tp->t.tr2, nextisstruct);
outcode("BN", tp->t.op, tp->t.type);
break;
}
/*
- * Generate a branch
+ * Generate a branch0
*/
-void branch(lab) int lab; {
+void branch0(lab) int lab; {
outcode("BN", BRANCH, lab);
}
/*
- * Generate a label
+ * Generate a label0
*/
-void label(l) int l; {
+void label0(l) int l; {
outcode("BN", LABEL, l);
}
/*
- * ap is a tree node whose type
+ * ap is a tree0 node whose type
* is some kind of pointer; return the size of the object
* to which the pointer points.
*/
-int plength(p) register union tree *p; {
+int plength(p) register union tree0 *p; {
register int t, l;
if (p==0 || ((t=p->t.type)&~TYPE) == 0) /* not a reference */
return(1);
- p->t.type = decref(t);
+ p->t.type = decref0(t);
l = length(p);
p->t.type = t;
return(l);
/*
* return the number of bytes in the object
- * whose tree node is acs.
+ * whose tree0 node is acs.
*/
-int length(cs) union tree *cs; {
+int length(cs) union tree0 *cs; {
register int t, elsz;
long n;
int nd;
n = 1;
nd = 0;
while ((t&XTYPE) == ARRAY) {
- t = decref(t);
+ t = decref0(t);
n *= cs->t.subsp[nd++];
}
if ((t&~TYPE)==FUNC)
else switch(t&TYPE) {
case VOID:
- error("Illegal use of void object");
+ error0("Illegal use of void object");
return(2);
case INT:
case STRUCT:
if ((elsz = cs->t.strp->S.ssize) == 0)
- error("Undefined structure");
+ error0("Undefined structure");
break;
default:
- error("Compiler error (length)");
+ error0("Compiler error0 (length)");
return(0);
}
n *= elsz;
if (n >= (_UNSIGNED_INT)50000)
- werror("very large data structure");
+ werror0("very large data structure");
return(n);
}
/*
* The number of bytes in an object, rounded up to a word.
*/
-int rlength(cs) union tree *cs; {
+int rlength(cs) union tree0 *cs; {
return((length(cs)+ALIGN) & ~ALIGN);
}
/*
* After an "if (...) goto", look to see if the transfer
- * is to a simple label.
+ * is to a simple label0.
*/
int simplegoto() {
register struct nmlist *csp;
csp->htype = ARRAY;
csp->hflag |= FLABL;
if (csp->hoffset==0)
- csp->hoffset = isn++;
+ csp->hoffset = isn0++;
}
if ((csp->hclass==0||csp->hclass==STATIC)
&& csp->htype==ARRAY) {
*/
void chconbrk(l) int l; {
if (l==0)
- error("Break/continue error");
+ error0("Break/continue error0");
}
/*
* The goto statement.
*/
void dogoto() {
- register union tree *np;
+ register union tree0 *np;
register char *st;
st = starttree();
- *cp++ = tree(0);
+ *cp0++ = tree0(0);
build(STAR);
- chkw(np = *--cp, -1);
- rcexpr(block(JUMP, 0, (int *)NULL, (union str *)NULL, np, TNULL));
+ chkw(np = *--cp0, -1);
+ rcexpr0(block(JUMP, 0, (int *)NULL, (union str *)NULL, np, TNULL0));
endtree(st);
}
register char *st;
st = starttree();
- *cp++ = (union tree *)&funcblk;
- *cp++ = tree(0);
+ *cp0++ = (union tree0 *)&funcblk0;
+ *cp0++ = tree0(0);
build(ASSIGN);
- cp[-1] = cp[-1]->t.tr2;
+ cp0[-1] = cp0[-1]->t.tr2;
build(RFORCE);
- rcexpr(*--cp);
+ rcexpr0(*--cp0);
endtree(st);
}
- branch(retlab);
+ branch0(retlab);
}
/*
- * Write a character on the error output.
+ * Write a character on the error0 output.
*/
/*
* Coded output:
case '\0':
va_end(ap);
if (ferror(bufp)) {
- error("Write error on temp");
+ error0("Write error0 on temp");
exit(1);
}
return;
default:
- error("Botch in outcode");
+ error0("Botch in outcode");
}
}
* 040-- non-float req. on right
* 0100-- is commutative
* 0200-- is right, not left-associative
- * 0400-- is leaf of tree
+ * 0400-- is leaf of tree0
* *0XX000-- XX is priority of operator
*/
-int opdope[] = {
+int opdope0[] = {
000000, /* EOFC */
000000, /* ; */
000000, /* { */
036001, /* mcall */
000000, /* goto */
000000, /* jump cond */
- 000000, /* branch cond */
+ 000000, /* branch0 cond */
000000, /* 105 */
000000, /* 106 */
000000, /* 107 */
#include <stdio.h>
#include <setjmp.h>
-
-#ifdef pdp11
-typedef int _INT;
-typedef long _LONG;
-typedef unsigned int _UNSIGNED_INT;
-typedef unsigned long _UNSIGNED_LONG;
-typedef float _FLOAT;
-typedef double _DOUBLE;
-#else
-#include <stdint.h>
-typedef int16_t _INT;
-typedef int32_t _LONG;
-typedef uint16_t _UNSIGNED_INT;
-typedef uint32_t _UNSIGNED_LONG;
-typedef struct { uint32_t h; } _FLOAT;
-typedef struct { uint32_t l; uint32_t h; } _DOUBLE;
-#endif
+#include "ccom.h"
#ifndef NULL
#define NULL 0
#endif
-#define TNULL (union tree *)NULL
+#define TNULL1 (union tree1 *)NULL
#define UNS(x) ((unsigned short)(x))
/*
* Tree node for unary and binary
*/
-struct tnode {
+struct tnode1 {
int op;
int type;
int degree;
- union tree *tr1;
- union tree *tr2;
+ union tree1 *tr1;
+ union tree1 *tr2;
};
/*
- * tree names for locals
+ * tree1 names for locals
*/
struct tname {
int op;
};
/*
- * tree names for externals
+ * tree1 names for externals
*/
struct xtname {
int op;
int op;
int type;
int degree;
- union tree *tr1;
- union tree *tr2;
+ union tree1 *tr1;
+ union tree1 *tr2;
int mask;
};
-union tree {
- struct tnode t;
+union tree1 {
+ struct tnode1 t;
struct tname n;
struct xtname x;
struct tconst c;
char *str2;
};
-struct swtab {
- int swlab;
- int swval;
-};
-
extern char maprel[];
extern char notrel[];
extern int nreg;
-extern int isn;
+extern int isn1;
extern int line;
extern int nerror; /* number of hard errors */
extern struct table cctab[];
extern char jmijeq[];
extern struct instab instab[];
extern struct instab branchtab[];
-extern int opdope[];
+extern int opdope1[];
extern char *opntab[];
extern int nstack;
extern int nfloat;
extern int panicposs; /* set when there might be need for regpanic */
extern jmp_buf jmpbuf;
extern long ftell();
-extern char *sbrk();
+/*extern char *sbrk();*/
extern struct optab *match();
-extern union tree *optim();
-extern union tree *unoptim();
-extern union tree *pow2();
-extern union tree *tnode();
-extern union tree *sdelay();
-extern union tree *ncopy();
-extern union tree *getblk();
-extern union tree *strfunc();
-extern union tree *isconstant();
-extern union tree *tconst();
-extern union tree *hardlongs();
-extern union tree *lconst();
-extern union tree *acommute();
-extern union tree *lvfield();
-extern union tree *paint();
+extern union tree1 *optim();
+extern union tree1 *unoptim();
+extern union tree1 *pow2();
+extern union tree1 *tnode1();
+extern union tree1 *sdelay();
+extern union tree1 *ncopy();
+extern union tree1 *getblk();
+extern union tree1 *strfunc();
+extern union tree1 *isconstant();
+extern union tree1 *tconst();
+extern union tree1 *hardlongs();
+extern union tree1 *lconst();
+extern union tree1 *acommute();
+extern union tree1 *lvfield();
+extern union tree1 *paint();
extern long ftell();
/*
*/
extern int xlab1, xlab2, xop, xzero;
-/*
- operators
-*/
-#define EOFC 0
-#define SEMI 1
-#define LBRACE 2
-#define RBRACE 3
-#define LBRACK 4
-#define RBRACK 5
-#define LPARN 6
-#define RPARN 7
-#define COLON 8
-#define COMMA 9
-#define FSEL 10
-#define FSELR 11
-#define FSELT 12
-#define FSELA 16
-#define ULSH 17
-#define ASULSH 18
-
-#define KEYW 19
-#define NAME 20
-#define CON 21
-#define STRING 22
-#define FCON 23
-#define SFCON 24
-#define LCON 25
-#define SLCON 26
-
-#define AUTOI 27
-#define AUTOD 28
-#define NULLOP 218
-#define INCBEF 30
-#define DECBEF 31
-#define INCAFT 32
-#define DECAFT 33
-#define EXCLA 34
-#define AMPER 35
-#define STAR 36
-#define NEG 37
-#define COMPL 38
-
-#define DOT 39
-#define PLUS 40
-#define MINUS 41
-#define TIMES 42
-#define DIVIDE 43
-#define MOD 44
-#define RSHIFT 45
-#define LSHIFT 46
-#define AND 47
-#define ANDN 55
-#define OR 48
-#define EXOR 49
-#define ARROW 50
-#define ITOF 51
-#define FTOI 52
-#define LOGAND 53
-#define LOGOR 54
-#define FTOL 56
-#define LTOF 57
-#define ITOL 58
-#define LTOI 59
-#define ITOP 13
-#define PTOI 14
-#define LTOP 15
-
-#define EQUAL 60
-#define NEQUAL 61
-#define LESSEQ 62
-#define LESS 63
-#define GREATEQ 64
-#define GREAT 65
-#define LESSEQP 66
-#define LESSP 67
-#define GREATQP 68
-#define GREATP 69
-
-#define ASPLUS 70
-#define ASMINUS 71
-#define ASTIMES 72
-#define ASDIV 73
-#define ASMOD 74
-#define ASRSH 75
-#define ASLSH 76
-#define ASAND 77
-#define ASOR 78
-#define ASXOR 79
-#define ASSIGN 80
-#define TAND 81
-#define LTIMES 82
-#define LDIV 83
-#define LMOD 84
-#define ASANDN 85
-#define LASTIMES 86
-#define LASDIV 87
-#define LASMOD 88
-
-#define QUEST 90
-/* #define MAX 93 not used; wanted macros in param.h */
-#define MAXP 94
-/* #define MIN 95 not used; wanted macros in param.h */
-#define MINP 96
-#define LLSHIFT 91
-#define ASLSHL 92
-#define SEQNC 97
-#define CALL1 98
-#define CALL2 99
-#define CALL 100
-#define MCALL 101
-#define JUMP 102
-#define CBRANCH 103
-#define INIT 104
-#define SETREG 105
-#define LOAD 106
-#define PTOI1 107
-#define ITOC 109
-#define RFORCE 110
-
-/*
- * Intermediate code operators
- */
-#define BRANCH 111
-#define LABEL 112
-#define NLABEL 113
-#define RLABEL 114
-#define STRASG 115
-#define STRSET 116
-#define UDIV 117
-#define UMOD 118
-#define ASUDIV 119
-#define ASUMOD 120
-#define ULTIMES 121 /* present for symmetry */
-#define ULDIV 122
-#define ULMOD 123
-#define ULASTIMES 124 /* present for symmetry */
-#define ULASDIV 125
-#define ULASMOD 126
-#define ULTOF 127
-#define ULLSHIFT 128 /* << for unsigned long */
-#define UASLSHL 129 /* <<= for unsigned long */
-
-#define BDATA 200
-#define PROG 202
-#define DATA 203
-#define BSS 204
-#define CSPACE 205
-#define SSPACE 206
-#define SYMDEF 207
-#define SAVE 208
-#define RETRN 209
-#define EVEN 210
-#define PROFIL 212
-#define SWIT 213
-#define EXPR 214
-#define SNAME 215
-#define RNAME 216
-#define ANAME 217
-#define SETSTK 219
-#define SINIT 220
-#define GLOBAL 221
-#define C3BRANCH 222
-#define ASSEM 223
-
-/*
- * types
- */
-#define INT 0
-#define CHAR 1
-#define FLOAT 2
-#define DOUBLE 3
-#define STRUCT 4
-#define RSTRUCT 5
-#define LONG 6
-#define UNSIGN 7
-#define UNCHAR 8
-#define UNLONG 9
-#define VOID 10
-
-#define TYLEN 2
-#define TYPE 017
-#define XTYPE (03<<4)
-#define PTR 020
-#define FUNC 040
-#define ARRAY 060
-
-/*
- storage classes
-*/
-#define KEYWC 1
-#define MOS 10
-#define AUTO 11
-#define EXTERN 12
-#define STATIC 13
-#define REG 14
-#define STRTAG 15
-#define ARG 16
-#define OFFS 20
-#define XOFFS 21
-#define SOFFS 22
-
-/*
- Flag bits
-*/
-
-#define BINARY 01
-#define LVALUE 02
-#define RELAT 04
-#define ASSGOP 010
-#define LWORD 020
-#define RWORD 040
-#define COMMUTE 0100
-#define RASSOC 0200
-#define LEAF 0400
-#define CNVRT 01000
-
#if 1 /* moved here from c12.c */
#define LSTSIZ 20
struct acl {
int nextl;
int nextn;
- union tree *nlist[LSTSIZ];
- union tree *llist[LSTSIZ+1];
+ union tree1 *nlist[LSTSIZ];
+ union tree1 *llist[LSTSIZ+1];
};
#endif
/* c10.c */
int main __P((int argc, char *argv[]));
-struct optab *match __P((union tree *tree, struct table *table, int nrleft, int nocvt));
-int rcexpr __P((union tree *atree, struct table *atable, int reg));
-int cexpr __P((register union tree *tree, struct table *table, int areg));
-int reorder __P((union tree **treep, struct table *table, int reg));
-int sreorder __P((union tree **treep, struct table *table, int reg, int recurf));
-int delay __P((union tree **treep, struct table *table, int reg));
-union tree *sdelay __P((union tree **ap));
-union tree *paint __P((register union tree *tp, register int type));
-union tree *ncopy __P((register union tree *p));
-int chkleaf __P((register union tree *tree, struct table *table, int reg));
-int comarg __P((register union tree *tree, int *flagp));
-union tree *strfunc __P((register union tree *tp));
-void doinit __P((register int type, register union tree *tree));
-void movreg __P((int r0, int r1, union tree *tree));
+struct optab *match __P((union tree1 *tree1, struct table *table, int nrleft, int nocvt));
+int rcexpr1 __P((union tree1 *atree, struct table *atable, int reg));
+int cexpr __P((register union tree1 *tree1, struct table *table, int areg));
+int reorder __P((union tree1 **treep, struct table *table, int reg));
+int sreorder __P((union tree1 **treep, struct table *table, int reg, int recurf));
+int delay __P((union tree1 **treep, struct table *table, int reg));
+union tree1 *sdelay __P((union tree1 **ap));
+union tree1 *paint __P((register union tree1 *tp, register int type));
+union tree1 *ncopy __P((register union tree1 *p));
+int chkleaf __P((register union tree1 *tree1, struct table *table, int reg));
+int comarg __P((register union tree1 *tree1, int *flagp));
+union tree1 *strfunc __P((register union tree1 *tp));
+void doinit __P((register int type, register union tree1 *tree1));
+void movreg __P((int r0, int r1, union tree1 *tree1));
/* c11.c */
-int degree __P((register union tree *t));
-void pname __P((register union tree *p, int flag));
-void pbase __P((register union tree *p));
-int xdcalc __P((register union tree *p, int nrleft));
-int dcalc __P((register union tree *p, int nrleft));
-int notcompat __P((register union tree *p, int ast, int deg, int op));
+int degree __P((register union tree1 *t));
+void pname __P((register union tree1 *p, int flag));
+void pbase __P((register union tree1 *p));
+int xdcalc __P((register union tree1 *p, int nrleft));
+int dcalc __P((register union tree1 *p, int nrleft));
+int notcompat __P((register union tree1 *p, int ast, int deg, int op));
int prins __P((int op, int c, struct instab *itable, int lbl));
-int collcon __P((register union tree *p));
-int isfloat __P((register union tree *t));
-int oddreg __P((register union tree *t, register int reg));
+int collcon __P((register union tree1 *p));
+int isfloat __P((register union tree1 *t));
+int oddreg __P((register union tree1 *t, register int reg));
int arlength __P((int t));
-void pswitch __P((struct swtab *afp, struct swtab *alp, int deflab));
+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 union tree *tree));
-union tree *pow2 __P((register union tree *tree));
-void cbranch __P((union tree *atree, register int lbl, int cond, register int reg));
-void branch __P((int lbl, int aop, int c));
-void longrel __P((union tree *atree, int lbl, int cond, int reg));
+int ispow2 __P((register union tree1 *tree1));
+union tree1 *pow2 __P((register union tree1 *tree1));
+void cbranch1 __P((union tree1 *atree, register int lbl, int cond, register int reg));
+void branch1 __P((int lbl, int aop, int c));
+void longrel __P((union tree1 *atree, int lbl, int cond, int reg));
int xlongrel __P((int f));
-void label __P((int l));
+void label1 __P((int l));
void popstk __P((int a));
-void werror __P((char *s));
-void error __P((char *s, ...));
+void werror1 __P((char *s));
+void error1 __P((char *s, ...));
void psoct __P((int an));
void getree __P((void));
int geti __P((void));
-void strasg __P((union tree *atp));
-int decref __P((register int t));
-int incref __P((register int t));
+void strasg __P((union tree1 *atp));
+int decref1 __P((register int t));
+int incref1 __P((register int t));
/* c12.c */
-union tree *optim __P((register union tree *tree));
-union tree *unoptim __P((register union tree *tree));
-union tree *lvfield __P((register union tree *t));
-union tree *acommute __P((register union tree *tree));
-int sideeffects __P((register union tree *tp));
+union tree1 *optim __P((register union tree1 *tree1));
+union tree1 *unoptim __P((register union tree1 *tree1));
+union tree1 *lvfield __P((register union tree1 *t));
+union tree1 *acommute __P((register union tree1 *tree1));
+int sideeffects __P((register union tree1 *tp));
void distrib __P((struct acl *list));
-void squash __P((union tree **p, union tree **maxp));
+void squash __P((union tree1 **p, union tree1 **maxp));
void _const __P((int op, register _INT *vp, _INT v, int type));
-union tree *lconst __P((int op, register union tree *lp, register union tree *rp));
-void insert __P((int op, register union tree *tree, register struct acl *list));
-union tree *tnode __P((int op, int type, union tree *tr1, union tree *tr2));
-union tree *tconst __P((int val, int type));
-union tree *getblk __P((int size));
+union tree1 *lconst __P((int op, register union tree1 *lp, register union tree1 *rp));
+void insert __P((int op, register union tree1 *tree1, register struct acl *list));
+union tree1 *tnode1 __P((int op, int type, union tree1 *tr1, union tree1 *tr2));
+union tree1 *tconst __P((int val, int type));
+union tree1 *getblk __P((int size));
int islong __P((int t));
-union tree *isconstant __P((register union tree *t));
-union tree *hardlongs __P((register union tree *t));
-int uns __P((union tree *tp));
+union tree1 *isconstant __P((register union tree1 *t));
+union tree1 *hardlongs __P((register union tree1 *t));
+int uns __P((union tree1 *tp));
#ifndef pdp11
/* fp.c */
/*
* C compiler, part 2
*
- * (long)btodb(l) produced 'no code table error for op: >>(17) type: 6'
+ * (long)btodb(l) produced 'no code table error1 for op: >>(17) type: 6'
* allow both long and ulong at line ~341. 1996/6/19
*/
#endif
#include <stdlib.h>
+#include <unistd.h>
#include "c1.h"
#ifdef DEBUG
struct table *cregtab;
int nreg = 3;
-int isn = 10000;
+int isn1 = 10000;
int main(argc, argv) int argc; char *argv[]; {
char buf1[BUFSIZ],
buf2[BUFSIZ];
if (argc<4) {
- error("Arg count");
+ error1("Arg count");
exit(1);
}
if (freopen(argv[1], "r", stdin)==NULL) {
- error("Missing temp file");
+ error1("Missing temp file");
exit(1);
}
setbuf(stdin,buf1); /* sbrk problems */
if ((freopen(argv[3], "w", stdout)) == NULL) {
- error("Can't create %s", argv[3]);
+ error1("Can't create %s", argv[3]);
exit(1);
}
setbuf(stdout,buf2); /* sbrk problems */
printf(".globl\n.data\n");
if (*argv[2] != '-') {
if (freopen(argv[2], "r", stdin)==NULL) {
- error("Missing temp file");
+ error1("Missing temp file");
exit(1);
}
setbuf(stdin,buf1); /* sbrk problems */
getree();
}
if (totspace >= (_UNSIGNED_INT)56000)
- werror("possibly too much data");
+ werror1("possibly too much data");
exit(nerror!=0);
}
/*
- * Given a tree, a code table, and a
+ * Given a tree1, a code table, and a
* count of available registers, find the code table
* for the appropriate operator such that the operands
* are of the right type and the number of registers
* required is not too large.
* Return a ptr to the table entry or 0 if none found.
*/
-struct optab *match(tree, table, nrleft, nocvt) union tree *tree; struct table *table; int nrleft; int nocvt; {
+struct optab *match(tree1, table, nrleft, nocvt) union tree1 *tree1; struct table *table; int nrleft; int nocvt; {
#define NOCVL 1
#define NOCVR 2
int op, d1, d2, dope;
- union tree *p2;
- register union tree *p1;
+ union tree1 *p2;
+ register union tree1 *p1;
register struct optab *opt;
- if (tree==NULL)
+ if (tree1==NULL)
return(NULL);
if (table==lsptab)
table = sptab;
- if ((op = tree->t.op)==0)
+ if ((op = tree1->t.op)==0)
return(0);
- dope = opdope[op];
+ dope = opdope1[op];
if ((dope&LEAF) == 0)
- p1 = tree->t.tr1;
+ p1 = tree1->t.tr1;
else
- p1 = tree;
+ p1 = tree1;
d1 = dcalc(p1, nrleft);
if ((dope&BINARY)!=0) {
- p2 = tree->t.tr2;
+ p2 = tree1->t.tr2;
/*
* If a subtree starts off with a conversion operator,
* try for a match with the conversion eliminated.
* the converted int in a register by
* movf double,fr0; movfi fr0,int .
*/
- if (opdope[p2->t.op]&CNVRT && (nocvt&NOCVR)==0
- && (opdope[p2->t.tr1->t.op]&CNVRT)==0) {
- tree->t.tr2 = p2->t.tr1;
- if (opt = match(tree, table, nrleft, NOCVL))
+ if (opdope1[p2->t.op]&CNVRT && (nocvt&NOCVR)==0
+ && (opdope1[p2->t.tr1->t.op]&CNVRT)==0) {
+ tree1->t.tr2 = p2->t.tr1;
+ if (opt = match(tree1, table, nrleft, NOCVL))
return(opt);
- tree->t.tr2 = p2;
- } else if (opdope[p1->t.op]&CNVRT && (nocvt&NOCVL)==0
- && (opdope[p1->t.tr1->t.op]&CNVRT)==0) {
- tree->t.tr1 = p1->t.tr1;
- if (opt = match(tree, table, nrleft, NOCVR))
+ tree1->t.tr2 = p2;
+ } else if (opdope1[p1->t.op]&CNVRT && (nocvt&NOCVL)==0
+ && (opdope1[p1->t.tr1->t.op]&CNVRT)==0) {
+ tree1->t.tr1 = p1->t.tr1;
+ if (opt = match(tree1, table, nrleft, NOCVR))
return(opt);
- tree->t.tr1 = p1;
+ tree1->t.tr1 = p1;
}
d2 = dcalc(p2, nrleft);
}
continue;
if (notcompat(p1, opt->tabtyp1, opt->tabdeg1, op))
continue;
- if ((opdope[op]&BINARY)!=0 && p2!=0) {
+ if ((opdope1[op]&BINARY)!=0 && p2!=0) {
if (d2 > (opt->tabdeg2&077)
|| (opt->tabdeg2 >= 0100) && (p2->t.op != STAR) )
continue;
}
/*
- * Given a tree, a code table, and a register,
- * produce code to evaluate the tree with the appropriate table.
+ * Given a tree1, a code table, and a register,
+ * produce code to evaluate the tree1 with the appropriate table.
* Registers reg and upcan be used.
* If there is a value, it is desired that it appear in reg.
* The routine returns the register in which the value actually appears.
- * This routine must work or there is an error.
+ * This routine must work or there is an error1.
* If the table called for is cctab, sptab, or efftab,
- * and tree can't be done using the called-for table,
+ * and tree1 can't be done using the called-for table,
* another try is made.
- * If the tree can't be compiled using cctab, regtab is
+ * If the tree1 can't be compiled using cctab, regtab is
* used and a "tst" instruction is produced.
- * If the tree can't be compiled using sptab,
+ * If the tree1 can't be compiled using sptab,
* regtab is used and the register is pushed on the stack.
- * If the tree can't be compiled using efftab,
+ * If the tree1 can't be compiled using efftab,
* just use regtab.
- * Regtab must succeed or an "op not found" error results.
+ * Regtab must succeed or an "op not found" error1 results.
*
* A number of special cases are recognized, and
* there is an interaction with the optimizer routines.
*/
-int rcexpr(atree, atable, reg) union tree *atree; struct table *atable; int reg; {
+int rcexpr1(atree, atable, reg) union tree1 *atree; struct table *atable; int reg; {
register int r;
int modf, nargs, recurf;
- register union tree *tree;
+ register union tree1 *tree1;
register struct table *table;
- /*fprintf(stderr, "rcexpr(0x%08x, 0x%08x, 0x%08x)\n", atree, atable, reg);*/
+ /*fprintf(stderr, "rcexpr1(0x%08x, 0x%08x, 0x%08x)\n", atree, atable, reg);*/
table = atable;
recurf = 0;
if (reg<0) {
}
}
again:
- if((tree=atree)==0)
+ if((tree1=atree)==0)
return(0);
- if (tree->t.type==VOID) {
+ if (tree1->t.type==VOID) {
if (table!=efftab)
- error("Illegal use of void");
- tree->t.type = INT;
+ error1("Illegal use of void");
+ tree1->t.type = INT;
}
- if (opdope[tree->t.op]&RELAT && tree->t.tr2->t.op==CON
- && tree->t.tr2->c.value==0
+ if (opdope1[tree1->t.op]&RELAT && tree1->t.tr2->t.op==CON
+ && tree1->t.tr2->c.value==0
&& table==cctab)
- tree = atree = tree->t.tr1;
+ tree1 = atree = tree1->t.tr1;
/*
* fieldselect(...) : in efftab mode,
* ignore the select, otherwise
* do the shift and mask.
*/
- if (tree->t.op == FSELT) {
+ if (tree1->t.op == FSELT) {
if (table==efftab)
- atree = tree = tree->t.tr1;
+ atree = tree1 = tree1->t.tr1;
else {
- tree->t.op = FSEL;
- atree = tree = optim(tree);
+ tree1->t.op = FSEL;
+ atree = tree1 = optim(tree1);
}
}
- switch (tree->t.op) {
+ switch (tree1->t.op) {
/*
* Structure assignments
*/
case STRASG:
- strasg(tree);
+ strasg(tree1);
return(0);
/*
* An initializing expression
*/
case INIT:
- tree = optim(tree);
- doinit(tree->t.type, tree->t.tr1);
+ tree1 = optim(tree1);
+ doinit(tree1->t.type, tree1->t.tr1);
return(0);
/*
* for a switch or a return
*/
case RFORCE:
- tree = tree->t.tr1;
- if((r=rcexpr(tree, regtab, reg)) != 0)
- movreg(r, 0, tree);
+ tree1 = tree1->t.tr1;
+ if((r=rcexpr1(tree1, regtab, reg)) != 0)
+ movreg(r, 0, tree1);
return(0);
/*
*/
case SEQNC:
r = nstack;
- rcexpr(tree->t.tr1, efftab, reg);
+ rcexpr1(tree1->t.tr1, efftab, reg);
nstack = r;
- atree = tree = tree->t.tr2;
+ atree = tree1 = tree1->t.tr2;
goto again;
/*
*/
case ANDN:
if (table==cctab) {
- tree->t.op = TAND;
- tree->t.tr2 = optim(tnode(COMPL, tree->t.type, tree->t.tr2, TNULL));
+ tree1->t.op = TAND;
+ tree1->t.tr2 = optim(tnode1(COMPL, tree1->t.type, tree1->t.tr2, TNULL1));
}
break;
* stop working. The compiler has been tested in all these
* different cases with the catch commented out and all the
* code generated was correct. So what was it here for?
- * If a strange error crops up, uncommenting the catch might
+ * If a strange error1 crops up, uncommenting the catch might
* be tried ...
*/
- if (tree->t.tr1->t.op!=NAME || tree->t.tr1->n.class!=EXTERN) {
+ if (tree1->t.tr1->t.op!=NAME || tree1->t.tr1->n.class!=EXTERN) {
nargs++;
nstack++;
}
#endif
- tree = tree->t.tr2;
- if(tree->t.op) {
- while (tree->t.op==COMMA) {
- r += comarg(tree->t.tr2, &modf);
- tree = tree->t.tr1;
+ tree1 = tree1->t.tr2;
+ if(tree1->t.op) {
+ while (tree1->t.op==COMMA) {
+ r += comarg(tree1->t.tr2, &modf);
+ tree1 = tree1->t.tr1;
nargs++;
}
- r += comarg(tree, &modf);
+ r += comarg(tree1, &modf);
nargs++;
}
- tree = atree;
- tree->t.op = CALL2;
- if (modf && tree->t.tr1->t.op==NAME
- && tree->t.tr1->n.class==EXTERN)
- tree->t.op = CALL1;
- if (cexpr(tree, regtab, reg)<0)
- error("compiler botch: call");
+ tree1 = atree;
+ tree1->t.op = CALL2;
+ if (modf && tree1->t.tr1->t.op==NAME
+ && tree1->t.tr1->n.class==EXTERN)
+ tree1->t.op = CALL1;
+ if (cexpr(tree1, regtab, reg)<0)
+ error1("compiler botch: call");
popstk(r);
nstack -= nargs;
if (table==efftab || table==regtab)
*/
case ASULSH: /* 18 */
case ULSH: /* 17 */
- if (tree->t.type != LONG && tree->t.type != UNLONG)
+ if (tree1->t.type != LONG && tree1->t.type != UNLONG)
break;
- if (tree->t.tr2->t.op==ITOL)
- tree->t.tr2 = tree->t.tr2->t.tr1;
+ if (tree1->t.tr2->t.op==ITOL)
+ tree1->t.tr2 = tree1->t.tr2->t.tr1;
else
- tree->t.tr2 = optim(tnode(LTOI,INT,tree->t.tr2,TNULL));
- if (tree->t.op==ASULSH)
+ tree1->t.tr2 = optim(tnode1(LTOI,INT,tree1->t.tr2,TNULL1));
+ if (tree1->t.op==ASULSH)
{
- tree->t.op = UASLSHL;
- tree->t.tr1 = tnode(AMPER, LONG+PTR, tree->t.tr1, TNULL);
+ tree1->t.op = UASLSHL;
+ tree1->t.tr1 = tnode1(AMPER, LONG+PTR, tree1->t.tr1, TNULL1);
}
else
- tree->t.op = ULLSHIFT;
+ tree1->t.op = ULLSHIFT;
break;
case ASLSH:
case LSHIFT:
- if (tree->t.type==LONG || tree->t.type==UNLONG) {
- if (tree->t.tr2->t.op==ITOL)
- tree->t.tr2 = tree->t.tr2->t.tr1;
+ if (tree1->t.type==LONG || tree1->t.type==UNLONG) {
+ if (tree1->t.tr2->t.op==ITOL)
+ tree1->t.tr2 = tree1->t.tr2->t.tr1;
else
- tree->t.tr2 = optim(tnode(LTOI,INT,tree->t.tr2,TNULL));
- if (tree->t.op==ASLSH)
- tree->t.op = ASLSHL;
+ tree1->t.tr2 = optim(tnode1(LTOI,INT,tree1->t.tr2,TNULL1));
+ if (tree1->t.op==ASLSH)
+ tree1->t.op = ASLSHL;
else
- tree->t.op = LLSHIFT;
+ tree1->t.op = LLSHIFT;
}
break;
*/
case TIMES:
case ASTIMES:
- tree = pow2(tree);
+ tree1 = pow2(tree1);
}
/*
* Try to find postfix ++ and -- operators that can be
* pulled out and done after the rest of the expression
*/
if (table!=cctab && table!=cregtab && recurf<2
- && (opdope[tree->t.op]&LEAF)==0) {
+ && (opdope1[tree1->t.op]&LEAF)==0) {
if (r=delay(&atree, table, reg)) {
- tree = atree;
+ tree1 = atree;
table = efftab;
reg = r-1;
}
if (table==cctab && atree->t.op==NAME)
return(reg);
}
- tree = atree;
- if (table==efftab && tree->t.op==NAME)
+ tree1 = atree;
+ if (table==efftab && tree1->t.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 ((r=cexpr(tree1, table, reg))>=0) {
+ if (table==cregtab && (tree1->t.op==INCAFT
+ || tree1->t.op==DECAFT || tree1->t.op==TIMES))
goto fixup;
return(r);
}
- if (table!=regtab && (table!=cctab||(opdope[tree->t.op]&RELAT)==0)) {
- if((r=cexpr(tree, regtab, reg))>=0) {
+ if (table!=regtab && (table!=cctab||(opdope1[tree1->t.op]&RELAT)==0)) {
+ if((r=cexpr(tree1, regtab, reg))>=0) {
fixup:
- modf = isfloat(tree);
- dbprint(tree->t.op);
+ modf = isfloat(tree1);
+ dbprint(tree1->t.op);
if (table==sptab || table==lsptab) {
- if (tree->t.type==LONG || tree->t.type==UNLONG){
+ if (tree1->t.type==LONG || tree1->t.type==UNLONG){
printf("mov\tr%d,-(sp)\n",r+1);
nstack++;
}
/*
* Special grace for unsigned chars as right operands
*/
- if (opdope[tree->t.op]&BINARY && tree->t.tr2->t.type==UNCHAR) {
- tree->t.tr2 = tnode(LOAD, UNSIGN, tree->t.tr2, TNULL);
- return(rcexpr(tree, table, reg));
+ if (opdope1[tree1->t.op]&BINARY && tree1->t.tr2->t.type==UNCHAR) {
+ tree1->t.tr2 = tnode1(LOAD, UNSIGN, tree1->t.tr2, TNULL1);
+ return(rcexpr1(tree1, table, reg));
}
/*
* There's a last chance for this operator
*/
- if (tree->t.op==LTOI) {
- r = rcexpr(tree->t.tr1, regtab, reg);
+ if (tree1->t.op==LTOI) {
+ r = rcexpr1(tree1->t.tr1, regtab, reg);
if (r >= 0) {
r++;
goto fixup;
}
}
- r = tree->t.op;
- if (tree->t.type == STRUCT)
- error("Illegal operation on structure");
+ r = tree1->t.op;
+ if (tree1->t.type == STRUCT)
+ error1("Illegal operation on structure");
else if (r > 0 && r < UASLSHL && opntab[r])
- error("No code table for op: %s(%d) type: %d", opntab[r], r,
- tree->t.type);
+ error1("No code table for op: %s(%d) type: %d", opntab[r], r,
+ tree1->t.type);
else
- error("No code table for op %d", r);
+ error1("No code table for op %d", r);
return(reg);
}
/*
- * Try to compile the tree with the code table using
+ * Try to compile the tree1 with the code table using
* registers areg and up. If successful,
* return the register where the value actually ended up.
* If unsuccessful, return -1.
* Most of the work is the macro-expansion of the
* code table.
*/
-int cexpr(tree, table, areg) register union tree *tree; struct table *table; int areg; {
+int cexpr(tree1, table, areg) register union tree1 *tree1; struct table *table; int areg; {
int c, r;
- register union tree *p, *p1;
+ register union tree1 *p, *p1;
struct table *ctable;
- union tree *p2;
+ union tree1 *p2;
char *string;
int reg, reg1, rreg, flag, opd;
struct optab *opt;
reg = areg;
- p1 = tree->t.tr2;
- c = tree->t.op;
- opd = opdope[c];
+ p1 = tree1->t.tr2;
+ c = tree1->t.op;
+ opd = opdope1[c];
/*
* When the value of a relational or a logical expression is
* desired, more work must be done.
*/
if ((opd&RELAT||c==LOGAND||c==LOGOR||c==EXCLA) && table!=cctab) {
- cbranch(tree, c=isn++, 1, reg);
- rcexpr((union tree *)&czero, table, reg);
- branch(isn, 0, 0);
- label(c);
- rcexpr((union tree *)&cone, table, reg);
- label(isn++);
+ cbranch1(tree1, c=isn1++, 1, reg);
+ rcexpr1((union tree1 *)&czero, table, reg);
+ branch1(isn1, 0, 0);
+ label1(c);
+ rcexpr1((union tree1 *)&cone, table, reg);
+ label1(isn1++);
return(reg);
}
if(c==QUEST) {
if (table==cctab)
return(-1);
- cbranch(tree->t.tr1, c=isn++, 0, reg);
+ cbranch1(tree1->t.tr1, c=isn1++, 0, reg);
flag = nstack;
- rreg = rcexpr(p1->t.tr1, table, reg);
+ rreg = rcexpr1(p1->t.tr1, table, reg);
nstack = flag;
- branch(r=isn++, 0, 0);
- label(c);
- reg = rcexpr(p1->t.tr2, table, rreg);
+ branch1(r=isn1++, 0, 0);
+ label1(c);
+ reg = rcexpr1(p1->t.tr2, table, rreg);
if (rreg!=reg)
- movreg(reg, rreg, tree->t.tr2);
- label(r);
+ movreg(reg, rreg, tree1->t.tr2);
+ label1(r);
return(rreg);
}
- reg = oddreg(tree, reg);
+ reg = oddreg(tree1, reg);
reg1 = reg+1;
/*
* long values take 2 registers.
*/
- if ((tree->t.type==LONG||tree->t.type==UNLONG||opd&RELAT&&(tree->t.tr1->t.type==LONG||tree->t.tr1->t.type==UNLONG))
- && tree->t.op!=ITOL)
+ if ((tree1->t.type==LONG||tree1->t.type==UNLONG||opd&RELAT&&(tree1->t.tr1->t.type==LONG||tree1->t.tr1->t.type==UNLONG))
+ && tree1->t.op!=ITOL)
reg1++;
/*
- * Leaves of the expression tree
+ * Leaves of the expression tree1
*/
- if ((r = chkleaf(tree, table, reg)) >= 0)
+ if ((r = chkleaf(tree1, table, reg)) >= 0)
return(r);
/*
* x + (-1) is better done as x-1.
*/
- if (tree->t.op==PLUS||tree->t.op==ASPLUS) {
- if ((p1=tree->t.tr2)->t.op==CON && p1->c.value==-1) {
+ if (tree1->t.op==PLUS||tree1->t.op==ASPLUS) {
+ if ((p1=tree1->t.tr2)->t.op==CON && p1->c.value==-1) {
p1->c.value = -p1->c.value;
- tree->t.op += (MINUS-PLUS);
+ tree1->t.op += (MINUS-PLUS);
}
}
/*
* Because of a peculiarity of the PDP11 table
* char = *intreg++ and *--intreg cannot go through.
*/
- if (tree->t.tr2 && (tree->t.tr2->t.op==AUTOI||tree->t.tr2->t.op==AUTOD)
- && (tree->t.tr1->t.type==CHAR || tree->t.tr1->t.type==UNCHAR)
- && tree->t.tr2->t.type!=CHAR && tree->t.tr2->t.type!=UNCHAR)
- tree->t.tr2 = tnode(LOAD, tree->t.tr2->t.type, tree->t.tr2, TNULL);
+ if (tree1->t.tr2 && (tree1->t.tr2->t.op==AUTOI||tree1->t.tr2->t.op==AUTOD)
+ && (tree1->t.tr1->t.type==CHAR || tree1->t.tr1->t.type==UNCHAR)
+ && tree1->t.tr2->t.type!=CHAR && tree1->t.tr2->t.type!=UNCHAR)
+ tree1->t.tr2 = tnode1(LOAD, tree1->t.tr2->t.type, tree1->t.tr2, TNULL1);
/*
* 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 (tree->t.tr2 && tree->t.tr1->t.op == NAME
- && tree->t.tr1->n.class == REG && tree->t.op == ASSIGN
- && tree->t.tr2->t.type == UNCHAR)
- tree->t.tr2 = tnode(LOAD, UNSIGN, tree->t.tr2, TNULL);
+ if (tree1->t.tr2 && tree1->t.tr1->t.op == NAME
+ && tree1->t.tr1->n.class == REG && tree1->t.op == ASSIGN
+ && tree1->t.tr2->t.type == UNCHAR)
+ tree1->t.tr2 = tnode1(LOAD, UNSIGN, tree1->t.tr2, TNULL1);
if (table==cregtab)
table = regtab;
/*
* a shift or
* postfix ++ or --. Unravelled, if the table is
* cctab and the operator is not special, try first
- * for efftab; if the table isn't, if the operator is,
+ * for efftab; if the table isn1't, if the operator is,
* or the first match fails, try to match
* with the table actually asked for.
*/
* r = nreg - reg - (reg-areg) - (reg1-reg-1);
*/
r = nreg - reg + areg - reg1 + 1;
- if (table!=cctab || c==INCAFT || c==DECAFT || tree->t.type==LONG || tree->t.type==UNLONG
-/* || c==ASRSH || c==ASLSH || c==ASULSH || tree->t.tr1->t.type==UNCHAR */
+ if (table!=cctab || c==INCAFT || c==DECAFT || tree1->t.type==LONG || tree1->t.type==UNLONG
+/* || c==ASRSH || c==ASLSH || c==ASULSH || tree1->t.tr1->t.type==UNCHAR */
|| c==ASRSH || c==ASLSH || c==ASULSH
- || (opt = match(tree, efftab, r, 0)) == 0)
- if ((opt=match(tree, table, r, 0))==0)
+ || (opt = match(tree1, efftab, r, 0)) == 0)
+ if ((opt=match(tree1, table, r, 0))==0)
return(-1);
string = opt->tabstring;
- p1 = tree->t.tr1;
+ p1 = tree1->t.tr1;
if (p1->t.op==FCON && p1->f.value>0) {
#ifdef pdp11
/* nonportable */
p1->f/*c*/.value = -p1->f/*c*/.value;
}
p2 = 0;
- if (opdope[tree->t.op]&BINARY) {
- p2 = tree->t.tr2;
+ if (opdope1[tree1->t.op]&BINARY) {
+ p2 = tree1->t.tr2;
if (p2->t.op==FCON && p2->f.value>0) {
#ifdef pdp11
/* nonportable */
switch (c) {
case '\n':
- dbprint(tree->t.op);
+ dbprint(tree1->t.op);
break;
case '\0':
- if (!isfloat(tree))
- if (tree->t.op==DIVIDE||tree->t.op==ASDIV)
+ if (!isfloat(tree1))
+ if (tree1->t.op==DIVIDE||tree1->t.op==ASDIV)
reg--;
- if (table==regtab && (opdope[tree->t.op]&ASSGOP)) {
- if (tree->t.tr1->t.type==CHAR)
+ if (table==regtab && (opdope1[tree1->t.op]&ASSGOP)) {
+ if (tree1->t.tr1->t.type==CHAR)
printf("movb r%d,r%d\n", reg, reg);
}
return(reg);
string++;
else
c = 0;
- prins(tree->t.op, c, instab, 0);
+ prins(tree1->t.op, c, instab, 0);
goto loop;
/* B1 */
case 'C':
if ((opd&LEAF) != 0)
- p = tree;
+ p = tree1;
else
p = p1;
goto pbyte;
/* BF */
case 'P':
- p = tree;
+ p = tree1;
goto pb1;
/* B2 */
if (p1->t.type==CHAR || p2->t.type==CHAR
|| p1->t.type==UNCHAR || p2->t.type==UNCHAR)
putchar('b');
- p = tree;
+ p = tree1;
goto pb1;
/* F */
/* H */
case 'H':
- p = tree;
+ p = tree1;
flag = 04;
subtre:
if ((c&04)!=0)
ctable = cctab;
if ((flag&01) && ctable==regtab && (c&01)==0
- && ((c&040)||tree->t.op==DIVIDE||tree->t.op==MOD
- || tree->t.op==ASDIV||tree->t.op==ASMOD||tree->t.op==ITOL))
+ && ((c&040)||tree1->t.op==DIVIDE||tree1->t.op==MOD
+ || tree1->t.op==ASDIV||tree1->t.op==ASMOD||tree1->t.op==ITOL))
ctable = cregtab;
if ((c&01)!=0) {
p = p->t.tr1;
if (c&010)
r = reg1;
else
- if (opdope[p->t.op]&LEAF || p->t.degree < 2)
+ if (opdope1[p->t.op]&LEAF || p->t.degree < 2)
r = reg;
else
r = areg;
- rreg = rcexpr(p, ctable, r);
+ rreg = rcexpr1(p, ctable, r);
if (ctable!=regtab && ctable!=cregtab)
goto loop;
if (c&010) {
else
reg1 = rreg;
} else if (rreg!=reg)
- if ((c&020)==0 && oddreg(tree, 0)==0 && tree->t.type!=LONG
- && tree->t.type!=UNLONG
+ if ((c&020)==0 && oddreg(tree1, 0)==0 && tree1->t.type!=LONG
+ && tree1->t.type!=UNLONG
&& (flag&04
|| flag&01&&xdcalc(p2,nreg-rreg-1)<=(opt->tabdeg2&077)
|| flag&02&&xdcalc(p1,nreg-rreg-1)<=(opt->tabdeg1&077))) {
string++;
r++;
}
- if (r>nreg || r>=4 && tree->t.type==DOUBLE) {
+ if (r>nreg || r>=4 && tree1->t.type==DOUBLE) {
if (regpanic)
- error("Register overflow: simplify expression");
+ error1("Register overflow: simplify expression");
else
longjmp(jmpbuf, 1);
}
goto loop;
case 'V': /* adc sbc, clr, or sxt as required for longs */
- switch(tree->t.op) {
+ switch(tree1->t.op) {
case PLUS:
case ASPLUS:
case INCBEF:
break;
case ASSIGN:
- p = tree->t.tr2;
+ p = tree1->t.tr2;
goto lcasev;
case ASDIV:
case ASMOD:
case ASULSH:
- p = tree->t.tr1;
+ p = tree1->t.tr1;
lcasev:
if (p->t.type!=LONG && p->t.type!=UNLONG) {
- if (uns(p) || uns(tree->t.tr2))
+ if (uns(p) || uns(tree1->t.tr2))
printf("clr");
else
printf("sxt");
* Mask used in field assignments
*/
case 'Z':
- printf("$%o", UNS(tree->F.mask));
+ printf("$%o", UNS(tree1->F.mask));
goto loop;
/*
/*
* This routine just calls sreorder (below)
- * on the subtrees and then on the tree itself.
+ * on the subtrees and then on the tree1 itself.
* It returns non-zero if anything changed.
*/
-int reorder(treep, table, reg) union tree **treep; struct table *table; int reg; {
+int reorder(treep, table, reg) union tree1 **treep; struct table *table; int reg; {
register int r, o;
- register union tree *p;
+ register union tree1 *p;
p = *treep;
o = p->t.op;
- if (opdope[o]&LEAF||o==LOGOR||o==LOGAND||o==SEQNC||o==QUEST||o==COLON)
+ if (opdope1[o]&LEAF||o==LOGOR||o==LOGAND||o==SEQNC||o==QUEST||o==COLON)
return(0);
while(sreorder(&p->t.tr1, regtab, reg, 1))
;
- if (opdope[o]&BINARY)
+ if (opdope1[o]&BINARY)
while(sreorder(&p->t.tr2, regtab, reg, 1))
;
r = 0;
* Basically this routine carries out two kinds of optimization.
* First, it observes that "x + (reg = y)" where actually
* the = is any assignment op is better done as "reg=y; x+reg".
- * In this case rcexpr is called to do the first part and the
- * tree is modified so the name of the register
+ * In this case rcexpr1 is called to do the first part and the
+ * tree1 is modified so the name of the register
* replaces the assignment.
* 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) union tree **treep; struct table *table; int reg; int recurf; {
- register union tree *p, *p1;
+int sreorder(treep, table, reg, recurf) union tree1 **treep; struct table *table; int reg; int recurf; {
+ register union tree1 *p, *p1;
p = *treep;
- if (opdope[p->t.op]&LEAF)
+ if (opdope1[p->t.op]&LEAF)
return(0);
if (p->t.op==PLUS && recurf)
if (reorder(&p->t.tr2, table, reg))
*treep = p = optim(p);
- if ((p1 = p->t.tr1)==TNULL)
+ if ((p1 = p->t.tr1)==TNULL1)
return(0);
if (p->t.op==STAR || p->t.op==PLUS) {
if (recurf && reorder(&p->t.tr1, table, reg)) {
*treep = p = optim(p);
- if (opdope[p->t.op]&LEAF)
+ if (opdope1[p->t.op]&LEAF)
return(0);
}
p1 = p->t.tr1;
if (p1->t.tr1->t.op!=NAME
|| p1->t.tr1->n.class!=REG
|| p1->t.tr1->n.nloc!=p->t.tr1->n.nloc)
- rcexpr(p, efftab, reg);
+ rcexpr1(p, efftab, reg);
p->t.tr2 = p1->t.tr2;
p->t.op = p1->t.op + ASPLUS - PLUS;
*treep = p;
OK:
if (table==cctab||table==cregtab)
reg += 020;
- rcexpr(optim(p), efftab, ~reg);
+ rcexpr1(optim(p), efftab, ~reg);
*treep = p1;
return(1);
}
* It observes that "x + y++" is better
* treated as "x + y; y++".
* If the operator is ++ or -- itself,
- * it calls rcexpr to load the operand, letting
- * the calling instance of rcexpr to do the
+ * it calls rcexpr1 to load the operand, letting
+ * the calling instance of rcexpr1 to do the
* ++ using efftab.
* Otherwise it uses sdelay to search for inc/dec
* among the operands.
*/
-int delay(treep, table, reg) union tree **treep; struct table *table; int reg; {
- register union tree *p, *p1;
+int delay(treep, table, reg) union tree1 **treep; struct table *table; int reg; {
+ register union tree1 *p, *p1;
register int r;
p = *treep;
r = p->t.tr1->n.class;
if (r == EXTERN || r == OFFS || r == STATIC &&
p->t.tr1->t.type == UNCHAR)
- return(1+rcexpr(p->t.tr1, table, reg));
+ return(1+rcexpr1(p->t.tr1, table, reg));
else
- return(1+rcexpr(paint(p->t.tr1, p->t.type), table,reg));
+ return(1+rcexpr1(paint(p->t.tr1, p->t.type), table,reg));
}
p1 = 0;
/*
* typo fix, original code.
- * if (opdope[p->t.op]&BINARY) {
+ * if (opdope1[p->t.op]&BINARY) {
* if (p->t.op==LOGAND || p->t.op==LOGOR
* || p->t.op==QUEST || p->t.op==COLON || p->t.op==SEQNC)
* return(0);
* if (p1==0)
* p1 = sdelay(&p->t.tr1);
*/
- if (opdope[p->t.op]&BINARY) {
+ if (opdope1[p->t.op]&BINARY) {
if (p->t.op==LOGAND || p->t.op==LOGOR
|| p->t.op==QUEST || p->t.op==COLON || p->t.op==SEQNC)
return(0);
if (p1==0)
p1 = sdelay(&p->t.tr1);
if (p1) {
- r = rcexpr(optim(p), table, reg);
+ r = rcexpr1(optim(p), table, reg);
*treep = p1;
return(r+1);
}
return(0);
}
-union tree *sdelay(ap) union tree **ap; {
- register union tree *p, *p1;
+union tree1 *sdelay(ap) union tree1 **ap; {
+ register union tree1 *p, *p1;
- if ((p = *ap)==TNULL)
- return(TNULL);
+ if ((p = *ap)==TNULL1)
+ return(TNULL1);
if ((p->t.op==INCAFT||p->t.op==DECAFT) && p->t.tr1->t.op==NAME) {
*ap = paint(ncopy(p->t.tr1), p->t.type);
return(p);
/*
* Propagate possible implicit type-changing operation
*/
-union tree *paint(tp, type) register union tree *tp; register int type; {
+union tree1 *paint(tp, type) register union tree1 *tp; register int type; {
if (tp->t.type==type)
return(tp);
if (tp->t.type==CHAR && type==INT)
return(tp);
if (tp->t.type==CHAR || tp->t.type==UNCHAR)
- return(optim(tnode(LOAD, type, tp, TNULL)));
+ return(optim(tnode1(LOAD, type, tp, TNULL1)));
tp->t.type = type;
if (tp->t.op==AMPER && type&XTYPE)
- tp->t.tr1 = paint(tp->t.tr1, decref(type));
+ tp->t.tr1 = paint(tp->t.tr1, decref1(type));
else if (tp->t.op==STAR)
- tp->t.tr1 = paint(tp->t.tr1, incref(type));
+ tp->t.tr1 = paint(tp->t.tr1, incref1(type));
else if (tp->t.op==ASSIGN) {
paint(tp->t.tr1, type);
paint(tp->t.tr2, type);
}
/*
- * Copy a tree node for a register variable.
+ * Copy a tree1 node for a register variable.
* Used by sdelay because if *reg-- is turned
* into *reg; reg-- the *reg will in turn
* be changed to some offset class, accidentally
* modifying the reg--.
*/
-union tree *ncopy(p) register union tree *p; {
- register union tree *q;
+union tree1 *ncopy(p) register union tree1 *p; {
+ register union tree1 *q;
q = getblk(sizeof(struct xtname));
q->n.op = p->n.op;
}
/*
- * If the tree can be immediately loaded into a register,
+ * If the tree1 can be immediately loaded into a register,
* produce code to do so and return success.
*/
-int chkleaf(tree, table, reg) register union tree *tree; struct table *table; int reg; {
- struct tnode lbuf;
+int chkleaf(tree1, table, reg) register union tree1 *tree1; struct table *table; int reg; {
+ struct tnode1 lbuf;
- /*fprintf(stderr, "chkleaf(0x%08x, 0x%08x, 0x%08x)\n", tree, table, reg);*/
- if (tree->t.op!=STAR && dcalc(tree, nreg-reg) > 12)
+ /*fprintf(stderr, "chkleaf(0x%08x, 0x%08x, 0x%08x)\n", tree1, table, reg);*/
+ if (tree1->t.op!=STAR && dcalc(tree1, nreg-reg) > 12)
return(-1);
lbuf.op = LOAD;
- lbuf.type = tree->t.type;
- lbuf.degree = tree->t.degree;
- lbuf.tr1 = tree;
+ lbuf.type = tree1->t.type;
+ lbuf.degree = tree1->t.degree;
+ lbuf.tr1 = tree1;
#if 1 /* can't have garbage in lbuf.tr2, cexpr() will deref it if non-NULL */
lbuf.tr2 = NULL;
#endif
- return(rcexpr((union tree *)&lbuf, table, reg));
+ return(rcexpr1((union tree1 *)&lbuf, table, reg));
}
/*
* Return the number of bytes pushed,
* for future popping.
*/
-int comarg(tree, flagp) register union tree *tree; int *flagp; {
+int comarg(tree1, flagp) register union tree1 *tree1; int *flagp; {
register int retval;
int i;
int size;
- if (tree->t.op==STRASG) {
- size = tree->F.mask;
- tree = tree->t.tr1;
- tree = strfunc(tree);
+ if (tree1->t.op==STRASG) {
+ size = tree1->F.mask;
+ tree1 = tree1->t.tr1;
+ tree1 = strfunc(tree1);
if (size <= sizeof(_INT)) {
- paint(tree, INT);
+ paint(tree1, INT);
goto normal;
}
if (size <= sizeof(_LONG)) {
- paint(tree, LONG);
+ paint(tree1, LONG);
goto normal;
}
- if (tree->t.op!=NAME && tree->t.op!=STAR) {
- error("Unimplemented structure assignment");
+ if (tree1->t.op!=NAME && tree1->t.op!=STAR) {
+ error1("Unimplemented structure assignment");
return(0);
}
- tree = tnode(AMPER, STRUCT+PTR, tree, TNULL);
- tree = tnode(PLUS, STRUCT+PTR, tree, tconst(size, INT));
- tree = optim(tree);
- retval = rcexpr(tree, regtab, 0);
+ tree1 = tnode1(AMPER, STRUCT+PTR, tree1, TNULL1);
+ tree1 = tnode1(PLUS, STRUCT+PTR, tree1, tconst(size, INT));
+ tree1 = optim(tree1);
+ retval = rcexpr1(tree1, regtab, 0);
size >>= 1;
if (size <= 5) {
for (i=0; i<size; i++)
if (retval!=0)
printf("mov r%d,r0\n", retval);
printf("mov $%o,r1\n", UNS(size));
- printf("L%d:mov -(r0),-(sp)\ndec\tr1\njne\tL%d\n", isn, isn);
- isn++;
+ printf("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) {
- rcexpr(tree, sptab, 0);
- retval = arlength(tree->t.type);
+ if (nstack || isfloat(tree1) || tree1->t.type==LONG || tree1->t.type==UNLONG) {
+ rcexpr1(tree1, sptab, 0);
+ retval = arlength(tree1->t.type);
} else {
(*flagp)++;
- rcexpr(tree, lsptab, 0);
+ rcexpr1(tree1, lsptab, 0);
retval = 0;
}
return(retval);
}
-union tree *strfunc(tp) register union tree *tp; {
+union tree1 *strfunc(tp) register union tree1 *tp; {
if (tp->t.op != CALL)
return(tp);
paint(tp, STRUCT+PTR);
- return(tnode(STAR, STRUCT, tp, TNULL));
+ return(tnode1(STAR, STRUCT, tp, TNULL1));
}
/*
* Compile an initializing expression
*/
-void doinit(type, tree) register int type; register union tree *tree; {
+void doinit(type, tree1) register int type; register union tree1 *tree1; {
_FLOAT sfval;
_DOUBLE fval;
_LONG lval;
if (type==CHAR || type==UNCHAR) {
printf(".byte ");
- if (tree->t.type&XTYPE)
+ if (tree1->t.type&XTYPE)
goto illinit;
type = INT;
}
switch (type) {
case INT:
case UNSIGN:
- if (tree->t.op==FTOI) {
- if (tree->t.tr1->t.op!=FCON && tree->t.tr1->t.op!=SFCON)
+ if (tree1->t.op==FTOI) {
+ if (tree1->t.tr1->t.op!=FCON && tree1->t.tr1->t.op!=SFCON)
goto illinit;
- tree = tree->t.tr1;
+ tree1 = tree1->t.tr1;
#ifdef pdp11
- tree->c.value = tree->f.fvalue;
+ tree1->c.value = tree1->f.fvalue;
#else
- tree->c.value = fp_double_to_int(tree->f.fvalue);
+ tree1->c.value = fp_double_to_int(tree1->f.fvalue);
#endif
- tree->t.op = CON;
- } else if (tree->t.op==LTOI) {
- if (tree->t.tr1->t.op!=LCON)
+ tree1->t.op = CON;
+ } else if (tree1->t.op==LTOI) {
+ if (tree1->t.tr1->t.op!=LCON)
goto illinit;
- tree = tree->t.tr1;
- lval = tree->l.lvalue;
- tree->t.op = CON;
- tree->c.value = lval;
+ tree1 = tree1->t.tr1;
+ lval = tree1->l.lvalue;
+ tree1->t.op = CON;
+ tree1->c.value = lval;
}
- if (tree->t.op == CON)
- printf("%o\n", UNS(tree->c.value));
- else if (tree->t.op==AMPER) {
- pname(tree->t.tr1, 0);
+ if (tree1->t.op == CON)
+ printf("%o\n", UNS(tree1->c.value));
+ else if (tree1->t.op==AMPER) {
+ pname(tree1->t.tr1, 0);
putchar('\n');
} else
goto illinit;
case DOUBLE:
case FLOAT:
- if (tree->t.op==ITOF) {
- if (tree->t.tr1->t.op==CON) {
+ if (tree1->t.op==ITOF) {
+ if (tree1->t.tr1->t.op==CON) {
/* note: this should be changed to respect the signedness of the int */
#ifdef pdp11
- fval = tree->t.tr1->c.value;
+ fval = tree1->t.tr1->c.value;
#else
- fval = fp_int_to_double(tree->t.tr1->c.value);
+ fval = fp_int_to_double(tree1->t.tr1->c.value);
#endif
} else
goto illinit;
- } else if (tree->t.op==FCON || tree->t.op==SFCON) {
- fval = tree->f.fvalue;
- } else if (tree->t.op==LTOF) {
- if (tree->t.tr1->t.op!=LCON)
+ } else if (tree1->t.op==FCON || tree1->t.op==SFCON) {
+ fval = tree1->f.fvalue;
+ } else if (tree1->t.op==LTOF) {
+ if (tree1->t.tr1->t.op!=LCON)
goto illinit;
/* note: this should be changed to respect the signedness of the long */
#ifdef pdp11
- fval = tree->t.tr1->l.lvalue;
+ fval = tree1->t.tr1->l.lvalue;
#else
- fval = fp_long_to_double(tree->t.tr1->l.lvalue);
+ fval = fp_long_to_double(tree1->t.tr1->l.lvalue);
#endif
} else
goto illinit;
case UNLONG:
case LONG:
- if (tree->t.op==FTOL) {
- tree = tree->t.tr1;
- if (tree->t.op==SFCON)
- tree->t.op = FCON;
- if (tree->t.op!= FCON)
+ if (tree1->t.op==FTOL) {
+ tree1 = tree1->t.tr1;
+ if (tree1->t.op==SFCON)
+ tree1->t.op = FCON;
+ if (tree1->t.op!= FCON)
goto illinit;
#ifdef pdp11
- lval = tree->f.fvalue;
+ lval = tree1->f.fvalue;
#else
- lval = fp_double_to_long(tree->f.fvalue);
+ lval = fp_double_to_long(tree1->f.fvalue);
#endif
- } else if (tree->t.op==ITOL) {
- if (tree->t.tr1->t.op != CON)
+ } else if (tree1->t.op==ITOL) {
+ if (tree1->t.tr1->t.op != CON)
goto illinit;
- if (uns(tree->t.tr1))
- lval = (_UNSIGNED_INT)tree->t.tr1->c.value;
+ if (uns(tree1->t.tr1))
+ lval = (_UNSIGNED_INT)tree1->t.tr1->c.value;
else
- lval = tree->t.tr1->c.value;
- } else if (tree->t.op==LCON) {
- lval = tree->l.lvalue;
+ lval = tree1->t.tr1->c.value;
+ } else if (tree1->t.op==LCON) {
+ lval = tree1->l.lvalue;
} else
goto illinit;
/* nonportable */
return;
}
illinit:
- error("Illegal initialization");
+ error1("Illegal initialization");
}
-void movreg(r0, r1, tree) int r0; int r1; union tree *tree; {
+void movreg(r0, r1, tree1) int r0; int r1; union tree1 *tree1; {
register char *s;
char c;
if (r0==r1)
return;
- if (tree->t.type==LONG || tree->t.type == UNLONG) {
+ if (tree1->t.type==LONG || tree1->t.type == UNLONG) {
if (r0>=nreg || r1>=nreg) {
- error("register overflow: compiler error");
+ error1("register overflow: compiler error1");
}
s = "mov r%d,r%d\nmov r%d,r%d\n";
if (r0 < r1)
printf(s, r0,r1,r0+1,r1+1);
return;
}
- c = isfloat(tree);
+ c = isfloat(tree1);
printf("mov%.1s r%d,r%d\n", &c, r0, r1);
}
static void outname __P((char *s));
-int degree(t) register union tree *t; {
- register union tree *t1;
+int degree(t) register union tree1 *t; {
+ register union tree1 *t1;
if (t==NULL || t->t.op==0)
return(0);
if (t->t.op==ITOL) {
if ((t1 = isconstant(t)) && (t1->c.value>=0 || uns(t1)))
return(-2);
- if (uns(t1 = t->t.tr1) && opdope[t1->t.op]&LEAF)
+ if (uns(t1 = t->t.tr1) && opdope1[t1->t.op]&LEAF)
return(-1);
}
- if ((opdope[t->t.op] & LEAF) != 0) {
+ if ((opdope1[t->t.op] & LEAF) != 0) {
if (t->t.type==CHAR || t->t.type==UNCHAR || t->t.type==FLOAT)
return(1);
return(0);
return(t->t.degree);
}
-void pname(p, flag) register union tree *p; int flag; {
+void pname(p, flag) register union tree1 *p; int flag; {
register int i;
loop:
if (p->n.class!=OFFS)
putchar('+');
if (p->n.class==REG)
- error("Illegal use of register");
+ error1("Illegal use of register");
}
switch(p->n.class) {
return;
}
- error("Compiler error: pname");
+ error1("Compiler error1: pname");
return;
case AMPER:
putchar('$');
p = p->t.tr1;
if (p->t.op==NAME && p->n.class==REG)
- error("Illegal use of register");
+ error1("Illegal use of register");
goto loop;
case AUTOI:
goto loop;
}
- error("compiler error: bad pname");
+ error1("compiler error1: bad pname");
}
-void pbase(p) register union tree *p; {
+void pbase(p) register union tree1 *p; {
if (p->n.class==SOFFS || p->n.class==STATIC)
printf("L%d", p->n.nloc);
printf("%s", p->x.name);
}
-int xdcalc(p, nrleft) register union tree *p; int nrleft; {
+int xdcalc(p, nrleft) register union tree1 *p; int nrleft; {
register int d;
if (p==NULL)
return(d);
}
-int dcalc(p, nrleft) register union tree *p; int nrleft; {
- register union tree *p1;
+int dcalc(p, nrleft) register union tree1 *p; int nrleft; {
+ register union tree1 *p1;
if (p==NULL)
return(0);
return(p->t.degree <= nrleft? 20: 24);
}
-int notcompat(p, ast, deg, op) register union tree *p; int ast; int deg; int op; {
+int notcompat(p, ast, deg, op) register union tree1 *p; int ast; int deg; int op; {
unsigned register at, st;
at = p->t.type;
printf(ip, lbl);
}
else {
- skip = isn++;
+ skip = isn1++;
printf(ip, skip);
}
return(skip);
}
}
- error("No match' for op %d", op);
+ error1("No match' for op %d", op);
return(skip);
}
-int collcon(p) register union tree *p; {
+int collcon(p) register union tree1 *p; {
register int op;
if (p==NULL)
return(0);
}
-int isfloat(t) register union tree *t; {
+int isfloat(t) register union tree1 *t; {
- if ((opdope[t->t.op]&RELAT)!=0)
+ if ((opdope1[t->t.op]&RELAT)!=0)
t = t->t.tr1;
if (t->t.type==FLOAT || t->t.type==DOUBLE) {
nfloat = 1;
return(0);
}
-int oddreg(t, reg) register union tree *t; register int reg; {
+int oddreg(t, reg) register union tree1 *t; register int reg; {
if (!isfloat(t)) {
- if (opdope[t->t.op]&RELAT) {
+ if (opdope1[t->t.op]&RELAT) {
if (t->t.tr1->t.type==LONG || t->t.tr1->t.type==UNLONG)
return((reg+1) & ~01);
return(reg);
case DOUBLE:
return(8);
}
- error("botch: peculiar type %d", t);
+ error1("botch: peculiar type %d", t);
return(1024);
}
* try using the calls to lrem and ldiv.
*/
-void pswitch(afp, alp, deflab) struct swtab *afp; struct swtab *alp; int deflab; {
+void pswitch1(afp, alp, deflab) struct swtab *afp; struct swtab *alp; int deflab; {
int ncase, i, j, tabs, worst, best, range;
register struct swtab *swp, *fp, *lp;
int *poctab;
printf("jbr L%d\n", deflab);
return;
}
- isn++;
+ isn1++;
if (sort(fp, lp))
return;
ncase = lp-fp;
if (range>0 && range <= 3*ncase) {
if (fp->swval)
printf("sub $%o,r0\n", UNS(fp->swval));
- printf(dirsw, UNS(range), deflab, isn, isn);
- isn++;
+ printf(dirsw, UNS(range), deflab, isn1, isn1);
+ isn1++;
for (i=fp->swval; ; i++) {
if (i==fp->swval) {
printf("L%d\n", fp->swlab);
best = i*worst;
}
}
- i = isn++;
+ i = isn1++;
printf(hashsw, UNS(tabs), i, i);
- isn++;
+ isn1++;
for (i=0; i<tabs; i++)
- printf("L%d\n", isn+i);
+ printf("L%d\n", isn1+i);
printf(".text\n");
for (i=0; i<tabs; i++) {
- printf("L%d:", isn++);
+ printf("L%d:", isn1++);
for (swp=fp; swp<=lp; swp++) {
/* lrem(0, swp->swval, tabs) */
if ((_UNSIGNED_INT)swp->swval%tabs == i) {
}
int sort(afp, alp) struct swtab *afp; struct swtab *alp; {
- register struct swtab *cp, *fp, *lp;
+ register struct swtab *cp1, *fp, *lp;
int intch, t;
fp = afp;
lp = alp;
while (fp < --lp) {
intch = 0;
- for (cp=fp; cp<lp; cp++) {
- if (cp->swval == cp[1].swval) {
- error("Duplicate case (%d)", cp->swval);
+ for (cp1=fp; cp1<lp; cp1++) {
+ if (cp1->swval == cp1[1].swval) {
+ error1("Duplicate case (%d)", cp1->swval);
return(1);
}
- if (cp->swval > cp[1].swval) {
+ if (cp1->swval > cp1[1].swval) {
intch++;
- t = cp->swval;
- cp->swval = cp[1].swval;
- cp[1].swval = t;
- t = cp->swlab;
- cp->swlab = cp[1].swlab;
- cp[1].swlab = t;
+ t = cp1->swval;
+ cp1->swval = cp1[1].swval;
+ cp1[1].swval = t;
+ t = cp1->swlab;
+ cp1->swlab = cp1[1].swlab;
+ cp1[1].swlab = t;
}
}
if (intch==0)
return(0);
}
-int ispow2(tree) register union tree *tree; {
+int ispow2(tree1) register union tree1 *tree1; {
register int d;
- if (!isfloat(tree) && tree->t.tr2->t.op==CON) {
- d = tree->t.tr2->c.value;
+ if (!isfloat(tree1) && tree1->t.tr2->t.op==CON) {
+ d = tree1->t.tr2->c.value;
if (d>1 && (d&(d-1))==0)
return(d);
}
return(0);
}
-union tree *pow2(tree) register union tree *tree; {
+union tree1 *pow2(tree1) register union tree1 *tree1; {
register int d, i;
- if (d = ispow2(tree)) {
+ if (d = ispow2(tree1)) {
for (i=0; (d>>=1)!=0; i++);
- tree->t.tr2->c.value = i;
- switch (tree->t.op) {
+ tree1->t.tr2->c.value = i;
+ switch (tree1->t.op) {
case TIMES:
- tree->t.op = LSHIFT;
+ tree1->t.op = LSHIFT;
break;
case ASTIMES:
- tree->t.op = ASLSH;
+ tree1->t.op = ASLSH;
break;
case PTOI:
- if (i==1 && tree->t.tr1->t.op==MINUS && !isconstant(tree->t.tr1->t.tr2)) {
- tree->t.op = PTOI1;
- tree->t.tr1 = tnode(LTOI, INT, tree->t.tr1, TNULL);
- return(optim(tree));
+ if (i==1 && tree1->t.tr1->t.op==MINUS && !isconstant(tree1->t.tr1->t.tr2)) {
+ tree1->t.op = PTOI1;
+ tree1->t.tr1 = tnode1(LTOI, INT, tree1->t.tr1, TNULL1);
+ return(optim(tree1));
}
- tree->t.op = LLSHIFT;
- tree->t.tr2->c.value = -i;
- i = tree->t.type;
- tree->t.type = LONG;
- tree = tnode(LTOI, i, tree, TNULL);
+ tree1->t.op = LLSHIFT;
+ tree1->t.tr2->c.value = -i;
+ i = tree1->t.type;
+ tree1->t.type = LONG;
+ tree1 = tnode1(LTOI, i, tree1, TNULL1);
break;
case DIVIDE:
- tree->t.op = ULSH;
- tree->t.tr2->c.value = -i;
+ tree1->t.op = ULSH;
+ tree1->t.tr2->c.value = -i;
break;
case ASDIV:
- tree->t.op = ASULSH;
- tree->t.tr2->c.value = -i;
+ tree1->t.op = ASULSH;
+ tree1->t.tr2->c.value = -i;
break;
case MOD:
- tree->t.op = AND;
- tree->t.tr2->c.value = (1<<i)-1;
+ tree1->t.op = AND;
+ tree1->t.tr2->c.value = (1<<i)-1;
break;
case ASMOD:
- tree->t.op = ASAND;
- tree->t.tr2->c.value = (1<<i)-1;
+ tree1->t.op = ASAND;
+ tree1->t.tr2->c.value = (1<<i)-1;
break;
default:
- error("pow2 botch");
+ error1("pow2 botch");
}
- tree = optim(tree);
+ tree1 = optim(tree1);
}
- return(tree);
+ return(tree1);
}
-void cbranch(atree, lbl, cond, reg) union tree *atree; register int lbl; int cond; register int reg; {
+void cbranch1(atree, lbl, cond, reg) union tree1 *atree; register int lbl; int cond; register int reg; {
int l1, op;
- register union tree *tree;
+ register union tree1 *tree1;
again:
- if ((tree=atree)==NULL)
+ if ((tree1=atree)==NULL)
return;
- switch(tree->t.op) {
+ switch(tree1->t.op) {
case LOGAND:
if (cond) {
- cbranch(tree->t.tr1, l1=isn++, 0, reg);
- cbranch(tree->t.tr2, lbl, 1, reg);
- label(l1);
+ cbranch1(tree1->t.tr1, l1=isn1++, 0, reg);
+ cbranch1(tree1->t.tr2, lbl, 1, reg);
+ label1(l1);
} else {
- cbranch(tree->t.tr1, lbl, 0, reg);
- cbranch(tree->t.tr2, lbl, 0, reg);
+ cbranch1(tree1->t.tr1, lbl, 0, reg);
+ cbranch1(tree1->t.tr2, lbl, 0, reg);
}
return;
case LOGOR:
if (cond) {
- cbranch(tree->t.tr1, lbl, 1, reg);
- cbranch(tree->t.tr2, lbl, 1, reg);
+ cbranch1(tree1->t.tr1, lbl, 1, reg);
+ cbranch1(tree1->t.tr2, lbl, 1, reg);
} else {
- cbranch(tree->t.tr1, l1=isn++, 1, reg);
- cbranch(tree->t.tr2, lbl, 0, reg);
- label(l1);
+ cbranch1(tree1->t.tr1, l1=isn1++, 1, reg);
+ cbranch1(tree1->t.tr2, lbl, 0, reg);
+ label1(l1);
}
return;
case EXCLA:
- cbranch(tree->t.tr1, lbl, !cond, reg);
+ cbranch1(tree1->t.tr1, lbl, !cond, reg);
return;
case SEQNC:
- rcexpr(tree->t.tr1, efftab, reg);
- atree = tree->t.tr2;
+ rcexpr1(tree1->t.tr1, efftab, reg);
+ atree = tree1->t.tr2;
goto again;
case ITOL:
- tree = tree->t.tr1;
+ tree1 = tree1->t.tr1;
break;
case QUEST:
- l1 = isn;
- isn += 2;
- cbranch(tree->t.tr1, l1, 0, reg);
- cbranch(tree->t.tr2->t.tr1, lbl, cond, reg);
- branch(l1+1, 0, 0);
- label(l1);
- cbranch(tree->t.tr2->t.tr2, lbl, cond, reg);
- label(l1+1);
+ l1 = isn1;
+ isn1 += 2;
+ cbranch1(tree1->t.tr1, l1, 0, reg);
+ cbranch1(tree1->t.tr2->t.tr1, lbl, cond, reg);
+ branch1(l1+1, 0, 0);
+ label1(l1);
+ cbranch1(tree1->t.tr2->t.tr2, lbl, cond, reg);
+ label1(l1+1);
return;
}
- op = tree->t.op;
- if (opdope[op]&RELAT
- && tree->t.tr1->t.op==ITOL && tree->t.tr2->t.op==ITOL
- && uns(tree->t.tr1->t.tr1) == uns(tree->t.tr2->t.tr1)) {
- tree->t.tr1 = tree->t.tr1->t.tr1;
- tree->t.tr2 = tree->t.tr2->t.tr1;
+ op = tree1->t.op;
+ if (opdope1[op]&RELAT
+ && tree1->t.tr1->t.op==ITOL && tree1->t.tr2->t.op==ITOL
+ && uns(tree1->t.tr1->t.tr1) == uns(tree1->t.tr2->t.tr1)) {
+ tree1->t.tr1 = tree1->t.tr1->t.tr1;
+ tree1->t.tr2 = tree1->t.tr2->t.tr1;
if (op>=LESSEQ && op<=GREAT
- && uns(tree->t.tr1))
- tree->t.op = op = op+LESSEQP-LESSEQ;
+ && uns(tree1->t.tr1))
+ tree1->t.op = op = op+LESSEQP-LESSEQ;
}
- if (tree->t.type==LONG || tree->t.type==UNLONG
- || opdope[op]&RELAT&&(tree->t.tr1->t.type==LONG || tree->t.tr1->t.type==UNLONG)) {
- longrel(tree, lbl, cond, reg);
+ if (tree1->t.type==LONG || tree1->t.type==UNLONG
+ || opdope1[op]&RELAT&&(tree1->t.tr1->t.type==LONG || tree1->t.tr1->t.type==UNLONG)) {
+ longrel(tree1, lbl, cond, reg);
return;
}
- rcexpr(tree, cctab, reg);
- op = tree->t.op;
- if ((opdope[op]&RELAT)==0)
+ rcexpr1(tree1, cctab, reg);
+ op = tree1->t.op;
+ if ((opdope1[op]&RELAT)==0)
op = NEQUAL;
else {
- l1 = tree->t.tr2->t.op;
- if ((l1==CON || l1==SFCON) && tree->t.tr2->c.value==0)
+ l1 = tree1->t.tr2->t.op;
+ if ((l1==CON || l1==SFCON) && tree1->t.tr2->c.value==0)
op += 200; /* special for ptr tests */
else
op = maprel[op-EQUAL];
}
- if (isfloat(tree))
+ if (isfloat(tree1))
printf("cfcc\n");
- branch(lbl, op, !cond);
+ branch1(lbl, op, !cond);
}
-void branch(lbl, aop, c) int lbl; int aop; int c; {
+void branch1(lbl, aop, c) int lbl; int aop; int c; {
register int op,
skip;
printf("\tL%d\n", lbl);
}
-void longrel(atree, lbl, cond, reg) union tree *atree; int lbl; int cond; int reg; {
+void longrel(atree, lbl, cond, reg) union tree1 *atree; int lbl; int cond; int reg; {
int xl1, xl2, xo, xz;
register int op, isrel;
- register union tree *tree;
+ register union tree1 *tree1;
if (reg&01)
reg++;
reorder(&atree, cctab, reg);
- tree = atree;
+ tree1 = atree;
isrel = 0;
- if (opdope[tree->t.op]&RELAT) {
+ if (opdope1[tree1->t.op]&RELAT) {
isrel++;
- op = tree->t.op;
+ op = tree1->t.op;
} else
op = NEQUAL;
if (!cond)
xlab2 = 0;
xop = op;
xz = xzero;
- xzero = !isrel || (tree->t.tr2->t.op==ITOL && tree->t.tr2->t.tr1->t.op==CON
- && tree->t.tr2->t.tr1->c.value==0);
- if (tree->t.op==ANDN) {
- tree->t.op = TAND;
- tree->t.tr2 = optim(tnode(COMPL, LONG, tree->t.tr2, TNULL));
+ xzero = !isrel || (tree1->t.tr2->t.op==ITOL && tree1->t.tr2->t.tr1->t.op==CON
+ && tree1->t.tr2->t.tr1->c.value==0);
+ if (tree1->t.op==ANDN) {
+ tree1->t.op = TAND;
+ tree1->t.tr2 = optim(tnode1(COMPL, LONG, tree1->t.tr2, TNULL1));
}
- if (cexpr(tree, cctab, reg) < 0) {
- reg = rcexpr(tree, regtab, reg);
+ if (cexpr(tree1, cctab, reg) < 0) {
+ reg = rcexpr1(tree1, regtab, reg);
printf("ashc $0,r%d\n", reg);
- branch(xlab1, op, 0);
+ branch1(xlab1, op, 0);
}
xlab1 = xl1;
xlab2 = xl2;
op = xop;
if (f==0) {
if (bno = lrtab[xzero][0][op-EQUAL])
- branch(xlab1, bno, 0);
+ branch1(xlab1, bno, 0);
if (bno = lrtab[xzero][1][op-EQUAL]) {
- xlab2 = isn++;
- branch(xlab2, bno, 0);
+ xlab2 = isn1++;
+ branch1(xlab2, bno, 0);
}
if (lrtab[xzero][2][op-EQUAL]==0)
return(1);
} else {
- branch(xlab1, lrtab[xzero][2][op-EQUAL], 0);
+ branch1(xlab1, lrtab[xzero][2][op-EQUAL], 0);
if (xlab2)
- label(xlab2);
+ label1(xlab2);
}
return(0);
}
-void label(l) int l; {
+void label1(l) int l; {
printf("L%d:", l);
}
printf("add $%o,sp\n", UNS(a));
}
-void werror(s) char *s; {
+void werror1(s) char *s; {
fprintf(stderr, "%d: %s\n",line,s);
}
#ifdef __STDC__
-void error(char *s, ...)
+void error1(char *s, ...)
#else
-void error(s, va_alist) char *s; va_dcl
+void error1(s, va_alist) char *s; va_dcl
#endif
{
va_list ap;
*/
#define STKS 100
void getree() {
- union tree *expstack[STKS], **sp;
- register union tree *tp;
+ union tree1 *expstack[STKS], **sp;
+ register union tree1 *tp;
register int t, op;
char s[80]; /* big for asm() stuff & long variable names */
struct swtab *swp;
sp = expstack;
for (;;) {
if (sp >= &expstack[STKS])
- error("Stack overflow botch");
+ error1("Stack overflow botch");
op = geti();
if ((op&0177400) != 0177000) {
- error("Intermediate file error");
+ error1("Intermediate file error1");
exit(1);
}
lbl = 0;
curbase = funcbase;
while(swp=(struct swtab *)getblk(sizeof(*swp)), swp->swlab = geti())
swp->swval = geti();
- pswitch((struct swtab *)funcbase, swp, t);
+ pswitch1((struct swtab *)funcbase, swp, t);
break;
case C3BRANCH: /* for fortran [sic] */
xpr:
line = geti();
if (sp != &expstack[1]) {
- error("Expression input botch");
+ error1("Expression input botch");
exit(1);
}
--sp;
if (regpanic==0 && panicposs)
outloc = ftell(stdout);
if (op==CBRANCH)
- cbranch(tp, lbl, cond, 0);
+ cbranch1(tp, lbl, cond, 0);
else if (op==EXPR)
- rcexpr(tp, efftab, 0);
+ rcexpr1(tp, efftab, 0);
else {
if (tp->t.type==LONG || tp->t.type==UNLONG) {
- rcexpr(tnode(RFORCE, tp->t.type, tp, TNULL), efftab, 0);
+ rcexpr1(tnode1(RFORCE, tp->t.type, tp, TNULL1), efftab, 0);
printf("ashc $0,r0\n");
} else {
- rcexpr(tp, cctab, 0);
+ rcexpr1(tp, cctab, 0);
if (isfloat(tp))
printf("cfcc\n");
}
t = geti();
op = geti();
if (t==0 && op>=0 || t == -1 && op<0) {
- *sp++ = tnode(ITOL, LONG, tconst(op, INT), TNULL);
+ *sp++ = tnode1(ITOL, LONG, tconst(op, INT), TNULL1);
break;
}
tp = getblk(sizeof(struct lconst));
tp = getblk(sizeof(struct ftconst));
tp->t.op = FCON;
tp->t.type = t;
- tp->f.value = isn++;
+ tp->f.value = isn1++;
#ifdef pdp11
tp->f.fvalue = atof(s);
#else
- fprintf(stderr, "%s\n", s);
tp->f.fvalue = fp_atof(s);
#endif
*sp++ = tp;
break;
case FSEL:
- tp = tnode(FSEL, geti(), *--sp, TNULL);
+ tp = tnode1(FSEL, geti(), *--sp, TNULL1);
t = geti();
- tp->t.tr2 = tnode(COMMA, INT, tconst(geti(), INT), tconst(t, INT));
+ tp->t.tr2 = tnode1(COMMA, INT, tconst(geti(), INT), tconst(t, INT));
if (tp->t.tr2->t.tr1->c.value==16)
tp = paint(tp->t.tr1, tp->t.type);
*sp++ = tp;
break;
case NULLOP:
- *sp++ = tnode(0, 0, TNULL, TNULL);
+ *sp++ = tnode1(0, 0, TNULL1, TNULL1);
break;
case LABEL:
- label(geti());
+ label1(geti());
break;
case NLABEL:
break;
case BRANCH:
- branch(geti(), 0, 0);
+ branch1(geti(), 0, 0);
break;
case SETREG:
break;
default:
- if (opdope[op]&BINARY) {
+ if (opdope1[op]&BINARY) {
if (sp < &expstack[1]) {
- error("Binary expression botch");
+ error1("Binary expression botch");
exit(1);
}
tp = *--sp;
#if 1
- sp[-1] = tnode(op, geti(), sp[-1], tp);
+ sp[-1] = tnode1(op, geti(), sp[-1], tp);
#else
- *sp++ = tnode(op, geti(), *--sp, tp);
+ *sp++ = tnode1(op, geti(), *--sp, tp);
#endif
} else
- sp[-1] = tnode(op, geti(), sp[-1], TNULL);
+ sp[-1] = tnode1(op, geti(), sp[-1], TNULL1);
break;
}
}
*s++ = '\0';
}
-void strasg(atp) union tree *atp; {
- register union tree *tp;
+void strasg(atp) union tree1 *atp; {
+ register union tree1 *tp;
register int nwords, i;
nwords = atp->F.mask/sizeof(_INT);
tp = atp->t.tr1;
while (tp->t.op == SEQNC) {
- rcexpr(tp->t.tr1, efftab, 0);
+ rcexpr1(tp->t.tr1, efftab, 0);
tp = tp->t.tr2;
}
if (tp->t.op != ASSIGN) {
if (tp->t.op==RFORCE) { /* function return */
if (sfuncr.nloc==0) {
- sfuncr.nloc = isn++;
+ sfuncr.nloc = isn1++;
printf(".bss\nL%d:.=.+%o\n.text\n", sfuncr.nloc,
UNS(nwords*sizeof(_INT)));
}
- atp->t.tr1 = tnode(ASSIGN, STRUCT, (union tree *)&sfuncr, tp->t.tr1);
+ atp->t.tr1 = tnode1(ASSIGN, STRUCT, (union tree1 *)&sfuncr, tp->t.tr1);
strasg(atp);
printf("mov $L%d,r0\n", sfuncr.nloc);
return;
}
if (tp->t.op==CALL) {
- rcexpr(tp, efftab, 0);
+ rcexpr1(tp, efftab, 0);
return;
}
- error("Illegal structure operation");
+ error1("Illegal structure operation");
return;
}
tp->t.tr2 = strfunc(tp->t.tr2);
else {
if (tp->t.tr1->t.op!=NAME && tp->t.tr1->t.op!=STAR
|| tp->t.tr2->t.op!=NAME && tp->t.tr2->t.op!=STAR) {
- error("unimplemented structure assignment");
+ error1("unimplemented structure assignment");
return;
}
- tp->t.tr1 = tnode(AMPER, STRUCT+PTR, tp->t.tr1, TNULL);
- tp->t.tr2 = tnode(AMPER, STRUCT+PTR, tp->t.tr2, TNULL);
+ tp->t.tr1 = tnode1(AMPER, STRUCT+PTR, tp->t.tr1, TNULL1);
+ tp->t.tr2 = tnode1(AMPER, STRUCT+PTR, tp->t.tr2, TNULL1);
tp->t.op = STRSET;
tp->t.type = STRUCT+PTR;
tp = optim(tp);
- rcexpr(tp, efftab, 0);
+ rcexpr1(tp, efftab, 0);
if (nwords < 7) {
for (i=0; i<nwords; i++)
printf("mov (r1)+,(r0)+\n");
if (nreg<=1)
printf("mov r2,-(sp)\n");
printf("mov $%o,r2\n", UNS(nwords));
- printf("L%d:mov (r1)+,(r0)+\ndec\tr2\njne\tL%d\n", isn, isn);
- isn++;
+ printf("L%d:mov (r1)+,(r0)+\ndec\tr2\njne\tL%d\n", isn1, isn1);
+ isn1++;
if (nreg<=1)
printf("mov (sp)+,r2\n");
return;
}
- rcexpr(tp, efftab, 0);
+ rcexpr1(tp, efftab, 0);
}
/*
* Reduce the degree-of-reference by one.
* e.g. turn "ptr-to-int" into "int".
*/
-int decref(t) register int t; {
+int decref1(t) register int t; {
if ((t & ~TYPE) == 0) {
- error("Illegal indirection");
+ error1("Illegal indirection");
return(t);
}
return(((_UNSIGNED_INT)t>>TYLEN) & ~TYPE | t&TYPE);
* Increase the degree of reference by
* one; e.g. turn "int" to "ptr-to-int".
*/
-int incref(t) register int t; {
+int incref1(t) register int t; {
return(((t&~TYPE)<<TYLEN) | (t&TYPE) | PTR);
}
*/
#include <stdlib.h>
+#include <unistd.h>
#include "c1.h"
-#include <sys/param.h> /* for MAX */
-union tree *optim(tree) register union tree *tree; {
+/*
+ * Macros for fast min/max.
+ */
+#define min(a,b) (((a)<(b))?(a):(b))
+#define max(a,b) (((a)>(b))?(a):(b))
+
+union tree1 *optim(tree1) register union tree1 *tree1; {
register int op, dope;
int d1, d2;
- union tree *t;
+ union tree1 *t;
#ifdef pdp11
union { double dv; _INT iv[4];} fp11;
#endif
- if (tree==NULL)
+ if (tree1==NULL)
return(NULL);
- if ((op = tree->t.op)==0)
- return(tree);
- if (op==NAME && tree->n.class==AUTO) {
- tree->n.class = OFFS;
- tree->n.regno = 5;
- tree->n.offset = tree->n.nloc;
+ if ((op = tree1->t.op)==0)
+ return(tree1);
+ if (op==NAME && tree1->n.class==AUTO) {
+ tree1->n.class = OFFS;
+ tree1->n.regno = 5;
+ tree1->n.offset = tree1->n.nloc;
}
- dope = opdope[op];
+ dope = opdope1[op];
if ((dope&LEAF) != 0) {
if (op==FCON) {
#ifdef pdp11
- fp11.dv = tree->f.fvalue;
+ fp11.dv = tree1->f.fvalue;
if (fp11.iv[1]==0
&& fp11.iv[2]==0
&& fp11.iv[3]==0) {
- tree->t.op = SFCON;
- tree->f.value = fp11.iv[0];
+ tree1->t.op = SFCON;
+ tree1->f.value = fp11.iv[0];
}
#else
- if (tree->f.fvalue.l==0
- && (tree->f.fvalue.h & 0xffff)==0) {
- tree->t.op = SFCON;
- tree->f.value = (int)(tree->f.fvalue.h >> 16) & 0xffff;
+ if (tree1->f.fvalue.l==0
+ && (tree1->f.fvalue.h & 0xffff)==0) {
+ tree1->t.op = SFCON;
+ tree1->f.value = (int)(tree1->f.fvalue.h >> 16) & 0xffff;
}
#endif
}
- return(tree);
+ return(tree1);
}
if ((dope&BINARY) == 0)
- return(unoptim(tree));
+ return(unoptim(tree1));
/* is known to be binary */
- if (tree->t.type==CHAR)
- tree->t.type = INT;
+ if (tree1->t.type==CHAR)
+ tree1->t.type = INT;
switch(op) {
/*
* PDP-11 special:
* by complementing the RHS.
*/
case ASAND:
- tree->t.op = ASANDN;
- tree->t.tr2 = tnode(COMPL, tree->t.tr2->t.type, tree->t.tr2, TNULL);
+ tree1->t.op = ASANDN;
+ tree1->t.tr2 = tnode1(COMPL, tree1->t.tr2->t.type, tree1->t.tr2, TNULL1);
break;
/*
* Longs are just truncated.
*/
case LTOP:
- tree->t.op = ITOP;
- tree->t.tr1 = unoptim(tnode(LTOI,INT,tree->t.tr1, TNULL));
+ tree1->t.op = ITOP;
+ tree1->t.tr1 = unoptim(tnode1(LTOI,INT,tree1->t.tr1, TNULL1));
case ITOP:
- tree->t.op = TIMES;
+ tree1->t.op = TIMES;
break;
case MINUS:
- if ((t = isconstant(tree->t.tr2)) && (!uns(t) || tree->t.type!=LONG)
+ if ((t = isconstant(tree1->t.tr2)) && (!uns(t) || tree1->t.type!=LONG)
&& (t->t.type!=INT || t->c.value!=(_INT)0100000)) {
- tree->t.op = PLUS;
+ tree1->t.op = PLUS;
if (t->t.type==DOUBLE) {
/* PDP-11 FP representation */
t->f/*c*/.value ^= 0100000;
}
break;
}
- op = tree->t.op;
- dope = opdope[op];
- if (dope&LVALUE && tree->t.tr1->t.op==FSEL)
- return(lvfield(tree));
+ op = tree1->t.op;
+ dope = opdope1[op];
+ if (dope&LVALUE && tree1->t.tr1->t.op==FSEL)
+ return(lvfield(tree1));
if ((dope&COMMUTE)!=0) {
- d1 = tree->t.type;
- tree = acommute(tree);
- if (tree->t.op == op)
- tree->t.type = d1;
+ d1 = tree1->t.type;
+ tree1 = acommute(tree1);
+ if (tree1->t.op == op)
+ tree1->t.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)
- return(tree);
+ if (tree1->t.op!=AND)
+ return(tree1);
/*
* long & pos-int is simpler
*/
- if ((tree->t.type==LONG || tree->t.type==UNLONG) && tree->t.tr2->t.op==ITOL
- && (tree->t.tr2->t.tr1->t.op==CON && tree->t.tr2->t.tr1->c.value>=0
- || uns(tree->t.tr2->t.tr1))) {
- tree->t.type = UNSIGN;
- t = tree->t.tr2;
- tree->t.tr2 = tree->t.tr2->t.tr1;
- t->t.tr1 = tree;
- tree->t.tr1 = tnode(LTOI, UNSIGN, tree->t.tr1, TNULL);
+ if ((tree1->t.type==LONG || tree1->t.type==UNLONG) && tree1->t.tr2->t.op==ITOL
+ && (tree1->t.tr2->t.tr1->t.op==CON && tree1->t.tr2->t.tr1->c.value>=0
+ || uns(tree1->t.tr2->t.tr1))) {
+ tree1->t.type = UNSIGN;
+ t = tree1->t.tr2;
+ tree1->t.tr2 = tree1->t.tr2->t.tr1;
+ t->t.tr1 = tree1;
+ tree1->t.tr1 = tnode1(LTOI, UNSIGN, tree1->t.tr1, TNULL1);
return(optim(t));
}
/*
* Keep constants to the right
*/
- if ((tree->t.tr1->t.op==ITOL && tree->t.tr1->t.tr1->t.op==CON)
- || tree->t.tr1->t.op==LCON) {
- t = tree->t.tr1;
- tree->t.tr1 = tree->t.tr2;
- tree->t.tr2 = t;
+ if ((tree1->t.tr1->t.op==ITOL && tree1->t.tr1->t.tr1->t.op==CON)
+ || tree1->t.tr1->t.op==LCON) {
+ t = tree1->t.tr1;
+ tree1->t.tr1 = tree1->t.tr2;
+ tree1->t.tr2 = t;
}
- tree->t.op = ANDN;
+ tree1->t.op = ANDN;
op = ANDN;
- tree->t.tr2 = tnode(COMPL, tree->t.tr2->t.type, tree->t.tr2, TNULL);
+ tree1->t.tr2 = tnode1(COMPL, tree1->t.tr2->t.type, tree1->t.tr2, TNULL1);
}
again:
- tree->t.tr1 = optim(tree->t.tr1);
- tree->t.tr2 = optim(tree->t.tr2);
- if (tree->t.type == LONG || tree->t.type==UNLONG) {
- t = lconst(tree->t.op, tree->t.tr1, tree->t.tr2);
+ tree1->t.tr1 = optim(tree1->t.tr1);
+ tree1->t.tr2 = optim(tree1->t.tr2);
+ if (tree1->t.type == LONG || tree1->t.type==UNLONG) {
+ t = lconst(tree1->t.op, tree1->t.tr1, tree1->t.tr2);
if (t)
return(t);
}
if ((dope&RELAT) != 0) {
- if ((d1=degree(tree->t.tr1)) < (d2=degree(tree->t.tr2))
- || d1==d2 && tree->t.tr1->t.op==NAME && tree->t.tr2->t.op!=NAME) {
- t = tree->t.tr1;
- tree->t.tr1 = tree->t.tr2;
- tree->t.tr2 = t;
- tree->t.op = maprel[op-EQUAL];
+ if ((d1=degree(tree1->t.tr1)) < (d2=degree(tree1->t.tr2))
+ || d1==d2 && tree1->t.tr1->t.op==NAME && tree1->t.tr2->t.op!=NAME) {
+ t = tree1->t.tr1;
+ tree1->t.tr1 = tree1->t.tr2;
+ tree1->t.tr2 = t;
+ tree1->t.op = maprel[op-EQUAL];
}
- if (tree->t.tr1->t.type==CHAR && tree->t.tr2->t.op==CON
- && (dcalc(tree->t.tr1, 0) <= 12 || tree->t.tr1->t.op==STAR)
- && tree->t.tr2->c.value <= 127 && tree->t.tr2->c.value >= 0)
- tree->t.tr2->t.type = CHAR;
+ if (tree1->t.tr1->t.type==CHAR && tree1->t.tr2->t.op==CON
+ && (dcalc(tree1->t.tr1, 0) <= 12 || tree1->t.tr1->t.op==STAR)
+ && tree1->t.tr2->c.value <= 127 && tree1->t.tr2->c.value >= 0)
+ tree1->t.tr2->t.type = CHAR;
}
- d1 = MAX(degree(tree->t.tr1), islong(tree->t.type));
- d2 = MAX(degree(tree->t.tr2), 0);
+ d1 = max(degree(tree1->t.tr1), islong(tree1->t.type));
+ d2 = max(degree(tree1->t.tr2), 0);
switch (op) {
/*
* In assignment to fields, treat all-zero and all-1 specially.
*/
case FSELA:
- if (tree->t.tr2->t.op==CON && tree->t.tr2->c.value==0) {
- tree->t.op = ASAND;
- tree->t.tr2->c.value = ~tree->F.mask;
- return(optim(tree));
+ if (tree1->t.tr2->t.op==CON && tree1->t.tr2->c.value==0) {
+ tree1->t.op = ASAND;
+ tree1->t.tr2->c.value = ~tree1->F.mask;
+ return(optim(tree1));
}
- if (tree->t.tr2->t.op==CON && tree->F.mask==tree->t.tr2->c.value) {
- tree->t.op = ASOR;
- return(optim(tree));
+ if (tree1->t.tr2->t.op==CON && tree1->F.mask==tree1->t.tr2->c.value) {
+ tree1->t.op = ASOR;
+ return(optim(tree1));
}
case LTIMES:
case ULMOD:
case ULASTIMES:
case ULASDIV:
- tree->t.degree = 10;
+ tree1->t.degree = 10;
break;
case ANDN:
- if (isconstant(tree->t.tr2) && tree->t.tr2->c.value==0) {
- return(tree->t.tr1);
+ if (isconstant(tree1->t.tr2) && tree1->t.tr2->c.value==0) {
+ return(tree1->t.tr1);
}
goto def;
case CALL:
- tree->t.degree = 10;
+ tree1->t.degree = 10;
break;
case QUEST:
case COLON:
- tree->t.degree = MAX(d1, d2);
+ tree1->t.degree = max(d1, d2);
break;
case PTOI:
case DIVIDE:
case ASDIV:
case ASTIMES:
- if (tree->t.tr2->t.op==CON && tree->t.tr2->c.value==1) {
+ if (tree1->t.tr2->t.op==CON && tree1->t.tr2->c.value==1) {
if (op==PTOI)
- return(optim(tnode(LTOI,INT,paint(tree->t.tr1,LONG), TNULL)));
- return(paint(tree->t.tr1, tree->t.type));
+ return(optim(tnode1(LTOI,INT,paint(tree1->t.tr1,LONG), TNULL1)));
+ return(paint(tree1->t.tr1, tree1->t.type));
}
case MOD:
case ASMOD:
- if ((uns(tree->t.tr1) || tree->t.op==PTOI) && ispow2(tree))
- return(pow2(tree));
- if ((op==MOD||op==ASMOD) && tree->t.type==DOUBLE) {
- error("Floating %% not defined");
- tree->t.type = INT;
+ if ((uns(tree1->t.tr1) || tree1->t.op==PTOI) && ispow2(tree1))
+ return(pow2(tree1));
+ if ((op==MOD||op==ASMOD) && tree1->t.type==DOUBLE) {
+ error1("Floating %% not defined");
+ tree1->t.type = INT;
}
case ULSH:
case ASULSH:
d1 += 2 + regpanic;
d2 += 2 + regpanic;
panicposs++;
- if (tree->t.type==LONG || tree->t.type==UNLONG)
- return(hardlongs(tree));
+ if (tree1->t.type==LONG || tree1->t.type==UNLONG)
+ return(hardlongs(tree1));
if ((op==MOD || op==DIVIDE || op==ASMOD || op==ASDIV)
- && (uns(tree->t.tr1) || uns(tree->t.tr2))
- && (tree->t.tr2->t.op!=CON || tree->t.tr2->c.value<=1)) {
+ && (uns(tree1->t.tr1) || uns(tree1->t.tr2))
+ && (tree1->t.tr2->t.op!=CON || tree1->t.tr2->c.value<=1)) {
if (op>=ASDIV) {
- tree->t.op += ASUDIV - ASDIV;
+ tree1->t.op += ASUDIV - ASDIV;
} else
- tree->t.op += UDIV - DIVIDE;
+ tree1->t.op += UDIV - DIVIDE;
d1 = d2 = 10;
}
goto constant;
case ASPLUS:
case ASMINUS:
- if (tree->t.tr2->t.op==CON && tree->t.tr2->c.value==0)
- return(tree->t.tr1);
+ if (tree1->t.tr2->t.op==CON && tree1->t.tr2->c.value==0)
+ return(tree1->t.tr1);
goto def;
case LSHIFT:
case RSHIFT:
case ASRSH:
case ASLSH:
- if (tree->t.tr2->t.op==CON && tree->t.tr2->c.value==0)
- return(paint(tree->t.tr1, tree->t.type));
+ if (tree1->t.tr2->t.op==CON && tree1->t.tr2->c.value==0)
+ return(paint(tree1->t.tr1, tree1->t.type));
/*
* PDP-11 special: turn right shifts into negative
* left shifts
*/
- if (tree->t.type == LONG || tree->t.type==UNLONG) {
+ if (tree1->t.type == LONG || tree1->t.type==UNLONG) {
d1++;
d2++;
}
if (op==LSHIFT||op==ASLSH)
goto constant;
- if (tree->t.tr2->t.op==CON && tree->t.tr2->c.value==1
- && !uns(tree->t.tr1) && !uns(tree->t.tr2))
+ if (tree1->t.tr2->t.op==CON && tree1->t.tr2->c.value==1
+ && !uns(tree1->t.tr1) && !uns(tree1->t.tr2))
goto constant;
op += (LSHIFT-RSHIFT);
- tree->t.op = op;
- tree->t.tr2 = tnode(NEG, tree->t.tr2->t.type, tree->t.tr2, TNULL);
- if (uns(tree->t.tr1) || uns(tree->t.tr2)) {
- if (tree->t.op==LSHIFT)
- tree->t.op = ULSH;
- else if (tree->t.op==ASLSH)
- tree->t.op = ASULSH;
+ tree1->t.op = op;
+ tree1->t.tr2 = tnode1(NEG, tree1->t.tr2->t.type, tree1->t.tr2, TNULL1);
+ if (uns(tree1->t.tr1) || uns(tree1->t.tr2)) {
+ if (tree1->t.op==LSHIFT)
+ tree1->t.op = ULSH;
+ else if (tree1->t.op==ASLSH)
+ tree1->t.op = ASULSH;
}
goto again;
constant:
- if (tree->t.tr1->t.op==CON && tree->t.tr2->t.op==CON) {
- _const(op, &tree->t.tr1->c.value, tree->t.tr2->c.value, tree->t.type);
- return(tree->t.tr1);
+ if (tree1->t.tr1->t.op==CON && tree1->t.tr2->t.op==CON) {
+ _const(op, &tree1->t.tr1->c.value, tree1->t.tr2->c.value, tree1->t.type);
+ return(tree1->t.tr1);
}
def:
default:
if (dope&RELAT) {
- if (tree->t.tr1->t.type==LONG || tree->t.tr1->t.type==UNLONG) /* long relations are a mess */
+ if (tree1->t.tr1->t.type==LONG || tree1->t.tr1->t.type==UNLONG) /* long relations are a mess */
d1 = 10;
- if (opdope[tree->t.tr1->t.op]&RELAT && tree->t.tr2->t.op==CON
- && tree->t.tr2->c.value==0) {
- tree = tree->t.tr1;
+ if (opdope1[tree1->t.tr1->t.op]&RELAT && tree1->t.tr2->t.op==CON
+ && tree1->t.tr2->c.value==0) {
+ tree1 = tree1->t.tr1;
switch(op) {
case GREATEQ:
- return((union tree *)&cone);
+ return((union tree1 *)&cone);
case LESS:
- return((union tree *)&czero);
+ return((union tree1 *)&czero);
case LESSEQ:
case EQUAL:
- tree->t.op = notrel[tree->t.op-EQUAL];
+ tree1->t.op = notrel[tree1->t.op-EQUAL];
}
- return(tree);
+ return(tree1);
}
}
- tree->t.degree = d1==d2? d1+islong(tree->t.type): MAX(d1, d2);
+ tree1->t.degree = d1==d2? d1+islong(tree1->t.type): max(d1, d2);
break;
}
- return(tree);
+ return(tree1);
}
-union tree *unoptim(tree) register union tree *tree; {
- register union tree *subtre, *p;
+union tree1 *unoptim(tree1) register union tree1 *tree1; {
+ register union tree1 *subtre, *p;
#ifndef pdp11
_LONG temp_long;
uint16_t temp[2];
#endif
- if (tree==NULL)
+ if (tree1==NULL)
return(NULL);
again:
- if (tree->t.op==AMPER && tree->t.tr1->t.op==STAR) {
- subtre = tree->t.tr1->t.tr1;
- subtre->t.type = tree->t.type;
+ if (tree1->t.op==AMPER && tree1->t.tr1->t.op==STAR) {
+ subtre = tree1->t.tr1->t.tr1;
+ subtre->t.type = tree1->t.type;
return(optim(subtre));
}
- subtre = tree->t.tr1 = optim(tree->t.tr1);
- switch (tree->t.op) {
+ subtre = tree1->t.tr1 = optim(tree1->t.tr1);
+ switch (tree1->t.op) {
case INCAFT:
case DECAFT:
- if (tree->t.type!=subtre->t.type)
- paint(subtre, tree->t.type);
+ if (tree1->t.type!=subtre->t.type)
+ paint(subtre, tree1->t.type);
break;
case ITOL:
subtre = getblk(sizeof(struct lconst));
subtre->t.op = LCON;
subtre->t.type = LONG;
- subtre->l.lvalue = tree->t.tr1->c.value;
+ subtre->l.lvalue = tree1->t.tr1->c.value;
return(subtre);
}
break;
case FTOI:
- if (uns(tree)) {
- tree->t.op = FTOL;
- tree->t.type = LONG;
- tree = tnode(LTOI, UNSIGN, tree, TNULL);
+ if (uns(tree1)) {
+ tree1->t.op = FTOL;
+ tree1->t.type = LONG;
+ tree1 = tnode1(LTOI, UNSIGN, tree1, TNULL1);
}
break;
case LTOF:
if (subtre->t.op==LCON) {
- tree = getblk(sizeof(struct ftconst));
- tree->t.op = FCON;
- tree->t.type = DOUBLE;
- tree->f/*c*/.value = isn++;
+ tree1 = getblk(sizeof(struct ftconst));
+ tree1->t.op = FCON;
+ tree1->t.type = DOUBLE;
+ tree1->f/*c*/.value = isn1++;
#ifdef pdp11
- tree->f.fvalue = subtre->l.lvalue;
+ tree1->f.fvalue = subtre->l.lvalue;
#else
- tree->f.fvalue = fp_long_to_double(subtre->l.lvalue);
+ tree1->f.fvalue = fp_long_to_double(subtre->l.lvalue);
#endif
- return(optim(tree));
+ return(optim(tree1));
}
if (subtre->t.type==UNLONG)
- tree->t.op = ULTOF;
+ tree1->t.op = ULTOF;
break;
case ITOF:
if (subtre->t.op==CON) {
- tree = getblk(sizeof(struct ftconst));
- tree->t.op = FCON;
- tree->t.type = DOUBLE;
- tree->f.value = isn++;
+ tree1 = getblk(sizeof(struct ftconst));
+ tree1->t.op = FCON;
+ tree1->t.type = DOUBLE;
+ tree1->f.value = isn1++;
#ifdef pdp11
if (uns(subtre))
- tree->f.fvalue = (_UNSIGNED_INT)subtre->c.value;
+ tree1->f.fvalue = (_UNSIGNED_INT)subtre->c.value;
else
- tree->f.fvalue = subtre->c.value;
+ tree1->f.fvalue = subtre->c.value;
#else
/* revisit the unsigned case */
if (uns(subtre))
- tree->f.fvalue = fp_long_to_double((_LONG)(_UNSIGNED_INT)subtre->c.value);
+ tree1->f.fvalue = fp_long_to_double((_LONG)(_UNSIGNED_INT)subtre->c.value);
else
- tree->f.fvalue = fp_int_to_double(subtre->c.value);
+ tree1->f.fvalue = fp_int_to_double(subtre->c.value);
#endif
- return(optim(tree));
+ return(optim(tree1));
}
if (uns(subtre)) {
- tree->t.tr1 = tnode(ITOL, LONG, subtre, TNULL);
- tree->t.op = LTOF;
- return(optim(tree));
+ tree1->t.tr1 = tnode1(ITOL, LONG, subtre, TNULL1);
+ tree1->t.op = LTOF;
+ return(optim(tree1));
}
break;
char c;
c = subtre->c.value;
subtre->c.value = c;
- subtre->t.type = tree->t.type;
+ subtre->t.type = tree1->t.type;
return(subtre);
- } else if (subtre->t.op==NAME && tree->t.type==INT) {
+ } else if (subtre->t.op==NAME && tree1->t.type==INT) {
subtre->t.type = CHAR;
return(subtre);
}
case LCON:
subtre->t.op = CON;
- subtre->t.type = tree->t.type;
+ subtre->t.type = tree1->t.type;
subtre->c.value = subtre->l.lvalue;
return(subtre);
case NAME:
subtre->n.offset += 2;
- subtre->t.type = tree->t.type;
+ subtre->t.type = tree1->t.type;
return(subtre);
case STAR:
- subtre->t.type = tree->t.type;
- subtre->t.tr1->t.type = tree->t.type+PTR;
- subtre->t.tr1 = tnode(PLUS, tree->t.type, subtre->t.tr1, tconst(2, INT));
+ subtre->t.type = tree1->t.type;
+ subtre->t.tr1->t.type = tree1->t.type+PTR;
+ subtre->t.tr1 = tnode1(PLUS, tree1->t.type, subtre->t.tr1, tconst(2, INT));
return(optim(subtre));
case ITOL:
- return(paint(subtre->t.tr1, tree->t.type));
+ return(paint(subtre->t.tr1, tree1->t.type));
case PLUS:
case MINUS:
case ANDN:
case OR:
case EXOR:
- subtre->t.tr2 = tnode(LTOI, tree->t.type, subtre->t.tr2, TNULL);
+ subtre->t.tr2 = tnode1(LTOI, tree1->t.type, subtre->t.tr2, TNULL1);
case NEG:
case COMPL:
- subtre->t.tr1 = tnode(LTOI, tree->t.type, subtre->t.tr1, TNULL);
- subtre->t.type = tree->t.type;
+ subtre->t.tr1 = tnode1(LTOI, tree1->t.type, subtre->t.tr1, TNULL1);
+ subtre->t.type = tree1->t.type;
return(optim(subtre));
}
break;
case FSEL:
- tree->t.op = AND;
- tree->t.tr1 = tree->t.tr2->t.tr1;
- tree->t.tr2->t.tr1 = subtre;
- tree->t.tr2->t.op = RSHIFT;
- tree->t.tr1->c.value = (1 << tree->t.tr1->c.value) - 1;
- return(optim(tree));
+ tree1->t.op = AND;
+ tree1->t.tr1 = tree1->t.tr2->t.tr1;
+ tree1->t.tr2->t.tr1 = subtre;
+ tree1->t.tr2->t.op = RSHIFT;
+ tree1->t.tr1->c.value = (1 << tree1->t.tr1->c.value) - 1;
+ return(optim(tree1));
case FSELR:
- tree->t.op = LSHIFT;
- tree->t.type = UNSIGN;
- tree->t.tr1 = tree->t.tr2;
- tree->t.tr1->t.op = AND;
- tree->t.tr2 = tree->t.tr2->t.tr2;
- tree->t.tr1->t.tr2 = subtre;
- tree->t.tr1->t.tr1->c.value = (1 << tree->t.tr1->t.tr1->c.value) -1;
- return(optim(tree));
+ tree1->t.op = LSHIFT;
+ tree1->t.type = UNSIGN;
+ tree1->t.tr1 = tree1->t.tr2;
+ tree1->t.tr1->t.op = AND;
+ tree1->t.tr2 = tree1->t.tr2->t.tr2;
+ tree1->t.tr1->t.tr2 = subtre;
+ tree1->t.tr1->t.tr1->c.value = (1 << tree1->t.tr1->t.tr1->c.value) -1;
+ return(optim(tree1));
case AMPER:
if (subtre->t.op==STAR)
return(subtre->t.tr1);
if (subtre->t.op==NAME && subtre->n.class == OFFS) {
- p = tnode(PLUS, tree->t.type, subtre, tree);
- subtre->t.type = tree->t.type;
- tree->t.op = CON;
- tree->t.type = INT;
- tree->t.degree = 0;
- tree->c.value = subtre->n.offset;
+ p = tnode1(PLUS, tree1->t.type, subtre, tree1);
+ subtre->t.type = tree1->t.type;
+ tree1->t.op = CON;
+ tree1->t.type = INT;
+ tree1->t.degree = 0;
+ tree1->c.value = subtre->n.offset;
subtre->n.class = REG;
subtre->n.nloc = subtre->n.regno;
subtre->n.offset = 0;
return(optim(p));
}
if (subtre->t.op==LOAD) {
- tree->t.tr1 = subtre->t.tr1;
+ tree1->t.tr1 = subtre->t.tr1;
goto again;
}
break;
case STAR:
if (subtre->t.op==AMPER) {
- subtre->t.tr1->t.type = tree->t.type;
+ subtre->t.tr1->t.type = tree1->t.type;
return(subtre->t.tr1);
}
- if (tree->t.type==STRUCT)
+ if (tree1->t.type==STRUCT)
break;
if (subtre->t.op==NAME && subtre->n.class==REG) {
- subtre->t.type = tree->t.type;
+ subtre->t.type = tree1->t.type;
subtre->n.class = OFFS;
subtre->n.regno = subtre->n.nloc;
return(subtre);
}
p = subtre->t.tr1;
if ((subtre->t.op==INCAFT||subtre->t.op==DECBEF)
- && tree->t.type!=LONG && tree->t.type!=UNLONG
+ && tree1->t.type!=LONG && tree1->t.type!=UNLONG
&& p->t.op==NAME && p->n.class==REG && p->t.type==subtre->t.type) {
- p->t.type = tree->t.type;
+ p->t.type = tree1->t.type;
p->t.op = subtre->t.op==INCAFT? AUTOI: AUTOD;
return(p);
}
if (subtre->t.tr2->t.op==CON) {
p->n.offset += subtre->t.tr2->c.value;
p->n.class = OFFS;
- p->t.type = tree->t.type;
+ p->t.type = tree1->t.type;
p->n.regno = p->n.nloc;
return(p);
}
subtre = subtre->t.tr2->t.tr1;
subtre->n.class += XOFFS-EXTERN;
subtre->n.regno = p->n.nloc;
- subtre->t.type = tree->t.type;
+ subtre->t.type = tree1->t.type;
return(subtre);
}
}
&& subtre->t.tr2->t.op==CON) {
p->n.offset -= subtre->t.tr2->c.value;
p->n.class = OFFS;
- p->t.type = tree->t.type;
+ p->t.type = tree1->t.type;
p->n.regno = p->n.nloc;
return(p);
}
break;
case EXCLA:
- if ((opdope[subtre->t.op]&RELAT)==0)
+ if ((opdope1[subtre->t.op]&RELAT)==0)
break;
- tree = subtre;
- tree->t.op = notrel[tree->t.op-EQUAL];
+ tree1 = subtre;
+ tree1->t.op = notrel[tree1->t.op-EQUAL];
break;
case COMPL:
- if (tree->t.type==CHAR)
- tree->t.type = INT;
- if (tree->t.op == subtre->t.op)
- return(paint(subtre->t.tr1, tree->t.type));
+ if (tree1->t.type==CHAR)
+ tree1->t.type = INT;
+ if (tree1->t.op == subtre->t.op)
+ return(paint(subtre->t.tr1, tree1->t.type));
if (subtre->t.op==CON) {
subtre->c.value = ~subtre->c.value;
- return(paint(subtre, tree->t.type));
+ return(paint(subtre, tree1->t.type));
}
if (subtre->t.op==LCON) {
subtre->l.lvalue = ~subtre->l.lvalue;
}
if (subtre->t.op==ITOL) {
if (subtre->t.tr1->t.op==CON) {
- tree = getblk(sizeof(struct lconst));
- tree->t.op = LCON;
- tree->t.type = LONG;
+ tree1 = getblk(sizeof(struct lconst));
+ tree1->t.op = LCON;
+ tree1->t.type = LONG;
if (uns(subtre->t.tr1))
- tree->l.lvalue = ~(_LONG)(_UNSIGNED_INT)
+ tree1->l.lvalue = ~(_LONG)(_UNSIGNED_INT)
subtre->t.tr1->c.value;
else
- tree->l.lvalue =
+ tree1->l.lvalue =
~subtre->t.tr1->c.value;
- return(tree);
+ return(tree1);
}
if (uns(subtre->t.tr1))
break;
- subtre->t.op = tree->t.op;
+ subtre->t.op = tree1->t.op;
subtre->t.type = subtre->t.tr1->t.type;
- tree->t.op = ITOL;
- tree->t.type = LONG;
+ tree1->t.op = ITOL;
+ tree1->t.type = LONG;
goto again;
}
case NEG:
- if (tree->t.type==CHAR)
- tree->t.type = INT;
- if (tree->t.op==subtre->t.op)
- return(paint(subtre->t.tr1, tree->t.type));
+ if (tree1->t.type==CHAR)
+ tree1->t.type = INT;
+ if (tree1->t.op==subtre->t.op)
+ return(paint(subtre->t.tr1, tree1->t.type));
if (subtre->t.op==CON) {
subtre->c.value = -subtre->c.value;
- return(paint(subtre, tree->t.type));
+ return(paint(subtre, tree1->t.type));
}
if (subtre->t.op==LCON) {
subtre->l.lvalue = -subtre->l.lvalue;
return(subtre);
}
if (subtre->t.op==ITOL && subtre->t.tr1->t.op==CON) {
- tree = getblk(sizeof(struct lconst));
- tree->t.op = LCON;
- tree->t.type = LONG;
+ tree1 = getblk(sizeof(struct lconst));
+ tree1->t.op = LCON;
+ tree1->t.type = LONG;
if (uns(subtre->t.tr1))
- tree->l.lvalue = -(_LONG)(_UNSIGNED_INT)
+ tree1->l.lvalue = -(_LONG)(_UNSIGNED_INT)
subtre->t.tr1->c.value;
else
- tree->l.lvalue = -subtre->t.tr1->c.value;
- return(tree);
+ tree1->l.lvalue = -subtre->t.tr1->c.value;
+ return(tree1);
}
/*
* PDP-11 FP negation
return(subtre);
}
}
- if ((opdope[tree->t.op]&LEAF)==0)
- tree->t.degree = MAX(islong(tree->t.type), degree(subtre));
- return(tree);
+ if ((opdope1[tree1->t.op]&LEAF)==0)
+ tree1->t.degree = max(islong(tree1->t.type), degree(subtre));
+ return(tree1);
}
/*
* Pure assignment is handled specially.
*/
-union tree *lvfield(t) register union tree *t; {
- register union tree *t1, *t2;
+union tree1 *lvfield(t) register union tree1 *t; {
+ register union tree1 *t1, *t2;
switch (t->t.op) {
t1->t.tr1 = t->t.tr2;
t->t.tr2 = t1;
t1 = t1->t.tr2;
- t1 = tnode(COMMA, INT, tconst(t1->t.tr1->c.value, INT),
+ t1 = tnode1(COMMA, INT, tconst(t1->t.tr1->c.value, INT),
tconst(t1->t.tr2->c.value, INT));
- return(optim(tnode(FSELT, UNSIGN, t, t1)));
+ return(optim(tnode1(FSELT, UNSIGN, t, t1)));
}
- error("Unimplemented field operator");
+ error1("Unimplemented field operator");
return(t);
}
struct acl {
int nextl;
int nextn;
- union tree *nlist[LSTSIZ];
- union tree *llist[LSTSIZ+1];
+ union tree1 *nlist[LSTSIZ];
+ union tree1 *llist[LSTSIZ+1];
};
#endif
-union tree *acommute(tree) register union tree *tree; {
+union tree1 *acommute(tree1) register union tree1 *tree1; {
struct acl acl;
int d, i, op, flt, d1, type;
- register union tree *t1, **t2;
- union tree *t;
+ register union tree1 *t1, **t2;
+ union tree1 *t;
acl.nextl = 0;
acl.nextn = 0;
- op = tree->t.op;
- type = tree->t.type;
- flt = isfloat(tree);
- insert(op, tree, &acl);
+ op = tree1->t.op;
+ type = tree1->t.type;
+ flt = isfloat(tree1);
+ insert(op, tree1, &acl);
acl.nextl--;
t2 = &acl.llist[acl.nextl];
if (!flt) {
}
if (acl.nextl <= 0) {
if ((*t2)->t.type==CHAR || (*t2)->t.type==UNCHAR)
- *t2 = tnode(LOAD, tree->t.type, *t2, TNULL);
- (*t2)->t.type = tree->t.type;
+ *t2 = tnode1(LOAD, tree1->t.type, *t2, TNULL1);
+ (*t2)->t.type = tree1->t.type;
return(*t2);
}
/* subsume constant in "&x+c" */
if (op==TIMES && t1->c.value==1 && acl.nextl>0)
if (--acl.nextl <= 0) {
t1 = acl.llist[0];
- if (uns(tree))
- paint(t1, tree->t.type);
+ if (uns(tree1))
+ paint(t1, tree1->t.type);
return(t1);
}
}
}
if (op==PLUS && !flt)
distrib(&acl);
- tree = *(t2 = &acl.llist[0]);
- d = MAX(degree(tree), islong(tree->t.type));
+ tree1 = *(t2 = &acl.llist[0]);
+ d = max(degree(tree1), islong(tree1->t.type));
if (op==TIMES && !flt) {
d += regpanic+1;
panicposs++;
* rt. op of ^ must be in a register.
*/
if (op==EXOR && dcalc(t, 0)<=12) {
- t1->t.tr2 = t = optim(tnode(LOAD, t->t.type, t, TNULL));
+ t1->t.tr2 = t = optim(tnode1(LOAD, t->t.type, t, TNULL1));
d1 = t->t.degree;
}
- t1->t.degree = d = d==d1? d+islong(t1->t.type): MAX(d, d1);
- t1->t.tr1 = tree;
- tree = t1;
- if (tree->t.type==LONG || tree->t.type==UNLONG) {
- if (tree->t.op==TIMES)
- tree = hardlongs(tree);
- else if (tree->t.op==PLUS && (t = isconstant(tree->t.tr1))
+ t1->t.degree = d = d==d1? d+islong(t1->t.type): max(d, d1);
+ t1->t.tr1 = tree1;
+ tree1 = t1;
+ if (tree1->t.type==LONG || tree1->t.type==UNLONG) {
+ if (tree1->t.op==TIMES)
+ tree1 = hardlongs(tree1);
+ else if (tree1->t.op==PLUS && (t = isconstant(tree1->t.tr1))
&& t->c.value < 0 && !uns(t)) {
- tree->t.op = MINUS;
+ tree1->t.op = MINUS;
t->c.value = - t->c.value;
- t = tree->t.tr1;
- tree->t.tr1 = tree->t.tr2;
- tree->t.tr2 = t;
+ t = tree1->t.tr1;
+ tree1->t.tr1 = tree1->t.tr2;
+ tree1->t.tr2 = t;
}
}
}
- if (tree->t.op==TIMES && ispow2(tree))
- tree->t.degree = MAX(degree(tree->t.tr1), islong(tree->t.type));
- paint(tree, type);
- return(tree);
+ if (tree1->t.op==TIMES && ispow2(tree1))
+ tree1->t.degree = max(degree(tree1->t.tr1), islong(tree1->t.type));
+ paint(tree1, type);
+ return(tree1);
}
-int sideeffects(tp) register union tree *tp; {
+int sideeffects(tp) register union tree1 *tp; {
register int dope;
if (tp==NULL)
return(0);
- dope = opdope[tp->t.op];
+ dope = opdope1[tp->t.op];
if (dope&LEAF) {
if (tp->t.op==AUTOI || tp->t.op==AUTOD)
return(1);
* fewest divisors. Reduce this pair to c1*(y+c2*x)
* and iterate until no reductions occur.
*/
- register union tree **p1, **p2;
- union tree *t;
+ register union tree1 **p1, **p2;
+ union tree1 *t;
int ndmaj, ndmin;
- union tree **dividend, **divisor;
- union tree **maxnod, **mindiv;
+ union tree1 **dividend, **divisor;
+ union tree1 **maxnod, **mindiv;
loop:
maxnod = &list->llist[list->nextl];
goto loop;
}
-void squash(p, maxp) union tree **p; union tree **maxp; {
- register union tree **np;
+void squash(p, maxp) union tree1 **p; union tree1 **maxp; {
+ register union tree1 **np;
for (np = p; np < maxp; np++)
*np = *(np+1);
}
}
if (v==0)
- werror("divide check");
+ werror1("divide check");
else
if (type==INT)
if (op==DIVIDE || op==UDIV)
*vp &= ~ v;
return;
}
- error("C error: const");
+ error1("C error1: const");
}
-union tree *lconst(op, lp, rp) int op; register union tree *lp; register union tree *rp; {
+union tree1 *lconst(op, lp, rp) int op; register union tree1 *lp; register union tree1 *rp; {
_UNSIGNED_LONG l, r;
if (lp->t.op==LCON)
case DIVIDE:
case LDIV:
if (r==0)
- error("Divide check");
+ error1("Divide check");
else
l /= r;
break;
case MOD:
case LMOD:
if (r==0)
- error("Divide check");
+ error1("Divide check");
else
l %= r;
break;
return(lp);
}
-void insert(op, tree, list) int op; register union tree *tree; register struct acl *list; {
+void insert(op, tree1, list) int op; register union tree1 *tree1; register struct acl *list; {
register int d;
int d1, i;
- union tree *t;
+ union tree1 *t;
ins:
- if (tree->t.op != op)
- tree = optim(tree);
- if (tree->t.op == op && list->nextn < LSTSIZ-2) {
- list->nlist[list->nextn++] = tree;
- insert(op, tree->t.tr1, list);
- insert(op, tree->t.tr2, list);
+ if (tree1->t.op != op)
+ tree1 = optim(tree1);
+ if (tree1->t.op == op && list->nextn < LSTSIZ-2) {
+ list->nlist[list->nextn++] = tree1;
+ insert(op, tree1->t.tr1, list);
+ insert(op, tree1->t.tr2, list);
return;
}
- if (!isfloat(tree)) {
+ if (!isfloat(tree1)) {
/* c1*(x+c2) -> c1*x+c1*c2 */
- if ((tree->t.op==TIMES||tree->t.op==LSHIFT)
- && tree->t.tr2->t.op==CON && tree->t.tr2->c.value>0
- && tree->t.tr1->t.op==PLUS && tree->t.tr1->t.tr2->t.op==CON) {
- d = tree->t.tr2->c.value;
- if (tree->t.op==TIMES)
- tree->t.tr2->c.value *= tree->t.tr1->t.tr2->c.value;
+ if ((tree1->t.op==TIMES||tree1->t.op==LSHIFT)
+ && tree1->t.tr2->t.op==CON && tree1->t.tr2->c.value>0
+ && tree1->t.tr1->t.op==PLUS && tree1->t.tr1->t.tr2->t.op==CON) {
+ d = tree1->t.tr2->c.value;
+ if (tree1->t.op==TIMES)
+ tree1->t.tr2->c.value *= tree1->t.tr1->t.tr2->c.value;
else
- tree->t.tr2->c.value = tree->t.tr1->t.tr2->c.value << d;
- tree->t.tr1->t.tr2->c.value = d;
- tree->t.tr1->t.op = tree->t.op;
- tree->t.op = PLUS;
- tree = optim(tree);
+ tree1->t.tr2->c.value = tree1->t.tr1->t.tr2->c.value << d;
+ tree1->t.tr1->t.tr2->c.value = d;
+ tree1->t.tr1->t.op = tree1->t.op;
+ tree1->t.op = PLUS;
+ tree1 = optim(tree1);
if (op==PLUS)
goto ins;
}
}
- d = degree(tree);
+ d = degree(tree1);
for (i=0; i<list->nextl; i++) {
if ((d1=degree(list->llist[i]))<d) {
t = list->llist[i];
- list->llist[i] = tree;
- tree = t;
+ list->llist[i] = tree1;
+ tree1 = t;
d = d1;
}
}
- list->llist[list->nextl++] = tree;
+ list->llist[list->nextl++] = tree1;
}
-union tree *tnode(op, type, tr1, tr2) int op; int type; union tree *tr1; union tree *tr2; {
- register union tree *p;
+union tree1 *tnode1(op, type, tr1, tr2) int op; int type; union tree1 *tr1; union tree1 *tr2; {
+ register union tree1 *p;
- p = getblk(sizeof(struct tnode));
+ p = getblk(sizeof(struct tnode1));
p->t.op = op;
p->t.type = type;
p->t.degree = 0;
return(p);
}
-union tree *tconst(val, type) int val; int type; {
- register union tree *p;
+union tree1 *tconst(val, type) int val; int type; {
+ register union tree1 *p;
p = getblk(sizeof(struct tconst));
p->t.op = CON;
return(p);
}
-union tree *getblk(size) int size; {
- register union tree *p;
+union tree1 *getblk(size) int size; {
+ register union tree1 *p;
if (size&01)
size++;
- p = (union tree *)curbase;
+ p = (union tree1 *)curbase;
if ((curbase += size) >= coremax) {
#ifdef pdp11
if (sbrk(1024) == (char *)-1) {
#else
if (sbrk(1024) != coremax) {
#endif
- error("Out of space-- c1");
+ error1("Out of space-- c1");
exit(1);
}
coremax += 1024;
return(1);
}
-union tree *isconstant(t) register union tree *t; {
+union tree1 *isconstant(t) register union tree1 *t; {
if (t->t.op==CON || t->t.op==SFCON)
return(t);
if (t->t.op==ITOL && t->t.tr1->t.op==CON)
return(NULL);
}
-union tree *hardlongs(t) register union tree *t; {
+union tree1 *hardlongs(t) register union tree1 *t; {
switch(t->t.op) {
case TIMES:
t->t.op += ULASTIMES-ASTIMES;
else
t->t.op += LASTIMES-ASTIMES;
- t->t.tr1 = tnode(AMPER, LONG+PTR, t->t.tr1, TNULL);
+ t->t.tr1 = tnode1(AMPER, LONG+PTR, t->t.tr1, TNULL1);
break;
default:
}
/*
- * Is tree of unsigned type?
+ * Is tree1 of unsigned type?
*/
-int uns(tp) union tree *tp; {
+int uns(tp) union tree1 *tp; {
register int t;
t = tp->t.type;
/*
* Operator dope table-- see description in c0.
*/
-int opdope[] = {
+int opdope1[] = {
000000, /* EOFC (0) */
000000, /* ; */
000000, /* { */
036000, /* mcall */
000000, /* goto */
000000, /* jump cond */
- 000000, /* branch cond */
+ 000000, /* branch1 cond */
000400, /* set nregs */
000000, /* load */
030001, /* ptoi1 */
000000, /* (108) */
000000, /* int->char */
000000, /* force r0 (110) */
- 000000, /* branch */
- 000000, /* label */
+ 000000, /* branch1 */
+ 000000, /* label1 */
000000, /* nlabel */
000000, /* rlabel */
000000, /* structure assign */
"mcall",
"goto",
"jump cond",
- "branch cond",
+ "branch1 cond",
"set nregs",
"load value",
"ptr->integer",
0,
"int->char",
"force register", /* 110 */
- "branch",
- "label",
+ "branch1",
+ "label1",
"nlabel",
"rlabel",
"=structure",
--- /dev/null
+#ifndef _CCOM_H_
+#define _CCOM_H_
+
+#ifdef pdp11
+typedef int _INT;
+typedef long _LONG;
+typedef unsigned int _UNSIGNED_INT;
+typedef unsigned long _UNSIGNED_LONG;
+typedef float _FLOAT;
+typedef double _DOUBLE;
+#else
+#include <stdint.h>
+typedef int16_t _INT;
+typedef int32_t _LONG;
+typedef uint16_t _UNSIGNED_INT;
+typedef uint32_t _UNSIGNED_LONG;
+typedef struct { uint32_t h; } _FLOAT;
+typedef struct { uint32_t l; uint32_t h; } _DOUBLE;
+#endif
+
+/*
+ * Table for recording switches.
+ */
+struct swtab {
+ int swlab;
+ int swval;
+};
+
+/*
+ operators
+*/
+#define EOFC 0
+#define SEMI 1
+#define LBRACE 2
+#define RBRACE 3
+#define LBRACK 4
+#define RBRACK 5
+#define LPARN 6
+#define RPARN 7
+#define COLON 8
+#define COMMA 9
+#define FSEL 10
+#define CAST 11 /* pass 0 only */
+#define FSELR 11 /* pass 1 only */
+#define ETYPE 12 /* pass 0 only */
+#define FSELT 12 /* pass 1 only */
+#define FSELA 16 /* pass 1 only */
+#define ULSH 17 /* pass 1 only */
+#define ASULSH 18 /* pass 1 only */
+
+#define KEYW 19
+#define NAME 20
+#define CON 21
+#define STRING 22
+#define FCON 23
+#define SFCON 24
+#define LCON 25
+#define SLCON 26
+#define NULLOP0 29 /* pass 0 only */
+#define NULLOP 218 /* interface version */
+
+#define AUTOI 27 /* pass 1 only */
+#define AUTOD 28 /* pass 1 only */
+#define INCBEF 30
+#define DECBEF 31
+#define INCAFT 32
+#define DECAFT 33
+#define EXCLA 34
+#define AMPER 35
+#define STAR 36
+#define NEG 37
+#define COMPL 38
+
+#define DOT 39
+#define PLUS 40
+#define MINUS 41
+#define TIMES 42
+#define DIVIDE 43
+#define MOD 44
+#define RSHIFT 45
+#define LSHIFT 46
+#define AND 47
+#define ANDN 55 /* pass 1 only */
+#define OR 48
+#define EXOR 49
+#define ARROW 50
+#define ITOF 51
+#define FTOI 52
+#define LOGAND 53
+#define LOGOR 54
+#define FTOL 56
+#define LTOF 57
+#define ITOL 58
+#define LTOI 59
+#define ITOP 13
+#define PTOI 14
+#define LTOP 15
+
+#define EQUAL 60
+#define NEQUAL 61
+#define LESSEQ 62
+#define LESS 63
+#define GREATEQ 64
+#define GREAT 65
+#define LESSEQP 66
+#define LESSP 67
+#define GREATQP 68
+#define GREATP 69
+
+#define ASPLUS 70
+#define ASMINUS 71
+#define ASTIMES 72
+#define ASDIV 73
+#define ASMOD 74
+#define ASRSH 75
+#define ASLSH 76
+#define ASSAND 77 /* pass 0 only */
+#define ASAND 77 /* pass 1 only */
+#define ASOR 78
+#define ASXOR 79
+#define ASSIGN 80
+#define TAND 81 /* pass 1 only */
+#define LTIMES 82 /* pass 1 only */
+#define LDIV 83 /* pass 1 only */
+#define LMOD 84 /* pass 1 only */
+#define ASANDN 85 /* pass 1 only */
+#define LASTIMES 86 /* pass 1 only */
+#define LASDIV 87 /* pass 1 only */
+#define LASMOD 88 /* pass 1 only */
+
+#define QUEST 90
+#define SIZEOF 91 /* pass 0 only */
+#define LLSHIFT 91 /* pass 1 only */
+#define ASLSHL 92 /* pass 1 only */
+#define MAX 93 /* pass 0 only */
+#define MAXP 94
+#define MIN 95 /* pass 0 only */
+#define MINP 96
+#define SEQNC 97
+#define CALL1 98 /* pass 1 only */
+#define CALL2 99 /* pass 1 only */
+#define CALL 100
+#define MCALL 101
+#define JUMP 102
+#define CBRANCH 103
+#define INIT 104
+#define SETREG 105
+#define LOAD 106 /* pass 1 only */
+#define PTOI1 107 /* pass 1 only */
+#define ITOC 109
+#define RFORCE 110
+
+/*
+ * Intermediate code operators
+ */
+#define BRANCH 111
+#define LABEL 112
+#define NLABEL 113
+#define RLABEL 114
+#define STRASG 115
+#define STRSET 116 /* pass 1 only */
+#define UDIV 117 /* pass 1 only */
+#define UMOD 118 /* pass 1 only */
+#define ASUDIV 119 /* pass 1 only */
+#define ASUMOD 120 /* pass 1 only */
+#define ULTIMES 121 /* present for symmetry; pass 1 only */
+#define ULDIV 122 /* pass 1 only */
+#define ULMOD 123 /* pass 1 only */
+#define ULASTIMES 124 /* present for symmetry; pass 1 only */
+#define ULASDIV 125 /* pass 1 only */
+#define ULASMOD 126 /* pass 1 only */
+#define ULTOF 127 /* pass 1 only */
+#define ULLSHIFT 128 /* << for unsigned long; pass 1 only */
+#define UASLSHL 129 /* <<= for unsigned long; pass 1 only */
+
+#define SEOF 200 /* stack EOF marker in expr compilation; pass 0 only */
+
+/*
+ * Special operators in intermediate code
+ */
+#define BDATA 200
+#define WDATA 201 /* pass 0 only */
+#define PROG 202
+#define DATA 203
+#define BSS 204
+#define CSPACE 205
+#define SSPACE 206
+#define SYMDEF 207
+#define SAVE 208
+#define RETRN 209
+#define EVEN 210
+#define PROFIL 212
+#define SWIT 213
+#define EXPR 214
+#define SNAME 215
+#define RNAME 216
+#define ANAME 217
+#define SETSTK 219
+#define SINIT 220
+#define GLOBAL 221 /* pass 1 only */
+#define C3BRANCH 222 /* pass 1 only */
+#define ASSEM 223
+
+/*
+ types
+*/
+#define INT 0
+#define CHAR 1
+#define FLOAT 2
+#define DOUBLE 3
+#define STRUCT 4
+#define RSTRUCT 5 /* pass 1 only */
+#define LONG 6
+#define UNSIGN 7
+#define UNCHAR 8
+#define UNLONG 9
+#define VOID 10
+#define UNION 8 /* adjusted later to struct; pass 0 only */
+
+#define ALIGN 01 /* pass 0 only */
+#define TYPE 017
+#define BIGTYPE 060000 /* pass 0 only */
+#define TYLEN 2
+#define XTYPE (03<<4)
+#define PTR 020
+#define FUNC 040
+#define ARRAY 060
+
+/*
+ storage classes
+*/
+#define KEYWC 1
+#define TYPEDEF 9 /* pass 0 only */
+#define MOS 10
+#define AUTO 11
+#define EXTERN 12
+#define STATIC 13
+#define REG 14
+#define STRTAG 15
+#define ARG 16 /* pass 0 only */
+#define ARG1 17 /* pass 0 only */
+#define AREG 18 /* pass 0 only */
+#define DEFXTRN 20 /* pass 0 only */
+#define MOU 21 /* pass 0 only */
+#define ENUMTAG 22 /* pass 0 only */
+#define ENUMCON 24 /* pass 0 only */
+#define ARG 16 /* pass 1 only */
+#define OFFS 20 /* pass 1 only */
+#define XOFFS 21 /* pass 1 only */
+#define SOFFS 22 /* pass 1 only */
+
+/*
+ keywords
+*/
+#define GOTO 20
+#define RETURN 21
+#define IF 22
+#define WHILE 23
+#define ELSE 24
+#define SWITCH 25
+#define CASE 26
+#define BREAK 27
+#define CONTIN 28
+#define DO 29
+#define DEFAULT 30
+#define FOR 31
+#define ENUM 32
+#define ASM 33
+
+/*
+ characters
+*/
+#define BSLASH 117
+#define SHARP 118
+#define INSERT 119
+#define PERIOD 120
+#define SQUOTE 121
+#define DQUOTE 122
+#define LETTER 123
+#define DIGIT 124
+#define NEWLN 125
+#define SPACE 126
+#define UNKN 127
+
+/*
+ * Special operators in intermediate code
+ */
+#define BDATA 200
+#define WDATA 201 /* pass 0 only */
+#define PROG 202
+#define DATA 203
+#define BSS 204
+#define CSPACE 205
+#define SSPACE 206
+#define SYMDEF 207
+#define SAVE 208
+#define RETRN 209
+#define EVEN 210
+#define PROFIL 212
+#define SWIT 213
+#define EXPR 214
+#define SNAME 215
+#define RNAME 216
+#define ANAME 217
+#define SETSTK 219
+#define SINIT 220
+#define GLOBAL 221 /* pass 1 only */
+#define C3BRANCH 222 /* pass 1 only */
+#define ASSEM 223
+
+/*
+ Flag bits
+*/
+
+#define BINARY 01
+#define LVALUE 02
+#define RELAT 04
+#define ASSGOP 010
+#define LWORD 020
+#define RWORD 040
+#define COMMUTE 0100
+#define RASSOC 0200
+#define LEAF 0400
+#define PCVOK 040000 /* pass 0 only */
+#define CNVRT 01000 /* pass 1 only */
+
+#endif
--- /dev/null
+s/@/ATSIGN/g
+s/^/@/
+s/$/@/
+s/[^A-Za-z0-9_]\+/@&@/g
+
+s/@opdope@/@opdope0@/g
+s/@rcexpr@/@rcexpr0@/g
+s/@error@/@error0@/g
+s/@pswitch@/@pswitch0@/g
+s/@cbranch@/@cbranch0@/g
+s/@label@/@label0@/g
+s/@branch@/@branch0@/g
+s/@werror@/@werror0@/g
+s/@decref@/@decref0@/g
+s/@incref@/@incref0@/g
+s/@isn@/@isn0@/g
+s/@tnode@/@tnode0@/g
+s/@funcblk@/@funcblk0@/g
+s/@cp@/@cp0@/g
+s/@tree@/@tree0@/g
+s/@xprtype@/@xprtype0@/g
+s/@TNULL@/@TNULL0@/g
+
+s/@//g
+s/ATSIGN/@/g
--- /dev/null
+s/@/ATSIGN/g
+s/^/@/
+s/$/@/
+s/[^A-Za-z0-9_]\+/@&@/g
+
+s/@opdope@/@opdope1@/g
+s/@rcexpr@/@rcexpr1@/g
+s/@error@/@error1@/g
+s/@pswitch@/@pswitch1@/g
+s/@cbranch@/@cbranch1@/g
+s/@label@/@label1@/g
+s/@branch@/@branch1@/g
+s/@werror@/@werror1@/g
+s/@decref@/@decref1@/g
+s/@incref@/@incref1@/g
+s/@isn@/@isn1@/g
+s/@tnode@/@tnode1@/g
+s/@funcblk@/@funcblk1@/g
+s/@cp@/@cp1@/g
+s/@tree@/@tree1@/g
+s/@xprtype@/@xprtype1@/g
+s/@TNULL@/@TNULL1@/g
+
+s/@//g
+s/ATSIGN/@/g