Added lint entry to Makefile and removed some things lint complained about

This commit is contained in:
bruce 1987-07-09 15:04:03 +00:00
parent 65aab404ba
commit e5dd1249b2
9 changed files with 133 additions and 89 deletions

View file

@ -1,50 +1,46 @@
# $Header$ # $Header$
EMHOME = ../../.. EMHOME = ../../..
INSTALL = $(EMHOME)/modules/install INSTALL = $(EMHOME)/modules/install
COMPARE = $(EMHOME)/modules/compare COMPARE = $(EMHOME)/modules/compare
LIBDIR = $(EMHOME)/modules/lib LINT = lint
BINDIR = $(EMHOME)/lib BINDIR = $(EMHOME)/lib
LIBOPT = libemopt.a 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 LEXLIB = -ll
INCLDIR = -I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg INCLDIR = -I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg
PREFLAGS= $(INCLDIR) -DPRIVATE=static# -DDEBUG PREFLAGS = $(INCLDIR) -DPRIVATE=static# -DDEBUG
# 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.
#PREFLAGS= $(PREFLAGS) -DSTATS #PREFLAGS = $(PREFLAGS) -DSTATS
PROFFLAG= -O
CFLAGS = $(PREFLAGS) $(PROFFLAG) PROFFLAG = -O
LLOPT = CFLAGS = $(PREFLAGS) $(PROFFLAG)
CMD = '$(CC) -c $(CFLAGS)' LINTFLAGS = $(PREFLAGS) -DNORCSID
LLOPT =
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 = 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 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\ dfa.c dfa.c.new trans.h trans.h.new trans.c trans.c.new\
incalls.d incalls.r incalls.r.new pseudo.d incalls.d incalls.r incalls.r.new pseudo.d
@ -52,10 +48,13 @@ all: em_nopt $(LIBOPT)
install: all install: all
$(INSTALL) lib/$(LIBOPT) $(INSTALL) lib/$(LIBOPT)
cp em_nopt $(BINDIR) cp em_nopt $(BINDIR)/em_nopt
lint: lintparser lintnopt
cmp: all cmp: all
$(COMPARE) lib/$(LIBOPT) $(COMPARE) lib/$(LIBOPT)
-cmp em_nopt $(BINDIR)/em_nopt
pr: pr:
@pr $(SRCS) @pr $(SRCS)
@ -69,10 +68,31 @@ clean:
rm -f $(NOFILES) main.o mkstrct.o $(POFILES) rm -f $(NOFILES) main.o mkstrct.o $(POFILES)
rm -f $(GENFILES) parser em_nopt $(LIBOPT) rm -f $(GENFILES) parser em_nopt $(LIBOPT)
em_nopt: main.o $(NOFILES) # How to build stand alone version of the optimizer
$(CC) -o em_nopt main.o $(NOFILES) $(LIBS)
$(LIBOPT): $(NOFILES) mkstrct.o pseudo.d incalls.d 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
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) rm -f $(LIBOPT)
ar rc $(LIBOPT) O_*.o $(NOFILES) mkstrct.o ar rc $(LIBOPT) O_*.o $(NOFILES) mkstrct.o
-sh -c 'ranlib $(LIBOPT)' -sh -c 'ranlib $(LIBOPT)'
@ -85,7 +105,7 @@ 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/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
@ -97,15 +117,26 @@ parserdummy: parser.g
LLgen $(LLOPT) parser.g LLgen $(LLOPT) parser.g
touch parserdummy 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 main.o: nopt.h
nopt.o: nopt.h nopt.o: nopt.h
mkstrct.o: nopt.h mkstrct.o: nopt.h
aux.o: nopt.h aux.o: nopt.h
pseudo.d: nopt.h makefuns.awk pseudo.d: nopt.h makefuns.awk
dfa.o: nopt.h trans.h dfadummy dfa.o: nopt.h trans.h
trans.o: nopt.h dfadummy trans.o: nopt.h
incalls.d: nopt.h makefuns.awk incalls.d: nopt.h makefuns.awk
incalls.r: dfadummy
parser.o: Lpars.h parser.h parser.o: Lpars.h parser.h
Lpars.o: Lpars.h Lpars.o: Lpars.h

View file

@ -4,8 +4,9 @@ static char rcsid4[] = "$Header$";
#include "nopt.h" #include "nopt.h"
arith
OO_rotate(w,amount) OO_rotate(w,amount)
int w, amount; arith w, amount;
{ {
long highmask, lowmask; long highmask, lowmask;
highmask = (long)(-1) << amount; highmask = (long)(-1) << amount;
@ -16,13 +17,13 @@ OO_rotate(w,amount)
} }
OO_signsame(a,b) OO_signsame(a,b)
int a, b; arith a, b;
{ {
return( (a ^ b) >= 0); return( (a ^ b) >= 0);
} }
OO_sfit(val,nbits) OO_sfit(val,nbits)
int val, nbits; arith val, nbits;
{ {
register long mask = 0; register long mask = 0;
register int i; register int i;
@ -32,7 +33,7 @@ OO_sfit(val,nbits)
} }
OO_ufit(val, nbits) OO_ufit(val, nbits)
int val, nbits; arith val, nbits;
{ {
register long mask = 0; register long mask = 0;
register int i; register int i;
@ -59,6 +60,7 @@ OO_extsame(a1,a2)
return (a1->em_dlb == a2->em_dlb); return (a1->em_dlb == a2->em_dlb);
default: default:
fatal("illegal type (%d) to sameext!",a1->em_argtype); fatal("illegal type (%d) to sameext!",a1->em_argtype);
/*NOTREACHED*/
} }
} }
@ -76,9 +78,11 @@ OO_namsame(a1,a2)
return (a1->em_dlb == a2->em_dlb); return (a1->em_dlb == a2->em_dlb);
default: default:
fatal("illegal type (%d) to samenam!",a1->em_argtype); fatal("illegal type (%d) to samenam!",a1->em_argtype);
/*NOTREACHED*/
} }
} }
arith
OO_offset(a) OO_offset(a)
register p_instr a; register p_instr a;
{ {
@ -91,5 +95,6 @@ OO_offset(a)
return a->em_off; return a->em_off;
default: default:
fatal("illegal type (%d) to offset!",a->em_argtype); fatal("illegal type (%d) to offset!",a->em_argtype);
/*NOTREACHED*/
} }
} }

View file

