# $Header$
-EMHOME = ../../..
-INSTALL = $(EMHOME)/modules/install
-COMPARE = $(EMHOME)/modules/compare
-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)
+EMHOME = ../../..
+INSTALL = $(EMHOME)/modules/install
+COMPARE = $(EMHOME)/modules/compare
+LINT = lint
+BINDIR = $(EMHOME)/lib
+LIBOPT = libemopt.a
# set HOWMUCH to head -20 to limit number of patterns used
-#HOWMUCH= head -20
-HOWMUCH = cat
+#HOWMUCH = head -20
+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# -DDEBUG
# Enable the next line to produce a version that output's the line number
# from the patterns file each time an optimization is performed.
-#PREFLAGS= $(PREFLAGS) -DSTATS
-PROFFLAG= -O
-CFLAGS = $(PREFLAGS) $(PROFFLAG)
-LLOPT =
-CMD = '$(CC) -c $(CFLAGS)'
+#PREFLAGS = $(PREFLAGS) -DSTATS
+
+PROFFLAG = -O
+CFLAGS = $(PREFLAGS) $(PROFFLAG)
+LINTFLAGS = $(PREFLAGS) -DNORCSID
+LLOPT =
+CMD = '$(CC) -c $(CFLAGS)'
.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 $@
-CSRC = main.c nopt.c mkstrct.c aux.c outputdfa.c outcalls.c\
+CSRC = main.c nopt.c mkstrct.c aux.c outputdfa.c outcalls.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
+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
-GENFILES = Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\
+GENFILES = Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\
dfa.c dfa.c.new trans.h trans.h.new trans.c trans.c.new\
incalls.d incalls.r incalls.r.new pseudo.d
install: all
$(INSTALL) lib/$(LIBOPT)
- cp em_nopt $(BINDIR)
+ cp em_nopt $(BINDIR)/em_nopt
+
+lint: lintparser lintnopt
cmp: all
$(COMPARE) lib/$(LIBOPT)
+ -cmp em_nopt $(BINDIR)/em_nopt
pr:
@pr $(SRCS)
rm -f $(NOFILES) main.o mkstrct.o $(POFILES)
rm -f $(GENFILES) parser em_nopt $(LIBOPT)
-em_nopt: main.o $(NOFILES)
- $(CC) -o em_nopt main.o $(NOFILES) $(LIBS)
+# How to build stand alone version of the optimizer
+
+NOPTLIB = $(EMHOME)/modules/lib/libread_emk.a\
+ $(EMHOME)/modules/lib/libemk.a\
+ $(EMHOME)/modules/lib/liballoc.a\
+ $(EMHOME)/modules/lib/malloc.o\
+ $(EMHOME)/modules/lib/libsystem.a\
+ $(EMHOME)/lib/em_data.a
+
+em_nopt: dfadummy main.o $(NOFILES)
+ $(CC) -o em_nopt main.o $(NOFILES) $(NOPTLIB)
+
+OLINT = main.c nopt.c aux.c dfa.c trans.c
+
+OLINTLIB = $(EMHOME)/modules/lib/llib-lread_emkV.ln\
+ $(EMHOME)/modules/lib/llib-lemk.ln\
+ $(EMHOME)/modules/lib/llib-lsystem.ln\
+ $(EMHOME)/modules/lib/llib-lalloc.ln
-$(LIBOPT): $(NOFILES) mkstrct.o pseudo.d incalls.d
+lintnopt: dfadummy $(OLINT)
+ $(LINT) $(LINTFLAGS) $(OLINT) $(OLINTLIB)
+
+# How to build the library version of the optimizer
+
+$(LIBOPT): dfadummy $(NOFILES) mkstrct.o pseudo.d incalls.d
rm -f $(LIBOPT)
ar rc $(LIBOPT) O_*.o $(NOFILES) mkstrct.o
-sh -c 'ranlib $(LIBOPT)'
# 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/liballoc.a\
$(EMHOME)/modules/lib/libstring.a\
$(EMHOME)/modules/lib/libsystem.a
LLgen $(LLOPT) parser.g
touch parserdummy
+PLINT = parser.c syntax.c outputdfa.c outcalls.c\
+ findworst.c initlex.c Lpars.c
+
+PLINTLIB = $(EMHOME)/modules/lib/llib-lalloc.ln\
+ $(EMHOME)/modules/lib/llib-lstring.ln\
+ $(EMHOME)/modules/lib/llib-lsystem.ln
+
+lintparser: parserdummy $(PLINT)
+ $(LINT) $(LINTFLAGS) $(PLINT) $(PLINTLIB)
+
+# Dependancies
+
main.o: nopt.h
nopt.o: nopt.h
mkstrct.o: nopt.h
aux.o: nopt.h
pseudo.d: nopt.h makefuns.awk
-dfa.o: nopt.h trans.h dfadummy
-trans.o: nopt.h dfadummy
+dfa.o: nopt.h trans.h
+trans.o: nopt.h
incalls.d: nopt.h makefuns.awk
-incalls.r: dfadummy
parser.o: Lpars.h parser.h
Lpars.o: Lpars.h
#include "nopt.h"
+arith
OO_rotate(w,amount)
- int w, amount;
+ arith w, amount;
{
long highmask, lowmask;
highmask = (long)(-1) << amount;
}
OO_signsame(a,b)
- int a, b;
+ arith a, b;
{
return( (a ^ b) >= 0);
}
OO_sfit(val,nbits)
- int val, nbits;
+ arith val, nbits;
{
register long mask = 0;
register int i;
}
OO_ufit(val, nbits)
- int val, nbits;
+ arith val, nbits;
{
register long mask = 0;
register int i;
return (a1->em_dlb == a2->em_dlb);
default:
fatal("illegal type (%d) to sameext!",a1->em_argtype);
+ /*NOTREACHED*/
}
}
return (a1->em_dlb == a2->em_dlb);
default:
fatal("illegal type (%d) to samenam!",a1->em_argtype);
+ /*NOTREACHED*/
}
}
+arith
OO_offset(a)
register p_instr a;
{
return a->em_off;
default:
fatal("illegal type (%d) to offset!",a->em_argtype);
+ /*NOTREACHED*/
}
}
/* requires a backup of n-i+1 instructions and a goto to state 0.
*/
int n = repl.m_len;
- int first,i,j;
+ int first,i;
int s;
int mostbackups = 0;
if(n==0) {
/* The first such match of the form pi pi+1 ... pn requires an output
/* of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi.
*/
- int s,i,j;
+ int s,i;
struct state *p;
int istrans;
int n = patterns[state].m_len;
exit(errors);
}
-/* VARARGS */
+/*VARARGS1*/
error(s,a1,a2,a3,a4)
char *s;
{
errors++;
}
-/* VARARGS */
+/*VARARGS1*/
fatal(s,a1,a2,a3,a4)
char *s;
{
static char *laststr;
int OO_noutput; /* number of instructions in output queue */
-int OO_WSIZE; /* wordlength */
-int OO_PSIZE; /* pointer length */
+arith OO_WSIZE; /* wordlength */
+arith OO_PSIZE; /* pointer length */
#ifdef STATS
int OO_wrstats = 1; /* pattern statistics output */
}
OO_outcst(opcode,cst)
- int opcode,cst;
+ int opcode;
+ arith cst;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
}
OO_outlab(opcode,lab)
- int opcode,lab;
+ int opcode;
+ label lab;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
OO_outext(opcode,arg,off)
int opcode;
p_instr arg;
- int off;
+ arith off;
{
register p_instr p = GETINSTR();
p->em_type = EM_MNEM;
extern p_instr OO_OTHER;
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 */
+extern arith OO_WSIZE; /* wordlength */
+extern arith OO_PSIZE; /* pointer length */
#ifdef STATS
extern int OO_wrstats; /* statistics output */
#endif
extern char *OO_freestr();
+extern arith OO_rotate();
+extern arith OO_offset();
#define CST(p) (p->em_cst)
#define PNAM(p) (p->em_pnam)
outputincalls()
{
struct idf *op;
- int opcode;
char *s;
for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) {
- opcode = op->id_opcode;
s = op->id_text;
switch(op->id_argfmt) {
case NOARG:
openofile(filename)
char *filename;
{
+ char *strcpy(), *strcat();
strcpy(ofilename,filename);
strcpy(ofiletemp,filename);
strcat(ofiletemp,".new");
outdotrans()
{
int s;
- int i;
- struct state *p;
struct action *a;
- int firsttest;
int seennontested;
+ int seentested;
fprintf(ofile,"#include \"nopt.h\"\n\n");
for(s=0;s<=higheststate;s++) {
if(actions[s]!=(struct action *)NULL) {
fprintf(ofile,"\nOO_%ddotrans() {\n",s);
+ fprintf(ofile,"\tregister p_instr *patt = OO_patternqueue;\n");
fprintf(ofile,"\t/* ");
outmnems(patterns[s]);
fprintf(ofile," */\n");
- fprintf(ofile,"\tregister p_instr *patt = OO_patternqueue;\n");
- seennontested=0;
- firsttest=1;
+ seentested = seennontested=0;
for(a=actions[s];a!=(struct action *)NULL;a=a->next) {
if(a->test!=(struct exp_node *)NULL) {
+ seentested++;
fprintf(ofile,"\tif(");
outexp(a->test,s);
fprintf(ofile,") {\n");
fprintf(ofile,"\tOO_state=%d;\n",s);
fprintf(ofile,"\treturn;\n");
}
- fprintf(ofile,"free:\tOO_nfree(%d);\n",patterns[s].m_len);
+ if(seentested) fprintf(ofile,"free:");
+ fprintf(ofile,"\tOO_nfree(%d);\n",patterns[s].m_len);
fprintf(ofile,"}\n");
}
/*
fprintf(ofile,"#ifdef STATS\n");
fprintf(ofile,"\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n",a->linenum);
fprintf(ofile,"#endif\n");
- outrepl(s,patterns[s],a->replacement);
+ outrepl(s,a->replacement);
findworst(a->replacement);
}
PRIVATE
-outrepl(state,patt,repl)
+outrepl(state,repl)
int state;
- struct mnems patt,repl;
+ struct mnems repl;
{
/*
/* Contruct <repl>=r1 r2 ... rn and put on output queue.
*/
int n = repl.m_len;
- int m = patt.m_len;
- int i,j,count;
+ int i;
for(i=1;i<=n;i++) {
struct mnem_elem *ri = repl.m_elems[i-1];
char *mnem = ri->op_code->id_text;
case CST:
case CSTOPT:
fprintf(ofile,"\t\tOO_outcst(op_%s,",mnem);
+ fprintf(ofile,"(arith)");
outexp(ri->arg,state);
fprintf(ofile,");\n");
break;
break;
case COMMA:
outext(e->exp_left);
- fprintf(ofile,","); outexp(e->exp_right,state);
+ fprintf(ofile,",");
+ fprintf(ofile,"(arith)");
+ outexp(e->exp_right,state);
break;
case SAMESIGN:
case SFIT:
case UFIT:
case ROTATE:
outop(e->node_type);
+ fprintf(ofile,"(arith)");
outexp(e->exp_left,state);
fprintf(ofile,",");
+ fprintf(ofile,"(arith)");
outexp(e->exp_right,state);
fprintf(ofile,")");
break;
outop(e->node_type);
outext(e->exp_left);
fprintf(ofile,",");
- outext(e->exp_right,state);
+ outext(e->exp_right);
fprintf(ofile,")");
break;
case PATARG:
;
patterns(struct exp_node **tests;)
- { struct mnem_list *list;
- struct exp_node *pair1, *pair2;
- struct exp_node *onetest; int argtype; }
+ {
+ struct mnem_list *list;
+ struct exp_node *onetest;
+ }
:
- {
- list = (struct mnem_list *)NULL;
- *tests = (struct exp_node *)NULL;
- }
+ {
+ list = (struct mnem_list *)NULL;
+ *tests = (struct exp_node *)NULL;
+ }
[
OPCODE
- {
- if(++lencurrpatt>longestpattern)
- longestpattern=lencurrpatt;
- list = addelem(list,opval, (struct exp_node *)NULL);
- opval->id_used=1;
- if(lencurrpatt==1)
- opval->id_startpatt=1;
- currentstate=dotransition(currentstate,opval,list,lencurrpatt);
- }
+ {
+ if(++lencurrpatt>longestpattern)
+ longestpattern=lencurrpatt;
+ list = addelem(list,opval, (struct exp_node *)NULL);
+ opval->id_used=1;
+ if(lencurrpatt==1)
+ opval->id_startpatt=1;
+ currentstate=dotransition(currentstate,opval,list,lencurrpatt);
+ }
[
restriction(opval->id_argfmt,&onetest)
{
exp(int level; struct exp_node **result;)
{ struct exp_node *res1, *res2;
- int operator, intval; }
+ int operator; }
:
%if(level <= MAXPRIO)
exp(MAXPRIO+1,&res1)
p->replacement.m_len = lenthisrepl;
p->replacement.m_elems = constructlist(repllist,lenthisrepl);
/* chain new action to END of action chain */
- if((q = actions[currentstate])==(struct action *)NULL)
- actions[currentstate] = p;
+ if((q = actions[state])==(struct action *)NULL)
+ actions[state] = p;
else {
while(q->next != (struct action *)NULL)
q = q->next;
int len;
{
struct mnem_elem **p;
- int i;
p = (struct mnem_elem **)Malloc(len*sizeof(struct mnem_elem *));
while(len--) {
p[len] = list->elem;
case UPLUS:
case UMINUS: return(11);
}
+ fprintf(stderr,"Internal error: priority: - unrecognized operator\n");
+ return(0);
}
struct exp_node *