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

@ -2,34 +2,45 @@
EMHOME = ../../.. EMHOME = ../../..
INSTALL = $(EMHOME)/modules/install INSTALL = $(EMHOME)/modules/install
COMPARE = $(EMHOME)/modules/compare COMPARE = $(EMHOME)/modules/compare
LIBOPT = libopt.a LIBDIR = $(EMHOME)/modules/lib
BINDIR = $(EMHOME)/lib
LIBOPT = libemopt.a
# libraries required for standalone em_nopt
INK = $(LIBDIR)/libread_emk.a
OUTK = $(LIBDIR)/libemk.a
SYS = $(LIBDIR)/libsystem.a
ALLOC = $(LIBDIR)/liballoc.a $(LIBDIR)/malloc.o
DATA = $(EMHOME)/lib/em_data.a
LIBS = $(INK) $(OUTK) $(ALLOC) $(DATA) $(SYS)
# set HOWMUCH to head -20 to limit number of patterns used # set HOWMUCH to head -20 to limit number of patterns used
#HOWMUCH = head -20 #HOWMUCH= head -20
HOWMUCH = cat HOWMUCH = cat
LEXLIB = -ll
INCLDIR = -I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg
PREFLAGS= $(INCLDIR) -DPRIVATE=static# -DDEBUG
LEXLIB = -ll
INCLDIR = -I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg
PREFLAGS = $(INCLDIR) -DPRIVATE=static
# Enable the next line to produce a version that output's the line number # Enable the next line to produce a version that output's the line number
# from the patterns file each time an optimization is performed. # from the patterns file each time an optimization is performed.
#PREFLAG = $(PREFLAGS) -DSTATS #PREFLAGS= $(PREFLAGS) -DSTATS
PROFFLAG = -O PROFFLAG= -O
CFLAGS = $(PREFLAGS) $(PROFFLAG) CFLAGS = $(PREFLAGS) $(PROFFLAG) -J
LLOPT = LLOPT =
CMD = '$(CC) -c $(CFLAGS)' CMD = '$(CC) -c $(CFLAGS)'
.SUFFIXES: .d .r .SUFFIXES: .d .r
.r.d:; CMD=$(CMD); export CMD; awk -f makefuns.awk $*.r | sh .r.d:; CMD=$(CMD); export CMD; awk -f makefuns.awk $*.r | sh
touch $@ touch $@
CSRC = nopt.c aux.c mkcalls.c outputdfa.c outcalls.c\ CSRC = main.c nopt.c mkstrct.c aux.c outputdfa.c outcalls.c\
findworst.c initlex.c findworst.c initlex.c
SRCS = Makefile nopt.h parser.h parser.g syntax.l pseudo.r patterns $(CSRC) SRCS = Makefile nopt.h parser.h parser.g syntax.l pseudo.r patterns $(CSRC)
NOFILES = nopt.o dfa.o trans.o aux.o mkcalls.o NOFILES = nopt.o dfa.o trans.o aux.o
POFILES = parser.o syntax.o outputdfa.o outcalls.o findworst.o initlex.o Lpars.o POFILES = parser.o syntax.o outputdfa.o outcalls.o findworst.o initlex.o Lpars.o
@ -37,10 +48,11 @@ GENFILES = Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\
dfa.c dfa.c.save trans.c trans.c.save incalls.d incalls.r\ dfa.c dfa.c.save trans.c trans.c.save incalls.d incalls.r\
incalls.r.save pseudo.d incalls.r.save pseudo.d
all: $(LIBOPT) all: em_nopt $(LIBOPT)
install: all install: all
$(INSTALL) lib/$(LIBOPT) $(INSTALL) lib/$(LIBOPT)
cp em_nopt $(BINDIR)
cmp: all cmp: all
$(COMPARE) lib/$(LIBOPT) $(COMPARE) lib/$(LIBOPT)
@ -52,13 +64,17 @@ opr:
make pr | opr make pr | opr
clean: clean:
rm -f C_*.o rm -f O_*.o
rm -f C_*.c rm -f O_*.c
rm -f $(NOFILES) $(POFILES) $(GENFILES) parser libopt.a rm -f $(NOFILES) main.o mkstrct.o $(POFILES)
rm -f $(GENFILES) parser libopt.a
$(LIBOPT): dfadummy $(NOFILES) pseudo.d incalls.d em_nopt: main.o $(NOFILES)
$(CC) -o em_nopt main.o $(NOFILES) $(LIBS)
$(LIBOPT): $(NOFILES) mkstrct.o pseudo.d incalls.d
rm -f $(LIBOPT) rm -f $(LIBOPT)
ar rc $(LIBOPT) C_*.o $(NOFILES) ar rc $(LIBOPT) O_*.o $(NOFILES) mkstrct.o
-sh -c 'ranlib $(LIBOPT)' -sh -c 'ranlib $(LIBOPT)'
dfadummy: patterns parser dfadummy: patterns parser
@ -76,7 +92,6 @@ dfadummy: patterns parser
# How to build program to parse patterns table and build c files. # How to build program to parse patterns table and build c files.
PARSERLIB = $(EMHOME)/lib/em_data.a\ PARSERLIB = $(EMHOME)/lib/em_data.a\
$(EMHOME)/modules/lib/libprint.a\
$(EMHOME)/modules/lib/liballoc.a\ $(EMHOME)/modules/lib/liballoc.a\
$(EMHOME)/modules/lib/libstring.a\ $(EMHOME)/modules/lib/libstring.a\
$(EMHOME)/modules/lib/libsystem.a $(EMHOME)/modules/lib/libsystem.a
@ -88,13 +103,14 @@ parserdummy: parser.g
LLgen $(LLOPT) parser.g LLgen $(LLOPT) parser.g
touch parserdummy touch parserdummy
main.o: nopt.h
nopt.o: nopt.h nopt.o: nopt.h
mkstrct.o: nopt.h
aux.o: nopt.h aux.o: nopt.h
pseudo.d: nopt.h pseudo.d: nopt.h makefuns.awk
mkcalls.o: nopt.h
dfa.o: nopt.h dfadummy dfa.o: nopt.h dfadummy
trans.o: nopt.h dfadummy trans.o: nopt.h dfadummy
incalls.d: nopt.h incalls.d: nopt.h makefuns.awk
incalls.r: dfadummy incalls.r: dfadummy
parser.o: Lpars.h parser.h parser.o: Lpars.h parser.h

View file

