Major change: All queues now in same buffer

This commit is contained in:
bruce 1987-07-21 13:23:09 +00:00
parent 3929b47776
commit 1c1eed4fd8
11 changed files with 308 additions and 331 deletions

View file

@ -1,5 +1,5 @@
# $Header$ # $Header$
EMHOME = ../../.. EMHOME = /proj/em/Work
INSTALL = $(EMHOME)/modules/install INSTALL = $(EMHOME)/modules/install
COMPARE = $(EMHOME)/modules/compare COMPARE = $(EMHOME)/modules/compare
LINT = lint LINT = lint
@ -35,7 +35,7 @@ CSRC = main.c nopt.c mkstrct.c aux.c outputdfa.c outcalls.c\
SRCS = Makefile nopt.h parser.h parser.g syntax.l pseudo.r\ SRCS = Makefile nopt.h parser.h parser.g syntax.l pseudo.r\
patterns $(CSRC) patterns $(CSRC)
NOFILES = nopt.o dfa.o trans.o aux.o NOFILES = nopt.o mkstrct.o dfa.o trans.o aux.o
POFILES = parser.o syntax.o outputdfa.o outcalls.o findworst.o\ POFILES = parser.o syntax.o outputdfa.o outcalls.o findworst.o\
initlex.o Lpars.o initlex.o Lpars.o
@ -77,13 +77,14 @@ NOPTLIB = $(EMHOME)/modules/lib/libread_emk.a\
$(EMHOME)/modules/lib/libemk.a\ $(EMHOME)/modules/lib/libemk.a\
$(EMHOME)/modules/lib/liballoc.a\ $(EMHOME)/modules/lib/liballoc.a\
$(EMHOME)/modules/lib/malloc.o\ $(EMHOME)/modules/lib/malloc.o\
$(EMHOME)/modules/lib/libstring.a\
$(EMHOME)/modules/lib/libsystem.a\ $(EMHOME)/modules/lib/libsystem.a\
$(EMHOME)/lib/em_data.a $(EMHOME)/lib/em_data.a
em_nopt: dfadummy main.o $(NOFILES) em_nopt: dfadummy main.o $(NOFILES)
$(CC) -o em_nopt main.o $(NOFILES) $(NOPTLIB) $(CC) -o em_nopt main.o $(NOFILES) $(NOPTLIB)
OLINT = main.c nopt.c aux.c dfa.c trans.c OLINT = main.c mkstrct.c nopt.c aux.c dfa.c trans.c
OLINTLIB = $(EMHOME)/modules/lib/llib-lread_emkV.ln\ OLINTLIB = $(EMHOME)/modules/lib/llib-lread_emkV.ln\
$(EMHOME)/modules/lib/llib-lemk.ln\ $(EMHOME)/modules/lib/llib-lemk.ln\

View file

@ -30,7 +30,7 @@ findworst(repl)
int s; int s;
int mostbackups = 0; int mostbackups = 0;
if(n==0) { if(n==0) {
fprintf(ofile,"\t\tOO_backup(%d);\n", longestpattern-1); fprintf(ofile,"\t\tOO_backup(%d);\n", maxpattern-1);
return; return;
} }
for(s=1;s<=higheststate;s++) { for(s=1;s<=higheststate;s++) {
@ -56,8 +56,7 @@ findworst(repl)
} }
} }
} }
if(mostbackups) fprintf(ofile,"\t\tOO_backup(%d);\n",mostbackups);
fprintf(ofile,"\t\tOO_backup(%d);\n",mostbackups);
} }
findfail(state,resout,rescpy,resgto) findfail(state,resout,rescpy,resgto)

View file

