ANSI C compilation fixes

This commit is contained in:
carl 2019-05-14 23:22:38 +08:00
parent 9bb69bbb98
commit b1f6d5d827
11 changed files with 1075 additions and 1013 deletions

View file

@ -6,30 +6,30 @@ static char rcsidp3[] = "$Id$";
#define UPDATEWORST(backups) if(backups>mostbackups) mostbackups = backups; #define UPDATEWORST(backups) if(backups>mostbackups) mostbackups = backups;
PRIVATE int leftmatch(); PRIVATE int rightmatch(struct mnems,struct mnems,int, int);
PRIVATE int rightmatch(); PRIVATE int leftmatch(struct mnems, struct mnems, int, int);
findworst(patt,repl)
struct mnems patt,repl; void findworst(struct mnems patt,struct mnems repl)
{ {
/* /*
/* Find the pattern that requires the most backup of output queue. / Find the pattern that requires the most backup of output queue.
/* Let repl be r1 r2 ... rn. All these are already on the output queue. / Let repl be r1 r2 ... rn. All these are already on the output queue.
/* Possibilities in order of most backup first are: / Possibilities in order of most backup first are:
/* a) pattern of form: p1 .... pb r1 r2 .... rn pc ... pd / a) pattern of form: p1 .... pb r1 r2 .... rn pc ... pd
/* i.e. <repl> completely in pattern. / i.e. <repl> completely in pattern.
/* requires a backup of b+n instructions / requires a backup of b+n instructions
/* and a goto to state 0. / and a goto to state 0.
/* b) pattern of form: p1 .... pb r1 r2 .... ri / b) pattern of form: p1 .... pb r1 r2 .... ri
/* i.e. a prefix of <repl> ends a pattern. / i.e. a prefix of <repl> ends a pattern.
/* requires a backup of b+n instructions / requires a backup of b+n instructions
/* and a goto to state 0. / and a goto to state 0.
/* c) pattern of form: ri ri+1 ... rn pc ... pd / c) pattern of form: ri ri+1 ... rn pc ... pd
/* i.e. a suffix of <repl> starts a pattern. / i.e. a suffix of <repl> starts a pattern.
/* requires a backup of j-i+1 instructions and a goto to state 0. / requires a backup of j-i+1 instructions and a goto to state 0.
/* d) pattern of the form: ri ri+1 ... rj / d) pattern of the form: ri ri+1 ... rj
/* i.e. a substring of <repl> is a complete pattern / i.e. a substring of <repl> is a complete pattern
/* requires a backup of j-i+1 instructions and a goto to state 0. / requires a backup of j-i+1 instructions and a goto to state 0.
*/ */
int n = repl.m_len; int n = repl.m_len;
int diff = patt.m_len - repl.m_len; int diff = patt.m_len - repl.m_len;
@ -45,7 +45,7 @@ findworst(patt,repl)
if(actions[s]==(struct action *)NULL) if(actions[s]==(struct action *)NULL)
continue; continue;
/* look for case a */ /* look for case a */
if(first=rightmatch(patterns[s],repl,1,n)) { if( (first=rightmatch(patterns[s],repl,1,n))) {
UPDATEWORST(first-1+n); UPDATEWORST(first-1+n);
} }
/* look for case b */ /* look for case b */
@ -76,16 +76,14 @@ findworst(patt,repl)
fprintf(ofile,"\t\tOO_mkrepl(%d,%d,%d);\n",n,diff,mostbackups); fprintf(ofile,"\t\tOO_mkrepl(%d,%d,%d);\n",n,diff,mostbackups);
} }
findfail(state,resout,rescpy,resgto) void findfail(int state, int *resout, int *rescpy, int *resgto)
int state;
int *resout, *rescpy, *resgto;
{ {
/* /*
/* If pattern matching fails in 'state', how many outputs and how many / If pattern matching fails in 'state', how many outputs and how many
/* push backs are requires. If pattern is of the form p1 p2 .... pn / push backs are requires. If pattern is of the form p1 p2 .... pn
/* look for patterns of the form p2 p3 ... pn; then p3 p4 ... pn; etc. / look for patterns of the form p2 p3 ... pn; then p3 p4 ... pn; etc.
/* The first such match of the form pi pi+1 ... pn requires an output / The first such match of the form pi pi+1 ... pn requires an output
/* of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi. / of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi.
*/ */
int s,i; int s,i;
struct state *p; struct state *p;
@ -114,15 +112,12 @@ findfail(state,resout,rescpy,resgto)
*resgto = 0; *resgto = 0;
} }
PRIVATE int PRIVATE int leftmatch(struct mnems patt,struct mnems repl,int i,int j)
leftmatch(patt,repl,i,j)
struct mnems patt,repl;
int i,j;
{ {
/* /*
/* Return the first complete match of the mnems <ri,ri+1,..,rj> of / Return the first complete match of the mnems <ri,ri+1,..,rj> of
/* 'repl' in the mnems of 'patt'. Find the leftmost match. / 'repl' in the mnems of 'patt'. Find the leftmost match.
/* Return 0 if fails. / Return 0 if fails.
*/ */
int lenrij = j-i+1; int lenrij = j-i+1;
int lastpos = patt.m_len - lenrij + 1; int lastpos = patt.m_len - lenrij + 1;
@ -139,15 +134,12 @@ leftmatch(patt,repl,i,j)
return(0); return(0);
} }
PRIVATE int PRIVATE int rightmatch(struct mnems patt,struct mnems repl,int i,int j)
rightmatch(patt,repl,i,j)
struct mnems patt,repl;
int i,j;
{ {
/* /*
/* Return the first complete match of the mnems <ri,ri+1,..,rj> of / Return the first complete match of the mnems <ri,ri+1,..,rj> of
/* 'repl' in the mnems of 'patt'. Find the rightmost match. / 'repl' in the mnems of 'patt'. Find the rightmost match.
/* Return 0 if fails. / Return 0 if fails.
*/ */
int lenrij = j-i+1; int lenrij = j-i+1;
int lastpos = patt.m_len - lenrij + 1; int lastpos = patt.m_len - lenrij + 1;

View file

@ -13,9 +13,9 @@ static char rcsidp2[] = "$Id$";
extern char em_flag[]; extern char em_flag[];
extern char em_mnem[][4]; extern char em_mnem[][4];
PRIVATE idinit(); PRIVATE void idinit(char *, int, int);
initlex() void initlex(void)
{ {
register int i,j; register int i,j;
init_idf(); init_idf();
@ -47,11 +47,8 @@ initlex()
} }
} }
PRIVATE
idinit(tag,opcode,argfmt) PRIVATE void idinit(char *tag, int opcode, int argfmt)
char *tag;
int opcode;
int argfmt;
{ {
struct idf *p; struct idf *p;
p = str2idf(tag,0); p = str2idf(tag,0);

View file

@ -3,49 +3,66 @@ BEGIN {
seenproc = 0; seenproc = 0;
CC="${CMD}" CC="${CMD}"
if (prototypes == "") prototypes = "prototypes" if (prototypes == "") prototypes = "prototypes"
print "#include \"nopt.h\""
} }
/^%/ {} /^%/ {}
/^$/ {} /^$/ {}
/^[a-z]/ && $3 !~ /.*NOTIMPLEMENTED.*/ { /^[a-z]/ && $3 !~ /.*NOTIMPLEMENTED.*/ {
if(seenproc) { if(seenproc) {
print "}" print "}"
print "--EOF--"
printf "if %s O_%s.c\n",CC,nam
printf "then :\nelse exit 1\nfi\n"
printf "rm -f O_%s.c\n",nam
} }
seenproc = 1 seenproc = 1
$1 = substr($1,1,index($1,"\t")-1); $1 = substr($1,1,index($1,"\t")-1);
nam = $1 nam = $1
printf "cat > O_%s.c << '--EOF--'\n",$1 print ""
print "#include \"nopt.h\""
printf "void O_%s(",$1 printf "void O_%s(",$1
prototype = "_PROTOTYPE(void O_" $1 ", (" prototype = "_PROTOTYPE(void O_" $1 ", ("
nparms = split($2,parms,":");
for(p=1;p<nparms;p++) { paramstr = $2
if(p!=1) { gsub(/\t/,"",paramstr)
printf "," gsub(/^[ \t]+/,"",paramstr)
} gsub(/[ \t]+$/,"",paramstr)
split(parms[p+1],a," ") gsub(/:([A-Za-z0-9]+[ ])/,"&!",paramstr)
printf a[1]
count = split(paramstr,p2,"!");
paramstr = ""
if (count == 0)
{
printf "void"
paramstr = paramstr "void"
} }
printf ")\n" else
if(nparms > 1) { {
prototype = prototype parms[1] for (i=1;i<=count;i++)
printf "\t%s",parms[1] {
} if (length(p2[i]) > 0)
else { {
prototype = prototype "void" nparms = split(p2[i],params,":");
} if (nparms >0 )
for(p=1;p<nparms;p++) { {
split(parms[p+1],a," ") gsub(/^[ \t]+/,"",params[1])
prototype = prototype " " a[1] gsub(/[ \t]+$/,"",params[1])
printf " %s;\n",a[1] gsub(/^[ \t]+/,"",params[2])
if(a[2]) { gsub(/[ \t]+$/,"",params[2])
prototype = prototype ", " a[2] a[3] a[4]
printf "\t%s%s%s",a[2],a[3],a[4] paramstr = paramstr params[1] " " params[2]
printf "%s %s",params[1],params[2]
if(count!=i)
{
paramstr = paramstr ", "
printf ", "
}
} else
{
printf "void"
paramstr = paramstr "void"
}
}
} }
} }
prototype = prototype paramstr
print ")"
print prototype "));" >> prototypes print prototype "));" >> prototypes
if($3) { if($3) {
printf "{\n\t%s\n",$3 printf "{\n\t%s\n",$3
@ -60,9 +77,6 @@ BEGIN {
END { END {
if(seenproc) { if(seenproc) {
print "}" print "}"
print "--EOF--" print ""
printf "if %s O_%s.c\n",CC,nam
printf "then :\nelse exit 1\nfi\n"
printf "rm -f O_%s.c\n",nam
} }
} }

View file

@ -4,20 +4,16 @@ static char rcsid3[] = "$Id$";
#include "nopt.h" #include "nopt.h"
void void EM_mkop(p, opcode)
EM_mkop(p,opcode) register p_instr p;int opcode;
register p_instr p;
int opcode;
{ {
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_opcode = opcode; p->em_opcode = opcode;
p->em_argtype = 0; p->em_argtype = 0;
} }
void void EM_mknarg(p, opcode)
EM_mknarg(p,opcode) register p_instr p;int opcode;
register p_instr p;
int opcode;
{ {
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_opcode = opcode; p->em_opcode = opcode;
@ -25,11 +21,8 @@ EM_mknarg(p,opcode)
p->em_cst = 0; p->em_cst = 0;
} }
void void EM_mkilb(p, opcode, lab)
EM_mkilb(p,opcode,lab) register p_instr p;int opcode;label lab;
register p_instr p;
int opcode;
label lab;
{ {
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_argtype = ilb_ptyp; p->em_argtype = ilb_ptyp;
@ -37,11 +30,8 @@ EM_mkilb(p,opcode,lab)
p->em_ilb = lab; p->em_ilb = lab;
} }
void void EM_mknof(p, opcode, lab, off)
EM_mknof(p,opcode,lab,off) register p_instr p;int opcode;label lab;
register p_instr p;
int opcode;
label lab;
arith off; arith off;
{ {
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
@ -51,24 +41,19 @@ EM_mknof(p,opcode,lab,off)
p->em_off = off; p->em_off = off;
} }
void void EM_mksof(p, opcode, name, off)
EM_mksof(p,opcode,name,off) register p_instr p;int opcode;char *name;
register p_instr p;
int opcode;
char *name;
arith off; arith off;
{ {
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_argtype = sof_ptyp; p->em_argtype = sof_ptyp;
p->em_opcode = opcode; p->em_opcode = opcode;
p->em_dnam = OO_freestr(name); p->em_dnam = OO_freestr(name);
p->em_off = off; p->em_off = off;
} }
void void EM_mkcst(p, opcode, cst)
EM_mkcst(p,opcode,cst) register p_instr p;int opcode;
register p_instr p;
int opcode;
arith cst; arith cst;
{ {
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
@ -77,11 +62,8 @@ EM_mkcst(p,opcode,cst)
p->em_cst = cst; p->em_cst = cst;
} }
void void EM_mkpro(p, opcode, pnam)
EM_mkpro(p,opcode,pnam) register p_instr p;int opcode;char *pnam;
register p_instr p;
int opcode;
char *pnam;
{ {
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_argtype = pro_ptyp; p->em_argtype = pro_ptyp;
@ -89,11 +71,8 @@ EM_mkpro(p,opcode,pnam)
p->em_pnam = OO_freestr(pnam); p->em_pnam = OO_freestr(pnam);
} }
void void EM_mkdefilb(p, opcode, deflb)
EM_mkdefilb(p,opcode,deflb) register p_instr p;int opcode;label deflb;
register p_instr p;
int opcode;
label deflb;
{ {
p->em_type = EM_DEFILB; p->em_type = EM_DEFILB;
p->em_opcode = opcode; p->em_opcode = opcode;
@ -101,8 +80,7 @@ EM_mkdefilb(p,opcode,deflb)
p->em_ilb = deflb; p->em_ilb = deflb;
} }
void void EM_Nop(opcode)
EM_Nop(opcode)
int opcode; int opcode;
{ {
register p_instr p = GETNXTPATT(); register p_instr p = GETNXTPATT();
@ -111,8 +89,7 @@ EM_Nop(opcode)
p->em_argtype = 0; p->em_argtype = 0;
} }
void void EM_Nnarg(opcode)
EM_Nnarg(opcode)
int opcode; int opcode;
{ {
register p_instr p = GETNXTPATT(); register p_instr p = GETNXTPATT();
@ -122,10 +99,8 @@ EM_Nnarg(opcode)
p->em_cst = 0; p->em_cst = 0;
} }
void void EM_Nilb(opcode, lab)
EM_Nilb(opcode,lab) int opcode;label lab;
int opcode;
label lab;
{ {
register p_instr p = GETNXTPATT(); register p_instr p = GETNXTPATT();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
@ -134,10 +109,8 @@ EM_Nilb(opcode,lab)
p->em_ilb = lab; p->em_ilb = lab;
} }
void void EM_Nnof(opcode, lab, off)
EM_Nnof(opcode,lab,off) int opcode;label lab;
int opcode;
label lab;
arith off; arith off;
{ {
register p_instr p = GETNXTPATT(); register p_instr p = GETNXTPATT();
@ -148,22 +121,19 @@ EM_Nnof(opcode,lab,off)
p->em_off = off; p->em_off = off;
} }
void void EM_Nsof(opcode, name, off)
EM_Nsof(opcode,name,off) int opcode;char *name;
int opcode;
char *name;
arith off; arith off;
{ {
register p_instr p = GETNXTPATT(); register p_instr p = GETNXTPATT();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_argtype = sof_ptyp; p->em_argtype = sof_ptyp;
p->em_opcode = opcode; p->em_opcode = opcode;
p->em_dnam = OO_freestr(name); p->em_dnam = OO_freestr(name);
p->em_off = off; p->em_off = off;
} }
void void EM_Ncst(opcode, cst)
EM_Ncst(opcode,cst)
int opcode; int opcode;
arith cst; arith cst;
{ {
@ -174,10 +144,8 @@ EM_Ncst(opcode,cst)
p->em_cst = cst; p->em_cst = cst;
} }
void void EM_Npro(opcode, pnam)
EM_Npro(opcode,pnam) int opcode;char *pnam;
int opcode;
char *pnam;
{ {
register p_instr p = GETNXTPATT(); register p_instr p = GETNXTPATT();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
@ -186,10 +154,8 @@ EM_Npro(opcode,pnam)
p->em_pnam = OO_freestr(pnam); p->em_pnam = OO_freestr(pnam);
} }
void void EM_Ndefilb(opcode, deflb)
EM_Ndefilb(opcode,deflb) int opcode;label deflb;
int opcode;
label deflb;
{ {
register p_instr p = GETNXTPATT(); register p_instr p = GETNXTPATT();
p->em_type = EM_DEFILB; p->em_type = EM_DEFILB;
@ -198,8 +164,7 @@ EM_Ndefilb(opcode,deflb)
p->em_ilb = deflb; p->em_ilb = deflb;
} }
void void EM_Rop(opcode)
EM_Rop(opcode)
int opcode; int opcode;
{ {
register p_instr p = GETNXTREPL(); register p_instr p = GETNXTREPL();
@ -208,8 +173,7 @@ EM_Rop(opcode)
p->em_argtype = 0; p->em_argtype = 0;
} }
void void EM_Rnarg(opcode)
EM_Rnarg(opcode)
int opcode; int opcode;
{ {
register p_instr p = GETNXTREPL(); register p_instr p = GETNXTREPL();
@ -219,10 +183,8 @@ EM_Rnarg(opcode)
p->em_cst = 0; p->em_cst = 0;
} }
void void EM_Rilb(opcode, lab)
EM_Rilb(opcode,lab) int opcode;label lab;
int opcode;
label lab;
{ {
register p_instr p = GETNXTREPL(); register p_instr p = GETNXTREPL();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
@ -231,10 +193,8 @@ EM_Rilb(opcode,lab)
p->em_ilb = lab; p->em_ilb = lab;
} }
void void EM_Rnof(opcode, lab, off)
EM_Rnof(opcode,lab,off) int opcode;label lab;
int opcode;
label lab;
arith off; arith off;
{ {
register p_instr p = GETNXTREPL(); register p_instr p = GETNXTREPL();
@ -245,22 +205,19 @@ EM_Rnof(opcode,lab,off)
p->em_off = off; p->em_off = off;
} }
void void EM_Rsof(opcode, name, off)
EM_Rsof(opcode,name,off) int opcode;char *name;
int opcode;
char *name;
arith off; arith off;
{ {
register p_instr p = GETNXTREPL(); register p_instr p = GETNXTREPL();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_argtype = sof_ptyp; p->em_argtype = sof_ptyp;
p->em_opcode = opcode; p->em_opcode = opcode;
p->em_dnam = OO_freestr(name); p->em_dnam = OO_freestr(name);
p->em_off = off; p->em_off = off;
} }
void void EM_Rcst(opcode, cst)
EM_Rcst(opcode,cst)
int opcode; int opcode;
arith cst; arith cst;
{ {
@ -271,10 +228,8 @@ EM_Rcst(opcode,cst)
p->em_cst = cst; p->em_cst = cst;
} }
void void EM_Rpro(opcode, pnam)
EM_Rpro(opcode,pnam) int opcode;char *pnam;
int opcode;
char *pnam;
{ {
register p_instr p = GETNXTREPL(); register p_instr p = GETNXTREPL();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
@ -283,10 +238,8 @@ EM_Rpro(opcode,pnam)
p->em_pnam = OO_freestr(pnam); p->em_pnam = OO_freestr(pnam);
} }
void void EM_Rdefilb(opcode, deflb)
EM_Rdefilb(opcode,deflb) int opcode;label deflb;
int opcode;
label deflb;
{ {
register p_instr p = GETNXTREPL(); register p_instr p = GETNXTREPL();
p->em_type = EM_DEFILB; p->em_type = EM_DEFILB;

View file

@ -4,36 +4,36 @@ static char rcsid2[] = "$Id$";
#include "nopt.h" #include "nopt.h"
extern struct dfa OO_checknext[]; /* Initialized in dfa.c */ extern struct dfa OO_checknext[]; /* Initialized in dfa.c */
extern struct dfa *OO_base[]; /* Initialized in dfa.c */ extern struct dfa *OO_base[]; /* Initialized in dfa.c */
extern struct dodefault OO_default[]; /* Initialized in dfa.c */ extern struct dodefault OO_default[]; /* Initialized in dfa.c */
extern int OO_maxpattern; /* Initialized in dfa.c */ extern int OO_maxpattern; /* Initialized in dfa.c */
extern int OO_maxreplacement; /* Initialized in dfa.c */ extern int OO_maxreplacement; /* Initialized in dfa.c */
extern int (*OO_ftrans[])(); /* Initialized in trans.c */ extern int (*OO_ftrans[])(); /* Initialized in trans.c */
extern char em_mnem[][4]; extern char em_mnem[][4];
extern char em_pseu[][4]; extern char em_pseu[][4];
int OO_state = 0; int OO_state = 0;
p_instr OO_buffer; p_instr OO_buffer;
p_instr OO_patternqueue; p_instr OO_patternqueue;
p_instr OO_nxtpatt; p_instr OO_nxtpatt;
p_instr OO_endbackup; p_instr OO_endbackup;
p_instr OO_nxtrepl; p_instr OO_nxtrepl;
static p_instr OO_replqueue; static p_instr OO_replqueue;
static char *filename; static char *filename;
static char *strqueue; static char *strqueue;
static char *nextstr; static char *nextstr;
static char *laststr; static char *laststr;
arith OO_WSIZE; /* wordlength */ arith OO_WSIZE; /* wordlength */
arith OO_DWSIZE; /* 2*wordlength */ arith OO_DWSIZE; /* 2*wordlength */
arith OO_PSIZE; /* pointer length */ arith OO_PSIZE; /* pointer length */
#ifdef STATS #ifdef STATS
int OO_wrstats = 1; /* pattern statistics output */ int OO_wrstats = 1; /* pattern statistics output */
#endif #endif
#ifdef DEBUG #ifdef DEBUG
#define printstate(s) dumpstate(s) #define printstate(s) dumpstate(s)
@ -42,108 +42,103 @@ int OO_wrstats = 1; /* pattern statistics output */
#endif /* DEBUG */ #endif /* DEBUG */
/**** WHICH IS FASTER? **** /**** WHICH IS FASTER? ****
#define BTSCPY(pp,qq,i,p,q,n) btscpy(p,q,(n)*sizeof(struct e_instr)) #define BTSCPY(pp,qq,i,p,q,n) btscpy(p,q,(n)*sizeof(struct e_instr))
**************************/ **************************/
#define BTSCPY(pp,qq,i,p,q,n) for(pp=(p),qq=(q),i=(n);i--;*pp++ = *qq++) #define BTSCPY(pp,qq,i,p,q,n) for(pp=(p),qq=(q),i=(n);i--;*pp++ = *qq++)
PRIVATE void allocmem(); PRIVATE void allocmem(void);
void void O_init(arith wsize, arith psize)
O_init(wsize,psize)
arith wsize, psize;
{ {
allocmem(); allocmem();
C_init(wsize,psize); C_init(wsize, psize);
OO_WSIZE = wsize; OO_WSIZE = wsize;
OO_DWSIZE = 2*wsize; OO_DWSIZE = 2 * wsize;
OO_PSIZE = psize; OO_PSIZE = psize;
} }
int int O_open(char *fname)
O_open(fname)
char *fname;
{ {
filename = fname; filename = fname;
return(C_open(fname)); return (C_open(fname));
} }
void void O_magic(void)
O_magic()
{ {
C_magic(); C_magic();
} }
void void O_close(void)
O_close()
{ {
C_close(); C_close();
} }
void void OO_dfa(register int last)
OO_dfa(last)
register int last;
{ {
register struct dfa *b; register struct dfa *b;
register struct dodefault *d; register struct dodefault *d;
register int (*f)(); register int (*f)();
for(;;) { for (;;)
{
printstate("OO_dfa"); printstate("OO_dfa");
if((b=OO_base[OO_state]) && ((b += last)->check==OO_state)) { if ((b = OO_base[OO_state]) && ((b += last)->check == OO_state))
if(f=OO_ftrans[OO_state = b->next]) (*f)(); {
if ((f = OO_ftrans[OO_state = b->next]))
(*f)();
} }
else if (OO_state) { else if (OO_state)
{
/* consult default entry */ /* consult default entry */
d = &OO_default[OO_state]; d = &OO_default[OO_state];
if(!OO_endbackup) OO_endbackup = OO_nxtpatt; if (!OO_endbackup)
OO_endbackup = OO_nxtpatt;
OO_nxtpatt--; OO_nxtpatt--;
OO_patternqueue += d->numout; OO_patternqueue += d->numout;
if(f=OO_ftrans[OO_state = d->next]) (*f)(); if ((f = OO_ftrans[OO_state = d->next]))
(*f)();
} }
else OO_flush(); else
if (!OO_endbackup) return; OO_flush();
if (!OO_endbackup)
return;
last = (OO_nxtpatt++)->em_opcode; last = (OO_nxtpatt++)->em_opcode;
if (OO_nxtpatt >= OO_endbackup) if (OO_nxtpatt >= OO_endbackup)
OO_endbackup = 0; OO_endbackup = 0;
} }
} }
PRIVATE void PRIVATE void fatal(s, a)
fatal(s,a) char *s;int a;
char *s;
int a;
{ {
fprint(STDERR, "%s: ", filename ? filename : "standard input"); fprint(STDERR, "%s: ", filename ? filename : "standard input");
fprint(STDERR,s,a); fprint(STDERR, s, a);
fprint(STDERR,"\n"); fprint(STDERR, "\n");
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
PRIVATE void PRIVATE void allocmem(void)
allocmem()
{ {
/* Allocate memory for queues on heap */ /* Allocate memory for queues on heap */
OO_buffer = (p_instr) OO_buffer = (p_instr) Malloc(
Malloc((unsigned)(MAXBUFFER*sizeof(struct e_instr))); (unsigned) (MAXBUFFER * sizeof(struct e_instr)));
OO_patternqueue = OO_nxtpatt = OO_buffer; OO_patternqueue = OO_nxtpatt = OO_buffer;
OO_replqueue = (p_instr) OO_replqueue = (p_instr) Malloc(
Malloc((unsigned)OO_maxreplacement*sizeof(struct e_instr)); (unsigned) OO_maxreplacement * sizeof(struct e_instr));
OO_nxtrepl = OO_replqueue; OO_nxtrepl = OO_replqueue;
nextstr = strqueue = nextstr = strqueue = (char *) Malloc(MAXSTRING * sizeof(char));
(char *)Malloc(MAXSTRING*sizeof(char));
laststr = strqueue + MAXSTRING - 1; laststr = strqueue + MAXSTRING - 1;
} }
char * char * OO_freestr(char *str)
OO_freestr(str)
char *str;
{ {
register char *s = str; register char *s = str;
register char *res; register char *res;
while (*s++); while (*s++)
again: ;
if ((s-str) > (laststr-nextstr)) { again: if ((s - str) > (laststr - nextstr))
unsigned newsize = (laststr - strqueue + 1)*2; {
res = Realloc(strqueue,newsize); unsigned newsize = (laststr - strqueue + 1) * 2;
res = Realloc(strqueue, newsize);
laststr = res + newsize - 1; laststr = res + newsize - 1;
nextstr = res + (nextstr - strqueue); nextstr = res + (nextstr - strqueue);
strqueue = res; strqueue = res;
@ -153,201 +148,202 @@ OO_freestr(str)
#endif #endif
goto again; goto again;
} }
res=nextstr; res = nextstr;
for(s=str;*nextstr++ = *s++;); for (s = str; (*nextstr++ = *s++);)
return(res); ;
return (res);
} }
void void OO_flush(void)
OO_flush()
{ {
/* /*
/* Output all instructions waiting in the output queue and free their Output all instructions waiting in the output queue and free their
/* storage including the saved strings. storage including the saved strings.
*/ */
register p_instr p,q; register p_instr p, q;
register int i,n; register int i, n;
printstate("Flush"); printstate("Flush");
for(p=OO_buffer;p<OO_patternqueue;p++) for (p = OO_buffer; p < OO_patternqueue; p++)
C_out(p); C_out(p);
if(p->em_opcode!=OTHER) if (p->em_opcode != OTHER)
C_out(p); C_out(p);
if(OO_endbackup) { if (OO_endbackup)
n = OO_endbackup-OO_nxtpatt; {
BTSCPY(p,q,i,OO_buffer,OO_nxtpatt,n); n = OO_endbackup - OO_nxtpatt;
BTSCPY(p, q, i, OO_buffer, OO_nxtpatt, n);
OO_endbackup = OO_buffer + n; OO_endbackup = OO_buffer + n;
} }
else nextstr = strqueue; else
nextstr = strqueue;
OO_patternqueue = OO_nxtpatt = OO_buffer; OO_patternqueue = OO_nxtpatt = OO_buffer;
} }
p_instr p_instr OO_halfflush(void)
OO_halfflush()
{ {
/* /*
/* Called when buffer full, flush half the buffer and move the Called when buffer full, flush half the buffer and move the
/* the pattern pointers to the new positions. Return a pointer the pattern pointers to the new positions. Return a pointer
/* to the new nxtpatt position and increment it. to the new nxtpatt position and increment it.
/* Note that OO_endbackup is always NIL (i.e. there are no Note that OO_endbackup is always NIL (i.e. there are no
/* instructions on the backup queue) when this is invoked. instructions on the backup queue) when this is invoked.
*/ */
register int i,n; register int i, n;
register p_instr p,q; register p_instr p, q;
printstate("Half flush"); printstate("Half flush");
n = MAXBUFFER / 2; n = MAXBUFFER / 2;
for(p=OO_buffer,i=n;i--;) for (p = OO_buffer, i = n; i--;)
C_out(p++); C_out(p++);
/* now copy the rest of buffer and pattern back */ /* now copy the rest of buffer and pattern back */
BTSCPY(p,q,i,OO_buffer,OO_buffer+n,(OO_nxtpatt-OO_buffer)-n); BTSCPY(p, q, i, OO_buffer, OO_buffer + n, (OO_nxtpatt - OO_buffer) - n);
OO_patternqueue -= n; OO_patternqueue -= n;
OO_nxtpatt -= n; OO_nxtpatt -= n;
printstate("after Half flush"); printstate("after Half flush");
return (OO_nxtpatt++); return (OO_nxtpatt++);
} }
void void OO_mkext(register p_instr p, int opcode, p_instr arg, arith off)
OO_mkext(p,opcode,arg,off)
register p_instr p;
int opcode;
p_instr arg;
arith off;
{ {
switch(arg->em_argtype) { switch (arg->em_argtype)
case cst_ptyp: {
EM_mkcst(p,opcode,off); case cst_ptyp:
break; EM_mkcst(p, opcode, off);
case sof_ptyp: break;
EM_mksof(p,opcode,arg->em_dnam,off); case sof_ptyp:
break; EM_mksof(p, opcode, arg->em_dnam, off);
case nof_ptyp: break;
EM_mknof(p,opcode,arg->em_dlb,off); case nof_ptyp:
break; EM_mknof(p, opcode, arg->em_dlb, off);
default: break;
fatal("Unexpected type %d in outext",arg->em_argtype); default:
fatal("Unexpected type %d in outext", arg->em_argtype);
} }
} }
void void OO_mkrepl(int lrepl, int diff, int numbkup)
OO_mkrepl(lrepl,diff,numbkup)
int lrepl,diff,numbkup;
{ {
/* copy the replacement queue into the buffer queue */ /* copy the replacement queue into the buffer queue */
/* then move the pattern queue back n places */ /* then move the pattern queue back n places */
register p_instr p,q; register p_instr p, q;
register int i; register int i;
printstate("Before backup"); printstate("Before backup");
if(OO_endbackup) { if (OO_endbackup)
{
/* move the region between OO_nxtpatt and OO_endbackup */ /* move the region between OO_nxtpatt and OO_endbackup */
if (diff > 0) { if (diff > 0)
{
/* move left by diff */ /* move left by diff */
BTSCPY(p,q,i,OO_nxtpatt-diff,OO_nxtpatt,OO_endbackup-OO_nxtpatt); BTSCPY(p, q, i, OO_nxtpatt - diff, OO_nxtpatt,
OO_endbackup - OO_nxtpatt);
OO_nxtpatt -= diff; OO_nxtpatt -= diff;
OO_endbackup -= diff; OO_endbackup -= diff;
} }
else if (diff < 0) { else if (diff < 0)
{
/* move right by diff */ /* move right by diff */
/* careful of overflowing buffer!! */ /* careful of overflowing buffer!! */
if ((OO_nxtpatt-diff)> (OO_buffer+MAXBUFFER) ) if ((OO_nxtpatt - diff) > (OO_buffer + MAXBUFFER))
OO_halfflush(); OO_halfflush();
/* cannot use btscpy as strings may overlap */ /* cannot use btscpy as strings may overlap */
p = (q=OO_endbackup-1) - diff; p = (q = OO_endbackup - 1) - diff;
while(q>=OO_nxtpatt) while (q >= OO_nxtpatt)
*p-- = *q--; *p-- = *q--;
OO_nxtpatt -= diff; OO_nxtpatt -= diff;
OO_endbackup -= diff; OO_endbackup -= diff;
} }
} }
/* copy the replacement */ /* copy the replacement */
if (lrepl) { if (lrepl)
BTSCPY(p,q,i,OO_patternqueue,OO_replqueue,lrepl); {
BTSCPY(p, q, i, OO_patternqueue, OO_replqueue, lrepl);
OO_nxtrepl = OO_replqueue; OO_nxtrepl = OO_replqueue;
OO_patternqueue += lrepl; OO_patternqueue += lrepl;
} }
/* now move the position of interest back nunbkup instructions */ /* now move the position of interest back nunbkup instructions */
if ((OO_patternqueue-OO_buffer) < numbkup) if ((OO_patternqueue - OO_buffer) < numbkup)
numbkup = (OO_patternqueue-OO_buffer); numbkup = (OO_patternqueue - OO_buffer);
OO_nxtpatt = OO_patternqueue -= numbkup; OO_nxtpatt = OO_patternqueue -= numbkup;
if(!OO_endbackup && numbkup) if (!OO_endbackup && numbkup)
OO_endbackup = OO_patternqueue+numbkup; OO_endbackup = OO_patternqueue + numbkup;
OO_state = 0; OO_state = 0;
printstate("After backup"); printstate("After backup");
} }
#ifdef DEBUG #ifdef DEBUG
void void
dumpstate(mess) dumpstate(char *mess)
char *mess;
{ {
p_instr p; p_instr p;
fprintf(stderr,"%s - state(%d): ",mess,OO_state); fprintf(stderr,"%s - state(%d): ",mess,OO_state);
p = OO_buffer; p = OO_buffer;
while(p<OO_patternqueue) while(p<OO_patternqueue)
prtinst(p++); prtinst(p++);
fprintf(stderr," |==| "); fprintf(stderr," |==| ");
while(p<OO_nxtpatt) while(p<OO_nxtpatt)
prtinst(p++); prtinst(p++);
fprintf(stderr," |==| "); fprintf(stderr," |==| ");
if(OO_endbackup) { if(OO_endbackup)
{
while(p<OO_endbackup) while(p<OO_endbackup)
prtinst(p++); prtinst(p++);
} }
fprintf(stderr,"\n"); fprintf(stderr,"\n");
} }
void void
prtinst(p) prtinst(p_instr p)
p_instr p;
{ {
switch(p->em_type) { switch(p->em_type)
case EM_MNEM: {
case EM_MNEM:
fprintf(stderr,"%s ",em_mnem[p->em_opcode-sp_fmnem]); fprintf(stderr,"%s ",em_mnem[p->em_opcode-sp_fmnem]);
break; break;
case EM_PSEU: case EM_PSEU:
fprintf(stderr,"%s ",em_pseu[p->em_opcode-sp_fpseu]); fprintf(stderr,"%s ",em_pseu[p->em_opcode-sp_fpseu]);
break; break;
case EM_STARTMES: case EM_STARTMES:
case EM_MESARG: case EM_MESARG:
case EM_ENDMES: case EM_ENDMES:
fprintf(stderr,"MES "); fprintf(stderr,"MES ");
break; break;
case EM_DEFILB: case EM_DEFILB:
fprintf(stderr,"%ld ", (long)p->em_ilb); fprintf(stderr,"%ld ", (long)p->em_ilb);
return; return;
case EM_DEFDLB: case EM_DEFDLB:
fprintf(stderr,"%ld ", (long)p->em_dlb); fprintf(stderr,"%ld ", (long)p->em_dlb);
return; return;
case EM_DEFDNAM: case EM_DEFDNAM:
fprintf(stderr,"%d ", p->em_dnam); fprintf(stderr,"%d ", p->em_dnam);
return; return;
case EM_ERROR: case EM_ERROR:
case EM_FATAL: case EM_FATAL:
case EM_EOF: case EM_EOF:
return; return;
} }
switch(p->em_argtype) { switch(p->em_argtype)
case 0: {
case 0:
break; break;
case cst_ptyp: case cst_ptyp:
fprintf(stderr,"%d ",p->em_cst); fprintf(stderr,"%d ",p->em_cst);
break; break;
case nof_ptyp: case nof_ptyp:
fprintf(stderr,".%d+%d ",p->em_dlb,p->em_off); fprintf(stderr,".%d+%d ",p->em_dlb,p->em_off);
break; break;
case sof_ptyp: case sof_ptyp:
fprintf(stderr,"%s+%d ",p->em_dnam,p->em_off); fprintf(stderr,"%s+%d ",p->em_dnam,p->em_off);
break; break;
case ilb_ptyp: case ilb_ptyp:
fprintf(stderr,"*%d ",p->em_ilb); fprintf(stderr,"*%d ",p->em_ilb);
break; break;
case pro_ptyp: case pro_ptyp:
fprintf(stderr,"$%s ",p->em_pnam); fprintf(stderr,"$%s ",p->em_pnam);
break; break;
case str_ptyp: case str_ptyp:
case ico_ptyp: case ico_ptyp:
case uco_ptyp: case uco_ptyp:
fprintf(stderr,"\"%s\"",p->em_string); fprintf(stderr,"\"%s\"",p->em_string);
break; break;
default: default:
fatal(" prtinst - Unregognized arg %d ",p->em_argtype); fatal(" prtinst - Unregognized arg %d ",p->em_argtype);
} }
} }

View file

@ -4,108 +4,128 @@ static char rcsidp4[] = "$Id$";
#include "parser.h" #include "parser.h"
outputincalls() void outputincalls(void)
{ {
struct idf *op; struct idf *op;
char *s; char *s;
for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { for (op = ops; op != (struct idf *) NULL; op = op->id_nextidf)
{
s = op->id_text; s = op->id_text;
switch(op->id_argfmt) { switch (op->id_argfmt)
case NOARG: {
fprintf(ofile,"%s\t|\t|\n",s); case NOARG:
if(op->id_used) { fprintf(ofile, "%s\t|\t|\n", s);
fprintf(ofile,"\tEM_Nop(op_%s);\n",s); if (op->id_used)
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); {
} fprintf(ofile, "\tEM_Nop(op_%s);\n", s);
else { fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
fprintf(ofile,"\tFLUSHDFA();\n"); }
fprintf(ofile,"\tC_%s();\n",s); else
} {
break; fprintf(ofile, "\tFLUSHDFA();\n");
case CSTOPT: fprintf(ofile, "\tC_%s();\n", s);
fprintf(ofile,"%s_narg\t|\t|\n",s); }
if(op->id_used) { break;
fprintf(ofile,"\tEM_Nnarg(op_%s);\n",s); case CSTOPT:
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile, "%s_narg\t|\t|\n", s);
} if (op->id_used)
else { {
fprintf(ofile,"\tFLUSHDFA();\n"); fprintf(ofile, "\tEM_Nnarg(op_%s);\n", s);
fprintf(ofile,"\tC_%s_narg();\n",s); fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
} }
/* fall thru */ else
case CST: {
fprintf(ofile,"%s\t| arith:n\t|\n",s); fprintf(ofile, "\tFLUSHDFA();\n");
if(op->id_used) { fprintf(ofile, "\tC_%s_narg();\n", s);
fprintf(ofile,"\tEM_Ncst(op_%s,n);\n",s); }
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); /* fall thru */
} case CST:
else { fprintf(ofile, "%s\t| arith:n\t|\n", s);
fprintf(ofile,"\tFLUSHDFA();\n"); if (op->id_used)
fprintf(ofile,"\tC_%s(n);\n",s); {
} fprintf(ofile, "\tEM_Ncst(op_%s,n);\n", s);
break; fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
case DEFILB: }
fprintf(ofile,"df_ilb\t| label:l\t|\n"); else
if(op->id_used) { {
fprintf(ofile,"\tEM_Ndefilb(op_%s,l);\n",s); fprintf(ofile, "\tFLUSHDFA();\n");
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile, "\tC_%s(n);\n", s);
} }
else { break;
fprintf(ofile,"\tFLUSHDFA();\n"); case DEFILB:
fprintf(ofile,"\tC_df_ilb(l);\n",s); fprintf(ofile, "df_ilb\t| label:l\t|\n");
} if (op->id_used)
break; {
case PNAM: fprintf(ofile, "\tEM_Ndefilb(op_%s,l);\n", s);
fprintf(ofile,"%s\t| char *:s\t|\n",s); fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
if(op->id_used) { }
fprintf(ofile,"\tEM_Npro(op_%s,s);\n",s); else
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); {
} fprintf(ofile, "\tFLUSHDFA();\n");
else { fprintf(ofile, "\tC_df_ilb(l);\n", s);
fprintf(ofile,"\tFLUSHDFA();\n"); }
fprintf(ofile,"\tC_%s(s);\n",s); break;
} case PNAM:
break; fprintf(ofile, "%s\t| char *:s\t|\n", s);
case LAB: if (op->id_used)
fprintf(ofile,"%s\t| label:l\t|\n",s); {
if(op->id_used) { fprintf(ofile, "\tEM_Npro(op_%s,s);\n", s);
fprintf(ofile,"\tEM_Nilb(op_%s,l);\n",s); fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); }
} else
else { {
fprintf(ofile,"\tFLUSHDFA();\n"); fprintf(ofile, "\tFLUSHDFA();\n");
fprintf(ofile,"\tC_%s(l);\n",s); fprintf(ofile, "\tC_%s(s);\n", s);
} }
break; break;
case EXT: case LAB:
fprintf(ofile,"%s\t| arith:n\t|\n",s); fprintf(ofile, "%s\t| label:l\t|\n", s);
if(op->id_used) { if (op->id_used)
fprintf(ofile,"\tEM_Ncst(op_%s,n);\n",s); {
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile, "\tEM_Nilb(op_%s,l);\n", s);
} fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
else { }
fprintf(ofile,"\tFLUSHDFA();\n"); else
fprintf(ofile,"\tC_%s(n);\n",s); {
} fprintf(ofile, "\tFLUSHDFA();\n");
fprintf(ofile,"%s_dnam\t| char *:s arith:n\t|\n",s); fprintf(ofile, "\tC_%s(l);\n", s);
if(op->id_used) { }
fprintf(ofile,"\tEM_Nsof(op_%s,s,n);\n",s); break;
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); case EXT:
} fprintf(ofile, "%s\t| arith:n\t|\n", s);
else { if (op->id_used)
fprintf(ofile,"\tFLUSHDFA();\n"); {
fprintf(ofile,"\tC_%s_dnam(s,n);\n",s); fprintf(ofile, "\tEM_Ncst(op_%s,n);\n", s);
} fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
fprintf(ofile,"%s_dlb\t| label:l arith:n\t|\n",s); }
if(op->id_used) { else
fprintf(ofile,"\tEM_Nnof(op_%s,l,n);\n",s); {
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile, "\tFLUSHDFA();\n");
} fprintf(ofile, "\tC_%s(n);\n", s);
else { }
fprintf(ofile,"\tFLUSHDFA();\n"); fprintf(ofile, "%s_dnam\t| char *:s arith:n\t|\n", s);
fprintf(ofile,"\tC_%s_dlb(l,n);\n",s); if (op->id_used)
} {
break; fprintf(ofile, "\tEM_Nsof(op_%s,s,n);\n", s);
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
}
else
{
fprintf(ofile, "\tFLUSHDFA();\n");
fprintf(ofile, "\tC_%s_dnam(s,n);\n", s);
}
fprintf(ofile, "%s_dlb\t| label:l arith:n\t|\n", s);
if (op->id_used)
{
fprintf(ofile, "\tEM_Nnof(op_%s,l,n);\n", s);
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
}
else
{
fprintf(ofile, "\tFLUSHDFA();\n");
fprintf(ofile, "\tC_%s_dlb(l,n);\n", s);
}
break;
} }
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,7 @@ static char rcsidp1[] = "$Id$";
#endif #endif
#include "parser.h" #include "parser.h"
#include "alloc.h"
#define MAXPRIO 11 #define MAXPRIO 11
@ -33,6 +34,20 @@ int nerrors = 0;
static int lencurrpatt; static int lencurrpatt;
static int lenthisrepl; static int lenthisrepl;
static int currentstate; /* Current state of dfa */ static int currentstate; /* Current state of dfa */
extern void back_token(void);
extern void parser(void);
/* Forward declarations */
void addaction(int, int, struct exp_node *,struct exp_node *,
struct mnem_list *);
struct mnem_elem **constructlist(struct mnem_list *, int);
struct mnem_list *addelem(struct mnem_list *, struct idf *,
struct exp_node *);
int dotransition(int, struct idf *, struct mnem_list *, int);
int priority(int);
void LLmessage(int);
} }
input : /* empty */ input : /* empty */
@ -326,11 +341,8 @@ binop : LOGAND
%lexical yylex; %lexical yylex;
{ {
addaction(startline, state, restrictions, finaltest, repllist) void addaction(int startline, int state, struct exp_node *restrictions,
int startline; struct exp_node *finaltest, struct mnem_list *repllist)
int state;
struct exp_node *restrictions, *finaltest;
struct mnem_list *repllist;
{ {
struct action *p, *q; struct action *p, *q;
p=(struct action *)Malloc(sizeof(struct action)); p=(struct action *)Malloc(sizeof(struct action));
@ -349,10 +361,7 @@ addaction(startline, state, restrictions, finaltest, repllist)
} }
} }
struct mnem_elem ** struct mnem_elem **constructlist(struct mnem_list *list, int len)
constructlist(list,len)
struct mnem_list *list;
int len;
{ {
struct mnem_elem **p; struct mnem_elem **p;
p = (struct mnem_elem **) p = (struct mnem_elem **)
@ -364,11 +373,9 @@ constructlist(list,len)
return(p); return(p);
} }
struct mnem_list * struct mnem_list *addelem(struct mnem_list *oldlist,
addelem(oldlist, mnem, test) struct idf *mnem,
struct mnem_list *oldlist; struct exp_node *test)
struct idf *mnem;
struct exp_node *test;
{ {
struct mnem_list *reslist; struct mnem_list *reslist;
struct mnem_elem *element; struct mnem_elem *element;
@ -381,12 +388,11 @@ addelem(oldlist, mnem, test)
return(reslist); return(reslist);
} }
int int dotransition(
dotransition(state, mnem, mnem_list, lenlist) int state,
int state; struct idf *mnem,
struct idf *mnem; struct mnem_list *mnem_list,
struct mnem_list *mnem_list; int lenlist)
int lenlist;
{ {
struct state *p; struct state *p;
/* look for existing transition */ /* look for existing transition */
@ -399,7 +405,7 @@ dotransition(state, mnem, mnem_list, lenlist)
p=(struct state *)Malloc(sizeof(struct state)); p=(struct state *)Malloc(sizeof(struct state));
p->op=mnem; p->op=mnem;
if(++higheststate>MAXSTATES) { if(++higheststate>MAXSTATES) {
fprintf(stderr,"Parser: More than %s states\n",MAXSTATES); fprintf(stderr,"Parser: More than %d states\n",MAXSTATES);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
p->goto_state= higheststate; p->goto_state= higheststate;
@ -427,7 +433,7 @@ combinetests(test1, test2)
return(mknode(LOGAND,test1,test2)); return(mknode(LOGAND,test1,test2));
} }
priority(op) int op; { int priority(int op) {
switch (op) { switch (op) {
case LOGOR: return(1); case LOGOR: return(1);
case LOGAND: return(2); case LOGAND: return(2);
@ -456,10 +462,8 @@ priority(op) int op; {
return(0); return(0);
} }
struct exp_node * struct exp_node *mknode(int op, struct exp_node *left,
mknode(op,left,right) struct exp_node *right)
int op;
struct exp_node *left,*right;
{ {
struct exp_node *p; struct exp_node *p;
p = (struct exp_node *)Malloc(sizeof(struct exp_node)); p = (struct exp_node *)Malloc(sizeof(struct exp_node));
@ -469,9 +473,7 @@ mknode(op,left,right)
return(p); return(p);
} }
struct exp_node * struct exp_node *mkleaf(int op, int val)
mkleaf(op,val)
int op,val;
{ {
struct exp_node *p; struct exp_node *p;
p = (struct exp_node *)Malloc(sizeof(struct exp_node)); p = (struct exp_node *)Malloc(sizeof(struct exp_node));
@ -480,8 +482,7 @@ mkleaf(op,val)
return(p); return(p);
} }
LLmessage(insertedtok) void LLmessage(int insertedtok)
int insertedtok;
{ {
nerrors++; nerrors++;
fprintf(stderr,"parser: syntax error on line %d: ",linenum); fprintf(stderr,"parser: syntax error on line %d: ",linenum);
@ -492,7 +493,8 @@ LLmessage(insertedtok)
else fprintf(stderr,"Deleted token %d\n",LLsymb); else fprintf(stderr,"Deleted token %d\n",LLsymb);
} }
main() { int main(int argc, char **argv)
{
initlex(); initlex();
states[0] = (struct state *)NULL; states[0] = (struct state *)NULL;
patterns[0].m_len = 0; patterns[0].m_len = 0;

View file

@ -1,4 +1,7 @@
/* $Id$ */ /* $Id$ */
#ifndef PARSER_H_
#define PARSER_H_
#include <stdio.h> #include <stdio.h>
#include <system.h> #include <system.h>
@ -88,10 +91,17 @@ extern struct idf *opval; /* opcode of returned OPCODE*/
extern int lastintval; /* value of last integer seen */ extern int lastintval; /* value of last integer seen */
extern int linenum; /*line number of input file*/ extern int linenum; /*line number of input file*/
/* Functions not returning int */ struct exp_node *mknode(int, struct exp_node *, struct exp_node *);
char *Malloc(); struct exp_node *mkleaf(int, int);
struct exp_node *mknode(); struct exp_node *combinetests(struct exp_node *, struct exp_node *);
struct exp_node *mkleaf(); struct mnem_list *addelem(struct mnem_list *, struct idf *, struct exp_node *);
struct exp_node *combinetests(); struct mnem_elem **constructlist(struct mnem_list *, int);
struct mnem_list *addelem(); void findworst(struct mnems,struct mnems);
struct mnem_elem **constructlist();
void outputincalls(void);
void outputnopt(void);
void initlex(void);
void findfail(int, int *, int *, int *);
#endif /* PARSER_H_ */

View file

@ -3,6 +3,7 @@
#include "Lpars.h" #include "Lpars.h"
#include "parser.h" #include "parser.h"
struct idf *opval; /* opcode of returned OPCODE*/ struct idf *opval; /* opcode of returned OPCODE*/
int lastintval; /* value of last integer seen */ int lastintval; /* value of last integer seen */
int linenum = 1; /*current line number of input file*/ int linenum = 1; /*current line number of input file*/
@ -59,7 +60,12 @@ offset return(OFFSET);
. return(yytext[0]); . return(yytext[0]);
%% %%
back_token() int yywrap(void)
{
return 1;
}
void back_token(void)
{ {
yyless(0); yyless(0);
} }

View file

@ -2,97 +2,88 @@
static char rcsid4[] = "$Id$"; static char rcsid4[] = "$Id$";
#endif #endif
#include <string.h>
#include "nopt.h" #include "nopt.h"
arith arith OO_rotate(arith w, arith amount)
OO_rotate(w,amount)
arith w, amount;
{ {
long highmask, lowmask; long highmask, lowmask;
highmask = (long)(-1) << amount; highmask = (long) (-1) << amount;
lowmask = ~highmask; lowmask = ~highmask;
if(OO_WSIZE!=4) if (OO_WSIZE != 4)
highmask &= (OO_WSIZE==2)?0xFFFF:0xFF; highmask &= (OO_WSIZE == 2) ? 0xFFFF : 0xFF;
return(((w<<amount)&highmask) | ((w >> (8*OO_WSIZE-amount))&lowmask)); return (((w << amount) & highmask)
| ((w >> (8 * OO_WSIZE - amount)) & lowmask));
} }
int int OO_signsame(arith a, arith b)
OO_signsame(a,b)
arith a, b;
{ {
return( (a ^ b) >= 0); return ((a ^ b) >= 0);
} }
int int OO_sfit(arith val, arith nbits)
OO_sfit(val,nbits)
arith val, nbits;
{ {
register long mask = ~((1L << (nbits - 1)) - 1); register long mask = ~((1L << (nbits - 1)) - 1);
return(((val&mask) == 0) | (val&mask)==mask); return (((val & mask) == 0) | ((val & mask) == mask));
} }
int int OO_ufit(arith val, arith nbits)
OO_ufit(val, nbits)
arith val, nbits;
{ {
return((val&(~((1L << (nbits - 1)) - 1))) == 0); return ((val & (~((1L << (nbits - 1)) - 1))) == 0);
} }
int int OO_extsame(register p_instr a1, register p_instr a2)
OO_extsame(a1,a2)
register p_instr a1, a2;
{ {
if (a1->em_argtype != a2->em_argtype) if (a1->em_argtype != a2->em_argtype)
return(0); return (0);
switch(a1->em_argtype) { switch (a1->em_argtype)
case cst_ptyp: {
return (a1->em_cst == a2->em_cst); case cst_ptyp:
case sof_ptyp: return (a1->em_cst == a2->em_cst);
if(a1->em_off != a2->em_off) case sof_ptyp:
return(0); if (a1->em_off != a2->em_off)
return (strcmp(a1->em_dnam,a2->em_dnam)==0); return (0);
case nof_ptyp: return (strcmp(a1->em_dnam, a2->em_dnam) == 0);
if (a1->em_off != a2->em_off) case nof_ptyp:
return(0); if (a1->em_off != a2->em_off)
return (a1->em_dlb == a2->em_dlb); return (0);
default: return (a1->em_dlb == a2->em_dlb);
fatal("illegal type (%d) to sameext!",a1->em_argtype); default:
/*NOTREACHED*/ fatal("illegal type (%d) to sameext!", a1->em_argtype);
/*NOTREACHED*/
} }
} }
int int OO_namsame(register p_instr a1, register p_instr a2)
OO_namsame(a1,a2)
register p_instr a1, a2;
{ {
if (a1->em_argtype != a2->em_argtype) if (a1->em_argtype != a2->em_argtype)
return(0); return (0);
switch(a1->em_argtype) { switch (a1->em_argtype)
case cst_ptyp: {
return 1; case cst_ptyp:
case sof_ptyp: return 1;
return (strcmp(a1->em_dnam,a2->em_dnam)==0); case sof_ptyp:
case nof_ptyp: return (strcmp(a1->em_dnam, a2->em_dnam) == 0);
return (a1->em_dlb == a2->em_dlb); case nof_ptyp:
default: return (a1->em_dlb == a2->em_dlb);
fatal("illegal type (%d) to samenam!",a1->em_argtype); default:
/*NOTREACHED*/ fatal("illegal type (%d) to samenam!", a1->em_argtype);
/*NOTREACHED*/
} }
} }
arith arith OO_offset(register p_instr a)
OO_offset(a)
register p_instr a;
{ {
switch(a->em_argtype) { switch (a->em_argtype)
case cst_ptyp: {
return a->em_cst; case cst_ptyp:
case sof_ptyp: return a->em_cst;
return a->em_off; case sof_ptyp:
case nof_ptyp: return a->em_off;
return a->em_off; case nof_ptyp:
default: return a->em_off;
fatal("illegal type (%d) to offset!",a->em_argtype); default:
/*NOTREACHED*/ fatal("illegal type (%d) to offset!", a->em_argtype);
/*NOTREACHED*/
} }
} }