Convert to new READ_EM data structure. Build a em_nopt. Input names now O_ and output C_. Add insert part support.

This commit is contained in:
bruce
1987-07-07 16:31:16 +00:00
parent 85421efb19
commit 466637933a
15 changed files with 815 additions and 648 deletions

View File

@@ -1,68 +1,67 @@
#ifndef NORCSID
static char rcsid[] = "$Header$";
static char rcsid2[] = "$Header$";
#endif
#include "nopt.h"
extern int maxpattern; /* Initialized from patterns in dfa.c */
extern int OO_maxpattern; /* Initialized from patterns in dfa.c */
#define MAXBACKUP 50
#define MAXOUTPUT 200
#define MAXFREEI 200
#define MAXSTRING 1000
#define GETINSTR() (nextifree>freeiqueue)?*(--nextifree):\
((struct instr *)Malloc(sizeof(struct instr)))
extern char em_mnem[][4];
extern char em_pseu[][4];
extern char em_mnem[][4];
p_instr *OO_freeiqueue;
p_instr *OO_nxtifree;
p_instr *OO_patternqueue;
p_instr *OO_nxtpatt;
p_instr *OO_bkupqueue;
p_instr *OO_nxtbackup;
p_instr OO_OTHER;
struct instr **OO_patternqueue;
struct instr **OO_nxtpatt;
struct instr **OO_bkupqueue;
struct instr **OO_nxtbackup;
static char *filename;
static p_instr *lastbackup;
static p_instr *outputqueue;
static p_instr *nextoutput;
static p_instr *lastoutput;
static p_instr *lastifree;
static char *strqueue;
static char *nextstr;
static char *laststr;
static char *filename;
static struct instr **lastbackup;
static struct instr **outputqueue;
static struct instr **nextoutput;
static struct instr **lastoutput;
static struct instr **freeiqueue;
static struct instr **nextifree;
static struct instr **lastifree;
static char *strqueue;
static char *nextstr;
static char *laststr;
int OO_noutput; /* number of instructions in output queue */
int OO_WSIZE; /* wordlength */
int OO_PSIZE; /* pointer length */
int OO_noutput; /* number of instructions in output queue */
int OO_WSIZE; /* wordlength */
int OO_PSIZE; /* pointer length */
#ifdef STATS
int OO_wrstats = 1; /* pattern statistics output */
int OO_wrstats = 1; /* pattern statistics output */
#endif
C_init(wsize,psize)
O_init(wsize,psize)
arith wsize, psize;
{
allocmem();
O_init(wsize,psize);
C_init(wsize,psize);
OO_WSIZE = wsize;
OO_PSIZE = psize;
}
C_open(fname)
O_open(fname)
char *fname;
{
filename = fname;
return(O_open(fname));
return(C_open(fname));
}
C_magic()
O_magic()
{
O_magic();
C_magic();
}
C_close()
O_close()
{
O_close();
C_close();
}
PRIVATE
@@ -70,9 +69,9 @@ fatal(s,a)
char *s;
int a;
{
fprint(STDERR, "%s: ", filename ? filename : "standard input");
fprint(STDERR,s,a);
fprint(STDERR,"\n");
fprintf(stderr, "%s: ", filename ? filename : "standard input");
fprintf(stderr,s,a);
fprintf(stderr,"\n");
sys_stop(S_EXIT);
}
@@ -81,48 +80,65 @@ allocmem()
{
/* Allocate memory for queues on heap */
OO_nxtpatt = OO_patternqueue =
(struct instr **)Malloc(maxpattern*sizeof(struct instr *));
(p_instr *)Malloc(OO_maxpattern*sizeof(p_instr));
OO_nxtbackup = OO_bkupqueue =
(struct instr **)Malloc(MAXBACKUP*sizeof(struct instr *));
(p_instr *)Malloc(MAXBACKUP*sizeof(p_instr));
lastbackup = OO_bkupqueue + MAXBACKUP - 1;
nextoutput = outputqueue =
(struct instr **)Malloc(MAXOUTPUT*sizeof(struct instr *));
(p_instr *)Malloc(MAXOUTPUT*sizeof(p_instr));
lastoutput = outputqueue + MAXOUTPUT - 1;
OO_noutput = 0;
nextifree = freeiqueue =
(struct instr **)Malloc(MAXFREEI*sizeof(struct instr *));
lastifree = freeiqueue + MAXFREEI - 1;
OO_nxtifree = OO_freeiqueue =
(p_instr *)Malloc(MAXFREEI*sizeof(p_instr));
lastifree = OO_freeiqueue + MAXFREEI - 1;
nextstr = strqueue =
(char *)Malloc(MAXSTRING*sizeof(char));
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_free(p)
struct instr *p;
p_instr p;
{
if(nextifree > lastifree) {
if(OO_nxtifree > lastifree) {
#ifdef DEBUG
fprint(STDERR,"Warning: Overflow of free intr. queue.\n");
fprint(STDERR,"Ignored free of ");
fprintf(stderr,"Warning: Overflow of free intr. queue.\n");
fprintf(stderr,"Ignored free of ");
prtinst(p);
fprint(STDERR,"\n");
fprintf(stderr,"\n");
printstate("Freea overflow");
#endif
return;
}
*nextifree++ = p;
*OO_nxtifree++ = p;
}
PRIVATE char *
freestr(s)
char *s;
char *
OO_freestr(str)
char *str;
{
char *res = nextstr;
while(*nextstr++ = *s++);
if(nextstr > laststr) {
fprint(STDERR,"string space overflowed!\n");
sys_stop(S_EXIT);
register char *s = str;
register char *res;
while (*s++);
again:
if ((s-str) > (laststr-nextstr)) {
unsigned newsize = (laststr - strqueue + 1)*2;
res = Realloc(strqueue,newsize);
laststr = res + newsize - 1;
nextstr = res + (nextstr - strqueue);
strqueue = res;
#ifdef DEBUG
fprintf(stderr,"Warning: Reallocated string area.");
fprintf(stderr,"New size is %d bytes\n", newsize);
#endif
goto again;
}
res=nextstr;
for(s=str;*nextstr++ = *s++;);
return(res);
}
@@ -132,13 +148,14 @@ OO_flush()
/* Output all instructions waiting in the output queue and free their
/* storage including the saved strings.
*/
struct instr **p;
register int n;
register p_instr *p;
#ifdef DEBUG
printstate("Flush");
#endif
if(OO_noutput) {
for(p=outputqueue;p<nextoutput;p++) {
OO_mkcalls(*p);
if (n = OO_noutput) {
for(p=outputqueue;n--;p++) {
EM_mkcalls(*p);
OO_free(*p);
}
nextoutput=outputqueue;
@@ -148,166 +165,13 @@ OO_flush()
}
}
OO_outop(opcode)
int opcode;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = none_ptyp;
OO_out(p);
}
OO_inop(opcode)
int opcode;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = none_ptyp;
*OO_nxtpatt++ = p;
}
OO_outcst(opcode,cst)
int opcode,cst;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = cst_ptyp;
p->acst = cst;
OO_out(p);
}
OO_incst(opcode,cst)
int opcode,cst;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = cst_ptyp;
p->acst = cst;
*OO_nxtpatt++ = p;
}
OO_outlab(opcode,lab)
int opcode,lab;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = cst_ptyp;
p->acst = lab;
OO_out(p);
}
OO_inlab(opcode,lab)
int opcode,lab;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = cst_ptyp;
p->acst = lab;
*OO_nxtpatt++ = p;
}
OO_outpnam(opcode,pnam)
int opcode;
char *pnam;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = pro_ptyp;
p->apnam = pnam;
OO_out(p);
}
OO_inpnam(opcode,pnam)
int opcode;
char *pnam;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = pro_ptyp;
p->apnam = freestr(pnam);
*OO_nxtpatt++ = p;
}
OO_outdefilb(opcode,deflb)
int opcode;
label deflb;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = lab_ptyp;
p->alab = deflb;
OO_out(p);
}
OO_indefilb(opcode,deflb)
int opcode;
label deflb;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = lab_ptyp;
p->alab = deflb;
*OO_nxtpatt++ = p;
}
OO_outext(opcode,arg,soff)
int opcode;
struct instr *arg;
int soff;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
switch(p->argtype = arg->argtype) {
case cst_ptyp:
p->acst = soff;
break;
case sof_ptyp:
p->adnam = arg->adnam;
p->asoff = soff;
break;
case nof_ptyp:
p->adlb = arg->adlb;
p->anoff = soff;
break;
default:
fatal("Unexpected type %d in outext",arg->argtype);
}
OO_out(p);
}
OO_indnam(opcode,name,off)
int opcode;
char *name;
int off;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = sof_ptyp;
p->adnam = freestr(name);
p->asoff = off;
*OO_nxtpatt++ = p;
}
OO_indlb(opcode,lab,off)
int opcode;
label lab;
int off;
{
register struct instr *p = GETINSTR();
p->opcode = opcode;
p->argtype = nof_ptyp;
p->adlb = lab;
p->anoff = off;
*OO_nxtpatt++ = p;
}
OO_out(p)
struct instr *p;
p_instr p;
{
/* Put the instruction p on the output queue */
if(nextoutput > lastoutput) {
#ifdef DEBUG
fprint(STDERR,"Warning: Overflow of outputqueue - output flushed\n");
fprintf(stderr,"Warning: Overflow of outputqueue - output flushed\n");
#endif
OO_flush();
}
@@ -315,13 +179,95 @@ OO_out(p)
*nextoutput++ = p;
}
OO_outop(opcode)
int opcode;
{
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,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,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;
p_instr arg;
int off;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
p->em_opcode = opcode;
switch(p->em_argtype = arg->em_argtype) {
case cst_ptyp:
p->em_cst = off;
break;
case sof_ptyp:
p->em_dnam = arg->em_dnam;
p->em_off = off;
break;
case nof_ptyp:
p->em_dlb = arg->em_dlb;
p->em_off = off;
break;
default:
fatal("Unexpected type %d in outext",arg->em_argtype);
}
OO_out(p);
}
OO_pushback(p)
struct instr *p;
p_instr p;
{
/* push instr. p onto bkupqueue */
if(OO_nxtbackup > lastbackup) {
#ifdef DEBUG
fprint(STDERR,"Warning: Overflow of bkupqueue-backup ignored\n");
fprintf(stderr,"Warning: Overflow of bkupqueue-backup ignored\n");
printstate("Backup overflow");
#endif
return;
@@ -330,7 +276,7 @@ OO_pushback(p)
}
OO_backup(n)
int n;
register int n;
{
/* copy (up to) n instructions from output to backup queues */
while(n-- && nextoutput>outputqueue) {
@@ -340,9 +286,9 @@ OO_backup(n)
}
OO_dodefault(numout, numcopy)
int numout, numcopy;
register int numout, numcopy;
{
register struct instr **p,**q;
register p_instr *p, *q;
q = (p = OO_patternqueue) + numout;
while(numcopy--) {
if(numout) {
@@ -360,60 +306,75 @@ PRIVATE
printstate(mess)
char *mess;
{
struct instr **p;
fprint(STDERR,"%s - state: ",mess);
p_instr *p;
fprintf(stderr,"%s - state: ",mess);
p = outputqueue;
while(p<nextoutput)
prtinst(*p++);
fprint(STDERR," |==| ");
fprintf(stderr," |==| ");
p = OO_patternqueue;
while(p<OO_nxtpatt)
prtinst(*p++);
fprint(STDERR," |==| ");
fprintf(stderr," |==| ");
p = OO_bkupqueue;
while(p<OO_nxtbackup)
prtinst(*p++);
fprint(STDERR,"\n");
fprintf(stderr,"\n");
}
PRIVATE
prtinst(p)
struct instr *p;
p_instr p;
{
switch(p->opcode) {
default:
fprint(STDERR,"%s",em_mnem[p->opcode-sp_fmnem]);
switch(p->em_type) {
case EM_MNEM:
if(p->em_opcode == OTHER)
fprintf(stderr,"OTHER");
else
fprintf(stderr,"%s",em_mnem[p->em_opcode-sp_fmnem]);
break;
case OTHER:
fprint(STDERR,"OTHER");
case EM_PSEU:
case EM_STARTMES:
fprintf(stderr,"%s",em_pseu[p->em_opcode-sp_fpseu]);
break;
case op_lab:
case EM_MESARG:
case EM_ENDMES:
break;
case EM_DEFILB:
fprintf(stderr,"%ld", (long)p->em_ilb);
break;
case EM_DEFDLB:
fprintf(stderr,"%ld", (long)p->em_dlb);
break;
case EM_DEFDNAM:
fprintf(stderr,"%d", p->em_dnam);
break;
case EM_ERROR:
case EM_FATAL:
case EM_EOF:
break;
}
switch(p->argtype) {
case none_ptyp:
fprint(STDERR," ");
switch(p->em_argtype) {
case 0:
fprintf(stderr," ");
break;
case cst_ptyp:
fprint(STDERR," %d ",p->acst);
break;
case lab_ptyp:
fprint(STDERR,"%d: ",p->alab);
fprintf(stderr," %d ",p->em_cst);
break;
case nof_ptyp:
fprint(STDERR," .%d+%d ",p->adlb,p->asoff);
fprintf(stderr," .%d+%d ",p->em_dlb,p->em_off);
break;
case sof_ptyp:
fprint(STDERR," %s+%d ",p->adnam,p->asoff);
fprintf(stderr," %s+%d ",p->em_dnam,p->em_off);
break;
case ilb_ptyp:
fprint(STDERR," *%d ",p->alab);
fprintf(stderr," *%d ",p->em_ilb);
break;
case pro_ptyp:
fprint(STDERR," $%s ",p->apnam);
fprintf(stderr," $%s ",p->em_pnam);
break;
default:
fatal(" prtinst - Unregognized arg %d ",p->argtype);
fatal(" prtinst - Unregognized arg %d ",p->em_argtype);
}
}
#endif