@ -18,7 +18,8 @@ int errors; /* Number of errors */
main(argc,argv) main(argc,argv)
char **argv; char **argv;
{ {
register p_instr p = GETINSTR(); static struct e_instr buff;
register p_instr p = &buff;
if (argc >= 2) { if (argc >= 2) {
filename = argv[1]; filename = argv[1];
@ -36,11 +37,13 @@ main(argc,argv)
} }
else if (!O_open( (char *) 0)) fatal("O_open failed"); else if (!O_open( (char *) 0)) fatal("O_open failed");
O_magic(); O_magic();
EM_mkcalls(p);
for(;;) { for(;;) {
EM_getinstr(p=GETNXTPATT());
switch(p->em_type) { switch(p->em_type) {
case EM_DEFILB: case EM_DEFILB:
*OO_nxtpatt++ = p; p->em_opcode=op_lab;
OO_dfa(p->em_opcode=op_lab);
break; break;
case EM_MNEM: case EM_MNEM:
switch(p->em_argtype) { switch(p->em_argtype) {
@ -57,23 +60,31 @@ main(argc,argv)
p->em_string = OO_freestr(p->em_string); p->em_string = OO_freestr(p->em_string);
break; break;
} }
*OO_nxtpatt++ = p;
OO_dfa(p->em_opcode);
break; break;
default: default:
FLUSHDFA(); p->em_opcode = OTHER;
EM_mkcalls(p); /* fall thru */
OO_free(p); if (OO_state) {
buff = *p;
OO_dfa(OTHER);
EM_mkcalls(&buff);
}
else {
OO_flush();
EM_mkcalls(p);
}
continue;
case EM_PSEU:
break; break;
case EM_EOF: case EM_EOF:
goto got_eof; goto got_eof;
case EM_ERROR: case EM_ERROR:
error("%s", EM_error); error("%s", EM_error);
break; continue;
case EM_FATAL: case EM_FATAL:
fatal("%s", EM_error); fatal("%s", EM_error);
} }
EM_getinstr(p=GETINSTR()); OO_dfa(p->em_opcode);
} }
got_eof: got_eof:
O_close(); O_close();

View file

@ -4,87 +4,92 @@ static char rcsid3[] = "$Header$";
#include "nopt.h" #include "nopt.h"
OO_inop(opcode) EM_mkop(p,opcode)
register p_instr p;
int opcode; int opcode;
{ {
register p_instr p = GETINSTR();
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;
*OO_nxtpatt++ = p;
} }
OO_incst(opcode,cst) EM_mknarg(p,opcode)
int opcode,cst; register p_instr p;
int opcode;
{ {
register p_instr p = GETINSTR();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_opcode = opcode; p->em_opcode = opcode;
p->em_argtype = cst_ptyp; p->em_argtype = 0;
p->em_cst = cst; p->em_cst = 0;
*OO_nxtpatt++ = p;
} }
OO_inlab(opcode,lab) EM_mkilb(p,opcode,lab)
int opcode,lab; register p_instr p;
int opcode;
label lab;
{ {
register p_instr p = GETINSTR();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = ilb_ptyp; p->em_argtype = ilb_ptyp;
p->em_opcode = opcode;
p->em_ilb = lab; p->em_ilb = lab;
*OO_nxtpatt++ = p;
} }
OO_inpnam(opcode,pnam) EM_mknof(p,opcode,lab,off)
register p_instr p;
int opcode;
label lab;
arith off;
{
p->em_type = EM_MNEM;
p->em_argtype = nof_ptyp;
p->em_opcode = opcode;
p->em_dlb = lab;
p->em_off = off;
}
EM_mksof(p,opcode,name,off)
register p_instr p;
int opcode;
char *name;
arith off;
{
p->em_type = EM_MNEM;
p->em_argtype = sof_ptyp;
p->em_opcode = opcode;
p->em_dnam = OO_freestr(name);
p->em_off = off;
}
EM_mkcst(p,opcode,cst)
register p_instr p;
int opcode;
arith cst;
{
p->em_type = EM_MNEM;
p->em_argtype = cst_ptyp;
p->em_opcode = opcode;
p->em_cst = cst;
}
EM_mkpro(p,opcode,pnam)
register p_instr p;
int opcode; int opcode;
char *pnam; char *pnam;
{ {
register p_instr p = GETINSTR();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = pro_ptyp; p->em_argtype = pro_ptyp;
p->em_opcode = opcode;
p->em_pnam = OO_freestr(pnam); p->em_pnam = OO_freestr(pnam);
*OO_nxtpatt++ = p;
} }
OO_indefilb(opcode,deflb) EM_mkdefilb(p,opcode,deflb)
register p_instr p;
int opcode; int opcode;
label deflb; label deflb;
{ {
register p_instr p = GETINSTR();
p->em_type = EM_DEFILB; p->em_type = EM_DEFILB;
p->em_opcode = opcode; p->em_opcode = opcode;
p->em_argtype = 0; p->em_argtype = 0;
p->em_ilb = deflb; p->em_ilb = deflb;
*OO_nxtpatt++ = p;
}
OO_indnam(opcode,name,off)
int opcode;
char *name;
int off;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = sof_ptyp;
p->em_dnam = OO_freestr(name);
p->em_off = off;
*OO_nxtpatt++ = p;
}
OO_indlb(opcode,lab,off)
int opcode;
label lab;
int off;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = nof_ptyp;
p->em_dlb = lab;
p->em_off = off;
*OO_nxtpatt++ = p;
} }

View file