@ -1,4 +1,7 @@
/* $Header$ */ #ifndef NORCSID
static char rcsid4[] = "$Header$";
#endif
#include "nopt.h" #include "nopt.h"
OO_rotate(w,amount) OO_rotate(w,amount)
@ -21,8 +24,8 @@ OO_signsame(a,b)
OO_sfit(val,nbits) OO_sfit(val,nbits)
int val, nbits; int val, nbits;
{ {
long mask = 0; register long mask = 0;
int i; register int i;
for(i=nbits-1;i<8*sizeof(mask);i++) for(i=nbits-1;i<8*sizeof(mask);i++)
mask |= (1<<i); mask |= (1<<i);
return(((val&mask) == 0) | (val&mask)==mask); return(((val&mask) == 0) | (val&mask)==mask);
@ -31,58 +34,62 @@ OO_sfit(val,nbits)
OO_ufit(val, nbits) OO_ufit(val, nbits)
int val, nbits; int val, nbits;
{ {
long mask = 0; register long mask = 0;
int i; register int i;
for(i=nbits;i<8*sizeof(mask);i++) for(i=nbits;i<8*sizeof(mask);i++)
mask |= (1<<i); mask |= (1<<i);
return((val&mask) == 0); return((val&mask) == 0);
} }
OO_extsame(a1,a2) OO_extsame(a1,a2)
struct instr *a1, *a2; register p_instr a1, a2;
{ {
if(a1->argtype != a2->argtype) return(0); if (a1->em_argtype != a2->em_argtype)
switch(a1->argtype) { return(0);
switch(a1->em_argtype) {
case cst_ptyp: case cst_ptyp:
return(a1->acst == a2->acst); return (a1->em_cst == a2->em_cst);
case sof_ptyp: case sof_ptyp:
if(a1->asoff != a2->asoff) return(0); if(a1->em_off != a2->em_off)
return(strcmp(a1->adnam,a2->adnam)==0); return(0);
return (strcmp(a1->em_dnam,a2->em_dnam)==0);
case nof_ptyp: case nof_ptyp:
if(a1->anoff != a2->anoff) return(0); if (a1->em_off != a2->em_off)
return(a1->adlb == a2->adlb); return(0);
return (a1->em_dlb == a2->em_dlb);
default: default:
fatal("illegal type (%d) to sameext!",a1->argtype); fatal("illegal type (%d) to sameext!",a1->em_argtype);
} }
} }
OO_namsame(a1,a2) OO_namsame(a1,a2)
struct instr *a1, *a2; register p_instr a1, a2;
{ {
if(a1->argtype != a2->argtype) return(0); if (a1->em_argtype != a2->em_argtype)
switch(a1->argtype) { return(0);
switch(a1->em_argtype) {
case cst_ptyp: case cst_ptyp:
return(1); return 1;
case sof_ptyp: case sof_ptyp:
return(strcmp(a1->adnam,a2->adnam)==0); return (strcmp(a1->em_dnam,a2->em_dnam)==0);
case nof_ptyp: case nof_ptyp:
return(a1->adlb == a2->adlb); return (a1->em_dlb == a2->em_dlb);
default: default:
fatal("illegal type (%d) to samenam!",a1->argtype); fatal("illegal type (%d) to samenam!",a1->em_argtype);
} }
} }
OO_offset(a) OO_offset(a)
struct instr *a; register p_instr a;
{ {
switch(a->argtype) { switch(a->em_argtype) {
case cst_ptyp: case cst_ptyp:
return(a->acst); return a->em_cst;
case sof_ptyp: case sof_ptyp:
return(a->asoff); return a->em_off;
case nof_ptyp: case nof_ptyp:
return(a->anoff); return a->em_off;
default: default:
fatal("illegal type (%d) to offset!",a->argtype); fatal("illegal type (%d) to offset!",a->em_argtype);
} }
} }

View file

@ -1,5 +1,5 @@
#ifndef NORCSID #ifndef NORCSID
static char rcsid[] = "$Header$"; static char rcsidp3[] = "$Header$";
#endif #endif
#include "parser.h" #include "parser.h"
@ -30,7 +30,7 @@ findworst(repl)
int s; int s;
int mostbackups = 0; int mostbackups = 0;
if(n==0) { if(n==0) {
fprint(ofile,"\t\t\tOO_backup(%d);\n", longestpattern-1); fprintf(ofile,"\t\t\tOO_backup(%d);\n", longestpattern-1);
return; return;
} }
for(s=1;s<=higheststate;s++) { for(s=1;s<=higheststate;s++) {
@ -57,7 +57,7 @@ findworst(repl)
} }
} }
if(mostbackups) if(mostbackups)
fprint(ofile,"\t\t\tOO_backup(%d);\n",mostbackups); fprintf(ofile,"\t\t\tOO_backup(%d);\n",mostbackups);
} }
findfail(state) findfail(state)
@ -85,12 +85,12 @@ findfail(state)
continue; continue;
if((leftmatch(patterns[s],patterns[state],i,n)==1)&& if((leftmatch(patterns[s],patterns[state],i,n)==1)&&
patterns[s].m_len==(n-i+1)) { patterns[s].m_len==(n-i+1)) {
fprint(ofile,"\t{%d,%d,%d},",i-1,n-i+1,s); fprintf(ofile,"\t{%d,%d,%d},",i-1,n-i+1,s);
return; return;
} }
} }
} }
fprint(ofile,"\t{%d,0,0},",n); fprintf(ofile,"\t{%d,0,0},",n);
} }
PRIVATE int PRIVATE int

View file

@ -1,5 +1,5 @@
#ifndef NORCSID #ifndef NORCSID
static char rcsid[] = "$Header$"; static char rcsidp2[] = "$Header$";
#endif #endif
#include <em_mnem.h> #include <em_mnem.h>

102
modules/src/em_opt/main.c Normal file
View file

@ -0,0 +1,102 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid1[] = "$Header$";
#endif
/* This is the main program for the stand-alone version of the
peephole optimizer.
*/
#include "nopt.h"
char *filename; /* Name of input file */
int errors; /* Number of errors */
main(argc,argv)
char **argv;
{
register p_instr p = GETINSTR();
if (argc >= 2) {
filename = argv[1];
}
else filename = 0;
if (!EM_open(filename)) {
fatal(EM_error);
}
EM_getinstr(p);
O_init((arith) EM_wordsize, (arith) EM_pointersize);
if (argc >= 3) {
if (!O_open(argv[2])) {
fatal("O_open failed");
}
}
else if (!O_open( (char *) 0)) fatal("O_open failed");
O_magic();
for(;;) {
switch(p->em_type) {
case EM_DEFILB:
*OO_nxtpatt++ = p;
OO_dfa(p->em_opcode=op_lab);
break;
case EM_MNEM:
switch(p->em_argtype) {
case sof_ptyp:
p->em_dnam = OO_freestr(p->em_dnam);
break;
case pro_ptyp:
p->em_pnam = OO_freestr(p->em_pnam);
break;
case str_ptyp:
case ico_ptyp:
case uco_ptyp:
case fco_ptyp:
p->em_string = OO_freestr(p->em_string);
break;
}
*OO_nxtpatt++ = p;
OO_dfa(p->em_opcode);
break;
default:
FLUSHDFA();
EM_mkcalls(p);
break;
case EM_EOF:
goto got_eof;
case EM_ERROR:
error("%s", EM_error);
break;
case EM_FATAL:
fatal("%s", EM_error);
}
EM_getinstr(p=GETINSTR());
}
got_eof:
O_close();
EM_close();
exit(errors);
}
/* VARARGS */
error(s,a1,a2,a3,a4)
char *s;
{
fprintf(stderr,
"%s, line %d: ",
filename ? filename : "standard input",
EM_lineno);
fprintf(stderr,s,a1,a2,a3,a4);
fprintf(stderr, "\n");
errors++;
}
/* VARARGS */
fatal(s,a1,a2,a3,a4)
char *s;
{
error(s,a1,a2,a3,a4);
exit(1);
}

View file

