diff --git a/h/con_float b/h/con_float index a0ce783cc..8f8eeb8ad 100644 --- a/h/con_float +++ b/h/con_float @@ -97,8 +97,7 @@ int sz; #include #include -int float_cst(str, sz, buf) char *str, *buf; -int sz; +static int float_cst(const char *float_str, int sz, char *buf) { int overflow = 0; flt_arith e; @@ -107,7 +106,7 @@ int sz; { return 1; } - flt_str2flt(str, &e); + flt_str2flt(float_str, &e); #ifdef IEEEFLOAT if (sz == 4) { @@ -115,7 +114,7 @@ int sz; #ifdef PDPFLOAT e.flt_exp += 129; #else - e.flt_exp += 127; + e.flt_exp += 127; #endif if (e.flt_mantissa.flt_h_32 == 0) e.flt_exp = 0; diff --git a/mach/i386/ncg/mach.c b/mach/i386/ncg/mach.c index 5f67a3dfb..008d683cf 100644 --- a/mach/i386/ncg/mach.c +++ b/mach/i386/ncg/mach.c @@ -16,7 +16,7 @@ static char rcs_mh[]= ID_MH ; */ void -con_part(sz,w) register sz; word w; { +con_part(int sz, word w) { while (part_size % sz) part_size++; diff --git a/mach/i86/ncg/mach.c b/mach/i86/ncg/mach.c index 17cc876b6..31d1926ea 100644 --- a/mach/i86/ncg/mach.c +++ b/mach/i86/ncg/mach.c @@ -14,7 +14,7 @@ static char rcs_mh[]= ID_MH ; */ void -con_part(sz,w) register sz; word w; { +con_part(int sz, word w) { while (part_size % sz) part_size++; diff --git a/mach/m68020/ncg/mach.c b/mach/m68020/ncg/mach.c index 0df6c8389..b86a06bbd 100644 --- a/mach/m68020/ncg/mach.c +++ b/mach/m68020/ncg/mach.c @@ -18,7 +18,7 @@ #include void -con_part(sz,w) register sz; word w; { +con_part(int sz, word w) { while (part_size % sz) part_size++; @@ -88,7 +88,7 @@ regscore(off,size,typ,score,totyp) return score; } struct regsav_t { - char *rs_reg; /* e.g. "a3" or "d5" */ + const char *rs_reg; /* e.g. "a3" or "d5" */ long rs_off; /* offset of variable */ int rs_size; /* 2 or 4 bytes */ } regsav[9]; diff --git a/mach/m68020/ncg/table b/mach/m68020/ncg/table index a0f649b3e..03a2ed3c6 100644 --- a/mach/m68020/ncg/table +++ b/mach/m68020/ncg/table @@ -25,7 +25,7 @@ Something very wrong here! #define SYNTAX_68020 1 #endif -/* #define FANCY_MODES 1 +/* #define FANCY_MODES 1 */ /* On the M68020, there are some real fancy addressing modes. Their use makes the code a bit shorter, but also much slower. The FANCY_MODES #define enables the use of these addressing diff --git a/mach/mips/top/table b/mach/mips/top/table index c0037f54d..655f288c7 100644 --- a/mach/mips/top/table +++ b/mach/mips/top/table @@ -4,6 +4,10 @@ MAXOP 5; LABEL_STARTER '.'; +{ +int plus(const char *, const char *, char *); +} + %%; X, Y, Z { TRUE }; @@ -27,7 +31,7 @@ static int fits16(long l) { } /* Tries sum = a + b with signed 16-bit integers. */ -int plus(const char *a, const char *b, const char *sum) +int plus(const char *a, const char *b, char *sum) { long la, lb, lsum; char *end; diff --git a/mach/pdp/top/table b/mach/pdp/top/table index 7de05c47c..eab213b6a 100644 --- a/mach/pdp/top/table +++ b/mach/pdp/top/table @@ -6,6 +6,13 @@ MAXOP 2; LABEL_STARTER 'I'; OPC_TERMINATOR ' '; +{ +int no_side_effects(char *); +int is_register(char *); +int is_scratchreg(char *); +int carry_dead(char *); +} + %%; /* useful addressing modes: */ diff --git a/mach/powerpc/ncg/mach.h b/mach/powerpc/ncg/mach.h index 0bca86fae..10c3a6a35 100644 --- a/mach/powerpc/ncg/mach.h +++ b/mach/powerpc/ncg/mach.h @@ -9,10 +9,10 @@ #define newilb(x) fprintf(codefile,"%s:\n",x) #define newdlb(x) fprintf(codefile,"%s:\n",x) #define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) -#define newlbss(l,x) fprintf(codefile,".comm %s,%u\n",l,x); +#define newlbss(l,x) fprintf(codefile,".comm %s,%ld\n",l,x); -#define cst_fmt "%d" -#define off_fmt "%d" +#define cst_fmt "%ld" +#define off_fmt "%ld" #define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/mach/powerpc/top/table b/mach/powerpc/top/table index 196cae128..b606fd0c5 100644 --- a/mach/powerpc/top/table +++ b/mach/powerpc/top/table @@ -4,6 +4,13 @@ MAXOP 5; LABEL_STARTER '.'; +{ +int not_using_sp(const char *); +int positive(const char *); +int lift(const char *); +int plus(const char *, const char *, char *); +} + %%; L1, L2, L3, L4, L5 { not_using_sp(VAL) }; @@ -160,7 +167,7 @@ static int liftcmp(const void *a, const void *b) { int lift(const char *s) { return bsearch(&s, liftables, sizeof(liftables) / sizeof(liftables[0]), - sizeof(liftables[0]), liftcmp); + sizeof(liftables[0]), liftcmp) != NULL; } @@ -170,7 +177,7 @@ static int fits16(long l) { } /* Tries sum = a + b with signed 16-bit integers. */ -int plus(const char *a, const char *b, const char *sum) +int plus(const char *a, const char *b, char *sum) { long la, lb, lsum; char *end; diff --git a/mach/proto/as/comm1.h b/mach/proto/as/comm1.h index 29acbca6e..87df5279a 100644 --- a/mach/proto/as/comm1.h +++ b/mach/proto/as/comm1.h @@ -106,7 +106,7 @@ extern int curr_token; int yyparse(void); /* comm4.c */ void stop(void); -void newmodule(const char *); +void newmodule(char *); /* comm5.c */ int yylex(void); void putval(int); diff --git a/mach/proto/as/comm4.c b/mach/proto/as/comm4.c index 08c053ed0..4abf13dbb 100644 --- a/mach/proto/as/comm4.c +++ b/mach/proto/as/comm4.c @@ -35,6 +35,10 @@ void stop(void) { exit(nerrors != 0); } +static void stop_on_signal(int sig) { + stop(); +} + int main(int argc, char **argv) { @@ -54,9 +58,9 @@ main(int argc, char **argv) } progname = *argv++; argc--; - for (p = sigs; i = *p++; ) + for (p = sigs; (i = *p++) != 0; ) if (signal(i, SIG_IGN) != SIG_IGN) - signal(i, stop); + signal(i, stop_on_signal); for (i = 0; i < argc; i++) { p = argv[i]; if (*p++ != '-') @@ -433,7 +437,7 @@ pass_23(int n) } void -newmodule(const char *s) +newmodule(char *s) { static char nmbuf[STRINGMAX]; diff --git a/mach/proto/ncg/build.lua b/mach/proto/ncg/build.lua index 1210382fc..6ab573a8a 100644 --- a/mach/proto/ncg/build.lua +++ b/mach/proto/ncg/build.lua @@ -20,6 +20,7 @@ definerule("build_ncg", "mach/proto/ncg/result.h", "mach/proto/ncg/state.h", "mach/proto/ncg/types.h", + "mach/proto/ncg/xmach.h", "mach/"..e.arch.."/ncg/mach.c", "mach/"..e.arch.."/ncg/*.h", } diff --git a/mach/proto/ncg/codegen.c b/mach/proto/ncg/codegen.c index 4ae6363f0..cb1bba8ac 100644 --- a/mach/proto/ncg/codegen.c +++ b/mach/proto/ncg/codegen.c @@ -706,7 +706,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for do { npos = exactmatch = 0; - for (rpp = reglist[propno]; rp = *rpp; rpp++) + for (rpp = reglist[propno]; (rp = *rpp) != NULL; rpp++) if (getrefcount((int)(rp - machregs), FALSE) == 0) { pos[npos++] = rp - machregs; diff --git a/mach/proto/ncg/fillem.c b/mach/proto/ncg/fillem.c index 7f0e4c681..c83144b1a 100644 --- a/mach/proto/ncg/fillem.c +++ b/mach/proto/ncg/fillem.c @@ -23,6 +23,9 @@ static char rcsid2[] = "$Id$"; #include "regvar.h" #include #endif +#ifdef USE_TES +#include "label.h" +#endif #include "extern.h" /* @@ -80,10 +83,16 @@ static int regallowed=0; extern char em_flag[]; extern short em_ptyp[]; -/* machine dependent */ +/* + * Declare the machine dependent functions. + * + * These functions now return void, which is not compatible with + * traditional K&R C. Old mach.c files stop working until one fixes + * them to return void, not int. + */ void con_part(int, word); void con_mult(word); -void con_float(void); /* actually returns void, but need K&R C compatibility */ +void con_float(void); void prolog(full nlocals); void mes(word); @@ -706,8 +715,8 @@ static void savelab(void) { } p = argstr; q = labstr; - while (*q++ = *p++) - ; + while ((*q++ = *p++) != '\0') + continue; } static void dumplab(void) { diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index 5b092340f..8b097f9ec 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -13,7 +13,7 @@ static char rcsid[] = "$Id$"; #include "result.h" #include "extern.h" #ifdef USE_TES -#include "mach.h" +#include "xmach.h" #endif /* diff --git a/mach/proto/ncg/main.c b/mach/proto/ncg/main.c index 0b3a40f86..80915e94d 100644 --- a/mach/proto/ncg/main.c +++ b/mach/proto/ncg/main.c @@ -6,7 +6,7 @@ static char rcsid[] = "$Id$"; #include "param.h" #include "tables.h" #include "types.h" -#include "mach.h" +#include "xmach.h" /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. diff --git a/mach/proto/ncg/types.h b/mach/proto/ncg/types.h index 825d2e42d..6427ffbf7 100644 --- a/mach/proto/ncg/types.h +++ b/mach/proto/ncg/types.h @@ -67,7 +67,3 @@ void garbage_collect(void); void itokcost(void); void error(const char *s, ...); void fatal(const char *s, ...); - -#ifdef MACH_OPTIONS -void mach_option(char *); /* machine dependent */ -#endif diff --git a/mach/proto/ncg/xmach.h b/mach/proto/ncg/xmach.h new file mode 100644 index 000000000..7211c00af --- /dev/null +++ b/mach/proto/ncg/xmach.h @@ -0,0 +1,15 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ + +/* + * Include "mach.h", then if "mach.h" defines MACH_OPTIONS, also + * declare mach_option(), a machine dependent function. + */ + +#include "mach.h" + +#ifdef MACH_OPTIONS +void mach_option(char *); +#endif diff --git a/mach/proto/top/queue.c b/mach/proto/top/queue.c index 922e59441..d88964a85 100644 --- a/mach/proto/top/queue.c +++ b/mach/proto/top/queue.c @@ -6,21 +6,18 @@ #include "top.h" #include "queue.h" -empty_queue(q) - register queue q; +void empty_queue(queue q) { q->head = q->tail = (instr_p) 0; q->qlen = 0; } -int empty(q) - queue q; +int empty(queue q) { return q->qlen == 0; } -remove_head(q) - register queue q; +void remove_head(queue q) { if ( (q->head = q->head->fw) == (instr_p) 0) { q->tail = (instr_p) 0; @@ -30,9 +27,7 @@ remove_head(q) q->qlen--; } -add(q,instr) - register queue q; - register instr_p instr; +void add(queue q, instr_p instr) { if (q->qlen++ == 0) { q->head = q->tail = instr; @@ -45,9 +40,7 @@ add(q,instr) instr->fw = (instr_p) 0; } -insert(q,instr) - register queue q; - register instr_p instr; +void insert(queue q, instr_p instr) { if (q->qlen++ == 0) { q->head = q->tail = instr; @@ -60,8 +53,7 @@ insert(q,instr) instr->bw = (instr_p) 0; } -join_queues(q1,q2) - register queue q1,q2; +void join_queues(queue q1, queue q2) { if (q1->qlen > 0) { q2->qlen += q1->qlen; diff --git a/mach/proto/top/queue.h b/mach/proto/top/queue.h index 05fff2d05..f3b3ba4bc 100644 --- a/mach/proto/top/queue.h +++ b/mach/proto/top/queue.h @@ -14,3 +14,10 @@ struct queue_t { #define qhead(q) (q)->head #define qlength(q) (q)->qlen #define next(x) (x)->fw + +void empty_queue(queue); +int empty(queue); +void remove_head(queue); +void add(queue, instr_p); +void insert(queue, instr_p); +void join_queues(queue, queue); diff --git a/mach/proto/top/top.c b/mach/proto/top/top.c index 5d57fa1de..1431ae585 100644 --- a/mach/proto/top/top.c +++ b/mach/proto/top/top.c @@ -4,6 +4,7 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ +#include #include #include #include @@ -13,18 +14,38 @@ /* STANDARD MACHINE-INDEPENT C CODE *************/ -extern char *lstrip(); -extern instr_p newinstr(); -extern instr_p read_instr(); -extern instr_p gen_instr(); +static void optimize(void); +static bool try_hashentry(int *, queue); +static int hash(queue); +static void fill_window(queue, int); +static void write_first(queue); +static void set_opcode(instr_p); +static bool check_pattern(patdescr_p, queue); +static bool check_operands(patdescr_p, queue); +static void clear_vars(void); +static bool opmatch(templ_p, const char *); +static bool split_operands(instr_p); +static void labeldef(instr_p); +static bool operand(instr_p, int); +static bool remainder_empty(instr_p); +static char *lstrip(char *, const char *); +static bool rstrip(char *, const char *); +static bool unify(const char *, struct variable *); +static void xform(patdescr_p, queue); +static void replacement(patdescr_p, queue); +static instr_p gen_instr(idescr_p); +static instr_p read_instr(void); +static instr_p newinstr(void); +static void oldinstr(instr_p); +static bool op_separator(instr_p); +static bool well_shaped(const char *); +static bool is_letter(char); -struct variable var[NRVARS+1]; -struct variable ANY; /* ANY symbol matching any instruction */ +static struct variable var[NRVARS+1]; +static struct variable ANY; /* ANY symbol matching any instruction */ -char *REST; /* Opcode of first instruction not matched by current pattern */ - -void labeldef(); -void set_opcode(); +/* Opcode of first instruction not matched by current pattern */ +static char *REST; #include "gen.c" @@ -36,7 +57,7 @@ void set_opcode(); /* Skip white space in the unprocessed part of instruction 'ip' */ #define skip_white(ip) while (is_white(*(ip)->rest_line)) (ip)->rest_line++ -main() +int main(void) { optimize(); exit(0); @@ -63,7 +84,7 @@ main() * is written to the output and is removed. */ -optimize() +static void optimize(void) { struct queue_t windowq, backupq; queue window, backup; @@ -93,11 +114,9 @@ optimize() -bool try_hashentry(list,window) - int *list; - queue window; +static bool try_hashentry(int *list, queue window) { - register int *pp; + int *pp; patdescr_p p; for (pp = list; *pp != -1; pp++) { @@ -126,11 +145,10 @@ bool try_hashentry(list,window) */ -int hash(w) - queue w; +static int hash(queue w) { - register char *p; - register sum,i; + char *p; + int sum,i; instr_p ip; ip = qhead(w); @@ -147,10 +165,9 @@ int hash(w) * When end-of-file is encountered it may contain fewer items. */ -fill_window(w,len) - register queue w; +static void fill_window(queue w, int len) { - register instr_p ip; + instr_p ip; while(qlength(w) < len) { if ((ip = read_instr()) == NIL) break; @@ -160,10 +177,9 @@ fill_window(w,len) } } -write_first(w) - queue w; +static void write_first(queue w) { - register instr_p ip = qhead(w); + instr_p ip = qhead(w); fputs(ip->line, stdout); remove_head(w); @@ -173,12 +189,9 @@ write_first(w) /* Try to recognize the opcode part of an instruction */ -void -set_opcode(ip) - register instr_p ip; +static void set_opcode(instr_p ip) { - register char *p,*q; - char *qlim; + char *p,*q,*qlim; if (ip->state == JUNK) return; skip_white(ip); @@ -206,13 +219,10 @@ set_opcode(ip) /* Check if pattern 'p' matches the current input */ -bool check_pattern(p,w) - patdescr_p p; - queue w; +static bool check_pattern(patdescr_p p, queue w) { - register idescr_p id_p; - idescr_p idlim; - register instr_p ip; + idescr_p id_p, idlim; + instr_p ip; ip = qhead(w); ANY.vstate = UNINSTANTIATED; @@ -232,12 +242,10 @@ bool check_pattern(p,w) -bool check_operands(p,w) - patdescr_p p; - queue w; +static bool check_operands(patdescr_p p, queue w) { - register instr_p ip; - register idescr_p id_p; + instr_p ip; + idescr_p id_p; int n; /* fprintf(stderr,"try pattern %d\n",p-patterns); */ @@ -263,9 +271,9 @@ bool check_operands(p,w) /* Reset all variables to uninstantiated */ -clear_vars() +static void clear_vars(void) { - register v; + int v; for (v = 1; v <= NRVARS; v++) var[v].vstate = UNINSTANTIATED; } @@ -278,9 +286,7 @@ clear_vars() * mode-definitions part of the table. */ -bool opmatch(t,s) - templ_p t; - char *s; +static bool opmatch(templ_p t, const char *s) { char *l, buf[MAXOPLEN+1]; bool was_instantiated; @@ -304,10 +310,9 @@ bool opmatch(t,s) /* Try to recognize the operands of an instruction */ -bool split_operands(ip) - register instr_p ip; +static bool split_operands(instr_p ip) { - register int i; + int i; bool res; if (strcmp(ip->opc,"labdef") ==0) { @@ -322,11 +327,9 @@ bool split_operands(ip) -void -labeldef(ip) - register instr_p ip; +static void labeldef(instr_p ip) { - register char *p; + char *p; int oplen; p = ip->rest_line; @@ -344,10 +347,9 @@ labeldef(ip) /* Try to recognize the next operand of instruction 'ip' */ -bool operand(ip,n) - register instr_p ip; +static bool operand(instr_p ip, int n) { - register char *p; + char *p; int oplen; #ifdef PAREN_OPEN int nesting = 0; @@ -381,8 +383,7 @@ bool operand(ip,n) * (or contains only white space). */ -bool remainder_empty(ip) - instr_p ip; +static bool remainder_empty(instr_p ip) { skip_white(ip); return *ip->rest_line == '\n'; @@ -393,8 +394,7 @@ bool remainder_empty(ip) * succeeds then return a pointer to the rest (unmatched part) of 'str'. */ -char *lstrip(str,ctxt) - register char *str, *ctxt; +static char *lstrip(char *str, const char *ctxt) { assert(ctxt != NULLSTRING); while (*str != '\0' && *str == *ctxt) { @@ -410,10 +410,10 @@ char *lstrip(str,ctxt) * replace truncate 'str'. */ -bool rstrip(str,ctxt) - char *str,*ctxt; +static bool rstrip(char *str, const char *ctxt) { - register char *s, *c; + char *s; + const char *c; for (s = str; *s != '\0'; s++); for (c = ctxt; *c != '\0'; c++); @@ -432,9 +432,7 @@ bool rstrip(str,ctxt) * variable becomes instantiated to the string. */ -bool unify(str,v) - char *str; - register struct variable *v; +static bool unify(const char *str, struct variable *v) { if (v->vstate == UNINSTANTIATED) { v->vstate = INSTANTIATED; @@ -449,11 +447,9 @@ bool unify(str,v) /* Transform the working window according to pattern 'p' */ -xform(p,w) - patdescr_p p; - queue w; +static void xform(patdescr_p p, queue w) { - register instr_p ip; + instr_p ip; int i; for (i = 0; i < p->patlen; i++) { @@ -471,11 +467,9 @@ xform(p,w) * Note that we generate instructions in reverser order. */ -replacement(p,w) - register patdescr_p p; - queue w; +static void replacement(patdescr_p p, queue w) { - register idescr_p id_p; + idescr_p id_p; for (id_p = &p->repl[p->replen-1]; id_p >= p->repl; id_p--) { insert(w,gen_instr(id_p)); @@ -490,13 +484,11 @@ replacement(p,w) * in exactly the same way as normal instructions that are just read in. */ -instr_p gen_instr(id_p) - idescr_p id_p; +static instr_p gen_instr(idescr_p id_p) { - char *opc; + char *opc, *s; instr_p ip; - register templ_p t; - register char *s; + templ_p t; bool islabdef; int n; static char tmp[] = "x"; @@ -547,13 +539,12 @@ instr_p gen_instr(id_p) static bool junk_state = FALSE; /* TRUE while processing a very long line */ -instr_p read_instr() +static instr_p read_instr(void) { instr_p ip; - register int c; - register char *p; - register FILE *inp = stdin; - char *plim; + int c; + char *p, *plim; + FILE *inp = stdin; ip = newinstr(); plim = &ip->line[MAXLINELEN]; @@ -586,9 +577,9 @@ instr_p read_instr() static instr_p instr_pool; int nr_mallocs = 0; /* for statistics */ -instr_p newinstr() +static instr_p newinstr(void) { - register instr_p ip; + instr_p ip; int i; if (instr_pool == NIL) { @@ -607,8 +598,7 @@ instr_p newinstr() return ip; } -oldinstr(ip) - instr_p ip; +static void oldinstr(instr_p ip) { ip->fw = instr_pool; instr_pool = ip; @@ -616,30 +606,9 @@ oldinstr(ip) -/* Debugging stuff */ - -badassertion(file,line) - char *file; - unsigned line; -{ - fprintf(stderr,"assertion failed file %s, line %u\n",file,line); - error("assertion"); -} - -/* VARARGS1 */ -error(s,a) - char *s,*a; -{ - fprintf(stderr,s,a); - fprintf(stderr,"\n"); - abort(); - exit(-1); -} - /* Low level routines */ -bool op_separator(ip) - instr_p ip; +static bool op_separator(instr_p ip) { skip_white(ip); if (*(ip->rest_line) == OP_SEPARATOR) { @@ -652,14 +621,13 @@ bool op_separator(ip) -bool well_shaped(opc) - char *opc; +static bool well_shaped(const char *opc) { return is_letter(opc[0]); } -bool is_letter(c) +static bool is_letter(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } diff --git a/mach/proto/top/top.h b/mach/proto/top/top.h index 1ea61cae1..0666a710c 100644 --- a/mach/proto/top/top.h +++ b/mach/proto/top/top.h @@ -89,5 +89,3 @@ typedef int bool; #define NIL (instr_p) 0 #define NULLSTRING (char *) 0 - -#define assert(x) if(!(x)) badassertion(__FILE__,__LINE__) diff --git a/mach/vc4/ncg/mach.h b/mach/vc4/ncg/mach.h index 89d2b8a97..a17bf9b6f 100644 --- a/mach/vc4/ncg/mach.h +++ b/mach/vc4/ncg/mach.h @@ -11,10 +11,10 @@ #define newilb(x) fprintf(codefile,"%s:\n",x) #define newdlb(x) fprintf(codefile,"%s:\n",x) #define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) -#define newlbss(l,x) fprintf(codefile,".comm %s,%u\n",l,x); +#define newlbss(l,x) fprintf(codefile,".comm %s,%ld\n",l,x); -#define cst_fmt "%d" -#define off_fmt "%d" +#define cst_fmt "%ld" +#define off_fmt "%ld" #define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/modules/src/flt_arith/flt_arith.h b/modules/src/flt_arith/flt_arith.h index b1c0a9893..beb5cc6fe 100644 --- a/modules/src/flt_arith/flt_arith.h +++ b/modules/src/flt_arith/flt_arith.h @@ -78,7 +78,7 @@ int flt_cmp(flt_arith *e1, flt_arith *e2); * digits. They may not both be missing. The decimal point, the e and the * exponent may be missing. */ -void flt_str2flt(char *s, flt_arith *e); +void flt_str2flt(const char *s, flt_arith *e); /** Converts the number indicated by `e` into a string, in a scientific * notation acceptable for EM. The result is stored in `buf`. At most * `bufsize` characters are stored. The maximum length needed is diff --git a/modules/src/flt_arith/flt_str2fl.c b/modules/src/flt_arith/flt_str2fl.c index 03c510ae3..e0c793dd8 100644 --- a/modules/src/flt_arith/flt_str2fl.c +++ b/modules/src/flt_arith/flt_str2fl.c @@ -216,7 +216,7 @@ static void add_exponent(register flt_arith *e, int exp) flt_status = status; } -void flt_str2flt(char *s, flt_arith *e) +void flt_str2flt(const char *s, flt_arith *e) { register int c; int dotseen = 0; diff --git a/modules/src/system/write.c b/modules/src/system/write.c index 7423a59a8..7f87ecc28 100644 --- a/modules/src/system/write.c +++ b/modules/src/system/write.c @@ -4,6 +4,7 @@ */ /* $Id$ */ +#include #include "system.h" int diff --git a/util/LLgen/build.lua b/util/LLgen/build.lua index 36e796fee..ea7cdf122 100644 --- a/util/LLgen/build.lua +++ b/util/LLgen/build.lua @@ -1,14 +1,14 @@ clibrary { name = "headers", - hdrs = { "./src/*.h" } + hdrs = { "./src/*.h" } -- rm alloc.h } cprogram { name = "llgen", - -- These use pre-LLgen'd versions of LLgen.c, Lpars.c and tokens.c. If - -- LLgen.g gets updated, they need rebuilding. Use the bootstrap script to - -- do this. + -- These use pre-LLgen'd versions of LLgen.c, Lpars.c, Lpars.h, and + -- tokens.c. If LLgen.g or tokens.g gets updated, they need + -- rebuilding. Use the bootstrap target to do this. srcs = { "./src/*.c" }, deps = { "+headers" }, @@ -20,6 +20,20 @@ cprogram { } } +-- This bootstrap target rebuilds LLgen's own parser with LLgen. +-- It acts like ./bootstrap.sh but without installing LLgen in PATH. +normalrule { + name = "bootstrap", + ins = "+llgen", + outleaves = { "phony" }, + commands = { + "cd %{abspath(cwd()..\"/src\")}", + "%{abspath(ins)} -vvv -x tokens.g LLgen.g", + "echo", + "echo You should now be able to rebuild LLgen with the new parser.", + } +} + definerule("llgen", { srcs = { type="targets" }, diff --git a/util/LLgen/lib/incl b/util/LLgen/lib/incl index 05b443c14..9c7ae0ba4 100644 --- a/util/LLgen/lib/incl +++ b/util/LLgen/lib/incl @@ -1,8 +1,6 @@ /* $Id$ */ #ifdef LL_DEBUG #include -#include -#include #define LL_assert(x) assert(x) #else #define LL_assert(x) /* nothing */ diff --git a/util/LLgen/lib/nc_rec b/util/LLgen/lib/nc_rec index 491252c68..2b4523777 100644 --- a/util/LLgen/lib/nc_rec +++ b/util/LLgen/lib/nc_rec @@ -118,8 +118,8 @@ static struct nonterminal *nonterminals; /* These functions must be called instead of the original functions in * 'malloc.h'. They offer a checking allocation mechanism. */ -static char *Malloc(unsigned); -static char *Realloc(char*, unsigned); +static void *Malloc(size_t); +static void *Realloc(void *, size_t); @@ -164,11 +164,11 @@ void LLnc_recover(void); -static char *Malloc(unsigned size) +static void *Malloc(size_t size) { - char *p; + void *p; - if ((p = malloc(size)) == (char *)0) { + if ((p = malloc(size)) == NULL) { fprintf(stderr, "fatal error: out of memory\n"); exit(1); } @@ -176,11 +176,11 @@ static char *Malloc(unsigned size) } -static char *Realloc(char *ptr, unsigned size) +static void *Realloc(void *ptr, size_t size) { - char *p; + void *p; - if ((p = realloc(ptr, size)) == (char *)0) { + if ((p = realloc(ptr, size)) == NULL) { fprintf(stderr, "fatal error: out of memory\n"); exit(1); } @@ -195,13 +195,13 @@ static void init_grammar(void) int i; terminals = (struct terminal *) - Malloc((unsigned) LLFIRST_NT * sizeof(struct terminal)); + Malloc(LLFIRST_NT * sizeof(struct terminal)); for (i = 0; i < LLFIRST_NT; i++) { (terminals + i)->link = (struct symbol *)0; } nonterminals = (struct nonterminal *) - Malloc((unsigned)LLNNONTERMINALS * sizeof(struct nonterminal)); + Malloc(LLNNONTERMINALS * sizeof(struct nonterminal)); for (i = 0; i < LLNNONTERMINALS; i++) { (nonterminals + i)->rule = (struct lhs *)0; (nonterminals + i)->link = (struct symbol *)0; @@ -637,8 +637,7 @@ static void new_head(struct stacks *stack, struct stack_elt *ptr) /* buffer full? */ stack->heads_buf_size += LLHEADS_BUF_INCR; stack->heads_buf = (struct stack_elt **) - Realloc((char *) - stack->heads_buf, (unsigned) + Realloc(stack->heads_buf, stack->heads_buf_size * sizeof(struct stack_elt *) ); @@ -677,8 +676,8 @@ static void to_delete(struct stacks *stack, struct stack_elt *ptr) else if (stack->nr_cleanups == stack->cleanup_buf_size) { stack->cleanup_buf_size += LLCLEANUP_BUF_INCR; stack->cleanup_buf = (struct stack_elt **) - Realloc((char *) stack->cleanup_buf, - (unsigned) stack->cleanup_buf_size * + Realloc(stack->cleanup_buf, + stack->cleanup_buf_size * sizeof(struct stack_elt *)); } *(stack->cleanup_buf + stack->nr_cleanups) = ptr; @@ -790,8 +789,7 @@ static int join(struct stacks *stack, struct stack_elt *top, int l_ahead) /* Allocate one more pointer to descendants */ size = se->nr_nexts * sizeof(struct edge); - se->edges = (struct edge *)Realloc((char *) se->edges, - (unsigned) size); + se->edges = (struct edge *)Realloc(se->edges, size); /* Link it */ (se->edges + se->nr_nexts - 1)->ptr = top->edges->ptr; @@ -904,8 +902,8 @@ static void generate_heads(struct stacks *stack, struct stack_elt *se, else if (stack->nr_visited == stack->visited_buf_size) { stack->visited_buf_size += LL_VIS_INCR; stack->visited_buf = (struct stack_elt **) - Realloc((char *) stack->visited_buf, - (unsigned) stack->visited_buf_size * + Realloc(stack->visited_buf, + stack->visited_buf_size * sizeof(struct stack_elt *)); } *(stack->visited_buf + stack->nr_visited) = next_se; @@ -1089,7 +1087,7 @@ static struct stack_elt *split(struct stack_elt *se) #endif new_stack->edges = (struct edge *) - Malloc((unsigned)se->nr_nexts * sizeof(struct edge)); + Malloc(se->nr_nexts * sizeof(struct edge)); /* Copy gets the same successors as the original */ memcpy((char *) new_stack->edges, (char *) se->edges, @@ -1242,14 +1240,14 @@ static void match_heads(struct stacks *stack, int symb) if (stack->heads_buf_size == 0) { stack->heads_buf_size = LLHEADS_BUF_INCR; stack->heads_buf = (struct stack_elt **) - Malloc((unsigned)stack->heads_buf_size * + Malloc(stack->heads_buf_size * sizeof(struct stack_elt *)); } else if (stack->nr_heads == stack->heads_buf_size) { stack->heads_buf_size += LLHEADS_BUF_INCR; stack->heads_buf = (struct stack_elt **) - Realloc((char *) stack->heads_buf, - (unsigned) stack->heads_buf_size * + Realloc(stack->heads_buf, + stack->heads_buf_size * sizeof(struct stack_elt *)); } *(stack->heads_buf + stack->nr_heads) = diff --git a/util/LLgen/src/LLgen.c b/util/LLgen/src/LLgen.c index 8676a4ca4..bce39148b 100644 --- a/util/LLgen/src/LLgen.c +++ b/util/LLgen/src/LLgen.c @@ -6,7 +6,6 @@ /* $Id$ */ #ifdef LL_DEBUG #include -#include #define LL_assert(x) assert(x) #else #define LL_assert(x) /* nothing */ @@ -251,7 +250,7 @@ LL_NOSCANDONE(C_IDENT); ff->ff_name = p; ff->ff_next = start; start = ff; - while (ff = ff->ff_next) { + while ((ff = ff->ff_next)) { if (! strcmp(p, ff->ff_name)) { error(linecount, "\"%s\" already used in a %%start", p); break; @@ -474,7 +473,7 @@ LL6_simpleproduction( { if (n_alts >= max_alts-2) { alt_table = (p_gram ) ralloc( (p_mem) alt_table, - (unsigned)(max_alts+=ALTINCR)*sizeof(t_gram)); + (max_alts+=ALTINCR)*sizeof(t_gram)); } if (t & DEF) { if (haddefault) { @@ -687,7 +686,7 @@ LL_SAFE(C_ILLEGAL); if (n_rules >= max_rules-2) { rule_table = (p_gram) ralloc( (p_mem) rule_table, - (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram)); + (max_rules+=RULEINCR)*sizeof(t_gram)); } elmcnt++; rule_table[n_rules++] = @@ -730,7 +729,7 @@ LL7_elem( { if (n_rules >= max_rules-2) { rule_table = (p_gram) ralloc( (p_mem) rule_table, - (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram)); + (max_rules+=RULEINCR)*sizeof(t_gram)); } kind = FIXED; cnt = 0; @@ -782,7 +781,7 @@ LLsdecr(4); if (n_rules >= max_rules-2) { rule_table = (p_gram) ralloc( (p_mem) rule_table, - (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram)); + (max_rules+=RULEINCR)*sizeof(t_gram)); } } elem = *--(q->t_rule); @@ -1314,7 +1313,7 @@ STATIC p_gram copyrule(register p_gram p,int length) register p_gram t; p_gram rule; - t = (p_gram) alloc((unsigned) length * sizeof(t_gram)); + t = (p_gram) alloc(length * sizeof(t_gram)); rule = t; while (length--) { *t++ = *p++; diff --git a/util/LLgen/src/LLgen.g b/util/LLgen/src/LLgen.g index d3dae69ed..896e458bd 100644 --- a/util/LLgen/src/LLgen.g +++ b/util/LLgen/src/LLgen.g @@ -131,7 +131,7 @@ def { register string p; } ff->ff_name = p; ff->ff_next = start; start = ff; - while (ff = ff->ff_next) { + while ((ff = ff->ff_next)) { if (! strcmp(p, ff->ff_name)) { error(linecount, "\"%s\" already used in a %%start", p); break; @@ -261,7 +261,7 @@ productions(p_gram *p;) { if (n_alts >= max_alts-2) { alt_table = (p_gram ) ralloc( (p_mem) alt_table, - (unsigned)(max_alts+=ALTINCR)*sizeof(t_gram)); + (max_alts+=ALTINCR)*sizeof(t_gram)); } if (t & DEF) { if (haddefault) { @@ -348,7 +348,7 @@ simpleproduction(p_gram *p; register int *conflres;) if (n_rules >= max_rules-2) { rule_table = (p_gram) ralloc( (p_mem) rule_table, - (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram)); + (max_rules+=RULEINCR)*sizeof(t_gram)); } elmcnt++; rule_table[n_rules++] = @@ -363,7 +363,7 @@ simpleproduction(p_gram *p; register int *conflres;) { if (n_rules >= max_rules-2) { rule_table = (p_gram) ralloc( (p_mem) rule_table, - (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram)); + (max_rules+=RULEINCR)*sizeof(t_gram)); } kind = FIXED; cnt = 0; @@ -391,7 +391,7 @@ simpleproduction(p_gram *p; register int *conflres;) if (n_rules >= max_rules-2) { rule_table = (p_gram) ralloc( (p_mem) rule_table, - (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram)); + (max_rules+=RULEINCR)*sizeof(t_gram)); } } elem = *--(q->t_rule); @@ -653,7 +653,7 @@ STATIC p_gram copyrule(register p_gram p,int length) register p_gram t; p_gram rule; - t = (p_gram) alloc((unsigned) length * sizeof(t_gram)); + t = (p_gram) alloc(length * sizeof(t_gram)); rule = t; while (length--) { *t++ = *p++; diff --git a/util/LLgen/src/Lpars.c b/util/LLgen/src/Lpars.c index 1b002de34..61adbbb2f 100644 --- a/util/LLgen/src/Lpars.c +++ b/util/LLgen/src/Lpars.c @@ -5,7 +5,6 @@ /* $Id$ */ #ifdef LL_DEBUG #include -#include #define LL_assert(x) assert(x) #else #define LL_assert(x) /* nothing */ diff --git a/util/LLgen/src/alloc.c b/util/LLgen/src/alloc.c index eb089d135..7cd71c266 100644 --- a/util/LLgen/src/alloc.c +++ b/util/LLgen/src/alloc.c @@ -17,7 +17,6 @@ */ #include -# include "alloc.h" # include "types.h" # include "extern.h" @@ -27,7 +26,7 @@ static string rcsid = "$Id$"; static string e_nomem = "Out of memory"; -p_mem alloc(unsigned int size) +p_mem alloc(size_t size) { /* Allocate "size" bytes. Panic if it fails @@ -38,7 +37,7 @@ p_mem alloc(unsigned int size) return p; } -p_mem ralloc(p_mem p,unsigned int size) +p_mem ralloc(p_mem p,size_t size) { /* Re-allocate the chunk of memory indicated by "p", to @@ -61,7 +60,7 @@ p_mem new_mem(register p_info p) be updated each time this routine is called */ p_mem rp; - unsigned sz; + size_t sz; if (p->i_max >= p->i_top) { /* No more free elements */ sz = p->i_size; diff --git a/util/LLgen/src/alloc.h b/util/LLgen/src/alloc.h deleted file mode 100644 index a86b46064..000000000 --- a/util/LLgen/src/alloc.h +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright (c) 2019 ACK Project. - * See the copyright notice in the ACK home directory, - * in the file "Copyright". - * - * Created on: 2019-02-16 - * - */ -#ifndef ALLOC_H_ -#define ALLOC_H_ - -#include "types.h" - -p_mem alloc(unsigned int size); -p_mem ralloc(p_mem p,unsigned int size); -p_mem new_mem(register p_info p); - - - -#endif /* ALLOC_H_ */ diff --git a/util/LLgen/src/compute.c b/util/LLgen/src/compute.c index fddd7b3e0..43c7dbc52 100644 --- a/util/LLgen/src/compute.c +++ b/util/LLgen/src/compute.c @@ -19,7 +19,6 @@ # include # include -# include "alloc.h" # include "types.h" # include "extern.h" # include "sets.h" @@ -198,7 +197,7 @@ void do_compute(void) for (f = files; f < maxfiles; f++) { register p_set s; - f->f_used = s = (p_set) alloc((unsigned) n * sizeof(*(f->f_used))); + f->f_used = s = (p_set) alloc(n * sizeof(*(f->f_used))); for (i = n; i; i--) *s++ = 0; for (i = f->f_nonterminals; i != -1; i = p->n_next) @@ -497,9 +496,7 @@ STATIC int nc_first(p_set setp,register p_gram p,int flag) q = g_getterm(p); if (flag == 0) - { - if (nc_first(q->t_nc_first,q->t_rule,0))/*nothing*/; - } + (void)nc_first(q->t_nc_first,q->t_rule,0); if (!noenter) s |= setunion(setp,q->t_nc_first); p++; if (r_getkind(q) == STAR || @@ -512,9 +509,7 @@ STATIC int nc_first(p_set setp,register p_gram p,int flag) l = g_getlink(p); if (flag == 0) - { - if (nc_first(l->l_nc_symbs,l->l_rule,0))/*nothing*/; - } + (void)nc_first(l->l_nc_symbs,l->l_rule,0); if (noenter == 0) { s |= setunion(setp,l->l_nc_symbs); @@ -528,14 +523,15 @@ STATIC int nc_first(p_set setp,register p_gram p,int flag) register p_start subp; if (!noenter) - if (subpars_sim) - s |= setunion(setp, start_firsts); - else { - for (subp = g_getsubparse(p); subp; + if (subpars_sim) + s |= setunion(setp, start_firsts); + else + { + for (subp = g_getsubparse(p); subp; subp = subp->ff_next) - s |= setunion(setp, (&nonterms[subp->ff_nont])->n_nc_first); - + s |= setunion(setp, (&nonterms[subp->ff_nont])->n_nc_first); + } } p++; continue; @@ -863,7 +859,7 @@ STATIC void do_lengthcomp(void) register p_nont p; p_mem alloc(); - length = (p_length) alloc((unsigned) (nnonterms * sizeof(*length))); + length = (p_length) alloc(nnonterms * sizeof(*length)); for (pl = &length[nnonterms - 1]; pl >= length; pl--) { pl->val = pl->cnt = INFINITY; diff --git a/util/LLgen/src/extern.h b/util/LLgen/src/extern.h index f1405e786..d3b3b89d6 100644 --- a/util/LLgen/src/extern.h +++ b/util/LLgen/src/extern.h @@ -19,6 +19,8 @@ * some variables that are visible in more than one file */ +# include "types.h" + # define LTEXTSZ 256 /* Size of longest token */ /* @@ -94,22 +96,38 @@ extern p_gram illegal_gram; extern int strip_grammar; extern int in_production; +/* LLgen.g */ +void LLparse(void); + +/* check.c */ +void conflchecks(void); + +/* compute.c */ +void do_compute(void); +int empty(p_gram); +int t_safety(int, int, int, int); +int t_after(int, int, int); + +/* gencode.c */ +void gencode(int); + +/* machdep.c */ +void TMPNAM(string); +string libpath(string); + +/* main.c */ void error(int lineno,string s,string t); void warning(int lineno,string s,string t); void fatal(int lineno,string s,string t); - - -int empty(register p_gram); -int t_safety(int, int, int, int); -int t_after(int, int, int); -string store(string); -void name_init(void); -p_gram search(int, register string, int); -void co_reach(void); -void install(string, string); void copyfile(string); +void install(string, string); +/* name.c */ +void name_init(void); +string store(string); +p_gram search(int, string, int); - +/* reach.c */ +void co_reach(void); #endif /* EXTERN_H_ */ diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index 6599a386a..81572de93 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -20,7 +20,6 @@ #include #include -# include "alloc.h" # include "types.h" # include "io.h" # include "extern.h" @@ -102,7 +101,7 @@ STATIC void doclose(FILE *f) STATIC int *mk_tokenlist(void) { register int i = ntokens; - register int *p = (int *) alloc((unsigned) (i * sizeof(int))) + i; + register int *p = (int *) alloc(i * sizeof(int)) + i; while (i--) *--p = -1; @@ -295,7 +294,7 @@ STATIC void genrecovery(void) for (psetl = setptr; psetl < maxptr; psetl++) prset(*psetl); fputs(c_arrend, f); - index = (int *) alloc((unsigned) (assval * sizeof(int))); + index = (int *) alloc(assval * sizeof(int)); for (q = index; q < &index[assval];) *q++ = -1; for (t = tokens; t < maxt; t++) @@ -344,7 +343,7 @@ STATIC void genncrecovery(void) fprintf(f, "#define LLFIRST_NT %d\n", assval); fprintf(f, "#define LLSETSIZE %d\n", nbytes); - index = (int *) alloc((unsigned) (assval * sizeof(int))); + index = (int *) alloc(assval * sizeof(int)); for (q = index; q < &index[assval];) *q++ = -1; for (t = tokens; t < maxt; t++) { @@ -988,14 +987,14 @@ STATIC int *dopush(register p_gram p, int safety, int toplevel, int **pp) /* * The safety only matters if toplevel != 0 */ - unsigned int i = 100; + size_t i = 100; register int *ip = (int *) alloc(100 * sizeof(int)); *pp = ip; for (;;) { - if (ip - *pp >= i) + if ((size_t)(ip - *pp) >= i) { *pp = (int *) ralloc((p_mem) (*pp), (i + 100) * sizeof(int)); ip = *pp + i; diff --git a/util/LLgen/src/machdep.c b/util/LLgen/src/machdep.c index d04f9ac3d..cf43119d4 100644 --- a/util/LLgen/src/machdep.c +++ b/util/LLgen/src/machdep.c @@ -16,12 +16,8 @@ * Machine dependant things */ #include -#ifdef USE_SYS -#include -#endif #include #include -# include "alloc.h" # include "extern.h" # include "types.h" @@ -33,29 +29,18 @@ static string rcsid5 = "$Id$"; #define LIBDIR "lib" #endif -void UNLINK(string x) -{ - /* Must remove the file "x" */ -#ifdef USE_SYS - sys_remove(x); /* systemcall to remove file */ -#else - remove(x); -#endif -} - - string libpath(string s) { /* Must deliver a full pathname to the library file "s" */ register string p; - register int length; + register size_t length; char* libdir = getenv("LLGEN_LIB_DIR"); if (!libdir) libdir = LIBDIR; length = strlen(libdir) + strlen(s) + 2; - p = (string) alloc((unsigned) length); + p = (string) alloc(length); strcpy(p,libdir); strcat(p,"/"); strcat(p,s); diff --git a/util/LLgen/src/main.c b/util/LLgen/src/main.c index 1f1cab2be..217214f68 100644 --- a/util/LLgen/src/main.c +++ b/util/LLgen/src/main.c @@ -33,14 +33,6 @@ STATIC void readgrammar(int, char *[]); STATIC void doparse(register p_file); STATIC void comfatal(void); -extern void UNLINK(string); -extern void RENAME(string, string); -extern void TMPNAM(string); -extern string libpath(string); -extern void conflchecks(void); -extern void do_compute(void); -extern void gencode(int); - int main(int argc, register string argv[]) { register string arg; @@ -210,8 +202,8 @@ int main(int argc, register string argv[]) } else gencode(argc); - UNLINK(f_temp); - UNLINK(f_pars); + remove(f_temp); + remove(f_pars); if (verbose) { fprintf(stderr, "number of nonterminals: %d\n", nnonterms); @@ -235,7 +227,7 @@ STATIC void readgrammar(int argc, char *argv[]) /* * Build the file structure */ - files = p = (p_file) alloc((unsigned) (argc + 1) * sizeof(t_file)); + files = p = (p_file) alloc((argc + 1) * sizeof(t_file)); if (argc-- == 1) { finput = stdin; @@ -328,11 +320,11 @@ STATIC void comfatal(void) if (fact != NULL) { fclose(fact); - UNLINK(f_temp); + remove(f_temp); } if (fpars != NULL) fclose(fpars); - UNLINK(f_pars); + remove(f_pars); exit(EXIT_FAILURE); } diff --git a/util/LLgen/src/name.c b/util/LLgen/src/name.c index 25fd22d74..871a1567e 100644 --- a/util/LLgen/src/name.c +++ b/util/LLgen/src/name.c @@ -19,7 +19,6 @@ #include #include -# include "alloc.h" # include "types.h" # include "extern.h" # include "assert.h" diff --git a/util/LLgen/src/savegram.c b/util/LLgen/src/savegram.c index 3638182b5..32539cfca 100644 --- a/util/LLgen/src/savegram.c +++ b/util/LLgen/src/savegram.c @@ -88,7 +88,7 @@ void save_grammar(FILE *f) /* Generate some constants in the grammar file */ /* Allocate terms list */ - t_list = (struct t_list *) alloc((unsigned) nterms * sizeof(struct t_list)); + t_list = (struct t_list *) alloc(nterms * sizeof(struct t_list)); t_list_index = 0; sub_list = (struct subparse_list *) alloc(nsubstarts * sizeof(struct subparse_list)); diff --git a/util/LLgen/src/sets.c b/util/LLgen/src/sets.c index 4422039b0..10bf7dca8 100644 --- a/util/LLgen/src/sets.c +++ b/util/LLgen/src/sets.c @@ -63,7 +63,7 @@ p_set get_set(void) static p_set sets, maxsets; if ((p = sets) >= maxsets) { - q = p = (p_set) alloc((unsigned) (50*setsize*sizeof(*sets))); + q = p = (p_set) alloc(50*setsize*sizeof(*sets)); maxsets = p + 50 * setsize; do { *q++ = 0; @@ -81,7 +81,7 @@ p_set setalloc(void) register p_set p; register int size = setsize; - p = (p_set) alloc((unsigned) (size * sizeof(*p))) + size; + p = (p_set) alloc(size * sizeof(*p)) + size; do { *--p = 0; } while (--size); diff --git a/util/LLgen/src/tokens.c b/util/LLgen/src/tokens.c index 0ac98a93b..936795710 100644 --- a/util/LLgen/src/tokens.c +++ b/util/LLgen/src/tokens.c @@ -6,7 +6,6 @@ /* $Id$ */ #ifdef LL_DEBUG #include -#include #define LL_assert(x) assert(x) #else #define LL_assert(x) /* nothing */ @@ -368,7 +367,7 @@ int input(void) */ register int c; - if (c = backupc) { + if ((c = backupc)) { /* Last char was "unput()". Deliver it again */ backupc = 0; diff --git a/util/LLgen/src/tokens.g b/util/LLgen/src/tokens.g index 3f8eb29b5..7f1b603fb 100644 --- a/util/LLgen/src/tokens.g +++ b/util/LLgen/src/tokens.g @@ -360,7 +360,7 @@ int input(void) */ register int c; - if (c = backupc) { + if ((c = backupc)) { /* Last char was "unput()". Deliver it again */ backupc = 0; diff --git a/util/LLgen/src/types.h b/util/LLgen/src/types.h index 0de5397b8..a20b8ab32 100644 --- a/util/LLgen/src/types.h +++ b/util/LLgen/src/types.h @@ -18,6 +18,8 @@ * Type and structure definitions */ +#include /* size_t */ + typedef int *p_set; /* pointer to bitset */ typedef char *p_mem; /* pointer to some core */ typedef char *string; @@ -259,14 +261,19 @@ typedef struct info_alloc { /* * Structure used for dynamically growing arrays */ - unsigned i_size; /* Size of the array */ - unsigned i_esize; /* Size of an element */ - unsigned i_incr; /* When filled, add room for i_incr elements */ + size_t i_size; /* Size of the array */ + size_t i_esize; /* Size of an element */ + size_t i_incr; /* When filled, add room for i_incr elements */ p_mem i_ptr; /* ptr to base of array */ p_mem i_max; /* ptr to first free */ p_mem i_top; /* ptr to top of array */ } t_info, *p_info; +/* alloc.c */ +p_mem alloc(size_t); +p_mem ralloc(p_mem, size_t); +p_mem new_mem(p_info); + # ifdef NDEBUG # define STATIC static # else /* not NDEBUG */ diff --git a/util/ack/ack.h b/util/ack/ack.h index 144fd5343..76a738745 100644 --- a/util/ack/ack.h +++ b/util/ack/ack.h @@ -64,6 +64,9 @@ typedef struct /* Own routines */ +/* files.h */ +extern void rmtemps(void); + /* rmach.c */ extern void setlist(char*); @@ -80,6 +83,7 @@ extern void fatal(const char*, ...); extern void vprint(const char*, ...); extern void fuerror(const char*, ...); extern void werror(const char*, ...); +extern void error(const char*, ...); extern void quit(int); extern char* keeps(const char*); #define throws(str) free(str) diff --git a/util/ack/main.c b/util/ack/main.c index 47fb44f0e..3e1bf8e2a 100644 --- a/util/ack/main.c +++ b/util/ack/main.c @@ -169,7 +169,7 @@ static void varinit(void) register char* envstr; extern char* em_dir; - if (envstr = getenv("ACKDIR")) + if ((envstr = getenv("ACKDIR")) != NULL) { em_dir = keeps(envstr); } diff --git a/util/ack/mktables.c b/util/ack/mktables.c index 214b93606..879cb05d6 100644 --- a/util/ack/mktables.c +++ b/util/ack/mktables.c @@ -22,10 +22,12 @@ FILE *dmach ; int offset ; -void readm(); +void start(const char *) ; +void stop(int) ; +void readm(void) ; -main(argc,argv) char **argv ; { - register i ; +int main(int argc, char **argv) { + int i ; start(argv[1]) ; for ( i=2 ; i #include #include #include diff --git a/util/ack/scan.c b/util/ack/scan.c index e846578de..0e6cfb6c2 100644 --- a/util/ack/scan.c +++ b/util/ack/scan.c @@ -113,12 +113,12 @@ static void try(list_elem *f_scan, const char *suffix) { */ register trf *sneak ; sneak= trafo ; - while( sneak=sneak->t_next ) { + while( (sneak=sneak->t_next) ) { sneak->t_scan=YES ; } scan_found() ; sneak= trafo ; - while( sneak=sneak->t_next ) { + while( (sneak=sneak->t_next) ) { sneak->t_scan=NO ; } return ; diff --git a/util/ack/trans.c b/util/ack/trans.c index 1152dfbd7..451b74c31 100644 --- a/util/ack/trans.c +++ b/util/ack/trans.c @@ -317,7 +317,8 @@ static growstring scanvars(const char* line) { case A_VAR: gr_add(&name, 0); - if (tr = getvar(gr_start(name))) + tr = getvar(gr_start(name)); + if (tr != NULL) { while (*tr) { @@ -333,7 +334,8 @@ static growstring scanvars(const char* line) break; case C_VAR: gr_add(&name, 0); - if (tr = getvar(gr_start(name))) + tr = getvar(gr_start(name)); + if (tr != NULL) { while (*tr) { diff --git a/util/ack/trans.h b/util/ack/trans.h index f16f64d7c..01d203ac5 100644 --- a/util/ack/trans.h +++ b/util/ack/trans.h @@ -50,7 +50,6 @@ int setfiles(trf *); void disc_files(trf *); void disc_inputs(trf *); void rmfile(path *); -void rmtemps(void); void add_input(path *, trf *); /* run.c */ diff --git a/util/cgg/main.c b/util/cgg/main.c index 75a066e5e..12d3b4fd4 100644 --- a/util/cgg/main.c +++ b/util/cgg/main.c @@ -785,7 +785,7 @@ static void verbose(void) fprintf(stderr, "Sets %d(%d)\n", nmachsets, MAXSETS); fprintf(stderr, "Tokeninstances %d(%d)\n", narinstance, MAXINSTANCE); fprintf(stderr, "Strings %d(%d)\n", ncodestrings, MAXSTRINGS); - fprintf(stderr, "Enodes %d(%d)\n", lastnode - nodes, MAXNODES); + fprintf(stderr, "Enodes %d(%d)\n", (int)(lastnode - nodes), MAXNODES); fprintf(stderr, "Patbytes %d(%d)\n", npatbytes, MAXPATTERN); } diff --git a/util/ego/bo/bo.c b/util/ego/bo/bo.c index 5845477c8..34fd27d2c 100644 --- a/util/ego/bo/bo.c +++ b/util/ego/bo/bo.c @@ -62,9 +62,7 @@ STATIC int Sbo; /* #optimizations found */ -STATIC line_p last_code(lines,skip_pseu) - line_p lines; - bool skip_pseu; +STATIC line_p last_code(line_p lines, bool skip_pseu) { /* Determine the last line of a list */ @@ -82,12 +80,11 @@ STATIC short cc_tab[12] = op_zne,op_bne,op_zgt,op_bgt,op_zge,op_bge}; -STATIC short rev_cond(cond) - short cond; +STATIC short rev_cond(short cond) { - register i; + register int i; - for (i = 0; i < 12; i++) { + for (i = 0; i < 12; i++) { if (cond == cc_tab[i]) return cc_tab[11-i]; } return op_nop; @@ -100,7 +97,7 @@ STATIC bool is_bcc(l) } -STATIC bo_optloop(p,b,x,bra,bcc) +STATIC void bo_optloop(p,b,x,bra,bcc) proc_p p; bblock_p b,x; line_p bra,bcc; @@ -180,7 +177,7 @@ OUTVERBOSE("branch optimization proc %d block %d\n", curproc->p_id,x->b_id); -STATIC bo_loops(p) +STATIC void bo_loops(p) proc_p p; { Lindex i; @@ -192,7 +189,7 @@ STATIC bo_loops(p) } } -STATIC mv_code(b1,b2) +STATIC void mv_code(b1,b2) bblock_p b1,b2; { line_p l,x; @@ -207,8 +204,7 @@ STATIC mv_code(b1,b2) } } -void -bo_switch(b) +STATIC void bo_switch(b) bblock_p b; { bblock_p s,x; @@ -256,7 +252,7 @@ OUTVERBOSE("branch optimization in proc %d, block %d",curproc->p_id,b->b_id); } } -STATIC bo_extproc(p) +STATIC void bo_extproc(p) proc_p p; { /* Allocate the extended data structures for procedure p */ @@ -272,7 +268,7 @@ STATIC bo_extproc(p) } -STATIC loop_blocks(p) +STATIC void loop_blocks(p) proc_p p; { /* Compute the LP_BLOCKS sets for all loops of p */ @@ -288,7 +284,7 @@ STATIC loop_blocks(p) } } -STATIC bo_cleanproc(p) +STATIC void bo_cleanproc(p) proc_p p; { /* Allocate the extended data structures for procedure p */ @@ -321,7 +317,7 @@ void bo_optimize(void *vp) -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { diff --git a/util/ego/ca/ca_put.c b/util/ego/ca/ca_put.c index 6f9eddba2..d89d0578e 100644 --- a/util/ego/ca/ca_put.c +++ b/util/ego/ca/ca_put.c @@ -11,6 +11,7 @@ #include #include "../share/types.h" #include "ca.h" +#include "ca_put.h" #include "../share/debug.h" #include "../share/def.h" #include "../share/map.h" @@ -22,18 +23,18 @@ FILE *outfile; STATIC proc_p thispro; -STATIC outinst(m) { +STATIC void outinst(int m) { outbyte( (byte) m ); } -STATIC coutshort(i) short i; { +STATIC void coutshort(short i) { outbyte( (byte) (i&BMASK) ); outbyte( (byte) (i>>8) ); } -STATIC coutint(i) short i; { +STATIC void coutint(short i) { if (i>= -sp_zcst0 && i< sp_ncst0-sp_zcst0) outbyte( (byte) (i+sp_zcst0+sp_fcst0) ); @@ -43,7 +44,7 @@ STATIC coutint(i) short i; { } } -STATIC coutoff(off) offset off; { +STATIC void coutoff(offset off) { if ((short) off == off) coutint((short) off); @@ -55,9 +56,7 @@ STATIC coutoff(off) offset off; { } -STATIC outsym(s,t) - char *s; - int t; +STATIC void outsym(const char *s, int t) { register byte *p; register unsigned num; @@ -85,21 +84,19 @@ STATIC outsym(s,t) } -STATIC outdsym(dbl) - dblock_p dbl; +STATIC void outdsym(dblock_p dbl) { if (dnames[dbl->d_id]) outsym(dnames[dbl->d_id],sp_dnam); } -STATIC outpsym(p) - proc_p p; +STATIC void outpsym(proc_p p) { outsym(pnames[p->p_id],sp_pnam); } -STATIC outddef(id) short id; { +STATIC void outddef(short id) { dblock_p dbl; @@ -111,7 +108,7 @@ STATIC outddef(id) short id; { } } -STATIC outpdef(p) proc_p p; { +STATIC void outpdef(proc_p p) { p->p_flags2 |= PF_SYMOUT; if (p->p_flags1 & PF_EXTERNAL) { outinst(ps_exp); @@ -120,7 +117,7 @@ STATIC outpdef(p) proc_p p; { } -STATIC outdocc(obj) obj_p obj; { +STATIC void outdocc(obj_p obj) { dblock_p dbl; dbl = obj->o_dblock; @@ -135,7 +132,7 @@ STATIC outdocc(obj) obj_p obj; { } -STATIC outpocc(p) proc_p p; { +STATIC void outpocc(proc_p p) { if ((p->p_flags2 & PF_SYMOUT) == 0) { p->p_flags2 |= PF_SYMOUT; if ((p->p_flags1 & PF_EXTERNAL) == 0) { @@ -146,8 +143,7 @@ STATIC outpocc(p) proc_p p; { } -STATIC coutobject(obj) - obj_p obj; +STATIC void coutobject(obj_p obj) { /* In general, an object is defined by a global data * label and an offset. There are two special cases: @@ -169,7 +165,7 @@ STATIC coutobject(obj) } -STATIC cputstr(abp) register argb_p abp; { +STATIC void cputstr(argb_p abp) { register argb_p tbp; register length; @@ -188,8 +184,7 @@ STATIC cputstr(abp) register argb_p abp; { } -STATIC outnum(n) - int n; +STATIC void outnum(int n) { if (n < 256) { outbyte((byte) sp_ilb1); @@ -201,8 +196,7 @@ STATIC outnum(n) } -STATIC numlab(n) - int n; +STATIC void numlab(int n) { if (n < sp_nilb0) { outbyte((byte) (n + sp_filb0)); @@ -212,8 +206,7 @@ STATIC numlab(n) } -STATIC cputargs(lnp) - line_p lnp; +STATIC void cputargs(line_p lnp) { register arg_p ap; int cnt = 0; @@ -264,8 +257,7 @@ STATIC cputargs(lnp) -STATIC outoperand(lnp) - line_p lnp; +STATIC void outoperand(line_p lnp) { /* Output the operand of instruction lnp */ @@ -320,8 +312,7 @@ STATIC outoperand(lnp) } -STATIC outvisibility(lnp) - line_p lnp; +STATIC void outvisibility(line_p lnp) { /* In EM names of datalabels and procedures can be made * externally visible, so they can be used in other files. @@ -377,9 +368,7 @@ STATIC outvisibility(lnp) } -cputlines(l,lf) - line_p l; - FILE *lf; +void cputlines(line_p l, FILE *lf) { /* Output the lines in Campact assembly language * format. @@ -405,13 +394,12 @@ cputlines(l,lf) oldline(lnp); } if (lmap != (line_p *) 0) { - oldmap(lmap,llength); + oldmap((void **) lmap,llength); lmap = (line_p *) 0; } } -cputmagic(lf) - FILE *lf; +void cputmagic(FILE *lf) { /* write the magic number */ diff --git a/util/ego/ca/ca_put.h b/util/ego/ca/ca_put.h index d7a3ce16d..4788b9561 100644 --- a/util/ego/ca/ca_put.h +++ b/util/ego/ca/ca_put.h @@ -10,5 +10,5 @@ */ -extern cputlines(); -extern cputmagic(); +void cputlines(line_p, FILE *); +void cputmagic(FILE *); diff --git a/util/ego/cf/cf.c b/util/ego/cf/cf.c index f695aa237..6ee94af46 100644 --- a/util/ego/cf/cf.c +++ b/util/ego/cf/cf.c @@ -26,6 +26,7 @@ #include "../share/get.h" #include "../share/put.h" #include "../share/def.h" +#include "../share/utils.h" #include "cf.h" #include "cf_succ.h" #include "cf_idom.h" @@ -75,7 +76,7 @@ STATIC short state; /* We use a finite state machine with the * INIT: initial state */ -STATIC nextblock() +STATIC void nextblock() { /* allocate a new basic block structure and * set b, bp and lp. @@ -138,12 +139,9 @@ STATIC line_p doread_line(p_out) return lnp; } -STATIC bool getbblocks(fp, kind_out, n_out, g_out, l_out) - FILE* fp; -short* kind_out; -short* n_out; -bblock_p* g_out; -line_p* l_out; +STATIC bool +getbblocks(FILE *fp, short *kind_out, short *n_out, bblock_p *g_out, + line_p *l_out) { bblock_p head = (bblock_p)0; line_p headl = (line_p)0; @@ -252,7 +250,7 @@ line_p* l_out; } } -STATIC interproc_analysis(p) +STATIC void interproc_analysis(p) proc_p p; { /* Interprocedural analysis of a procedure p determines: @@ -362,7 +360,7 @@ STATIC interproc_analysis(p) } } -STATIC cf_cleanproc(p) +STATIC void cf_cleanproc(p) proc_p p; { /* Remove the extended data structures of p */ @@ -477,7 +475,7 @@ STATIC bool add_info(q, p) return diff; } -STATIC trans_clos(head) +STATIC void trans_clos(head) proc_p head; { /* Compute the transitive closure of the used/changed @@ -508,7 +506,7 @@ STATIC trans_clos(head) } } -indir_calls() +STATIC void indir_calls() { Cindex i; proc_p p; @@ -522,7 +520,7 @@ indir_calls() Cdeleteset(cai_set); } -main(argc, argv) int argc; +int main(argc, argv) int argc; char* argv[]; { FILE* f, *f2, *gf2; /* The EM input, EM output, basic block output */ diff --git a/util/ego/cf/cf_idom.c b/util/ego/cf/cf_idom.c index 187052c38..3238751cc 100644 --- a/util/ego/cf/cf_idom.c +++ b/util/ego/cf/cf_idom.c @@ -34,7 +34,7 @@ short dfs_nr; bblock_p *vertex; /* dynamically allocated array */ -STATIC dfs(v) +STATIC void dfs(v) bblock_p v; { /* Depth First Search */ @@ -56,7 +56,7 @@ STATIC dfs(v) -STATIC compress(v) +STATIC void compress(v) bblock_p v; { if (v->B_ANCESTOR->B_ANCESTOR != (bblock_p) 0) { @@ -83,7 +83,7 @@ STATIC bblock_p eval(v) -STATIC linkblocks(v,w) +STATIC void linkblocks(v,w) bblock_p v,w; { w->B_ANCESTOR = v; @@ -91,9 +91,7 @@ STATIC linkblocks(v,w) -dominators(r,n) - bblock_p r; - short n; +void dominators(bblock_p r, short n) { /* Compute the immediate dominator of every basic * block in the control flow graph rooted by r. @@ -139,5 +137,6 @@ dominators(r,n) } } r->b_idom = (bblock_p) 0; - oldmap(vertex,n); /* release memory for dynamic array vertex */ + /* release memory for dynamic array vertex */ + oldmap((void **) vertex,n); } diff --git a/util/ego/cf/cf_idom.h b/util/ego/cf/cf_idom.h index 825d1531b..c6daa0104 100644 --- a/util/ego/cf/cf_idom.h +++ b/util/ego/cf/cf_idom.h @@ -9,7 +9,8 @@ */ -extern dominator(); /* (bblock_p head, short n) +void dominators(bblock_p head, short n); + /* * Compute for every basic block its immediate * dominator. The dominator relation is hence * recorded as a tree in which every node contains diff --git a/util/ego/cf/cf_loop.c b/util/ego/cf/cf_loop.c index 23e6ce430..5df219be7 100644 --- a/util/ego/cf/cf_loop.c +++ b/util/ego/cf/cf_loop.c @@ -83,7 +83,7 @@ STATIC bool inner_loop(l1,l2) -STATIC insrt(b,lpb,s_p) +STATIC void insrt(b,lpb,s_p) bblock_p b; lset *lpb; lset *s_p; @@ -162,7 +162,7 @@ STATIC loop_p org_loop(lp,loops) -STATIC collapse_loops(loops_p) +STATIC void collapse_loops(loops_p) lset *loops_p; { register Lindex li1, li2; @@ -187,7 +187,7 @@ STATIC collapse_loops(loops_p) } -STATIC loop_per_block(lp) +STATIC void loop_per_block(lp) loop_p lp; { bblock_p b; @@ -205,7 +205,7 @@ STATIC loop_per_block(lp) -STATIC loop_attrib(loops) +STATIC void loop_attrib(loops) lset loops; { /* Compute several attributes */ @@ -223,7 +223,7 @@ STATIC loop_attrib(loops) -STATIC nest_levels(loops) +STATIC void nest_levels(loops) lset loops; { /* Compute the nesting levels of all loops of @@ -250,7 +250,7 @@ STATIC nest_levels(loops) } -STATIC cleanup(loops) +STATIC void cleanup(loops) lset loops; { /* Throw away the LP_BLOCKS sets */ @@ -280,7 +280,7 @@ STATIC bool does_exit(b,lp) } -STATIC mark_succ(b,lp) +STATIC void mark_succ(b,lp) bblock_p b; loop_p lp; { @@ -339,7 +339,7 @@ STATIC void mark_blocks(lp) -STATIC mark_loopblocks(loops) +STATIC void mark_loopblocks(loops) lset loops; { /* Determine for all loops which basic blocks @@ -360,7 +360,7 @@ STATIC mark_loopblocks(loops) -loop_detection(p) +void loop_detection(p) proc_p p; { /* Find all natural loops of procedure p. Every loop is diff --git a/util/ego/cf/cf_loop.h b/util/ego/cf/cf_loop.h index d6652c884..f7280fa10 100644 --- a/util/ego/cf/cf_loop.h +++ b/util/ego/cf/cf_loop.h @@ -8,7 +8,7 @@ * L O O P D E T E C T I O N */ -extern loop_detection(); /* (proc_p p) +void loop_detection(proc_p p); /* * Detect all loops of procedure p. * Every basic block of p is assigned * a set of all loops it is part of. diff --git a/util/ego/cf/cf_succ.c b/util/ego/cf/cf_succ.c index 1af8cbc0e..626ec5a01 100644 --- a/util/ego/cf/cf_succ.c +++ b/util/ego/cf/cf_succ.c @@ -21,12 +21,13 @@ #include "../share/lset.h" #include "../share/cset.h" #include "cf.h" +#include "cf_succ.h" #include "../share/map.h" extern char em_flag[]; -STATIC succeeds(succ,pred) +STATIC void succeeds(succ,pred) bblock_p succ, pred; { assert(pred != (bblock_p) 0); @@ -75,7 +76,7 @@ STATIC arg_p use_label(arg,b) -STATIC case_flow(instr,desc,b) +STATIC void case_flow(instr,desc,b) short instr; line_p desc; bblock_p b; @@ -176,7 +177,7 @@ STATIC line_p case_descr(lnp) -STATIC last2_instrs(b,last_out,prev_out) +STATIC void last2_instrs(b,last_out,prev_out) bblock_p b; line_p *last_out,*prev_out; { @@ -205,7 +206,7 @@ STATIC last2_instrs(b,last_out,prev_out) -control_flow(head) +void control_flow(head) bblock_p head; { /* compute the successor and predecessor relation diff --git a/util/ego/cf/cf_succ.h b/util/ego/cf/cf_succ.h index 9f07d65e1..832396ef3 100644 --- a/util/ego/cf/cf_succ.h +++ b/util/ego/cf/cf_succ.h @@ -8,7 +8,8 @@ * S U C C E S S O R / P R E D E C E S S O R R E L A T I O N S */ -extern control_flow(); /* (bblock_p head) +void control_flow(bblock_p head); + /* * Compute for every basic block * its successors and predecessors * in the control flow graph. diff --git a/util/ego/cj/cj.c b/util/ego/cj/cj.c index 946436281..1df9461f8 100644 --- a/util/ego/cj/cj.c +++ b/util/ego/cj/cj.c @@ -134,7 +134,7 @@ STATIC bool is_desirable(text) } -STATIC cp_loops(b1,b2) +STATIC void cp_loops(b1,b2) bblock_p b1,b2; { /* Copy the loopset of b2 to b1 */ @@ -149,7 +149,7 @@ STATIC cp_loops(b1,b2) } -STATIC jump_cross(l1,l2,b1,b2) +STATIC void jump_cross(l1,l2,b1,b2) line_p l1,l2; bblock_p b1,b2; { @@ -317,7 +317,7 @@ void cj_optimize(void *vp) } -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { diff --git a/util/ego/cs/cs_avail.c b/util/ego/cs/cs_avail.c index 1947051e0..bb06b081e 100644 --- a/util/ego/cs/cs_avail.c +++ b/util/ego/cs/cs_avail.c @@ -56,11 +56,11 @@ STATIC bool same_avail(byte kind, avail_p avp1, avail_p avp2) case BINAIR_OP: case REMAINDER: if (commutative(avp1->av_instr & BMASK)) - return avp1->av_oleft == avp2->av_oleft && - avp1->av_oright == avp2->av_oright + return (avp1->av_oleft == avp2->av_oleft && + avp1->av_oright == avp2->av_oright) || - avp1->av_oleft == avp2->av_oright && - avp1->av_oright == avp2->av_oleft + (avp1->av_oleft == avp2->av_oright && + avp1->av_oright == avp2->av_oleft) ; else return avp1->av_oleft == avp2->av_oleft && @@ -98,7 +98,8 @@ STATIC entity_p result_local(offset size, line_p l) if (l == (line_p) 0) return (entity_p) 0; - if (INSTR(l)==op_stl && size==ws || INSTR(l)==op_sdl && size==2*ws) { + if ((INSTR(l)==op_stl && size==ws) || + (INSTR(l)==op_sdl && size==2*ws)) { enp = getentity(l, &dummy); if (is_regvar(enp->en_loc)) { OUTTRACE("save local found, %ld(LB)", enp->en_loc); diff --git a/util/ego/em_ego/em_ego.c b/util/ego/em_ego/em_ego.c index eb177116a..14caea2bf 100644 --- a/util/ego/em_ego/em_ego.c +++ b/util/ego/em_ego/em_ego.c @@ -4,6 +4,7 @@ optimizer itself one day ... */ +#include #include #include #include @@ -121,14 +122,15 @@ cleanup() } /*VARARGS1*/ -static void - fatal(s, s2) char* s; -char* s2; +static void fatal(const char *s, ...) { /* A fatal error occurred; exit gracefully */ + va_list ap; + va_start(ap, s); + fprint(STDERR, "%s: ", prog_name); - fprint(STDERR, s, s2); + doprnt(STDERR, s, ap); fprint(STDERR, "\n"); cleanup(); sys_stop(S_EXIT); diff --git a/util/ego/ic/ic.c b/util/ego/ic/ic.c index e59ad1d96..a0203aefb 100644 --- a/util/ego/ic/ic.c +++ b/util/ego/ic/ic.c @@ -52,12 +52,12 @@ lab_id lastlid = 0; offset mespar = UNKNOWN_SIZE; /* argumument of ps_par message of current procedure */ -extern process_lines(); -extern int readline(); -extern line_p readoperand(); -extern line_p inpseudo(); +STATIC void process_lines(FILE *); +STATIC int readline(short *, line_p *); +STATIC line_p readoperand(short); +STATIC line_p inpseudo(short); -main(argc, argv) int argc; +int main(argc, argv) int argc; char* argv[]; { /* The input files must be legal EM Compact @@ -133,7 +133,7 @@ char* argv[]; #define END_INSTR 4 #define DELETED_INSTR 5 -STATIC add_end() +STATIC void add_end() { /* Add an end-pseudo to the current instruction list */ @@ -142,7 +142,7 @@ STATIC add_end() lastline->l_instr = ps_end; } -process_lines(fout) +STATIC void process_lines(fout) FILE* fout; { line_p lnp; @@ -235,8 +235,7 @@ process_lines(fout) } } -int readline(instr_out, lnp_out) short* instr_out; -line_p* lnp_out; +STATIC int readline(short *instr_out, line_p *lnp_out) { register line_p lnp; short n; @@ -310,7 +309,7 @@ line_p* lnp_out; /* NOTREACHED */ } -line_p readoperand(instr) short instr; +STATIC line_p readoperand(short instr) { /* Read the operand of the given instruction. * Create a line struct and return a pointer to it. @@ -432,7 +431,7 @@ static char* hol_label() return lastname; } -line_p inpseudo(n) short n; +STATIC line_p inpseudo(short n) { int m; line_p lnp; diff --git a/util/ego/ic/ic_aux.c b/util/ego/ic/ic_aux.c index 5cf7e0675..1f3eee3c8 100644 --- a/util/ego/ic/ic_aux.c +++ b/util/ego/ic/ic_aux.c @@ -28,8 +28,7 @@ /* opr_size */ -offset opr_size(instr) - short instr; +offset opr_size(short instr) { switch(instr) { case op_loe: @@ -96,9 +95,7 @@ STATIC offset argsize(arg) } -STATIC offset blocksize(pseudo,args) - byte pseudo; - arg_p args; +STATIC offset blocksize(byte pseudo, arg_p args) { /* Determine the number of bytes of a datablock */ @@ -167,7 +164,7 @@ STATIC arg_p copy_rom(args) -dblockdef(db,n,lnp) +void dblockdef(db,n,lnp) dblock_p db; int n; line_p lnp; @@ -206,10 +203,7 @@ dblockdef(db,n,lnp) /* combine */ -combine(db,l1,l2,pseu) - dblock_p db; - line_p l1,l2; - byte pseu; +void combine(dblock_p db, line_p l1, line_p l2, byte pseu) { /* Combine two successive ROMs/CONs (without a data label * in between into a single ROM. E.g.: @@ -258,7 +252,7 @@ combine(db,l1,l2,pseu) /* arglist */ -STATIC arg_string(length,abp) +STATIC void arg_string(length,abp) offset length; register argb_p abp; { @@ -447,10 +441,7 @@ STATIC obj_p make_object(dbl,off,size) -obj_p object(ident,off,size) - char *ident; - offset off; - offset size; +obj_p object(char *ident, offset off, offset size) { dblock_p dbl; diff --git a/util/ego/ic/ic_aux.h b/util/ego/ic/ic_aux.h index 92cd3c792..cc9ffc41f 100644 --- a/util/ego/ic/ic_aux.h +++ b/util/ego/ic/ic_aux.h @@ -10,35 +10,38 @@ -extern offset opr_size(); /* ( short instr ) +offset opr_size(short instr); /* * size of operand of given instruction. * The operand is an object , so the * instruction can be loe, zre etc.. */ -extern dblockdef(); /* (dblock_p db, int n, line_p lnp) +void dblockdef(dblock_p db, int n, line_p lnp); + /* * Fill in d_pseudo, d_size and * d_values fields of db. */ -extern combine(); /* (dblock_p db;line_p l1,l2;byte pseu) +void combine(dblock_p db, line_p l1, line_p l2, byte pseu); + /* * Combine two successive ROMs or CONs * (with no data label in between) * into one ROM or CON. */ -extern line_p arglist(); /* ( int m) +line_p arglist(int m); /* * Read a list of m arguments. If m * is 0, then the list is of * undetermined length; it is * then terminated by a cend symbol. */ -extern bool is_datalabel(); /* ( line_p l) +bool is_datalabel(line_p l); /* * TRUE if l is a data label defining * occurrence (i.e. its l_instr * field is ps_sym). */ -extern dblock_p block_of_lab(); /* (char *ident) +dblock_p block_of_lab(char *ident); /* * Find the datablock with * the given name. */ -extern obj_p object(); /* (char *ident,offset off,short size) +obj_p object(char *ident, offset off, offset size); + /* * Create an object struct. */ diff --git a/util/ego/ic/ic_io.c b/util/ego/ic/ic_io.c index 7d7ff48be..65d1d4260 100644 --- a/util/ego/ic/ic_io.c +++ b/util/ego/ic/ic_io.c @@ -95,15 +95,15 @@ offset get_off() { } } -STATIC make_string(n) int n; { +STATIC void make_string(n) int n; { sprintf(string,".%u",n); } -STATIC inident() { - register n; +STATIC void inident() { + register int n; register char *p = string; - register c; + register int c; n = get_int(); while (n--) { @@ -140,7 +140,7 @@ int table3(n) int n; { } int table1() { - register n; + register int n; n = readbyte(); if (n == EOF) @@ -161,7 +161,7 @@ int table1() { } int table2() { - register n; + register int n; n = readbyte(); if ((n < sp_fcst0 + sp_ncst0) && (n >= sp_fcst0)) { @@ -174,10 +174,7 @@ int table2() { -file_init(f,state,length) - FILE *f; - short state; - long length; +void file_init(FILE *f, short state, long length) { short n; @@ -193,7 +190,7 @@ file_init(f,state,length) -arch_init(arch) +void arch_init(arch) FILE *arch; { short n; diff --git a/util/ego/ic/ic_io.h b/util/ego/ic/ic_io.h index dcbc20ffc..e8531cec3 100644 --- a/util/ego/ic/ic_io.h +++ b/util/ego/ic/ic_io.h @@ -8,22 +8,24 @@ * L O W L E V E L I / O R O U T I N E S */ +#include /* FILE */ -extern int table1(); /* ( ) +int table1(void); /* * Read an instruction from the * Compact Assembly Language input * file (in 'neutral state'). */ -extern int table2(); /* ( ) +int table2(void); /* * Read an instruction argument. */ -extern int table3(); /* ( int ) +int table3(int); /* * Read 'Common Table' item. */ -extern short get_int(); /* ( ) */ -extern offset get_off(); /* ( ) */ -extern char readchar(); /* ( ) */ -extern file_init(); /* (FILE *f, short state, long length) +short get_int(void); +offset get_off(void); +char readchar(void); +void file_init(FILE *f, short state, long length); + /* * Input file initialization. All * following read operations will read * from the given file f. Also checks @@ -32,7 +34,7 @@ extern file_init(); /* (FILE *f, short state, long length) * If the state is ARCHIVE, length * specifies the length of the module. */ -extern arch_init(); /* (FILE *arch) +void arch_init(FILE *arch); /* * Same as file_init,but opens an * archive file. So it checks the * magic number for archives. diff --git a/util/ego/ic/ic_lib.c b/util/ego/ic/ic_lib.c index 7721bf27e..3933493e8 100644 --- a/util/ego/ic/ic_lib.c +++ b/util/ego/ic/ic_lib.c @@ -22,7 +22,7 @@ #include "../share/files.h" #include "ic_lib.h" -STATIC skip_string(n) +STATIC void skip_string(n) offset n; { /* Read a string of length n and void it */ @@ -60,7 +60,7 @@ STATIC void skip_arguments() } } -STATIC bool proc_wanted(name) char* name; +STATIC bool proc_wanted(const char *name) { /* See if 'name' is the name of an external procedure * that has been used before, but for which no body @@ -79,7 +79,7 @@ STATIC bool proc_wanted(name) char* name; } } -STATIC bool data_wanted(name) char* name; +STATIC bool data_wanted(const char *name) { /* See if 'name' is the name of an externally visible * data block that has been used before, but for which diff --git a/util/ego/ic/ic_lib.h b/util/ego/ic/ic_lib.h index 27cee4e16..9ba8836ca 100644 --- a/util/ego/ic/ic_lib.h +++ b/util/ego/ic/ic_lib.h @@ -9,7 +9,8 @@ */ -extern FILE *next_file(); /* (int argc, char *argv[]) +FILE *next_file(int argc, char *argv[]); + /* * See if there are any more EM input files. * 'argv' contains the names of the files * that are passed as arguments to ic. diff --git a/util/ego/ic/ic_lookup.c b/util/ego/ic/ic_lookup.c index 34c2391fa..5e4867d1b 100644 --- a/util/ego/ic/ic_lookup.c +++ b/util/ego/ic/ic_lookup.c @@ -17,6 +17,7 @@ #include "../share/debug.h" #include "../share/map.h" #include "ic.h" +#include "ic_io.h" #include "ic_lookup.h" #include "../share/alloc.h" @@ -43,8 +44,7 @@ char *lastname; -lab_id instr_lab(number) - short number; +lab_id instr_lab(short number) { register num_p *npp, np; @@ -82,7 +82,7 @@ lab_id instr_lab(number) /* symlookup */ -STATIC unsigned hash(string) char *string; { +STATIC unsigned hash(const char *string) { register char *p; register unsigned i,sum; @@ -91,9 +91,7 @@ STATIC unsigned hash(string) char *string; { return(sum); } -dblock_p symlookup(name, status) - char *name; - int status; +dblock_p symlookup(const char *name, int status) { /* Look up the name of a data block. The name can appear * in either a defining or applied occurrence (status is @@ -206,9 +204,7 @@ proc_p getproc(status) /* proclookup */ -proc_p proclookup(name, status) - char *name; - int status; +proc_p proclookup(const char *name, int status) { register prc_p *ppp, pp; register proc_p dp; @@ -271,7 +267,7 @@ proc_p proclookup(name, status) /* cleaninstrlabs */ -cleaninstrlabs() +void cleaninstrlabs() { register num_p *npp, np, next; @@ -290,7 +286,7 @@ cleaninstrlabs() /* dump_procnames */ -dump_procnames(hash,n,f) +void dump_procnames(hash,n,f) prc_p hash[]; int n; FILE *f; @@ -328,7 +324,7 @@ dump_procnames(hash,n,f) /* cleanprocs */ -cleanprocs(hash,n,mask) +void cleanprocs(hash,n,mask) prc_p hash[]; int n,mask; { @@ -372,7 +368,7 @@ cleanprocs(hash,n,mask) /* dump_dblocknames */ -dump_dblocknames(hash,n,f) +void dump_dblocknames(hash,n,f) sym_p hash[]; int n; FILE *f; @@ -404,7 +400,7 @@ dump_dblocknames(hash,n,f) /* cleandblocks */ -cleandblocks(hash,n,mask) +void cleandblocks(hash,n,mask) sym_p hash[]; int n,mask; { diff --git a/util/ego/ic/ic_lookup.h b/util/ego/ic/ic_lookup.h index aad66621e..8a92930d3 100644 --- a/util/ego/ic/ic_lookup.h +++ b/util/ego/ic/ic_lookup.h @@ -35,42 +35,52 @@ extern sym_p symhash[]; extern prc_p prochash[]; extern num_p numhash[]; -extern lab_id instr_lab(); /* ( short number) +lab_id instr_lab(short number); /* * Maps EM labels to sequential * integers. */ -extern dblock_p symlookup(); /* (char *ident, int status) +dblock_p symlookup(const char *ident, int status); + /* * Look up the data block with * the given name. */ -extern dblock_p getsym(); /* ( int status) +dblock_p getsym(int status); /* * Read and look up a symbol. * If this is the first occurrence * of it, then make it external * (if status=OCCURRING) or * internal (if DEFINING). */ -extern proc_p getproc(); /* (int status) +proc_p getproc(int status); /* * Same as getsym, but for procedure * names. */ -extern proc_p proclookup(); /* ( char *ident, int status) +proc_p proclookup(const char *ident, int status); + /* * Find (in the hashtable) the * procedure with the given name. */ -extern cleaninstrlabs(); /* ( ) +void cleaninstrlabs(void); /* * Forget about all instruction labels. */ -extern dump_procnames(); /* (prc_p hash[], int n, FILE *f) +void dump_procnames(prc_p hash[], int n, FILE *f); + /* * Save the names of the procedures * in file f; hash is the hashtable * used and n is its length. */ -extern cleanprocs(); /* (prc_p hash[], int n,mask) +void cleanprocs(prc_p hash[], int n, int mask); + /* * Make the names of all procedures * for which p_flags1&mask = 0 invisible */ -extern cleandblocks(); /* (sym_p hash[], int n) +void dump_dblocknames(sym_p hash[], int n, FILE *f); + /* + * Save the names of the EM data + * blocks in FILE f. + */ +void cleandblocks(sym_p hash[], int n, int mask); + /* * Make the names of all data blocks * for which d_flags1&mask = 0 invisible */ diff --git a/util/ego/il/il.c b/util/ego/il/il.c index 6ae0fbce2..e5931e980 100644 --- a/util/ego/il/il.c +++ b/util/ego/il/il.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,9 @@ #include "../share/map.h" #include "il_aux.h" #include "il1_anal.h" +#include "il1_aux.h" #include "il2_aux.h" +#include "il3_change.h" #include "il3_subst.h" #include "../share/get.h" #include "../share/put.h" @@ -56,7 +59,7 @@ int Sbig_caller, Sdispensable, Schangedcallee, Sbigcallee, Sspace, Szeroratio; * The call descriptors are put in a file (calfile). */ -pass1(lnam, bnam, cnam) char* lnam, *bnam, *cnam; +STATIC void pass1(const char *lnam, const char *bnam, const char *cnam) { FILE* f, *gf, *cf, *ccf; /* The EM input, the basic block graph, * the call-list file and the calcnt file. @@ -124,8 +127,7 @@ pass1(lnam, bnam, cnam) char* lnam, *bnam, *cnam; STATIC char cname2[128] = TMP_DIR; -pass2(cnam, space) char* cnam; -long space; +STATIC void pass2(const char *cnam, long space) { FILE* cf, *cf2, *ccf; call_p c, a; @@ -176,7 +178,7 @@ long space; * EM textfile. */ -pass3(lnam, lnam2) char* lnam, *lnam2; +void pass3(const char *lnam, const char *lnam2) { bool verbose = TRUE; FILE* lfile, *lfilerand, *lfile2, *sfile; @@ -244,7 +246,7 @@ pass3(lnam, lnam2) char* lnam, *lnam2; } } -STATIC il_extptab(ptab) +STATIC void il_extptab(ptab) proc_p ptab; { /* Allocate space for extension of proctable entries. @@ -261,7 +263,7 @@ STATIC il_extptab(ptab) } } -STATIC il_cleanptab(ptab) +STATIC void il_cleanptab(ptab) proc_p ptab; { /* De-allocate space for extensions */ @@ -275,7 +277,7 @@ STATIC il_cleanptab(ptab) } #ifdef VERBOSE -Sdiagnostics() +STATIC void Sdiagnostics() { /* print statictical information */ @@ -324,7 +326,7 @@ void il_flags(void *vp) } } -main(argc, argv) int argc; +int main(argc, argv) int argc; char* argv[]; { struct files* files = findfiles(argc, argv); diff --git a/util/ego/il/il1_anal.c b/util/ego/il/il1_anal.c index b0ff4a79a..7b0840d5c 100644 --- a/util/ego/il/il1_anal.c +++ b/util/ego/il/il1_anal.c @@ -15,6 +15,7 @@ #include "il.h" #include "../share/debug.h" #include "../share/alloc.h" +#include "../share/cset.h" #include "../share/global.h" #include "../share/lset.h" #include "../share/utils.h" @@ -38,7 +39,7 @@ -apriori(proctab) +void apriori(proctab) proc_p proctab; { /* For every procedure, see if we can determine @@ -68,7 +69,7 @@ apriori(proctab) } -STATIC check_labels(p,arglist) +STATIC void check_labels(p,arglist) proc_p p; arg_p arglist; { @@ -91,7 +92,7 @@ STATIC check_labels(p,arglist) -STATIC anal_instr(p,b,cf) +STATIC void anal_instr(p,b,cf) proc_p p; bblock_p b; FILE *cf; @@ -152,7 +153,7 @@ STATIC anal_instr(p,b,cf) -anal_proc(p,cf,ccf) +void anal_proc(p,cf,ccf) proc_p p; FILE *cf,*ccf; { diff --git a/util/ego/il/il1_anal.h b/util/ego/il/il1_anal.h index de44c4b13..dada53d57 100644 --- a/util/ego/il/il1_anal.h +++ b/util/ego/il/il1_anal.h @@ -8,14 +8,16 @@ * I L 1 _ A N A L . H */ -extern apriori(); /* (proc_p proctab) +void apriori(proc_p proctab); + /* * For every procedure, see if we can determine * from the information provided by the previous * phases of the optimizer that it cannot or should not * be expanded in line. This will reduce the length * of the call list. */ -extern anal_proc(); /* (proc_p p, FILE *cf, *cff) +void anal_proc(proc_p p, FILE *cf, FILE *cff); + /* * Analyse a procedure. See which formal parameters * it uses and which procedures it calls. * cf and ccf are the call-file and the call-count file. diff --git a/util/ego/il/il1_aux.c b/util/ego/il/il1_aux.c index d8da36dea..31e9cdd42 100644 --- a/util/ego/il/il1_aux.c +++ b/util/ego/il/il1_aux.c @@ -57,7 +57,7 @@ STATIC bool is_reg(off,s) } -rem_actuals(acts) +void rem_actuals(acts) actual_p acts; { /* remove the actual-list */ @@ -73,7 +73,7 @@ rem_actuals(acts) -remov_formals(p) +void remov_formals(p) proc_p p; { /* Remove the list of formals of p */ diff --git a/util/ego/il/il1_aux.h b/util/ego/il/il1_aux.h index af8fe1ecf..18bd594fd 100644 --- a/util/ego/il/il1_aux.h +++ b/util/ego/il/il1_aux.h @@ -8,34 +8,36 @@ * I L 1 _ A U X . H */ -extern bool same_size(); /* (int t1,t2) +bool same_size(int t1, int t2); /* * See if the two types t1 and t2 have * the same size. */ -extern rem_actuals(); /* (actual_p atcs) +void rem_actuals(actual_p acts);/* * remove an actual-list from core. */ -extern remov_formals(); /* (proc_p p) +void remov_formals(proc_p p); /* * Remove the formals-list of p from core. */ -extern void rem_indir_acc(); /* (proc_p p) +void rem_indir_acc(proc_p p); /* * Remove formal that may be accessed * indirectly from formal lists of p */ -extern bool par_overlap(); /* (offset off1, int t1, offset off2, int t2) +bool par_overlap(offset off1, int t1, offset off2, int t2); + /* * See if the formal at offset off1 and type t1 * overlaps the formal at offset off2 * and type t2. */ -extern short looplevel(); /* (bblock_p b) +short looplevel(bblock_p b); /* * Determine the loop nesting level of b. */ -extern int proclength(); /* (proc_p p) +int proclength(proc_p p); /* * Determine the number of EM instructions * in p. Do not count pseudos. */ -extern line_p copy_code(); /* (line_p l1,l2) +line_p copy_code(line_p l1, line_p l2); + /* * copy the code between l1 and l2. * Pseudos may not be contained in * the list of instructions. If l1==l2 diff --git a/util/ego/il/il1_cal.c b/util/ego/il/il1_cal.c index 854370697..6ec240c86 100644 --- a/util/ego/il/il1_cal.c +++ b/util/ego/il/il1_cal.c @@ -13,6 +13,7 @@ #include #include "../share/types.h" #include "il.h" +#include "il_aux.h" #include "il1_cal.h" #include "../share/debug.h" #include "../share/alloc.h" @@ -91,7 +92,7 @@ STATIC void inc_count(caller,callee) -anal_cal(p,call,b,cf) +void anal_cal(p,call,b,cf) proc_p p; line_p call; bblock_p b; diff --git a/util/ego/il/il1_cal.h b/util/ego/il/il1_cal.h index 1b17269f8..41a17be2e 100644 --- a/util/ego/il/il1_cal.h +++ b/util/ego/il/il1_cal.h @@ -29,7 +29,8 @@ extern struct class classtab[]; #define CLASS9 9 -extern anal_cal(); /* (line_p call, bblock_p b) +void anal_cal(proc_p p, line_p call, bblock_p b, FILE *cf); + /* * analyze a call instruction; * try to recognize the actual parameter * expressions. diff --git a/util/ego/il/il1_formal.c b/util/ego/il/il1_formal.c index 94e2e32f7..4e62c96d1 100644 --- a/util/ego/il/il1_formal.c +++ b/util/ego/il/il1_formal.c @@ -70,7 +70,7 @@ formal_p find_formal(p,type,off) -STATIC no_inl_pars(p) +STATIC void no_inl_pars(p) proc_p p; { /* p may not have any in line parameters */ @@ -81,7 +81,7 @@ STATIC no_inl_pars(p) -STATIC inc_use(f,b) +STATIC void inc_use(f,b) formal_p f; bblock_p b; { diff --git a/util/ego/il/il1_formal.h b/util/ego/il/il1_formal.h index bd2aea74d..625f40113 100644 --- a/util/ego/il/il1_formal.h +++ b/util/ego/il/il1_formal.h @@ -8,8 +8,8 @@ * I L 1 _ F O R M A L . C */ -extern void formal(); /* (proc_p p; bblock_p b; offset off; - * int type, usage) +void formal(proc_p p, bblock_p b, offset off, int type, int usage); + /* * Analyze a reference to a parameter of p. * The type denotes its size (single,double, * pointer). diff --git a/util/ego/il/il2_aux.c b/util/ego/il/il2_aux.c index 33a98ec42..786607d01 100644 --- a/util/ego/il/il2_aux.c +++ b/util/ego/il/il2_aux.c @@ -17,6 +17,7 @@ #include "../share/debug.h" #include "../share/alloc.h" #include "../share/global.h" +#include "../share/cset.h" #include "../share/lset.h" #include "il_aux.h" #include "il2_aux.h" @@ -34,6 +35,9 @@ #define CHANGED(p) p->p_flags2 |= PF_CHANGED #define IS_CHANGED(p) (p->p_flags2 & PF_CHANGED) +#ifdef VERBOSE +STATIC void Sstat(proc_p proclist, long space); +#endif STATIC bool match_pars(fm,act) @@ -220,7 +224,7 @@ STATIC short param_score(c) -assign_ratio(c) +void assign_ratio(c) call_p c; { /* This routine is one of the most important ones @@ -289,7 +293,7 @@ call_p abstract(c) -STATIC adjust_counts(callee,ccf) +STATIC void adjust_counts(callee,ccf) proc_p callee; FILE *ccf; { @@ -389,7 +393,7 @@ STATIC call_p find_origin(c) -STATIC selected(a) +STATIC void selected(a) call_p a; { /* The call a is selected for in line expansion. @@ -406,7 +410,7 @@ STATIC selected(a) -STATIC compare(x,best,space) +STATIC void compare(x,best,space) call_p x, *best; long space; { @@ -450,7 +454,7 @@ STATIC call_p best_one(list,space) -STATIC singles(cals) +STATIC void singles(cals) call_p cals; { /* If a procedure is only called once, this call @@ -486,7 +490,7 @@ STATIC singles(cals) -STATIC single_calls(proclist) +STATIC void single_calls(proclist) proc_p proclist; { proc_p p; @@ -505,7 +509,7 @@ STATIC single_calls(proclist) -select_calls(proclist,ccf,space) +void select_calls(proclist,ccf,space) proc_p proclist; FILE *ccf; long space ; @@ -549,7 +553,7 @@ select_calls(proclist,ccf,space) -STATIC nonnested_calls(cfile) +STATIC void nonnested_calls(cfile) FILE *cfile; { register call_p c,a; @@ -569,7 +573,7 @@ STATIC nonnested_calls(cfile) -STATIC copy_pars(src,dest) +STATIC void copy_pars(src,dest) call_p src, dest; { /* Copy the actual parameters of src to dest. */ @@ -589,7 +593,7 @@ STATIC copy_pars(src,dest) -STATIC nest_pars(cals) +STATIC void nest_pars(cals) call_p cals; { /* Recursive auxiliary procedure of add_actuals. */ @@ -607,7 +611,7 @@ STATIC nest_pars(cals) -add_actuals(proclist,cfile) +void add_actuals(proclist,cfile) proc_p proclist; FILE *cfile; { @@ -633,7 +637,7 @@ add_actuals(proclist,cfile) -STATIC clean(cals) +STATIC void clean(cals) call_p *cals; { call_p c,next,*cpp; @@ -655,7 +659,7 @@ STATIC clean(cals) } -cleancals(proclist) +void cleancals(proclist) proc_p proclist; { /* Remove all calls in the P_CALS list of p @@ -672,7 +676,7 @@ cleancals(proclist) -append_abstract(a,p) +void append_abstract(a,p) call_p a; proc_p p; { @@ -698,7 +702,7 @@ append_abstract(a,p) */ -Sstatist(list,space) +STATIC void Sstatist(list,space) call_p list; long space; { @@ -717,7 +721,7 @@ Sstatist(list,space) } } -Sstat(proclist,space) +STATIC void Sstat(proclist,space) proc_p proclist; long space; { diff --git a/util/ego/il/il2_aux.h b/util/ego/il/il2_aux.h index dd1283258..8c4efdebe 100644 --- a/util/ego/il/il2_aux.h +++ b/util/ego/il/il2_aux.h @@ -3,22 +3,23 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ -extern bool anal_params(); /* (call_p c) +bool anal_params(call_p c); /* * See which parameters of the call * may be expanded in line. * If the formals and actuals do not * match, return FALSE */ -extern assign_ratio(); /* (call_p c) +void assign_ratio(call_p c); /* * Assigna ratio number to the call, * indicating how desirable it is to * expand the call in line. */ -extern call_p abstract(); /* (call_p c) +call_p abstract(call_p c); /* * Abstract essential information from * the call. */ -extern select_calls(); /* (call_p alist; FILE *ccf;short space) +void select_calls(proc_p proclist, FILE *ccf, long space); + /* * Select the best calls to be expanded. * Every procedure gets a list of * selected calls appearing in it. @@ -26,10 +27,11 @@ extern select_calls(); /* (call_p alist; FILE *ccf;short space) * program is allowed to grow * (expressed in number of EM instructions). */ -extern cleancals(); /* (proc_p plist) +void cleancals(proc_p alist); /* * Remove all calls that were not selected. */ -extern add_actuals(); /* (proc_p plist; FILE *cfile) +void add_actuals(proc_p plist, FILE *cfile); + /* * Add the actual parameters to the descriptor abstracts * of the selected calls. * the calfile contains the full descriptors of all @@ -37,7 +39,8 @@ extern add_actuals(); /* (proc_p plist; FILE *cfile) * These two are combined to yield a file of full * descriptors of the selected calls. */ -extern append_abstract(); /* (call_p a; proc_p p) +void append_abstract(call_p a, proc_p p); + /* * Put the call-descriptor abstract in the p_cals * list of p. */ diff --git a/util/ego/il/il3_aux.c b/util/ego/il/il3_aux.c index bca67f12d..1732519cb 100644 --- a/util/ego/il/il3_aux.c +++ b/util/ego/il/il3_aux.c @@ -14,7 +14,6 @@ #include "../share/debug.h" #include "../share/alloc.h" #include "../share/global.h" -#include "il_aux.h" #include "il3_aux.h" @@ -33,7 +32,7 @@ line_p last_line(lines) -app_list(list,l) +void app_list(list,l) line_p list,l; { /* Append the list after line l */ @@ -53,7 +52,7 @@ app_list(list,l) -rem_line(l) +void rem_line(l) line_p l; { /* Remove a line from the list */ diff --git a/util/ego/il/il3_aux.h b/util/ego/il/il3_aux.h index 8b0e6b6b6..2552b1cab 100644 --- a/util/ego/il/il3_aux.h +++ b/util/ego/il/il3_aux.h @@ -8,13 +8,14 @@ * I L 3 _ A U X . H */ -extern line_p last_line(); /* (line_p list) +line_p last_line(line_p list); /* * Find the last line of a list. */ -extern app_list(); /* (line_p list,l) +void app_list(line_p list, line_p l); + /* * Put list after l */ -extern rem_line(); /* (line_p l) +void rem_line(line_p l); /* * Remove a line from a (doubly linked) * list. */ diff --git a/util/ego/il/il3_change.c b/util/ego/il/il3_change.c index b783375c1..24333f6ed 100644 --- a/util/ego/il/il3_change.c +++ b/util/ego/il/il3_change.c @@ -54,7 +54,7 @@ STATIC line_p par_expr(l,expr) -STATIC rem_text(l1,l2) +STATIC void rem_text(l1,l2) line_p l1,l2; { /* Remove the lines from l1 to l2 (inclusive) */ @@ -69,7 +69,7 @@ STATIC rem_text(l1,l2) -STATIC store_tmp(p,l,size) +STATIC void store_tmp(p,l,size) proc_p p; line_p l; offset size; @@ -103,7 +103,7 @@ STATIC store_tmp(p,l,size) -STATIC chg_actuals(c,cal) +STATIC void chg_actuals(c,cal) call_p c; line_p cal; { @@ -131,7 +131,7 @@ STATIC chg_actuals(c,cal) -STATIC rm_callpart(c,cal) +STATIC void rm_callpart(c,cal) call_p c; line_p cal; { @@ -155,7 +155,7 @@ STATIC rm_callpart(c,cal) -chg_callseq(c,cal,l_out) +void chg_callseq(c,cal,l_out) call_p c; line_p cal,*l_out; { @@ -237,7 +237,7 @@ STATIC void act_info(off,acts,ab_off,act_out,off_out) -STATIC store_off(off,l) +STATIC void store_off(off,l) offset off; line_p l; { @@ -251,7 +251,7 @@ STATIC store_off(off,l) -STATIC inl_actual(l,expr) +STATIC void inl_actual(l,expr) line_p l, expr; { /* Expand an actual parameter in line. @@ -281,7 +281,7 @@ STATIC inl_actual(l,expr) -STATIC localref(l,c,ab_off,lb_off) +STATIC void localref(l,c,ab_off,lb_off) line_p l; call_p c; offset ab_off, lb_off; @@ -311,7 +311,7 @@ STATIC localref(l,c,ab_off,lb_off) -STATIC chg_mes(l,c,ab_off,lb_off) +STATIC void chg_mes(l,c,ab_off,lb_off) line_p l; call_p c; offset ab_off, lb_off; @@ -355,7 +355,7 @@ STATIC chg_mes(l,c,ab_off,lb_off) -STATIC chg_ret(l,c,lab) +STATIC void chg_ret(l,c,lab) line_p l,lab; call_p c; { @@ -379,7 +379,7 @@ STATIC chg_ret(l,c,lab) -STATIC mod_instr(l,c,lab,ab_off,lb_off,lab_off) +STATIC void mod_instr(l,c,lab,ab_off,lb_off,lab_off) line_p l,lab; call_p c; offset ab_off,lb_off; @@ -421,7 +421,7 @@ STATIC mod_instr(l,c,lab,ab_off,lb_off,lab_off) } -modify(text,c,lab,ab_off,lb_off,lab_off) +void modify(text,c,lab,ab_off,lb_off,lab_off) line_p text,lab; call_p c; offset ab_off,lb_off; @@ -453,7 +453,7 @@ modify(text,c,lab,ab_off,lb_off,lab_off) -mod_actuals(nc,c,lab,ab_off,lb_off,lab_off) +void mod_actuals(nc,c,lab,ab_off,lb_off,lab_off) call_p nc,c; line_p lab; offset ab_off,lb_off; @@ -534,7 +534,7 @@ insert(text,l,firstline) -liquidate(p,text) +void liquidate(p,text) proc_p p; line_p text; { diff --git a/util/ego/il/il3_change.h b/util/ego/il/il3_change.h index 95c14f11c..8c8921ac1 100644 --- a/util/ego/il/il3_change.h +++ b/util/ego/il/il3_change.h @@ -9,7 +9,8 @@ */ -extern chg_callseq(); /* (call_p c; line_p cal, *l_out) +void chg_callseq(call_p c, line_p cal, line_p *l_out); + /* * Change the calling sequence of * the call c. The parameters are * changed and the sequence @@ -19,28 +20,33 @@ extern chg_callseq(); /* (call_p c; line_p cal, *l_out) * text of the called routine must * be put. */ -extern line_p make_label(); /* (line_p l; proc_p p) +line_p make_label(line_p l, proc_p p); + /* * Make sure that the instruction after * l contains a label. If this is not * already the case, create a new label. */ -extern modify(); /* (line_p text; call_p c; line_p lab; - * offset ab_off, lb_off; int lab_off) +void modify(line_p text, call_p c, line_p lab, offset ab_off, + offset lb_off, int lab_off); + /* * Modify the EM text of the called * procedure. */ -extern mod_actuals(); /* (call_p nc,c; line_p lab; - * offset ab_off, lb_off; int lab_off) +void mod_actuals(call_p nc, call_p c, line_p lab, offset ab_off, + offset lb_off, int lab_off); + /* * Modify the actual parameters of the * call nc the same way as the text of * call c would be modified. */ -extern void insert(); /* (line_p text,l,firstline) +void insert(line_p text, line_p l, line_p firstline); + /* * Insert the modified EM text. * Pseudos are put after the pseudos * of the caller. */ -extern liquidate(); /* (proc_p p; line_p text) +void liquidate(proc_p p, line_p text); + /* * All calls to p were expanded in line, * so p is no longer needed. */ diff --git a/util/ego/il/il3_subst.c b/util/ego/il/il3_subst.c index dcb39e80f..7438e784a 100644 --- a/util/ego/il/il3_subst.c +++ b/util/ego/il/il3_subst.c @@ -47,9 +47,7 @@ STATIC line_p fetch_text(lf,c) -line_p scan_to_cal(lines,n) - line_p lines; - short n; +line_p scan_to_cal(line_p lines, short n) { /* Find the n-th CAL instruction */ @@ -65,7 +63,7 @@ line_p scan_to_cal(lines,n) -substitute(lf,c,cal,firstline) +void substitute(lf,c,cal,firstline) FILE *lf; call_p c; line_p cal,firstline; diff --git a/util/ego/il/il3_subst.h b/util/ego/il/il3_subst.h index a44cc4a65..f525666d9 100644 --- a/util/ego/il/il3_subst.h +++ b/util/ego/il/il3_subst.h @@ -9,10 +9,12 @@ * I L 3 _ S U B S T . H */ -extern line_p scan_to_cal(); /* (line_p lines; short n) +line_p scan_to_cal(line_p lines, short n); + /* * Find the n-th cal instruction. */ -extern substitute(); /* (FILE *lf;call_p c; line_ pcal,firstline) +void substitute(FILE *lf, call_p c, line_p cal, line_p firstline); + /* * Perform in line substitution of the call described * by c. The EM text of the called routine is fetched * and modified, the calling sequence is changed, diff --git a/util/ego/il/il_aux.c b/util/ego/il/il_aux.c index 2d6917ed1..4e8d50c41 100644 --- a/util/ego/il/il_aux.c +++ b/util/ego/il/il_aux.c @@ -106,7 +106,7 @@ line_p copy_expr(l1) -rem_call(c) +void rem_call(c) call_p c; { actual_p act, nexta; @@ -132,7 +132,7 @@ rem_call(c) -/* rem_graph */ +/* remunit */ STATIC short remlines(l) line_p l; @@ -149,11 +149,7 @@ STATIC short remlines(l) -void -remunit(kind,p,l) - short kind; - proc_p p; - line_p l; +void remunit(short kind, proc_p p, line_p l) { register bblock_p b; bblock_p next; @@ -176,12 +172,13 @@ remunit(kind,p,l) oldloop(Lelem(pi)); } Ldeleteset(p->p_loops); - oldmap(lmap,llength); - oldmap(lbmap,llength); - oldmap(bmap,blength); - oldmap(lpmap,lplength); + oldmap((void **) lmap,llength); + oldmap((void **) lbmap,llength); + oldmap((void **) bmap,blength); + oldmap((void **) lpmap,lplength); } -remcc(head) + +void remcc(head) calcnt_p head; { calcnt_p cc, next; @@ -271,8 +268,8 @@ line_p get_text(lf,p_out) * and labels to basic blocks are not used. */ if (*p_out != (proc_p) 0) { - oldmap(lmap,llength); - oldmap(lbmap,llength); + oldmap((void **) lmap,llength); + oldmap((void **) lbmap,llength); lmap = oldlmap; lpmap = oldlpmap; } @@ -309,7 +306,7 @@ calcnt_p getcc(ccf,p) /* The following routines are only used by the Inline Substitution phase */ -STATIC putactuals(alist,cfile) +STATIC void putactuals(alist,cfile) actual_p alist; FILE *cfile; { @@ -336,10 +333,7 @@ STATIC putactuals(alist,cfile) -putcall(c,cfile,level) - call_p c; - FILE *cfile; - short level; +void putcall(call_p c, FILE *cfile, short level) { /* output a call */ diff --git a/util/ego/il/il_aux.h b/util/ego/il/il_aux.h index 1e1cbadea..1f9b31784 100644 --- a/util/ego/il/il_aux.h +++ b/util/ego/il/il_aux.h @@ -9,50 +9,57 @@ * I L _ A U X . H */ -extern int tsize(); /* (int type) +#include /* FILE */ + +int tsize(int type); /* * Determine the size of a variable of * the given type. */ -extern line_p duplicate(); /* (line_p lnp) +line_p duplicate(line_p lnp); /* * Make a duplicate of the given EM * instruction. Pseudos may not be * passed as argumnets. */ -extern line_p copy_expr(); /* (line_p l1) +line_p copy_expr(line_p l1); /* * copy the expression l1. * Pseudos may not be contained in * the list of instructions. */ -extern rem_call(); /* (call_p c) +void rem_call(call_p c); /* * Remove a call from main memory. */ -extern rem_graph(); /* (proc_p p) +void remunit(short kind, proc_p p, line_p l); + /* * Remove the CFG and EM text of * a procedure from core. */ -extern remcc(); /* (calcnt_p head) +void remcc(calcnt_p head); /* * Remove call-count info from core. */ -extern call_p getcall(); /* (FILE *cf) +call_p getcall(FILE *cf); /* * Read a call from the call-file */ -extern line_p get_text(); /* (FILE *lf; proc_p *p_out) +line_p get_text(FILE *lf, proc_p *p_out); + /* * Read the EM text of one procedure. * The procedure read is returned via * p_out. */ -extern calcnt_p getcc(); /* (FILE *ccf; proc_p p) +calcnt_p getcc(FILE *ccf, proc_p p); + /* * Read the call-count information * of procedure p. */ -extern putcall(); /* (call_p call; FILE *cfile; short level) +void putcall(call_p call, FILE *cfile, short level); + /* * Write the call * with the given id to the given file. * The level is the nesting level, used by * putcall when it calls itself recurively. * It should be 0 on outer levels. */ -extern long putcc(); /* (calcnt_p head; FILE *ccf) +long putcc(calcnt_p head, FILE *ccf); + /* * Write call-count information to * file ccf. */ diff --git a/util/ego/lv/lv.c b/util/ego/lv/lv.c index 375fd8f55..8b916bc48 100644 --- a/util/ego/lv/lv.c +++ b/util/ego/lv/lv.c @@ -41,16 +41,16 @@ short nrvars; STATIC int Slv; STATIC bool mesgflag = FALSE; /* Suppress generation of live/dead info */ -STATIC app_block(); +STATIC void app_block(); -STATIC clean_up() +STATIC void clean_up() { local_p *p; for (p = &locals[1]; p <= &locals[nrlocals]; p++) { oldlocal(*p); } - oldmap(locals,nrlocals); + oldmap((void **) locals,nrlocals); } @@ -137,7 +137,7 @@ STATIC bool is_def(l) } -STATIC def_use(p) +STATIC void def_use(p) proc_p p; { /* Compute DEF(b) and USE(b), for every basic block b @@ -200,7 +200,7 @@ STATIC def_use(p) -STATIC unite_ins(bbset,setp) +STATIC void unite_ins(bbset,setp) lset bbset; cset *setp; { @@ -218,7 +218,7 @@ STATIC unite_ins(bbset,setp) -STATIC solve_lv(p) +STATIC void solve_lv(p) proc_p p; { /* Solve the data flow equations for Live Variables, @@ -254,7 +254,7 @@ STATIC solve_lv(p) } -STATIC live_variables_analysis(p) +STATIC void live_variables_analysis(p) proc_p p; { make_localtab(p); @@ -264,7 +264,7 @@ STATIC live_variables_analysis(p) } -STATIC init_live_dead(b) +STATIC void init_live_dead(b) bblock_p b; { /* For every register variable, see if it is @@ -313,7 +313,7 @@ STATIC line_p make_mesg(mesg,loc) -STATIC block_entry(b,prev) +STATIC void block_entry(b,prev) bblock_p b,prev; { short v,vn; @@ -345,7 +345,7 @@ STATIC block_entry(b,prev) -STATIC app_block(l,b) +STATIC void app_block(l,b) line_p l; bblock_p b; { @@ -369,7 +369,7 @@ STATIC app_block(l,b) -STATIC definition(l,useless_out,v_out,mesgflag) +STATIC void definition(l,useless_out,v_out,mesgflag) line_p l; bool *useless_out; short *v_out; @@ -420,7 +420,7 @@ STATIC definition(l,useless_out,v_out,mesgflag) -STATIC use(l,mesgflag) +STATIC void use(l,mesgflag) line_p l; bool mesgflag; { @@ -451,7 +451,7 @@ STATIC use(l,mesgflag) STATIC void nothing(line_p l1, line_p l2, offset size) { } /* No action to be undertaken at level 0 of parser */ -STATIC rem_code(l1,l2,b) +STATIC void rem_code(l1,l2,b) line_p l1,l2; bblock_p b; { @@ -481,9 +481,7 @@ STATIC rem_code(l1,l2,b) -lv_mesg(p,mesgflag) - proc_p p; - bool mesgflag; +STATIC void lv_mesg(proc_p p, bool mesgflag) { /* Create live/dead messages for every possible register * variable of p. A dead-message is put after a "use" of @@ -553,8 +551,7 @@ OUTVERBOSE("useless assignment ,proc %d,local %d", curproc->p_id, } -STATIC lv_extend(p) - proc_p p; +STATIC void lv_extend(proc_p p) { /* Allocate extended data structures for Use Definition analysis */ @@ -566,8 +563,7 @@ STATIC lv_extend(p) } -STATIC lv_cleanup(p) - proc_p p; +STATIC void lv_cleanup(proc_p p) { /* Deallocate extended data structures for Use Definition analysis */ @@ -610,7 +606,7 @@ void lv_optimize(void *vp) -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { diff --git a/util/ego/ra/build.lua b/util/ego/ra/build.lua index 4b934de56..cae0cfdb2 100644 --- a/util/ego/ra/build.lua +++ b/util/ego/ra/build.lua @@ -24,6 +24,7 @@ cprogram { "modules/src/em_data+lib", "h+emheaders", "+itemtab_h", + "./ra*.h", }, vars = { ["+cflags"] = {"-DVERBOSE", "-DNOTCOMPACT"} diff --git a/util/ego/ra/makeitems.c b/util/ego/ra/makeitems.c index 83f6703bd..f8bc64989 100644 --- a/util/ego/ra/makeitems.c +++ b/util/ego/ra/makeitems.c @@ -3,7 +3,8 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ - + +#include #include #include #include @@ -20,16 +21,20 @@ */ -#define TRUE 1 -#define FALSE 0 +void error(const char *s) +{ + fprintf(stderr,"%s\n",s); + exit(-1); +} -convert(mnemfile,itemfile) - FILE *mnemfile, *itemfile; + +void convert(FILE *mnemfile, FILE *itemfile) { char mnem1[20], mnem2[20],def[20],itemtype[20]; - int newcl,opc,index; + int opc,index; + bool newcl; - newcl = TRUE; + newcl = true; printf("struct item_descr itemtab[] = {\n"); for (;;) { fscanf(mnemfile,"%19s%19s%d",def,mnem1,&opc); @@ -47,28 +52,17 @@ convert(mnemfile,itemfile) * it has no type. */ printf("{NO_ITEM,0}, /* %s */\n", mnem1); - newcl = FALSE; + newcl = false; } else { printf("{%s,%d}, /* %s */\n",itemtype,index, mnem1); - newcl = TRUE; + newcl = true; } } printf("};\n"); } - -error(s) - 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; diff --git a/util/ego/ra/ra.c b/util/ego/ra/ra.c index 0b1d5e493..f8d7ee32e 100644 --- a/util/ego/ra/ra.c +++ b/util/ego/ra/ra.c @@ -18,6 +18,7 @@ #include "../share/files.h" #include "../share/get.h" #include "../share/put.h" +#include "../share/cset.h" #include "../share/lset.h" #include "../share/map.h" #include "../share/alloc.h" @@ -25,6 +26,7 @@ #include "ra.h" #include "ra_items.h" #include "ra_allocl.h" +#include "ra_lifet.h" #include "ra_profits.h" #include "ra_pack.h" #include "ra_xform.h" @@ -35,6 +37,8 @@ #define oldrabx(x) oldstruct(bext_ra,x) #define oldralpx(x) oldstruct(lpext_ra,x) +STATIC void stat_regusage(alloc_p list); + short alloc_id; static item_p items[NRITEMTYPES]; int nrinstrs; @@ -72,7 +76,7 @@ STATIC cond_p getcondtab(f) return tab; } -get_atab(f,tab) +STATIC void get_atab(f,tab) FILE *f; cond_p tab[NRREGTYPES][NRREGTYPES]; { @@ -88,7 +92,7 @@ get_atab(f,tab) } -get_otab(f,tab) +STATIC void get_otab(f,tab) FILE *f; cond_p tab[NRREGTYPES]; { @@ -155,7 +159,7 @@ STATIC bblock_p header(lp) } -STATIC ra_extproc(p) +STATIC void ra_extproc(p) proc_p p; { /* Allocate the extended data structures for procedure p */ @@ -178,7 +182,7 @@ STATIC ra_extproc(p) -STATIC ra_cleanproc(p) +STATIC void ra_cleanproc(p) proc_p p; { /* Allocate the extended data structures for procedure p */ @@ -199,7 +203,7 @@ STATIC ra_cleanproc(p) -STATIC loop_blocks(p) +STATIC void loop_blocks(p) proc_p p; { /* Compute the LP_BLOCKS sets for all loops of p */ @@ -218,7 +222,7 @@ STATIC loop_blocks(p) -STATIC make_instrmap(p,map) +STATIC void make_instrmap(p,map) proc_p p; line_p map[]; { @@ -253,7 +257,7 @@ STATIC bool useful_item(item) } -STATIC cleantimeset(s) +STATIC void cleantimeset(s) lset s; { register Lindex i; @@ -300,7 +304,7 @@ STATIC item_p cat_items(items) -STATIC clean_interval(list) +STATIC void clean_interval(list) interv_p list; { register interv_p x,next; @@ -313,7 +317,7 @@ STATIC clean_interval(list) -STATIC clean_allocs(list) +STATIC void clean_allocs(list) alloc_p list; { register alloc_p x,next; @@ -331,7 +335,7 @@ STATIC clean_allocs(list) -STATIC cleanitems(list) +STATIC void cleanitems(list) item_p list; { register item_p x,next; @@ -390,13 +394,13 @@ void ra_optimize(void *vp) clean_allocs(unpacked); clean_allocs(packed); cleanitems(itemlist); - oldmap(instrmap,nrinstrs-1); + oldmap((void **) instrmap,nrinstrs-1); ra_cleanproc(p); } -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { @@ -430,6 +434,10 @@ char *str_regtypes[] = { }; +/* + * All calls to print_items() and print_allocs() are in comments! + */ +#if 0 print_items(items,p) item_p items[]; proc_p p; @@ -510,10 +518,11 @@ print_allocs(list) } } } +#endif -short regs_needed[4]; -stat_regusage(list) +STATIC short regs_needed[4]; +STATIC void stat_regusage(list) alloc_p list; { int i; @@ -531,6 +540,10 @@ stat_regusage(list) +/* + * All calls to statistics() are in comments! + */ +#if 0 int cnt_regtypes[reg_float+1]; statistics(items) @@ -557,3 +570,4 @@ statistics(items) fprintf(stderr, "#%s = %d\n",str_regtypes[r],cnt_regtypes[r]); } } +#endif diff --git a/util/ego/ra/ra_allocl.c b/util/ego/ra/ra_allocl.c index e2ca7d657..eff2420df 100644 --- a/util/ego/ra/ra_allocl.c +++ b/util/ego/ra/ra_allocl.c @@ -27,7 +27,7 @@ #include "ra_allocl.h" #include "ra_interv.h" -STATIC count_usage(p,item,nrloops,sloopcnt,dloopcnt) +STATIC void count_usage(p,item,nrloops,sloopcnt,dloopcnt) proc_p p; item_p item; short nrloops, sloopcnt[], dloopcnt[]; @@ -92,7 +92,7 @@ STATIC alloc_p cons_alloc(item,timespan,stat_usecount, } -STATIC insert_alloc(alloc,list_p) +STATIC void insert_alloc(alloc,list_p) alloc_p alloc, *list_p; { alloc->al_next = *list_p; @@ -157,7 +157,7 @@ STATIC bblock_p init_point(item) } -STATIC add_blocks(b,s,span) +STATIC void add_blocks(b,s,span) bblock_p b; cset *s; interv_p *span; @@ -176,7 +176,7 @@ STATIC add_blocks(b,s,span) -STATIC whole_lifetime(item,ini_out,span_out) +STATIC void whole_lifetime(item,ini_out,span_out) item_p item; bblock_p *ini_out; interv_p *span_out; @@ -267,12 +267,10 @@ STATIC short countuses(usage,b) -STATIC allocs_of_item(p,item,loops,sloopcnt,dloopcnt,alloc_list_p) - proc_p p; - item_p item; - lset loops; - short *sloopcnt,*dloopcnt; /* dynamic arrays */ - alloc_p *alloc_list_p; +STATIC void +allocs_of_item(proc_p p, item_p item, lset loops, + short *sloopcnt, short *dloopcnt, /* dynamic arrays */ + alloc_p *alloc_list_p) { register Lindex li; loop_p lp; @@ -328,10 +326,7 @@ STATIC allocs_of_item(p,item,loops,sloopcnt,dloopcnt,alloc_list_p) -alloc_p build_alloc_list(p,nrloops,itemlist) - proc_p p; - short nrloops; - item_p itemlist; +alloc_p build_alloc_list(proc_p p, short nrloops, item_p itemlist) { short *sloopcnt,*dloopcnt; /* dynamic arrays */ register item_p item; @@ -351,7 +346,7 @@ alloc_p build_alloc_list(p,nrloops,itemlist) -build_rivals_graph(alloclist) +void build_rivals_graph(alloclist) alloc_p alloclist; { /* See which allocations in the list are rivals of each other, diff --git a/util/ego/ra/ra_allocl.h b/util/ego/ra/ra_allocl.h index 4278f995c..cb7050031 100644 --- a/util/ego/ra/ra_allocl.h +++ b/util/ego/ra/ra_allocl.h @@ -9,13 +9,13 @@ * R A _ A L L O C L I S T . H */ -extern alloc_p build_alloc_list(); /* (proc_p p; short nrloops; - * item_p itemlist) +alloc_p build_alloc_list(proc_p p, short nrloops, item_p itemlist); + /* * Build a list of possible allocations * for procedure p. An allocation * essentially is a pair (item,timespan) */ -extern build_rivals_graph(); /* (alloc_p alloclist) +void build_rivals_graph(alloc_p alloclist); /* See which allocations in the list are * rivals of each other, i.e. there is * some point of time, falling in both diff --git a/util/ego/ra/ra_aux.c b/util/ego/ra/ra_aux.c index d1d4b4309..5bfea06f8 100644 --- a/util/ego/ra/ra_aux.c +++ b/util/ego/ra/ra_aux.c @@ -38,8 +38,7 @@ time_p cons_time(l,b) -short loop_scale(lev) - short lev; +short loop_scale(short lev) { return (lev == 0 ? 1 : (lev > 3 ? 32 : 8 * lev)); } diff --git a/util/ego/ra/ra_aux.h b/util/ego/ra/ra_aux.h index f3c127403..5dc7e54ec 100644 --- a/util/ego/ra/ra_aux.h +++ b/util/ego/ra/ra_aux.h @@ -18,11 +18,11 @@ * register message of the local with * the given offset. */ -extern time_p cons_time(); /* (line_p l; bblock_p b) +time_p cons_time(line_p l, bblock_p b); /* * Construct a 'time' record with * fields 'l' and 'b'. */ -extern short loop_scale(); /* (short lev) +short loop_scale(short lev); /* * Estimate how many times an item * appearing in a loop of nesting * level 'lev' will be used dynamically. diff --git a/util/ego/ra/ra_interv.c b/util/ego/ra/ra_interv.c index b333124ad..0b727fa4a 100644 --- a/util/ego/ra/ra_interv.c +++ b/util/ego/ra/ra_interv.c @@ -19,8 +19,7 @@ #include "ra.h" #include "ra_interv.h" -interv_p cons_interval(t_start,t_stop) - short t_start,t_stop; +interv_p cons_interval(short t_start, short t_stop) { interv_p x; @@ -32,9 +31,7 @@ interv_p cons_interval(t_start,t_stop) -add_interval(t1,t2,list) - short t1,t2; - interv_p *list; +void add_interval(short t1, short t2, interv_p *list) { /* Add interval (t1,t2) to the list of intervals (which is * an in-out parameter!). The list is sorted in 'chronological' @@ -116,7 +113,7 @@ interv_p proc_lifetime(p) -STATIC set_min_max(iv1,iv2) +STATIC void set_min_max(iv1,iv2) interv_p *iv1,*iv2; { /* Auxiliary routine of intersect */ @@ -201,9 +198,7 @@ bool not_disjoint(list1,list2) -bool contains(t,timespan) - short t; - interv_p timespan; +bool contains(short t, interv_p timespan) { register interv_p iv; diff --git a/util/ego/ra/ra_interv.h b/util/ego/ra/ra_interv.h index 3c4275dc9..0f7dc3e1f 100644 --- a/util/ego/ra/ra_interv.h +++ b/util/ego/ra/ra_interv.h @@ -10,31 +10,39 @@ */ -extern interv_p cons_interval();/* (short t_start,t_stop) +interv_p cons_interval(short t_start, short t_stop); + /* * construct an interval */ -extern add_interval(); /* (short t1,t2; interv_p *list) +void add_interval(short t1, short t2, interv_p *list); + /* * Add interval (t1,t2) to the list of * intervals (which is an in-out parameter!). */ -extern interv_p loop_lifetime();/* (loop_p lp) +interv_p loop_lifetime(loop_p lp); + /* * Determine the timespan of the loop, * expressed as a list of intervals. */ -extern interv_p proc_lifetime();/* (proc_p p) +interv_p proc_lifetime(proc_p p); + /* * Determine the timespan of a procedure, * expressed as an interval. */ -extern interv_p intersect(); /* (interv_p list1,list2) +interv_p intersect(interv_p list1, interv_p list2); + /* * Intersect two lifetimes, each denoted * by a list of intervals. */ -extern bool not_disjoint(); /* (interv_p list1,list2) +bool not_disjoint(interv_p list1, interv_p list2); + /* * See if list1 and list2 do overlap somewhere. */ -extern bool contains(); /* (short t;interv_p timespan) +bool contains(short t, interv_p timespan); + /* * See if t is part of the timespan. */ -extern interv_p copy_timespan();/* (interv_p list) +interv_p copy_timespan(interv_p list); + /* * Make a copy of the timespan. */ diff --git a/util/ego/ra/ra_items.c b/util/ego/ra/ra_items.c index 49d1d847b..320330b34 100644 --- a/util/ego/ra/ra_items.c +++ b/util/ego/ra/ra_items.c @@ -33,7 +33,7 @@ /* prevent small constants from being put in a register */ -clean_tab(items) +void clean_tab(items) item_p items[]; { int t; @@ -85,7 +85,7 @@ item_p item_of(off,items) -fill_item(item,l) +void fill_item(item,l) item_p item; line_p l; { @@ -238,7 +238,7 @@ STATIC short item_size(item) -STATIC init_item(a,b) +STATIC void init_item(a,b) item_p a,b; { a->it_type = b->it_type; @@ -296,7 +296,7 @@ STATIC void add_item(item,t,items) -STATIC add_usage(l,b,items) +STATIC void add_usage(l,b,items) line_p l; bblock_p b; item_p items[]; @@ -323,7 +323,7 @@ STATIC add_usage(l,b,items) -build_itemlist(p,items,nrinstr_out) +void build_itemlist(p,items,nrinstr_out) proc_p p; item_p items[]; int *nrinstr_out; @@ -336,7 +336,7 @@ build_itemlist(p,items,nrinstr_out) register line_p l; register bblock_p b; - register cnt= 0; + register int cnt= 0; clean_tab(items); for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) { diff --git a/util/ego/ra/ra_items.h b/util/ego/ra/ra_items.h index 0ec5cf8c0..5582da4f5 100644 --- a/util/ego/ra/ra_items.h +++ b/util/ego/ra/ra_items.h @@ -8,26 +8,30 @@ * R A _ I T E M S . H */ -extern short item_type(); /* (line_p l) +short item_type(line_p l); /* * Determine the type of item (constant,local * variable etc.) accessed by l. */ -extern bool is_item(); /* (line_p l) +bool is_item(line_p l); /* * See if l accesses an item */ -extern item_p item_of(); /* (offset off;item_p items) +item_p item_of(offset off, item_p items[]); + /* * Determine the descriptor of the item * accessed by l; return 0 if not found */ -extern fill_item(); /* (item_p item;line_p l) +void fill_item(item_p item, line_p l); + /* * Compute the type and obj/off attributes * of the item accessed by l and put them * in the given item descriptor. */ -extern bool same_item(); /* (item_p a,b) +bool same_item(item_p a, item_p b); + /* * See if a and b are the same items. */ -extern build_itemlist(); /* (proc_p p;item_p items[]; int *nrinstr_out) +void build_itemlist(proc_p p, item_p items[], int *nrinstr_out); + /* * Determine all items accessed by procedure p * and put them in the items lists. All items * of type T must be put in list items[T]. diff --git a/util/ego/ra/ra_lifet.c b/util/ego/ra/ra_lifet.c index 5ea15826f..9e800b5fe 100644 --- a/util/ego/ra/ra_lifet.c +++ b/util/ego/ra/ra_lifet.c @@ -23,6 +23,7 @@ #include "../share/alloc.h" #include "ra.h" #include "ra_aux.h" +#include "ra_interv.h" #include "ra_items.h" #include "ra_lifet.h" @@ -33,7 +34,7 @@ #define is_deadmsg(l) (INSTR(l) == ps_mes && aoff(ARG(l),0) == ms_ego && \ aoff(ARG(l),1) == ego_dead) -build_lifetimes(items) +void build_lifetimes(items) item_p items[]; { /* compute the it_lives attribute of every item; this is diff --git a/util/ego/ra/ra_lifet.h b/util/ego/ra/ra_lifet.h index a6b2df4f1..d5927a37d 100644 --- a/util/ego/ra/ra_lifet.h +++ b/util/ego/ra/ra_lifet.h @@ -9,7 +9,8 @@ */ -extern build_lifetimes(); /* item_p items[]; +void build_lifetimes(item_p items[]); + /* * compute the it_lives attribute of every * item; this is a list of intervals * during which the item is live, diff --git a/util/ego/ra/ra_pack.c b/util/ego/ra/ra_pack.c index 92d005297..6e644d4e6 100644 --- a/util/ego/ra/ra_pack.c +++ b/util/ego/ra/ra_pack.c @@ -21,6 +21,8 @@ #include "ra.h" #include "ra_aux.h" #include "ra_interv.h" +#include "ra_pack.h" +#include "ra_profits.h" short regs_occupied[NRREGTYPES]; /* #occupied registers for reg_pointer, @@ -28,7 +30,7 @@ short regs_occupied[NRREGTYPES]; /* #occupied registers for reg_pointer, */ #define reg_available(t) (regs_available[t] > regs_occupied[t]) -STATIC initregcount() +STATIC void initregcount() { int t; @@ -47,9 +49,7 @@ STATIC alloc_p make_dummy() } -STATIC bool fits_in(a,b,cont_item) - alloc_p a,b; - bool *cont_item; +STATIC bool fits_in(alloc_p a, alloc_p b, bool *cont_item) { /* See if allocation a can be assigned the same register as b. * Both allocations should be of the same register-type. @@ -152,7 +152,7 @@ STATIC alloc_p choose_location(alloc,packed,p) -STATIC update_lists(alloc,unpacked,packed,fit) +STATIC void update_lists(alloc,unpacked,packed,fit) alloc_p alloc,unpacked,packed,fit; { /* 'alloc' has been granted a register; move it from the 'unpacked' @@ -237,7 +237,7 @@ STATIC alloc_p best_cumprofits(list,x_out,prev_out) -STATIC account_regsave(packed,unpacked) +STATIC void account_regsave(packed,unpacked) alloc_p packed,unpacked; { /* After all packing has been done, we check for every allocated @@ -327,7 +327,7 @@ STATIC alloc_p find_prev(alloc,list) * account_regsave from rejecting it. */ -STATIC repl_allocs(new,old,packed) +STATIC void repl_allocs(new,old,packed) alloc_p new,old,packed; { alloc_p x,next,prev,*p; @@ -356,7 +356,7 @@ STATIC repl_allocs(new,old,packed) -STATIC assemble_allocs(packed) +STATIC void assemble_allocs(packed) alloc_p packed; { register alloc_p x,m,next; @@ -377,10 +377,8 @@ STATIC assemble_allocs(packed) } } -pack(alloclist,time_opt,packed_out,not_packed_out,p) - alloc_p alloclist, *packed_out,*not_packed_out; - bool time_opt; - proc_p p; +void pack(alloc_p alloclist, bool time_opt, alloc_p *packed_out, + alloc_p *not_packed_out, proc_p p) { /* This is the packing system. It decides which allations * to grant a register. diff --git a/util/ego/ra/ra_pack.h b/util/ego/ra/ra_pack.h index 471025462..3abcd5e0f 100644 --- a/util/ego/ra/ra_pack.h +++ b/util/ego/ra/ra_pack.h @@ -9,8 +9,9 @@ * R A _ P A C K . H */ -extern pack(); /* ( alloc_p alloclist, *packed_out,*not_packed_out; - * bool time_opt; proc_p p) +void pack(alloc_p alloclist, bool time_opt, alloc_p *packed_out, + alloc_p *not_packed_out, proc_p p); + /* * This is the packing system. It decides which * allations to grant a register. */ diff --git a/util/ego/ra/ra_profits.c b/util/ego/ra/ra_profits.c index cfb82bcb7..b04e60a69 100644 --- a/util/ego/ra/ra_profits.c +++ b/util/ego/ra/ra_profits.c @@ -18,9 +18,7 @@ #include "ra_aux.h" #include "ra_profits.h" -STATIC bool test_cond(cond,val) - short cond; - offset val; +STATIC bool test_cond(short cond, offset val) { switch(cond) { case DEFAULT: @@ -34,10 +32,7 @@ STATIC bool test_cond(cond,val) } } -STATIC short map_value(tab,val,time) - struct cond_tab tab[]; - offset val; - bool time; +STATIC short map_value(struct cond_tab tab[], offset val, bool time) { cond_p p; @@ -49,10 +44,7 @@ STATIC short map_value(tab,val,time) } -STATIC short index_value(tab,n,time) - struct cond_tab tab[]; - short n; - bool time; +STATIC short index_value(struct cond_tab tab[], short n, bool time) { cond_p p; @@ -61,16 +53,15 @@ STATIC short index_value(tab,n,time) } -allocscore(itemtyp,localtyp,size,off,totyp,time_out,space_out) - short itemtyp, localtyp,totyp,size; - offset off; - short *time_out, *space_out; +STATIC void +allocscore(short itemtyp, short localtyp, short size, offset off, + short totyp, short *time_out, short *space_out) { cond_p m = (cond_p) 0; if (localtyp == reg_loop) localtyp = reg_any; - if (size == ws || size == ps && totyp == reg_pointer || - size == 2 * ws && totyp == reg_float) { + if (size == ws || (size == ps && totyp == reg_pointer) || + (size == 2 * ws && totyp == reg_float)) { switch(itemtyp) { case LOCALVAR: m = alocaltab[localtyp][totyp]; @@ -103,10 +94,9 @@ allocscore(itemtyp,localtyp,size,off,totyp,time_out,space_out) */ } -opening_cost(itemtyp,localtyp,off,time_out,space_out) - short itemtyp, localtyp; - offset off; - short *time_out, *space_out; +STATIC void +opening_cost(short itemtyp, short localtyp, offset off, + short *time_out, short *space_out) { cond_p m; @@ -142,8 +132,7 @@ opening_cost(itemtyp,localtyp,off,time_out,space_out) -regsave_cost(regs,time_out,space_out) - short regs[], *time_out, *space_out; +void regsave_cost(short regs[], short *time_out, short *space_out) { /* Estimate the costs of saving and restoring the registers * The array regs contains the number of registers of every @@ -178,9 +167,7 @@ STATIC short dyn_inits(inits) -compute_profits(alloclist,time_opt) - alloc_p alloclist; - bool time_opt; +void compute_profits(alloc_p alloclist, bool time_opt) { /* Compute the profits attribute of every allocation. * If the item of an allocation may be put in several types diff --git a/util/ego/ra/ra_profits.h b/util/ego/ra/ra_profits.h index 1a015cf95..33f6877fe 100644 --- a/util/ego/ra/ra_profits.h +++ b/util/ego/ra/ra_profits.h @@ -9,8 +9,8 @@ * R A _ P R O F I T S . H */ -extern compute_profits();/* (alloc_p alloclist) +void compute_profits(alloc_p alloclist, bool time_opt); + /* * Compute the profits attribute of every allocation. */ -extern regsave_cost(); /* (short regs[], *time_out, *space_out) - */ +void regsave_cost(short regs[], short *time_out, short *space_out); diff --git a/util/ego/ra/ra_xform.c b/util/ego/ra/ra_xform.c index 119803706..9d4d41b9f 100644 --- a/util/ego/ra/ra_xform.c +++ b/util/ego/ra/ra_xform.c @@ -77,8 +77,7 @@ struct repl repl_tab[NRREPLACEMENTS][REPL_LENGTH] = { -init_replacements(psize,wsize) - short psize,wsize; +void init_replacements(short psize, short wsize) { /* The replacement code to be generated depends on the * wordsize and pointer size of the target machine. @@ -137,9 +136,7 @@ STATIC int repl_index(l) -STATIC bool is_current(alloc,t) - alloc_p alloc; - short t; +STATIC bool is_current(alloc_p alloc, short t) { /* Is time t part of alloc's timespan? */ @@ -147,7 +144,7 @@ STATIC bool is_current(alloc,t) } -STATIC match_item(item,l) +STATIC bool match_item(item,l) item_p item; line_p l; { @@ -188,7 +185,7 @@ STATIC alloc_p find_alloc(alloclist,l,t) } -STATIC replace_line(l,b,list) +STATIC void replace_line(l,b,list) line_p l,list; bblock_p b; { @@ -245,7 +242,7 @@ STATIC line_p repl_code(lnp,regnr) -STATIC apply_alloc(b,l,alloc) +STATIC void apply_alloc(b,l,alloc) bblock_p b; line_p l; alloc_p alloc; @@ -355,7 +352,7 @@ STATIC line_p init_place(b) -STATIC append_code(l1,l2,b) +STATIC void append_code(l1,l2,b) line_p l1,l2; bblock_p b; { @@ -380,7 +377,7 @@ STATIC append_code(l1,l2,b) -STATIC emit_init_code(list) +STATIC void emit_init_code(list) alloc_p list; { /* Emit initialization code for all packed allocations. @@ -409,7 +406,7 @@ STATIC emit_init_code(list) -STATIC emit_mesregs(p,alloclist) +STATIC void emit_mesregs(p,alloclist) proc_p p; alloc_p alloclist; { @@ -432,7 +429,7 @@ STATIC emit_mesregs(p,alloclist) -rem_mes(p) +STATIC void rem_mes(p) proc_p p; { register bblock_p b; @@ -455,11 +452,8 @@ rem_mes(p) -xform_proc(p,alloclist,nrinstrs,instrmap) - proc_p p; - alloc_p alloclist; - short nrinstrs; - line_p instrmap[]; +void +xform_proc(proc_p p, alloc_p alloclist, short nrinstrs, line_p instrmap[]) { /* Transform every instruction of procedure p that uses an item * at a point where the item is kept in a register. @@ -498,10 +492,7 @@ xform_proc(p,alloclist,nrinstrs,instrmap) -bool always_in_reg(off,allocs,size_out) - offset off; - alloc_p allocs; - short *size_out; +bool always_in_reg(offset off, alloc_p allocs, short *size_out) { /* See if the local variable with the given offset is stored * in a register during its entire lifetime. As a side effect, @@ -526,7 +517,7 @@ bool always_in_reg(off,allocs,size_out) } -rem_locals(p,allocs) +void rem_locals(p,allocs) proc_p p; alloc_p allocs; { diff --git a/util/ego/ra/ra_xform.h b/util/ego/ra/ra_xform.h index 4254daafe..9d446934e 100644 --- a/util/ego/ra/ra_xform.h +++ b/util/ego/ra/ra_xform.h @@ -9,21 +9,35 @@ * R A _ X F O R M . H */ -extern init_replacements(); /* (short psize,wsize) +void init_replacements(short psize, short wsize); + /* * This routine must be called once, before * any call to xform_proc. It initializes * a machine dependent table. */ -extern xform_proc(); /* (proc_p p; alloc_p alloclist; - * short nrinstrs; line_p instrmap[]) +void xform_proc(proc_p p, alloc_p alloclist, short nrinstrs, + line_p instrmap[]); + /* * Transform a procedure. Alloclist must * contain the packed allocations (i.e. those * allocations that are assigned a register). */ -bool always_in_reg(); /* ( offset off; alloc_p allocs; - * short *size_out;) +bool always_in_reg(offset off, alloc_p allocs, short *size_out); + /* * See if the local variable with the given * offset is stored in a register during its * entire lifetime. As a side effect, * return the size of the local. */ +void rem_locals(proc_p p, alloc_p allocs); + /* + * Try to decrease the number of locals of + * procedure p, by looking at which locals + * are always stored in a register. + */ +void rem_formals(proc_p p, alloc_p allocs); + /* + * Try to decrease the number of formals of + * procedure p, by looking at which formals + * are always stored in a register. + */ diff --git a/util/ego/share/alloc.c b/util/ego/share/alloc.c index 2bd309b81..fc47e32ae 100644 --- a/util/ego/share/alloc.c +++ b/util/ego/share/alloc.c @@ -184,12 +184,12 @@ void olddblock(dblock_p dbl) { } -short **newmap(short length) { - return((short **) newcore((length+1) * sizeof(short *))); +void **newmap(short length) { + return(newcore((length+1) * sizeof(short *))); } /*ARGSUSED1*/ -void oldmap(short **mp, short length) { +void oldmap(void **mp, short length) { oldcore(mp, (length+1) * sizeof(short *)); } @@ -213,7 +213,7 @@ short *newtable(short length) { } /*ARGSUSED1*/ -void oldtable(short **mp, short length) { +void oldtable(short *mp, short length) { oldcore(mp, (length+1) * sizeof(short)); } diff --git a/util/ego/share/alloc.h b/util/ego/share/alloc.h index 17b32b483..3f86e3e5e 100644 --- a/util/ego/share/alloc.h +++ b/util/ego/share/alloc.h @@ -25,7 +25,7 @@ void *myalloc(size_t); line_p newline(byte optype); arg_p newarg(byte argtyp); -short **newmap(short length); +void **newmap(short length); cset newbitvect(short nrbytes); cond_p newcondtab(int length); @@ -35,12 +35,12 @@ void oldargs(arg_p); void oldargb(argb_p); void oldobjects(obj_p); void olddblock(dblock_p); -void oldmap(short **mp, short length); +void oldmap(void **mp, short length); void oldbitvect(cset s, short nrbytes); void oldcondtab(cond_p); short *newtable(short length); -void oldtable(short **mp, short length); +void oldtable(short *mp, short length); #define newdblock() (dblock_p) newstruct(dblock) #define newobject() (obj_p) newstruct(obj) diff --git a/util/ego/share/cset.h b/util/ego/share/cset.h index 83f4566ab..1ad77ba20 100644 --- a/util/ego/share/cset.h +++ b/util/ego/share/cset.h @@ -19,7 +19,7 @@ void Cjoin(cset, cset *); void Cintersect(cset, cset *); void Cdeleteset(cset); bool Cis_subset(cset, cset); -void Cclearset(cset, cset *); +void Cclear_set(cset *); void Ccopy_set(cset, cset *); void Csubtract(cset, cset *); bool Cequal(cset, cset); diff --git a/util/ego/share/get.c b/util/ego/share/get.c index d804d63c6..6cc695471 100644 --- a/util/ego/share/get.c +++ b/util/ego/share/get.c @@ -136,7 +136,7 @@ STATIC lset getlset(void *(*p)(short)) int id; s = Lempty_set(); - while (id = getshort()) { + while ((id = getshort()) != 0) { Ladd( (*p) (id), &s); } return s; diff --git a/util/ego/share/locals.c b/util/ego/share/locals.c index 1b94406a5..d8ec8c5cd 100644 --- a/util/ego/share/locals.c +++ b/util/ego/share/locals.c @@ -68,7 +68,7 @@ STATIC void localvar(offset off, short size, local_p *locs, bool reg, -STATIC check_message(line_p l, local_p *locs) +STATIC void check_message(line_p l, local_p *locs) { /* See if l is a register message */ diff --git a/util/ego/share/makecldef.c b/util/ego/share/makecldef.c index 2913e26f5..ac831ed3b 100644 --- a/util/ego/share/makecldef.c +++ b/util/ego/share/makecldef.c @@ -3,7 +3,8 @@ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ - + +#include #include #include #include @@ -23,16 +24,20 @@ */ -#define TRUE 1 -#define FALSE 0 +void error(const char *s) +{ + fprintf(stderr,"%s\n",s); + exit(-1); +} -convert(mnemfile,classfile) - FILE *mnemfile, *classfile; + +void convert(FILE *mnemfile, FILE *classfile) { char mnem1[10], mnem2[10],def[10]; - int src,res,newcl,opc; + int src,res,opc; + bool newcl; - newcl = TRUE; + newcl = true; printf("struct class classtab[] = {\n"); printf("\tNOCLASS,\tNOCLASS,\n"); /* EM mnemonics start at 1, arrays in C at 0 */ @@ -52,29 +57,18 @@ convert(mnemfile,classfile) * it has no class. */ printf("\tNOCLASS,\tNOCLASS,\n"); - newcl = FALSE; + newcl = false; } else { printf("\tCLASS%d,\t\tCLASS%d,\n",src,res); /* print a line like "CLASS8, CLASS1," */ - newcl = TRUE; + newcl = true; } } printf("};\n"); } - -error(s) - 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; diff --git a/util/ego/share/put.c b/util/ego/share/put.c index 30c382bfa..2ce0c3863 100644 --- a/util/ego/share/put.c +++ b/util/ego/share/put.c @@ -240,7 +240,7 @@ void putdtable(dblock_p head, FILE *df) } fclose(curoutp); if (omap != (obj_p *) 0) { - oldmap((short **) omap,olength); /* release memory for omap */ + oldmap((void **) omap,olength); /* release memory for omap */ } } @@ -309,7 +309,7 @@ void putptable(proc_p head, FILE *pf, bool all) } fclose(curoutp); if (pmap != (proc_p *) 0) { - oldmap((short **) pmap,plength); /* release memory for pmap */ + oldmap((void **) pmap,plength); /* release memory for pmap */ } } @@ -416,9 +416,9 @@ void putunit(short kind, proc_p p, line_p l, FILE *gf, FILE *lf) oldbblock(b); } /* Release the memory for the lmap, lbmap, bmap, lpmap tables */ - if (lmap != (line_p *) 0) oldmap((short **) lmap,llength); - if (lbmap != (bblock_p *) 0) oldmap((short **) lbmap,llength); - if (bmap != (bblock_p *) 0) oldmap((short **) bmap,blength); - if (lpmap != (loop_p *) 0) oldmap((short **) lpmap,lplength); + if (lmap != (line_p *) 0) oldmap((void **) lmap,llength); + if (lbmap != (bblock_p *) 0) oldmap((void **) lbmap,llength); + if (bmap != (bblock_p *) 0) oldmap((void **) bmap,blength); + if (lpmap != (loop_p *) 0) oldmap((void **) lpmap,lplength); curoutp = lf; } diff --git a/util/ego/sr/sr.c b/util/ego/sr/sr.c index 9bbed7bd7..eeb0e3c55 100644 --- a/util/ego/sr/sr.c +++ b/util/ego/sr/sr.c @@ -23,6 +23,7 @@ #include "../share/utils.h" #include "sr_aux.h" #include "sr_iv.h" +#include "sr_reduce.h" /* Strength reduction tries to change expensive operators occurring * in a loop into cheaper operators. The expensive operators considered @@ -69,7 +70,7 @@ void sr_machinit(void *vp) fscanf(f,"%d",&sli_threshold); } -STATIC del_ivs(ivs) +STATIC void del_ivs(ivs) lset ivs; { /* Delete the set of iv structs */ @@ -83,7 +84,7 @@ STATIC del_ivs(ivs) } -STATIC do_loop(loop) +STATIC void do_loop(loop) loop_p loop; { lset ivs, vars; @@ -111,7 +112,7 @@ STATIC do_loop(loop) -STATIC loopblocks(p) +STATIC void loopblocks(p) proc_p p; { /* Compute the LP_BLOCKS sets for all loops of p */ @@ -129,7 +130,7 @@ STATIC loopblocks(p) -STATIC opt_proc(p) +STATIC void opt_proc(p) proc_p p; { /* Optimize all loops of one procedure. We first do all @@ -182,7 +183,7 @@ STATIC bblock_p header(lp) -STATIC sr_extproc(p) +STATIC void sr_extproc(p) proc_p p; { /* Allocate the extended data structures for procedure p */ @@ -202,7 +203,7 @@ STATIC sr_extproc(p) } -STATIC sr_cleanproc(p) +STATIC void sr_cleanproc(p) proc_p p; { /* Remove the extended data structures for procedure p */ @@ -232,7 +233,7 @@ void sr_optimize(void *vp) -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { diff --git a/util/ego/sr/sr_aux.c b/util/ego/sr/sr_aux.c index 2e6d9c7f4..4ebd133f6 100644 --- a/util/ego/sr/sr_aux.c +++ b/util/ego/sr/sr_aux.c @@ -107,7 +107,7 @@ int elemsize(lnp) -concatenate(list1,list2) +void concatenate(list1,list2) line_p list1,list2; { /* Append list2 to the end of list1. list1 may not be empty. */ diff --git a/util/ego/sr/sr_aux.h b/util/ego/sr/sr_aux.h index 3b1961e67..785799bff 100644 --- a/util/ego/sr/sr_aux.h +++ b/util/ego/sr/sr_aux.h @@ -6,20 +6,23 @@ /* S R _ A U X . H */ -extern bool is_loopconst(); /* (line_p l; lset vars) +bool is_loopconst(line_p l, lset vars); + /* * See if l is a loop-constant. vars is the * set of variables changed in the loop. */ -extern bool is_caddress(); /* (line_p l) +bool is_caddress(line_p l, lset vars); + /* * See if l loads a loop-invariant entity of * size pointer-size. */ -extern int elemsize(); /* (line_p l) +int elemsize(line_p l); /* * l is an instruction that loads an array * descriptor. Try to determine the size * of the array elements. */ -extern concatenate(); /* (line_p list1,list2) +void concatenate(line_p list1, line_p list2); + /* * Append list2 to the end of list1 */ #define is_const(l) (INSTR(l) == op_loc) diff --git a/util/ego/sr/sr_cand.c b/util/ego/sr/sr_cand.c index 6c286d8ed..6449ecca3 100644 --- a/util/ego/sr/sr_cand.c +++ b/util/ego/sr/sr_cand.c @@ -49,7 +49,7 @@ STATIC lset cand, /* set of candidates */ -STATIC un_cand(lnp) +STATIC void un_cand(lnp) line_p lnp; { /* remove the variable stored into by lnp from the list of @@ -84,7 +84,7 @@ STATIC bool is_cand(lnp) } -STATIC make_cand(lnp) +STATIC void make_cand(lnp) line_p lnp; { /* make the variable stored into by lnp a candidate */ @@ -96,14 +96,14 @@ STATIC make_cand(lnp) -STATIC do_dismiss(lnp) +STATIC void do_dismiss(lnp) line_p lnp; { Ladd(lnp,&dism); } -STATIC dismiss(lnp) +STATIC void dismiss(lnp) line_p lnp; { /* The variable referenced by lnp is turned definitely into @@ -151,7 +151,7 @@ STATIC void try_cand(lnp,b) } -candidates(lp,cand_out,vars_out) +void candidates(lp,cand_out,vars_out) loop_p lp; lset *cand_out, *vars_out; { diff --git a/util/ego/sr/sr_cand.h b/util/ego/sr/sr_cand.h index 2d1b12420..201a25745 100644 --- a/util/ego/sr/sr_cand.h +++ b/util/ego/sr/sr_cand.h @@ -9,7 +9,8 @@ */ -extern candidates(); /* (loop_p lp; lset *iv_cand, *vars) +void candidates(loop_p lp, lset *iv_cand, lset *vars); + /* * Find candidate induction variables, * i.e. local variables that are assigned * a value precisely once within the loop, diff --git a/util/ego/sr/sr_expr.c b/util/ego/sr/sr_expr.c index 110d934d9..c92133368 100644 --- a/util/ego/sr/sr_expr.c +++ b/util/ego/sr/sr_expr.c @@ -111,10 +111,9 @@ STATIC int me_kind(l,sign_in,sign_out) -STATIC bool match_expr(l,iv_allowed,lbegin,iv_seen,sign) - line_p l,*lbegin; - bool iv_allowed, *iv_seen; - int sign; +STATIC bool +match_expr(line_p l, bool iv_allowed, line_p *lbegin, bool *iv_seen, + int sign) { /* This routine is a top down parser for simple * EM expressions. It recognizes expressions that diff --git a/util/ego/sr/sr_expr.h b/util/ego/sr/sr_expr.h index ef00bf2c7..6b97c2fab 100644 --- a/util/ego/sr/sr_expr.h +++ b/util/ego/sr/sr_expr.h @@ -9,8 +9,9 @@ * */ -extern bool is_ivexpr();/* (line_p l; lset ivs,vars; line_p *lbegin; iv_p *iv; - * int *out_sign) +bool is_ivexpr(line_p l, lset ivs, lset vars, line_p *lbegin, iv_p *iv, + int *out_sign); + /* * Try to recognize an expression that is a linear * function of presicely one induction variable. * It may only use loop constants (besides the diff --git a/util/ego/sr/sr_iv.c b/util/ego/sr/sr_iv.c index aa96e23c5..b0d11004f 100644 --- a/util/ego/sr/sr_iv.c +++ b/util/ego/sr/sr_iv.c @@ -76,7 +76,7 @@ STATIC bool is_same(l,lnp) } -STATIC ivar(lnp,step) +STATIC void ivar(lnp,step) line_p lnp; int step; { @@ -153,7 +153,7 @@ STATIC void try_patterns(lnp) } -induc_vars(loop,ivar_out, vars_out) +void induc_vars(loop,ivar_out, vars_out) loop_p loop; lset *ivar_out, *vars_out; { diff --git a/util/ego/sr/sr_iv.h b/util/ego/sr/sr_iv.h index 45169b2a2..a1a1337bb 100644 --- a/util/ego/sr/sr_iv.h +++ b/util/ego/sr/sr_iv.h @@ -5,7 +5,8 @@ */ /* S R _ I V . H */ -extern induc_vars(); /* (loop_p loop; lset *ivars, *vars) +void induc_vars(loop_p loop, lset *ivars, lset *vars); + /* * Find the set of induction variables * of the loop. Also find the set of (local) * variables that are changed. diff --git a/util/ego/sr/sr_reduce.c b/util/ego/sr/sr_reduce.c index e8b347f96..c78e456a1 100644 --- a/util/ego/sr/sr_reduce.c +++ b/util/ego/sr/sr_reduce.c @@ -55,7 +55,7 @@ STATIC int regtyp(code) } -STATIC gen_regmes(tmp,score,code,p) +STATIC void gen_regmes(tmp,score,code,p) offset tmp; int score; code_p code; @@ -121,7 +121,7 @@ STATIC line_p newcode(code,tmp) -STATIC replcode(code,text) +STATIC void replcode(code,text) code_p code; line_p text; { @@ -171,7 +171,7 @@ STATIC line_p add_code(pl, l) -STATIC init_code(code,tmp) +STATIC void init_code(code,tmp) code_p code; offset tmp; { @@ -239,7 +239,7 @@ STATIC init_code(code,tmp) *p = l; /* new last instruction */ } -STATIC incr_code(code,tmp) +STATIC void incr_code(code,tmp) code_p code; offset tmp; { @@ -322,7 +322,7 @@ STATIC incr_code(code,tmp) } -STATIC remcode(c) +STATIC void remcode(c) code_p c; { line_p l, next; @@ -453,7 +453,7 @@ STATIC code_p available(c,vars) return (code_p) 0; } -STATIC fix_header(lp) +STATIC void fix_header(lp) loop_p lp; { /* Check if a header block was added, and if so, add a branch to @@ -487,7 +487,7 @@ STATIC fix_header(lp) } } -STATIC reduce(code,vars) +STATIC void reduce(code,vars) code_p code; lset vars; { @@ -711,7 +711,7 @@ STATIC void try_array(lp,ivs,vars,b,arr) -STATIC clean_avail() +STATIC void clean_avail() { Lindex i; @@ -723,7 +723,7 @@ STATIC clean_avail() -strength_reduction(lp,ivs,vars) +void strength_reduction(lp,ivs,vars) loop_p lp; /* description of the loop */ lset ivs; /* set of induction variables of the loop */ lset vars; /* set of local variables changed in loop */ diff --git a/util/ego/sr/sr_reduce.h b/util/ego/sr/sr_reduce.h index 503d7ec9b..909c33ae4 100644 --- a/util/ego/sr/sr_reduce.h +++ b/util/ego/sr/sr_reduce.h @@ -5,6 +5,7 @@ */ /* S R _ R E D U C E . H */ -extern strength_reduction(); /* (loop_p loop; lset ivs, vars) - * Perform streength reduction. +void strength_reduction(loop_p loop, lset ivs, lset vars); + /* + * Perform strength reduction. */ diff --git a/util/ego/sr/sr_xform.c b/util/ego/sr/sr_xform.c index aa30b2cfa..d48a70844 100644 --- a/util/ego/sr/sr_xform.c +++ b/util/ego/sr/sr_xform.c @@ -66,7 +66,7 @@ line_p move_pointer(tmp,dir) /* make_header */ -STATIC copy_loops(b1,b2,except) +STATIC void copy_loops(b1,b2,except) bblock_p b1,b2; loop_p except; { @@ -108,7 +108,7 @@ STATIC lab_id label(b) } -STATIC adjust_jump(newtarg,oldtarg,c) +STATIC void adjust_jump(newtarg,oldtarg,c) bblock_p newtarg,oldtarg,c; { /* If the last instruction of c is a jump to the diff --git a/util/ego/sr/sr_xform.h b/util/ego/sr/sr_xform.h index a6065c90d..f09cffefe 100644 --- a/util/ego/sr/sr_xform.h +++ b/util/ego/sr/sr_xform.h @@ -11,12 +11,12 @@ -extern line_p move_pointer(); /* (offset tmp; int dir ) */ +line_p move_pointer(offset tmp, int dir); /* Generate EM code to load/store a pointer variable * onto/from the stack, depending on dir(ection). * We accept all kinds of pointer sizes. */ -extern void make_header() ; /* (loop_p lp) */ +void make_header(loop_p lp); /* Make sure that the loop has a header block, i.e. a block * has the loop entry block as its only successor and * that dominates the loop entry block. diff --git a/util/ego/ud/ud.c b/util/ego/ud/ud.c index 3a5e3d7a8..34460ab07 100644 --- a/util/ego/ud/ud.c +++ b/util/ego/ud/ud.c @@ -103,7 +103,7 @@ STATIC short map_value(tab,val,time) } -STATIC init_root(root) +STATIC void init_root(root) bblock_p root; { /* Initialise the IN OUT sets of the entry block of the @@ -133,7 +133,7 @@ STATIC init_root(root) -STATIC unite_outs(bbset,setp) +STATIC void unite_outs(bbset,setp) lset bbset; cset *setp; { @@ -151,7 +151,7 @@ STATIC unite_outs(bbset,setp) -STATIC solve_equations(p) +STATIC void solve_equations(p) proc_p p; { /* Solve the data flow equations for reaching @@ -390,7 +390,7 @@ pr_cblocks(p) #endif -STATIC ud_analysis(p) +STATIC void ud_analysis(p) proc_p p; { /* Perform use-definition analysis on procedure p */ @@ -415,20 +415,20 @@ STATIC ud_analysis(p) -STATIC clean_maps() +STATIC void clean_maps() { local_p *p; cset *v; - oldmap(defs,nrexpldefs); + oldmap((void **) defs,nrexpldefs); for (p = &locals[1]; p <= &locals[nrlocals]; p++) { oldlocal(*p); } - oldmap(locals,nrlocals); + oldmap((void **) locals,nrlocals); for (v = &vardefs[1]; v <= &vardefs[nrvars]; v++) { Cdeleteset(*v); } - oldmap(vardefs,nrvars); + oldmap((void **) vardefs,nrvars); } @@ -469,7 +469,7 @@ STATIC bool try_optim(l,b) -value_propagation(p) +STATIC void value_propagation(p) proc_p p; { /* Apply value propagation to procedure p */ @@ -484,7 +484,7 @@ value_propagation(p) * e.g. the value of A might be statically known too now. */ - while (changes) { + while (changes) { changes = FALSE; for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) { for (l = b->b_start; l != (line_p) 0; l = next) { @@ -495,12 +495,12 @@ value_propagation(p) } } } - oldmap(copies,nrcopies); + oldmap((void **) copies,nrcopies); oldtable(def_to_copynr,nrdefs); } -STATIC ud_extend(p) +STATIC void ud_extend(p) proc_p p; { /* Allocate extended data structures for Use Definition analysis */ @@ -513,7 +513,7 @@ STATIC ud_extend(p) } -STATIC ud_cleanup(p) +STATIC void ud_cleanup(p) proc_p p; { /* Deallocate extended data structures for Use Definition analysis */ @@ -553,7 +553,7 @@ void ud_optimize(void *vp) clean_maps(); } -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { diff --git a/util/ego/ud/ud_aux.c b/util/ego/ud/ud_aux.c index e027f4e10..34e93233a 100644 --- a/util/ego/ud/ud_aux.c +++ b/util/ego/ud/ud_aux.c @@ -24,7 +24,7 @@ #include "../share/utils.h" #include "ud_defs.h" -repl_line(old,new,b) +void repl_line(old,new,b) line_p old,new; bblock_p b; { diff --git a/util/ego/ud/ud_aux.h b/util/ego/ud/ud_aux.h index 829b2cc3b..f9b57592d 100644 --- a/util/ego/ud/ud_aux.h +++ b/util/ego/ud/ud_aux.h @@ -10,12 +10,14 @@ */ -extern repl_line(); /* (line_p old,new; bblock_p b) +void repl_line(line_p old, line_p new, bblock_p b); + /* * Replace EM instruction 'old' by a * copy of 'new'. Update doubly-linked * list. */ -extern bool same_var(); /* (line_p use,def) +bool same_var(line_p use, line_p def); + /* * 'use' is an instruction that uses a variable * for which we maintain ud-info (e.g. a LOL). * See if 'def' references the same variable. diff --git a/util/ego/ud/ud_const.c b/util/ego/ud/ud_const.c index cc5b33159..1e589c321 100644 --- a/util/ego/ud/ud_const.c +++ b/util/ego/ud/ud_const.c @@ -109,9 +109,7 @@ bool value_known(def,val_out) -bool affected(use,v,l) - line_p use,l; - short v; +bool affected(line_p use, short v, line_p l) { /* See if the variable referenced by 'use' may be * changed by instruction l, which is either a cal, cai or @@ -223,7 +221,7 @@ line_p unique_def(use,b,defnr_out) -fold_const(l,b,val) +void fold_const(l,b,val) line_p l; bblock_p b; offset val; diff --git a/util/ego/ud/ud_const.h b/util/ego/ud/ud_const.h index c75ad0482..4675376b3 100644 --- a/util/ego/ud/ud_const.h +++ b/util/ego/ud/ud_const.h @@ -6,23 +6,27 @@ /* C O N S T A N T P R O P A G A T I O N */ -extern line_p unique_def(); /* ( line_p use; bblock_p b; short *defnr_out;) +line_p unique_def(line_p use, bblock_p b, short *defnr_out); + /* * See if there is a unique explicit definition * of the variable used by 'use' that * reaches 'use'. */ -extern bool value_known(); /* (line_p def; offset *val_out) +bool value_known(line_p def, offset *val_out); + /* * See if the value stored by definition 'def' * is known statically (i.e. is a constant). */ -extern fold_const(); /* (line_p l; bblock_p b; offset val) +void fold_const(line_p l, bblock_p b, offset val); + /* * Perform the substitutions required for * constant folding. */ -extern bool is_use(); /* (line_p l) +bool is_use(line_p l); /* * See if 'l' is a use of a variable. */ -extern bool affected(); /* (line_p use,l; short v) +bool affected(line_p use, short v, line_p l); + /* * See if the variable referenced by 'use' may * be changed by instruction l, which is * either a cal, cai or an indirect assignment. diff --git a/util/ego/ud/ud_copy.c b/util/ego/ud/ud_copy.c index 096b228ab..eeaee49e8 100644 --- a/util/ego/ud/ud_copy.c +++ b/util/ego/ud/ud_copy.c @@ -83,7 +83,7 @@ STATIC void traverse_defs(p,action) -STATIC make_copytab(p) +STATIC void make_copytab(p) proc_p p; { /* Make a table of all copies appearing in procedure p. @@ -165,7 +165,7 @@ STATIC void gen_kill_copies(p) -STATIC intersect_outs(bbset,setp,full_set) +STATIC void intersect_outs(bbset,setp,full_set) lset bbset; cset *setp,full_set; { @@ -183,7 +183,7 @@ STATIC intersect_outs(bbset,setp,full_set) -STATIC init_cin(p,full_set) +STATIC void init_cin(p,full_set) proc_p p; cset full_set; { @@ -218,7 +218,7 @@ STATIC init_cin(p,full_set) -STATIC solve_cin(p) +STATIC void solve_cin(p) proc_p p; { /* Solve the data flow equations for reaching @@ -267,7 +267,7 @@ STATIC solve_cin(p) -copy_analysis(p) +void copy_analysis(p) proc_p p; { /* Determine which copies procedure p has. Compute C_IN(b), @@ -311,7 +311,7 @@ bool is_copy(def) -fold_var(old,new,b) +void fold_var(old,new,b) line_p old, new; bblock_p b; { @@ -369,10 +369,7 @@ END DEBUG */ -bool value_retained(copy,defnr,use,b) - line_p copy,use; - short defnr; - bblock_p b; +bool value_retained(line_p copy, short defnr, line_p use, bblock_p b) { /* See if the right hand side variable of the * copy still has the same value at 'use'. diff --git a/util/ego/ud/ud_copy.h b/util/ego/ud/ud_copy.h index c427cc058..d106661a5 100644 --- a/util/ego/ud/ud_copy.h +++ b/util/ego/ud/ud_copy.h @@ -16,23 +16,24 @@ extern short nrcopies; /* number of copies in the current procedure * (length of copies-table) */ -extern copy_analysis(); /* (proc_p p) +void copy_analysis(proc_p p); /* * Determine which copies procedure p has. * Compute C_IN(b), for every basic block b. */ -extern bool is_copy(); /* (line_p def) +bool is_copy(line_p def); /* * See if the definition def is also a 'copy', * i.e. an statement of the form * 'A := B' (or, in EM terminology: * a sequence 'Load Variable; Store Variable'). */ -extern fold_var(); /* (line_p old,new; bblock_p b) +void fold_var(line_p old, line_p new, bblock_p b); + /* * The variable referenced by the * EM instruction 'old' must be replaced * by the variable referenced by 'new'. */ -extern bool value_retained(); /* (line_p copy; short defnr; line_p use; - * bblock_p b) +bool value_retained(line_p copy, short defnr, line_p use, bblock_p b); + /* * See if the right hand side variable of the * copy still has the same value at 'use'. * If the copy and the use are in the same diff --git a/util/ego/ud/ud_defs.c b/util/ego/ud/ud_defs.c index 04839476d..1f227f9aa 100644 --- a/util/ego/ud/ud_defs.c +++ b/util/ego/ud/ud_defs.c @@ -80,7 +80,7 @@ bool does_impl_def(l) } -make_defs(p) +void make_defs(p) proc_p p; { /* Make a map of all explicit definitions @@ -134,7 +134,7 @@ make_defs(p) -STATIC init_gen(nrdefs) +STATIC void init_gen(nrdefs) short nrdefs; { /* Initializing routine of gen_sets. Compute the set @@ -161,7 +161,7 @@ STATIC init_gen(nrdefs) -STATIC clean_gen() +STATIC void clean_gen() { Cdeleteset(all_globl_defs); Cdeleteset(all_indir_defs); @@ -200,7 +200,7 @@ STATIC bool same_target(l,defnr) -STATIC rem_prev_defs(l,gen_p) +STATIC void rem_prev_defs(l,gen_p) line_p l; cset *gen_p; { @@ -223,7 +223,7 @@ STATIC rem_prev_defs(l,gen_p) -STATIC impl_globl_defs(p,gen_p) +STATIC void impl_globl_defs(p,gen_p) proc_p p; cset *gen_p; { @@ -287,7 +287,7 @@ STATIC void impl_gen_defs(l,gen_p) -gen_sets(p) +void gen_sets(p) proc_p p; { /* Compute for every basic block b of p the @@ -329,9 +329,7 @@ gen_sets(p) -STATIC killed_defs(v,b) - short v; - bblock_p b; +STATIC void killed_defs(short v, bblock_p b) { /* Put all definitions of v occurring outside b * in KILL(b). In fact, we also put explicit @@ -355,7 +353,7 @@ STATIC killed_defs(v,b) -kill_sets(p) +void kill_sets(p) proc_p p; { /* For every basic block b of p compute the set diff --git a/util/ego/ud/ud_defs.h b/util/ego/ud/ud_defs.h index f77f7217b..ed4e2dc15 100644 --- a/util/ego/ud/ud_defs.h +++ b/util/ego/ud/ud_defs.h @@ -13,21 +13,21 @@ extern short nrexpldefs; /* number of explicit definitions */ extern line_p *defs; /* map of explicit definitions */ extern cset *vardefs; /* set of explicit defs. of all variables */ -extern make_defs(); /* (proc_p p) +void make_defs(proc_p p); /* * Compute defs[], vardefs[] * and CHGVARS(b) (for every b). */ -extern gen_sets(); /* (proc_p p) +void gen_sets(proc_p p); /* * Compute GEN(b) (for every b). */ -extern kill_sets(); /* (proc_p p) - *Compute KILL(b) (for every b). +void kill_sets(proc_p p); /* + * Compute KILL(b) (for every b). */ -extern bool does_expl_def(); /* (line_p l) +bool does_expl_def(line_p l); /* * See if instruction l does an explicit * definition (e.g. a STL). */ -extern bool does_impl_def(); /* (line_p l) +bool does_impl_def(line_p l); /* * See if instruction l does an implicit * definition (e.g. a CAL). */ diff --git a/util/int/M.warn_h b/util/int/M.warn_h index 10f7be304..ae890a1f5 100755 --- a/util/int/M.warn_h +++ b/util/int/M.warn_h @@ -9,5 +9,10 @@ sed ' s/.*"/#define / ' +echo +echo 'void init_wmsg(void);' +echo 'void do_warn(int, int, const char *);' +echo 'void set_wmask(int);' +echo echo '#define warning(n) do_warn((n), __LINE__, __FILE__)' diff --git a/util/int/disassemble.c b/util/int/disassemble.c index f89cd6026..8605eb2a1 100644 --- a/util/int/disassemble.c +++ b/util/int/disassemble.c @@ -9,6 +9,7 @@ #include "memdirect.h" #include "proctab.h" #include "alloc.h" +#include "whatever.h" PRIVATE ptr TC; PRIVATE void do_pr_instr(unsigned int); diff --git a/util/int/do_array.c b/util/int/do_array.c index 9f850d4c7..94d976249 100644 --- a/util/int/do_array.c +++ b/util/int/do_array.c @@ -11,6 +11,7 @@ #include "mem.h" #include "text.h" #include "fra.h" +#include "switch.h" #define LAR 1 #define SAR 2 diff --git a/util/int/do_branch.c b/util/int/do_branch.c index bc279f786..8c4e546ad 100644 --- a/util/int/do_branch.c +++ b/util/int/do_branch.c @@ -12,6 +12,7 @@ #include "text.h" #include "fra.h" #include "warn.h" +#include "switch.h" /* Note that in the EM assembly language brach instructions have lables as their arguments, where in the EM machine language they diff --git a/util/int/do_comp.c b/util/int/do_comp.c index 9a5c3bd35..6b2f68b18 100644 --- a/util/int/do_comp.c +++ b/util/int/do_comp.c @@ -16,6 +16,7 @@ #include "text.h" #include "fra.h" #include "stack.h" +#include "switch.h" PRIVATE void compare_obj(size); diff --git a/util/int/do_conv.c b/util/int/do_conv.c index b1ee08132..70cbac50c 100644 --- a/util/int/do_conv.c +++ b/util/int/do_conv.c @@ -14,6 +14,7 @@ #include "fra.h" #include "warn.h" #include "stack.h" +#include "switch.h" void DoCII(void) { diff --git a/util/int/do_fpar.c b/util/int/do_fpar.c index 0d267027f..6422d4e5a 100644 --- a/util/int/do_fpar.c +++ b/util/int/do_fpar.c @@ -14,6 +14,7 @@ #include "fra.h" #include "io.h" #include "warn.h" +#include "switch.h" #ifndef NOFLOAT diff --git a/util/int/do_incdec.c b/util/int/do_incdec.c index 426288a57..97a5e2bff 100644 --- a/util/int/do_incdec.c +++ b/util/int/do_incdec.c @@ -15,6 +15,7 @@ #include "stack.h" #include "fra.h" #include "warn.h" +#include "switch.h" PRIVATE long inc(long), dec(long); diff --git a/util/int/do_intar.c b/util/int/do_intar.c index df81f5511..30bbf36d8 100644 --- a/util/int/do_intar.c +++ b/util/int/do_intar.c @@ -13,6 +13,7 @@ #include "warn.h" #include "text.h" #include "fra.h" +#include "switch.h" PRIVATE long adi(long, long, size), sbi(long, long, size), dvi(long, long, size); PRIVATE long mli(long, long, size), rmi(long, long), ngi(long, size); diff --git a/util/int/do_load.c b/util/int/do_load.c index b5faf42da..28e95a1d5 100644 --- a/util/int/do_load.c +++ b/util/int/do_load.c @@ -13,6 +13,7 @@ #include "fra.h" #include "rsb.h" #include "warn.h" +#include "switch.h" PRIVATE ptr lexback_LB(unsigned long); diff --git a/util/int/do_logic.c b/util/int/do_logic.c index 9e06bc7af..04b9a326e 100644 --- a/util/int/do_logic.c +++ b/util/int/do_logic.c @@ -14,6 +14,7 @@ #include "trap.h" #include "text.h" #include "fra.h" +#include "switch.h" #ifdef LOGGING extern int must_test; diff --git a/util/int/do_misc.c b/util/int/do_misc.c index 6c12f9723..f5fec2070 100644 --- a/util/int/do_misc.c +++ b/util/int/do_misc.c @@ -22,6 +22,8 @@ #include "rsb.h" #include "io.h" #include "linfil.h" +#include "switch.h" +#include "whatever.h" extern int running; /* from main.c */ @@ -32,13 +34,9 @@ ptr FIL; PRIVATE void index_jump(size), range_check(size), search_jump(size); PRIVATE void gto(ptr); -void putLIN(long); -void putFIL(ptr); #define asp(l) newSP(SP + arg_f(l)) -extern void moncall(void); - /** ASP f: Adjust the stack pointer by f */ void DoASP(register long l) { diff --git a/util/int/do_proc.c b/util/int/do_proc.c index 8c5e05892..d2e307048 100644 --- a/util/int/do_proc.c +++ b/util/int/do_proc.c @@ -19,12 +19,13 @@ #include "fra.h" #include "rsb.h" #include "linfil.h" +#include "switch.h" +#include "whatever.h" extern int running; /* from main.c */ /* Forward declarations */ PRIVATE void lfr(size), ret(size); -void call(long, int); /** CAI -: Call procedure (procedure identifier on stack) */ void DoCAI(void) /* proc identifier on top of stack */ diff --git a/util/int/do_ptrar.c b/util/int/do_ptrar.c index b576d3fb2..eb198d042 100644 --- a/util/int/do_ptrar.c +++ b/util/int/do_ptrar.c @@ -14,6 +14,7 @@ #include "warn.h" #include "text.h" #include "fra.h" +#include "switch.h" #define adp(p,w) ((p) + (w)) #define sbs(t,s) ((s) - (t)) diff --git a/util/int/do_sets.c b/util/int/do_sets.c index 9b560d851..f25b60967 100644 --- a/util/int/do_sets.c +++ b/util/int/do_sets.c @@ -11,6 +11,7 @@ #include "mem.h" #include "text.h" #include "fra.h" +#include "switch.h" PRIVATE void bit_test(size), create_set(size); diff --git a/util/int/do_store.c b/util/int/do_store.c index c5fc9fb56..711837fb6 100644 --- a/util/int/do_store.c +++ b/util/int/do_store.c @@ -12,6 +12,7 @@ #include "text.h" #include "fra.h" #include "warn.h" +#include "switch.h" /** STL l: Store local or parameter */ void DoSTL(register long l) diff --git a/util/int/do_unsar.c b/util/int/do_unsar.c index 89560946f..815c2a1c4 100644 --- a/util/int/do_unsar.c +++ b/util/int/do_unsar.c @@ -13,6 +13,7 @@ #include "warn.h" #include "text.h" #include "fra.h" +#include "switch.h" /************************************************************************ * No checking is performed, except for division by zero. * diff --git a/util/int/init.c b/util/int/init.c index 44e25ceb7..04b9421e7 100644 --- a/util/int/init.c +++ b/util/int/init.c @@ -21,10 +21,12 @@ #include "alloc.h" #include "warn.h" #include "mem.h" +#include "m_sigtrp.h" #include "io.h" #include "shadow.h" #include "trap.h" #include "read.h" +#include "whatever.h" /**************************************************************** diff --git a/util/int/io.c b/util/int/io.c index a903307aa..684f167aa 100644 --- a/util/int/io.c +++ b/util/int/io.c @@ -16,6 +16,7 @@ #include "warn.h" #include "log.h" #include "linfil.h" +#include "whatever.h" extern int running; /* from main.c */ extern char *prog_name; /* from main.c */ diff --git a/util/int/logging.h b/util/int/logging.h index ff95bcf62..59f612aa8 100644 --- a/util/int/logging.h +++ b/util/int/logging.h @@ -2,3 +2,7 @@ #define LOGGING 1 /* Includes logging when defined */ +#ifdef LOGGING +/* warn.c */ +void warningcont(int); +#endif /* LOGGING */ diff --git a/util/int/m_ioctl.c b/util/int/m_ioctl.c index 23fa9ddee..0e7261e13 100644 --- a/util/int/m_ioctl.c +++ b/util/int/m_ioctl.c @@ -9,6 +9,7 @@ #include "global.h" #include "mem.h" #include "warn.h" +#include "whatever.h" #ifdef WANT_SGTTY #include @@ -42,9 +43,7 @@ * (0 for success, -1 for failure) * ***********************************************************************/ -int do_ioctl(fd, req, addr) - int fd, req; - ptr addr; +int do_ioctl(int fd, int req, ptr addr) { register long e; #ifdef WANT_SGTTY diff --git a/util/int/m_sigtrp.c b/util/int/m_sigtrp.c index a4dbf600f..f48f9b0ab 100644 --- a/util/int/m_sigtrp.c +++ b/util/int/m_sigtrp.c @@ -12,6 +12,7 @@ #include "trap.h" #include "m_sigtrp.h" #include "io.h" +#include "whatever.h" /*************************** SIGTRP ************************************* * The monitor call "sigtrp()" is handled by "do_sigtrp()". The first * diff --git a/util/int/main.c b/util/int/main.c index 5587a3112..d88e0ddac 100644 --- a/util/int/main.c +++ b/util/int/main.c @@ -23,6 +23,8 @@ #include "opcode.h" #include "m_sigtrp.h" #include "rsb.h" +#include "switch.h" +#include "whatever.h" char mess_file[64] = "int.mess"; /* name of message file */ @@ -39,12 +41,6 @@ extern long inr; /* from log.c */ PRIVATE char *dflt_av[] = {"e.out", 0}; /* default arguments */ -/* External definitions - too lazy to create a header file for each. */ -extern void init(int , char **); -extern void disassemble(void); -extern void tally(void); -extern void out_tally(void); - /** Check dynamically that the interpreter can run on the target machine. */ static void check_requirements(char *name) { diff --git a/util/int/mem.h b/util/int/mem.h index 2f1d7cfd6..b57be0f20 100644 --- a/util/int/mem.h +++ b/util/int/mem.h @@ -4,6 +4,7 @@ /* $Id$ */ +#include "data.h" #include "stack.h" /******** Memory address & location defines ********/ @@ -65,12 +66,3 @@ #define st_inc(n) newSP(SP - (n)) /* stack grows */ #define st_dec(n) newSP(SP + (n)) /* stack shrinks */ - - -/******** Function return types ********/ - -extern ptr st_ldip(), dt_ldip(); -extern ptr st_lddp(), dt_lddp(), dppop(); -extern long st_lds(), st_ldsw(), dt_lds(), dt_ldsw(), spop(), swpop(), wpop(); -extern unsigned long st_ldu(), st_lduw(), dt_ldu(), dt_lduw(), upop(), uwpop(); - diff --git a/util/int/moncalls.c b/util/int/moncalls.c index 20b46532b..78b507fe7 100644 --- a/util/int/moncalls.c +++ b/util/int/moncalls.c @@ -5,16 +5,24 @@ /* $Id$ */ #include "sysidf.h" +#include "io.h" #include "log.h" #include "alloc.h" #include "shadow.h" +#include "m_sigtrp.h" +#include "monstruct.h" +#include "whatever.h" #include #include #include +#include #include +#include +#include #include #include +#include extern int running; /* from main.c */ extern int fd_limit; /* from io.c */ @@ -1091,7 +1099,7 @@ PRIVATE int vec(n1, n2, addr, vecvec) /* copy the elements */ for ( cp1 = buf[n1], n_ent = 0, p = addr; - ldp = mem_lddp(p); + (ldp = mem_lddp(p)) != 0; p += psize, n_ent++ ) { if (!savestr(n2, ldp)) { @@ -1099,7 +1107,7 @@ PRIVATE int vec(n1, n2, addr, vecvec) } (*vecvec)[n_ent] = cp1; cp2 = buf[n2]; - while (*cp1++ = *cp2++) { + while ((*cp1++ = *cp2++) != '\0') { /* nothing */ } } @@ -1107,9 +1115,7 @@ PRIVATE int vec(n1, n2, addr, vecvec) return 1; } -int memfault(addr, length) - ptr addr; - size length; +int memfault(ptr addr, size length) { /* centralizes (almost) all memory access tests in MON */ if (!is_in_mem(addr, length)) { @@ -1119,17 +1125,14 @@ int memfault(addr, length) return 0; } -efault(wrn) - int wrn; /* warning number */ +void efault(int wrn /* warning number */) { warning(wrn); errno = 14; /* EFAULT */ } -einval(wrn) - int wrn; /* warning number */ +void einval(int wrn /* warning number */) { warning(wrn); errno = 22; /* EINVAL */ } - diff --git a/util/int/monstruct.c b/util/int/monstruct.c index 71a99d9a3..27e769d87 100644 --- a/util/int/monstruct.c +++ b/util/int/monstruct.c @@ -9,6 +9,7 @@ #include "global.h" #include "mem.h" #include "monstruct.h" +#include "whatever.h" #include #include @@ -42,9 +43,7 @@ PRIVATE mem_stfld(addr, offset, length, val) mem_stn(addr + offset, val, length); } -int stat2mem(addr, statb) - ptr addr; - struct stat *statb; +int stat2mem(ptr addr, struct stat *statb) { if (memfault(addr, V7st_sz)) return 0; @@ -62,9 +61,7 @@ int stat2mem(addr, statb) return 1; } -int timeb2mem(addr, timebb) - ptr addr; - struct timeb *timebb; +int timeb2mem(ptr addr, struct timeb *timebb) { if (memfault(addr, V7tb_sz)) return 0; @@ -75,9 +72,7 @@ int timeb2mem(addr, timebb) return 1; } -int tms2mem(addr, tmsb) - ptr addr; - struct tms *tmsb; +int tms2mem(ptr addr, struct tms *tmsb) { if (memfault(addr, V7tms_sz)) return 0; diff --git a/util/int/monstruct.h b/util/int/monstruct.h index 0fe89dd38..729f6d007 100644 --- a/util/int/monstruct.h +++ b/util/int/monstruct.h @@ -12,6 +12,8 @@ /* $Id$ */ +#include "global.h" /* ptr */ + /* struct stat */ #define V7st_dev 0L, 2L /* short */ #define V7st_ino 2L, 2L /* unsigned short */ @@ -67,3 +69,10 @@ #define V7t_lnextc 5L, 1L /* char */ #define V7t_sz_ltch 6L +struct stat; +struct timeb; +struct tms; + +int stat2mem(ptr, struct stat *); +int timeb2mem(ptr, struct timeb *); +int tms2mem(ptr, struct tms *); diff --git a/util/int/rsb.c b/util/int/rsb.c index 4e7f7a6db..417263148 100644 --- a/util/int/rsb.c +++ b/util/int/rsb.c @@ -14,6 +14,7 @@ #include "segment.h" #include "text.h" #include "warn.h" +#include "whatever.h" /* offsets to be added to a local base */ int rsb_rsbcode; diff --git a/util/int/switch.c b/util/int/switch.c index b96f9a750..4bc587a65 100644 --- a/util/int/switch.c +++ b/util/int/switch.c @@ -10,6 +10,7 @@ #include "text.h" #include "trap.h" #include "warn.h" +#include "switch.h" void do_instr(unsigned int opcode) { diff --git a/util/int/switch.h b/util/int/switch.h new file mode 100644 index 000000000..1cecc50a5 --- /dev/null +++ b/util/int/switch.h @@ -0,0 +1,151 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-10-23 + * + */ +#ifndef SWITCH_H_ +#define SWITCH_H_ + +#include "global.h" /* size */ + +/* switch.c */ +void do_instr(unsigned int); + +/* do_*.c */ +void DoAAR(size); +void DoADF(size); +void DoADI(size); +void DoADP(long); +void DoADS(size); +void DoADU(size); +void DoAND(size); +void DoASP(long); +void DoASS(size); +void DoBEQ(long); +void DoBGE(long); +void DoBGT(long); +void DoBLE(long); +void DoBLM(size); +void DoBLS(size); +void DoBLT(long); +void DoBNE(long); +void DoBRA(long); +void DoCAI(void); +void DoCAL(long); +void DoCFF(void); +void DoCFI(void); +void DoCFU(void); +void DoCIF(void); +void DoCII(void); +void DoCIU(void); +void DoCMF(size); +void DoCMI(size); +void DoCMP(void); +void DoCMS(size); +void DoCMU(size); +void DoCOM(size); +void DoCSA(size); +void DoCSB(size); +void DoCUF(void); +void DoCUI(void); +void DoCUU(void); +void DoDCH(void); +void DoDEC(void); +void DoDEE(long); +void DoDEL(long); +void DoDUP(size); +void DoDUS(size); +void DoDVF(size); +void DoDVI(size); +void DoDVU(size); +void DoEXG(size); +void DoFEF(size); +void DoFIF(size); +void DoFIL(unsigned long); +void DoGTO(unsigned long); +void DoINC(void); +void DoINE(long); +void DoINL(long); +void DoINN(size); +void DoIOR(size); +void DoLAE(unsigned long); +void DoLAL(long); +void DoLAR(size); +void DoLDC(long); +void DoLDE(long); +void DoLDF(long); +void DoLDL(long); +void DoLFR(size); +void DoLIL(long); +void DoLIM(void); +void DoLIN(unsigned long); +void DoLNI(void); +void DoLOC(long); +void DoLOE(long); +void DoLOF(long); +void DoLOI(size); +void DoLOL(long); +void DoLOR(long); +void DoLOS(size); +void DoLPB(void); +void DoLPI(long); +void DoLXA(unsigned long); +void DoLXL(unsigned long); +void DoMLF(size); +void DoMLI(size); +void DoMLU(size); +void DoMON(void); +void DoNGF(size); +void DoNGI(size); +void DoNOP(void); +void DoRCK(size); +void DoRET(size); +void DoRMI(size); +void DoRMU(size); +void DoROL(size); +void DoROR(size); +void DoRTT(void); +void DoSAR(size); +void DoSBF(size); +void DoSBI(size); +void DoSBS(size); +void DoSBU(size); +void DoSDE(unsigned long); +void DoSDF(long); +void DoSDL(long); +void DoSET(size); +void DoSIG(void); +void DoSIL(long); +void DoSIM(void); +void DoSLI(size); +void DoSLU(size); +void DoSRI(size); +void DoSRU(size); +void DoSTE(unsigned long); +void DoSTF(long); +void DoSTI(size); +void DoSTL(long); +void DoSTR(long); +void DoSTS(size); +void DoTEQ(void); +void DoTGE(void); +void DoTGT(void); +void DoTLE(void); +void DoTLT(void); +void DoTNE(void); +void DoTRP(void); +void DoXOR(size); +void DoZEQ(long); +void DoZER(size); +void DoZGE(long); +void DoZGT(long); +void DoZLE(long); +void DoZLT(long); +void DoZNE(long); +void DoZRE(long); +void DoZRF(size); +void DoZRL(long); + +#endif /* SWITCH_H_ */ diff --git a/util/int/tally.c b/util/int/tally.c index bad5fbbe3..f59562478 100644 --- a/util/int/tally.c +++ b/util/int/tally.c @@ -9,6 +9,7 @@ #include "global.h" #include "linfil.h" #include "alloc.h" +#include "whatever.h" struct line_tally { /* one for each line */ diff --git a/util/int/trap.c b/util/int/trap.c index dcbc42b99..829aa849d 100644 --- a/util/int/trap.c +++ b/util/int/trap.c @@ -18,6 +18,7 @@ #include "linfil.h" #include "rsb.h" #include "fra.h" +#include "whatever.h" extern jmp_buf trapbuf; /* from main.c */ diff --git a/util/int/warn.c b/util/int/warn.c index 973a0a8b2..656b1945d 100644 --- a/util/int/warn.c +++ b/util/int/warn.c @@ -94,7 +94,7 @@ PRIVATE long count_wrn(int nr) PRIVATE int latest_warning_printed; /* set if ... */ /*ARGSUSED*/ -void do_warn(int nr, int L, char *F) +void do_warn(int nr, int L, const char *F) { latest_warning_printed = 0; if (nr < WMSG) { diff --git a/util/int/whatever.h b/util/int/whatever.h new file mode 100644 index 000000000..9aa4b1831 --- /dev/null +++ b/util/int/whatever.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2019 ACK Project. + * See the copyright notice in the ACK home directory, + * in the file "Copyright". + * + * Created on: 2019-10-23 + * + */ +#ifndef WHATEVER_H_ +#define WHATEVER_H_ + +#include "global.h" /* ptr, size */ + +/* + * This header is for _whatever_ isn't in another header. + */ + +/* disassemble.c */ +void disassemble(void); + +/* do_misc.c */ +void putLIN(long); +void putFIL(ptr); + +/* do_proc.c */ +void call(long, int); + +/* init.c */ +void init(int , char **); + +/* m_ioctl.c */ +int do_ioctl(int, int, ptr); + +/* moncalls.c */ +void moncall(void); +int memfault(ptr, size); +void efault(int); +void einval(int); + +/* tally.c */ +void tally(void); +void out_tally(void); + +#endif /* WHATEVER_H_ */ diff --git a/util/led/debug.h b/util/led/debug.h index 979e0cec8..da1e1e972 100644 --- a/util/led/debug.h +++ b/util/led/debug.h @@ -7,6 +7,7 @@ #ifndef __DEBUG_H_INCLUDED__ #define __DEBUG_H_INCLUDED__ +#include "error.h" #ifdef NDEBUG @@ -15,13 +16,11 @@ #else extern int DEB; -#define debug(s, a1, a2, a3, a4) (DEB && printf(s, a1, a2, a3, a4)) +#define debug(s, a1, a2, a3, a4) (DEB && do_debug(s, a1, a2, a3, a4)) #endif extern int Verbose; #define verbose(s, a1, a2, a3, a4) (Verbose && do_verbose(s, a1, a2, a3, a4)) -extern void fatal(char* format, ...); - #endif /* __DEBUG_H_INCLUDED__ */ diff --git a/util/led/error.c b/util/led/error.c index 1d2be80b0..73125136a 100644 --- a/util/led/error.c +++ b/util/led/error.c @@ -60,6 +60,17 @@ void error(char *format, ...) va_end(ap); } +/* VARARGS1 */ +int do_debug(char *format, ...) +{ + /* printf() and return 1 */ + va_list ap; + va_start(ap, format); + vprintf(format, ap); + va_end(ap); + return 1; +} + /* VARARGS1 */ int do_verbose(char *format, ...) { diff --git a/util/led/error.h b/util/led/error.h index 8071a9f06..637b1c42c 100644 --- a/util/led/error.h +++ b/util/led/error.h @@ -13,6 +13,7 @@ void stop(void); void fatal(char *format, ...); void warning(char *format, ...); void error(char *format, ...); +int do_debug(char *format, ...); int do_verbose(char *format, ...); diff --git a/util/led/main.c b/util/led/main.c index 4fcb42900..1ba5d7fac 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -580,7 +580,7 @@ void addbase(struct outname *name) address((name->on_type & S_EXT) ? ALLOGCHR : ALLOLCHR, (ind_t)name->on_foff ), - name->on_type, name->on_valu, 0 + name->on_type, (unsigned long)name->on_valu, 0 ); } diff --git a/util/led/relocate.c b/util/led/relocate.c index 9f7df829d..a167645d0 100644 --- a/util/led/relocate.c +++ b/util/led/relocate.c @@ -416,7 +416,8 @@ static void put_mips_valu(char* addr, uint32_t value) /* The two bottom zero bits are implicit. */ if (value & 3) - fatal("invalid MIPS relocation value 0x%x", value); + fatal("invalid MIPS relocation value 0x%lx", + (unsigned long)value); value >>= 2; switch (opcode >> 26) @@ -560,7 +561,8 @@ void relocate(struct outhead *head, char* emit, struct outname names[], struct o * Pick up previous value at location to be relocated. */ valu = getvalu(emit + (relo->or_addr - off), relo->or_type); - debug("read relocation from 0x%08x type 0x%x value 0x%08x symbol %d\n", realaddress, relo->or_type, valu, relo->or_nami); + debug("read relocation from 0x%08lx type 0x%x value 0x%08lx symbol %u\n", + (unsigned long)realaddress, relo->or_type, valu, relo->or_nami); /* * Or_nami is an index in the name table of the considered module. @@ -595,7 +597,8 @@ void relocate(struct outhead *head, char* emit, struct outname names[], struct o /* * Now put the value back. */ - debug("written fixed up relocation to 0x%08x type 0x%x value 0x%08x\n", realaddress, relo->or_type, valu, 0); + debug("written fixed up relocation to 0x%08lx type 0x%x value 0x%08lx\n", + (unsigned long)realaddress, relo->or_type, valu, 0); putvalu(valu, emit + (relo->or_addr - off), relo->or_type); /* diff --git a/util/led/sym.c b/util/led/sym.c index e946a5a17..8320a5a4c 100644 --- a/util/led/sym.c +++ b/util/led/sym.c @@ -19,6 +19,7 @@ static char rcsid[] = "$Id$"; #include "error.h" #include "memory.h" #include "debug.h" +#include "save.h" #include "sym.h" /* @@ -66,7 +67,8 @@ struct outname *searchname(char *string, int hashval) register struct symbol *sym; symindex = hashtable[hashval]; - debug("looking for %s %d %ld:", string, hashval, hashtable[hashval], 0); + debug("looking for %s %d %z:", string, hashval, + (size_t)hashtable[hashval], 0); while (symindex != BADOFF) { sym = (struct symbol *)address(ALLOSYMB, symindex); name = (struct outname *)address(ALLOGLOB, sym->sy_name); @@ -76,7 +78,8 @@ struct outname *searchname(char *string, int hashval) while (*rcp == *namestring++) if (*rcp++ == '\0') { debug("found %x, %x, %lx\n", - name->on_type, name->on_desc, name->on_valu, 0); + name->on_type, name->on_desc, + (unsigned long)name->on_valu, 0); return name; } symindex = sym->sy_next; @@ -99,12 +102,11 @@ void entername(struct outname* name, int hashval) ind_t namindex; register struct symbol *sym; struct outname *newname; - extern ind_t savechar(); debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc); savindex = savechar(ALLOGCHR, (ind_t)name->on_foff); symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol)); - debug("; %ld\n", symindex, 0, 0, 0); + debug("; %z\n", (size_t)symindex, 0, 0, 0); namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname)); if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF) fatal("symbol table overflow"); @@ -137,7 +139,7 @@ int hash(register char* p) register unsigned short h = 0; register int c; - while (c = *p++) { + while ((c = *p++) != '\0') { h <<= 2; h += c; } diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index c648d276c..0c0e16514 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -607,7 +607,7 @@ coercdeflist_el {startline = lineno; tokpatlen=0; inithall();} STACK allocates generates YIELDS tokeninstance { checkhall(); - n_coerc(0,0,$4,$5,(struct varinfo *) 0,$7); + n_coerc(0,0,$4,$5,NULL,&$7); freevi($4); freevi($5); } @@ -623,7 +623,7 @@ coercdeflist_el optexpr allocates generates yields { tokpatro[0] = 0; checkhall(); - n_coerc($3,$5,$6,$7,$8); + n_coerc($3,$5,$6,$7,$8,NULL); freevi($6); freevi($7); cursetno = -1; diff --git a/util/ncgg/coerc.c b/util/ncgg/coerc.c index 23b711b22..50265c59e 100644 --- a/util/ncgg/coerc.c +++ b/util/ncgg/coerc.c @@ -208,7 +208,7 @@ set_t unstackset; /*VARARGS5*/ -void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in) +void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_p inp) { register c3_p c3p; register int i; @@ -236,7 +236,7 @@ void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct vari { NEW(rp, struct varinfo); rp->vi_next = 0; - rp->vi_int[0] = in.in_index; + rp->vi_int[0] = inp->in_index; } if (nallreg > 1) error("More than 1 register may not be allocated"); @@ -250,7 +250,7 @@ void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct vari dopattern(ti == 0, VI_NULL, al, ge, rp, VI_NULL); if (ti == 0) for (i = 0; i < SETSIZE; i++) - unstackset.set_val[i] |= in.in_set[i]; + unstackset.set_val[i] |= inp->in_set[i]; freevi(rp); } diff --git a/util/ncgg/coerc.h b/util/ncgg/coerc.h index b34338e2f..e45c75754 100644 --- a/util/ncgg/coerc.h +++ b/util/ncgg/coerc.h @@ -23,8 +23,7 @@ struct varinfo *gen_preturn(void); struct varinfo *gen_tlab(int n); void n_stack(int s, int e, int p, struct varinfo *vi); void checkstacking(register short *sp); -/* cgg.y is buggy!!! it has one less parameter.. */ -/*void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in);*/ +void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_p inp); void checkunstacking(int setno); #endif /* COERC_H_ */ diff --git a/util/ncgg/cvtkeywords b/util/ncgg/cvtkeywords index 54682d600..46472ecbc 100755 --- a/util/ncgg/cvtkeywords +++ b/util/ncgg/cvtkeywords @@ -11,7 +11,7 @@ g/^#/d .r tokendefs a -enterkeyw() { +void enterkeyw(void) { register symbol *sy_p; . diff --git a/util/ncgg/extern.h b/util/ncgg/extern.h index bcff46002..7c999f088 100644 --- a/util/ncgg/extern.h +++ b/util/ncgg/extern.h @@ -38,8 +38,23 @@ extern int maxtokensize; extern int nprocargs, maxprocargs; extern int use_tes; -extern void error(const char* s, ...); +/* genenerated files */ +extern void enterkeyw(void); +extern int yyparse(void); + +/* emlookup.c */ +extern void initemhash(void); + +/* error.c */ extern void fatal(const char* s, ...); +extern void error(const char* s, ...); extern int tabovf(char *string); -extern int strlookup(char *str); + +/* output.c */ extern void errorexit(void); +extern void initio(void); +extern void finishio(void); +extern void statistics(void); + +/* strlookup.c */ +extern int strlookup(char *str); diff --git a/util/ncgg/iocc.c b/util/ncgg/iocc.c index 96ad56f6f..cbce9149d 100644 --- a/util/ncgg/iocc.c +++ b/util/ncgg/iocc.c @@ -174,11 +174,12 @@ iocc_t descr_iocc(char *ident) default: assert(0); case TYPINT: - if (tp->tk_att[i].ta_type != -1) + if (tp->tk_att[i].ta_type != -1) { if (tp->tk_att[i].ta_type == -2) arexp[i] = iextoaddr(arexp[i]); else typerr++; + } break; case TYPBOOL: typerr++; diff --git a/util/ncgg/main.c b/util/ncgg/main.c index b1a7cac0b..46ddeb051 100644 --- a/util/ncgg/main.c +++ b/util/ncgg/main.c @@ -12,16 +12,10 @@ static char rcsid[] = "$Id$"; #include "hall.h" #include "expr.h" #include "extern.h" +#include "lookup.h" char *filename; -extern void enterkeyw(void); -extern void initio(void); -extern void initemhash(void); -extern void finishio(void); -extern void statistics(void); -extern int yyparse(void); - int main(int argc, char **argv) { extern int nerrors; diff --git a/util/opt/mktab.y b/util/opt/mktab.y index d2e39d5f2..54588f06a 100644 --- a/util/opt/mktab.y +++ b/util/opt/mktab.y @@ -349,7 +349,7 @@ void printnodes(void) printf("};\n\nshort lastind = %d;\n\nexpr_t enodes[] = {\n",prevind); for (p=nodes;pex_operator,p->ex_lnode,p->ex_rnode); + (int)(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); diff --git a/util/topgen/topgen.g b/util/topgen/topgen.g index 1d0284d63..0dc923929 100644 --- a/util/topgen/topgen.g +++ b/util/topgen/topgen.g @@ -41,14 +41,14 @@ extern void error(char *s, char* s1); optim_description { struct symtab *p; } : - SPACE* parameter_line* + SPACE* parameters { p = findident("MAXOP",LOOKING,&deftable); if (p == 0) maxoperand = 2; /* default */ else maxoperand = p->s_num; } separator SPACE* mode_definitions - separator SPACE* patterns - separator + separator SPACE* patterns + separator { register int c; fprintf(genc, linedir, lineno, inpfile); while ((c = getc(input)) != EOF) { @@ -57,17 +57,25 @@ optim_description } ; +parameters : + [ parameter_line | declaration_block ]* +; + parameter_line - { struct symtab *p;} : + { struct symtab *p; + int lin; + } : identifier { p = findident(idbuf,ENTERING,&deftable);} SPACE + { lin = lineno;} value { p->s_num = atoi(buf);} /* This action in fact only needed for MAXOP */ LINE_TERMINATOR SPACE* - { fprintf(genh,"#define %s %s\n",p->s_name,buf);} + { fprintf(genh, linedir, lin, inpfile); + fprintf(genh,"#define %s %s\n",p->s_name,buf);} ; value @@ -89,9 +97,30 @@ value { *p1 = '\0';} ; +declaration_block : + OPEN_BRACKET + { fprintf(genh, linedir, lineno, inpfile);} + [ + [ LINE_TERMINATOR + | OPERAND_SEPARATOR + | PATTERN_SEPARATOR + | INSTRUCTION_SEPARATOR + | SPACE + | LETTER + | DIGIT + | OTHER + | '%' + ] + { putc(dot.t_attrib, genh);} + ]* + CLOSE_BRACKET + SPACE* + { putc('\n', genh);} +; + mode_definitions { int lin; } : - { fputs("tok_chk(varno) {\n\tint r;\n", genc); + { fputs("int tok_chk(int varno) {\n\tint r;\n", genc); fputs("\tchar *VAL;\n\n",genc); fputs("\tVAL = var[varno].value;\n",genc); fputs("\tswitch(varno) {\n",genc);