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)
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 ", " printf ", "
} }
split(parms[p+1],a," ") } else
printf a[1] {
} printf "void"
printf ")\n" paramstr = paramstr "void"
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]
} }
} }
}
}
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,11 +41,8 @@ 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;
@ -65,10 +52,8 @@ EM_mksof(p,opcode,name,off)
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,10 +121,8 @@ 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();
@ -162,8 +133,7 @@ EM_Nsof(opcode,name,off)
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,10 +205,8 @@ 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();
@ -259,8 +217,7 @@ EM_Rsof(opcode,name,off)
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

@ -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++) #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);
@ -59,58 +57,58 @@ O_init(wsize,psize)
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);
@ -118,30 +116,27 @@ fatal(s,a)
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; unsigned newsize = (laststr - strqueue + 1) * 2;
res = Realloc(strqueue, newsize); res = Realloc(strqueue, newsize);
laststr = res + newsize - 1; laststr = res + newsize - 1;
@ -154,16 +149,16 @@ OO_freestr(str)
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;
@ -172,24 +167,25 @@ OO_flush()
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; n = OO_endbackup - OO_nxtpatt;
BTSCPY(p, q, i, OO_buffer, OO_nxtpatt, n); 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;
@ -205,14 +201,10 @@ OO_halfflush()
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; switch (arg->em_argtype)
int opcode;
p_instr arg;
arith off;
{ {
switch(arg->em_argtype) {
case cst_ptyp: case cst_ptyp:
EM_mkcst(p, opcode, off); EM_mkcst(p, opcode, off);
break; break;
@ -227,24 +219,26 @@ OO_mkext(p,opcode,arg,off)
} }
} }
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))
@ -258,7 +252,8 @@ OO_mkrepl(lrepl,diff,numbkup)
} }
} }
/* 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;
@ -275,8 +270,7 @@ OO_mkrepl(lrepl,diff,numbkup)
#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);
@ -287,7 +281,8 @@ dumpstate(mess)
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++);
} }
@ -295,10 +290,10 @@ dumpstate(mess)
} }
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;
@ -324,7 +319,8 @@ prtinst(p)
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:

View file

@ -4,104 +4,124 @@ 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: case NOARG:
fprintf(ofile, "%s\t|\t|\n", s); 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, "\tEM_Nop(op_%s);\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();\n", s); fprintf(ofile, "\tC_%s();\n", s);
} }
break; break;
case CSTOPT: case CSTOPT:
fprintf(ofile, "%s_narg\t|\t|\n", s); 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, "\tEM_Nnarg(op_%s);\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_narg();\n", s); fprintf(ofile, "\tC_%s_narg();\n", s);
} }
/* fall thru */ /* fall thru */
case CST: case CST:
fprintf(ofile, "%s\t| arith:n\t|\n", s); 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, "\tEM_Ncst(op_%s,n);\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(n);\n", s); fprintf(ofile, "\tC_%s(n);\n", s);
} }
break; break;
case DEFILB: case DEFILB:
fprintf(ofile, "df_ilb\t| label:l\t|\n"); 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, "\tEM_Ndefilb(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_df_ilb(l);\n", s); fprintf(ofile, "\tC_df_ilb(l);\n", s);
} }
break; break;
case PNAM: case PNAM:
fprintf(ofile, "%s\t| char *:s\t|\n", s); 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, "\tEM_Npro(op_%s,s);\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(s);\n", s); fprintf(ofile, "\tC_%s(s);\n", s);
} }
break; break;
case LAB: case LAB:
fprintf(ofile, "%s\t| label:l\t|\n", s); 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, "\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(l);\n", s);
} }
break; break;
case EXT: case EXT:
fprintf(ofile, "%s\t| arith:n\t|\n", s); 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, "\tEM_Ncst(op_%s,n);\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(n);\n", s); fprintf(ofile, "\tC_%s(n);\n", s);
} }
fprintf(ofile, "%s_dnam\t| char *:s arith:n\t|\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, "\tEM_Nsof(op_%s,s,n);\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_dnam(s,n);\n", s); fprintf(ofile, "\tC_%s_dnam(s,n);\n", s);
} }
fprintf(ofile, "%s_dlb\t| label:l arith:n\t|\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, "\tEM_Nnof(op_%s,l,n);\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_dlb(l,n);\n", s); fprintf(ofile, "\tC_%s_dlb(l,n);\n", s);
} }