@ -26,7 +26,7 @@ findworst(repl)
/* requires a backup of n-i+1 instructions and a goto to state 0. /* requires a backup of n-i+1 instructions and a goto to state 0.
*/ */
int n = repl.m_len; int n = repl.m_len;
int first,i,j; int first,i;
int s; int s;
int mostbackups = 0; int mostbackups = 0;
if(n==0) { if(n==0) {
@ -71,7 +71,7 @@ findfail(state,resout,rescpy,resgto)
/* The first such match of the form pi pi+1 ... pn requires an output /* The first such match of the form pi pi+1 ... pn requires an output
/* of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi. /* of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi.
*/ */
int s,i,j; int s,i;
struct state *p; struct state *p;
int istrans; int istrans;
int n = patterns[state].m_len; int n = patterns[state].m_len;

View file

@ -80,7 +80,7 @@ main(argc,argv)
exit(errors); exit(errors);
} }
/* VARARGS */ /*VARARGS1*/
error(s,a1,a2,a3,a4) error(s,a1,a2,a3,a4)
char *s; char *s;
{ {
@ -93,7 +93,7 @@ error(s,a1,a2,a3,a4)
errors++; errors++;
} }
/* VARARGS */ /*VARARGS1*/
fatal(s,a1,a2,a3,a4) fatal(s,a1,a2,a3,a4)
char *s; char *s;
{ {

View file

@ -31,8 +31,8 @@ static char *nextstr;
static char *laststr; static char *laststr;
int OO_noutput; /* number of instructions in output queue */ int OO_noutput; /* number of instructions in output queue */
int OO_WSIZE; /* wordlength */ arith OO_WSIZE; /* wordlength */
int 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 */
@ -199,7 +199,8 @@ OO_outop(opcode)
} }
OO_outcst(opcode,cst) OO_outcst(opcode,cst)
int opcode,cst; int opcode;
arith cst;
{ {
register p_instr p = GETINSTR(); register p_instr p = GETINSTR();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
@ -210,7 +211,8 @@ OO_outcst(opcode,cst)
} }
OO_outlab(opcode,lab) OO_outlab(opcode,lab)
int opcode,lab; int opcode;
label lab;
{ {
register p_instr p = GETINSTR(); register p_instr p = GETINSTR();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;
@ -247,7 +249,7 @@ OO_outdefilb(opcode,deflb)
OO_outext(opcode,arg,off) OO_outext(opcode,arg,off)
int opcode; int opcode;
p_instr arg; p_instr arg;
int off; arith off;
{ {
register p_instr p = GETINSTR(); register p_instr p = GETINSTR();
p->em_type = EM_MNEM; p->em_type = EM_MNEM;

View file

@ -35,13 +35,15 @@ extern p_instr *OO_nxtbackup;
extern p_instr OO_OTHER; extern p_instr OO_OTHER;
extern int OO_state; extern int OO_state;
extern int OO_noutput; /* number of instructions in output queue */ extern int OO_noutput; /* number of instructions in output queue */
extern int OO_WSIZE; /* wordlength */ extern arith OO_WSIZE; /* wordlength */
extern int OO_PSIZE; /* pointer length */ extern arith OO_PSIZE; /* pointer length */
#ifdef STATS #ifdef STATS
extern int OO_wrstats; /* statistics output */ extern int OO_wrstats; /* statistics output */
#endif #endif
extern char *OO_freestr(); extern char *OO_freestr();
extern arith OO_rotate();
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)

View file

@ -7,10 +7,8 @@ static char rcsidp4[] = "$Header$";
outputincalls() outputincalls()
{ {
struct idf *op; struct idf *op;
int opcode;
char *s; char *s;
for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) {
opcode = op->id_opcode;
s = op->id_text; s = op->id_text;
switch(op->id_argfmt) { switch(op->id_argfmt) {
case NOARG: case NOARG:

View file

@ -33,6 +33,7 @@ PRIVATE
openofile(filename) openofile(filename)
char *filename; char *filename;
{ {
char *strcpy(), *strcat();
strcpy(ofilename,filename); strcpy(ofilename,filename);
strcpy(ofiletemp,filename); strcpy(ofiletemp,filename);
strcat(ofiletemp,".new"); strcat(ofiletemp,".new");
@ -210,23 +211,21 @@ PRIVATE
outdotrans() outdotrans()
{ {
int s; int s;
int i;
struct state *p;
struct action *a; struct action *a;
int firsttest;
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,"\t/* "); fprintf(ofile,"\t/* ");
outmnems(patterns[s]); outmnems(patterns[s]);
fprintf(ofile," */\n"); fprintf(ofile," */\n");
fprintf(ofile,"\tregister p_instr *patt = OO_patternqueue;\n"); seentested = seennontested=0;
seennontested=0;
firsttest=1;
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");
@ -246,7 +245,8 @@ outdotrans()
fprintf(ofile,"\tOO_state=%d;\n",s); fprintf(ofile,"\tOO_state=%d;\n",s);
fprintf(ofile,"\treturn;\n"); 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,"}\n");
} }
/* /*
@ -278,21 +278,20 @@ outoneaction(s,a)
fprintf(ofile,"#ifdef STATS\n"); fprintf(ofile,"#ifdef STATS\n");
fprintf(ofile,"\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n",a->linenum); fprintf(ofile,"\t\tif(OO_wrstats) fprintf(stderr,\"%d\\n\");\n",a->linenum);
fprintf(ofile,"#endif\n"); fprintf(ofile,"#endif\n");
outrepl(s,patterns[s],a->replacement); outrepl(s,a->replacement);
findworst(a->replacement); findworst(a->replacement);
} }
PRIVATE PRIVATE
outrepl(state,patt,repl) outrepl(state,repl)
int state; int state;
struct mnems patt,repl; struct mnems repl;
{ {
/* /*
/* Contruct <repl>=r1 r2 ... rn and put on output queue. /* Contruct <repl>=r1 r2 ... rn and put on output queue.
*/ */
int n = repl.m_len; int n = repl.m_len;
int m = patt.m_len; int i;
int i,j,count;
for(i=1;i<=n;i++) { for(i=1;i<=n;i++) {
struct mnem_elem *ri = repl.m_elems[i-1]; struct mnem_elem *ri = repl.m_elems[i-1];
char *mnem = ri->op_code->id_text; char *mnem = ri->op_code->id_text;
@ -303,6 +302,7 @@ outrepl(state,patt,repl)
case CST: case CST:
case CSTOPT: case CSTOPT:
fprintf(ofile,"\t\tOO_outcst(op_%s,",mnem); fprintf(ofile,"\t\tOO_outcst(op_%s,",mnem);
fprintf(ofile,"(arith)");
outexp(ri->arg,state); outexp(ri->arg,state);
fprintf(ofile,");\n"); fprintf(ofile,");\n");
break; break;
@ -377,15 +377,19 @@ outexp(e,state)
break; break;
case COMMA: case COMMA:
outext(e->exp_left); outext(e->exp_left);
fprintf(ofile,","); outexp(e->exp_right,state); fprintf(ofile,",");
fprintf(ofile,"(arith)");
outexp(e->exp_right,state);
break; break;
case SAMESIGN: case SAMESIGN:
case SFIT: case SFIT:
case UFIT: case UFIT:
case ROTATE: case ROTATE:
outop(e->node_type); outop(e->node_type);
fprintf(ofile,"(arith)");
outexp(e->exp_left,state); outexp(e->exp_left,state);
fprintf(ofile,","); fprintf(ofile,",");
fprintf(ofile,"(arith)");
outexp(e->exp_right,state); outexp(e->exp_right,state);
fprintf(ofile,")"); fprintf(ofile,")");
break; break;
@ -394,7 +398,7 @@ outexp(e,state)
outop(e->node_type); outop(e->node_type);
outext(e->exp_left); outext(e->exp_left);
fprintf(ofile,","); fprintf(ofile,",");
outext(e->exp_right,state); outext(e->exp_right);
fprintf(ofile,")"); fprintf(ofile,")");
break; break;
case PATARG: case PATARG:

View file

@ -65,25 +65,26 @@ optimization
; ;
patterns(struct exp_node **tests;) patterns(struct exp_node **tests;)
{ struct mnem_list *list; {
struct exp_node *pair1, *pair2; struct mnem_list *list;
struct exp_node *onetest; int argtype; } struct exp_node *onetest;
}
: :
{ {
list = (struct mnem_list *)NULL; list = (struct mnem_list *)NULL;
*tests = (struct exp_node *)NULL; *tests = (struct exp_node *)NULL;
} }
[ [
OPCODE OPCODE
{ {
if(++lencurrpatt>longestpattern) if(++lencurrpatt>longestpattern)
longestpattern=lencurrpatt; longestpattern=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)
opval->id_startpatt=1; opval->id_startpatt=1;
currentstate=dotransition(currentstate,opval,list,lencurrpatt); currentstate=dotransition(currentstate,opval,list,lencurrpatt);
} }
[ [
restriction(opval->id_argfmt,&onetest) restriction(opval->id_argfmt,&onetest)
{ {
@ -202,7 +203,7 @@ action(struct mnem_list **list;)
exp(int level; struct exp_node **result;) exp(int level; struct exp_node **result;)
{ struct exp_node *res1, *res2; { struct exp_node *res1, *res2;
int operator, intval; } int operator; }
: :
%if(level <= MAXPRIO) %if(level <= MAXPRIO)
exp(MAXPRIO+1,&res1) exp(MAXPRIO+1,&res1)
@ -331,8 +332,8 @@ addaction(startline, state, restrictions, finaltest, repllist)
p->replacement.m_len = lenthisrepl; p->replacement.m_len = lenthisrepl;
p->replacement.m_elems = constructlist(repllist,lenthisrepl); p->replacement.m_elems = constructlist(repllist,lenthisrepl);
/* chain new action to END of action chain */ /* chain new action to END of action chain */
if((q = actions[currentstate])==(struct action *)NULL) if((q = actions[state])==(struct action *)NULL)
actions[currentstate] = p; actions[state] = p;
else { else {
while(q->next != (struct action *)NULL) while(q->next != (struct action *)NULL)
q = q->next; q = q->next;
@ -346,7 +347,6 @@ constructlist(list,len)
int len; int len;
{ {
struct mnem_elem **p; struct mnem_elem **p;
int i;
p = (struct mnem_elem **)Malloc(len*sizeof(struct mnem_elem *)); p = (struct mnem_elem **)Malloc(len*sizeof(struct mnem_elem *));
while(len--) { while(len--) {
p[len] = list->elem; p[len] = list->elem;
@ -443,6 +443,8 @@ priority(op) int op; {
case UPLUS: case UPLUS:
case UMINUS: return(11); case UMINUS: return(11);
} }
fprintf(stderr,"Internal error: priority: - unrecognized operator\n");
return(0);
} }
struct exp_node * struct exp_node *