@ -6,36 +6,39 @@ static char rcsid2[] = "$Header$";
extern int (*OO_fstate[])(); /* Initialized from patterns in dfa.c */ extern int (*OO_fstate[])(); /* Initialized from patterns in dfa.c */
extern int OO_maxpattern; /* Initialized from patterns in dfa.c */ extern int OO_maxpattern; /* Initialized from patterns in dfa.c */
#define MAXBACKUP 50 extern int OO_maxreplacement; /* Initialized from patterns in dfa.c */
#define MAXOUTPUT 200
#define MAXSTRING 1000
extern char em_mnem[][4]; extern char em_mnem[][4];
extern char em_pseu[][4]; extern char em_pseu[][4];
p_instr OO_freeq; p_instr OO_buffer;
p_instr *OO_patternqueue; p_instr OO_patternqueue;
p_instr *OO_nxtpatt; p_instr OO_nxtpatt;
p_instr *OO_bkupqueue; p_instr OO_endbackup;
p_instr *OO_nxtbackup; p_instr OO_nxtrepl;
p_instr OO_OTHER; static p_instr OO_replqueue;
static char *filename; static char *filename;
static p_instr *lastbackup;
static p_instr *outputqueue;
static p_instr *nextoutput;
static p_instr *lastoutput;
static char *strqueue; static char *strqueue;
static char *nextstr; static char *nextstr;
static char *laststr; static char *laststr;
int OO_noutput; /* number of instructions in output queue */
arith OO_WSIZE; /* wordlength */ arith OO_WSIZE; /* wordlength */
arith OO_PSIZE; /* pointer length */ arith OO_PSIZE; /* pointer length */
#ifdef STATS #ifdef STATS
int OO_wrstats = 1; /* pattern statistics output */ int OO_wrstats = 1; /* pattern statistics output */
#endif #endif
#ifdef DEBUG
#define printstate(s) dumpstate(s)
#else
#define printstate(s)
#endif DEBUG
/**** WHICH IS FASTER? ****
#define BTSCPY(pp,qq,i,p,q,n) btscpy(p,q,(n)*sizeof(struct e_instr))
**************************/
#define BTSCPY(pp,qq,i,p,q,n) for(pp=(p),qq=(q),i=(n);i--;*pp++ = *qq++)
O_init(wsize,psize) O_init(wsize,psize)
arith wsize, psize; arith wsize, psize;
@ -67,10 +70,12 @@ OO_dfa(last)
register int last; register int last;
{ {
for(;;) { for(;;) {
printstate("OO_dfa");
(*OO_fstate[OO_state])(last); (*OO_fstate[OO_state])(last);
if (OO_nxtbackup==OO_bkupqueue) if (!OO_endbackup) return;
return; last = (OO_nxtpatt++)->em_opcode;
last = ((*OO_nxtpatt++ = *(--OO_nxtbackup))->em_opcode); if (OO_nxtpatt >= OO_endbackup)
OO_endbackup = 0;
} }
} }
@ -89,34 +94,15 @@ PRIVATE
allocmem() allocmem()
{ {
/* Allocate memory for queues on heap */ /* Allocate memory for queues on heap */
OO_nxtpatt = OO_patternqueue = OO_buffer = (p_instr)
(p_instr *)Malloc(OO_maxpattern*sizeof(p_instr)); Malloc((unsigned)(MAXBUFFER*sizeof(struct e_instr)));
OO_nxtbackup = OO_bkupqueue = OO_patternqueue = OO_nxtpatt = OO_buffer;
(p_instr *)Malloc(MAXBACKUP*sizeof(p_instr)); OO_replqueue = (p_instr)
lastbackup = OO_bkupqueue + MAXBACKUP - 1; Malloc((unsigned)OO_maxreplacement*sizeof(struct e_instr));
nextoutput = outputqueue = OO_nxtrepl = OO_replqueue;
(p_instr *)Malloc(MAXOUTPUT*sizeof(p_instr));
lastoutput = outputqueue + MAXOUTPUT - 1;
OO_noutput = 0;
nextstr = strqueue = nextstr = strqueue =
(char *)Malloc(MAXSTRING*sizeof(char)); (char *)Malloc(MAXSTRING*sizeof(char));
laststr = strqueue + MAXSTRING - 1; laststr = strqueue + MAXSTRING - 1;
/* allocate dummy OTHER data structure */
OO_OTHER = (p_instr)Malloc(sizeof(struct e_instr));
OO_OTHER->em_type = EM_MNEM;
OO_OTHER->em_opcode = OTHER;
OO_OTHER->em_argtype = 0;
}
OO_nfree(n)
register int n;
{
register p_instr *p = OO_nxtpatt = OO_patternqueue;
while(n--) {
OO_free(*p); /* OO_free is macro so don't use *p++ */
p++;
}
OO_state = 0;
} }
char * char *
@ -150,235 +136,196 @@ 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 int n; register p_instr p,q;
register p_instr *p; register int i,n;
#ifdef DEBUG
printstate("Flush"); printstate("Flush");
#endif for(p=OO_buffer;p<OO_patternqueue;p++)
if (n = OO_noutput) { EM_mkcalls(p);
for(p=outputqueue;n--;p++) { if(p->em_opcode!=OTHER)
EM_mkcalls(*p); EM_mkcalls(p);
OO_free(*p); if(OO_endbackup) {
} n = OO_endbackup-OO_nxtpatt;
nextoutput=outputqueue; BTSCPY(p,q,i,OO_buffer,OO_nxtpatt,n);
if(OO_nxtbackup==OO_bkupqueue) OO_endbackup = OO_buffer + n;
nextstr = strqueue;
OO_noutput = 0;
} }
else nextstr = strqueue;
OO_patternqueue = OO_nxtpatt = OO_buffer;
} }
OO_out(p) p_instr
p_instr p; OO_halfflush()
{ {
/* Put the instruction p on the output queue */ /*
if(nextoutput > lastoutput) { /* Called when buffer full, flush half the buffer and move the
#ifdef DEBUG /* the pattern pointers to the new positions. Return a pointer
fprintf(stderr,"Warning: Overflow of outputqueue - output flushed\n"); /* to the new nxtpatt position and increment it.
#endif /* Note that OO_endbackup is always NIL (i.e. there are no
OO_flush(); /* instructions on the backup queue) when this is invoked.
} */
OO_noutput++; register int i,n;
*nextoutput++ = p; register p_instr p,q;
printstate("Half flush");
n = MAXBUFFER / 2;
for(p=OO_buffer,i=n;i--;)
EM_mkcalls(p++);
/* now copy the rest of buffer and pattern back */
BTSCPY(p,q,i,OO_buffer,OO_buffer+n,n+(OO_nxtpatt-OO_buffer));
OO_patternqueue -= n;
OO_nxtpatt -= n;
printstate("after Half flush");
return (OO_nxtpatt++);
} }
OO_outop(opcode) OO_mkext(p,opcode,arg,off)
int opcode; register p_instr p;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = 0;
OO_out(p);
}
OO_outcst(opcode,cst)
int opcode;
arith cst;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = cst_ptyp;
p->em_cst = cst;
OO_out(p);
}
OO_outlab(opcode,lab)
int opcode;
label lab;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = ilb_ptyp;
p->em_ilb = lab;
OO_out(p);
}
OO_outpnam(opcode,pnam)
int opcode;
char *pnam;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = pro_ptyp;
p->em_pnam = pnam;
OO_out(p);
}
OO_outdefilb(opcode,deflb)
int opcode;
label deflb;
{
register p_instr p = GETINSTR();
p->em_type = EM_DEFILB;
p->em_opcode = opcode;
p->em_argtype = 0;
p->em_ilb = deflb;
OO_out(p);
}
OO_outext(opcode,arg,off)
int opcode; int opcode;
p_instr arg; p_instr arg;
arith off; arith off;
{ {
register p_instr p = GETINSTR(); switch(arg->em_argtype) {
p->em_type = EM_MNEM;
p->em_opcode = opcode;
switch(p->em_argtype = arg->em_argtype) {
case cst_ptyp: case cst_ptyp:
p->em_cst = off; EM_mkcst(p,opcode,off);
break; break;
case sof_ptyp: case sof_ptyp:
p->em_dnam = arg->em_dnam; EM_mksof(p,opcode,arg->em_dnam,off);
p->em_off = off;
break; break;
case nof_ptyp: case nof_ptyp:
p->em_dlb = arg->em_dlb; EM_mknof(p,opcode,arg->em_dlb,off);
p->em_off = off;
break; break;
default: default:
fatal("Unexpected type %d in outext",arg->em_argtype); fatal("Unexpected type %d in outext",arg->em_argtype);
} }
OO_out(p);
}
OO_pushback(p)
p_instr p;
{
/* push instr. p onto bkupqueue */
if(OO_nxtbackup > lastbackup) {
#ifdef DEBUG
fprintf(stderr,"Warning: Overflow of bkupqueue-backup ignored\n");
printstate("Backup overflow");
#endif
return;
}
*OO_nxtbackup++ = p;
} }
OO_backup(n) OO_backup(n)
register int n; int n;
{ {
/* copy (up to) n instructions from output to backup queues */ /* copy the replacement queue into the buffer queue */
while(n-- && nextoutput>outputqueue) { /* then move the pattern queue back n places */
OO_pushback(*(--nextoutput)); register p_instr p,q;
OO_noutput--; register int i,lrepl, diff;
printstate("Before backup");
lrepl = OO_nxtrepl-OO_replqueue;
if(OO_endbackup) {
/* move the region between OO_nxtpatt and OO_endbackup */
if ((diff = (OO_nxtpatt-OO_patternqueue) - lrepl) > 0) {
/* move left by diff */
BTSCPY(p,q,i,OO_nxtpatt-diff,OO_nxtpatt,OO_endbackup-OO_nxtpatt);
OO_nxtpatt -= diff;
OO_endbackup -= diff;
}
else if (diff < 0) {
/* move right by diff */
/* careful of overflowing buffer!! */
if ((OO_nxtpatt-diff)> (OO_buffer+MAXBUFFER) )
OO_halfflush();
/* cannot use btscpy as strings may overlap */
p = (q=OO_endbackup-1) - diff;
while(q>=OO_nxtpatt)
*p-- = *q--;
OO_nxtpatt -= diff;
OO_endbackup -= diff;
}
} }
/* copy the replacement */
if (lrepl) {
BTSCPY(p,q,i,OO_patternqueue,OO_replqueue,lrepl);
OO_nxtrepl = OO_replqueue;
OO_patternqueue += lrepl;
}
/* now move the position of interest back n instructions */
if ((OO_patternqueue-OO_buffer) < n)
n = (OO_patternqueue-OO_buffer);
OO_nxtpatt = OO_patternqueue -= n;
if(!OO_endbackup && n)
OO_endbackup = OO_patternqueue+n;
OO_state = 0;
printstate("After backup");
} }
OO_dodefault(numout, numcopy,newstate) OO_dodefault(numout, newstate)
register int numout, numcopy; int numout;
int newstate; int newstate;
{ {
register p_instr *p, *q; printstate("Before dodefault");
OO_pushback(*--OO_nxtpatt); if(!OO_endbackup) OO_endbackup = OO_nxtpatt;
q = (p = OO_patternqueue) + numout; OO_nxtpatt--;
while(numcopy--) { OO_patternqueue += numout;
if(numout) {
numout--;
OO_out(*p);
}
*p++ = *q++;
}
OO_nxtpatt = p;
while(numout--) OO_out(*p++);
OO_state = newstate; OO_state = newstate;
printstate("After dodefault");
} }
#ifdef DEBUG #ifdef DEBUG
PRIVATE dumpstate(mess)
printstate(mess)
char *mess; char *mess;
{ {
p_instr *p; p_instr p;
fprintf(stderr,"%s - state: ",mess); fprintf(stderr,"%s - state(%d): ",mess,OO_state);
p = outputqueue; p = OO_buffer;
while(p<nextoutput) while(p<OO_patternqueue)
prtinst(*p++); prtinst(p++);
fprintf(stderr," |==| "); fprintf(stderr," |==| ");
p = OO_patternqueue;
while(p<OO_nxtpatt) while(p<OO_nxtpatt)
prtinst(*p++); prtinst(p++);
fprintf(stderr," |==| "); fprintf(stderr," |==| ");
p = OO_bkupqueue; if(OO_endbackup) {
while(p<OO_nxtbackup) while(p<OO_endbackup)
prtinst(*p++); prtinst(p++);
}
fprintf(stderr,"\n"); fprintf(stderr,"\n");
} }
PRIVATE
prtinst(p) prtinst(p)
p_instr p; p_instr p;
{ {
switch(p->em_type) { switch(p->em_type) {
case EM_MNEM: case EM_MNEM:
if(p->em_opcode == OTHER) fprintf(stderr,"%s ",em_mnem[p->em_opcode-sp_fmnem]);
fprintf(stderr,"OTHER");
else
fprintf(stderr,"%s",em_mnem[p->em_opcode-sp_fmnem]);
break; break;
case EM_PSEU: case EM_PSEU:
case EM_STARTMES: fprintf(stderr,"%s ",em_pseu[p->em_opcode-sp_fpseu]);
fprintf(stderr,"%s",em_pseu[p->em_opcode-sp_fpseu]);
break; break;
case EM_STARTMES:
case EM_MESARG: case EM_MESARG:
case EM_ENDMES: case EM_ENDMES:
fprintf(stderr,"MES ");
break; break;
case EM_DEFILB: case EM_DEFILB:
fprintf(stderr,"%ld", (long)p->em_ilb); fprintf(stderr,"%ld ", (long)p->em_ilb);
break; return;
case EM_DEFDLB: case EM_DEFDLB:
fprintf(stderr,"%ld", (long)p->em_dlb); fprintf(stderr,"%ld ", (long)p->em_dlb);
break; return;
case EM_DEFDNAM: case EM_DEFDNAM:
fprintf(stderr,"%d", p->em_dnam); fprintf(stderr,"%d ", p->em_dnam);
break; return;
case EM_ERROR: case EM_ERROR:
case EM_FATAL: case EM_FATAL:
case EM_EOF: case EM_EOF:
break; return;
} }
switch(p->em_argtype) { switch(p->em_argtype) {
case 0: case 0:
fprintf(stderr," ");
break; break;
case cst_ptyp: case cst_ptyp:
fprintf(stderr," %d ",p->em_cst); fprintf(stderr,"%d ",p->em_cst);
break; break;
case nof_ptyp: case nof_ptyp:
fprintf(stderr," .%d+%d ",p->em_dlb,p->em_off); fprintf(stderr,".%d+%d ",p->em_dlb,p->em_off);
break; break;
case sof_ptyp: case sof_ptyp:
fprintf(stderr," %s+%d ",p->em_dnam,p->em_off); fprintf(stderr,"%s+%d ",p->em_dnam,p->em_off);
break; break;
case ilb_ptyp: case ilb_ptyp:
fprintf(stderr," *%d ",p->em_ilb); fprintf(stderr,"*%d ",p->em_ilb);
break; break;
case pro_ptyp: case pro_ptyp:
fprintf(stderr," $%s ",p->em_pnam); fprintf(stderr,"$%s ",p->em_pnam);
break;
case str_ptyp:
case ico_ptyp:
case uco_ptyp:
fprintf(stderr,"\"%s\"",p->em_string);
break; break;
default: default:
fatal(" prtinst - Unregognized arg %d ",p->em_argtype); fatal(" prtinst - Unregognized arg %d ",p->em_argtype);

View file

@ -12,26 +12,29 @@
#include <system.h> #include <system.h>
#include <emO_code.h> #include <emO_code.h>
#define MAXBUFFER 200
#define MAXSTRING 1000
#define OTHER 0 #define OTHER 0
#define op_lab sp_fpseu #define op_lab sp_fpseu
typedef struct e_instr *p_instr; typedef struct e_instr *p_instr;
#define FLUSHDFA() if(OO_state) {\ extern p_instr OO_buffer;
*OO_nxtpatt++ = OO_OTHER; OO_dfa(OTHER);\ extern p_instr OO_patternqueue;
} else if(OO_noutput) OO_flush(); extern p_instr OO_nxtpatt;
extern p_instr OO_endbackup;
extern p_instr OO_nxtrepl;
#define GETINSTR() ((p_instr)st_alloc((char **)&OO_freeq,sizeof(struct e_instr),20)) p_instr OO_halfflush();
#define OO_free(p) st_free((p),&OO_freeq,sizeof(struct e_instr))
# define GETNXTPATT() (OO_nxtpatt>&OO_buffer[MAXBUFFER]?OO_halfflush():OO_nxtpatt++)
# define GETNXTREPL() (OO_nxtrepl++)
# define FLUSHDFA() (GETNXTPATT())->em_opcode=OTHER;\
if (OO_state) OO_dfa(OTHER); else OO_flush()
extern p_instr OO_freeq;
extern p_instr *OO_patternqueue;
extern p_instr *OO_nxtpatt;
extern p_instr *OO_bkupqueue;
extern p_instr *OO_nxtbackup;
extern p_instr OO_OTHER;
extern int OO_state; extern int OO_state;
extern int OO_noutput; /* number of instructions in output queue */
extern arith OO_WSIZE; /* wordlength */ extern arith OO_WSIZE; /* wordlength */
extern arith OO_PSIZE; /* pointer length */ extern arith OO_PSIZE; /* pointer length */
#ifdef STATS #ifdef STATS
@ -42,8 +45,9 @@ extern char *OO_freestr();
extern arith OO_rotate(); extern arith OO_rotate();
extern arith OO_offset(); extern arith OO_offset();
#define CST(p) (p->em_cst) #define CST(p) (p.em_cst)
#define PNAM(p) (p->em_pnam) #define PNAM(p) (p.em_pnam)
#define LAB(p) (p->em_ilb) #define LAB(p) (p.em_ilb)
#define DEFILB(p) (p->em_ilb) #define DEFILB(p) (p.em_ilb)
#define DEFINED(p) (p.em_argtype)

View file

@ -14,7 +14,7 @@ outputincalls()
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,"\tOO_inop(op_%s);\n",s); fprintf(ofile,"\tEM_mkop(GETNXTPATT(),op_%s);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
@ -25,7 +25,7 @@ outputincalls()
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,"\tOO_inop(op_%s);\n",s); fprintf(ofile,"\tEM_mknarg(GETNXTPATT(),op_%s);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
@ -36,7 +36,7 @@ outputincalls()
case CST: case CST:
fprintf(ofile,"%s\t| int:n\t|\n",s); fprintf(ofile,"%s\t| int:n\t|\n",s);
if(op->id_used) { if(op->id_used) {
fprintf(ofile,"\tOO_incst(op_%s,n);\n",s); fprintf(ofile,"\tEM_mkcst(GETNXTPATT(),op_%s,n);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
@ -47,7 +47,7 @@ outputincalls()
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,"\tOO_indefilb(op_%s,l);\n",s); fprintf(ofile,"\tEM_mkdefilb(GETNXTPATT(),op_%s,l);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
@ -58,7 +58,7 @@ outputincalls()
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,"\tOO_inpnam(op_%s,s);\n",s); fprintf(ofile,"\tEM_mkpro(GETNXTPATT(),op_%s,s);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
@ -69,7 +69,7 @@ outputincalls()
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,"\tOO_inlab(op_%s,l);\n",s); fprintf(ofile,"\tEM_mkilb(GETNXTPATT(),op_%s,l);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
@ -80,7 +80,7 @@ outputincalls()
case EXT: case EXT:
fprintf(ofile,"%s\t| int:n\t|\n",s); fprintf(ofile,"%s\t| int:n\t|\n",s);
if(op->id_used) { if(op->id_used) {
fprintf(ofile,"\tOO_incst(op_%s,n);\n",s); fprintf(ofile,"\tEM_mkcst(GETNXTPATT(),op_%s,n);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
@ -89,7 +89,7 @@ outputincalls()
} }
fprintf(ofile,"%s_dnam\t| char *:s int:n\t|\n",s); fprintf(ofile,"%s_dnam\t| char *:s int:n\t|\n",s);
if(op->id_used) { if(op->id_used) {
fprintf(ofile,"\tOO_indnam(op_%s,s,n);\n",s); fprintf(ofile,"\tEM_mksof(GETNXTPATT(),op_%s,s,n);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
@ -98,7 +98,7 @@ outputincalls()
} }
fprintf(ofile,"%s_dlb\t| label:l int:n\t|\n",s); fprintf(ofile,"%s_dlb\t| label:l int:n\t|\n",s);
if(op->id_used) { if(op->id_used) {
fprintf(ofile,"\tOO_indlb(op_%s,l,n);\n",s); fprintf(ofile,"\tEM_mknof(GETNXTPATT(),op_%s,l,n);\n",s);
fprintf(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {

View file

@ -99,7 +99,7 @@ outdfa()
int seenswitch; int seenswitch;
fprintf(ofile,"#include \"nopt.h\"\n"); fprintf(ofile,"#include \"nopt.h\"\n");
fprintf(ofile,"\n"); fprintf(ofile,"\n");
fprintf(ofile,"int OO_maxpattern = %d;\n", longestpattern); fprintf(ofile,"int OO_maxreplacement = %d;\n", maxreplacement);
fprintf(ofile,"int OO_state = 0;\n"); fprintf(ofile,"int OO_state = 0;\n");
fprintf(ofile,"\n"); fprintf(ofile,"\n");
for(s=0;s<=higheststate;s++) { for(s=0;s<=higheststate;s++) {
@ -114,6 +114,9 @@ outdfa()
fprintf(ofile,"static dfa%d(opcode)\n",s); fprintf(ofile,"static dfa%d(opcode)\n",s);
fprintf(ofile,"\tint opcode;\n"); fprintf(ofile,"\tint opcode;\n");
fprintf(ofile,"{\n"); fprintf(ofile,"{\n");
fprintf(ofile,"\t/* ");
outmnems(patterns[s]);
fprintf(ofile," */\n");
seenswitch = 0; seenswitch = 0;
for(p=states[s];p!=(struct state *)NULL;p=p->next) { for(p=states[s];p!=(struct state *)NULL;p=p->next) {
if(!seenswitch) { if(!seenswitch) {
@ -133,19 +136,12 @@ outdfa()
} }
fprintf(ofile,"\tdefault:\n"); fprintf(ofile,"\tdefault:\n");
fprintf(ofile,"\t\tOO_flush();\n"); fprintf(ofile,"\t\tOO_flush();\n");
fprintf(ofile,"\t\tEM_mkcalls(*--OO_nxtpatt);\n");
fprintf(ofile,"\t\tOO_free(*OO_nxtpatt);\n");
fprintf(ofile,"\t\tbreak;\n");
fprintf(ofile,"\tcase OTHER:\n");
fprintf(ofile,"\t\tOO_flush();\n");
fprintf(ofile,"\t\t--OO_nxtpatt;\n");
fprintf(ofile,"\t\tbreak;\n"); fprintf(ofile,"\t\tbreak;\n");
} }
else { else {
if(seenswitch) fprintf(ofile,"\tdefault:\n"); if(seenswitch) fprintf(ofile,"\tdefault:\n");
findfail(s,&nout,&ncpy,&ngto); findfail(s,&nout,&ncpy,&ngto);
fprintf(ofile,"\t\tOO_dodefault(%d,%d,%d);\n", fprintf(ofile,"\t\tOO_dodefault(%d,%d);\n",nout,ngto);
nout,ncpy,ngto);
if(actions[ngto]!=NULL) if(actions[ngto]!=NULL)
fprintf(ofile,"\t\tOO_%ddotrans();\n",ngto); fprintf(ofile,"\t\tOO_%ddotrans();\n",ngto);
if(seenswitch) fprintf(ofile,"\t\tbreak;\n"); if(seenswitch) fprintf(ofile,"\t\tbreak;\n");
@ -171,24 +167,23 @@ outdotrans()
int s; int s;
struct action *a; struct action *a;
int seennontested; int seennontested;
int seentested;
fprintf(ofile,"#include \"nopt.h\"\n\n"); fprintf(ofile,"#include \"nopt.h\"\n\n");
for(s=0;s<=higheststate;s++) { for(s=0;s<=higheststate;s++) {
if(actions[s]!=(struct action *)NULL) { if(actions[s]!=(struct action *)NULL) {
fprintf(ofile,"\nOO_%ddotrans() {\n",s); fprintf(ofile,"\nOO_%ddotrans() {\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");
seentested = 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) {
seentested++;
fprintf(ofile,"\tif("); fprintf(ofile,"\tif(");
outexp(a->test,s); outexp(a->test,s);
fprintf(ofile,") {\n"); fprintf(ofile,") {\n");
outoneaction(s,a); outoneaction(s,a);
fprintf(ofile,"\t\tgoto free;\n\t}\n"); fprintf(ofile,"\t\treturn;\n");
fprintf(ofile,"\t}\n");
} }
else { else {
if(seennontested) { if(seennontested) {
@ -199,12 +194,8 @@ outdotrans()
outoneaction(s,a); outoneaction(s,a);
} }
} }
if(!seennontested) { if(!seennontested)
fprintf(ofile,"\tOO_state=%d;\n",s); fprintf(ofile,"\tOO_state=%d;\n",s);
fprintf(ofile,"\treturn;\n");
}
if(seentested) fprintf(ofile,"free:");
fprintf(ofile,"\tOO_nfree(%d);\n",patterns[s].m_len);
fprintf(ofile,"}\n"); fprintf(ofile,"}\n");
} }
/* /*
@ -243,32 +234,42 @@ outrepl(state,repl)
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\tOO_outop(op_%s);\n",mnem); fprintf(ofile,"\t\tEM_mkop(GETNXTREPL(),op_%s);\n",mnem);
break; break;
case CST: case CST:
case CSTOPT: fprintf(ofile,"\t\tEM_mkcst(GETNXTREPL(),op_%s,",mnem);
fprintf(ofile,"\t\tOO_outcst(op_%s,",mnem);
fprintf(ofile,"(arith)"); fprintf(ofile,"(arith)");
outexp(ri->arg,state); outexp(ri->arg,state);
fprintf(ofile,");\n"); fprintf(ofile,");\n");
break; break;
case CSTOPT:
if(ri->arg) {
fprintf(ofile,"\t\tEM_mkcst(GETNXTREPL(),op_%s,",mnem);
fprintf(ofile,"(arith)");
outexp(ri->arg,state);
}
else {
fprintf(ofile,"\t\tEM_mknarg(GETNXTREPL(),op_%s);\n",mnem);
}
fprintf(ofile,");\n");
break;
case LAB: case LAB:
fprintf(ofile,"\t\tOO_outlab(op_%s,",mnem); fprintf(ofile,"\t\tEM_mkilb(GETNXTREPL(),op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprintf(ofile,");\n"); fprintf(ofile,");\n");
break; break;
case DEFILB: case DEFILB:
fprintf(ofile,"\t\tOO_outdefilb(op_%s,",mnem); fprintf(ofile,"\t\tEM_mkdefilb(GETNXTREPL(),op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprintf(ofile,");\n"); fprintf(ofile,");\n");
break; break;
case PNAM: case PNAM:
fprintf(ofile,"\t\tOO_outpnam(op_%s,",mnem); fprintf(ofile,"\t\tEM_mkpro(GETNXTREPL(),op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprintf(ofile,");\n"); fprintf(ofile,");\n");
break; break;
case EXT: case EXT:
fprintf(ofile,"\t\tOO_outext(op_%s,",mnem); fprintf(ofile,"\t\tOO_mkext(GETNXTREPL(),op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprintf(ofile,");\n"); fprintf(ofile,");\n");
break; break;
@ -316,10 +317,10 @@ outexp(e,state)
fprintf(ofile,")"); fprintf(ofile,")");
break; break;
case DEFINED: case DEFINED:
fprintf(ofile,"(patt[%d]->em_argtype)",e->leaf_val-1); fprintf(ofile,"DEFINED(patt[%d])",e->leaf_val-1);
break; break;
case UNDEFINED: case UNDEFINED:
fprintf(ofile,"(patt[%d]->em_argtype==0)",e->leaf_val-1); fprintf(ofile,"!DEFINED(patt[%d])",e->leaf_val-1);
break; break;
case COMMA: case COMMA:
outext(e->exp_left); outext(e->exp_left);
@ -367,7 +368,7 @@ outexp(e,state)
fprintf(ofile,"PNAM(patt[%d])",e->leaf_val-1); fprintf(ofile,"PNAM(patt[%d])",e->leaf_val-1);
break; break;
case EXT: case EXT:
fprintf(ofile,"OO_offset(patt[%d])",e->leaf_val-1); fprintf(ofile,"OO_offset(patt+%d)",e->leaf_val-1);
break; break;
} }
break; break;
@ -388,7 +389,7 @@ outext(e)
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

View file

@ -25,7 +25,8 @@ struct action *actions[MAXSTATES];
struct mnems patterns[MAXSTATES]; struct mnems patterns[MAXSTATES];
int higheststate = 0; /* Highest state yet allocated */ int higheststate = 0; /* Highest state yet allocated */
struct idf *ops; /* Chained list of all ops */ struct idf *ops; /* Chained list of all ops */
int longestpattern = 0; int maxpattern = 0;
int maxreplacement = 0;
int nerrors = 0; int nerrors = 0;
static int lencurrpatt; static int lencurrpatt;
@ -77,8 +78,8 @@ patterns(struct exp_node **tests;)
[ [
OPCODE OPCODE
{ {
if(++lencurrpatt>longestpattern) if(++lencurrpatt>maxpattern)
longestpattern=lencurrpatt; maxpattern=lencurrpatt;
list = addelem(list,opval, (struct exp_node *)NULL); list = addelem(list,opval, (struct exp_node *)NULL);
opval->id_used=1; opval->id_used=1;
if(lencurrpatt==1) if(lencurrpatt==1)
@ -169,7 +170,8 @@ action(struct mnem_list **list;)
[ [
OPCODE OPCODE
{ {
lenthisrepl++; if(++lenthisrepl>maxreplacement)
maxreplacement = lenthisrepl;
test= (struct exp_node *)NULL; test= (struct exp_node *)NULL;
keepopval = opval; keepopval = opval;
} }
@ -347,7 +349,8 @@ constructlist(list,len)
int len; int len;
{ {
struct mnem_elem **p; struct mnem_elem **p;
p = (struct mnem_elem **)Malloc(len*sizeof(struct mnem_elem *)); p = (struct mnem_elem **)
Malloc((unsigned)(len*sizeof(struct mnem_elem *)));
while(len--) { while(len--) {
p[len] = list->elem; p[len] = list->elem;
list = list->next; list = list->next;

View file

@ -77,7 +77,8 @@ extern struct action *actions[MAXSTATES];
extern struct mnems patterns[MAXSTATES]; extern struct mnems patterns[MAXSTATES];
extern int higheststate; /* Highest state yet allocated */ extern int higheststate; /* Highest state yet allocated */
extern struct idf *ops; /* Chained list of all ops */ extern struct idf *ops; /* Chained list of all ops */
extern int longestpattern; extern int maxpattern;
extern int maxreplacement;
extern int nerrors; extern int nerrors;
extern FILE *ofile; extern FILE *ofile;

View file

@ -1,17 +1,22 @@
df_dlb | label:l | df_dlb | label:l |
FLUSHDFA(); register p_instr p = GETNXTPATT();
FLUSHDFA(p);
C_df_dlb(l); C_df_dlb(l);
df_dnam | char *:s | df_dnam | char *:s |
FLUSHDFA(); register p_instr p = GETNXTPATT();
FLUSHDFA(p);
C_df_dnam(s); C_df_dnam(s);
pro | char *:s arith:l | pro | char *:s arith:l |
FLUSHDFA(); register p_instr p = GETNXTPATT();
FLUSHDFA(p);
C_pro(s,l); C_pro(s,l);
pro_narg | char *:s | pro_narg | char *:s |
FLUSHDFA(); register p_instr p = GETNXTPATT();
FLUSHDFA(p);
C_pro_narg(s); C_pro_narg(s);
end | arith:l | end | arith:l |
FLUSHDFA(); register p_instr p = GETNXTPATT();
FLUSHDFA(p);
C_end(l); C_end(l);
end_narg | | end_narg | |
FLUSHDFA(); FLUSHDFA();