@ -9,16 +9,16 @@ BEGIN {
if(seenproc) { if(seenproc) {
print "}" print "}"
print "--EOF--" print "--EOF--"
printf "if %s C_%s.c\n",CC,nam printf "if %s O_%s.c\n",CC,nam
printf "then :\nelse exit 1\nfi\n" printf "then :\nelse exit 1\nfi\n"
printf "rm -f C_%s.c\n",nam 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 > C_%s.c << '--EOF--'\n",$1 printf "cat > O_%s.c << '--EOF--'\n",$1
print "#include \"nopt.h\"" print "#include \"nopt.h\""
printf "C_%s(",$1 printf "O_%s(",$1
nparms = split($2,parms,":"); nparms = split($2,parms,":");
for(p=1;p<nparms;p++) { for(p=1;p<nparms;p++) {
if(p!=1) { if(p!=1) {
@ -52,8 +52,8 @@ END {
if(seenproc) { if(seenproc) {
print "}" print "}"
print "--EOF--" print "--EOF--"
printf "if %s C_%s.c\n",CC,nam printf "if %s O_%s.c\n",CC,nam
printf "then :\nelse exit 1\nfi\n" printf "then :\nelse exit 1\nfi\n"
printf "rm -f C_%s.c\n",nam printf "rm -f O_%s.c\n",nam
} }
} }

View file

@ -0,0 +1,90 @@
#ifndef NORCSID
static char rcsid3[] = "$Header$";
#endif
#include "nopt.h"
OO_inop(opcode)
int opcode;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
p->em_opcode = opcode;
p->em_argtype = 0;
*OO_nxtpatt++ = p;
}
OO_incst(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_nxtpatt++ = p;
}
OO_inlab(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_nxtpatt++ = p;
}
OO_inpnam(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 = OO_freestr(pnam);
*OO_nxtpatt++ = p;
}
OO_indefilb(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_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

@ -1,68 +1,67 @@
#ifndef NORCSID #ifndef NORCSID
static char rcsid[] = "$Header$"; static char rcsid2[] = "$Header$";
#endif #endif
#include "nopt.h" #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 MAXBACKUP 50
#define MAXOUTPUT 200 #define MAXOUTPUT 200
#define MAXFREEI 200 #define MAXFREEI 200
#define MAXSTRING 1000 #define MAXSTRING 1000
#define GETINSTR() (nextifree>freeiqueue)?*(--nextifree):\ extern char em_mnem[][4];
((struct instr *)Malloc(sizeof(struct instr))) 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; static char *filename;
struct instr **OO_nxtpatt; static p_instr *lastbackup;
struct instr **OO_bkupqueue; static p_instr *outputqueue;
struct instr **OO_nxtbackup; static p_instr *nextoutput;
static p_instr *lastoutput;
static p_instr *lastifree;
static char *strqueue;
static char *nextstr;
static char *laststr;
static char *filename; int OO_noutput; /* number of instructions in output queue */
static struct instr **lastbackup; int OO_WSIZE; /* wordlength */
static struct instr **outputqueue; int OO_PSIZE; /* pointer length */
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 */
#ifdef STATS #ifdef STATS
int OO_wrstats = 1; /* pattern statistics output */ int OO_wrstats = 1; /* pattern statistics output */
#endif #endif
C_init(wsize,psize) O_init(wsize,psize)
arith wsize, psize; arith wsize, psize;
{ {
allocmem(); allocmem();
O_init(wsize,psize); C_init(wsize,psize);
OO_WSIZE = wsize; OO_WSIZE = wsize;
OO_PSIZE = psize; OO_PSIZE = psize;
} }
C_open(fname) O_open(fname)
char *fname; char *fname;
{ {
filename = 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 PRIVATE
@ -70,9 +69,9 @@ fatal(s,a)
char *s; char *s;
int a; int a;
{ {
fprint(STDERR, "%s: ", filename ? filename : "standard input"); fprintf(stderr, "%s: ", filename ? filename : "standard input");
fprint(STDERR,s,a); fprintf(stderr,s,a);
fprint(STDERR,"\n"); fprintf(stderr,"\n");
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
@ -81,48 +80,65 @@ allocmem()
{ {
/* Allocate memory for queues on heap */ /* Allocate memory for queues on heap */
OO_nxtpatt = OO_patternqueue = OO_nxtpatt = OO_patternqueue =
(struct instr **)Malloc(maxpattern*sizeof(struct instr *)); (p_instr *)Malloc(OO_maxpattern*sizeof(p_instr));
OO_nxtbackup = OO_bkupqueue = OO_nxtbackup = OO_bkupqueue =
(struct instr **)Malloc(MAXBACKUP*sizeof(struct instr *)); (p_instr *)Malloc(MAXBACKUP*sizeof(p_instr));
lastbackup = OO_bkupqueue + MAXBACKUP - 1; lastbackup = OO_bkupqueue + MAXBACKUP - 1;
nextoutput = outputqueue = nextoutput = outputqueue =
(struct instr **)Malloc(MAXOUTPUT*sizeof(struct instr *)); (p_instr *)Malloc(MAXOUTPUT*sizeof(p_instr));
lastoutput = outputqueue + MAXOUTPUT - 1; lastoutput = outputqueue + MAXOUTPUT - 1;
OO_noutput = 0; OO_noutput = 0;
nextifree = freeiqueue = OO_nxtifree = OO_freeiqueue =
(struct instr **)Malloc(MAXFREEI*sizeof(struct instr *)); (p_instr *)Malloc(MAXFREEI*sizeof(p_instr));
lastifree = freeiqueue + MAXFREEI - 1; lastifree = OO_freeiqueue + MAXFREEI - 1;
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_free(p) OO_free(p)
struct instr *p; p_instr p;
{ {
if(nextifree > lastifree) { if(OO_nxtifree > lastifree) {
#ifdef DEBUG #ifdef DEBUG
fprint(STDERR,"Warning: Overflow of free intr. queue.\n"); fprintf(stderr,"Warning: Overflow of free intr. queue.\n");
fprint(STDERR,"Ignored free of "); fprintf(stderr,"Ignored free of ");
prtinst(p); prtinst(p);
fprint(STDERR,"\n"); fprintf(stderr,"\n");
printstate("Freea overflow"); printstate("Freea overflow");
#endif #endif
return; return;
} }
*nextifree++ = p; *OO_nxtifree++ = p;
} }
PRIVATE char * char *
freestr(s) OO_freestr(str)
char *s; char *str;
{ {
char *res = nextstr; register char *s = str;
while(*nextstr++ = *s++); register char *res;
if(nextstr > laststr) { while (*s++);
fprint(STDERR,"string space overflowed!\n"); again:
sys_stop(S_EXIT); 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); return(res);
} }
@ -132,13 +148,14 @@ 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.
*/ */
struct instr **p; register int n;
register p_instr *p;
#ifdef DEBUG #ifdef DEBUG
printstate("Flush"); printstate("Flush");
#endif #endif
if(OO_noutput) { if (n = OO_noutput) {
for(p=outputqueue;p<nextoutput;p++) { for(p=outputqueue;n--;p++) {
OO_mkcalls(*p); EM_mkcalls(*p);
OO_free(*p); OO_free(*p);
} }
nextoutput=outputqueue; 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) OO_out(p)
struct instr *p; p_instr p;
{ {
/* Put the instruction p on the output queue */ /* Put the instruction p on the output queue */
if(nextoutput > lastoutput) { if(nextoutput > lastoutput) {
#ifdef DEBUG #ifdef DEBUG
fprint(STDERR,"Warning: Overflow of outputqueue - output flushed\n"); fprintf(stderr,"Warning: Overflow of outputqueue - output flushed\n");
#endif #endif
OO_flush(); OO_flush();
} }
@ -315,13 +179,95 @@ OO_out(p)
*nextoutput++ = 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) OO_pushback(p)
struct instr *p; p_instr p;
{ {
/* push instr. p onto bkupqueue */ /* push instr. p onto bkupqueue */
if(OO_nxtbackup > lastbackup) { if(OO_nxtbackup > lastbackup) {
#ifdef DEBUG #ifdef DEBUG
fprint(STDERR,"Warning: Overflow of bkupqueue-backup ignored\n"); fprintf(stderr,"Warning: Overflow of bkupqueue-backup ignored\n");
printstate("Backup overflow"); printstate("Backup overflow");
#endif #endif
return; return;
@ -330,7 +276,7 @@ OO_pushback(p)
} }
OO_backup(n) OO_backup(n)
int n; register int n;
{ {
/* copy (up to) n instructions from output to backup queues */ /* copy (up to) n instructions from output to backup queues */
while(n-- && nextoutput>outputqueue) { while(n-- && nextoutput>outputqueue) {
@ -340,9 +286,9 @@ OO_backup(n)
} }
OO_dodefault(numout, numcopy) 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; q = (p = OO_patternqueue) + numout;
while(numcopy--) { while(numcopy--) {
if(numout) { if(numout) {
@ -360,60 +306,75 @@ PRIVATE
printstate(mess) printstate(mess)
char *mess; char *mess;
{ {
struct instr **p; p_instr *p;
fprint(STDERR,"%s - state: ",mess); fprintf(stderr,"%s - state: ",mess);
p = outputqueue; p = outputqueue;
while(p<nextoutput) while(p<nextoutput)
prtinst(*p++); prtinst(*p++);
fprint(STDERR," |==| "); fprintf(stderr," |==| ");
p = OO_patternqueue; p = OO_patternqueue;
while(p<OO_nxtpatt) while(p<OO_nxtpatt)
prtinst(*p++); prtinst(*p++);
fprint(STDERR," |==| "); fprintf(stderr," |==| ");
p = OO_bkupqueue; p = OO_bkupqueue;
while(p<OO_nxtbackup) while(p<OO_nxtbackup)
prtinst(*p++); prtinst(*p++);
fprint(STDERR,"\n"); fprintf(stderr,"\n");
} }
PRIVATE PRIVATE
prtinst(p) prtinst(p)
struct instr *p; p_instr p;
{ {
switch(p->opcode) { switch(p->em_type) {
default: case EM_MNEM:
fprint(STDERR,"%s",em_mnem[p->opcode-sp_fmnem]); if(p->em_opcode == OTHER)
fprintf(stderr,"OTHER");
else
fprintf(stderr,"%s",em_mnem[p->em_opcode-sp_fmnem]);
break; break;
case OTHER: case EM_PSEU:
fprint(STDERR,"OTHER"); case EM_STARTMES:
fprintf(stderr,"%s",em_pseu[p->em_opcode-sp_fpseu]);
break; 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; break;
} }
switch(p->argtype) { switch(p->em_argtype) {
case none_ptyp: case 0:
fprint(STDERR," "); fprintf(stderr," ");
break; break;
case cst_ptyp: case cst_ptyp:
fprint(STDERR," %d ",p->acst); fprintf(stderr," %d ",p->em_cst);
break;
case lab_ptyp:
fprint(STDERR,"%d: ",p->alab);
break; break;
case nof_ptyp: case nof_ptyp:
fprint(STDERR," .%d+%d ",p->adlb,p->asoff); fprintf(stderr," .%d+%d ",p->em_dlb,p->em_off);
break; break;
case sof_ptyp: case sof_ptyp:
fprint(STDERR," %s+%d ",p->adnam,p->asoff); fprintf(stderr," %s+%d ",p->em_dnam,p->em_off);
break; break;
case ilb_ptyp: case ilb_ptyp:
fprint(STDERR," *%d ",p->alab); fprintf(stderr," *%d ",p->em_ilb);
break; break;
case pro_ptyp: case pro_ptyp:
fprint(STDERR," $%s ",p->apnam); fprintf(stderr," $%s ",p->em_pnam);
break; break;
default: default:
fatal(" prtinst - Unregognized arg %d ",p->argtype); fatal(" prtinst - Unregognized arg %d ",p->em_argtype);
} }
} }
#endif #endif

View file

@ -1,4 +1,5 @@
/* $Header$ */ /* $Header$ */
#include <stdio.h>
#include <em_spec.h> #include <em_spec.h>
#include <em_mnem.h> #include <em_mnem.h>
#include <em_pseu.h> #include <em_pseu.h>
@ -10,60 +11,40 @@
#include <em_comp.h> #include <em_comp.h>
#include <system.h> #include <system.h>
#include <idf_pkg.spec> #include <idf_pkg.spec>
#include <emO_code.h> #include "emO_code.h"
#define NULL 0 #define OTHER 255
#define FLUSHDFA() if(OO_state) { OO_inop(OTHER); OO_dfa(OTHER); } \
else if(OO_noutput) OO_flush();
#define NEXTEM() ((OO_nxtbackup>OO_bkupqueue)?\
((*OO_nxtpatt++ = *(--OO_nxtbackup))->opcode):\
0)
#define op_lab 255 #define FLUSHDFA() if(OO_state) {\
#define OTHER 254 *OO_nxtpatt++ = OO_OTHER; OO_dfa(OTHER);\
#define none_ptyp 0 } else if(OO_noutput) OO_flush();
#define GETINSTR() (OO_nxtifree>OO_freeiqueue)?*(--OO_nxtifree):\
((p_instr)Malloc(sizeof(struct e_instr)))
struct e_instr *EM_getinstr(); #define op_lab sp_ilb1
struct instr { typedef struct e_instr *p_instr;
int opcode;
int argtype;
union {
arith cst;
label lab;
char *pnam;
struct {
label dlb;
arith noff;
} ndlb;
struct {
char *dnam;
arith soff;
} sdlb;
} val;
#define acst val.cst
#define alab val.lab
#define apnam val.pnam
#define adlb val.ndlb.dlb
#define anoff val.ndlb.noff
#define adnam val.sdlb.dnam
#define asoff val.sdlb.soff
};
extern struct instr **OO_patternqueue; extern p_instr *OO_freeiqueue;
extern struct instr **OO_nxtpatt; extern p_instr *OO_nxtifree;
extern struct instr **OO_bkupqueue; extern p_instr *OO_patternqueue;
extern struct instr **OO_nxtbackup; extern p_instr *OO_nxtpatt;
extern int OO_state; extern p_instr *OO_bkupqueue;
extern int OO_noutput; /* number of instructions in output queue */ extern p_instr *OO_nxtbackup;
extern int OO_WSIZE; /* wordlength */ extern p_instr OO_OTHER;
extern int OO_PSIZE; /* pointer length */ extern int OO_state;
extern int OO_noutput; /* number of instructions in output queue */
extern int OO_WSIZE; /* wordlength */
extern int OO_PSIZE; /* pointer length */
#ifdef STATS #ifdef STATS
extern int OO_wrstats; /* statistics output */ extern int OO_wrstats; /* statistics output */
#endif #endif
#define CST(p) (p->acst) extern char *OO_freestr();
#define PNAM(p) (p->apnam)
#define LAB(p) (p->alab) #define CST(p) (p->em_cst)
#define DEFILB(p) (p->alab) #define PNAM(p) (p->em_pnam)
#define LAB(p) (p->em_ilb)
#define DEFILB(p) (p->em_ilb)

View file

@ -1,5 +1,5 @@
#ifndef NORCSID #ifndef NORCSID
static char rcsid[] = "$Header$"; static char rcsidp4[] = "$Header$";
#endif #endif
#include "parser.h" #include "parser.h"
@ -9,8 +9,8 @@ outputincalls()
struct idf *op; struct idf *op;
int opcode; int opcode;
char *s; char *s;
if(!sys_open("incalls.r",OP_WRITE,&ofile)) { if((ofile=fopen("incalls.r","w"))==NULL) {
fprint(STDERR,"Fatal Error: cannot open output file incalls.r\n"); fprintf(stderr,"Fatal Error: cannot open output file incalls.r\n");
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) {
@ -18,98 +18,98 @@ outputincalls()
s = op->id_text; s = op->id_text;
switch(op->id_argfmt) { switch(op->id_argfmt) {
case NOARG: case NOARG:
fprint(ofile,"%s\t|\t|\n",s); fprintf(ofile,"%s\t|\t|\n",s);
if(op->id_used) { if(op->id_used) {
fprint(ofile,"\tOO_inop(op_%s);\n",s); fprintf(ofile,"\tOO_inop(op_%s);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_%s();\n",s); fprintf(ofile,"\tC_%s();\n",s);
} }
break; break;
case CSTOPT: case CSTOPT:
fprint(ofile,"%s_narg\t|\t|\n",s); fprintf(ofile,"%s_narg\t|\t|\n",s);
if(op->id_used) { if(op->id_used) {
fprint(ofile,"\tOO_inop(op_%s);\n",s); fprintf(ofile,"\tOO_inop(op_%s);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_%s_narg();\n",s); fprintf(ofile,"\tC_%s_narg();\n",s);
} }
/* fall thru */ /* fall thru */
case CST: case CST:
fprint(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) {
fprint(ofile,"\tOO_incst(op_%s,n);\n",s); fprintf(ofile,"\tOO_incst(op_%s,n);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_%s(n);\n",s); fprintf(ofile,"\tC_%s(n);\n",s);
} }
break; break;
case DEFILB: case DEFILB:
fprint(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) {
fprint(ofile,"\tOO_indefilb(op_%s,l);\n",s); fprintf(ofile,"\tOO_indefilb(op_%s,l);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_df_ilb(l);\n",s); fprintf(ofile,"\tC_df_ilb(l);\n",s);
} }
break; break;
case PNAM: case PNAM:
fprint(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) {
fprint(ofile,"\tOO_inpnam(op_%s,s);\n",s); fprintf(ofile,"\tOO_inpnam(op_%s,s);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_%s(s);\n",s); fprintf(ofile,"\tC_%s(s);\n",s);
} }
break; break;
case LAB: case LAB:
fprint(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) {
fprint(ofile,"\tOO_inlab(op_%s,l);\n",s); fprintf(ofile,"\tOO_inlab(op_%s,l);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_%s(l);\n",s); fprintf(ofile,"\tC_%s(l);\n",s);
} }
break; break;
case EXT: case EXT:
fprint(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) {
fprint(ofile,"\tOO_incst(op_%s,n);\n",s); fprintf(ofile,"\tOO_incst(op_%s,n);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_%s(n);\n",s); fprintf(ofile,"\tC_%s(n);\n",s);
} }
fprint(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) {
fprint(ofile,"\tOO_indnam(op_%s,s,n);\n",s); fprintf(ofile,"\tOO_indnam(op_%s,s,n);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_%s_dnam(s,n);\n",s); fprintf(ofile,"\tC_%s_dnam(s,n);\n",s);
} }
fprint(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) {
fprint(ofile,"\tOO_indlb(op_%s,l,n);\n",s); fprintf(ofile,"\tOO_indlb(op_%s,l,n);\n",s);
fprint(ofile,"\tOO_dfa(op_%s);\n",s); fprintf(ofile,"\tOO_dfa(op_%s);\n",s);
} }
else { else {
fprint(ofile,"\tFLUSHDFA();\n"); fprintf(ofile,"\tFLUSHDFA();\n");
fprint(ofile,"\tO_%s_dlb(l,n);\n",s); fprintf(ofile,"\tC_%s_dlb(l,n);\n",s);
} }
break; break;
} }

View file

@ -1,16 +1,16 @@
#ifndef NORCSID #ifndef NORCSID
static char rcsid[] = "$Header$"; static char rcsidp5[] = "$Header$";
#endif #endif
#include "parser.h" #include "parser.h"
#include "Lpars.h" #include "Lpars.h"
File *ofile; FILE *ofile;
outputnopt() outputnopt()
{ {
if(!sys_open("dfa.c",OP_WRITE,&ofile)) { if((ofile=fopen("dfa.c","w"))==NULL) {
fprint(STDERR,"Couldn't open dfa.c for output\n"); fprintf(stderr,"Couldn't open dfa.c for output\n");
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
outheaders(); outheaders();
@ -24,28 +24,28 @@ outputnopt()
PRIVATE PRIVATE
outheaders() outheaders()
{ {
fprint(ofile,"#include \"nopt.h\"\n"); fprintf(ofile,"#include \"nopt.h\"\n");
fprint(ofile,"\n"); fprintf(ofile,"\n");
fprint(ofile,"int maxpattern = %d;\n", longestpattern); fprintf(ofile,"int OO_maxpattern = %d;\n", longestpattern);
fprint(ofile,"\n"); fprintf(ofile,"\n");
} }
PRIVATE PRIVATE
outtables() outtables()
{ {
int s; int s;
fprint(ofile,"static struct defact {\n"); fprintf(ofile,"static struct defact {\n");
fprint(ofile,"\tint numoutput;\n"); fprintf(ofile,"\tint numoutput;\n");
fprint(ofile,"\tint numcopy;\n"); fprintf(ofile,"\tint numcopy;\n");
fprint(ofile,"\tint nextstate;\n"); fprintf(ofile,"\tint nextstate;\n");
fprint(ofile,"} defaultactions[] = {\n"); fprintf(ofile,"} defaultactions[] = {\n");
for(s=0;s<=higheststate;s++) { for(s=0;s<=higheststate;s++) {
findfail(s); findfail(s);
if(s%4==3) if(s%4==3)
fprint(ofile,"\n"); fprintf(ofile,"\n");
} }
fprint(ofile,"};\n"); fprintf(ofile,"};\n");
fprint(ofile,"\n"); fprintf(ofile,"\n");
} }
PRIVATE PRIVATE
@ -54,54 +54,56 @@ outdfa()
int s; int s;
struct idf *op; struct idf *op;
struct state *p; struct state *p;
fprint(ofile,"int OO_state = 0;\n"); fprintf(ofile,"int OO_state = 0;\n");
fprint(ofile,"\n"); fprintf(ofile,"\n");
fprint(ofile,"OO_dfa(last) int last; {\n"); fprintf(ofile,"OO_dfa(last) register int last; {\n");
fprint(ofile,"\twhile(last) {\n"); fprintf(ofile,"\tfor(;;) {\n");
fprint(ofile,"\t\tswitch(last) {\n"); fprintf(ofile,"\t\tswitch(last) {\n");
for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) {
if(!op->id_used) if(!op->id_used)
continue; continue;
fprint(ofile,"\t\tcase op_%s:\n",op->id_text); fprintf(ofile,"\t\tcase op_%s:\n",op->id_text);
fprint(ofile,"\t\t\tswitch(OO_state) {\n"); fprintf(ofile,"\t\t\tswitch(OO_state) {\n");
if(!op->id_startpatt) { if(!op->id_startpatt) {
fprint(ofile,"\t\t\tcase 0: "); fprintf(ofile,"\t\t\tcase 0: ");
fprint(ofile,"OO_out(*--OO_nxtpatt); "); fprintf(ofile,"OO_out(*--OO_nxtpatt); ");
fprint(ofile,"break;\n"); fprintf(ofile,"break;\n");
} }
for(s=0;s<=higheststate;s++) for(s=0;s<=higheststate;s++)
for(p=states[s];p!=(struct state *)NULL;p=p->next) { for(p=states[s];p!=(struct state *)NULL;p=p->next) {
if(p->op==op) { if(p->op==op) {
fprint(ofile,"\t\t\tcase %d: ",s); fprintf(ofile,"\t\t\tcase %d: ",s);
if(actions[p->goto_state]==(struct action *)NULL) if(actions[p->goto_state]==(struct action *)NULL)
fprint(ofile,"OO_state = %d; ",p->goto_state); fprintf(ofile,"OO_state = %d; ",p->goto_state);
else fprint(ofile,"OO_dotrans(%d); ",p->goto_state); else fprintf(ofile,"OO_dotrans(%d); ",p->goto_state);
fprint(ofile,"break;\n"); fprintf(ofile,"break;\n");
} }
} }
fprint(ofile,"\t\t\tdefault: dodefaultaction(); break;\n"); fprintf(ofile,"\t\t\tdefault: dodefaultaction(); break;\n");
fprint(ofile,"\t\t\t}\n"); fprintf(ofile,"\t\t\t}\n");
fprint(ofile,"\t\t\tbreak;\n"); fprintf(ofile,"\t\t\tbreak;\n");
} }
fprint(ofile,"\t\tdefault:\n"); fprintf(ofile,"\t\tdefault:\n");
fprint(ofile,"\t\t\tif(OO_state) dodefaultaction();\n"); fprintf(ofile,"\t\t\tif(OO_state) dodefaultaction();\n");
fprint(ofile,"\t\t\telse {\n"); fprintf(ofile,"\t\t\telse {\n");
fprint(ofile,"\t\t\t\tOO_flush();\n"); fprintf(ofile,"\t\t\t\tOO_flush();\n");
fprint(ofile,"\t\t\t\tOO_mkcalls(*--OO_nxtpatt);\n"); fprintf(ofile,"\t\t\t\tEM_mkcalls(*--OO_nxtpatt);\n");
fprint(ofile,"\t\t\t\tOO_free(*OO_nxtpatt);\n"); fprintf(ofile,"\t\t\t\tOO_free(*OO_nxtpatt);\n");
fprint(ofile,"\t\t\t}\n"); fprintf(ofile,"\t\t\t}\n");
fprint(ofile,"\t\t\tbreak;\n"); fprintf(ofile,"\t\t\tbreak;\n");
fprint(ofile,"\t\tcase OTHER:\n"); fprintf(ofile,"\t\tcase OTHER:\n");
fprint(ofile,"\t\t\tif(OO_state) dodefaultaction();\n"); fprintf(ofile,"\t\t\tif(OO_state) dodefaultaction();\n");
fprint(ofile,"\t\t\telse {\n"); fprintf(ofile,"\t\t\telse {\n");
fprint(ofile,"\t\t\t\tOO_flush();\n"); fprintf(ofile,"\t\t\t\tOO_flush();\n");
fprint(ofile,"\t\t\t\tOO_free(*--OO_nxtpatt);\n"); fprintf(ofile,"\t\t\t\t--OO_nxtpatt;\n");
fprint(ofile,"\t\t\t}\n"); fprintf(ofile,"\t\t\t}\n");
fprint(ofile,"\t\t\tbreak;\n"); fprintf(ofile,"\t\t\tbreak;\n");
fprint(ofile,"\t\t}\n"); fprintf(ofile,"\t\t}\n");
fprint(ofile,"\tlast = NEXTEM();\n"); fprintf(ofile,"\t\tif (OO_nxtbackup==OO_bkupqueue)\n");
fprint(ofile,"\t}\n"); fprintf(ofile,"\t\t\treturn;\n");
fprint(ofile,"}\n"); fprintf(ofile,"\t\tlast = ((*OO_nxtpatt++ = *(--OO_nxtbackup))->em_opcode);\n");
fprintf(ofile,"\t}\n");
fprintf(ofile,"}\n");
} }
PRIVATE PRIVATE
@ -110,7 +112,7 @@ outmnems(l)
{ {
int i; int i;
for(i=1;i<=l.m_len;i++) for(i=1;i<=l.m_len;i++)
fprint(ofile,"%s ",l.m_elems[i-1]->op_code->id_text); fprintf(ofile,"%s ",l.m_elems[i-1]->op_code->id_text);
} }
PRIVATE PRIVATE
@ -121,61 +123,61 @@ outdotrans()
struct state *p; struct state *p;
struct action *a; struct action *a;
int seennontested; int seennontested;
if(!sys_open("trans.c",OP_WRITE,&ofile)) { if((ofile=fopen("trans.c","w"))==NULL) {
fprint(STDERR,"Fatal Error: cannot open output file trans.c\n"); fprintf(stderr,"Fatal Error: cannot open output file trans.c\n");
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
fprint(ofile,"#include \"nopt.h\"\n\n"); fprintf(ofile,"#include \"nopt.h\"\n\n");
fprint(ofile,"\nOO_dotrans(s) int s; {\n"); fprintf(ofile,"\nOO_dotrans(s) int s; {\n");
fprint(ofile,"\tregister struct instr **patt = OO_patternqueue;\n"); fprintf(ofile,"\tregister p_instr *patt = OO_patternqueue;\n");
fprint(ofile,"\tswitch(OO_state=s) {\n"); fprintf(ofile,"\tswitch(OO_state=s) {\n");
fprint(ofile,"\tdefault: return;\n"); fprintf(ofile,"\tdefault: return;\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) {
fprint(ofile,"\tcase %d: /*",s); fprintf(ofile,"\tcase %d: /*",s);
outmnems(patterns[s]); outmnems(patterns[s]);
fprint(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) {
fprint(ofile,"\t\tif("); fprintf(ofile,"\t\tif(");
outexp(a->test,s); outexp(a->test,s);
fprint(ofile,") {\n"); fprintf(ofile,") {\n");
outoneaction(s,a); outoneaction(s,a);
fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len); fprintf(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len);
fprint(ofile,"\t\t}\n"); fprintf(ofile,"\t\t}\n");
} }
else { else {
if(seennontested) { if(seennontested) {
fprint(STDERR,"parser: more than one untested action on state %d\n",s); fprintf(stderr,"parser: more than one untested action on state %d\n",s);
nerrors++; nerrors++;
} }
seennontested++; seennontested++;
outoneaction(s,a); outoneaction(s,a);
fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len); fprintf(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len);
} }
} }
if(!seennontested) if(!seennontested)
fprint(ofile,"\t\treturn;\n"); fprintf(ofile,"\t\treturn;\n");
} }
fprint(ofile,"\t}\n"); fprintf(ofile,"\t}\n");
for(i=longestpattern;i>0;i--) for(i=longestpattern;i>0;i--)
fprint(ofile," free%d: OO_free(*--OO_nxtpatt);\n",i); fprintf(ofile," free%d: OO_free(*--OO_nxtpatt);\n",i);
fprint(ofile," free0: ;\n"); fprintf(ofile," free0: ;\n");
fprint(ofile,"\tOO_state=0;\n"); fprintf(ofile,"\tOO_state=0;\n");
fprint(ofile,"}\n"); fprintf(ofile,"}\n");
fprint(ofile,"\n"); fprintf(ofile,"\n");
} }
PRIVATE PRIVATE
outdodefault() outdodefault()
{ {
fprint(ofile,"\nstatic dodefaultaction() {\n"); fprintf(ofile,"\nstatic dodefaultaction() {\n");
fprint(ofile,"\tregister struct defact *p = &defaultactions[OO_state];\n"); fprintf(ofile,"\tregister struct defact *p = &defaultactions[OO_state];\n");
fprint(ofile,"\tOO_pushback(*--OO_nxtpatt);\n"); fprintf(ofile,"\tOO_pushback(*--OO_nxtpatt);\n");
fprint(ofile,"\tOO_dodefault(p->numoutput,p->numcopy);\n"); fprintf(ofile,"\tOO_dodefault(p->numoutput,p->numcopy);\n");
fprint(ofile,"\tOO_dotrans(p->nextstate);\n"); fprintf(ofile,"\tOO_dotrans(p->nextstate);\n");
fprint(ofile,"}\n"); fprintf(ofile,"}\n");
} }
PRIVATE PRIVATE
@ -183,13 +185,13 @@ outoneaction(s,a)
int s; int s;
struct action *a; struct action *a;
{ {
fprint(ofile,"\t\t/* "); fprintf(ofile,"\t\t/* ");
fprint(ofile," -> "); fprintf(ofile," -> ");
outmnems(a->replacement); outmnems(a->replacement);
fprint(ofile," */\n"); fprintf(ofile," */\n");
fprint(ofile,"#ifdef STATS\n"); fprintf(ofile,"#ifdef STATS\n");
fprint(ofile,"\t\t\tif(OO_wrstats) fprint(STDERR,\"%d\\n\");\n",a->linenum); fprintf(ofile,"\t\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n",a->linenum);
fprint(ofile,"#endif\n"); fprintf(ofile,"#endif\n");
outrepl(s,patterns[s],a->replacement); outrepl(s,patterns[s],a->replacement);
findworst(a->replacement); findworst(a->replacement);
} }
@ -210,33 +212,33 @@ outrepl(state,patt,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:
fprint(ofile,"\t\t\tOO_outop(op_%s);\n",mnem); fprintf(ofile,"\t\t\tOO_outop(op_%s);\n",mnem);
break; break;
case CST: case CST:
case CSTOPT: case CSTOPT:
fprint(ofile,"\t\t\tOO_outcst(op_%s,",mnem); fprintf(ofile,"\t\t\tOO_outcst(op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprint(ofile,");\n"); fprintf(ofile,");\n");
break; break;
case LAB: case LAB:
fprint(ofile,"\t\t\tOO_outlab(op_%s,",mnem); fprintf(ofile,"\t\t\tOO_outlab(op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprint(ofile,");\n"); fprintf(ofile,");\n");
break; break;
case DEFILB: case DEFILB:
fprint(ofile,"\t\t\tOO_outdefilb(op_%s,",mnem); fprintf(ofile,"\t\t\tOO_outdefilb(op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprint(ofile,");\n"); fprintf(ofile,");\n");
break; break;
case PNAM: case PNAM:
fprint(ofile,"\t\t\tOO_outpnam(op_%s,",mnem); fprintf(ofile,"\t\t\tOO_outpnam(op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprint(ofile,");\n"); fprintf(ofile,");\n");
break; break;
case EXT: case EXT:
fprint(ofile,"\t\t\tOO_outext(op_%s,",mnem); fprintf(ofile,"\t\t\tOO_outext(op_%s,",mnem);
outexp(ri->arg,state); outexp(ri->arg,state);
fprint(ofile,");\n"); fprintf(ofile,");\n");
break; break;
} }
} }
@ -266,30 +268,30 @@ outexp(e,state)
case GE: case GE:
case LSHIFT: case LSHIFT:
case RSHIFT: case RSHIFT:
fprint(ofile,"("); fprintf(ofile,"(");
outexp(e->exp_left,state); outexp(e->exp_left,state);
outop(e->node_type); outop(e->node_type);
outexp(e->exp_right,state); outexp(e->exp_right,state);
fprint(ofile,")"); fprintf(ofile,")");
break; break;
case NOT: case NOT:
case COMP: case COMP:
case UPLUS: case UPLUS:
case UMINUS: case UMINUS:
fprint(ofile,"("); fprintf(ofile,"(");
outop(e->node_type); outop(e->node_type);
outexp(e->exp_left,state); outexp(e->exp_left,state);
fprint(ofile,")"); fprintf(ofile,")");
break; break;
case DEFINED: case DEFINED:
fprint(ofile,"(patt[%d]->argtype!=none_ptyp)",e->leaf_val-1); fprintf(ofile,"(patt[%d]->em_argtype)",e->leaf_val-1);
break; break;
case UNDEFINED: case UNDEFINED:
fprint(ofile,"(patt[%d]->argtype==none_ptyp)",e->leaf_val-1); fprintf(ofile,"(patt[%d]->em_argtype==0)",e->leaf_val-1);
break; break;
case COMMA: case COMMA:
outext(e->exp_left); outext(e->exp_left);
fprint(ofile,","); outexp(e->exp_right,state); fprintf(ofile,","); outexp(e->exp_right,state);
break; break;
case SAMESIGN: case SAMESIGN:
case SFIT: case SFIT:
@ -297,48 +299,48 @@ outexp(e,state)
case ROTATE: case ROTATE:
outop(e->node_type); outop(e->node_type);
outexp(e->exp_left,state); outexp(e->exp_left,state);
fprint(ofile,","); fprintf(ofile,",");
outexp(e->exp_right,state); outexp(e->exp_right,state);
fprint(ofile,")"); fprintf(ofile,")");
break; break;
case SAMEEXT: case SAMEEXT:
case SAMENAM: case SAMENAM:
outop(e->node_type); outop(e->node_type);
outext(e->exp_left); outext(e->exp_left);
fprint(ofile,","); fprintf(ofile,",");
outext(e->exp_right,state); outext(e->exp_right,state);
fprint(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:
fprint(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:
case CSTOPT: case CSTOPT:
fprint(ofile,"CST(patt[%d])",e->leaf_val-1); fprintf(ofile,"CST(patt[%d])",e->leaf_val-1);
break; break;
case LAB: case LAB:
fprint(ofile,"LAB(patt[%d])",e->leaf_val-1); fprintf(ofile,"LAB(patt[%d])",e->leaf_val-1);
break; break;
case DEFILB: case DEFILB:
fprint(ofile,"DEFILB(patt[%d])",e->leaf_val-1); fprintf(ofile,"DEFILB(patt[%d])",e->leaf_val-1);
break; break;
case PNAM: case PNAM:
fprint(ofile,"PNAM(patt[%d])",e->leaf_val-1); fprintf(ofile,"PNAM(patt[%d])",e->leaf_val-1);
break; break;
case EXT: case EXT:
fprint(ofile,"OO_offset(patt[%d])",e->leaf_val-1); fprintf(ofile,"OO_offset(patt[%d])",e->leaf_val-1);
break; break;
} }
break; break;
case PSIZE: case PSIZE:
fprint(ofile,"OO_PSIZE"); break; fprintf(ofile,"OO_PSIZE"); break;
case WSIZE: case WSIZE:
fprint(ofile,"OO_WSIZE"); break; fprintf(ofile,"OO_WSIZE"); break;
case INT: case INT:
fprint(ofile,"%d",e->leaf_val); break; fprintf(ofile,"%d",e->leaf_val); break;
} }
} }
@ -347,10 +349,10 @@ outext(e)
struct exp_node *e; struct exp_node *e;
{ {
if(e->node_type!=PATARG) { if(e->node_type!=PATARG) {
fprint(STDERR,"Internal error in outext of parser\n"); fprintf(stderr,"Internal error in outext of parser\n");
nerrors++; nerrors++;
} }
fprint(ofile,"patt[%d]",e->leaf_val-1); fprintf(ofile,"patt[%d]",e->leaf_val-1);
} }
PRIVATE PRIVATE
@ -358,33 +360,33 @@ outop(op)
int op; int op;
{ {
switch(op) { switch(op) {
case LOGAND: fprint(ofile,"&&"); break; case LOGAND: fprintf(ofile,"&&"); break;
case LOGOR: fprint(ofile,"||"); break; case LOGOR: fprintf(ofile,"||"); break;
case BITAND: fprint(ofile,"&"); break; case BITAND: fprintf(ofile,"&"); break;
case BITOR: fprint(ofile,"|"); break; case BITOR: fprintf(ofile,"|"); break;
case XOR: fprint(ofile,"^"); break; case XOR: fprintf(ofile,"^"); break;
case MINUS: fprint(ofile,"-"); break; case MINUS: fprintf(ofile,"-"); break;
case PLUS: fprint(ofile,"+"); break; case PLUS: fprintf(ofile,"+"); break;
case TIMES: fprint(ofile,"*"); break; case TIMES: fprintf(ofile,"*"); break;
case DIV: fprint(ofile,"/"); break; case DIV: fprintf(ofile,"/"); break;
case MOD: fprint(ofile,"%%"); break; case MOD: fprintf(ofile,"%%"); break;
case EQ: fprint(ofile,"=="); break; case EQ: fprintf(ofile,"=="); break;
case NE: fprint(ofile,"!="); break; case NE: fprintf(ofile,"!="); break;
case LT: fprint(ofile,"<"); break; case LT: fprintf(ofile,"<"); break;
case LE: fprint(ofile,"<="); break; case LE: fprintf(ofile,"<="); break;
case GT: fprint(ofile,">"); break; case GT: fprintf(ofile,">"); break;
case GE: fprint(ofile,">="); break; case GE: fprintf(ofile,">="); break;
case LSHIFT: fprint(ofile,"<<"); break; case LSHIFT: fprintf(ofile,"<<"); break;
case RSHIFT: fprint(ofile,">>"); break; case RSHIFT: fprintf(ofile,">>"); break;
case NOT: fprint(ofile,"!"); break; case NOT: fprintf(ofile,"!"); break;
case COMP: fprint(ofile,"~"); break; case COMP: fprintf(ofile,"~"); break;
case UPLUS: fprint(ofile,"+"); break; case UPLUS: fprintf(ofile,"+"); break;
case UMINUS: fprint(ofile,"-"); break; case UMINUS: fprintf(ofile,"-"); break;
case SAMESIGN: fprint(ofile,"OO_signsame("); break; case SAMESIGN: fprintf(ofile,"OO_signsame("); break;
case SFIT: fprint(ofile,"OO_sfit("); break; case SFIT: fprintf(ofile,"OO_sfit("); break;
case UFIT: fprint(ofile,"OO_ufit("); break; case UFIT: fprintf(ofile,"OO_ufit("); break;
case ROTATE: fprint(ofile,"OO_rotate("); break; case ROTATE: fprintf(ofile,"OO_rotate("); break;
case SAMEEXT: fprint(ofile,"OO_extsame("); break; case SAMEEXT: fprintf(ofile,"OO_extsame("); break;
case SAMENAM: fprint(ofile,"OO_namsame("); break; case SAMENAM: fprintf(ofile,"OO_namsame("); break;
} }
} }

View file

@ -1,4 +1,3 @@
/* $Header$ */
/* Parser to read optimization patterns of the form: /* Parser to read optimization patterns of the form:
op1 op2 ... test : action op1 op2 ... test : action
or or
@ -13,6 +12,10 @@
%start parser, input; %start parser, input;
{ {
#ifndef NORCSID
static char rcsidp1[] = "$Header$";
#endif
#include "parser.h" #include "parser.h"
#define MAXPRIO 11 #define MAXPRIO 11
@ -20,14 +23,14 @@
struct state *states[MAXSTATES]; struct state *states[MAXSTATES];
struct action *actions[MAXSTATES]; 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 longestpattern = 0;
int nerrors = 0; 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 */
} }
input : /* empty */ input : /* empty */
@ -101,9 +104,6 @@ restriction(int argtype; struct exp_node **test;)
[ optrelop(&relop) exp(1,test) [ optrelop(&relop) exp(1,test)
{ {
*test = mknode(relop,mkleaf(PATARG,lencurrpatt),*test); *test = mknode(relop,mkleaf(PATARG,lencurrpatt),*test);
*test = mknode(LOGAND,
mkleaf(DEFINED,lencurrpatt),
*test);
} }
| DEFINED | DEFINED
{ {
@ -280,7 +280,7 @@ argno(int *val;)
{ {
*val = lastintval; *val = lastintval;
if(lastintval<0 || (lastintval>lencurrpatt)) { if(lastintval<0 || (lastintval>lencurrpatt)) {
fprint(STDERR ,"Illegal $%d on line %d\n", fprintf(stderr ,"Illegal $%d on line %d\n",
lastintval,linenum); lastintval,linenum);
nerrors++; nerrors++;
} }
@ -390,7 +390,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) {
fprint("Parser: More than %s states\n",MAXSTATES); fprintf(stderr,"Parser: More than %s states\n",MAXSTATES);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
p->goto_state= higheststate; p->goto_state= higheststate;
@ -473,12 +473,12 @@ LLmessage(insertedtok)
int insertedtok; int insertedtok;
{ {
nerrors++; nerrors++;
fprint(STDERR,"parser: syntax error on line %d: ",linenum); fprintf(stderr,"parser: syntax error on line %d: ",linenum);
if(insertedtok) { if(insertedtok) {
fprint(STDERR,"Inserted token %d\n",insertedtok); fprintf(stderr,"Inserted token %d\n",insertedtok);
yyless(0); yyless(0);
} }
else fprint(STDERR,"Deleted token %d\n",LLsymb); else fprintf(stderr,"Deleted token %d\n",LLsymb);
} }
main() { main() {
@ -487,7 +487,7 @@ main() {
patterns[0].m_len = 0; patterns[0].m_len = 0;
parser(); parser();
if(nerrors) { if(nerrors) {
fprint(STDERR,"%d errors detected\n",nerrors); fprintf(stderr,"%d errors detected\n",nerrors);
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
outputnopt(); outputnopt();

View file

@ -1,8 +1,7 @@
/* $Header$ */ /* $Header$ */
#include <stdio.h>
#include <system.h> #include <system.h>
#define NULL 0
/* type of arguments expected by each instruction */ /* type of arguments expected by each instruction */
#define NOARG 1 #define NOARG 1
#define CST 2 #define CST 2
@ -73,24 +72,24 @@ struct state {
#define MAXPATTERN 20 #define MAXPATTERN 20
/* Parser globals */ /* Parser globals */
extern struct state *states[MAXSTATES]; extern struct state *states[MAXSTATES];
extern struct action *actions[MAXSTATES]; 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 longestpattern;
extern int nerrors; extern int nerrors;
extern File *ofile; extern FILE *ofile;
/* Lexical analyser globals */ /* Lexical analyser globals */
extern struct idf *opval; /* opcode of returned OPCODE*/ 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 */ /* Functions not returning int */
char *Malloc(); char *Malloc();
struct exp_node *mknode(); struct exp_node *mknode();
struct exp_node *mkleaf(); struct exp_node *mkleaf();
struct exp_node *combinetests(); struct exp_node *combinetests();
struct mnem_list *addelem(); struct mnem_list *addelem();
struct mnem_elem **constructlist(); struct mnem_elem **constructlist();

View file

@ -1,174 +1,183 @@
df_dlb | label:l | df_dlb | label:l |
FLUSHDFA(); FLUSHDFA();
O_df_dlb(l); C_df_dlb(l);
df_dnam | char *:s | df_dnam | char *:s |
FLUSHDFA(); FLUSHDFA();
O_df_dnam(s); C_df_dnam(s);
pro | char *:s arith:l | pro | char *:s arith:l |
FLUSHDFA(); FLUSHDFA();
O_pro(s,l); C_pro(s,l);
pro_narg | char *:s | pro_narg | char *:s |
FLUSHDFA(); FLUSHDFA();
O_pro_narg(s); C_pro_narg(s);
end | arith:l | end | arith:l |
FLUSHDFA(); FLUSHDFA();
O_end(l); C_end(l);
end_narg | | end_narg | |
FLUSHDFA(); FLUSHDFA();
O_end_narg(); C_end_narg();
exa_dnam | char *:s | exa_dnam | char *:s |
FLUSHDFA(); FLUSHDFA();
O_exa_dnam(s); C_exa_dnam(s);
exa_dlb | label:l | exa_dlb | label:l |
FLUSHDFA(); FLUSHDFA();
O_exa_dlb(l); C_exa_dlb(l);
exp | char *:s | exp | char *:s |
FLUSHDFA(); FLUSHDFA();
O_exp(s); C_exp(s);
ina_dnam | char *:s | ina_dnam | char *:s |
FLUSHDFA(); FLUSHDFA();
O_ina_dnam(s); C_ina_dnam(s);
ina_dlb | label:l | ina_dlb | label:l |
FLUSHDFA(); FLUSHDFA();
O_ina_dlb(l); C_ina_dlb(l);
inp | char *:s | inp | char *:s |
FLUSHDFA(); FLUSHDFA();
O_inp(s); C_inp(s);
bss_cst | arith:n arith:w int:i | bss_cst | arith:n arith:w int:i |
FLUSHDFA(); FLUSHDFA();
O_bss_cst(n,w,i); C_bss_cst(n,w,i);
bss_icon | arith:n char *:s arith:sz int:i | bss_icon | arith:n char *:s arith:sz int:i |
FLUSHDFA(); FLUSHDFA();
O_bss_icon(n,s,sz,i); C_bss_icon(n,s,sz,i);
bss_ucon | arith:n char *:s arith:sz int:i | bss_ucon | arith:n char *:s arith:sz int:i |
FLUSHDFA(); FLUSHDFA();
O_bss_ucon(n,s,sz,i); C_bss_ucon(n,s,sz,i);
bss_fcon | arith:n char *:s arith:sz int:i | bss_fcon | arith:n char *:s arith:sz int:i |
FLUSHDFA(); FLUSHDFA();
O_bss_fcon(n,s,sz,i); C_bss_fcon(n,s,sz,i);
bss_dnam | arith:n char *:s arith:offs int:i | bss_dnam | arith:n char *:s arith:offs int:i |
FLUSHDFA(); FLUSHDFA();
O_bss_dnam(n,s,offs,i); C_bss_dnam(n,s,offs,i);
bss_dlb | arith:n label:l arith:offs int:i | bss_dlb | arith:n label:l arith:offs int:i |
FLUSHDFA(); FLUSHDFA();
O_bss_dlb(n,l,offs,i); C_bss_dlb(n,l,offs,i);
bss_ilb | arith:n label:l int:i | bss_ilb | arith:n label:l int:i |
FLUSHDFA(); FLUSHDFA();
O_bss_ilb(n,l,i); C_bss_ilb(n,l,i);
bss_pnam | arith:n char *:s int:i | bss_pnam | arith:n char *:s int:i |
FLUSHDFA(); FLUSHDFA();
O_bss_pnam(n,s,i); C_bss_pnam(n,s,i);
hol_cst | arith:n arith:w int:i | hol_cst | arith:n arith:w int:i |
FLUSHDFA(); FLUSHDFA();
O_hol_cst(n,w,i); C_hol_cst(n,w,i);
hol_icon | arith:n char *:s arith:sz int:i | hol_icon | arith:n char *:s arith:sz int:i |
FLUSHDFA(); FLUSHDFA();
O_hol_icon(n,s,sz,i); C_hol_icon(n,s,sz,i);
hol_ucon | arith:n char *:s arith:sz int:i | hol_ucon | arith:n char *:s arith:sz int:i |
FLUSHDFA(); FLUSHDFA();
O_hol_ucon(n,s,sz,i); C_hol_ucon(n,s,sz,i);
hol_fcon | arith:n char *:s arith:sz int:i | hol_fcon | arith:n char *:s arith:sz int:i |
FLUSHDFA(); FLUSHDFA();
O_hol_fcon(n,s,sz,i); C_hol_fcon(n,s,sz,i);
hol_dnam | arith:n char *:s arith:offs int:i | hol_dnam | arith:n char *:s arith:offs int:i |
FLUSHDFA(); FLUSHDFA();
O_hol_dnam(n,s,offs,i); C_hol_dnam(n,s,offs,i);
hol_dlb | arith:n label:l arith:offs int:i | hol_dlb | arith:n label:l arith:offs int:i |
FLUSHDFA(); FLUSHDFA();
O_hol_dlb(n,l,offs,i); C_hol_dlb(n,l,offs,i);
hol_ilb | arith:n label:l int:i | hol_ilb | arith:n label:l int:i |
FLUSHDFA(); FLUSHDFA();
O_hol_ilb(n,l,i); C_hol_ilb(n,l,i);
hol_pnam | arith:n char *:s int:i | hol_pnam | arith:n char *:s int:i |
FLUSHDFA(); FLUSHDFA();
O_hol_pnam(n,s,i); C_hol_pnam(n,s,i);
con_cst | arith:l | con_cst | arith:l |
FLUSHDFA(); FLUSHDFA();
O_con_cst(l); C_con_cst(l);
con_icon | char *:val arith:siz | con_icon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_con_icon(val,siz); C_con_icon(val,siz);
con_ucon | char *:val arith:siz | con_ucon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_con_ucon(val,siz); C_con_ucon(val,siz);
con_fcon | char *:val arith:siz | con_fcon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_con_fcon(val,siz); C_con_fcon(val,siz);
con_scon | char *:str arith:siz | con_scon | char *:str arith:siz |
FLUSHDFA(); FLUSHDFA();
O_con_scon(str,siz); C_con_scon(str,siz);
con_dnam | char *:str arith:val | con_dnam | char *:str arith:val |
FLUSHDFA(); FLUSHDFA();
O_con_dnam(str,val); C_con_dnam(str,val);
con_dlb | label:l arith:val | con_dlb | label:l arith:val |
FLUSHDFA(); FLUSHDFA();
O_con_dlb(l,val); C_con_dlb(l,val);
con_ilb | label:l | con_ilb | label:l |
FLUSHDFA(); FLUSHDFA();
O_con_ilb(l); C_con_ilb(l);
con_pnam | char *:str | con_pnam | char *:str |
FLUSHDFA(); FLUSHDFA();
O_con_pnam(str); C_con_pnam(str);
rom_cst | arith:l | rom_cst | arith:l |
FLUSHDFA(); FLUSHDFA();
O_rom_cst(l); C_rom_cst(l);
rom_icon | char *:val arith:siz | rom_icon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_rom_icon(val,siz); C_rom_icon(val,siz);
rom_ucon | char *:val arith:siz | rom_ucon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_rom_ucon(val,siz); C_rom_ucon(val,siz);
rom_fcon | char *:val arith:siz | rom_fcon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_rom_fcon(val,siz); C_rom_fcon(val,siz);
rom_scon | char *:str arith:siz | rom_scon | char *:str arith:siz |
FLUSHDFA(); FLUSHDFA();
O_rom_scon(str,siz); C_rom_scon(str,siz);
rom_dnam | char *:str arith:val | rom_dnam | char *:str arith:val |
FLUSHDFA(); FLUSHDFA();
O_rom_dnam(str,val); C_rom_dnam(str,val);
rom_dlb | label:l arith:val | rom_dlb | label:l arith:val |
FLUSHDFA(); FLUSHDFA();
O_rom_dlb(l,val); C_rom_dlb(l,val);
rom_ilb | label:l | rom_ilb | label:l |
FLUSHDFA(); FLUSHDFA();
O_rom_ilb(l); C_rom_ilb(l);
rom_pnam | char *:str | rom_pnam | char *:str |
FLUSHDFA(); FLUSHDFA();
O_rom_pnam(str); C_rom_pnam(str);
cst | arith:l | cst | arith:l |
FLUSHDFA(); FLUSHDFA();
O_cst(l); C_cst(l);
icon | char *:val arith:siz | icon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_icon(val,siz); C_icon(val,siz);
ucon | char *:val arith:siz | ucon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_ucon(val,siz); C_ucon(val,siz);
fcon | char *:val arith:siz | fcon | char *:val arith:siz |
FLUSHDFA(); FLUSHDFA();
O_fcon(val,siz); C_fcon(val,siz);
scon | char *:str arith:siz | scon | char *:str arith:siz |
FLUSHDFA(); FLUSHDFA();
O_scon(str,siz); C_scon(str,siz);
dnam | char *:str arith:val | dnam | char *:str arith:val |
FLUSHDFA(); FLUSHDFA();
O_dnam(str,val); C_dnam(str,val);
dlb | label:l arith:val | dlb | label:l arith:val |
FLUSHDFA(); FLUSHDFA();
O_dlb(l,val); C_dlb(l,val);
ilb | label:l | ilb | label:l |
FLUSHDFA(); FLUSHDFA();
O_ilb(l); C_ilb(l);
pnam | char *:str | pnam | char *:str |
FLUSHDFA(); FLUSHDFA();
O_pnam(str); C_pnam(str);
mes_begin | int:ms | mes_begin | int:ms |
FLUSHDFA(); FLUSHDFA();
O_mes_begin(ms); C_mes_begin(ms);
mes_end | | mes_end | |
FLUSHDFA(); FLUSHDFA();
O_mes_end(); C_mes_end();
exc | arith:c1 arith:c2 | exc | arith:c1 arith:c2 |
FLUSHDFA(); FLUSHDFA();
O_exc(c1,c2); C_exc(c1,c2);
insertpart | int:id |
FLUSHDFA();
C_insertpart(id);
beginpart | int:id |
FLUSHDFA();
C_beginpart(id);
endpart | int:id |
FLUSHDFA();
C_endpart(id);

View file

@ -3,9 +3,9 @@
#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*/
%} %}
%% %%
sfit return(SFIT); sfit return(SFIT);
@ -19,7 +19,7 @@ samesign return(SAMESIGN);
sameext return(SAMEEXT); sameext return(SAMEEXT);
samenam return(SAMENAM); samenam return(SAMENAM);
offset return(OFFSET); offset return(OFFSET);
[a-z]* { [a-z][a-z][a-z] {
opval = str2idf(yytext,0); opval = str2idf(yytext,0);
return(OPCODE); return(OPCODE);
} }