ANSI C compilation fixes
This commit is contained in:
parent
9bb69bbb98
commit
b1f6d5d827
|
@ -6,30 +6,30 @@ static char rcsidp3[] = "$Id$";
|
|||
|
||||
#define UPDATEWORST(backups) if(backups>mostbackups) mostbackups = backups;
|
||||
|
||||
PRIVATE int leftmatch();
|
||||
PRIVATE int rightmatch();
|
||||
PRIVATE int rightmatch(struct mnems,struct mnems,int, int);
|
||||
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.
|
||||
/* Let repl be r1 r2 ... rn. All these are already on the output queue.
|
||||
/* Possibilities in order of most backup first are:
|
||||
/* a) pattern of form: p1 .... pb r1 r2 .... rn pc ... pd
|
||||
/* i.e. <repl> completely in pattern.
|
||||
/* requires a backup of b+n instructions
|
||||
/* and a goto to state 0.
|
||||
/* b) pattern of form: p1 .... pb r1 r2 .... ri
|
||||
/* i.e. a prefix of <repl> ends a pattern.
|
||||
/* requires a backup of b+n instructions
|
||||
/* and a goto to state 0.
|
||||
/* c) pattern of form: ri ri+1 ... rn pc ... pd
|
||||
/* i.e. a suffix of <repl> starts a pattern.
|
||||
/* requires a backup of j-i+1 instructions and a goto to state 0.
|
||||
/* d) pattern of the form: ri ri+1 ... rj
|
||||
/* i.e. a substring of <repl> is a complete pattern
|
||||
/* requires a backup of j-i+1 instructions and a goto to state 0.
|
||||
/ 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.
|
||||
/ Possibilities in order of most backup first are:
|
||||
/ a) pattern of form: p1 .... pb r1 r2 .... rn pc ... pd
|
||||
/ i.e. <repl> completely in pattern.
|
||||
/ requires a backup of b+n instructions
|
||||
/ and a goto to state 0.
|
||||
/ b) pattern of form: p1 .... pb r1 r2 .... ri
|
||||
/ i.e. a prefix of <repl> ends a pattern.
|
||||
/ requires a backup of b+n instructions
|
||||
/ and a goto to state 0.
|
||||
/ c) pattern of form: ri ri+1 ... rn pc ... pd
|
||||
/ i.e. a suffix of <repl> starts a pattern.
|
||||
/ requires a backup of j-i+1 instructions and a goto to state 0.
|
||||
/ d) pattern of the form: ri ri+1 ... rj
|
||||
/ i.e. a substring of <repl> is a complete pattern
|
||||
/ requires a backup of j-i+1 instructions and a goto to state 0.
|
||||
*/
|
||||
int n = repl.m_len;
|
||||
int diff = patt.m_len - repl.m_len;
|
||||
|
@ -45,7 +45,7 @@ findworst(patt,repl)
|
|||
if(actions[s]==(struct action *)NULL)
|
||||
continue;
|
||||
/* look for case a */
|
||||
if(first=rightmatch(patterns[s],repl,1,n)) {
|
||||
if( (first=rightmatch(patterns[s],repl,1,n))) {
|
||||
UPDATEWORST(first-1+n);
|
||||
}
|
||||
/* look for case b */
|
||||
|
@ -76,16 +76,14 @@ findworst(patt,repl)
|
|||
fprintf(ofile,"\t\tOO_mkrepl(%d,%d,%d);\n",n,diff,mostbackups);
|
||||
}
|
||||
|
||||
findfail(state,resout,rescpy,resgto)
|
||||
int state;
|
||||
int *resout, *rescpy, *resgto;
|
||||
void findfail(int state, int *resout, int *rescpy, int *resgto)
|
||||
{
|
||||
/*
|
||||
/* 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
|
||||
/* 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
|
||||
/* of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi.
|
||||
/ 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
|
||||
/ 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
|
||||
/ of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi.
|
||||
*/
|
||||
int s,i;
|
||||
struct state *p;
|
||||
|
@ -114,15 +112,12 @@ findfail(state,resout,rescpy,resgto)
|
|||
*resgto = 0;
|
||||
}
|
||||
|
||||
PRIVATE int
|
||||
leftmatch(patt,repl,i,j)
|
||||
struct mnems patt,repl;
|
||||
int i,j;
|
||||
PRIVATE int leftmatch(struct mnems patt,struct mnems repl,int i,int j)
|
||||
{
|
||||
/*
|
||||
/* Return the first complete match of the mnems <ri,ri+1,..,rj> of
|
||||
/* 'repl' in the mnems of 'patt'. Find the leftmost match.
|
||||
/* Return 0 if fails.
|
||||
/ Return the first complete match of the mnems <ri,ri+1,..,rj> of
|
||||
/ 'repl' in the mnems of 'patt'. Find the leftmost match.
|
||||
/ Return 0 if fails.
|
||||
*/
|
||||
int lenrij = j-i+1;
|
||||
int lastpos = patt.m_len - lenrij + 1;
|
||||
|
@ -139,15 +134,12 @@ leftmatch(patt,repl,i,j)
|
|||
return(0);
|
||||
}
|
||||
|
||||
PRIVATE int
|
||||
rightmatch(patt,repl,i,j)
|
||||
struct mnems patt,repl;
|
||||
int i,j;
|
||||
PRIVATE int rightmatch(struct mnems patt,struct mnems repl,int i,int j)
|
||||
{
|
||||
/*
|
||||
/* Return the first complete match of the mnems <ri,ri+1,..,rj> of
|
||||
/* 'repl' in the mnems of 'patt'. Find the rightmost match.
|
||||
/* Return 0 if fails.
|
||||
/ Return the first complete match of the mnems <ri,ri+1,..,rj> of
|
||||
/ 'repl' in the mnems of 'patt'. Find the rightmost match.
|
||||
/ Return 0 if fails.
|
||||
*/
|
||||
int lenrij = j-i+1;
|
||||
int lastpos = patt.m_len - lenrij + 1;
|
||||
|
|
|
@ -13,9 +13,9 @@ static char rcsidp2[] = "$Id$";
|
|||
extern char em_flag[];
|
||||
extern char em_mnem[][4];
|
||||
|
||||
PRIVATE idinit();
|
||||
PRIVATE void idinit(char *, int, int);
|
||||
|
||||
initlex()
|
||||
void initlex(void)
|
||||
{
|
||||
register int i,j;
|
||||
init_idf();
|
||||
|
@ -47,11 +47,8 @@ initlex()
|
|||
}
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
idinit(tag,opcode,argfmt)
|
||||
char *tag;
|
||||
int opcode;
|
||||
int argfmt;
|
||||
|
||||
PRIVATE void idinit(char *tag, int opcode, int argfmt)
|
||||
{
|
||||
struct idf *p;
|
||||
p = str2idf(tag,0);
|
||||
|
|
|
@ -3,49 +3,66 @@ BEGIN {
|
|||
seenproc = 0;
|
||||
CC="${CMD}"
|
||||
if (prototypes == "") prototypes = "prototypes"
|
||||
print "#include \"nopt.h\""
|
||||
}
|
||||
/^%/ {}
|
||||
/^$/ {}
|
||||
/^[a-z]/ && $3 !~ /.*NOTIMPLEMENTED.*/ {
|
||||
if(seenproc) {
|
||||
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
|
||||
$1 = substr($1,1,index($1,"\t")-1);
|
||||
nam = $1
|
||||
printf "cat > O_%s.c << '--EOF--'\n",$1
|
||||
print "#include \"nopt.h\""
|
||||
print ""
|
||||
printf "void O_%s(",$1
|
||||
prototype = "_PROTOTYPE(void O_" $1 ", ("
|
||||
nparms = split($2,parms,":");
|
||||
for(p=1;p<nparms;p++) {
|
||||
if(p!=1) {
|
||||
|
||||
paramstr = $2
|
||||
gsub(/\t/,"",paramstr)
|
||||
gsub(/^[ \t]+/,"",paramstr)
|
||||
gsub(/[ \t]+$/,"",paramstr)
|
||||
gsub(/:([A-Za-z0-9]+[ ])/,"&!",paramstr)
|
||||
|
||||
|
||||
count = split(paramstr,p2,"!");
|
||||
paramstr = ""
|
||||
if (count == 0)
|
||||
{
|
||||
printf "void"
|
||||
paramstr = paramstr "void"
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=1;i<=count;i++)
|
||||
{
|
||||
if (length(p2[i]) > 0)
|
||||
{
|
||||
nparms = split(p2[i],params,":");
|
||||
if (nparms >0 )
|
||||
{
|
||||
gsub(/^[ \t]+/,"",params[1])
|
||||
gsub(/[ \t]+$/,"",params[1])
|
||||
gsub(/^[ \t]+/,"",params[2])
|
||||
gsub(/[ \t]+$/,"",params[2])
|
||||
|
||||
paramstr = paramstr params[1] " " params[2]
|
||||
printf "%s %s",params[1],params[2]
|
||||
if(count!=i)
|
||||
{
|
||||
paramstr = paramstr ", "
|
||||
printf ", "
|
||||
}
|
||||
split(parms[p+1],a," ")
|
||||
printf a[1]
|
||||
}
|
||||
printf ")\n"
|
||||
if(nparms > 1) {
|
||||
prototype = prototype parms[1]
|
||||
printf "\t%s",parms[1]
|
||||
}
|
||||
else {
|
||||
prototype = prototype "void"
|
||||
}
|
||||
for(p=1;p<nparms;p++) {
|
||||
split(parms[p+1],a," ")
|
||||
prototype = prototype " " a[1]
|
||||
printf " %s;\n",a[1]
|
||||
if(a[2]) {
|
||||
prototype = prototype ", " a[2] a[3] a[4]
|
||||
printf "\t%s%s%s",a[2],a[3],a[4]
|
||||
} else
|
||||
{
|
||||
printf "void"
|
||||
paramstr = paramstr "void"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prototype = prototype paramstr
|
||||
print ")"
|
||||
print prototype "));" >> prototypes
|
||||
if($3) {
|
||||
printf "{\n\t%s\n",$3
|
||||
|
@ -60,9 +77,6 @@ BEGIN {
|
|||
END {
|
||||
if(seenproc) {
|
||||
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
|
||||
print ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,20 +4,16 @@ static char rcsid3[] = "$Id$";
|
|||
|
||||
#include "nopt.h"
|
||||
|
||||
void
|
||||
EM_mkop(p,opcode)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
void EM_mkop(p, opcode)
|
||||
register p_instr p;int opcode;
|
||||
{
|
||||
p->em_type = EM_MNEM;
|
||||
p->em_opcode = opcode;
|
||||
p->em_argtype = 0;
|
||||
}
|
||||
|
||||
void
|
||||
EM_mknarg(p,opcode)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
void EM_mknarg(p, opcode)
|
||||
register p_instr p;int opcode;
|
||||
{
|
||||
p->em_type = EM_MNEM;
|
||||
p->em_opcode = opcode;
|
||||
|
@ -25,11 +21,8 @@ EM_mknarg(p,opcode)
|
|||
p->em_cst = 0;
|
||||
}
|
||||
|
||||
void
|
||||
EM_mkilb(p,opcode,lab)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
label lab;
|
||||
void EM_mkilb(p, opcode, lab)
|
||||
register p_instr p;int opcode;label lab;
|
||||
{
|
||||
p->em_type = EM_MNEM;
|
||||
p->em_argtype = ilb_ptyp;
|
||||
|
@ -37,11 +30,8 @@ EM_mkilb(p,opcode,lab)
|
|||
p->em_ilb = lab;
|
||||
}
|
||||
|
||||
void
|
||||
EM_mknof(p,opcode,lab,off)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
label lab;
|
||||
void EM_mknof(p, opcode, lab, off)
|
||||
register p_instr p;int opcode;label lab;
|
||||
arith off;
|
||||
{
|
||||
p->em_type = EM_MNEM;
|
||||
|
@ -51,11 +41,8 @@ EM_mknof(p,opcode,lab,off)
|
|||
p->em_off = off;
|
||||
}
|
||||
|
||||
void
|
||||
EM_mksof(p,opcode,name,off)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
char *name;
|
||||
void EM_mksof(p, opcode, name, off)
|
||||
register p_instr p;int opcode;char *name;
|
||||
arith off;
|
||||
{
|
||||
p->em_type = EM_MNEM;
|
||||
|
@ -65,10 +52,8 @@ EM_mksof(p,opcode,name,off)
|
|||
p->em_off = off;
|
||||
}
|
||||
|
||||
void
|
||||
EM_mkcst(p,opcode,cst)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
void EM_mkcst(p, opcode, cst)
|
||||
register p_instr p;int opcode;
|
||||
arith cst;
|
||||
{
|
||||
p->em_type = EM_MNEM;
|
||||
|
@ -77,11 +62,8 @@ EM_mkcst(p,opcode,cst)
|
|||
p->em_cst = cst;
|
||||
}
|
||||
|
||||
void
|
||||
EM_mkpro(p,opcode,pnam)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
char *pnam;
|
||||
void EM_mkpro(p, opcode, pnam)
|
||||
register p_instr p;int opcode;char *pnam;
|
||||
{
|
||||
p->em_type = EM_MNEM;
|
||||
p->em_argtype = pro_ptyp;
|
||||
|
@ -89,11 +71,8 @@ EM_mkpro(p,opcode,pnam)
|
|||
p->em_pnam = OO_freestr(pnam);
|
||||
}
|
||||
|
||||
void
|
||||
EM_mkdefilb(p,opcode,deflb)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
label deflb;
|
||||
void EM_mkdefilb(p, opcode, deflb)
|
||||
register p_instr p;int opcode;label deflb;
|
||||
{
|
||||
p->em_type = EM_DEFILB;
|
||||
p->em_opcode = opcode;
|
||||
|
@ -101,8 +80,7 @@ EM_mkdefilb(p,opcode,deflb)
|
|||
p->em_ilb = deflb;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Nop(opcode)
|
||||
void EM_Nop(opcode)
|
||||
int opcode;
|
||||
{
|
||||
register p_instr p = GETNXTPATT();
|
||||
|
@ -111,8 +89,7 @@ EM_Nop(opcode)
|
|||
p->em_argtype = 0;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Nnarg(opcode)
|
||||
void EM_Nnarg(opcode)
|
||||
int opcode;
|
||||
{
|
||||
register p_instr p = GETNXTPATT();
|
||||
|
@ -122,10 +99,8 @@ EM_Nnarg(opcode)
|
|||
p->em_cst = 0;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Nilb(opcode,lab)
|
||||
int opcode;
|
||||
label lab;
|
||||
void EM_Nilb(opcode, lab)
|
||||
int opcode;label lab;
|
||||
{
|
||||
register p_instr p = GETNXTPATT();
|
||||
p->em_type = EM_MNEM;
|
||||
|
@ -134,10 +109,8 @@ EM_Nilb(opcode,lab)
|
|||
p->em_ilb = lab;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Nnof(opcode,lab,off)
|
||||
int opcode;
|
||||
label lab;
|
||||
void EM_Nnof(opcode, lab, off)
|
||||
int opcode;label lab;
|
||||
arith off;
|
||||
{
|
||||
register p_instr p = GETNXTPATT();
|
||||
|
@ -148,10 +121,8 @@ EM_Nnof(opcode,lab,off)
|
|||
p->em_off = off;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Nsof(opcode,name,off)
|
||||
int opcode;
|
||||
char *name;
|
||||
void EM_Nsof(opcode, name, off)
|
||||
int opcode;char *name;
|
||||
arith off;
|
||||
{
|
||||
register p_instr p = GETNXTPATT();
|
||||
|
@ -162,8 +133,7 @@ EM_Nsof(opcode,name,off)
|
|||
p->em_off = off;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Ncst(opcode,cst)
|
||||
void EM_Ncst(opcode, cst)
|
||||
int opcode;
|
||||
arith cst;
|
||||
{
|
||||
|
@ -174,10 +144,8 @@ EM_Ncst(opcode,cst)
|
|||
p->em_cst = cst;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Npro(opcode,pnam)
|
||||
int opcode;
|
||||
char *pnam;
|
||||
void EM_Npro(opcode, pnam)
|
||||
int opcode;char *pnam;
|
||||
{
|
||||
register p_instr p = GETNXTPATT();
|
||||
p->em_type = EM_MNEM;
|
||||
|
@ -186,10 +154,8 @@ EM_Npro(opcode,pnam)
|
|||
p->em_pnam = OO_freestr(pnam);
|
||||
}
|
||||
|
||||
void
|
||||
EM_Ndefilb(opcode,deflb)
|
||||
int opcode;
|
||||
label deflb;
|
||||
void EM_Ndefilb(opcode, deflb)
|
||||
int opcode;label deflb;
|
||||
{
|
||||
register p_instr p = GETNXTPATT();
|
||||
p->em_type = EM_DEFILB;
|
||||
|
@ -198,8 +164,7 @@ EM_Ndefilb(opcode,deflb)
|
|||
p->em_ilb = deflb;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Rop(opcode)
|
||||
void EM_Rop(opcode)
|
||||
int opcode;
|
||||
{
|
||||
register p_instr p = GETNXTREPL();
|
||||
|
@ -208,8 +173,7 @@ EM_Rop(opcode)
|
|||
p->em_argtype = 0;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Rnarg(opcode)
|
||||
void EM_Rnarg(opcode)
|
||||
int opcode;
|
||||
{
|
||||
register p_instr p = GETNXTREPL();
|
||||
|
@ -219,10 +183,8 @@ EM_Rnarg(opcode)
|
|||
p->em_cst = 0;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Rilb(opcode,lab)
|
||||
int opcode;
|
||||
label lab;
|
||||
void EM_Rilb(opcode, lab)
|
||||
int opcode;label lab;
|
||||
{
|
||||
register p_instr p = GETNXTREPL();
|
||||
p->em_type = EM_MNEM;
|
||||
|
@ -231,10 +193,8 @@ EM_Rilb(opcode,lab)
|
|||
p->em_ilb = lab;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Rnof(opcode,lab,off)
|
||||
int opcode;
|
||||
label lab;
|
||||
void EM_Rnof(opcode, lab, off)
|
||||
int opcode;label lab;
|
||||
arith off;
|
||||
{
|
||||
register p_instr p = GETNXTREPL();
|
||||
|
@ -245,10 +205,8 @@ EM_Rnof(opcode,lab,off)
|
|||
p->em_off = off;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Rsof(opcode,name,off)
|
||||
int opcode;
|
||||
char *name;
|
||||
void EM_Rsof(opcode, name, off)
|
||||
int opcode;char *name;
|
||||
arith off;
|
||||
{
|
||||
register p_instr p = GETNXTREPL();
|
||||
|
@ -259,8 +217,7 @@ EM_Rsof(opcode,name,off)
|
|||
p->em_off = off;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Rcst(opcode,cst)
|
||||
void EM_Rcst(opcode, cst)
|
||||
int opcode;
|
||||
arith cst;
|
||||
{
|
||||
|
@ -271,10 +228,8 @@ EM_Rcst(opcode,cst)
|
|||
p->em_cst = cst;
|
||||
}
|
||||
|
||||
void
|
||||
EM_Rpro(opcode,pnam)
|
||||
int opcode;
|
||||
char *pnam;
|
||||
void EM_Rpro(opcode, pnam)
|
||||
int opcode;char *pnam;
|
||||
{
|
||||
register p_instr p = GETNXTREPL();
|
||||
p->em_type = EM_MNEM;
|
||||
|
@ -283,10 +238,8 @@ EM_Rpro(opcode,pnam)
|
|||
p->em_pnam = OO_freestr(pnam);
|
||||
}
|
||||
|
||||
void
|
||||
EM_Rdefilb(opcode,deflb)
|
||||
int opcode;
|
||||
label deflb;
|
||||
void EM_Rdefilb(opcode, deflb)
|
||||
int opcode;label deflb;
|
||||
{
|
||||
register p_instr p = GETNXTREPL();
|
||||
p->em_type = EM_DEFILB;
|
||||
|
|
|
@ -46,11 +46,9 @@ int OO_wrstats = 1; /* pattern statistics output */
|
|||
**************************/
|
||||
#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
|
||||
O_init(wsize,psize)
|
||||
arith wsize, psize;
|
||||
void O_init(arith wsize, arith psize)
|
||||
{
|
||||
allocmem();
|
||||
C_init(wsize, psize);
|
||||
|
@ -59,58 +57,58 @@ O_init(wsize,psize)
|
|||
OO_PSIZE = psize;
|
||||
}
|
||||
|
||||
int
|
||||
O_open(fname)
|
||||
char *fname;
|
||||
int O_open(char *fname)
|
||||
{
|
||||
filename = fname;
|
||||
return (C_open(fname));
|
||||
}
|
||||
|
||||
void
|
||||
O_magic()
|
||||
void O_magic(void)
|
||||
{
|
||||
C_magic();
|
||||
}
|
||||
|
||||
void
|
||||
O_close()
|
||||
void O_close(void)
|
||||
{
|
||||
C_close();
|
||||
}
|
||||
|
||||
void
|
||||
OO_dfa(last)
|
||||
register int last;
|
||||
void OO_dfa(register int last)
|
||||
{
|
||||
register struct dfa *b;
|
||||
register struct dodefault *d;
|
||||
register int (*f)();
|
||||
for(;;) {
|
||||
for (;;)
|
||||
{
|
||||
printstate("OO_dfa");
|
||||
if((b=OO_base[OO_state]) && ((b += last)->check==OO_state)) {
|
||||
if(f=OO_ftrans[OO_state = b->next]) (*f)();
|
||||
if ((b = OO_base[OO_state]) && ((b += last)->check == OO_state))
|
||||
{
|
||||
if ((f = OO_ftrans[OO_state = b->next]))
|
||||
(*f)();
|
||||
}
|
||||
else if (OO_state) {
|
||||
else if (OO_state)
|
||||
{
|
||||
/* consult default entry */
|
||||
d = &OO_default[OO_state];
|
||||
if(!OO_endbackup) OO_endbackup = OO_nxtpatt;
|
||||
if (!OO_endbackup)
|
||||
OO_endbackup = OO_nxtpatt;
|
||||
OO_nxtpatt--;
|
||||
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();
|
||||
if (!OO_endbackup) return;
|
||||
else
|
||||
OO_flush();
|
||||
if (!OO_endbackup)
|
||||
return;
|
||||
last = (OO_nxtpatt++)->em_opcode;
|
||||
if (OO_nxtpatt >= OO_endbackup)
|
||||
OO_endbackup = 0;
|
||||
}
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
fatal(s,a)
|
||||
char *s;
|
||||
int a;
|
||||
PRIVATE void fatal(s, a)
|
||||
char *s;int a;
|
||||
{
|
||||
fprint(STDERR, "%s: ", filename ? filename : "standard input");
|
||||
fprint(STDERR, s, a);
|
||||
|
@ -118,30 +116,27 @@ fatal(s,a)
|
|||
sys_stop(S_EXIT);
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
allocmem()
|
||||
PRIVATE void allocmem(void)
|
||||
{
|
||||
/* Allocate memory for queues on heap */
|
||||
OO_buffer = (p_instr)
|
||||
Malloc((unsigned)(MAXBUFFER*sizeof(struct e_instr)));
|
||||
OO_buffer = (p_instr) Malloc(
|
||||
(unsigned) (MAXBUFFER * sizeof(struct e_instr)));
|
||||
OO_patternqueue = OO_nxtpatt = OO_buffer;
|
||||
OO_replqueue = (p_instr)
|
||||
Malloc((unsigned)OO_maxreplacement*sizeof(struct e_instr));
|
||||
OO_replqueue = (p_instr) Malloc(
|
||||
(unsigned) OO_maxreplacement * sizeof(struct e_instr));
|
||||
OO_nxtrepl = OO_replqueue;
|
||||
nextstr = strqueue =
|
||||
(char *)Malloc(MAXSTRING*sizeof(char));
|
||||
nextstr = strqueue = (char *) Malloc(MAXSTRING * sizeof(char));
|
||||
laststr = strqueue + MAXSTRING - 1;
|
||||
}
|
||||
|
||||
char *
|
||||
OO_freestr(str)
|
||||
char *str;
|
||||
char * OO_freestr(char *str)
|
||||
{
|
||||
register char *s = str;
|
||||
register char *res;
|
||||
while (*s++);
|
||||
again:
|
||||
if ((s-str) > (laststr-nextstr)) {
|
||||
while (*s++)
|
||||
;
|
||||
again: if ((s - str) > (laststr - nextstr))
|
||||
{
|
||||
unsigned newsize = (laststr - strqueue + 1) * 2;
|
||||
res = Realloc(strqueue, newsize);
|
||||
laststr = res + newsize - 1;
|
||||
|
@ -154,16 +149,16 @@ OO_freestr(str)
|
|||
goto again;
|
||||
}
|
||||
res = nextstr;
|
||||
for(s=str;*nextstr++ = *s++;);
|
||||
for (s = str; (*nextstr++ = *s++);)
|
||||
;
|
||||
return (res);
|
||||
}
|
||||
|
||||
void
|
||||
OO_flush()
|
||||
void OO_flush(void)
|
||||
{
|
||||
/*
|
||||
/* Output all instructions waiting in the output queue and free their
|
||||
/* storage including the saved strings.
|
||||
Output all instructions waiting in the output queue and free their
|
||||
storage including the saved strings.
|
||||
*/
|
||||
register p_instr p, q;
|
||||
register int i, n;
|
||||
|
@ -172,24 +167,25 @@ OO_flush()
|
|||
C_out(p);
|
||||
if (p->em_opcode != OTHER)
|
||||
C_out(p);
|
||||
if(OO_endbackup) {
|
||||
if (OO_endbackup)
|
||||
{
|
||||
n = OO_endbackup - OO_nxtpatt;
|
||||
BTSCPY(p, q, i, OO_buffer, OO_nxtpatt, n);
|
||||
OO_endbackup = OO_buffer + n;
|
||||
}
|
||||
else nextstr = strqueue;
|
||||
else
|
||||
nextstr = strqueue;
|
||||
OO_patternqueue = OO_nxtpatt = OO_buffer;
|
||||
}
|
||||
|
||||
p_instr
|
||||
OO_halfflush()
|
||||
p_instr OO_halfflush(void)
|
||||
{
|
||||
/*
|
||||
/* Called when buffer full, flush half the buffer and move the
|
||||
/* the pattern pointers to the new positions. Return a pointer
|
||||
/* to the new nxtpatt position and increment it.
|
||||
/* Note that OO_endbackup is always NIL (i.e. there are no
|
||||
/* instructions on the backup queue) when this is invoked.
|
||||
Called when buffer full, flush half the buffer and move the
|
||||
the pattern pointers to the new positions. Return a pointer
|
||||
to the new nxtpatt position and increment it.
|
||||
Note that OO_endbackup is always NIL (i.e. there are no
|
||||
instructions on the backup queue) when this is invoked.
|
||||
*/
|
||||
register int i, n;
|
||||
register p_instr p, q;
|
||||
|
@ -205,14 +201,10 @@ OO_halfflush()
|
|||
return (OO_nxtpatt++);
|
||||
}
|
||||
|
||||
void
|
||||
OO_mkext(p,opcode,arg,off)
|
||||
register p_instr p;
|
||||
int opcode;
|
||||
p_instr arg;
|
||||
arith off;
|
||||
void OO_mkext(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);
|
||||
break;
|
||||
|
@ -227,24 +219,26 @@ OO_mkext(p,opcode,arg,off)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
OO_mkrepl(lrepl,diff,numbkup)
|
||||
int lrepl,diff,numbkup;
|
||||
void OO_mkrepl(int lrepl, int diff, int numbkup)
|
||||
{
|
||||
/* copy the replacement queue into the buffer queue */
|
||||
/* then move the pattern queue back n places */
|
||||
register p_instr p, q;
|
||||
register int i;
|
||||
printstate("Before backup");
|
||||
if(OO_endbackup) {
|
||||
if (OO_endbackup)
|
||||
{
|
||||
/* move the region between OO_nxtpatt and OO_endbackup */
|
||||
if (diff > 0) {
|
||||
if (diff > 0)
|
||||
{
|
||||
/* 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_endbackup -= diff;
|
||||
}
|
||||
else if (diff < 0) {
|
||||
else if (diff < 0)
|
||||
{
|
||||
/* move right by diff */
|
||||
/* careful of overflowing buffer!! */
|
||||
if ((OO_nxtpatt - diff) > (OO_buffer + MAXBUFFER))
|
||||
|
@ -258,7 +252,8 @@ OO_mkrepl(lrepl,diff,numbkup)
|
|||
}
|
||||
}
|
||||
/* copy the replacement */
|
||||
if (lrepl) {
|
||||
if (lrepl)
|
||||
{
|
||||
BTSCPY(p, q, i, OO_patternqueue, OO_replqueue, lrepl);
|
||||
OO_nxtrepl = OO_replqueue;
|
||||
OO_patternqueue += lrepl;
|
||||
|
@ -275,8 +270,7 @@ OO_mkrepl(lrepl,diff,numbkup)
|
|||
|
||||
#ifdef DEBUG
|
||||
void
|
||||
dumpstate(mess)
|
||||
char *mess;
|
||||
dumpstate(char *mess)
|
||||
{
|
||||
p_instr p;
|
||||
fprintf(stderr,"%s - state(%d): ",mess,OO_state);
|
||||
|
@ -287,7 +281,8 @@ dumpstate(mess)
|
|||
while(p<OO_nxtpatt)
|
||||
prtinst(p++);
|
||||
fprintf(stderr," |==| ");
|
||||
if(OO_endbackup) {
|
||||
if(OO_endbackup)
|
||||
{
|
||||
while(p<OO_endbackup)
|
||||
prtinst(p++);
|
||||
}
|
||||
|
@ -295,10 +290,10 @@ dumpstate(mess)
|
|||
}
|
||||
|
||||
void
|
||||
prtinst(p)
|
||||
p_instr p;
|
||||
prtinst(p_instr p)
|
||||
{
|
||||
switch(p->em_type)
|
||||
{
|
||||
switch(p->em_type) {
|
||||
case EM_MNEM:
|
||||
fprintf(stderr,"%s ",em_mnem[p->em_opcode-sp_fmnem]);
|
||||
break;
|
||||
|
@ -324,7 +319,8 @@ prtinst(p)
|
|||
case EM_EOF:
|
||||
return;
|
||||
}
|
||||
switch(p->em_argtype) {
|
||||
switch(p->em_argtype)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case cst_ptyp:
|
||||
|
|
|
@ -4,104 +4,124 @@ static char rcsidp4[] = "$Id$";
|
|||
|
||||
#include "parser.h"
|
||||
|
||||
outputincalls()
|
||||
void outputincalls(void)
|
||||
{
|
||||
struct idf *op;
|
||||
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;
|
||||
switch(op->id_argfmt) {
|
||||
switch (op->id_argfmt)
|
||||
{
|
||||
case NOARG:
|
||||
fprintf(ofile, "%s\t|\t|\n", s);
|
||||
if(op->id_used) {
|
||||
if (op->id_used)
|
||||
{
|
||||
fprintf(ofile, "\tEM_Nop(op_%s);\n", s);
|
||||
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\tFLUSHDFA();\n");
|
||||
fprintf(ofile, "\tC_%s();\n", s);
|
||||
}
|
||||
break;
|
||||
case CSTOPT:
|
||||
fprintf(ofile, "%s_narg\t|\t|\n", s);
|
||||
if(op->id_used) {
|
||||
if (op->id_used)
|
||||
{
|
||||
fprintf(ofile, "\tEM_Nnarg(op_%s);\n", s);
|
||||
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\tFLUSHDFA();\n");
|
||||
fprintf(ofile, "\tC_%s_narg();\n", s);
|
||||
}
|
||||
/* fall thru */
|
||||
case CST:
|
||||
fprintf(ofile, "%s\t| arith:n\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);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\tFLUSHDFA();\n");
|
||||
fprintf(ofile, "\tC_%s(n);\n", s);
|
||||
}
|
||||
break;
|
||||
case DEFILB:
|
||||
fprintf(ofile, "df_ilb\t| label:l\t|\n");
|
||||
if(op->id_used) {
|
||||
if (op->id_used)
|
||||
{
|
||||
fprintf(ofile, "\tEM_Ndefilb(op_%s,l);\n", s);
|
||||
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\tFLUSHDFA();\n");
|
||||
fprintf(ofile, "\tC_df_ilb(l);\n", s);
|
||||
}
|
||||
break;
|
||||
case PNAM:
|
||||
fprintf(ofile, "%s\t| char *:s\t|\n", s);
|
||||
if(op->id_used) {
|
||||
if (op->id_used)
|
||||
{
|
||||
fprintf(ofile, "\tEM_Npro(op_%s,s);\n", s);
|
||||
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\tFLUSHDFA();\n");
|
||||
fprintf(ofile, "\tC_%s(s);\n", s);
|
||||
}
|
||||
break;
|
||||
case LAB:
|
||||
fprintf(ofile, "%s\t| label:l\t|\n", s);
|
||||
if(op->id_used) {
|
||||
if (op->id_used)
|
||||
{
|
||||
fprintf(ofile, "\tEM_Nilb(op_%s,l);\n", s);
|
||||
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\tFLUSHDFA();\n");
|
||||
fprintf(ofile, "\tC_%s(l);\n", s);
|
||||
}
|
||||
break;
|
||||
case EXT:
|
||||
fprintf(ofile, "%s\t| arith:n\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);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\tFLUSHDFA();\n");
|
||||
fprintf(ofile, "\tC_%s(n);\n", s);
|
||||
}
|
||||
fprintf(ofile, "%s_dnam\t| char *:s arith:n\t|\n", s);
|
||||
if(op->id_used) {
|
||||
if (op->id_used)
|
||||
{
|
||||
fprintf(ofile, "\tEM_Nsof(op_%s,s,n);\n", s);
|
||||
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
|
||||
}
|
||||
else {
|
||||
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) {
|
||||
if (op->id_used)
|
||||
{
|
||||
fprintf(ofile, "\tEM_Nnof(op_%s,l,n);\n", s);
|
||||
fprintf(ofile, "\tOO_dfa(op_%s);\n", s);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\tFLUSHDFA();\n");
|
||||
fprintf(ofile, "\tC_%s_dlb(l,n);\n", s);
|
||||
}
|
||||
|
|
|
@ -3,25 +3,31 @@ static char rcsidp5[] = "$Id$";
|
|||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "alloc.h"
|
||||
#include "parser.h"
|
||||
#include "Lpars.h"
|
||||
|
||||
FILE *ofile;
|
||||
|
||||
PRIVATE openofile();
|
||||
PRIVATE installofile();
|
||||
PRIVATE UNLINK();
|
||||
PRIVATE RENAME();
|
||||
PRIVATE outdfa();
|
||||
PRIVATE outmnems();
|
||||
PRIVATE outdotrans();
|
||||
PRIVATE outoneaction();
|
||||
PRIVATE outrepl();
|
||||
PRIVATE outexp();
|
||||
PRIVATE outext();
|
||||
PRIVATE outop();
|
||||
PRIVATE void openofile(char *);
|
||||
PRIVATE void installofile(void);
|
||||
PRIVATE void UNLINK(char *);
|
||||
PRIVATE void RENAME(char *, char *);
|
||||
PRIVATE void increase_next(unsigned int);
|
||||
PRIVATE void store_row(int, register int *);
|
||||
PRIVATE void outdfa(void);
|
||||
PRIVATE void outmnems(struct mnems);
|
||||
PRIVATE int sametest(int, int, struct exp_node *, struct exp_node *);
|
||||
PRIVATE int samerepl(int, int, struct mnems, struct mnems);
|
||||
PRIVATE int samecode(int, int);
|
||||
PRIVATE void outdotrans(void);
|
||||
PRIVATE void outoneaction(int, struct action *);
|
||||
PRIVATE void outrepl(int, struct mnems);
|
||||
PRIVATE void outexp(struct exp_node *, int);
|
||||
PRIVATE void outext(struct exp_node *);
|
||||
PRIVATE void outop(int op);
|
||||
|
||||
outputnopt()
|
||||
void outputnopt(void)
|
||||
{
|
||||
openofile("dfa.c");
|
||||
outdfa();
|
||||
|
@ -37,21 +43,19 @@ outputnopt()
|
|||
static char ofilename[80];
|
||||
static char ofiletemp[80];
|
||||
|
||||
PRIVATE
|
||||
openofile(filename)
|
||||
char *filename;
|
||||
PRIVATE void openofile(char *filename)
|
||||
{
|
||||
strcpy(ofilename, filename);
|
||||
strcpy(ofiletemp, filename);
|
||||
strcat(ofiletemp, ".new");
|
||||
if((ofile=fopen(ofiletemp,"w"))==NULL) {
|
||||
if ((ofile = fopen(ofiletemp, "w")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "Fatal Error: cannot open output file %s\n", ofiletemp);
|
||||
sys_stop(S_EXIT);
|
||||
}
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
installofile()
|
||||
PRIVATE void installofile(void)
|
||||
{
|
||||
/*
|
||||
* if contents of newly generated ofiletemp is different
|
||||
|
@ -61,46 +65,46 @@ installofile()
|
|||
register FILE *f1, *f2;
|
||||
register int c1, c2;
|
||||
fclose(ofile);
|
||||
if((f1 = fopen(ofiletemp,"r")) == NULL) {
|
||||
if ((f1 = fopen(ofiletemp, "r")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "Fatal Error: cannont reopen file %s\n", ofiletemp);
|
||||
sys_stop(S_EXIT);
|
||||
}
|
||||
if((f2 = fopen(ofilename,"r")) == NULL) {
|
||||
if ((f2 = fopen(ofilename, "r")) == NULL)
|
||||
{
|
||||
fclose(f1);
|
||||
RENAME(ofiletemp, ofilename);
|
||||
return;
|
||||
}
|
||||
do {
|
||||
do
|
||||
{
|
||||
c1 = getc(f1);
|
||||
c2 = getc(f2);
|
||||
} while (c1 == c2 && c1 != EOF);
|
||||
fclose(f1);
|
||||
fclose(f2);
|
||||
if (c1 != c2) {
|
||||
if (c1 != c2)
|
||||
{
|
||||
RENAME(ofiletemp, ofilename);
|
||||
}
|
||||
else UNLINK(ofiletemp);
|
||||
else
|
||||
UNLINK(ofiletemp);
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
UNLINK(x)
|
||||
char *x;
|
||||
PRIVATE void UNLINK(char *x)
|
||||
{
|
||||
/* Must remove the file "x" */
|
||||
unlink(x); /* systemcall to remove file */
|
||||
remove(x); /* systemcall to remove file */
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
RENAME(x,y)
|
||||
char *x, *y;
|
||||
PRIVATE void RENAME(char *x, char*y)
|
||||
{
|
||||
/* Must move the file "x" to the file "y" */
|
||||
unlink(y);
|
||||
if(link(x,y)!=0) {
|
||||
fprintf(stderr,"Cannot link to %s",y);
|
||||
if (rename(x, y) != 0)
|
||||
{
|
||||
fprintf(stderr, "Cannot rename to %s", y);
|
||||
sys_stop(S_EXIT);
|
||||
}
|
||||
unlink(x);
|
||||
}
|
||||
|
||||
# define MAXOPCODE 255
|
||||
|
@ -110,20 +114,19 @@ int *next, *check, *base;
|
|||
unsigned currsize; /* current size of next and check arrays */
|
||||
int maxpos = 0; /* highest used position in these arrayes */
|
||||
|
||||
PRIVATE
|
||||
increase_next(size)
|
||||
int size;
|
||||
PRIVATE void increase_next(unsigned int size)
|
||||
{
|
||||
/* realloc arrays next and check so they are at least
|
||||
* of size 'size'
|
||||
*/
|
||||
char *Realloc();
|
||||
unsigned newsize = currsize;
|
||||
register int i;
|
||||
do {
|
||||
register unsigned int i;
|
||||
do
|
||||
{
|
||||
newsize *= 2;
|
||||
} while (newsize < size);
|
||||
printf("Note: Extending next/check arrays from %d to %d\n",currsize,newsize);
|
||||
printf("Note: Extending next/check arrays from %d to %d\n", currsize,
|
||||
newsize);
|
||||
next = (int *) Realloc(next, newsize);
|
||||
check = (int *) Realloc(check, newsize);
|
||||
/* clear ends of new arrays */
|
||||
|
@ -132,39 +135,41 @@ increase_next(size)
|
|||
currsize = newsize;
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
store_row(state,row)
|
||||
int state;
|
||||
register int *row;
|
||||
PRIVATE void store_row(int state, register int *row)
|
||||
{
|
||||
/* find a place to store row in arrays */
|
||||
register b,i,o;
|
||||
register int b, i, o;
|
||||
register int *n = next;
|
||||
b = 0;
|
||||
for(;;) {
|
||||
for (;;)
|
||||
{
|
||||
/* look for first possible place to store it */
|
||||
for(i=0;i<MAXOPCODE;i++) {
|
||||
if(row[i]) {
|
||||
if((o = b+i)>currsize) increase_next(o);
|
||||
if(n[o]!=EMPTY) goto nextpos;
|
||||
for (i = 0; i < MAXOPCODE; i++)
|
||||
{
|
||||
if (row[i])
|
||||
{
|
||||
if ((o = b + i) > currsize)
|
||||
increase_next(o);
|
||||
if (n[o] != EMPTY)
|
||||
goto nextpos;
|
||||
}
|
||||
}
|
||||
/* found a place */
|
||||
base[state] = b;
|
||||
for (i = 0; i < MAXOPCODE; i++)
|
||||
if(row[i]) {
|
||||
if((o=b+i) >maxpos) maxpos = o;
|
||||
if (row[i])
|
||||
{
|
||||
if ((o = b + i) > maxpos)
|
||||
maxpos = o;
|
||||
next[o] = row[i];
|
||||
check[o] = state;
|
||||
}
|
||||
return;
|
||||
nextpos:
|
||||
++b;
|
||||
nextpos: ++b;
|
||||
}
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
outdfa()
|
||||
PRIVATE void outdfa(void)
|
||||
{
|
||||
register int s, i;
|
||||
register struct state *p;
|
||||
|
@ -188,13 +193,17 @@ outdfa()
|
|||
check = (int *) Malloc(currsize * sizeof(int));
|
||||
base = (int *) Malloc(((unsigned) (higheststate + 1)) * sizeof(int));
|
||||
/* fill next array with EMPTY */
|
||||
for(i=0;i<currsize;i++) check[i]=next[i]=EMPTY;
|
||||
for(s=0;s<=higheststate;s++) {
|
||||
for (i = 0; i < currsize; i++)
|
||||
check[i] = next[i] = EMPTY;
|
||||
for (s = 0; s <= higheststate; s++)
|
||||
{
|
||||
/* empty row */
|
||||
for(i=0;i<MAXOPCODE;i++) row[i]=0;
|
||||
for (i = 0; i < MAXOPCODE; i++)
|
||||
row[i] = 0;
|
||||
numinrow = 0;
|
||||
/* fill in non zero entries */
|
||||
for(p=states[s];p!=(struct state *)NULL;p=p->next) {
|
||||
for (p = states[s]; p != (struct state *) NULL; p = p->next)
|
||||
{
|
||||
numinrow++;
|
||||
row[p->op->id_opcode] = p->goto_state;
|
||||
}
|
||||
|
@ -213,13 +222,15 @@ outdfa()
|
|||
printf("Compacted using row displacement into %d entries\n", maxpos);
|
||||
/* output the arrays */
|
||||
fprintf(ofile, "struct dfa OO_checknext[] = {\n");
|
||||
for(i=0;i<=maxpos;i++) {
|
||||
for (i = 0; i <= maxpos; i++)
|
||||
{
|
||||
fprintf(ofile, "\t/* %4d */\t", i);
|
||||
fprintf(ofile, "{%4d,%4d},\n", check[i], next[i]);
|
||||
}
|
||||
fprintf(ofile, "};\n\n");
|
||||
fprintf(ofile, "struct dfa *OO_base[] = {\n");
|
||||
for(s=0;s<=higheststate;s++) {
|
||||
for (s = 0; s <= higheststate; s++)
|
||||
{
|
||||
fprintf(ofile, "\t/* %4d: ", s);
|
||||
outmnems(patterns[s]);
|
||||
fprintf(ofile, "*/\t");
|
||||
|
@ -230,7 +241,8 @@ outdfa()
|
|||
}
|
||||
fprintf(ofile, "};\n\n");
|
||||
fprintf(ofile, "struct dodefault OO_default[] = {\n");
|
||||
for(s=0;s<=higheststate;s++) {
|
||||
for (s = 0; s <= higheststate; s++)
|
||||
{
|
||||
fprintf(ofile, "\t/* %4d: ", s);
|
||||
outmnems(patterns[s]);
|
||||
fprintf(ofile, "*/\t");
|
||||
|
@ -240,25 +252,24 @@ outdfa()
|
|||
fprintf(ofile, "};\n\n");
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
outmnems(l)
|
||||
struct mnems l;
|
||||
PRIVATE void outmnems(struct mnems l)
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i <= l.m_len; i++)
|
||||
fprintf(ofile, "%s ", l.m_elems[i - 1]->op_code->id_text);
|
||||
}
|
||||
|
||||
PRIVATE int
|
||||
sametest(s1,s2,e1,e2)
|
||||
int s1,s2;
|
||||
struct exp_node *e1,*e2;
|
||||
PRIVATE int sametest(int s1, int s2, struct exp_node *e1, struct exp_node *e2)
|
||||
{
|
||||
/* return 1 if tests are identical */
|
||||
if(e1) {
|
||||
if(!e2) return 0;
|
||||
if(e1->node_type!=e2->node_type) return 0;
|
||||
switch(e1->node_type) {
|
||||
if (e1)
|
||||
{
|
||||
if (!e2)
|
||||
return 0;
|
||||
if (e1->node_type != e2->node_type)
|
||||
return 0;
|
||||
switch (e1->node_type)
|
||||
{
|
||||
case LOGAND:
|
||||
case LOGOR:
|
||||
case BITAND:
|
||||
|
@ -284,8 +295,8 @@ sametest(s1,s2,e1,e2)
|
|||
case ROTATE:
|
||||
case SAMEEXT:
|
||||
case SAMENAM:
|
||||
return (sametest(s1,s2,e1->exp_left,e2->exp_left) &&
|
||||
sametest(s1,s2,e1->exp_right,e2->exp_right));
|
||||
return (sametest(s1, s2, e1->exp_left, e2->exp_left)
|
||||
&& sametest(s1, s2, e1->exp_right, e2->exp_right));
|
||||
case NOT:
|
||||
case COMP:
|
||||
case UPLUS:
|
||||
|
@ -297,11 +308,10 @@ sametest(s1,s2,e1,e2)
|
|||
return (e1->leaf_val == e2->leaf_val);
|
||||
case PATARG:
|
||||
/* depends on pattern !! */
|
||||
if (e1->leaf_val != e2->leaf_val) return 0;
|
||||
return (patterns[s1].m_elems[e1->leaf_val-1]->
|
||||
op_code->id_argfmt
|
||||
== patterns[s2].m_elems[e2->leaf_val-1]->
|
||||
op_code->id_argfmt);
|
||||
if (e1->leaf_val != e2->leaf_val)
|
||||
return 0;
|
||||
return (patterns[s1].m_elems[e1->leaf_val - 1]->op_code->id_argfmt
|
||||
== patterns[s2].m_elems[e2->leaf_val - 1]->op_code->id_argfmt);
|
||||
case PSIZE:
|
||||
case WSIZE:
|
||||
case DWSIZE:
|
||||
|
@ -310,49 +320,54 @@ sametest(s1,s2,e1,e2)
|
|||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
else return (e2==0);
|
||||
else
|
||||
return (e2 == 0);
|
||||
}
|
||||
|
||||
PRIVATE int
|
||||
samerepl(s1,s2,r1,r2)
|
||||
int s1,s2;
|
||||
struct mnems r1,r2;
|
||||
PRIVATE int samerepl(int s1, int s2, struct mnems r1, struct mnems r2)
|
||||
{
|
||||
/* return 1 if replacements are identical */
|
||||
register int i;
|
||||
register struct mnem_elem *m1, *m2;
|
||||
if (r1.m_len != r2.m_len) return 0; /* different length */
|
||||
for(i=0;i<r1.m_len;i++) {
|
||||
if (r1.m_len != r2.m_len)
|
||||
return 0; /* different length */
|
||||
for (i = 0; i < r1.m_len; i++)
|
||||
{
|
||||
m1 = r1.m_elems[i];
|
||||
m2 = r2.m_elems[i];
|
||||
if(m1->op_code!=m2->op_code) return 0;
|
||||
if(!sametest(s1,s2,m1->arg,m2->arg)) return 0;
|
||||
if (m1->op_code != m2->op_code)
|
||||
return 0;
|
||||
if (!sametest(s1, s2, m1->arg, m2->arg))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
PRIVATE int
|
||||
samecode(s1,s2)
|
||||
int s1,s2;
|
||||
PRIVATE int samecode(int s1, int s2)
|
||||
{
|
||||
/* return 1 if replacement code of state s1 and s2 are identical */
|
||||
register struct action *a1, *a2;
|
||||
if (patterns[s1].m_len != patterns[s2].m_len) return 0;
|
||||
if (patterns[s1].m_len != patterns[s2].m_len)
|
||||
return 0;
|
||||
a1 = actions[s1];
|
||||
a2 = actions[s2];
|
||||
while(a1) {
|
||||
if(!a2) return 0; /* a2 is shorter */
|
||||
if(!samerepl(s1,s2,a1->replacement,a2->replacement)) return 0;
|
||||
if(!sametest(s1,s2,a1->test,a2->test)) return 0;
|
||||
while (a1)
|
||||
{
|
||||
if (!a2)
|
||||
return 0; /* a2 is shorter */
|
||||
if (!samerepl(s1, s2, a1->replacement, a2->replacement))
|
||||
return 0;
|
||||
if (!sametest(s1, s2, a1->test, a2->test))
|
||||
return 0;
|
||||
a1 = a1->next;
|
||||
a2 = a2->next;
|
||||
}
|
||||
if(a2) return 0; /* a2 is longer */
|
||||
if (a2)
|
||||
return 0; /* a2 is longer */
|
||||
return 1;
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
outdotrans()
|
||||
PRIVATE void outdotrans(void)
|
||||
{
|
||||
register int s, t;
|
||||
struct action *a;
|
||||
|
@ -361,14 +376,18 @@ outdotrans()
|
|||
fprintf(ofile, "#include \"nopt.h\"\n\n");
|
||||
/* keep track of which procedure used for each state */
|
||||
farray = (int *) Malloc((unsigned) (higheststate + 1) * sizeof(int));
|
||||
for(s=0;s<=higheststate;s++) farray[s] = EMPTY;
|
||||
for (s = 0; s <= higheststate; s++)
|
||||
farray[s] = EMPTY;
|
||||
/* output the functions avoiding duplicates */
|
||||
for(s=0;s<=higheststate;s++) {
|
||||
if(actions[s]!=(struct action *)NULL) {
|
||||
for (s = 0; s <= higheststate; s++)
|
||||
{
|
||||
if (actions[s] != (struct action *) NULL)
|
||||
{
|
||||
/* first look for a previous identical function */
|
||||
for(t=0;t<s;t++) {
|
||||
if(actions[t]!=(struct action *)NULL &&
|
||||
samecode(s,t)) {
|
||||
for (t = 0; t < s; t++)
|
||||
{
|
||||
if (actions[t] != (struct action *) NULL && samecode(s, t))
|
||||
{
|
||||
/* use state 't' instead */
|
||||
farray[s] = t;
|
||||
goto next_func;
|
||||
|
@ -376,14 +395,16 @@ outdotrans()
|
|||
}
|
||||
/* no identical function so make new one */
|
||||
farray[s] = s;
|
||||
fprintf(ofile,"\nstatic do%dtrans() {\n",s);
|
||||
fprintf(ofile, "\nstatic void do%dtrans(void) {\n", s);
|
||||
fprintf(ofile, "\tregister p_instr patt = OO_patternqueue;\n");
|
||||
fprintf(ofile, "\t/* ");
|
||||
outmnems(patterns[s]);
|
||||
fprintf(ofile, " */\n");
|
||||
seennontested = 0;
|
||||
for(a=actions[s];a!=(struct action *)NULL;a=a->next) {
|
||||
if(a->test!=(struct exp_node *)NULL) {
|
||||
for (a = actions[s]; a != (struct action *) NULL; a = a->next)
|
||||
{
|
||||
if (a->test != (struct exp_node *) NULL)
|
||||
{
|
||||
fprintf(ofile, "\tif(");
|
||||
outexp(a->test, s);
|
||||
fprintf(ofile, ") {\n");
|
||||
|
@ -391,9 +412,13 @@ outdotrans()
|
|||
fprintf(ofile, "\t\treturn;\n");
|
||||
fprintf(ofile, "\t}\n");
|
||||
}
|
||||
else {
|
||||
if(seennontested) {
|
||||
fprintf(stderr,"parser: more than one untested action on state %d\n",s);
|
||||
else
|
||||
{
|
||||
if (seennontested)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"parser: more than one untested action on state %d\n",
|
||||
s);
|
||||
nerrors++;
|
||||
}
|
||||
seennontested++;
|
||||
|
@ -402,12 +427,12 @@ outdotrans()
|
|||
}
|
||||
fprintf(ofile, "}\n");
|
||||
}
|
||||
next_func:
|
||||
continue;
|
||||
next_func: continue;
|
||||
}
|
||||
/* output the array itself */
|
||||
fprintf(ofile,"\n\nint (*OO_ftrans[])()=\n{\n");
|
||||
for(s=0;s<=higheststate;s++) {
|
||||
fprintf(ofile, "\n\nvoid (*OO_ftrans[])(void)=\n{\n");
|
||||
for (s = 0; s <= higheststate; s++)
|
||||
{
|
||||
if (farray[s] != EMPTY)
|
||||
fprintf(ofile, "\tdo%dtrans,\n", farray[s]);
|
||||
else
|
||||
|
@ -416,35 +441,31 @@ outdotrans()
|
|||
fprintf(ofile, "};\n");
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
outoneaction(s,a)
|
||||
int s;
|
||||
struct action *a;
|
||||
PRIVATE void outoneaction(int s, struct action *a)
|
||||
{
|
||||
fprintf(ofile, "\t\t/* -> ");
|
||||
outmnems(a->replacement);
|
||||
fprintf(ofile, " */\n");
|
||||
fprintf(ofile, "#ifdef STATS\n");
|
||||
fprintf(ofile,"\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n",a->linenum);
|
||||
fprintf(ofile, "\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n",
|
||||
a->linenum);
|
||||
fprintf(ofile, "#endif\n");
|
||||
outrepl(s, a->replacement);
|
||||
findworst(patterns[s], a->replacement);
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
outrepl(state,repl)
|
||||
int state;
|
||||
struct mnems repl;
|
||||
PRIVATE void outrepl(int state, struct mnems repl)
|
||||
{
|
||||
/*
|
||||
/* Contruct <repl>=r1 r2 ... rn and put on output queue.
|
||||
*/
|
||||
int n = repl.m_len;
|
||||
int i;
|
||||
for(i=1;i<=n;i++) {
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
struct mnem_elem *ri = repl.m_elems[i - 1];
|
||||
char *mnem = ri->op_code->id_text;
|
||||
switch(ri->op_code->id_argfmt) {
|
||||
switch (ri->op_code->id_argfmt)
|
||||
{
|
||||
case NOARG:
|
||||
fprintf(ofile, "\t\tEM_Rop(op_%s);\n", mnem);
|
||||
break;
|
||||
|
@ -455,12 +476,14 @@ outrepl(state,repl)
|
|||
fprintf(ofile, ");\n");
|
||||
break;
|
||||
case CSTOPT:
|
||||
if(ri->arg) {
|
||||
if (ri->arg)
|
||||
{
|
||||
fprintf(ofile, "\t\tEM_Rcst(op_%s,", mnem);
|
||||
fprintf(ofile, "(arith)");
|
||||
outexp(ri->arg, state);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
fprintf(ofile, "\t\tEM_Rnarg(op_%s);\n", mnem);
|
||||
}
|
||||
fprintf(ofile, ");\n");
|
||||
|
@ -489,12 +512,10 @@ outrepl(state,repl)
|
|||
}
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
outexp(e,state)
|
||||
struct exp_node *e;
|
||||
int state;
|
||||
PRIVATE void outexp(struct exp_node *e, int state)
|
||||
{
|
||||
switch (e->node_type)
|
||||
{
|
||||
switch(e->node_type) {
|
||||
case LOGAND:
|
||||
case LOGOR:
|
||||
case BITAND:
|
||||
|
@ -561,9 +582,11 @@ outexp(e,state)
|
|||
fprintf(ofile, ")");
|
||||
break;
|
||||
case PATARG:
|
||||
switch(patterns[state].m_elems[e->leaf_val-1]->op_code->id_argfmt) {
|
||||
switch (patterns[state].m_elems[e->leaf_val - 1]->op_code->id_argfmt)
|
||||
{
|
||||
case NOARG:
|
||||
fprintf(stderr,"error: mnem %d has no argument\n",e->leaf_val);
|
||||
fprintf(stderr, "error: mnem %d has no argument\n",
|
||||
e->leaf_val);
|
||||
nerrors++;
|
||||
break;
|
||||
case CST:
|
||||
|
@ -585,59 +608,117 @@ outexp(e,state)
|
|||
}
|
||||
break;
|
||||
case PSIZE:
|
||||
fprintf(ofile,"OO_PSIZE"); break;
|
||||
fprintf(ofile, "OO_PSIZE");
|
||||
break;
|
||||
case WSIZE:
|
||||
fprintf(ofile,"OO_WSIZE"); break;
|
||||
fprintf(ofile, "OO_WSIZE");
|
||||
break;
|
||||
case DWSIZE:
|
||||
fprintf(ofile,"OO_DWSIZE"); break;
|
||||
fprintf(ofile, "OO_DWSIZE");
|
||||
break;
|
||||
case INT:
|
||||
fprintf(ofile,"%d",e->leaf_val); break;
|
||||
fprintf(ofile, "%d", e->leaf_val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
outext(e)
|
||||
struct exp_node *e;
|
||||
PRIVATE void outext(struct exp_node *e)
|
||||
{
|
||||
if (e->node_type != PATARG)
|
||||
{
|
||||
if(e->node_type!=PATARG) {
|
||||
fprintf(stderr, "Internal error in outext of parser\n");
|
||||
nerrors++;
|
||||
}
|
||||
fprintf(ofile, "patt+%d", e->leaf_val - 1);
|
||||
}
|
||||
|
||||
PRIVATE
|
||||
outop(op)
|
||||
int op;
|
||||
PRIVATE void outop(int op)
|
||||
{
|
||||
switch(op) {
|
||||
case LOGAND: fprintf(ofile,"&&"); break;
|
||||
case LOGOR: fprintf(ofile,"||"); break;
|
||||
case BITAND: fprintf(ofile,"&"); break;
|
||||
case BITOR: fprintf(ofile,"|"); break;
|
||||
case XOR: fprintf(ofile,"^"); break;
|
||||
case MINUS: fprintf(ofile,"-"); break;
|
||||
case PLUS: fprintf(ofile,"+"); break;
|
||||
case TIMES: fprintf(ofile,"*"); break;
|
||||
case DIV: fprintf(ofile,"/"); break;
|
||||
case MOD: fprintf(ofile,"%%"); break;
|
||||
case EQ: fprintf(ofile,"=="); break;
|
||||
case NE: fprintf(ofile,"!="); break;
|
||||
case LT: fprintf(ofile,"<"); break;
|
||||
case LE: fprintf(ofile,"<="); break;
|
||||
case GT: fprintf(ofile,">"); break;
|
||||
case GE: fprintf(ofile,">="); break;
|
||||
case LSHIFT: fprintf(ofile,"<<"); break;
|
||||
case RSHIFT: fprintf(ofile,">>"); break;
|
||||
case NOT: fprintf(ofile,"!"); break;
|
||||
case COMP: fprintf(ofile,"~"); break;
|
||||
case UPLUS: fprintf(ofile,"+"); break;
|
||||
case UMINUS: fprintf(ofile,"-"); break;
|
||||
case SAMESIGN: fprintf(ofile,"OO_signsame("); break;
|
||||
case SFIT: fprintf(ofile,"OO_sfit("); break;
|
||||
case UFIT: fprintf(ofile,"OO_ufit("); break;
|
||||
case ROTATE: fprintf(ofile,"OO_rotate("); break;
|
||||
case SAMEEXT: fprintf(ofile,"OO_extsame("); break;
|
||||
case SAMENAM: fprintf(ofile,"OO_namsame("); break;
|
||||
switch (op)
|
||||
{
|
||||
case LOGAND:
|
||||
fprintf(ofile, "&&");
|
||||
break;
|
||||
case LOGOR:
|
||||
fprintf(ofile, "||");
|
||||
break;
|
||||
case BITAND:
|
||||
fprintf(ofile, "&");
|
||||
break;
|
||||
case BITOR:
|
||||
fprintf(ofile, "|");
|
||||
break;
|
||||
case XOR:
|
||||
fprintf(ofile, "^");
|
||||
break;
|
||||
case MINUS:
|
||||
fprintf(ofile, "-");
|
||||
break;
|
||||
case PLUS:
|
||||
fprintf(ofile, "+");
|
||||
break;
|
||||
case TIMES:
|
||||
fprintf(ofile, "*");
|
||||
break;
|
||||
case DIV:
|
||||
fprintf(ofile, "/");
|
||||
break;
|
||||
case MOD:
|
||||
fprintf(ofile, "%%");
|
||||
break;
|
||||
case EQ:
|
||||
fprintf(ofile, "==");
|
||||
break;
|
||||
case NE:
|
||||
fprintf(ofile, "!=");
|
||||
break;
|
||||
case LT:
|
||||
fprintf(ofile, "<");
|
||||
break;
|
||||
case LE:
|
||||
fprintf(ofile, "<=");
|
||||
break;
|
||||
case GT:
|
||||
fprintf(ofile, ">");
|
||||
break;
|
||||
case GE:
|
||||
fprintf(ofile, ">=");
|
||||
break;
|
||||
case LSHIFT:
|
||||
fprintf(ofile, "<<");
|
||||
break;
|
||||
case RSHIFT:
|
||||
fprintf(ofile, ">>");
|
||||
break;
|
||||
case NOT:
|
||||
fprintf(ofile, "!");
|
||||
break;
|
||||
case COMP:
|
||||
fprintf(ofile, "~");
|
||||
break;
|
||||
case UPLUS:
|
||||
fprintf(ofile, "+");
|
||||
break;
|
||||
case UMINUS:
|
||||
fprintf(ofile, "-");
|
||||
break;
|
||||
case SAMESIGN:
|
||||
fprintf(ofile, "OO_signsame(");
|
||||
break;
|
||||
case SFIT:
|
||||
fprintf(ofile, "OO_sfit(");
|
||||
break;
|
||||
case UFIT:
|
||||
fprintf(ofile, "OO_ufit(");
|
||||
break;
|
||||
case ROTATE:
|
||||
fprintf(ofile, "OO_rotate(");
|
||||
break;
|
||||
case SAMEEXT:
|
||||
fprintf(ofile, "OO_extsame(");
|
||||
break;
|
||||
case SAMENAM:
|
||||
fprintf(ofile, "OO_namsame(");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ static char rcsidp1[] = "$Id$";
|
|||
#endif
|
||||
|
||||
#include "parser.h"
|
||||
#include "alloc.h"
|
||||
|
||||
#define MAXPRIO 11
|
||||
|
||||
|
@ -33,6 +34,20 @@ int nerrors = 0;
|
|||
static int lencurrpatt;
|
||||
static int lenthisrepl;
|
||||
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 */
|
||||
|
@ -326,11 +341,8 @@ binop : LOGAND
|
|||
%lexical yylex;
|
||||
|
||||
{
|
||||
addaction(startline, state, restrictions, finaltest, repllist)
|
||||
int startline;
|
||||
int state;
|
||||
struct exp_node *restrictions, *finaltest;
|
||||
struct mnem_list *repllist;
|
||||
void addaction(int startline, int state, struct exp_node *restrictions,
|
||||
struct exp_node *finaltest, struct mnem_list *repllist)
|
||||
{
|
||||
struct action *p, *q;
|
||||
p=(struct action *)Malloc(sizeof(struct action));
|
||||
|
@ -349,10 +361,7 @@ addaction(startline, state, restrictions, finaltest, repllist)
|
|||
}
|
||||
}
|
||||
|
||||
struct mnem_elem **
|
||||
constructlist(list,len)
|
||||
struct mnem_list *list;
|
||||
int len;
|
||||
struct mnem_elem **constructlist(struct mnem_list *list, int len)
|
||||
{
|
||||
struct mnem_elem **p;
|
||||
p = (struct mnem_elem **)
|
||||
|
@ -364,11 +373,9 @@ constructlist(list,len)
|
|||
return(p);
|
||||
}
|
||||
|
||||
struct mnem_list *
|
||||
addelem(oldlist, mnem, test)
|
||||
struct mnem_list *oldlist;
|
||||
struct idf *mnem;
|
||||
struct exp_node *test;
|
||||
struct mnem_list *addelem(struct mnem_list *oldlist,
|
||||
struct idf *mnem,
|
||||
struct exp_node *test)
|
||||
{
|
||||
struct mnem_list *reslist;
|
||||
struct mnem_elem *element;
|
||||
|
@ -381,12 +388,11 @@ addelem(oldlist, mnem, test)
|
|||
return(reslist);
|
||||
}
|
||||
|
||||
int
|
||||
dotransition(state, mnem, mnem_list, lenlist)
|
||||
int state;
|
||||
struct idf *mnem;
|
||||
struct mnem_list *mnem_list;
|
||||
int lenlist;
|
||||
int dotransition(
|
||||
int state,
|
||||
struct idf *mnem,
|
||||
struct mnem_list *mnem_list,
|
||||
int lenlist)
|
||||
{
|
||||
struct state *p;
|
||||
/* look for existing transition */
|
||||
|
@ -399,7 +405,7 @@ dotransition(state, mnem, mnem_list, lenlist)
|
|||
p=(struct state *)Malloc(sizeof(struct state));
|
||||
p->op=mnem;
|
||||
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);
|
||||
}
|
||||
p->goto_state= higheststate;
|
||||
|
@ -427,7 +433,7 @@ combinetests(test1, test2)
|
|||
return(mknode(LOGAND,test1,test2));
|
||||
}
|
||||
|
||||
priority(op) int op; {
|
||||
int priority(int op) {
|
||||
switch (op) {
|
||||
case LOGOR: return(1);
|
||||
case LOGAND: return(2);
|
||||
|
@ -456,10 +462,8 @@ priority(op) int op; {
|
|||
return(0);
|
||||
}
|
||||
|
||||
struct exp_node *
|
||||
mknode(op,left,right)
|
||||
int op;
|
||||
struct exp_node *left,*right;
|
||||
struct exp_node *mknode(int op, struct exp_node *left,
|
||||
struct exp_node *right)
|
||||
{
|
||||
struct exp_node *p;
|
||||
p = (struct exp_node *)Malloc(sizeof(struct exp_node));
|
||||
|
@ -469,9 +473,7 @@ mknode(op,left,right)
|
|||
return(p);
|
||||
}
|
||||
|
||||
struct exp_node *
|
||||
mkleaf(op,val)
|
||||
int op,val;
|
||||
struct exp_node *mkleaf(int op, int val)
|
||||
{
|
||||
struct exp_node *p;
|
||||
p = (struct exp_node *)Malloc(sizeof(struct exp_node));
|
||||
|
@ -480,8 +482,7 @@ mkleaf(op,val)
|
|||
return(p);
|
||||
}
|
||||
|
||||
LLmessage(insertedtok)
|
||||
int insertedtok;
|
||||
void LLmessage(int insertedtok)
|
||||
{
|
||||
nerrors++;
|
||||
fprintf(stderr,"parser: syntax error on line %d: ",linenum);
|
||||
|
@ -492,7 +493,8 @@ LLmessage(insertedtok)
|
|||
else fprintf(stderr,"Deleted token %d\n",LLsymb);
|
||||
}
|
||||
|
||||
main() {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
initlex();
|
||||
states[0] = (struct state *)NULL;
|
||||
patterns[0].m_len = 0;
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
/* $Id$ */
|
||||
#ifndef PARSER_H_
|
||||
#define PARSER_H_
|
||||
|
||||
#include <stdio.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 linenum; /*line number of input file*/
|
||||
|
||||
/* Functions not returning int */
|
||||
char *Malloc();
|
||||
struct exp_node *mknode();
|
||||
struct exp_node *mkleaf();
|
||||
struct exp_node *combinetests();
|
||||
struct mnem_list *addelem();
|
||||
struct mnem_elem **constructlist();
|
||||
struct exp_node *mknode(int, struct exp_node *, struct exp_node *);
|
||||
struct exp_node *mkleaf(int, int);
|
||||
struct exp_node *combinetests(struct exp_node *, struct exp_node *);
|
||||
struct mnem_list *addelem(struct mnem_list *, struct idf *, struct exp_node *);
|
||||
struct mnem_elem **constructlist(struct mnem_list *, int);
|
||||
void findworst(struct mnems,struct mnems);
|
||||
|
||||
void outputincalls(void);
|
||||
void outputnopt(void);
|
||||
void initlex(void);
|
||||
void findfail(int, int *, int *, int *);
|
||||
|
||||
|
||||
#endif /* PARSER_H_ */
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "Lpars.h"
|
||||
#include "parser.h"
|
||||
|
||||
|
||||
struct idf *opval; /* opcode of returned OPCODE*/
|
||||
int lastintval; /* value of last integer seen */
|
||||
int linenum = 1; /*current line number of input file*/
|
||||
|
@ -59,7 +60,12 @@ offset return(OFFSET);
|
|||
. return(yytext[0]);
|
||||
%%
|
||||
|
||||
back_token()
|
||||
int yywrap(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void back_token(void)
|
||||
{
|
||||
yyless(0);
|
||||
}
|
||||
|
|
|
@ -2,49 +2,42 @@
|
|||
static char rcsid4[] = "$Id$";
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "nopt.h"
|
||||
|
||||
arith
|
||||
OO_rotate(w,amount)
|
||||
arith w, amount;
|
||||
arith OO_rotate(arith w, arith amount)
|
||||
{
|
||||
long highmask, lowmask;
|
||||
highmask = (long) (-1) << amount;
|
||||
lowmask = ~highmask;
|
||||
if (OO_WSIZE != 4)
|
||||
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
|
||||
OO_signsame(a,b)
|
||||
arith a, b;
|
||||
int OO_signsame(arith a, arith b)
|
||||
{
|
||||
return ((a ^ b) >= 0);
|
||||
}
|
||||
|
||||
int
|
||||
OO_sfit(val,nbits)
|
||||
arith val, nbits;
|
||||
int OO_sfit(arith val, arith nbits)
|
||||
{
|
||||
register long mask = ~((1L << (nbits - 1)) - 1);
|
||||
return(((val&mask) == 0) | (val&mask)==mask);
|
||||
return (((val & mask) == 0) | ((val & mask) == mask));
|
||||
}
|
||||
|
||||
int
|
||||
OO_ufit(val, nbits)
|
||||
arith val, nbits;
|
||||
int OO_ufit(arith val, arith nbits)
|
||||
{
|
||||
return ((val & (~((1L << (nbits - 1)) - 1))) == 0);
|
||||
}
|
||||
|
||||
int
|
||||
OO_extsame(a1,a2)
|
||||
register p_instr a1, a2;
|
||||
int OO_extsame(register p_instr a1, register p_instr a2)
|
||||
{
|
||||
if (a1->em_argtype != a2->em_argtype)
|
||||
return (0);
|
||||
switch(a1->em_argtype) {
|
||||
switch (a1->em_argtype)
|
||||
{
|
||||
case cst_ptyp:
|
||||
return (a1->em_cst == a2->em_cst);
|
||||
case sof_ptyp:
|
||||
|
@ -61,13 +54,12 @@ OO_extsame(a1,a2)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
OO_namsame(a1,a2)
|
||||
register p_instr a1, a2;
|
||||
int OO_namsame(register p_instr a1, register p_instr a2)
|
||||
{
|
||||
if (a1->em_argtype != a2->em_argtype)
|
||||
return (0);
|
||||
switch(a1->em_argtype) {
|
||||
switch (a1->em_argtype)
|
||||
{
|
||||
case cst_ptyp:
|
||||
return 1;
|
||||
case sof_ptyp:
|
||||
|
@ -80,11 +72,10 @@ OO_namsame(a1,a2)
|
|||
}
|
||||
}
|
||||
|
||||
arith
|
||||
OO_offset(a)
|
||||
register p_instr a;
|
||||
arith OO_offset(register p_instr a)
|
||||
{
|
||||
switch (a->em_argtype)
|
||||
{
|
||||
switch(a->em_argtype) {
|
||||
case cst_ptyp:
|
||||
return a->em_cst;
|
||||
case sof_ptyp:
|
||||
|
|
Loading…
Reference in a new issue