View file

@ -3,25 +3,31 @@ static char rcsidp5[] = "$Id$";
#endif #endif
#include <string.h> #include <string.h>
#include "alloc.h"
#include "parser.h" #include "parser.h"
#include "Lpars.h" #include "Lpars.h"
FILE *ofile; FILE *ofile;
PRIVATE openofile(); PRIVATE void openofile(char *);
PRIVATE installofile(); PRIVATE void installofile(void);
PRIVATE UNLINK(); PRIVATE void UNLINK(char *);
PRIVATE RENAME(); PRIVATE void RENAME(char *, char *);
PRIVATE outdfa(); PRIVATE void increase_next(unsigned int);
PRIVATE outmnems(); PRIVATE void store_row(int, register int *);
PRIVATE outdotrans(); PRIVATE void outdfa(void);
PRIVATE outoneaction(); PRIVATE void outmnems(struct mnems);
PRIVATE outrepl(); PRIVATE int sametest(int, int, struct exp_node *, struct exp_node *);
PRIVATE outexp(); PRIVATE int samerepl(int, int, struct mnems, struct mnems);
PRIVATE outext(); PRIVATE int samecode(int, int);
PRIVATE outop(); 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"); openofile("dfa.c");
outdfa(); outdfa();
@ -37,21 +43,19 @@ outputnopt()
static char ofilename[80]; static char ofilename[80];
static char ofiletemp[80]; static char ofiletemp[80];
PRIVATE PRIVATE void openofile(char *filename)
openofile(filename)
char *filename;
{ {
strcpy(ofilename, filename); strcpy(ofilename, filename);
strcpy(ofiletemp, filename); strcpy(ofiletemp, filename);
strcat(ofiletemp, ".new"); 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); fprintf(stderr, "Fatal Error: cannot open output file %s\n", ofiletemp);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
} }
PRIVATE PRIVATE void installofile(void)
installofile()
{ {
/* /*
* if contents of newly generated ofiletemp is different * if contents of newly generated ofiletemp is different
@ -61,46 +65,46 @@ installofile()
register FILE *f1, *f2; register FILE *f1, *f2;
register int c1, c2; register int c1, c2;
fclose(ofile); fclose(ofile);
if((f1 = fopen(ofiletemp,"r")) == NULL) { if ((f1 = fopen(ofiletemp, "r")) == NULL)
{
fprintf(stderr, "Fatal Error: cannont reopen file %s\n", ofiletemp); fprintf(stderr, "Fatal Error: cannont reopen file %s\n", ofiletemp);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
if((f2 = fopen(ofilename,"r")) == NULL) { if ((f2 = fopen(ofilename, "r")) == NULL)
{
fclose(f1); fclose(f1);
RENAME(ofiletemp, ofilename); RENAME(ofiletemp, ofilename);
return; return;
} }
do { do
{
c1 = getc(f1); c1 = getc(f1);
c2 = getc(f2); c2 = getc(f2);
} while (c1 == c2 && c1 != EOF); } while (c1 == c2 && c1 != EOF);
fclose(f1); fclose(f1);
fclose(f2); fclose(f2);
if (c1 != c2) { if (c1 != c2)
{
RENAME(ofiletemp, ofilename); RENAME(ofiletemp, ofilename);
} }
else UNLINK(ofiletemp); else
UNLINK(ofiletemp);
} }
PRIVATE PRIVATE void UNLINK(char *x)
UNLINK(x)
char *x;
{ {
/* Must remove the file "x" */ /* Must remove the file "x" */
unlink(x); /* systemcall to remove file */ remove(x); /* systemcall to remove file */
} }
PRIVATE PRIVATE void RENAME(char *x, char*y)
RENAME(x,y)
char *x, *y;
{ {
/* Must move the file "x" to the file "y" */ /* Must move the file "x" to the file "y" */
unlink(y); if (rename(x, y) != 0)
if(link(x,y)!=0) { {
fprintf(stderr,"Cannot link to %s",y); fprintf(stderr, "Cannot rename to %s", y);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
unlink(x);
} }
# define MAXOPCODE 255 # define MAXOPCODE 255
@ -110,20 +114,19 @@ int *next, *check, *base;
unsigned currsize; /* current size of next and check arrays */ unsigned currsize; /* current size of next and check arrays */
int maxpos = 0; /* highest used position in these arrayes */ int maxpos = 0; /* highest used position in these arrayes */
PRIVATE PRIVATE void increase_next(unsigned int size)
increase_next(size)
int size;
{ {
/* realloc arrays next and check so they are at least /* realloc arrays next and check so they are at least
* of size 'size' * of size 'size'
*/ */
char *Realloc();
unsigned newsize = currsize; unsigned newsize = currsize;
register int i; register unsigned int i;
do { do
{
newsize *= 2; newsize *= 2;
} while (newsize < size); } 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); next = (int *) Realloc(next, newsize);
check = (int *) Realloc(check, newsize); check = (int *) Realloc(check, newsize);
/* clear ends of new arrays */ /* clear ends of new arrays */
@ -132,39 +135,41 @@ increase_next(size)
currsize = newsize; currsize = newsize;
} }
PRIVATE PRIVATE void store_row(int state, register int *row)
store_row(state,row)
int state;
register int *row;
{ {
/* find a place to store row in arrays */ /* find a place to store row in arrays */
register b,i,o; register int b, i, o;
register int *n = next; register int *n = next;
b = 0; b = 0;
for(;;) { for (;;)
{
/* look for first possible place to store it */ /* look for first possible place to store it */
for(i=0;i<MAXOPCODE;i++) { for (i = 0; i < MAXOPCODE; i++)
if(row[i]) { {
if((o = b+i)>currsize) increase_next(o); if (row[i])
if(n[o]!=EMPTY) goto nextpos; {
if ((o = b + i) > currsize)
increase_next(o);
if (n[o] != EMPTY)
goto nextpos;
} }
} }
/* found a place */ /* found a place */
base[state] = b; base[state] = b;
for (i = 0; i < MAXOPCODE; i++) for (i = 0; i < MAXOPCODE; i++)
if(row[i]) { if (row[i])
if((o=b+i) >maxpos) maxpos = o; {
if ((o = b + i) > maxpos)
maxpos = o;
next[o] = row[i]; next[o] = row[i];
check[o] = state; check[o] = state;
} }
return; return;
nextpos: nextpos: ++b;
++b;
} }
} }
PRIVATE PRIVATE void outdfa(void)
outdfa()
{ {
register int s, i; register int s, i;
register struct state *p; register struct state *p;
@ -188,13 +193,17 @@ outdfa()
check = (int *) Malloc(currsize * sizeof(int)); check = (int *) Malloc(currsize * sizeof(int));
base = (int *) Malloc(((unsigned) (higheststate + 1)) * sizeof(int)); base = (int *) Malloc(((unsigned) (higheststate + 1)) * sizeof(int));
/* fill next array with EMPTY */ /* fill next array with EMPTY */
for(i=0;i<currsize;i++) check[i]=next[i]=EMPTY; for (i = 0; i < currsize; i++)
for(s=0;s<=higheststate;s++) { check[i] = next[i] = EMPTY;
for (s = 0; s <= higheststate; s++)
{
/* empty row */ /* empty row */
for(i=0;i<MAXOPCODE;i++) row[i]=0; for (i = 0; i < MAXOPCODE; i++)
row[i] = 0;
numinrow = 0; numinrow = 0;
/* fill in non zero entries */ /* 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++; numinrow++;
row[p->op->id_opcode] = p->goto_state; row[p->op->id_opcode] = p->goto_state;
} }
@ -213,13 +222,15 @@ outdfa()
printf("Compacted using row displacement into %d entries\n", maxpos); printf("Compacted using row displacement into %d entries\n", maxpos);
/* output the arrays */ /* output the arrays */
fprintf(ofile, "struct dfa OO_checknext[] = {\n"); 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, "\t/* %4d */\t", i);
fprintf(ofile, "{%4d,%4d},\n", check[i], next[i]); fprintf(ofile, "{%4d,%4d},\n", check[i], next[i]);
} }
fprintf(ofile, "};\n\n"); fprintf(ofile, "};\n\n");
fprintf(ofile, "struct dfa *OO_base[] = {\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); fprintf(ofile, "\t/* %4d: ", s);
outmnems(patterns[s]); outmnems(patterns[s]);
fprintf(ofile, "*/\t"); fprintf(ofile, "*/\t");
@ -230,7 +241,8 @@ outdfa()
} }
fprintf(ofile, "};\n\n"); fprintf(ofile, "};\n\n");
fprintf(ofile, "struct dodefault OO_default[] = {\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); fprintf(ofile, "\t/* %4d: ", s);
outmnems(patterns[s]); outmnems(patterns[s]);
fprintf(ofile, "*/\t"); fprintf(ofile, "*/\t");
@ -240,25 +252,24 @@ outdfa()
fprintf(ofile, "};\n\n"); fprintf(ofile, "};\n\n");
} }
PRIVATE PRIVATE void outmnems(struct mnems l)
outmnems(l)
struct mnems l;
{ {
int i; int i;
for (i = 1; i <= l.m_len; i++) for (i = 1; i <= l.m_len; i++)
fprintf(ofile, "%s ", l.m_elems[i - 1]->op_code->id_text); fprintf(ofile, "%s ", l.m_elems[i - 1]->op_code->id_text);
} }
PRIVATE int PRIVATE int sametest(int s1, int s2, struct exp_node *e1, struct exp_node *e2)
sametest(s1,s2,e1,e2)
int s1,s2;
struct exp_node *e1,*e2;
{ {
/* return 1 if tests are identical */ /* return 1 if tests are identical */
if(e1) { if (e1)
if(!e2) return 0; {
if(e1->node_type!=e2->node_type) return 0; if (!e2)
switch(e1->node_type) { return 0;
if (e1->node_type != e2->node_type)
return 0;
switch (e1->node_type)
{
case LOGAND: case LOGAND:
case LOGOR: case LOGOR:
case BITAND: case BITAND:
@ -284,8 +295,8 @@ sametest(s1,s2,e1,e2)
case ROTATE: case ROTATE:
case SAMEEXT: case SAMEEXT:
case SAMENAM: case SAMENAM:
return (sametest(s1,s2,e1->exp_left,e2->exp_left) && return (sametest(s1, s2, e1->exp_left, e2->exp_left)
sametest(s1,s2,e1->exp_right,e2->exp_right)); && sametest(s1, s2, e1->exp_right, e2->exp_right));
case NOT: case NOT:
case COMP: case COMP:
case UPLUS: case UPLUS:
@ -297,11 +308,10 @@ sametest(s1,s2,e1,e2)
return (e1->leaf_val == e2->leaf_val); return (e1->leaf_val == e2->leaf_val);
case PATARG: case PATARG:
/* depends on pattern !! */ /* depends on pattern !! */
if (e1->leaf_val != e2->leaf_val) return 0; if (e1->leaf_val != e2->leaf_val)
return (patterns[s1].m_elems[e1->leaf_val-1]-> return 0;
op_code->id_argfmt return (patterns[s1].m_elems[e1->leaf_val - 1]->op_code->id_argfmt
== patterns[s2].m_elems[e2->leaf_val-1]-> == patterns[s2].m_elems[e2->leaf_val - 1]->op_code->id_argfmt);
op_code->id_argfmt);
case PSIZE: case PSIZE:
case WSIZE: case WSIZE:
case DWSIZE: case DWSIZE:
@ -310,49 +320,54 @@ sametest(s1,s2,e1,e2)
} }
/*NOTREACHED*/ /*NOTREACHED*/
} }
else return (e2==0); else
return (e2 == 0);
} }
PRIVATE int PRIVATE int samerepl(int s1, int s2, struct mnems r1, struct mnems r2)
samerepl(s1,s2,r1,r2)
int s1,s2;
struct mnems r1,r2;
{ {
/* return 1 if replacements are identical */ /* return 1 if replacements are identical */
register int i; register int i;
register struct mnem_elem *m1, *m2; register struct mnem_elem *m1, *m2;
if (r1.m_len != r2.m_len) return 0; /* different length */ if (r1.m_len != r2.m_len)
for(i=0;i<r1.m_len;i++) { return 0; /* different length */
for (i = 0; i < r1.m_len; i++)
{
m1 = r1.m_elems[i]; m1 = r1.m_elems[i];
m2 = r2.m_elems[i]; m2 = r2.m_elems[i];
if(m1->op_code!=m2->op_code) return 0; if (m1->op_code != m2->op_code)
if(!sametest(s1,s2,m1->arg,m2->arg)) return 0; return 0;
if (!sametest(s1, s2, m1->arg, m2->arg))
return 0;
} }
return 1; return 1;
} }
PRIVATE int PRIVATE int samecode(int s1, int s2)
samecode(s1,s2)
int s1,s2;
{ {
/* return 1 if replacement code of state s1 and s2 are identical */ /* return 1 if replacement code of state s1 and s2 are identical */
register struct action *a1, *a2; 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]; a1 = actions[s1];
a2 = actions[s2]; a2 = actions[s2];
while(a1) { while (a1)
if(!a2) return 0; /* a2 is shorter */ {
if(!samerepl(s1,s2,a1->replacement,a2->replacement)) return 0; if (!a2)
if(!sametest(s1,s2,a1->test,a2->test)) return 0; 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; a1 = a1->next;
a2 = a2->next; a2 = a2->next;
} }
if(a2) return 0; /* a2 is longer */ if (a2)
return 0; /* a2 is longer */
return 1; return 1;
} }
PRIVATE PRIVATE void outdotrans(void)
outdotrans()
{ {
register int s, t; register int s, t;
struct action *a; struct action *a;
@ -361,14 +376,18 @@ outdotrans()
fprintf(ofile, "#include \"nopt.h\"\n\n"); fprintf(ofile, "#include \"nopt.h\"\n\n");
/* keep track of which procedure used for each state */ /* keep track of which procedure used for each state */
farray = (int *) Malloc((unsigned) (higheststate + 1) * sizeof(int)); 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 */ /* output the functions avoiding duplicates */
for(s=0;s<=higheststate;s++) { for (s = 0; s <= higheststate; s++)
if(actions[s]!=(struct action *)NULL) { {
if (actions[s] != (struct action *) NULL)
{
/* first look for a previous identical function */ /* first look for a previous identical function */
for(t=0;t<s;t++) { for (t = 0; t < s; t++)
if(actions[t]!=(struct action *)NULL && {
samecode(s,t)) { if (actions[t] != (struct action *) NULL && samecode(s, t))
{
/* use state 't' instead */ /* use state 't' instead */
farray[s] = t; farray[s] = t;
goto next_func; goto next_func;
@ -376,14 +395,16 @@ outdotrans()
} }
/* no identical function so make new one */ /* no identical function so make new one */
farray[s] = s; 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, "\tregister p_instr patt = OO_patternqueue;\n");
fprintf(ofile, "\t/* "); fprintf(ofile, "\t/* ");
outmnems(patterns[s]); outmnems(patterns[s]);
fprintf(ofile, " */\n"); fprintf(ofile, " */\n");
seennontested = 0; seennontested = 0;
for(a=actions[s];a!=(struct action *)NULL;a=a->next) { for (a = actions[s]; a != (struct action *) NULL; a = a->next)
if(a->test!=(struct exp_node *)NULL) { {
if (a->test != (struct exp_node *) NULL)
{
fprintf(ofile, "\tif("); fprintf(ofile, "\tif(");
outexp(a->test, s); outexp(a->test, s);
fprintf(ofile, ") {\n"); fprintf(ofile, ") {\n");
@ -391,9 +412,13 @@ outdotrans()
fprintf(ofile, "\t\treturn;\n"); fprintf(ofile, "\t\treturn;\n");
fprintf(ofile, "\t}\n"); fprintf(ofile, "\t}\n");
} }
else { else
if(seennontested) { {
fprintf(stderr,"parser: more than one untested action on state %d\n",s); if (seennontested)
{
fprintf(stderr,
"parser: more than one untested action on state %d\n",
s);
nerrors++; nerrors++;
} }
seennontested++; seennontested++;
@ -402,12 +427,12 @@ outdotrans()
} }
fprintf(ofile, "}\n"); fprintf(ofile, "}\n");
} }
next_func: next_func: continue;
continue;
} }
/* output the array itself */ /* output the array itself */
fprintf(ofile,"\n\nint (*OO_ftrans[])()=\n{\n"); fprintf(ofile, "\n\nvoid (*OO_ftrans[])(void)=\n{\n");
for(s=0;s<=higheststate;s++) { for (s = 0; s <= higheststate; s++)
{
if (farray[s] != EMPTY) if (farray[s] != EMPTY)
fprintf(ofile, "\tdo%dtrans,\n", farray[s]); fprintf(ofile, "\tdo%dtrans,\n", farray[s]);
else else
@ -416,35 +441,31 @@ outdotrans()
fprintf(ofile, "};\n"); fprintf(ofile, "};\n");
} }
PRIVATE PRIVATE void outoneaction(int s, struct action *a)
outoneaction(s,a)
int s;
struct action *a;
{ {
fprintf(ofile, "\t\t/* -> "); fprintf(ofile, "\t\t/* -> ");
outmnems(a->replacement); outmnems(a->replacement);
fprintf(ofile, " */\n"); fprintf(ofile, " */\n");
fprintf(ofile, "#ifdef STATS\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"); fprintf(ofile, "#endif\n");
outrepl(s, a->replacement); outrepl(s, a->replacement);
findworst(patterns[s], a->replacement); findworst(patterns[s], a->replacement);
} }
PRIVATE PRIVATE void outrepl(int state, struct mnems repl)
outrepl(state,repl)
int state;
struct mnems repl;
{ {
/*
/* Contruct <repl>=r1 r2 ... rn and put on output queue. /* Contruct <repl>=r1 r2 ... rn and put on output queue.
*/ */
int n = repl.m_len; int n = repl.m_len;
int i; int i;
for(i=1;i<=n;i++) { for (i = 1; i <= n; i++)
{
struct mnem_elem *ri = repl.m_elems[i - 1]; struct mnem_elem *ri = repl.m_elems[i - 1];
char *mnem = ri->op_code->id_text; char *mnem = ri->op_code->id_text;
switch(ri->op_code->id_argfmt) { switch (ri->op_code->id_argfmt)
{
case NOARG: case NOARG:
fprintf(ofile, "\t\tEM_Rop(op_%s);\n", mnem); fprintf(ofile, "\t\tEM_Rop(op_%s);\n", mnem);
break; break;
@ -455,12 +476,14 @@ outrepl(state,repl)
fprintf(ofile, ");\n"); fprintf(ofile, ");\n");
break; break;
case CSTOPT: case CSTOPT:
if(ri->arg) { if (ri->arg)
{
fprintf(ofile, "\t\tEM_Rcst(op_%s,", mnem); fprintf(ofile, "\t\tEM_Rcst(op_%s,", mnem);
fprintf(ofile, "(arith)"); fprintf(ofile, "(arith)");
outexp(ri->arg, state); outexp(ri->arg, state);
} }
else { else
{
fprintf(ofile, "\t\tEM_Rnarg(op_%s);\n", mnem); fprintf(ofile, "\t\tEM_Rnarg(op_%s);\n", mnem);
} }
fprintf(ofile, ");\n"); fprintf(ofile, ");\n");
@ -489,12 +512,10 @@ outrepl(state,repl)
} }
} }
PRIVATE PRIVATE void outexp(struct exp_node *e, int state)
outexp(e,state) {
struct exp_node *e; switch (e->node_type)
int state;
{ {
switch(e->node_type) {
case LOGAND: case LOGAND:
case LOGOR: case LOGOR:
case BITAND: case BITAND:
@ -561,9 +582,11 @@ outexp(e,state)
fprintf(ofile, ")"); fprintf(ofile, ")");
break; break;
case PATARG: 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: 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++; nerrors++;
break; break;
case CST: case CST:
@ -585,59 +608,117 @@ outexp(e,state)
} }
break; break;
case PSIZE: case PSIZE:
fprintf(ofile,"OO_PSIZE"); break; fprintf(ofile, "OO_PSIZE");
break;
case WSIZE: case WSIZE:
fprintf(ofile,"OO_WSIZE"); break; fprintf(ofile, "OO_WSIZE");
break;
case DWSIZE: case DWSIZE:
fprintf(ofile,"OO_DWSIZE"); break; fprintf(ofile, "OO_DWSIZE");
break;
case INT: case INT:
fprintf(ofile,"%d",e->leaf_val); break; fprintf(ofile, "%d", e->leaf_val);
break;
} }
} }
PRIVATE PRIVATE void outext(struct exp_node *e)
outext(e) {
struct exp_node *e; if (e->node_type != PATARG)
{ {
if(e->node_type!=PATARG) {
fprintf(stderr, "Internal error in outext of parser\n"); fprintf(stderr, "Internal error in outext of parser\n");
nerrors++; nerrors++;
} }
fprintf(ofile, "patt+%d", e->leaf_val - 1); fprintf(ofile, "patt+%d", e->leaf_val - 1);
} }
PRIVATE PRIVATE void outop(int op)
outop(op)
int op;
{ {
switch(op) { switch (op)
case LOGAND: fprintf(ofile,"&&"); break; {
case LOGOR: fprintf(ofile,"||"); break; case LOGAND:
case BITAND: fprintf(ofile,"&"); break; fprintf(ofile, "&&");
case BITOR: fprintf(ofile,"|"); break; break;
case XOR: fprintf(ofile,"^"); break; case LOGOR:
case MINUS: fprintf(ofile,"-"); break; fprintf(ofile, "||");
case PLUS: fprintf(ofile,"+"); break; break;
case TIMES: fprintf(ofile,"*"); break; case BITAND:
case DIV: fprintf(ofile,"/"); break; fprintf(ofile, "&");
case MOD: fprintf(ofile,"%%"); break; break;
case EQ: fprintf(ofile,"=="); break; case BITOR:
case NE: fprintf(ofile,"!="); break; fprintf(ofile, "|");
case LT: fprintf(ofile,"<"); break; break;
case LE: fprintf(ofile,"<="); break; case XOR:
case GT: fprintf(ofile,">"); break; fprintf(ofile, "^");
case GE: fprintf(ofile,">="); break; break;
case LSHIFT: fprintf(ofile,"<<"); break; case MINUS:
case RSHIFT: fprintf(ofile,">>"); break; fprintf(ofile, "-");
case NOT: fprintf(ofile,"!"); break; break;
case COMP: fprintf(ofile,"~"); break; case PLUS:
case UPLUS: fprintf(ofile,"+"); break; fprintf(ofile, "+");
case UMINUS: fprintf(ofile,"-"); break; break;
case SAMESIGN: fprintf(ofile,"OO_signsame("); break; case TIMES:
case SFIT: fprintf(ofile,"OO_sfit("); break; fprintf(ofile, "*");
case UFIT: fprintf(ofile,"OO_ufit("); break; break;
case ROTATE: fprintf(ofile,"OO_rotate("); break; case DIV:
case SAMEEXT: fprintf(ofile,"OO_extsame("); break; fprintf(ofile, "/");
case SAMENAM: fprintf(ofile,"OO_namsame("); break; 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;
} }
} }

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,49 +2,42 @@
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: case cst_ptyp:
return (a1->em_cst == a2->em_cst); return (a1->em_cst == a2->em_cst);
case sof_ptyp: case sof_ptyp:
@ -61,13 +54,12 @@ OO_extsame(a1,a2)
} }
} }
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: case cst_ptyp:
return 1; return 1;
case sof_ptyp: case sof_ptyp:
@ -80,11 +72,10 @@ OO_namsame(a1,a2)
} }
} }
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: case cst_ptyp:
return a->em_cst; return a->em_cst;
case sof_ptyp: case sof_ptyp: