* given arguments.
*/
extern bool dom(); /* (bblock_p b1,b2)
- /* See if b1 dominates b2. Note that a
+ * See if b1 dominates b2. Note that a
* block always * dominates itself.
*/
extern bblock_p common_dom(); /* (bblock_p a,b)
#include "debug.h"
#include "global.h"
-
-
int linecount; /* # lines in this file */
bool verbose_flag = FALSE; /* generate verbose output ? */
+#ifdef __STDC__
+
/* VARARGS1 */
-error(s,a) char *s,*a; {
+void error(char *s, ...)
+{
+ va_list ap;
+ fprintf(stderr,"error on line %u",linecount);
+ if (filename != (char *) 0) {
+ fprintf(stderr," file %s",filename);
+ }
+ fprintf(stderr,": ");
+ va_start(ap, s);
+ vfprintf(stderr,s, ap);
+ va_end(ap);
+ fprintf(stderr,"\n");
+ abort();
+ exit(-1);
+}
+
+#ifdef TRACE
+/* VARARGS1 */
+void OUTTRACE(char *s, ...)
+{
+ va_list ap;
+ fprintf(stderr,"> ");
+ va_start(ap, s);
+ vfprintf(stderr,s, ap);
+ va_end(ap);
+ fprintf(stderr,"\n");
+}
+#endif
+#ifdef VERBOSE
+/* VARARGS1 */
+void OUTVERBOSE(char *s, ...)
+{
+ if (verbose_flag) {
+ va_list ap;
+
+ fprintf(stderr,"optimization: ");
+ va_start(ap, s);
+ vfprintf(stderr,s, ap);
+ va_end(ap);
+ fprintf(stderr,"\n");
+ }
+}
+#endif
+
+#else /* __STDC__ */
+
+/* VARARGS1 */
+void error(char *s, char *a)
+{
fprintf(stderr,"error on line %u",linecount);
if (filename != (char *) 0) {
fprintf(stderr," file %s",filename);
#ifdef TRACE
/* VARARGS1 */
-OUTTRACE(s,n)
- char *s;
- int n;
+void OUTTRACE(char *s, int n)
{
fprintf(stderr,"> ");
fprintf(stderr,s,n);
#ifdef VERBOSE
/* VARARGS1 */
-OUTVERBOSE(s,n1,n2)
- char *s;
- int n1,n2;
+void OUTVERBOSE(char *s, int n1, int n2)
{
if (verbose_flag) {
fprintf(stderr,"optimization: ");
}
#endif
-
+#endif /* __STDC__ */
#ifdef DEBUG
-badassertion(file,line) char *file; unsigned line; {
-
+void badassertion(char *file, unsigned int line)
+{
fprintf(stderr,"assertion failed file %s, line %u\n",file,line);
error("assertion");
}
/* Valid Address */
-VA(a) short *a; {
+void VA(short *a)
+{
if (a == (short *) 0) error("VA: 0 argument");
if ( ((unsigned) a & 01) == 01) {
/* MACHINE DEPENDENT TEST */
/* Valid Instruction code */
-VI(i) short i; {
+void VI(short i)
+{
if (i > ps_last) error("VI: illegal instr: %d", i);
}
/* Valid Line */
-VL(l) line_p l; {
+void VL(line_p l)
+{
byte instr, optype;
VA((short *) l);
/* Valid Data block */
-VD(d) dblock_p d; {
+void VD(dblock_p d)
+{
byte pseudo;
VA((short *) d);
/* Valid Object */
-VO(o) obj_p o; {
+void VO(obj_p o)
+{
offset off;
VA((short *) o);
/* Valid Proc */
-VP(p) proc_p p; {
+void VP(proc_p p)
+{
proc_id pid;
int nrlabs;
extern int linecount; /* # lines in this file */
extern bool verbose_flag; /* generate verbose output ? */
+#ifdef __STDC__
+
/* VARARGS 1 */
-extern error();
+void error(char *fmt, ...);
+
+# ifdef TRACE
+void OUTTRACE(char *s, ...);
+# else /* TRACE */
+# define OUTTRACE(s,n)
+# endif /* TRACE */
+# ifdef VERBOSE
+void OUTVERBOSE(char *s, ...);
+# else /* VERBOSE */
+# define OUTVERBOSE(s,n1,n2)
+# endif /* VERBOSE */
+
+#else /* __STDC__ */
+
+/* VARARGS 1 */
+extern error();
-#ifdef TRACE
+# ifdef TRACE
extern OUTTRACE();
-#else
-#define OUTTRACE(s,n)
-#endif
-#ifdef VERBOSE
+# else /* TRACE */
+# define OUTTRACE(s,n)
+# endif /* TRACE */
+
+# ifdef VERBOSE
extern OUTVERBOSE();
-#else
-#define OUTVERBOSE(s,n1,n2)
-#endif
+# else /* VERBOSE */
+# define OUTVERBOSE(s,n1,n2)
+# endif /* VERBOSE */
+
+#endif /* __STDC__ */
+
#ifdef DEBUG
/* Some (all?) Unix debuggers don't particularly like
#endif
-STATIC mach_init(machfile,phase_machinit)
- char *machfile;
- int (*phase_machinit)();
+STATIC void mach_init(char *machfile, int (*phase_machinit)(FILE *))
{
/* Read target machine dependent information */
-go(argc,argv,initialize,optimize,phase_machinit,proc_flag)
- int argc;
- char *argv[];
- int (*initialize)();
- int (*optimize)();
- int (*phase_machinit)();
- int (*proc_flag)();
+void go(int argc, char *argv[], int (*initialize)(void),
+ int (*optimize)(proc_p), int (*phase_machinit)(FILE *),
+ int (*proc_flag)(char *))
{
FILE *f, *gf, *f2, *gf2; /* The EM input and output and
* the basic block graphs input and output
}
-no_action() { }
+int no_action(proc_p dummy)
+{
+ return 0;
+}
-core_usage()
+void core_usage()
{
#ifdef DEBUG
if (core_flag) {
#endif
}
-report(s,n)
- char *s;
- int n;
+void report(char *s, int n)
{
/* Report number of optimizations found, if report_flag is set */
*
*/
+#ifdef __STDC__
+
+void go(int argc, char *argv[], int (*initialize)(void),
+ int (*optimize)(proc_p), int (*phase_machinit)(FILE *),
+ int (*proc_flag)(char *));
+
+int no_action(proc_p dummy);
+
+void core_usage();
+void report(char *s, int n);
+
+#else
extern go(); /* ( int argc; char *argv[];
* int (*initialize)(); int (*optimize)();
* Report number of optimizations found, if
* report_flag is set
*/
+
+#endif
\ No newline at end of file
#include <stdlib.h>
#include <stdio.h>
-
+#include <string.h>
/* MAKECLASSDEF
*
* This program is used by several phases of the optimizer
#define TRUE 1
#define FALSE 0
-convert(mnemfile,classfile)
- FILE *mnemfile, *classfile;
+void error(char *);
+
+void convert(FILE *mnemfile, FILE *classfile)
{
char mnem1[10], mnem2[10],def[10];
int src,res,newcl,opc;
printf("};\n");
}
-
-
-error(s)
- char *s;
+void error(char *s)
{
fprintf(stderr,"%s\n",s);
exit(-1);
}
-
-main(argc,argv)
- int argc;
- char *argv[];
+int main(int argc, char *argv[])
{
FILE *f1,*f2;
void oldline(line_p lnp);
void oldargb(argb_p abp);
void oldreg(reg_p rp);
+void oldargs(arg_p ap);
/*
* alloc routines:
return(ap);
}
-void ldargs(arg_p ap)
+void oldargs(arg_p ap)
{
arg_p next;
* Author: Hans van Staveren
*/
-flow() {
+void findreach();
+void reach(line_p lnp);
+void cleaninstrs();
+void flow()
+{
findreach(); /* determine reachable labels */
cleaninstrs(); /* throw away unreachable code */
}
-findreach() {
- register num_p *npp,np;
+void findreach()
+{
+ num_p *npp,np;
reach(instrs);
for(npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++)
}
}
-reach(lnp) register line_p lnp; {
- register num_p np;
+void reach(line_p lnp)
+{
+ num_p np;
for (;lnp != (line_p) 0; lnp = lnp->l_next) {
if(lnp->l_optyp == OPNUMLAB) {
}
}
-cleaninstrs() {
- register line_p *lpp,lp,*lastbra;
- bool reachable,superfluous;
+void cleaninstrs()
+{
+ line_p *lpp, lp, *lastbra;
+ bool reachable, superfluous;
int instr;
lpp = &instrs; lastbra = (line_p *) 0; reachable = TRUE;
/* don't add op_mli and op_mlu! */
};
+
+void enter(char *name, int value);
+void yyerror(char *s);
+void printnodes();
+void initio();
+void outpat(int exprno, int instrno);
+void outbyte(int b);
+void outshort(int s);
+void out(int w);
+
int patCBO;
int rplCBO;
%}
byte h_value;
} hashmnem[HASHSIZE];
-inithash() {
- register i;
+void inithash()
+{
+ int i;
enter("lab",op_lab);
enter("LLP",op_LLP);
enter(em_mnem[i],i+sp_fmnem);
}
-unsigned hashname(name) register char *name; {
- register unsigned h;
+unsigned int hashname(char *name)
+{
+ unsigned int h;
h = (*name++)&BMASK;
h = (h<<4)^((*name++)&BMASK);
return(h);
}
-enter(name,value) char *name; {
- register unsigned h;
+void enter(char *name, int value)
+{
+ unsigned int h;
h=hashname(name)%HASHSIZE;
while (hashmnem[h].h_name[0] != 0)
hashmnem[h].h_value = value;
}
-int mlookup(name) char *name; {
- register unsigned h;
+int mlookup(char *name)
+{
+ unsigned int h;
h = hashname(name)%HASHSIZE;
while (strncmp(hashmnem[h].h_name,name,3) != 0 &&
return(hashmnem[h].h_value&BMASK); /* 0 if not found */
}
-main() {
-
+int main(int argc, char *argv[])
+{
inithash();
initio();
yyparse();
return nerrors;
}
-yyerror(s) char *s; {
-
+void yyerror(char *s)
+{
fprintf(stderr,"line %d: %s\n",lino,s);
nerrors++;
}
-lookup(comm,operator,lnode,rnode) {
- register expr_p p;
+int lookup(int comm, int operator, int lnode, int rnode)
+{
+ expr_p p;
for (p=nodes+1;p<lastnode;p++) {
if (p->ex_operator != operator)
continue;
- if (!(p->ex_lnode == lnode && p->ex_rnode == rnode ||
- comm && p->ex_lnode == rnode && p->ex_rnode == lnode))
+ if (!((p->ex_lnode == lnode && p->ex_rnode == rnode) ||
+ (comm && p->ex_lnode == rnode && p->ex_rnode == lnode)))
continue;
return(p-nodes);
}
return(p-nodes);
}
-printnodes() {
- register expr_p p;
+void printnodes()
+{
+ expr_p p;
printf("};\n\nshort lastind = %d;\n\nexpr_t enodes[] = {\n",prevind);
for (p=nodes;p<lastnode;p++)
- printf("/* %3d */\t%3d,%6u,%6u,\n",
+ printf("/* %3ld */\t%3d,%6u,%6u,\n",
p-nodes,p->ex_operator,p->ex_lnode,p->ex_rnode);
printf("};\n\niarg_t iargs[%d];\n", (maxpatlen>0 ? maxpatlen : 1));
if (patid[0])
printf("static char rcsid[] = %s;\n",patid);
}
-initio() {
- register i;
+void initio()
+{
+ int i;
printf("#include \"param.h\"\n#include \"types.h\"\n");
printf("#include \"pattern.h\"\n\n");
curind = 1;
}
-outpat(exprno, instrno)
+void outpat(int exprno, int instrno)
{
- register int i;
+ int i;
outbyte(0); outshort(prevind); prevind=curind-3;
out(patlen);
if (patlen>maxpatlen) maxpatlen=patlen;
}
-outbyte(b) {
-
+void outbyte(int b)
+{
printf(",%3d",b);
curind++;
}
-outshort(s) {
-
+void outshort(int s)
+{
outbyte(s&0377);
outbyte((s>>8)&0377);
}
-out(w) {
-
+void out(int w)
+{
if (w<255) {
outbyte(w);
} else {
#include <stdio.h>
#endif
+int optimize();
+
#define ILLHASH 0177777
short pathash[256]; /* table of indices into pattern[] */
/* SEP */ { op_SEP, op_ste, op_sde }
};
-opcheck(bp) register byte *bp; {
-
+void opcheck(byte *bp)
+{
if (((*bp)&BMASK) >= op_pfirst)
*bp = transl[((*bp)&BMASK)-op_pfirst][opind];
}
* Estimated improvement possible: about 2%
*/
-hashpatterns() {
+void hashpatterns()
+{
short index;
- register byte *bp,*tp;
- register short i;
- unsigned short hashvalue;
+ byte *bp,*tp;
+ short i;
+ short hashvalue;
byte *save;
int patlen;
}
}
-peephole() {
+int peephole()
+{
static bool phashed = FALSE;
if (!phashed) {
return optimize();
}
-optimize() {
- register num_p *npp,np;
- register instr;
+int optimize()
+{
+ num_p *npp,np;
+ int instr;
bool madeopt;
madeopt = basicblock(&instrs);
return madeopt;
}
-offset oabs(off) offset off; {
-
+offset oabs(offset off)
+{
return(off >= 0 ? off : -off);
}
-line_p repline(ev,patlen) eval_t ev; {
- register line_p lp;
- register iarg_p iap;
- register sym_p sp;
+line_p repline(eval_t ev, int patlen)
+{
+ line_p lp;
+ iarg_p iap;
+ sym_p sp;
offset diff,newdiff;
assert(ev.e_typ != EV_UNDEF);
}
}
-offset rotate(w,amount) offset w,amount; {
+offset rotate(offset w, offset amount)
+{
offset highmask,lowmask;
#ifndef LONGOFF
eval_t undefres = { EV_UNDEF };
-eval_t compute(pexp) register expr_p pexp; {
+eval_t compute(expr_p pexp)
+{
eval_t leaf1,leaf2,res;
- register i;
- register sym_p sp;
+ int i;
+ sym_p sp;
offset mask;
switch(nparam[pexp->ex_operator]) {
assert(FALSE);
case 2:
leaf2 = compute(&enodes[pexp->ex_rnode]);
- if (leaf2.e_typ == EV_UNDEF ||
- nonumlab[pexp->ex_operator] && leaf2.e_typ == EV_NUMLAB ||
- onlyconst[pexp->ex_operator] && leaf2.e_typ != EV_CONST)
+ if ((leaf2.e_typ == EV_UNDEF) ||
+ (nonumlab[pexp->ex_operator] && leaf2.e_typ == EV_NUMLAB) ||
+ (onlyconst[pexp->ex_operator] && leaf2.e_typ != EV_CONST) )
return(undefres);
case 1:
leaf1 = compute(&enodes[pexp->ex_lnode]);
- if (leaf1.e_typ == EV_UNDEF ||
- nonumlab[pexp->ex_operator] && leaf1.e_typ == EV_NUMLAB ||
- onlyconst[pexp->ex_operator] && leaf1.e_typ != EV_CONST)
+ if ((leaf1.e_typ == EV_UNDEF) ||
+ (nonumlab[pexp->ex_operator] && leaf1.e_typ == EV_NUMLAB) ||
+ (onlyconst[pexp->ex_operator] && leaf1.e_typ != EV_CONST))
return(undefres);
case 0:
break;
{
byte *p;
unsigned int num;
- warning("May do something nasty... (%s)", __func__);
+ printf("May do something nasty... (%s)", __func__);
if (sp->s_name[0] == '.') {
num = atoi(&sp->s_name[1]);
if (num < 256) {
* Author: Hans van Staveren
*/
-regvar(ap) register arg_p ap; {
- register reg_p rp;
- register i;
+void regvar(arg_p ap)
+{
+ reg_p rp;
+ int i;
rp = newreg();
i=0;
curpro.freg = rp;
}
-inreg(off) offset off; {
+int inreg(offset off)
+{
register reg_p rp;
for (rp=curpro.freg; rp != (reg_p) 0; rp=rp->r_next)
return(FALSE);
}
-outregs() {
- register reg_p rp,tp;
- register i;
+void outregs()
+{
+ reg_p rp,tp;
+ int i;
for(rp=curpro.freg; rp != (reg_p) 0; rp = tp) {
tp = rp->r_next;
}
/* outtes() handles the output of the top elt. messages */
-outtes() {
- register num_p *npp, np;
+void outtes() {
+ num_p *npp, np;
for (npp=curpro.numhash;npp< &curpro.numhash[NNUMHASH]; npp++) {
for (np = *npp; np != (num_p) 0; np=np->n_next) {
}
}
-incregusage(off) offset off; {
- register reg_p rp;
+void incregusage(offset off)
+{
+ reg_p rp;
#ifndef GLOBAL_OPT
/* If we're optimizing the output of the global optimizer
extern char *pop_push[];
extern char flow_tab[];
+void assign_label(num_p label);
+void do_inst_label(line_p lnp);
+
#define NON_CONTINUABLE(i) (flow_tab[i]&JUMP)
#define ISABRANCH(i) (flow_tab[i]&HASLABEL)
#define ISCONDBRANCH(i) (flow_tab[i]&CONDBRA)
int state;
static int stacktop = 0;
-init_state()
+void init_state()
{
stacktop = 0;
state = KNOWN;
}
-tes_pseudos()
+void tes_pseudos()
{
- register line_p lp;
+ line_p lp;
for (lp = pseudos; lp != (line_p)0; lp = lp->l_next) {
switch(INSTR(lp)) {
case ps_con:
case ps_rom:
if (lp->l_optyp == OPLIST) {
- register arg_p ap = lp->l_a.la_arg;
+ arg_p ap = lp->l_a.la_arg;
while (ap != (arg_p) 0) {
if (ap->a_typ == ARGNUM) {
}
}
-tes_instr(lnp, x, y)
-line_p lnp, x, y;
+void tes_instr(line_p lnp, line_p x, line_p y)
{
char *s;
- register instr = INSTR(lnp);
- register int arg, argdef;
+ int instr = INSTR(lnp);
+ int arg, argdef;
int neg = 0;
if (instr == op_lab) {
}
}
-assign_label(label)
-register num_p label;
+void assign_label(num_p label)
{
if (label->n_flags & NUMSET) {
if (state == NOTREACHED || stacktop > label->n_size) {
}
}
-do_inst_label(lnp) /* (re-)install a label */
-line_p lnp;
+void do_inst_label(line_p lnp) /* (re-)install a label */
{
num_p label = lnp->l_a.la_np->n_repl;
int instr = INSTR(lnp);