Next batch

This commit is contained in:
Manoel Trapier
2013-03-14 14:54:26 +01:00
committed by Manoël Trapier
parent bd3e7b87e6
commit 452127650a
62 changed files with 944 additions and 1307 deletions

View File

@@ -224,7 +224,7 @@ void iconvert(char* buf, char* str, char* fmt)
int last, i ; int last, i ;
uint32_t value ; uint32_t value ;
ni=buf ; no=str ; nf=fmt ; ni=buf ; no=str ; nf=fmt ;
while ( last = *nf++ ) { while (( last = *nf++ )) {
last -= '0' ; last -= '0' ;
if ( last<1 || last >9 ) fatal("illegal out.h format string\n"); if ( last<1 || last >9 ) fatal("illegal out.h format string\n");
value=0 ; value=0 ;

View File

@@ -35,8 +35,10 @@ long s_base[S_MAX]; /* for specially encoded bases */
char *filename; char *filename;
int narg; int narg;
main(argc, argv) void process(int fd);
char **argv; void do_file(int fd);
int main(int argc, char *argv[])
{ {
if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) { if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) {
@@ -96,10 +98,9 @@ char **argv;
exit(0); exit(0);
} }
extern int rd_unsigned2(); int rd_unsigned2(int fd);
process(fd) void process(int fd)
int fd;
{ {
unsigned int magic; unsigned int magic;
long nextpos; long nextpos;
@@ -134,8 +135,7 @@ process(fd)
} }
} }
do_file(fd) void do_file(int fd)
int fd;
{ {
struct outname *nbufp = NULL; struct outname *nbufp = NULL;
struct outname nbuf; struct outname nbuf;
@@ -295,8 +295,7 @@ do_file(fd)
free((char *)cbufp); free((char *)cbufp);
} }
compare(p1, p2) int compare(struct outname *p1, struct outname *p2)
struct outname *p1, *p2;
{ {
int i; int i;
@@ -330,7 +329,7 @@ struct outname *p1, *p2;
return(0); return(0);
} }
rd_fatal() void rd_fatal()
{ {
fprintf(stderr,"read error on %s\n", filename); fprintf(stderr,"read error on %s\n", filename);
read_error = 1; read_error = 1;

View File

@@ -12,13 +12,21 @@ static char rcsid[] = "$Id$";
#define OK 0 /* Return value of gethead if Orl Korekt. */ #define OK 0 /* Return value of gethead if Orl Korekt. */
#define BMASK 0xFF /* To extract least significant 8 bits from an int. */ #define BMASK 0xFF /* To extract least significant 8 bits from an int. */
void show(struct outhead *headp);
void showflags(unsigned int flagword);
void showsect();
void showname(struct outname *namep);
void error(char *format, ...);
void showrelo();
/* ARGSUSED */ /* ARGSUSED */
main(argc, argv) #define prog argv[0]
int argc;
char *argv[]; int main(int argc, char *argv[])
# define prog argv[0]
{ {
register char **arg = argv; char **arg = argv;
struct outhead header; struct outhead header;
while (*++arg) { while (*++arg) {
@@ -42,13 +50,12 @@ main(argc, argv)
* NB. The header has already been read and is in the struct outhead `headp' * NB. The header has already been read and is in the struct outhead `headp'
* points to. * points to.
*/ */
show(headp) void show(struct outhead *headp)
register struct outhead *headp;
{ {
register int i; int i;
register struct outname *np; struct outname *np;
register struct outname *name; /* Dynamically allocated name-array. */ struct outname *name; /* Dynamically allocated name-array. */
register char *string;/* Base of string area. */ char *string;/* Base of string area. */
extern char *myalloc(); extern char *myalloc();
printf("Version %d\n", headp->oh_stamp); printf("Version %d\n", headp->oh_stamp);
@@ -98,8 +105,7 @@ show(headp)
/* /*
* Show flags from header. * Show flags from header.
*/ */
showflags(flagword) void showflags(unsigned int flagword)
unsigned flagword;
{ {
if (flagword & HF_LINK) printf("unresolved references left\n"); if (flagword & HF_LINK) printf("unresolved references left\n");
} }
@@ -107,7 +113,7 @@ showflags(flagword)
/* /*
* Show a section. * Show a section.
*/ */
showsect() void showsect()
{ {
struct outsect section; struct outsect section;
@@ -122,7 +128,7 @@ showsect()
/* /*
* Show a relocation record. * Show a relocation record.
*/ */
showrelo() void showrelo()
{ {
struct outrelo relrec; struct outrelo relrec;
@@ -152,8 +158,7 @@ showrelo()
/* /*
* Show the name in the struct `namep' points to. * Show the name in the struct `namep' points to.
*/ */
showname(namep) void showname(struct outname *namep)
struct outname *namep;
{ {
if (namep->on_mptr) if (namep->on_mptr)
printf("\t%s\n", namep->on_mptr); printf("\t%s\n", namep->on_mptr);
@@ -200,9 +205,7 @@ showname(namep)
/* /*
* Core allocation via malloc() but fatal if no core. * Core allocation via malloc() but fatal if no core.
*/ */
char * char *myalloc(unsigned int u)
myalloc(u)
unsigned int u;
{ {
register char *rcp; register char *rcp;
@@ -215,14 +218,16 @@ myalloc(u)
} }
/* VARARGS1 */ /* VARARGS1 */
error(s, a1, a2, a3, a4) void error(char *format, ...)
char *s;
{ {
va_list ap;
fflush(stdout); fflush(stdout);
fprintf(stderr, s, a1, a2, a3, a4); va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
} }
rd_fatal() void rd_fatal()
{ {
error("Error in reading the object file\n"); error("Error in reading the object file\n");
exit(1); exit(1);

View File

@@ -23,8 +23,7 @@ FILE *tf;
struct outhead buf; struct outhead buf;
int readerror, writeerror; int readerror, writeerror;
main(argc, argv) int main(int argc, char *argv[])
char **argv;
{ {
int status; int status;
@@ -40,8 +39,7 @@ char **argv;
exit(status); exit(status);
} }
strip(name) int strip(char *name)
char *name;
{ {
long size; long size;
int fw; int fw;
@@ -113,12 +111,9 @@ char *name;
return(0); return(0);
} }
copy(fnam, tnam, size, fr, fw) int copy(char *fnam, char *tnam, long size, int fr, int fw)
char *fnam;
char *tnam;
long size;
{ {
register s, n; int s, n;
char lbuf[512]; char lbuf[512];
while(size != (long)0) { while(size != (long)0) {
@@ -140,12 +135,12 @@ long size;
return(0); return(0);
} }
rd_fatal() void rd_fatal()
{ {
readerror = 1; readerror = 1;
} }
wr_fatal() void wr_fatal()
{ {
writeerror = 1; writeerror = 1;
} }

View File

@@ -4,6 +4,9 @@
optimizer itself one day ... optimizer itself one day ...
*/ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <em_path.h> #include <em_path.h>
#include <signal.h> #include <signal.h>
#include <system.h> #include <system.h>
@@ -42,10 +45,6 @@ static char *phnames[] = {
#define MAXARGS 1024 /* mar # of args */ #define MAXARGS 1024 /* mar # of args */
#define NTEMPS 4 /* # of temporary files; not tunable */ #define NTEMPS 4 /* # of temporary files; not tunable */
extern char *mktemp();
extern char *strcpy(), *strcat();
extern char *strrchr();
static char ddump[128] = TMP_DIR; /* data label dump file */ static char ddump[128] = TMP_DIR; /* data label dump file */
static char pdump[128] = TMP_DIR; /* procedure name dump file */ static char pdump[128] = TMP_DIR; /* procedure name dump file */
static char tmpbufs[NTEMPS*2][128] = { static char tmpbufs[NTEMPS*2][128] = {
@@ -82,8 +81,7 @@ static char *prog_name;
static int v_flag; static int v_flag;
static void static void cleanup()
cleanup()
{ {
/* Cleanup temporaries */ /* Cleanup temporaries */
@@ -100,10 +98,7 @@ cleanup()
} }
/*VARARGS1*/ /*VARARGS1*/
static void static void fatal(char *s, char *s2)
fatal(s, s2)
char *s;
char *s2;
{ {
/* A fatal error occurred; exit gracefully */ /* A fatal error occurred; exit gracefully */
@@ -115,28 +110,23 @@ fatal(s, s2)
/*NOTREACHED*/ /*NOTREACHED*/
} }
static void static void add_file(char *s)
add_file(s)
char *s;
{ {
/* Add an input file to the list */ /* Add an input file to the list */
if (nfiles >= MAXARGS) fatal("too many files"); if (nfiles >= MAXARGS) fatal("too many files", NULL);
phargs[nfiles++] = s; phargs[nfiles++] = s;
} }
static void static void add_uphase(int p)
add_uphase(p)
int p;
{ {
/* Add an optimizer phase to the list of phases to run */ /* Add an optimizer phase to the list of phases to run */
if (nuphases >= MAXUPHASES) fatal("too many phases"); if (nuphases >= MAXUPHASES) fatal("too many phases", NULL);
uphases[nuphases++] = p; uphases[nuphases++] = p;
} }
static void static void catch()
catch()
{ {
/* Catch interrupts and exit gracefully */ /* Catch interrupts and exit gracefully */
@@ -144,8 +134,7 @@ catch()
sys_stop(S_EXIT); sys_stop(S_EXIT);
} }
static void static void old_infiles()
old_infiles()
{ {
/* Remove old input files unless we have to keep them around. */ /* Remove old input files unless we have to keep them around. */
@@ -156,8 +145,7 @@ old_infiles()
for (i = 1; i <= NTEMPS; i++) (void) unlink(phargs[i]); for (i = 1; i <= NTEMPS; i++) (void) unlink(phargs[i]);
} }
static void static void get_infiles()
get_infiles()
{ {
/* Make output temps from previous phase input temps of next phase. */ /* Make output temps from previous phase input temps of next phase. */
@@ -170,8 +158,7 @@ get_infiles()
} }
} }
static void static void new_outfiles()
new_outfiles()
{ {
static int tmpindex = 0; static int tmpindex = 0;
static int Bindex = 0; static int Bindex = 0;
@@ -197,9 +184,7 @@ new_outfiles()
} }
} }
static void static void run_phase(int phase)
run_phase(phase)
int phase;
{ {
/* Run one phase of the global optimizer; special cases are /* Run one phase of the global optimizer; special cases are
IC and CA. IC and CA.
@@ -250,7 +235,7 @@ run_phase(phase)
break; break;
} }
if ((pid = fork()) < 0) { if ((pid = fork()) < 0) {
fatal("Could not fork"); fatal("Could not fork", NULL);
} }
else if (pid == 0) { else if (pid == 0) {
if (v_flag) { if (v_flag) {
@@ -278,18 +263,16 @@ run_phase(phase)
} }
} }
main(argc, argv) int main(int argc, char *argv[])
int argc;
char *argv[];
{ {
register int i = 0; int i = 0;
if (signal(SIGHUP, catch) == SIG_IGN) (void) signal(SIGHUP, SIG_IGN); if (signal(SIGHUP, catch) == SIG_IGN) (void) signal(SIGHUP, SIG_IGN);
if (signal(SIGQUIT, catch) == SIG_IGN) (void) signal(SIGQUIT, SIG_IGN); if (signal(SIGQUIT, catch) == SIG_IGN) (void) signal(SIGQUIT, SIG_IGN);
if (signal(SIGINT, catch) == SIG_IGN) (void) signal(SIGINT, SIG_IGN); if (signal(SIGINT, catch) == SIG_IGN) (void) signal(SIGINT, SIG_IGN);
prog_name = argv[0]; prog_name = argv[0];
phase_args = &argv[1]; phase_args = &argv[1];
while (--argc > 0) { while (--argc > 0) {
argv++; argv++;
if (argv[0][0] == '-') { if (argv[0][0] == '-') {
switch(argv[0][1]) { switch(argv[0][1]) {
@@ -386,7 +369,7 @@ main(argc, argv)
} }
if (! opt_dir) { if (! opt_dir) {
fatal("no correct -P flag given"); fatal("no correct -P flag given", NULL);
} }
if (keeptemps) { if (keeptemps) {
@@ -418,4 +401,5 @@ main(argc, argv)
cleanup(); cleanup();
sys_stop(S_END); sys_stop(S_END);
/*NOTREACHED*/ /*NOTREACHED*/
return 0;
} }

View File

@@ -6,6 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
/* MAKE ITEMS TABLE /* MAKE ITEMS TABLE
* *
@@ -22,8 +23,9 @@
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
convert(mnemfile,itemfile) void error(char *s);
FILE *mnemfile, *itemfile;
void convert(FILE *mnemfile, FILE *itemfile)
{ {
char mnem1[20], mnem2[20],def[20],itemtype[20]; char mnem1[20], mnem2[20],def[20],itemtype[20];
int newcl,opc,index; int newcl,opc,index;
@@ -57,17 +59,14 @@ convert(mnemfile,itemfile)
error(s) void error(char *s)
char *s;
{ {
fprintf(stderr,"%s\n",s); fprintf(stderr,"%s\n",s);
exit(-1); exit(-1);
} }
main(argc,argv) int main(int argc, char *argv[])
int argc;
char *argv[];
{ {
FILE *f1,*f2; FILE *f1,*f2;

View File

@@ -35,6 +35,8 @@
#define oldrabx(x) oldstruct(bext_ra,x) #define oldrabx(x) oldstruct(bext_ra,x)
#define oldralpx(x) oldstruct(lpext_ra,x) #define oldralpx(x) oldstruct(lpext_ra,x)
void stat_regusage(alloc_p list);
short alloc_id; short alloc_id;
static item_p items[NRITEMTYPES]; static item_p items[NRITEMTYPES];
int nrinstrs; int nrinstrs;
@@ -100,10 +102,11 @@ void get_otab(FILE *f, cond_p tab[NRREGTYPES])
static void ra_machinit(FILE *f) static int ra_machinit(void *param)
{ {
/* Read target machine dependent information for this phase */ /* Read target machine dependent information for this phase */
char s[100]; char s[100];
FILE *f = (FILE *)param;
for (;;) { for (;;) {
while(getc(f) != '\n'); while(getc(f) != '\n');
@@ -127,6 +130,8 @@ static void ra_machinit(FILE *f)
oglobaltab = getcondtab(f); oglobaltab = getcondtab(f);
oproctab = getcondtab(f); oproctab = getcondtab(f);
regsav_cost = getcondtab(f); regsav_cost = getcondtab(f);
return 0;
} }
@@ -171,10 +176,10 @@ static void ra_extproc(proc_p p)
static void ra_cleanproc(proc_p p) static int ra_cleanproc(void *param)
{ {
/* Allocate the extended data structures for procedure p */ /* Allocate the extended data structures for procedure p */
proc_p p = (proc_p)param;
loop_p lp; loop_p lp;
Lindex pi; Lindex pi;
bblock_p b; bblock_p b;
@@ -187,6 +192,8 @@ static void ra_cleanproc(proc_p p)
for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) { for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) {
oldrabx(b->b_extend); oldrabx(b->b_extend);
} }
return 0;
} }
@@ -325,20 +332,22 @@ static void cleanitems(item_p list)
} }
void ra_initialize() int ra_initialize(void *dummy)
{ {
init_replacements(ps,ws); init_replacements(ps,ws);
return 0;
} }
void ra_optimize(proc_p p) int ra_optimize(void *param)
{ {
proc_p p = (proc_p)param;
item_p itemlist; item_p itemlist;
alloc_p alloclist,packed,unpacked; alloc_p alloclist,packed,unpacked;
offset locls; offset locls;
bool time_opt = (time_space_ratio == 100); bool time_opt = (time_space_ratio == 100);
if (IS_ENTERED_WITH_GTO(p)) return; if (IS_ENTERED_WITH_GTO(p)) return 0;
ra_extproc(p); ra_extproc(p);
loop_blocks(p); loop_blocks(p);
alloc_id =0; alloc_id =0;
@@ -369,8 +378,9 @@ void ra_optimize(proc_p p)
clean_allocs(unpacked); clean_allocs(unpacked);
clean_allocs(packed); clean_allocs(packed);
cleanitems(itemlist); cleanitems(itemlist);
oldmap(instrmap,nrinstrs-1); oldmap((short **)instrmap,nrinstrs-1);
ra_cleanproc(p); ra_cleanproc(p);
return 0;
} }

View File

@@ -27,10 +27,7 @@
#include "ra_allocl.h" #include "ra_allocl.h"
#include "ra_interv.h" #include "ra_interv.h"
STATIC count_usage(p,item,nrloops,sloopcnt,dloopcnt) static void count_usage(proc_p p, item_p item, short nrloops, short sloopcnt[], short dloopcnt[])
proc_p p;
item_p item;
short nrloops, sloopcnt[], dloopcnt[];
{ {
/* Determine how many times the item is used in every loop. /* Determine how many times the item is used in every loop.
* We maintain a 'static' count and a 'dynamic' count. The dynamic * We maintain a 'static' count and a 'dynamic' count. The dynamic
@@ -67,14 +64,8 @@ STATIC count_usage(p,item,nrloops,sloopcnt,dloopcnt)
STATIC alloc_p cons_alloc(item,timespan,stat_usecount, static alloc_p cons_alloc(item_p item, interv_p timespan, short stat_usecount,
dyn_usecount,inits,wholeproc,isloop,iswholeproc) short dyn_usecount, lset inits, alloc_p wholeproc, bool isloop, bool iswholeproc)
item_p item;
interv_p timespan;
short stat_usecount,dyn_usecount;
lset inits;
alloc_p wholeproc;
bool isloop,iswholeproc;
{ {
alloc_p x; alloc_p x;
@@ -92,22 +83,16 @@ STATIC alloc_p cons_alloc(item,timespan,stat_usecount,
} }
STATIC insert_alloc(alloc,list_p) static void insert_alloc(alloc_p alloc, alloc_p *list_p)
alloc_p alloc, *list_p;
{ {
alloc->al_next = *list_p; alloc->al_next = *list_p;
*list_p = alloc; *list_p = alloc;
} }
#define MUST_INIT(i,b) (i->it_type!=LOCALVAR ||contains(b->B_BEGIN,i->it_lives)) #define MUST_INIT(i,b) (i->it_type!=LOCALVAR ||contains(b->B_BEGIN,i->it_lives))
#define MUST_UPDATE(i,b) (i->it_type==LOCALVAR &&contains(b->B_BEGIN,i->it_lives)) #define MUST_UPDATE(i,b) (i->it_type==LOCALVAR &&contains(b->B_BEGIN,i->it_lives))
STATIC lset loop_inits(lp,item,header) static lset loop_inits(loop_p lp, item_p item, bblock_p header)
loop_p lp;
item_p item;
bblock_p header;
{ {
/* Build the set of entry points to loop lp where item /* Build the set of entry points to loop lp where item
* must be initialized * must be initialized
@@ -124,8 +109,7 @@ STATIC lset loop_inits(lp,item,header)
#define IN_LOOP(b) (Lnrelems(b->b_loops) > 0) #define IN_LOOP(b) (Lnrelems(b->b_loops) > 0)
STATIC bblock_p init_point(item) static bblock_p init_point(item_p item)
item_p item;
{ {
/* Find the most appropriate point to initialize any register /* Find the most appropriate point to initialize any register
* containing the item. We want to do the initialization as * containing the item. We want to do the initialization as
@@ -157,10 +141,7 @@ STATIC bblock_p init_point(item)
} }
STATIC add_blocks(b,s,span) static void add_blocks(bblock_p b, cset *s, interv_p *span)
bblock_p b;
cset *s;
interv_p *span;
{ {
Lindex pi; Lindex pi;
@@ -176,10 +157,7 @@ STATIC add_blocks(b,s,span)
STATIC whole_lifetime(item,ini_out,span_out) static void whole_lifetime(item_p item, bblock_p *ini_out, interv_p *span_out)
item_p item;
bblock_p *ini_out;
interv_p *span_out;
{ {
/* Find the initialization point and the time_span of the item, if /* Find the initialization point and the time_span of the item, if
* we put the item in a register during all its uses. * we put the item in a register during all its uses.
@@ -205,13 +183,7 @@ STATIC whole_lifetime(item,ini_out,span_out)
*span_out = span; *span_out = span;
} }
static lset proc_inits(proc_p p, item_p item, bblock_p ini)
STATIC lset proc_inits(p,item,ini)
proc_p p;
item_p item;
bblock_p ini;
{ {
lset s = Lempty_set(); lset s = Lempty_set();
@@ -223,9 +195,7 @@ STATIC lset proc_inits(p,item,ini)
} }
STATIC bool updates_needed(lp,item) static bool updates_needed(loop_p lp, item_p item)
loop_p lp;
item_p item;
{ {
/* See if the value of item is live after the loop has /* See if the value of item is live after the loop has
* been exited, i.e. must the item be updated after the loop? * been exited, i.e. must the item be updated after the loop?
@@ -250,9 +220,7 @@ STATIC bool updates_needed(lp,item)
STATIC short countuses(usage,b) static short countuses(lset usage, bblock_p b)
lset usage;
bblock_p b;
{ {
short cnt = 0; short cnt = 0;
Lindex ti; Lindex ti;
@@ -267,14 +235,9 @@ STATIC short countuses(usage,b)
STATIC allocs_of_item(p,item,loops,sloopcnt,dloopcnt,alloc_list_p) static void allocs_of_item(proc_p p, item_p item, lset loops, short *sloopcnt, short *dloopcnt, alloc_p *alloc_list_p)
proc_p p;
item_p item;
lset loops;
short *sloopcnt,*dloopcnt; /* dynamic arrays */
alloc_p *alloc_list_p;
{ {
register Lindex li; Lindex li;
loop_p lp; loop_p lp;
bblock_p header,ini; bblock_p header,ini;
short susecount,dusecount; short susecount,dusecount;
@@ -328,13 +291,10 @@ STATIC allocs_of_item(p,item,loops,sloopcnt,dloopcnt,alloc_list_p)
alloc_p build_alloc_list(p,nrloops,itemlist) alloc_p build_alloc_list(proc_p p, short nrloops, item_p itemlist)
proc_p p;
short nrloops;
item_p itemlist;
{ {
short *sloopcnt,*dloopcnt; /* dynamic arrays */ short *sloopcnt,*dloopcnt; /* dynamic arrays */
register item_p item; item_p item;
alloc_p alloc_list = (alloc_p) 0; alloc_p alloc_list = (alloc_p) 0;
sloopcnt = (short *) newtable(nrloops); sloopcnt = (short *) newtable(nrloops);
@@ -344,15 +304,14 @@ alloc_p build_alloc_list(p,nrloops,itemlist)
allocs_of_item(p,item,p->p_loops,sloopcnt,dloopcnt, allocs_of_item(p,item,p->p_loops,sloopcnt,dloopcnt,
&alloc_list); &alloc_list);
} }
oldtable(sloopcnt,nrloops); oldtable((short **)sloopcnt,nrloops);
oldtable(dloopcnt,nrloops); oldtable((short **)dloopcnt,nrloops);
return alloc_list; return alloc_list;
} }
build_rivals_graph(alloclist) void build_rivals_graph(alloc_p alloclist)
alloc_p alloclist;
{ {
/* See which allocations in the list are rivals of each other, /* See which allocations in the list are rivals of each other,
* i.e. there is some point of time, falling in both * i.e. there is some point of time, falling in both
@@ -364,7 +323,7 @@ build_rivals_graph(alloclist)
* allocation. * allocation.
*/ */
register alloc_p alloc,x; alloc_p alloc,x;
for (alloc = alloclist; alloc != (alloc_p) 0; alloc = alloc->al_next) { for (alloc = alloclist; alloc != (alloc_p) 0; alloc = alloc->al_next) {
alloc->al_rivals = Cempty_set(alloc_id); alloc->al_rivals = Cempty_set(alloc_id);

View File

@@ -9,13 +9,13 @@
* R A _ A L L O C L I S T . H * R A _ A L L O C L I S T . H
*/ */
extern alloc_p build_alloc_list(); /* (proc_p p; short nrloops;*/ alloc_p build_alloc_list(proc_p p, short nrloops, item_p itemlist);
/* item_p itemlist) /* item_p itemlist)
* Build a list of possible allocations * Build a list of possible allocations
* for procedure p. An allocation * for procedure p. An allocation
* essentially is a pair (item,timespan) * 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 /* See which allocations in the list are
* rivals of each other, i.e. there is * rivals of each other, i.e. there is
* some point of time, falling in both * some point of time, falling in both

View File

@@ -18,8 +18,7 @@
#include "ra.h" #include "ra.h"
#include "ra_interv.h" #include "ra_interv.h"
interv_p cons_interval(t_start,t_stop) interv_p cons_interval(short t_start, short t_stop)
short t_start,t_stop;
{ {
interv_p x; interv_p x;
@@ -31,9 +30,7 @@ interv_p cons_interval(t_start,t_stop)
add_interval(t1,t2,list) void add_interval(short t1, short t2, interv_p *list)
short t1,t2;
interv_p *list;
{ {
/* Add interval (t1,t2) to the list of intervals (which is /* Add interval (t1,t2) to the list of intervals (which is
* an in-out parameter!). The list is sorted in 'chronological' * an in-out parameter!). The list is sorted in 'chronological'
@@ -41,7 +38,7 @@ add_interval(t1,t2,list)
* putting adjacent intervals in one interval. * putting adjacent intervals in one interval.
*/ */
register interv_p x1, x2, *q; interv_p x1, x2, *q;
int adjacent = 0; int adjacent = 0;
interv_p x; interv_p x;
@@ -82,16 +79,15 @@ add_interval(t1,t2,list)
interv_p loop_lifetime(lp) interv_p loop_lifetime(loop_p lp)
loop_p lp;
{ {
/* Determine the timespan of the loop, expressed as a list /* Determine the timespan of the loop, expressed as a list
* of intervals. * of intervals.
*/ */
interv_p lt = 0; interv_p lt = 0;
register bblock_p b; bblock_p b;
register Lindex bi; Lindex bi;
for (bi = Lfirst(lp->LP_BLOCKS); bi != (Lindex) 0; for (bi = Lfirst(lp->LP_BLOCKS); bi != (Lindex) 0;
bi = Lnext(bi,lp->LP_BLOCKS)) { bi = Lnext(bi,lp->LP_BLOCKS)) {
@@ -102,12 +98,11 @@ interv_p loop_lifetime(lp)
} }
interv_p proc_lifetime(p) interv_p proc_lifetime(proc_p p)
proc_p p;
{ {
/* Determine the lifetime of an entire procedure */ /* Determine the lifetime of an entire procedure */
register bblock_p b; bblock_p b;
for (b = p->p_start; b->b_next != (bblock_p) 0; b = b->b_next) ; for (b = p->p_start; b->b_next != (bblock_p) 0; b = b->b_next) ;
return cons_interval(0,b->B_END); return cons_interval(0,b->B_END);
@@ -115,8 +110,7 @@ interv_p proc_lifetime(p)
STATIC set_min_max(iv1,iv2) static void set_min_max(interv_p *iv1, interv_p *iv2)
interv_p *iv1,*iv2;
{ {
/* Auxiliary routine of intersect */ /* Auxiliary routine of intersect */
@@ -133,8 +127,7 @@ STATIC set_min_max(iv1,iv2)
interv_p intersect(list1,list2) interv_p intersect(interv_p list1, interv_p list2)
interv_p list1,list2;
{ {
/* Intersect two lifetimes, each denoted by a list of intervals. /* Intersect two lifetimes, each denoted by a list of intervals.
* We maintain two pointers, pmin and pmax, pointing to the * We maintain two pointers, pmin and pmax, pointing to the
@@ -177,8 +170,7 @@ interv_p intersect(list1,list2)
bool not_disjoint(list1,list2) bool not_disjoint(interv_p list1, interv_p list2)
interv_p list1,list2;
{ {
/* See if list1 and list2 do overlap somewhere */ /* See if list1 and list2 do overlap somewhere */
@@ -200,11 +192,9 @@ bool not_disjoint(list1,list2)
bool contains(t,timespan) bool contains(short t, interv_p timespan)
short t;
interv_p timespan;
{ {
register interv_p iv; interv_p iv;
for (iv = timespan; iv != (interv_p) 0; iv = iv->i_next) { for (iv = timespan; iv != (interv_p) 0; iv = iv->i_next) {
if (t <= iv->i_stop) return (t >= iv->i_start); if (t <= iv->i_stop) return (t >= iv->i_start);
@@ -214,8 +204,7 @@ bool contains(t,timespan)
interv_p copy_timespan(list) interv_p copy_timespan(interv_p list)
interv_p list;
{ {
/* copy the time span */ /* copy the time span */

View File

@@ -10,31 +10,31 @@
*/ */
extern interv_p cons_interval();/* (short t_start,t_stop) interv_p cons_interval(short t_start, short t_stop);
* construct an interval /* 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 /* Add interval (t1,t2) to the list of
* intervals (which is an in-out parameter!). * 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, /* Determine the timespan of the loop,
* expressed as a list of intervals. * 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, /* Determine the timespan of a procedure,
* expressed as an interval. * 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 /* Intersect two lifetimes, each denoted
* by a list of intervals. * 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. /* 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. /* 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. /* Make a copy of the timespan.
*/ */

View File

@@ -33,8 +33,7 @@
/* prevent small constants from being put in a register */ /* prevent small constants from being put in a register */
clean_tab(items) static void clean_tab(item_p items[])
item_p items[];
{ {
int t; int t;
@@ -46,8 +45,7 @@ clean_tab(items)
short item_type(l) short item_type(line_p l)
line_p l;
{ {
int instr = INSTR(l); int instr = INSTR(l);
int t; int t;
@@ -60,18 +58,15 @@ short item_type(l)
bool is_item(l) bool is_item(line_p l)
line_p l;
{ {
return item_type(l) != NO_ITEM; return item_type(l) != NO_ITEM;
} }
item_p item_of(off,items) item_p item_of(offset off, item_p items[])
offset off;
item_p items[];
{ {
register item_p x; item_p x;
for (x = items[LOCALVAR]; x != (item_p) 0; x = x->it_next) { for (x = items[LOCALVAR]; x != (item_p) 0; x = x->it_next) {
if (off == x->i_t.it_off) { if (off == x->i_t.it_off) {
@@ -85,9 +80,7 @@ item_p item_of(off,items)
fill_item(item,l) void fill_item(item_p item, line_p l)
item_p item;
line_p l;
{ {
item->it_type = item_type(l); item->it_type = item_type(l);
item->it_desirable = TRUE; item->it_desirable = TRUE;
@@ -105,8 +98,7 @@ fill_item(item,l)
STATIC bool desirable(l) static bool desirable(line_p l)
line_p l;
{ {
/* See if it is really desirable to put the item of line l /* See if it is really desirable to put the item of line l
* in a register. We do not put an item in a register if it * in a register. We do not put an item in a register if it
@@ -127,8 +119,7 @@ STATIC bool desirable(l)
STATIC int cmp_items(a,b) static int cmp_items(item_p a, item_p b)
item_p a,b;
{ {
/* This routine defines the <, = and > relations between items, /* This routine defines the <, = and > relations between items,
* used to sort them for fast lookup. * used to sort them for fast lookup.
@@ -156,15 +147,13 @@ STATIC int cmp_items(a,b)
bool same_item(a,b) bool same_item(item_p a, item_p b)
item_p a,b;
{ {
return cmp_items(a,b) == 0; return cmp_items(a,b) == 0;
} }
STATIC bool lt_item(a,b) static bool lt_item(item_p a, item_p b)
item_p a,b;
{ {
return cmp_items(a,b) == -1; return cmp_items(a,b) == -1;
} }
@@ -191,8 +180,7 @@ static item_p items[NRITEMTYPES]; /* items[i] points to the list of type i */
STATIC short reg_type(item) static short reg_type(item_p item)
item_p item;
{ {
/* See which type of register the item should best be assigned to */ /* See which type of register the item should best be assigned to */
@@ -210,12 +198,12 @@ STATIC short reg_type(item)
default: assert(FALSE); default: assert(FALSE);
} }
/* NOTREACHED */ /* NOTREACHED */
return 0;
} }
STATIC short item_size(item) static short item_size(item_p item)
item_p item;
{ {
/* Determine the size of the item (in bytes) */ /* Determine the size of the item (in bytes) */
@@ -234,12 +222,12 @@ STATIC short item_size(item)
default: assert(FALSE); default: assert(FALSE);
} }
/* NOTREACHED */ /* NOTREACHED */
return 0;
} }
STATIC init_item(a,b) static void init_item(item_p a, item_p b)
item_p a,b;
{ {
a->it_type = b->it_type; a->it_type = b->it_type;
switch(a->it_type) { switch(a->it_type) {
@@ -260,16 +248,12 @@ STATIC init_item(a,b)
STATIC add_item(item,t,items) static void add_item(item_p item, time_p t, item_p items[])
item_p item;
time_p t;
item_p items[];
{ {
/* See if there was already a list element for item. In any /* See if there was already a list element for item. In any
* case record the fact that item is used at 't'. * case record the fact that item is used at 't'.
*/ */
item_p x, *q;
register item_p x, *q;
q = &items[item->it_type]; /* each type has its own list */ q = &items[item->it_type]; /* each type has its own list */
for (x = *q; x != (item_p) 0; x = *q) { for (x = *q; x != (item_p) 0; x = *q) {
@@ -296,10 +280,7 @@ STATIC add_item(item,t,items)
STATIC add_usage(l,b,items) static void add_usage(line_p l, bblock_p b, item_p items[])
line_p l;
bblock_p b;
item_p items[];
{ {
/* An item is used at line l. Add it to the list of items. /* An item is used at line l. Add it to the list of items.
* A local variable is only considered to be an item, if * A local variable is only considered to be an item, if
@@ -323,10 +304,7 @@ STATIC add_usage(l,b,items)
build_itemlist(p,items,nrinstr_out) void build_itemlist(proc_p p, item_p items[], int *nrinstr_out)
proc_p p;
item_p items[];
int *nrinstr_out;
{ {
/* Make a list of all items used in procedure p. /* Make a list of all items used in procedure p.
* An item is anything that can be put in a register, * An item is anything that can be put in a register,

View File

@@ -8,27 +8,27 @@
* R A _ I T E M S . H * 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 /* Determine the type of item (constant,local
* variable etc.) accessed by l. * variable etc.) accessed by l.
*/ */
extern bool is_item(); /* (line_p l) bool is_item(line_p l);
* See if l accesses an item /* 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 /* Determine the descriptor of the item
* accessed by l; return 0 if not found * 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 /* Compute the type and obj/off attributes
* of the item accessed by l and put them * of the item accessed by l and put them
* in the given item descriptor. * 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. /* 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 /* Determine all items accessed by procedure p
* and put them in the items lists. All items * and put them in the items lists. All items
* of type T must be put in list items[T]. * of type T must be put in list items[T].
* Also determine the number of instructions * Also determine the number of instructions

View File

@@ -33,8 +33,7 @@
#define is_deadmsg(l) (INSTR(l) == ps_mes && aoff(ARG(l),0) == ms_ego && \ #define is_deadmsg(l) (INSTR(l) == ps_mes && aoff(ARG(l),0) == ms_ego && \
aoff(ARG(l),1) == ego_dead) aoff(ARG(l),1) == ego_dead)
build_lifetimes(items) void build_lifetimes(item_p items[])
item_p items[];
{ {
/* compute the it_lives attribute of every item; this is /* compute the it_lives attribute of every item; this is
* a list of intervals during which the item is live, * a list of intervals during which the item is live,
@@ -52,8 +51,8 @@ build_lifetimes(items)
* dead-message that is not a live -or dead message. * dead-message that is not a live -or dead message.
*/ */
register line_p l; line_p l;
register short now; short now;
item_p item; item_p item;
short last_code; short last_code;

View File

@@ -9,8 +9,8 @@
*/ */
extern build_lifetimes(); /* item_p items[]; void build_lifetimes(item_p items[]);
* compute the it_lives attribute of every /* compute the it_lives attribute of every
* item; this is a list of intervals * item; this is a list of intervals
* during which the item is live, * during which the item is live,
* i.e. its current value may be used. * i.e. its current value may be used.

View File

@@ -27,7 +27,7 @@ short regs_occupied[NRREGTYPES]; /* #occupied registers for reg_pointer,
*/ */
#define reg_available(t) (regs_available[t] > regs_occupied[t]) #define reg_available(t) (regs_available[t] > regs_occupied[t])
STATIC initregcount() static void initregcount()
{ {
int t; int t;
@@ -36,7 +36,7 @@ STATIC initregcount()
} }
} }
STATIC alloc_p make_dummy() static alloc_p make_dummy()
{ {
alloc_p x; alloc_p x;
@@ -46,9 +46,7 @@ STATIC alloc_p make_dummy()
} }
STATIC bool fits_in(a,b,cont_item) static bool fits_in(alloc_p a, alloc_p b, bool *cont_item)
alloc_p a,b;
bool *cont_item;
{ {
/* See if allocation a can be assigned the same register as b. /* See if allocation a can be assigned the same register as b.
* Both allocations should be of the same register-type. * Both allocations should be of the same register-type.
@@ -72,15 +70,14 @@ STATIC bool fits_in(a,b,cont_item)
} }
STATIC alloc_p find_fitting_alloc(alloc,packed) static alloc_p find_fitting_alloc(alloc_p alloc, alloc_p packed)
alloc_p alloc,packed;
{ {
/* Try to find and already packed allocation that is assigned /* Try to find and already packed allocation that is assigned
* a register that may also be used for alloc. * a register that may also be used for alloc.
* We prefer allocations that have the same item as alloc. * We prefer allocations that have the same item as alloc.
*/ */
register alloc_p x; alloc_p x;
alloc_p cand = (alloc_p) 0; alloc_p cand = (alloc_p) 0;
bool cont_item; bool cont_item;
@@ -94,8 +91,7 @@ STATIC alloc_p find_fitting_alloc(alloc,packed)
} }
STATIC bool room_for(alloc,packed) static bool room_for(alloc_p alloc, alloc_p packed)
alloc_p alloc,packed;
{ {
/* See if there is any register available for alloc */ /* See if there is any register available for alloc */
@@ -105,13 +101,11 @@ STATIC bool room_for(alloc,packed)
STATIC alloc_p best_alloc(unpacked,packed,time_opt) static alloc_p best_alloc(alloc_p unpacked, alloc_p packed, bool time_opt)
alloc_p unpacked,packed;
bool time_opt; /* now unused */
{ {
/* Find the next best candidate */ /* Find the next best candidate */
register alloc_p x,best; alloc_p x,best;
best = unpacked; /* dummy */ best = unpacked; /* dummy */
@@ -127,9 +121,7 @@ STATIC alloc_p best_alloc(unpacked,packed,time_opt)
STATIC alloc_p choose_location(alloc,packed,p) static alloc_p choose_location(alloc_p alloc, alloc_p packed, proc_p p)
alloc_p alloc,packed;
proc_p p;
{ {
/* Decide in which register to put alloc */ /* Decide in which register to put alloc */
@@ -151,8 +143,7 @@ STATIC alloc_p choose_location(alloc,packed,p)
STATIC update_lists(alloc,unpacked,packed,fit) static void update_lists(alloc_p alloc, alloc_p unpacked, alloc_p packed, alloc_p fit)
alloc_p alloc,unpacked,packed,fit;
{ {
/* 'alloc' has been granted a register; move it from the 'unpacked' /* 'alloc' has been granted a register; move it from the 'unpacked'
* list to the 'packed' list. Also remove any allocation from 'unpacked' * list to the 'packed' list. Also remove any allocation from 'unpacked'
@@ -161,7 +152,7 @@ STATIC update_lists(alloc,unpacked,packed,fit)
* 2. a timespan that overlaps the timespan of alloc. * 2. a timespan that overlaps the timespan of alloc.
*/ */
register alloc_p x,q,next; alloc_p x,q,next;
q = unpacked; /* dummy element at head of list */ q = unpacked; /* dummy element at head of list */
for (x = unpacked->al_next; x != (alloc_p) 0; x = next) { for (x = unpacked->al_next; x != (alloc_p) 0; x = next) {
@@ -191,8 +182,7 @@ STATIC update_lists(alloc,unpacked,packed,fit)
STATIC short cum_profits(alloc) static short cum_profits(alloc_p alloc)
alloc_p alloc;
{ {
/* Add the profits of all allocations packed in the same /* Add the profits of all allocations packed in the same
* register as alloc (i.e. alloc and all its 'mates'). * register as alloc (i.e. alloc and all its 'mates').
@@ -209,12 +199,11 @@ STATIC short cum_profits(alloc)
STATIC alloc_p best_cumprofits(list,x_out,prev_out) static void best_cumprofits(alloc_p list, alloc_p *x_out, alloc_p *prev_out)
alloc_p list, *x_out, *prev_out;
{ {
/* Find the allocation with the best cummulative profits */ /* Find the allocation with the best cummulative profits */
register alloc_p x,prev,best_prev; alloc_p x,prev,best_prev;
short best = 0, cum; short best = 0, cum;
prev = list; prev = list;
@@ -232,12 +221,12 @@ STATIC alloc_p best_cumprofits(list,x_out,prev_out)
*x_out = best_prev->al_next; *x_out = best_prev->al_next;
*prev_out = best_prev; *prev_out = best_prev;
} }
} }
STATIC account_regsave(packed,unpacked) static void account_regsave(alloc_p packed, alloc_p unpacked)
alloc_p packed,unpacked;
{ {
/* After all packing has been done, we check for every allocated /* After all packing has been done, we check for every allocated
* register whether it is really advantageous to use this * register whether it is really advantageous to use this
@@ -283,15 +272,13 @@ STATIC account_regsave(packed,unpacked)
STATIC bool in_single_reg(item,packed) static bool in_single_reg(item_p item, alloc_p packed)
item_p item;
alloc_p packed;
{ {
/* See if item is allocated in only one register (i.e. not in /* See if item is allocated in only one register (i.e. not in
* several different registers during several parts of its lifetime. * several different registers during several parts of its lifetime.
*/ */
register alloc_p x,m; alloc_p x,m;
bool seen = FALSE; bool seen = FALSE;
for (x = packed->al_next; x != (alloc_p) 0; x = x->al_next) { for (x = packed->al_next; x != (alloc_p) 0; x = x->al_next) {
@@ -308,10 +295,9 @@ STATIC bool in_single_reg(item,packed)
STATIC alloc_p find_prev(alloc,list) static alloc_p find_prev(alloc_p alloc, alloc_p list)
alloc_p alloc,list;
{ {
register alloc_p x; alloc_p x;
assert ( alloc != (alloc_p) 0); assert ( alloc != (alloc_p) 0);
for (x = list; x->al_next != alloc ; x = x->al_next) for (x = list; x->al_next != alloc ; x = x->al_next)
@@ -326,8 +312,7 @@ STATIC alloc_p find_prev(alloc,list)
* account_regsave from rejecting it. * account_regsave from rejecting it.
*/ */
STATIC repl_allocs(new,old,packed) static void repl_allocs(alloc_p new, alloc_p old, alloc_p packed)
alloc_p new,old,packed;
{ {
alloc_p x,next,prev,*p; alloc_p x,next,prev,*p;
short prof = 0; short prof = 0;
@@ -355,10 +340,9 @@ STATIC repl_allocs(new,old,packed)
STATIC assemble_allocs(packed) static void assemble_allocs(alloc_p packed)
alloc_p packed;
{ {
register alloc_p x,m,next; alloc_p x,m,next;
alloc_p e; alloc_p e;
bool voidb; bool voidb;
@@ -376,10 +360,7 @@ STATIC assemble_allocs(packed)
} }
} }
pack(alloclist,time_opt,packed_out,not_packed_out,p) void pack(alloc_p alloclist, bool time_opt, alloc_p *packed_out, alloc_p *not_packed_out, proc_p p)
alloc_p alloclist, *packed_out,*not_packed_out;
bool time_opt;
proc_p p;
{ {
/* This is the packing system. It decides which allations /* This is the packing system. It decides which allations
* to grant a register. * to grant a register.
@@ -391,7 +372,7 @@ pack(alloclist,time_opt,packed_out,not_packed_out,p)
* the same registers (i.e. these allocations fit together). * the same registers (i.e. these allocations fit together).
*/ */
register alloc_p x; alloc_p x;
alloc_p packed,unpacked,fit; alloc_p packed,unpacked,fit;
initregcount(); initregcount();

View File

@@ -9,8 +9,7 @@
* R A _ P A C K . H * R A _ P A C K . H
*/ */
extern pack(); /* ( alloc_p alloclist, *packed_out,*not_packed_out; void pack(alloc_p alloclist, bool time_opt, alloc_p *packed_out, alloc_p *not_packed_out, proc_p p);
* bool time_opt; proc_p p) /* This is the packing system. It decides which
* This is the packing system. It decides which
* allations to grant a register. * allations to grant a register.
*/ */

View File

@@ -18,9 +18,7 @@
#include "ra_aux.h" #include "ra_aux.h"
#include "ra_profits.h" #include "ra_profits.h"
STATIC bool test_cond(cond,val) static bool test_cond(short cond, offset val)
short cond;
offset val;
{ {
switch(cond) { switch(cond) {
case DEFAULT: case DEFAULT:
@@ -32,12 +30,10 @@ STATIC bool test_cond(cond,val)
case IN_0_8: case IN_0_8:
return val >= 0 && val <= 8; return val >= 0 && val <= 8;
} }
return FALSE;
} }
STATIC short map_value(tab,val,time) static short map_value(struct cond_tab tab[], offset val, bool time)
struct cond_tab tab[];
offset val;
bool time;
{ {
cond_p p; cond_p p;
@@ -46,13 +42,11 @@ STATIC short map_value(tab,val,time)
return (time ? p->mc_tval : p->mc_sval); return (time ? p->mc_tval : p->mc_sval);
} }
} }
return 0;
} }
STATIC short index_value(tab,n,time) static short index_value(struct cond_tab tab[], short n, bool time)
struct cond_tab tab[];
short n;
bool time;
{ {
cond_p p; cond_p p;
@@ -61,15 +55,13 @@ STATIC short index_value(tab,n,time)
} }
allocscore(itemtyp,localtyp,size,off,totyp,time_out,space_out) static void allocscore(short itemtyp, short localtyp, short size, offset off, short totyp,
short itemtyp, localtyp,totyp,size; short *time_out, short *space_out)
offset off;
short *time_out, *space_out;
{ {
cond_p m = (cond_p) 0; cond_p m = (cond_p) 0;
if (localtyp == reg_loop) localtyp = reg_any; if (localtyp == reg_loop) localtyp = reg_any;
if (size == ws || size ==ps && totyp == reg_pointer) { if ( ( (size == ws) || (size ==ps) ) && (totyp == reg_pointer) ) {
switch(itemtyp) { switch(itemtyp) {
case LOCALVAR: case LOCALVAR:
m = alocaltab[localtyp][totyp]; m = alocaltab[localtyp][totyp];
@@ -102,10 +94,8 @@ allocscore(itemtyp,localtyp,size,off,totyp,time_out,space_out)
*/ */
} }
opening_cost(itemtyp,localtyp,off,time_out,space_out) static void opening_cost(short itemtyp, short localtyp, offset off,
short itemtyp, localtyp; short *time_out, short *space_out)
offset off;
short *time_out, *space_out;
{ {
cond_p m; cond_p m;
@@ -138,11 +128,7 @@ opening_cost(itemtyp,localtyp,off,time_out,space_out)
*/ */
} }
void regsave_cost(short regs[], short *time_out, short *space_out)
regsave_cost(regs,time_out,space_out)
short regs[], *time_out, *space_out;
{ {
/* Estimate the costs of saving and restoring the registers /* Estimate the costs of saving and restoring the registers
* The array regs contains the number of registers of every * The array regs contains the number of registers of every
@@ -161,8 +147,7 @@ regsave_cost(regs,time_out,space_out)
STATIC short dyn_inits(inits) static short dyn_inits(lset inits)
lset inits;
{ {
Lindex i; Lindex i;
short sum = 0; short sum = 0;
@@ -177,16 +162,14 @@ STATIC short dyn_inits(inits)
compute_profits(alloclist,time_opt) void compute_profits(alloc_p alloclist, bool time_opt)
alloc_p alloclist;
bool time_opt;
{ {
/* Compute the profits attribute of every allocation. /* Compute the profits attribute of every allocation.
* If the item of an allocation may be put in several types * If the item of an allocation may be put in several types
* of register, we choose only the most advanteagous one. * of register, we choose only the most advanteagous one.
*/ */
register alloc_p alloc; alloc_p alloc;
short s,t,rtyp,maxsc; short s,t,rtyp,maxsc;
item_p item; item_p item;
short time,space,sc; short time,space,sc;

View File

@@ -9,8 +9,7 @@
* R A _ P R O F I T S . H * 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. /* 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);

View File

@@ -77,8 +77,7 @@ struct repl repl_tab[NRREPLACEMENTS][REPL_LENGTH] = {
init_replacements(psize,wsize) void init_replacements(short psize, short wsize)
short psize,wsize;
{ {
/* The replacement code to be generated depends on the /* The replacement code to be generated depends on the
* wordsize and pointer size of the target machine. * wordsize and pointer size of the target machine.
@@ -88,7 +87,7 @@ init_replacements(psize,wsize)
* as a 'Load pointer' instruction. * as a 'Load pointer' instruction.
*/ */
register int i,j; int i,j;
short load_pointer; short load_pointer;
struct repl *r; struct repl *r;
@@ -129,27 +128,21 @@ init_replacements(psize,wsize)
STATIC int repl_index(l) static int repl_index(line_p l)
line_p l;
{ {
return itemtab[INSTR(l) - sp_fmnem].id_replindex; return itemtab[INSTR(l) - sp_fmnem].id_replindex;
} }
STATIC bool is_current(alloc,t) static bool is_current(alloc_p alloc, short t)
alloc_p alloc;
short t;
{ {
/* Is time t part of alloc's timespan? */ /* Is time t part of alloc's timespan? */
return contains(t,alloc->al_timespan); return contains(t,alloc->al_timespan);
} }
STATIC match_item(item,l) static int match_item(item_p item, line_p l)
item_p item;
line_p l;
{ {
/* See if the item used by l is the same one as 'item' */ /* See if the item used by l is the same one as 'item' */
struct item thisitem; struct item thisitem;
@@ -161,21 +154,17 @@ STATIC match_item(item,l)
*/ */
thisitem.it_type = LOCAL_ADDR; thisitem.it_type = LOCAL_ADDR;
} }
return item->it_type == thisitem.it_type && same_item(item,&thisitem); return (item->it_type == thisitem.it_type) && same_item(item,&thisitem);
} }
STATIC alloc_p find_alloc(alloclist,l,t) static alloc_p find_alloc(alloc_p alloclist, line_p l, short t)
alloc_p alloclist;
line_p l;
short t;
{ {
/* See if any of the allocations of the list applies to instruction /* See if any of the allocations of the list applies to instruction
* l at time t. * l at time t.
*/ */
alloc_p alloc,m;
register alloc_p alloc,m;
for (alloc = alloclist; alloc != (alloc_p) 0; alloc = alloc->al_next) { for (alloc = alloclist; alloc != (alloc_p) 0; alloc = alloc->al_next) {
for (m = alloc; m != (alloc_p) 0; m = m->al_mates) { for (m = alloc; m != (alloc_p) 0; m = m->al_mates) {
@@ -188,9 +177,7 @@ STATIC alloc_p find_alloc(alloclist,l,t)
} }
STATIC replace_line(l,b,list) static void replace_line(line_p l, bblock_p b, line_p list)
line_p l,list;
bblock_p b;
{ {
if (b->b_start == l) { if (b->b_start == l) {
b->b_start = list; b->b_start = list;
@@ -209,9 +196,7 @@ STATIC replace_line(l,b,list)
} }
STATIC line_p repl_code(lnp,regnr) static line_p repl_code(line_p lnp, offset regnr)
line_p lnp;
offset regnr;
{ {
line_p head,*q,l,prev = (line_p) 0; line_p head,*q,l,prev = (line_p) 0;
int i,index; int i,index;
@@ -245,10 +230,7 @@ STATIC line_p repl_code(lnp,regnr)
STATIC apply_alloc(b,l,alloc) static void apply_alloc(bblock_p b, line_p l, alloc_p alloc)
bblock_p b;
line_p l;
alloc_p alloc;
{ {
/* 'l' is an EM instruction using an item that will be put in /* 'l' is an EM instruction using an item that will be put in
* a register. Generate new code that uses the register instead * a register. Generate new code that uses the register instead
@@ -284,7 +266,7 @@ STATIC apply_alloc(b,l,alloc)
STATIC int loaditem_tab[NRITEMTYPES][2] = static int loaditem_tab[NRITEMTYPES][2] =
{ /* WS 2 * WS */ { /* WS 2 * WS */
/*LOCALVAR*/ op_lol, op_ldl, /*LOCALVAR*/ op_lol, op_ldl,
/*LOCAL_ADDR*/ op_lal, op_lal, /*LOCAL_ADDR*/ op_lal, op_lal,
@@ -295,8 +277,7 @@ STATIC int loaditem_tab[NRITEMTYPES][2] =
}; };
STATIC line_p load_item(item) static line_p load_item(item_p item)
item_p item;
{ {
/* Generate an EM instruction that loads the item on the stack */ /* Generate an EM instruction that loads the item on the stack */
@@ -320,9 +301,7 @@ STATIC line_p load_item(item)
} }
STATIC line_p store_local(size,off) static line_p store_local(short size, offset off)
short size;
offset off;
{ {
line_p l = int_line(off); line_p l = int_line(off);
@@ -332,11 +311,9 @@ STATIC line_p store_local(size,off)
STATIC line_p init_place(b) static line_p init_place(bblock_p b)
bblock_p b;
{ {
line_p l,prev;
register line_p l,prev;
prev = (line_p) 0; prev = (line_p) 0;
for (l = b->b_start; l != (line_p) 0; l = l->l_next) { for (l = b->b_start; l != (line_p) 0; l = l->l_next) {
@@ -355,12 +332,9 @@ STATIC line_p init_place(b)
STATIC append_code(l1,l2,b) static void append_code(line_p l1, line_p l2, bblock_p b)
line_p l1,l2;
bblock_p b;
{ {
/* Append instruction l1 and l2 at begin of block b */ /* Append instruction l1 and l2 at begin of block b */
line_p l; line_p l;
DLINK(l1,l2); DLINK(l1,l2);
@@ -380,15 +354,14 @@ STATIC append_code(l1,l2,b)
STATIC emit_init_code(list) static void emit_init_code(alloc_p list)
alloc_p list;
{ {
/* Emit initialization code for all packed allocations. /* Emit initialization code for all packed allocations.
* This code looks like "dummy_local := item", e.g. * This code looks like "dummy_local := item", e.g.
* "LOC 25 ; STL -10" in EM terminology. * "LOC 25 ; STL -10" in EM terminology.
*/ */
register alloc_p alloc,m; alloc_p alloc,m;
Lindex bi; Lindex bi;
bblock_p b; bblock_p b;
@@ -409,9 +382,7 @@ STATIC emit_init_code(list)
STATIC emit_mesregs(p,alloclist) static void emit_mesregs(proc_p p, alloc_p alloclist)
proc_p p;
alloc_p alloclist;
{ {
line_p l,m,x; line_p l,m,x;
alloc_p alloc; alloc_p alloc;
@@ -432,11 +403,10 @@ STATIC emit_mesregs(p,alloclist)
rem_mes(p) static void rem_mes(proc_p p)
proc_p p;
{ {
register bblock_p b; bblock_p b;
register line_p l,next; line_p l,next;
offset m; offset m;
for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) { for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) {
@@ -455,19 +425,15 @@ rem_mes(p)
xform_proc(p,alloclist,nrinstrs,instrmap) void xform_proc(proc_p p, alloc_p alloclist, short nrinstrs, line_p instrmap[])
proc_p p;
alloc_p alloclist;
short nrinstrs;
line_p instrmap[];
{ {
/* Transform every instruction of procedure p that uses an item /* Transform every instruction of procedure p that uses an item
* at a point where the item is kept in a register. * at a point where the item is kept in a register.
*/ */
register short now = 0; short now = 0;
register line_p l,next; line_p l,next;
register bblock_p b; bblock_p b;
alloc_p alloc; alloc_p alloc;
for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) { for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) {
@@ -498,10 +464,7 @@ xform_proc(p,alloclist,nrinstrs,instrmap)
bool always_in_reg(off,allocs,size_out) bool always_in_reg(offset off, alloc_p allocs, short *size_out)
offset off;
alloc_p allocs;
short *size_out;
{ {
/* See if the local variable with the given offset is stored /* See if the local variable with the given offset is stored
* in a register during its entire lifetime. As a side effect, * in a register during its entire lifetime. As a side effect,
@@ -526,9 +489,7 @@ bool always_in_reg(off,allocs,size_out)
} }
rem_locals(p,allocs) void rem_locals(proc_p p, alloc_p allocs)
proc_p p;
alloc_p allocs;
{ {
/* Try to decrease the number of locals of procedure p, by /* Try to decrease the number of locals of procedure p, by
* looking at which locals are always stored in a register. * looking at which locals are always stored in a register.
@@ -551,9 +512,8 @@ rem_locals(p,allocs)
} }
p->p_localbytes = nrlocals; p->p_localbytes = nrlocals;
} }
rem_formals(p,allocs)
proc_p p; void rem_formals(proc_p p, alloc_p allocs)
alloc_p allocs;
{ {
/* Try to decrease the number of formals of procedure p, by /* Try to decrease the number of formals of procedure p, by
* looking at which formals are always stored in a register. * looking at which formals are always stored in a register.

View File

@@ -9,21 +9,23 @@
* R A _ X F O R M . H * 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 /* This routine must be called once, before
* any call to xform_proc. It initializes * any call to xform_proc. It initializes
* a machine dependent table. * a machine dependent table.
*/ */
extern xform_proc(); /* (proc_p p; alloc_p alloclist; void xform_proc(proc_p p, alloc_p alloclist, short nrinstrs, line_p instrmap[]);
* short nrinstrs; line_p instrmap[]) /* Transform a procedure. Alloclist must
* Transform a procedure. Alloclist must
* contain the packed allocations (i.e. those * contain the packed allocations (i.e. those
* allocations that are assigned a register). * allocations that are assigned a register).
*/ */
bool always_in_reg(); /* ( offset off; alloc_p allocs; bool always_in_reg(offset off, alloc_p allocs, short *size_out);
* short *size_out;) /* See if the local variable with the given
* See if the local variable with the given
* offset is stored in a register during its * offset is stored in a register during its
* entire lifetime. As a side effect, * entire lifetime. As a side effect,
* return the size of the local. * return the size of the local.
*/ */
void rem_locals(proc_p p, alloc_p allocs);
void rem_formals(proc_p p, alloc_p allocs);

View File

@@ -11,6 +11,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <em_mnem.h> #include <em_mnem.h>
#include <em_spec.h> #include <em_spec.h>
#include "../share/types.h" #include "../share/types.h"
@@ -37,7 +38,7 @@
#define NOT_MARKED(b) (!(b->b_flags&BF_MARK)) #define NOT_MARKED(b) (!(b->b_flags&BF_MARK))
#define IN_LOOP(b) (Lnrelems(b->b_loops) > 0) #define IN_LOOP(b) (Lnrelems(b->b_loops) > 0)
STATIC int Ssp; /* number of optimizations */ static int Ssp; /* number of optimizations */
/* According to the EM definition, the stack must be cleaned up /* According to the EM definition, the stack must be cleaned up
* before any return. However, for some backends it causes no harm * before any return. However, for some backends it causes no harm
@@ -45,17 +46,17 @@ STATIC int Ssp; /* number of optimizations */
* more globally. * more globally.
*/ */
STATIC int globl_sp_allowed; static int globl_sp_allowed;
#define IS_ASP(l) (INSTR(l) == op_asp && TYPE(l) == OPSHORT && SHORT(l) > 0) #define IS_ASP(l) (INSTR(l) == op_asp && TYPE(l) == OPSHORT && SHORT(l) > 0)
STATIC sp_machinit(f) static int sp_machinit(void *param)
FILE *f;
{ {
/* Read target machine dependent information for this phase */ /* Read target machine dependent information for this phase */
char s[100]; char s[100];
FILE *f = (FILE*)param;
for (;;) { for (;;) {
while(getc(f) != '\n'); while(getc(f) != '\n');
@@ -63,10 +64,11 @@ STATIC sp_machinit(f)
if (strcmp(s,"%%SP") == 0)break; if (strcmp(s,"%%SP") == 0)break;
} }
fscanf(f,"%d",&globl_sp_allowed); fscanf(f,"%d",&globl_sp_allowed);
return 0;
} }
comb_asps(l1,l2,b)
line_p l1,l2; void comb_asps(line_p l1, line_p l2, bblock_p b)
bblock_p b;
{ {
assert(INSTR(l1) == op_asp); assert(INSTR(l1) == op_asp);
assert(INSTR(l2) == op_asp); assert(INSTR(l2) == op_asp);
@@ -76,18 +78,17 @@ comb_asps(l1,l2,b)
SHORT(l2) += SHORT(l1); SHORT(l2) += SHORT(l1);
rm_line(l1,b); rm_line(l1,b);
} }
stack_pollution(b)
bblock_p b; static void stack_pollution(bblock_p b)
{ {
/* For every pair of successive ASP instructions in basic /* For every pair of successive ASP instructions in basic
* block b, try to combine the two into one ASP. * block b, try to combine the two into one ASP.
*/ */
register line_p l; line_p l;
line_p asp,next = b->b_start; line_p asp,next = b->b_start;
bool asp_seen = FALSE; bool asp_seen = FALSE;
int stack_diff,pop,push; int stack_diff,pop,push;
@@ -133,11 +134,10 @@ stack_pollution(b)
} while (asp != (line_p) 0); } while (asp != (line_p) 0);
} }
STATIC bool block_save(b) static bool block_save(bblock_p b)
bblock_p b;
{ {
register line_p l; line_p l;
int stack_diff,pop,push; int stack_diff,pop,push;
bool ok; bool ok;
@@ -160,8 +160,7 @@ STATIC bool block_save(b)
STATIC mark_pred(b) static void mark_pred(bblock_p b)
bblock_p b;
{ {
Lindex i; Lindex i;
bblock_p x; bblock_p x;
@@ -179,10 +178,9 @@ STATIC mark_pred(b)
STATIC mark_unsave_blocks(p) static void mark_unsave_blocks(proc_p p)
proc_p p;
{ {
register bblock_p b; bblock_p b;
for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) { for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) {
if (NOT_MARKED(b) && !block_save(b)) { if (NOT_MARKED(b) && !block_save(b)) {
@@ -193,24 +191,23 @@ STATIC mark_unsave_blocks(p)
} }
sp_optimize(p) static int sp_optimize(void *param)
proc_p p;
{ {
register bblock_p b; bblock_p b;
proc_p p = (proc_p)param;
if (IS_ENTERED_WITH_GTO(p)) return; if (IS_ENTERED_WITH_GTO(p)) return 0;
mark_unsave_blocks(p); mark_unsave_blocks(p);
for (b = p->p_start; b != 0; b = b->b_next) { for (b = p->p_start; b != 0; b = b->b_next) {
stack_pollution(b); stack_pollution(b);
} }
return 0;
} }
main(argc,argv) int main(int argc, char *argv[])
int argc;
char *argv[];
{ {
go(argc,argv,no_action,sp_optimize,sp_machinit,no_action); go(argc,argv,no_action,sp_optimize,sp_machinit,no_action);
report("stack adjustments deleted",Ssp); report("stack adjustments deleted",Ssp);

View File

@@ -8,6 +8,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "../share/types.h" #include "../share/types.h"
#include "sr.h" #include "sr.h"
#include "../share/debug.h" #include "../share/debug.h"
@@ -51,12 +52,11 @@ int sli_threshold;
int Ssr; /* #optimizations found */ int Ssr; /* #optimizations found */
sr_machinit(f) static int sr_machinit(void *param)
FILE *f;
{ {
/* Read target machine dependent information */ /* Read target machine dependent information */
char s[100]; char s[100];
FILE *f = (FILE*)param;
for (;;) { for (;;) {
while(getc(f) != '\n'); while(getc(f) != '\n');
@@ -66,10 +66,11 @@ sr_machinit(f)
fscanf(f,"%d",&ovfl_harmful); fscanf(f,"%d",&ovfl_harmful);
fscanf(f,"%d",&arrbound_harmful); fscanf(f,"%d",&arrbound_harmful);
fscanf(f,"%d",&sli_threshold); fscanf(f,"%d",&sli_threshold);
return 0;
} }
STATIC del_ivs(ivs) static void del_ivs(lset ivs)
lset ivs;
{ {
/* Delete the set of iv structs */ /* Delete the set of iv structs */
@@ -82,8 +83,7 @@ STATIC del_ivs(ivs)
} }
STATIC do_loop(loop) static void do_loop(loop_p loop)
loop_p loop;
{ {
lset ivs, vars; lset ivs, vars;
@@ -110,13 +110,12 @@ STATIC do_loop(loop)
STATIC loopblocks(p) static void loopblocks(proc_p p)
proc_p p;
{ {
/* Compute the LP_BLOCKS sets for all loops of p */ /* Compute the LP_BLOCKS sets for all loops of p */
register bblock_p b; bblock_p b;
register Lindex i; Lindex i;
for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) { for (b = p->p_start; b != (bblock_p) 0; b = b->b_next) {
for (i = Lfirst(b->b_loops); i != (Lindex) 0; for (i = Lfirst(b->b_loops); i != (Lindex) 0;
@@ -128,8 +127,7 @@ STATIC loopblocks(p)
STATIC opt_proc(p) static void opt_proc(proc_p p)
proc_p p;
{ {
/* Optimize all loops of one procedure. We first do all /* Optimize all loops of one procedure. We first do all
* outer loops at the lowest nesting level and proceed * outer loops at the lowest nesting level and proceed
@@ -160,8 +158,7 @@ STATIC opt_proc(p)
STATIC bblock_p header(lp) static bblock_p header(loop_p lp)
loop_p lp;
{ {
/* Try to determine the 'header' block of loop lp. /* Try to determine the 'header' block of loop lp.
* If 'e' is the entry block of loop L, then block 'b' is * If 'e' is the entry block of loop L, then block 'b' is
@@ -172,22 +169,21 @@ STATIC bblock_p header(lp)
bblock_p x = lp->lp_entry->b_idom; bblock_p x = lp->lp_entry->b_idom;
if (x != (bblock_p) 0 && Lnrelems(x->b_succ) == 1 && if ( (x != NULL) && (Lnrelems(x->b_succ) == 1) &&
(bblock_p) Lelem(Lfirst(x->b_succ)) == lp->lp_entry) { ((bblock_p) Lelem(Lfirst(x->b_succ)) == lp->lp_entry) ) {
return x; return x;
} }
return (bblock_p) 0; return NULL;
} }
STATIC sr_extproc(p) static void sr_extproc(proc_p p)
proc_p p;
{ {
/* Allocate the extended data structures for procedure p */ /* Allocate the extended data structures for procedure p */
register loop_p lp; loop_p lp;
register Lindex pi; Lindex pi;
for (pi = Lfirst(p->p_loops); pi != (Lindex) 0; for (pi = Lfirst(p->p_loops); pi != (Lindex) 0;
pi = Lnext(pi,p->p_loops)) { pi = Lnext(pi,p->p_loops)) {
@@ -201,13 +197,12 @@ STATIC sr_extproc(p)
} }
STATIC sr_cleanproc(p) static void sr_cleanproc(proc_p p)
proc_p p;
{ {
/* Remove the extended data structures for procedure p */ /* Remove the extended data structures for procedure p */
register loop_p lp; loop_p lp;
register Lindex pi; Lindex pi;
for (pi = Lfirst(p->p_loops); pi != (Lindex) 0; for (pi = Lfirst(p->p_loops); pi != (Lindex) 0;
@@ -218,21 +213,21 @@ STATIC sr_cleanproc(p)
} }
sr_optimize(p) static int sr_optimize(void *param)
proc_p p;
{ {
if (IS_ENTERED_WITH_GTO(p)) return; proc_p p = (proc_p)param;
if (IS_ENTERED_WITH_GTO(p)) return 0;
sr_extproc(p); sr_extproc(p);
loopblocks(p); loopblocks(p);
opt_proc(p); opt_proc(p);
sr_cleanproc(p); sr_cleanproc(p);
return 0;
} }
main(argc,argv) int main(int argc, char *argv[])
int argc;
char *argv[];
{ {
go(argc,argv,no_action,sr_optimize,sr_machinit,no_action); go(argc,argv,no_action,sr_optimize,sr_machinit,no_action);
report("strength reductions",Ssr); report("strength reductions",Ssr);

View File

@@ -24,9 +24,7 @@
#define INSIDE_LOOP(b,lp) Lis_elem(b,lp->LP_BLOCKS) #define INSIDE_LOOP(b,lp) Lis_elem(b,lp->LP_BLOCKS)
bool is_loopconst(lnp,vars) bool is_loopconst(line_p lnp, lset vars)
line_p lnp;
lset vars;
{ {
Lindex i; Lindex i;
@@ -41,9 +39,7 @@ bool is_loopconst(lnp,vars)
} }
bool is_caddress(lnp,vars) bool is_caddress(line_p lnp, lset vars)
line_p lnp;
lset vars; /* variables changed in loop */
{ {
/* See if lnp is a single instruction (i.e. without arguments) /* See if lnp is a single instruction (i.e. without arguments)
* that pushes a loop-invariant entity of size pointer-size (ps) * that pushes a loop-invariant entity of size pointer-size (ps)
@@ -63,13 +59,12 @@ bool is_caddress(lnp,vars)
return FALSE; return FALSE;
} }
/* NOTREACHED */ /* NOTREACHED */
return FALSE;
} }
STATIC arg_p find_arg(n,list) static arg_p find_arg(int n, arg_p list)
int n;
arg_p list;
{ {
/* Find the n-th element of the list */ /* Find the n-th element of the list */
@@ -81,8 +76,7 @@ STATIC arg_p find_arg(n,list)
} }
int elemsize(lnp) int elemsize(line_p lnp)
line_p lnp;
{ {
/* lnp is an instruction that loads the address of an array /* lnp is an instruction that loads the address of an array
* descriptor. Find the size of the elements of the array. * descriptor. Find the size of the elements of the array.
@@ -107,12 +101,11 @@ int elemsize(lnp)
concatenate(list1,list2) void concatenate(line_p list1, line_p list2)
line_p list1,list2;
{ {
/* Append list2 to the end of list1. list1 may not be empty. */ /* Append list2 to the end of list1. list1 may not be empty. */
register line_p l; line_p l;
assert(list1 != (line_p) 0); assert(list1 != (line_p) 0);
for (l =list1; l->l_next != (line_p) 0; l = l->l_next); for (l =list1; l->l_next != (line_p) 0; l = l->l_next);

View File

@@ -6,20 +6,20 @@
/* S R _ A U X . H */ /* S R _ A U X . H */
extern bool is_loopconst(); /* (line_p l; lset vars) bool is_loopconst(line_p lnp, lset vars);
* See if l is a loop-constant. vars is the /* See if l is a loop-constant. vars is the
* set of variables changed in the loop. * set of variables changed in the loop.
*/ */
extern bool is_caddress(); /* (line_p l) bool is_caddress(line_p lnp, lset vars);
* See if l loads a loop-invariant entity of /* See if l loads a loop-invariant entity of
* size pointer-size. * size pointer-size.
*/ */
extern int elemsize(); /* (line_p l) int elemsize(line_p lnp);
* l is an instruction that loads an array /* l is an instruction that loads an array
* descriptor. Try to determine the size * descriptor. Try to determine the size
* of the array elements. * 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 /* Append list2 to the end of list1
*/ */
#define is_const(l) (INSTR(l) == op_loc) #define is_const(l) (INSTR(l) == op_loc)

View File

@@ -41,7 +41,7 @@
*/ */
STATIC lset cand, /* set of candidates */ static lset cand, /* set of candidates */
dism; /* set of dismissed variables */ dism; /* set of dismissed variables */
@@ -49,8 +49,7 @@ STATIC lset cand, /* set of candidates */
STATIC un_cand(lnp) static void un_cand(line_p lnp)
line_p lnp;
{ {
/* remove the variable stored into by lnp from the list of /* remove the variable stored into by lnp from the list of
* candidates (if it was there anyway). * candidates (if it was there anyway).
@@ -68,8 +67,7 @@ STATIC un_cand(lnp)
} }
STATIC bool is_cand(lnp) static bool is_cand(line_p lnp)
line_p lnp;
{ {
/* see if the variable stored into by lnp is a candate */ /* see if the variable stored into by lnp is a candate */
@@ -84,8 +82,7 @@ STATIC bool is_cand(lnp)
} }
STATIC make_cand(lnp) static void make_cand(line_p lnp)
line_p lnp;
{ {
/* make the variable stored into by lnp a candidate */ /* make the variable stored into by lnp a candidate */
@@ -96,15 +93,13 @@ STATIC make_cand(lnp)
STATIC do_dismiss(lnp) static void do_dismiss(line_p lnp)
line_p lnp;
{ {
Ladd(lnp,&dism); Ladd(lnp,&dism);
} }
STATIC dismiss(lnp) static void dismiss(line_p lnp)
line_p lnp;
{ {
/* The variable referenced by lnp is turned definitely into /* The variable referenced by lnp is turned definitely into
* a non-candidate. * a non-candidate.
@@ -117,8 +112,7 @@ STATIC dismiss(lnp)
} }
STATIC bool not_dismissed(lnp) static bool not_dismissed(line_p lnp)
line_p lnp;
{ {
Lindex i; Lindex i;
@@ -131,9 +125,7 @@ STATIC bool not_dismissed(lnp)
} }
STATIC try_cand(lnp,b) static void try_cand(line_p lnp, bblock_p b)
line_p lnp;
bblock_p b;
{ {
/* If the variable stored into by lnp was not already a candidate /* If the variable stored into by lnp was not already a candidate
* and was not dismissed, then it is made a candidate * and was not dismissed, then it is made a candidate
@@ -151,9 +143,7 @@ STATIC try_cand(lnp,b)
} }
candidates(lp,cand_out,vars_out) void candidates(loop_p lp, lset *cand_out, lset *vars_out)
loop_p lp;
lset *cand_out, *vars_out;
{ {
/* Find the candidate induction variables. /* Find the candidate induction variables.
*/ */

View File

@@ -9,8 +9,8 @@
*/ */
extern candidates(); /* (loop_p lp; lset *iv_cand, *vars) void candidates(loop_p lp, lset *cand_out, lset *vars_out);
* Find candidate induction variables, /* Find candidate induction variables,
* i.e. local variables that are assigned * i.e. local variables that are assigned
* a value precisely once within the loop, * a value precisely once within the loop,
* within a strong block. Also find the * within a strong block. Also find the

View File

@@ -26,10 +26,9 @@
STATIC lset ivvars; /* set of induction variables */ static lset ivvars; /* set of induction variables */
STATIC short nature(lnp) static short nature(line_p lnp)
line_p lnp;
{ {
/* Auxiliary routine used by inc_or_dec, is_add and plus_or_min. /* Auxiliary routine used by inc_or_dec, is_add and plus_or_min.
* Determine if lnp had INCREMENT/DECREMENT-nature (1), * Determine if lnp had INCREMENT/DECREMENT-nature (1),
@@ -62,8 +61,7 @@ STATIC short nature(lnp)
#define inc_or_dec(l) (nature(l) == 1) #define inc_or_dec(l) (nature(l) == 1)
STATIC bool is_same(l,lnp) static bool is_same(line_p l, line_p lnp)
line_p l, lnp;
{ {
/* lnp is a STL x , where x is a candidate /* lnp is a STL x , where x is a candidate
* induction variable. See if l is a LOL x * induction variable. See if l is a LOL x
@@ -76,9 +74,7 @@ STATIC bool is_same(l,lnp)
} }
STATIC ivar(lnp,step) static void ivar(line_p lnp, int step)
line_p lnp;
int step;
{ {
/* Record the fact that we've found a new induction variable. /* Record the fact that we've found a new induction variable.
* lnp points to the last instruction of the code that * lnp points to the last instruction of the code that
@@ -95,8 +91,7 @@ STATIC ivar(lnp,step)
} }
STATIC int sign(lnp) static int sign(line_p lnp)
line_p lnp;
{ {
switch(INSTR(lnp)) { switch(INSTR(lnp)) {
case op_inc: case op_inc:
@@ -113,11 +108,11 @@ STATIC int sign(lnp)
assert(FALSE); assert(FALSE);
} }
/* NOTREACHED */ /* NOTREACHED */
return FALSE;
} }
STATIC try_patterns(lnp) static void try_patterns(line_p lnp)
line_p lnp;
{ {
/* lnp is a STL x; try to recognize /* lnp is a STL x; try to recognize
* one of the patterns: * one of the patterns:
@@ -153,9 +148,7 @@ STATIC try_patterns(lnp)
} }
induc_vars(loop,ivar_out, vars_out) void induc_vars(loop_p loop, lset *ivar_out, lset *vars_out)
loop_p loop;
lset *ivar_out, *vars_out;
{ {
/* Construct the set of induction variables. We use several /* Construct the set of induction variables. We use several
* global variables computed by 'candidates'. * global variables computed by 'candidates'.

View File

@@ -5,8 +5,8 @@
*/ */
/* S R _ I V . H */ /* S R _ I V . H */
extern induc_vars(); /* (loop_p loop; lset *ivars, *vars) void induc_vars(loop_p loop, lset *ivar_out, lset *vars_out);
* Find the set of induction variables /* Find the set of induction variables
* of the loop. Also find the set of (local) * of the loop. Also find the set of (local)
* variables that are changed. * variables that are changed.
*/ */

View File

@@ -30,7 +30,7 @@
STATIC lset avail; static lset avail;
/* If an expression such as "iv * const" or "A[iv]" is /* If an expression such as "iv * const" or "A[iv]" is
* used more than once in a loop, we only use one temporary * used more than once in a loop, we only use one temporary
* local for it and reuse this local each time. * local for it and reuse this local each time.
@@ -38,8 +38,7 @@ STATIC lset avail;
* be available. * be available.
*/ */
STATIC int regtyp(code) static int regtyp(code_p code)
code_p code;
{ {
switch(code->co_instr) { switch(code->co_instr) {
case op_mli: case op_mli:
@@ -51,14 +50,11 @@ STATIC int regtyp(code)
return reg_pointer; return reg_pointer;
} }
/* NOTREACHED */ /* NOTREACHED */
return reg_pointer;
} }
STATIC gen_regmes(tmp,score,code,p) static void gen_regmes(offset tmp, int score, code_p code, proc_p p)
offset tmp;
int score;
code_p code;
proc_p p;
{ {
/* generate a register message for the temporary variable and /* generate a register message for the temporary variable and
* insert it at the start of the procedure. * insert it at the start of the procedure.
@@ -75,9 +71,7 @@ STATIC gen_regmes(tmp,score,code,p)
} }
STATIC line_p newcode(code,tmp) static line_p newcode(code_p code, offset tmp)
code_p code;
offset tmp;
{ {
/* Construct the EM code that will replace the reducible code, /* Construct the EM code that will replace the reducible code,
* e.g. iv * c -> tmp * e.g. iv * c -> tmp
@@ -120,9 +114,7 @@ STATIC line_p newcode(code,tmp)
STATIC replcode(code,text) static void replcode(code_p code, line_p text)
code_p code;
line_p text;
{ {
/* Replace old code (extending from code->co_lfirst to /* Replace old code (extending from code->co_lfirst to
* code->co_llast) by new code (headed by 'text'). * code->co_llast) by new code (headed by 'text').
@@ -149,8 +141,7 @@ STATIC replcode(code,text)
/* Note that the old code is still accessible via code->co_lfirst */ /* Note that the old code is still accessible via code->co_lfirst */
} }
STATIC line_p add_code(pl, l) static line_p add_code(line_p pl, line_p l)
line_p pl, l;
{ {
if (! pl) { if (! pl) {
PREV(l) = 0; PREV(l) = 0;
@@ -170,9 +161,7 @@ STATIC line_p add_code(pl, l)
STATIC init_code(code,tmp) static void init_code(code_p code, offset tmp)
code_p code;
offset tmp;
{ {
/* Generate code to set up the temporary local. /* Generate code to set up the temporary local.
* For multiplication, its initial value is const*iv_expr, * For multiplication, its initial value is const*iv_expr,
@@ -238,9 +227,7 @@ STATIC init_code(code,tmp)
*p = l; /* new last instruction */ *p = l; /* new last instruction */
} }
STATIC incr_code(code,tmp) static void incr_code(code_p code, offset tmp)
code_p code;
offset tmp;
{ {
/* Generate code to increment the temporary local variable. /* Generate code to increment the temporary local variable.
* The variable is incremented by * The variable is incremented by
@@ -321,8 +308,7 @@ STATIC incr_code(code,tmp)
} }
STATIC remcode(c) static void remcode(code_p c)
code_p c;
{ {
line_p l, next; line_p l, next;
@@ -334,9 +320,7 @@ STATIC remcode(c)
} }
STATIC bool same_address(l1,l2,vars) static bool same_address(line_p l1, line_p l2, lset vars)
line_p l1,l2;
lset vars;
{ {
/* See if l1 and l2 load the same address */ /* See if l1 and l2 load the same address */
@@ -357,18 +341,17 @@ STATIC bool same_address(l1,l2,vars)
default: default:
return FALSE; return FALSE;
} }
return FALSE;
} }
STATIC bool same_expr(lb1,le1,lb2,le2) static bool same_expr(line_p lb1, line_p le1, line_p lb2, line_p le2)
line_p lb1,le1,lb2,le2;
{ {
/* See if the code from lb1 to le1 is the same /* See if the code from lb1 to le1 is the same
* expression as the code from lb2 to le2. * expression as the code from lb2 to le2.
*/ */
line_p l1,l2;
register line_p l1,l2;
l1 = lb1; l1 = lb1;
l2 = lb2; l2 = lb2;
@@ -395,9 +378,7 @@ STATIC bool same_expr(lb1,le1,lb2,le2)
} }
} }
STATIC bool same_code(c1,c2,vars) static bool same_code(code_p c1, code_p c2, lset vars)
code_p c1,c2;
lset vars;
{ {
/* See if c1 and c2 compute the same expression. Two array /* See if c1 and c2 compute the same expression. Two array
* references can be the same even if one is e.g a fetch * references can be the same even if one is e.g a fetch
@@ -428,12 +409,11 @@ STATIC bool same_code(c1,c2,vars)
assert(FALSE); assert(FALSE);
} }
/* NOTREACHED */ /* NOTREACHED */
return FALSE;
} }
STATIC code_p available(c,vars) static code_p available(code_p c, lset vars)
code_p c;
lset vars;
{ {
/* See if the code is already available. /* See if the code is already available.
* If so, return a pointer to the first occurrence * If so, return a pointer to the first occurrence
@@ -452,8 +432,7 @@ STATIC code_p available(c,vars)
return (code_p) 0; return (code_p) 0;
} }
STATIC fix_header(lp) static void fix_header(loop_p lp)
loop_p lp;
{ {
/* Check if a header block was added, and if so, add a branch to /* Check if a header block was added, and if so, add a branch to
* the entry block. * the entry block.
@@ -486,21 +465,19 @@ STATIC fix_header(lp)
} }
} }
STATIC reduce(code,vars) static void reduce(code_p code, lset vars)
code_p code;
lset vars;
{ {
/* Perform the actual transformations. The code on the left /* Perform the actual transformations. The code on the left
* gets transformed into the code on the right. Note that * gets transformed into the code on the right. Note that
* each piece of code is assigned a name, that will be * each piece of code is assigned a name, that will be
* used to describe the whole process. * used to describe the whole process.
* *
* t = iv * 118; (init_code) * t = iv * 118; (init_code)
* do ---> do * do ---> do
* .. iv * 118 .. .. t .. (new_code) * .. iv * 118 .. .. t .. (new_code)
* iv++; iv++; * iv++; iv++;
* t += 118; (incr_code) * t += 118; (incr_code)
* od od * od od
*/ */
offset tmp; offset tmp;
@@ -543,11 +520,7 @@ STATIC reduce(code,vars)
STATIC try_multiply(lp,ivs,vars,b,mul) static void try_multiply(loop_p lp, lset ivs, lset vars, bblock_p b, line_p mul)
loop_p lp;
lset ivs,vars;
bblock_p b;
line_p mul;
{ {
/* See if we can reduce the strength of the multiply /* See if we can reduce the strength of the multiply
* instruction. If so, then set up the global common * instruction. If so, then set up the global common
@@ -605,11 +578,7 @@ STATIC try_multiply(lp,ivs,vars,b,mul)
STATIC try_leftshift(lp,ivs,vars,b,shft) static void try_leftshift(loop_p lp, lset ivs, lset vars, bblock_p b, line_p shft)
loop_p lp;
lset ivs,vars;
bblock_p b;
line_p shft;
{ {
/* See if we can reduce the strength of the leftshift /* See if we can reduce the strength of the leftshift
* instruction. If so, then set up the global common * instruction. If so, then set up the global common
@@ -656,11 +625,7 @@ STATIC try_leftshift(lp,ivs,vars,b,shft)
} }
STATIC try_array(lp,ivs,vars,b,arr) static void try_array(loop_p lp, lset ivs, lset vars, bblock_p b, line_p arr)
loop_p lp;
lset ivs,vars;
bblock_p b;
line_p arr;
{ {
/* See if we can reduce the strength of the array reference /* See if we can reduce the strength of the array reference
* instruction 'arr'. * instruction 'arr'.
@@ -710,7 +675,7 @@ STATIC try_array(lp,ivs,vars,b,arr)
STATIC clean_avail() static void clean_avail()
{ {
Lindex i; Lindex i;
@@ -721,11 +686,12 @@ STATIC clean_avail()
} }
/*
strength_reduction(lp,ivs,vars) * lp ==> description of the loop
loop_p lp; /* description of the loop */ * ivs ==> set of induction variables of the loop
lset ivs; /* set of induction variables of the loop */ * vars ==> set of local variables changed in loop
lset vars; /* set of local variables changed in loop */ */
void strength_reduction(loop_p lp, lset ivs, lset vars)
{ {
/* Find all expensive instructions (leftshift, multiply, array) and see /* Find all expensive instructions (leftshift, multiply, array) and see
* if they can be reduced. We branch to several instruction-specific * if they can be reduced. We branch to several instruction-specific

View File

@@ -5,6 +5,6 @@
*/ */
/* S R _ R E D U C E . H */ /* S R _ R E D U C E . H */
extern strength_reduction(); /* (loop_p loop; lset ivs, vars) void strength_reduction(loop_p lp, lset ivs, lset vars);
* Perform streength reduction. /* Perform streength reduction.
*/ */

View File

@@ -29,9 +29,7 @@
/* Transformations on EM texts */ /* Transformations on EM texts */
line_p move_pointer(tmp,dir) line_p move_pointer(offset tmp, int dir)
offset tmp;
int dir;
{ {
/* Generate EM code to load/store a pointer variable /* Generate EM code to load/store a pointer variable
* onto/from the stack, depending on dir(ection). * onto/from the stack, depending on dir(ection).
@@ -66,9 +64,7 @@ line_p move_pointer(tmp,dir)
/* make_header */ /* make_header */
STATIC copy_loops(b1,b2,except) static void copy_loops(bblock_p b1, bblock_p b2, loop_p except)
bblock_p b1,b2;
loop_p except;
{ {
/* Copy the loopset of b2 to b1, except for 'except' */ /* Copy the loopset of b2 to b1, except for 'except' */
@@ -84,8 +80,7 @@ STATIC copy_loops(b1,b2,except)
} }
STATIC lab_id label(b) static lab_id label(bblock_p b)
bblock_p b;
{ {
/* Find the label at the head of block b. If there is /* Find the label at the head of block b. If there is
* no such label yet, create one. * no such label yet, create one.
@@ -108,8 +103,7 @@ STATIC lab_id label(b)
} }
STATIC adjust_jump(newtarg,oldtarg,c) static void adjust_jump(bblock_p newtarg, bblock_p oldtarg, bblock_p c)
bblock_p newtarg,oldtarg,c;
{ {
/* If the last instruction of c is a jump to the /* If the last instruction of c is a jump to the
* old target, then change it into a jump to the * old target, then change it into a jump to the
@@ -138,8 +132,7 @@ STATIC adjust_jump(newtarg,oldtarg,c)
} }
make_header(lp) void make_header(loop_p lp)
loop_p lp;
{ {
/* Make sure that the loop has a header block, i.e. a block /* Make sure that the loop has a header block, i.e. a block
* has the loop entry block as its only successor and * has the loop entry block as its only successor and

View File

@@ -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 /* Generate EM code to load/store a pointer variable
* onto/from the stack, depending on dir(ection). * onto/from the stack, depending on dir(ection).
* We accept all kinds of pointer sizes. * We accept all kinds of pointer sizes.
*/ */
extern make_header() ; /* (loop_p lp) */ void make_header(loop_p lp);
/* Make sure that the loop has a header block, i.e. a block /* Make sure that the loop has a header block, i.e. a block
* has the loop entry block as its only successor and * has the loop entry block as its only successor and
* that dominates the loop entry block. * that dominates the loop entry block.

View File

@@ -7,6 +7,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <em_spec.h> #include <em_spec.h>
#include "../share/types.h" #include "../share/types.h"
#include "ud.h" #include "ud.h"
@@ -39,8 +40,7 @@ int Svalue,Svariable;
cond_p globl_cond_tab,local_cond_tab; cond_p globl_cond_tab,local_cond_tab;
STATIC cond_p getcondtab(f) static cond_p getcondtab(FILE *f)
FILE *f;
{ {
int l,i; int l,i;
cond_p tab; cond_p tab;
@@ -56,11 +56,10 @@ STATIC cond_p getcondtab(f)
} }
STATIC ud_machinit(f) static int ud_machinit(void *param)
FILE *f;
{ {
char s[100]; char s[100];
FILE *f = (FILE *)param;
for (;;) { for (;;) {
while(getc(f) != '\n'); while(getc(f) != '\n');
fscanf(f,"%s",s); fscanf(f,"%s",s);
@@ -68,13 +67,13 @@ STATIC ud_machinit(f)
} }
globl_cond_tab = getcondtab(f); globl_cond_tab = getcondtab(f);
local_cond_tab = getcondtab(f); local_cond_tab = getcondtab(f);
return 0;
} }
STATIC bool test_cond(cond,val) static bool test_cond(short cond, offset val)
short cond;
offset val;
{ {
switch(cond) { switch(cond) {
case DEFAULT: case DEFAULT:
@@ -84,13 +83,11 @@ STATIC bool test_cond(cond,val)
} }
assert(FALSE); assert(FALSE);
/* NOTREACHED */ /* NOTREACHED */
return FALSE;
} }
STATIC short map_value(tab,val,time) static short map_value(struct cond_tab tab[], offset val, bool time)
struct cond_tab tab[];
offset val;
bool time;
{ {
cond_p p; cond_p p;
@@ -102,8 +99,7 @@ STATIC short map_value(tab,val,time)
} }
STATIC init_root(root) static int init_root(void *param)
bblock_p root;
{ {
/* Initialise the IN OUT sets of the entry block of the /* Initialise the IN OUT sets of the entry block of the
* current procedure. Global variables and parameters * current procedure. Global variables and parameters
@@ -112,7 +108,7 @@ STATIC init_root(root)
* to all global variables and parameters are * to all global variables and parameters are
* put in IN. * put in IN.
*/ */
bblock_p root = (bblock_p)param;
short v; short v;
for (v = 1; v <= nrglobals; v++) { for (v = 1; v <= nrglobals; v++) {
@@ -127,14 +123,14 @@ STATIC init_root(root)
Ccopy_set(IN(root),&OUT(root)); Ccopy_set(IN(root),&OUT(root));
Csubtract(KILL(root),&OUT(root)); Csubtract(KILL(root),&OUT(root));
Cjoin(GEN(root),&OUT(root)); Cjoin(GEN(root),&OUT(root));
return 0;
} }
STATIC unite_outs(bbset,setp) static void unite_outs(lset bbset, cset *setp)
lset bbset;
cset *setp;
{ {
/* Take the union of OUT(b), for all b in bbset, /* Take the union of OUT(b), for all b in bbset,
* and put the result in setp. * and put the result in setp.
@@ -150,8 +146,7 @@ STATIC unite_outs(bbset,setp)
STATIC solve_equations(p) static void solve_equations(proc_p p)
proc_p p;
{ {
/* Solve the data flow equations for reaching /* Solve the data flow equations for reaching
* definitions of procedure p. * definitions of procedure p.
@@ -163,7 +158,7 @@ STATIC solve_equations(p)
* solve the equations. * solve the equations.
*/ */
register bblock_p b; bblock_p b;
bool change; bool change;
cset newin; cset newin;
@@ -203,14 +198,13 @@ STATIC solve_equations(p)
short global_addr_cost() static short global_addr_cost()
{ {
return add_timespace(map_value(globl_cond_tab,(offset) 0,TRUE), return add_timespace(map_value(globl_cond_tab,(offset) 0,TRUE),
map_value(globl_cond_tab,(offset) 0,FALSE)); map_value(globl_cond_tab,(offset) 0,FALSE));
} }
short local_addr_cost(off) short local_addr_cost(offset off)
offset off;
{ {
return add_timespace(map_value(local_cond_tab,off,TRUE), return add_timespace(map_value(local_cond_tab,off,TRUE),
map_value(local_cond_tab,off,FALSE)); map_value(local_cond_tab,off,FALSE));
@@ -218,8 +212,7 @@ short local_addr_cost(off)
STATIC bool fold_is_desirable(old,new) static bool fold_is_desirable(line_p old, line_p new)
line_p old,new;
{ {
/* See if it is desirable to replace the variable used by the /* See if it is desirable to replace the variable used by the
* EM instruction 'old' by the variable used by 'new'. * EM instruction 'old' by the variable used by 'new'.
@@ -264,7 +257,8 @@ STATIC bool fold_is_desirable(old,new)
#ifdef TRACE #ifdef TRACE
/*********** TRACING ROUTINES ***********/ /*********** TRACING ROUTINES ***********/
pr_localtab() { static void pr_localtab()
{
short i; short i;
local_p lc; local_p lc;
@@ -278,7 +272,7 @@ pr_localtab() {
} }
} }
pr_globals() void pr_globals()
{ {
dblock_p d; dblock_p d;
obj_p obj; obj_p obj;
@@ -296,7 +290,7 @@ pr_globals()
extern char em_mnem[]; extern char em_mnem[];
pr_defs() static void pr_defs()
{ {
short i; short i;
line_p l; line_p l;
@@ -323,10 +317,7 @@ pr_defs()
} }
pr_set(name,k,s,n) static void pr_set(char *name, short k, cset s, short n)
char *name;
cset s;
short k,n;
{ {
short i; short i;
@@ -339,8 +330,7 @@ pr_set(name,k,s,n)
printf ("}\n"); printf ("}\n");
} }
pr_blocks(p) static void pr_blocks(proc_p p)
proc_p p;
{ {
bblock_p b; bblock_p b;
short n; short n;
@@ -356,7 +346,7 @@ pr_blocks(p)
} }
} }
pr_copies() static void pr_copies()
{ {
short i; short i;
@@ -368,8 +358,7 @@ pr_copies()
} }
} }
pr_cblocks(p) static void pr_cblocks(proc_p p)
proc_p p;
{ {
bblock_p b; bblock_p b;
short n; short n;
@@ -388,8 +377,7 @@ pr_cblocks(p)
#endif #endif
STATIC ud_analysis(p) static void ud_analysis(proc_p p)
proc_p p;
{ {
/* Perform use-definition analysis on procedure p */ /* Perform use-definition analysis on procedure p */
@@ -413,27 +401,25 @@ STATIC ud_analysis(p)
STATIC clean_maps() static void clean_maps()
{ {
local_p *p; local_p *p;
cset *v; cset *v;
oldmap(defs,nrexpldefs); oldmap((short **)defs,nrexpldefs);
for (p = &locals[1]; p <= &locals[nrlocals]; p++) { for (p = &locals[1]; p <= &locals[nrlocals]; p++) {
oldlocal(*p); oldlocal(*p);
} }
oldmap(locals,nrlocals); oldmap((short **)locals,nrlocals);
for (v = &vardefs[1]; v <= &vardefs[nrvars]; v++) { for (v = &vardefs[1]; v <= &vardefs[nrvars]; v++) {
Cdeleteset(*v); Cdeleteset(*v);
} }
oldmap(vardefs,nrvars); oldmap((short **)vardefs,nrvars);
} }
STATIC bool try_optim(l,b) static bool try_optim(line_p l, bblock_p b)
line_p l;
bblock_p b;
{ {
/* Try copy propagation and constant propagation */ /* Try copy propagation and constant propagation */
@@ -467,8 +453,7 @@ STATIC bool try_optim(l,b)
value_propagation(p) void value_propagation(proc_p p)
proc_p p;
{ {
/* Apply value propagation to procedure p */ /* Apply value propagation to procedure p */
@@ -493,13 +478,12 @@ value_propagation(p)
} }
} }
} }
oldmap(copies,nrcopies); oldmap((short **)copies,nrcopies);
oldtable(def_to_copynr,nrdefs); oldtable((short **)def_to_copynr,nrdefs);
} }
STATIC ud_extend(p) static void ud_extend(proc_p p)
proc_p p;
{ {
/* Allocate extended data structures for Use Definition analysis */ /* Allocate extended data structures for Use Definition analysis */
@@ -511,8 +495,7 @@ STATIC ud_extend(p)
} }
STATIC ud_cleanup(p) static void ud_cleanup(proc_p p)
proc_p p;
{ {
/* Deallocate extended data structures for Use Definition analysis */ /* Deallocate extended data structures for Use Definition analysis */
@@ -531,10 +514,10 @@ STATIC ud_cleanup(p)
} }
ud_optimize(p) static int ud_optimize(void *param)
proc_p p;
{ {
if (IS_ENTERED_WITH_GTO(p)) return; proc_p p = (proc_p)param;
if (IS_ENTERED_WITH_GTO(p)) return 0;
ud_extend(p); ud_extend(p);
locals = (local_p *) 0; locals = (local_p *) 0;
vardefs = (cset *) 0; vardefs = (cset *) 0;
@@ -548,6 +531,8 @@ ud_optimize(p)
value_propagation(p); value_propagation(p);
ud_cleanup(p); ud_cleanup(p);
clean_maps(); clean_maps();
return 0;
} }
main(argc,argv) main(argc,argv)

View File

@@ -24,9 +24,7 @@
#include "../share/aux.h" #include "../share/aux.h"
#include "ud_defs.h" #include "ud_defs.h"
repl_line(old,new,b) void repl_line(line_p old, line_p new, bblock_p b)
line_p old,new;
bblock_p b;
{ {
/* Replace 'old' by 'new' */ /* Replace 'old' by 'new' */
@@ -44,8 +42,7 @@ repl_line(old,new,b)
bool same_var(use,def) bool same_var(line_p use, line_p def)
line_p use,def;
{ {
/* 'use' is an instruction that uses a variable /* 'use' is an instruction that uses a variable
* for which we maintain ud-info (e.g. a LOL). * for which we maintain ud-info (e.g. a LOL).

View File

@@ -10,13 +10,13 @@
*/ */
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 /* Replace EM instruction 'old' by a
* copy of 'new'. Update doubly-linked * copy of 'new'. Update doubly-linked
* list. * 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 /* 'use' is an instruction that uses a variable
* for which we maintain ud-info (e.g. a LOL). * for which we maintain ud-info (e.g. a LOL).
* See if 'def' references the same variable. * See if 'def' references the same variable.
*/ */

View File

@@ -27,8 +27,7 @@
#define CALLS_UNKNOWN(p) (p->p_flags1 & (byte) PF_CALUNKNOWN) #define CALLS_UNKNOWN(p) (p->p_flags1 & (byte) PF_CALUNKNOWN)
bool is_use(l) bool is_use(line_p l)
line_p l;
{ {
/* See if 'l' is a use of a variable */ /* See if 'l' is a use of a variable */
@@ -42,14 +41,13 @@ bool is_use(l)
return FALSE; return FALSE;
} }
/* NOTREACHED */ /* NOTREACHED */
return FALSE;
} }
bool value_known(def,val_out) bool value_known(line_p def, offset *val_out)
line_p def;
offset *val_out;
{ {
/* See if the value stored by definition 'def' /* See if the value stored by definition 'def'
* is known statically (i.e. is a constant). * is known statically (i.e. is a constant).
@@ -109,9 +107,7 @@ bool value_known(def,val_out)
bool affected(use,v,l) bool affected(line_p use, short v, line_p l)
line_p use,l;
short v;
{ {
/* See if the variable referenced by 'use' may be /* See if the variable referenced by 'use' may be
* changed by instruction l, which is either a cal, cai or * changed by instruction l, which is either a cal, cai or
@@ -131,10 +127,7 @@ bool affected(use,v,l)
STATIC search_backwards(use,v,found,def) static void search_backwards(line_p use, short v, bool *found, line_p *def)
line_p use, *def;
short v;
bool *found;
{ {
/* Search backwards in the current basic block, /* Search backwards in the current basic block,
* starting at 'use', trying to find a definition * starting at 'use', trying to find a definition
@@ -163,8 +156,7 @@ STATIC search_backwards(use,v,found,def)
STATIC short outer_def(vdefs,in) static short outer_def(cset vdefs, cset in)
cset vdefs, in;
{ {
/* See if there is a unique definition of variable /* See if there is a unique definition of variable
* v reaching the beginning of block b. * v reaching the beginning of block b.
@@ -188,10 +180,7 @@ STATIC short outer_def(vdefs,in)
line_p unique_def(use,b,defnr_out) line_p unique_def(line_p use, bblock_p b, short *defnr_out)
line_p use;
bblock_p b;
short *defnr_out;
{ {
/* See if there is one unique explicit definition /* See if there is one unique explicit definition
* of the variable used by 'use', that reaches 'use'. * of the variable used by 'use', that reaches 'use'.
@@ -223,10 +212,7 @@ line_p unique_def(use,b,defnr_out)
fold_const(l,b,val) void fold_const(line_p l, bblock_p b, offset val)
line_p l;
bblock_p b;
offset val;
{ {
/* Perform the substitutions required for constant folding */ /* Perform the substitutions required for constant folding */

View File

@@ -6,24 +6,24 @@
/* C O N S T A N T P R O P A G A T I O N */ /* 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 /* See if there is a unique explicit definition
* of the variable used by 'use' that * of the variable used by 'use' that
* reaches 'use'. * 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' /* See if the value stored by definition 'def'
* is known statically (i.e. is a constant). * 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 /* Perform the substitutions required for
* constant folding. * constant folding.
*/ */
extern bool is_use(); /* (line_p l) bool is_use(line_p l);
* See if 'l' is a use of a variable. /* 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 /* See if the variable referenced by 'use' may
* be changed by instruction l, which is * be changed by instruction l, which is
* either a cal, cai or an indirect assignment. * either a cal, cai or an indirect assignment.
*/ */

View File

@@ -42,9 +42,7 @@ short nrcopies; /* number of copies in the current procedure
#define COUNT 0 #define COUNT 0
#define MAP 1 #define MAP 1
STATIC traverse_defs(p,action) static void traverse_defs(proc_p p, int action)
proc_p p;
int action;
{ {
bblock_p b; bblock_p b;
line_p l; line_p l;
@@ -83,8 +81,7 @@ STATIC traverse_defs(p,action)
STATIC make_copytab(p) static void make_copytab(proc_p p)
proc_p p;
{ {
/* Make a table of all copies appearing in procedure p. /* Make a table of all copies appearing in procedure p.
* We first count how many there are, because we * We first count how many there are, because we
@@ -97,14 +94,13 @@ STATIC make_copytab(p)
STATIC bool is_changed(varl,start,stop) static bool is_changed(line_p varl, line_p start, line_p stop)
line_p varl, start, stop;
{ {
/* See if the variable used by instruction varl /* See if the variable used by instruction varl
* is changed anywhere between 'start' and 'stop' * is changed anywhere between 'start' and 'stop'
*/ */
register line_p l; line_p l;
short v; short v;
bool found; bool found;
@@ -121,15 +117,14 @@ STATIC bool is_changed(varl,start,stop)
STATIC gen_kill_copies(p) static void gen_kill_copies(proc_p p)
proc_p p;
{ {
/* Compute C_GEN and C_KILL for every basic block /* Compute C_GEN and C_KILL for every basic block
* of p. * of p.
*/ */
register line_p l; line_p l;
register bblock_p b,n; bblock_p b,n;
short v; short v;
bool found; bool found;
short copycnt = 1, defcnt = 1; short copycnt = 1, defcnt = 1;
@@ -165,9 +160,7 @@ STATIC gen_kill_copies(p)
STATIC intersect_outs(bbset,setp,full_set) static void intersect_outs(lset bbset, cset *setp, cset full_set)
lset bbset;
cset *setp,full_set;
{ {
/* Take the intersection of C_OUT(b), for all b in bbset, /* Take the intersection of C_OUT(b), for all b in bbset,
* and put the result in setp. * and put the result in setp.
@@ -183,9 +176,7 @@ STATIC intersect_outs(bbset,setp,full_set)
STATIC init_cin(p,full_set) static void init_cin(proc_p p, cset full_set)
proc_p p;
cset full_set;
{ {
/* Initialize C_IN(b) and C_OUT(b), for every basic block b. /* Initialize C_IN(b) and C_OUT(b), for every basic block b.
* C_IN of the root of the CFG (i.e. the procedure entry block) * C_IN of the root of the CFG (i.e. the procedure entry block)
@@ -218,8 +209,7 @@ STATIC init_cin(p,full_set)
STATIC solve_cin(p) static void solve_cin(proc_p p)
proc_p p;
{ {
/* Solve the data flow equations for reaching /* Solve the data flow equations for reaching
* definitions of procedure p. * definitions of procedure p.
@@ -233,7 +223,7 @@ STATIC solve_cin(p)
* solve the equations. * solve the equations.
*/ */
register bblock_p b; bblock_p b;
bool change; bool change;
cset newin,full_set; cset newin,full_set;
short n; short n;
@@ -267,8 +257,7 @@ STATIC solve_cin(p)
copy_analysis(p) void copy_analysis(proc_p p)
proc_p p;
{ {
/* Determine which copies procedure p has. Compute C_IN(b), /* Determine which copies procedure p has. Compute C_IN(b),
* for every basic block b. * for every basic block b.
@@ -281,8 +270,7 @@ copy_analysis(p)
bool is_copy(def) bool is_copy(line_p def)
line_p def;
{ {
/* See if the definition def is also a 'copy', i.e. an /* See if the definition def is also a 'copy', i.e. an
* statement of the form 'A := B' (or, in EM terminology: * statement of the form 'A := B' (or, in EM terminology:
@@ -311,9 +299,7 @@ bool is_copy(def)
fold_var(old,new,b) void fold_var(line_p old, line_p new, bblock_p b)
line_p old, new;
bblock_p b;
{ {
/* The variable referenced by the EM instruction 'old' /* The variable referenced by the EM instruction 'old'
* must be replaced by the variable referenced by 'new'. * must be replaced by the variable referenced by 'new'.
@@ -369,10 +355,7 @@ END DEBUG */
bool value_retained(copy,defnr,use,b) bool value_retained(line_p copy, short defnr, line_p use, bblock_p b)
line_p copy,use;
short defnr;
bblock_p b;
{ {
/* See if the right hand side variable of the /* See if the right hand side variable of the
* copy still has the same value at 'use'. * copy still has the same value at 'use'.

View File

@@ -16,23 +16,23 @@ extern short nrcopies; /* number of copies in the current procedure
* (length of copies-table) * (length of copies-table)
*/ */
extern copy_analysis(); /* (proc_p p) void copy_analysis(proc_p p);
* Determine which copies procedure p has. /* Determine which copies procedure p has.
* Compute C_IN(b), for every basic block b. * 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', /* See if the definition def is also a 'copy',
* i.e. an statement of the form * i.e. an statement of the form
* 'A := B' (or, in EM terminology: * 'A := B' (or, in EM terminology:
* a sequence 'Load Variable; Store Variable'). * 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 /* The variable referenced by the
* EM instruction 'old' must be replaced * EM instruction 'old' must be replaced
* by the variable referenced by 'new'. * by the variable referenced by 'new'.
*/ */
extern bool value_retained(); /* (line_p copy; short defnr; line_p use; bool value_retained(line_p copy, short defnr, line_p use, bblock_p b);
* bblock_p b) /* bblock_p b)
* See if the right hand side variable of the * See if the right hand side variable of the
* copy still has the same value at 'use'. * copy still has the same value at 'use'.
* If the copy and the use are in the same * If the copy and the use are in the same

View File

@@ -27,12 +27,11 @@ short nrexpldefs; /* number of explicit definitions */
line_p *defs; line_p *defs;
cset *vardefs; cset *vardefs;
STATIC cset all_globl_defs, all_indir_defs; static cset all_globl_defs, all_indir_defs;
/* auxiliary sets, used by gen_sets */ /* auxiliary sets, used by gen_sets */
bool does_expl_def(l) bool does_expl_def(line_p l)
line_p l;
{ {
/* See if instruction l does an explicit definition */ /* See if instruction l does an explicit definition */
@@ -52,12 +51,12 @@ bool does_expl_def(l)
return FALSE; return FALSE;
} }
/* NOTREACHED */ /* NOTREACHED */
return FALSE;
} }
bool does_impl_def(l) bool does_impl_def(line_p l)
line_p l;
{ {
/* See if instruction l does an implicit definition */ /* See if instruction l does an implicit definition */
@@ -77,11 +76,11 @@ bool does_impl_def(l)
default: default:
return FALSE; return FALSE;
} }
return FALSE;
} }
make_defs(p) void make_defs(proc_p p)
proc_p p;
{ {
/* Make a map of all explicit definitions /* Make a map of all explicit definitions
* occurring in p. * occurring in p.
@@ -93,8 +92,8 @@ make_defs(p)
* explicit definition. * explicit definition.
*/ */
register bblock_p b; bblock_p b;
register line_p l; line_p l;
short v, i, cnt = 0; short v, i, cnt = 0;
bool found; bool found;
@@ -134,8 +133,7 @@ make_defs(p)
STATIC init_gen(nrdefs) static void init_gen(short nrdefs)
short nrdefs;
{ {
/* Initializing routine of gen_sets. Compute the set /* Initializing routine of gen_sets. Compute the set
* of all implicit definitions to global variables * of all implicit definitions to global variables
@@ -161,7 +159,7 @@ STATIC init_gen(nrdefs)
STATIC clean_gen() static void clean_gen()
{ {
Cdeleteset(all_globl_defs); Cdeleteset(all_globl_defs);
Cdeleteset(all_indir_defs); Cdeleteset(all_indir_defs);
@@ -169,9 +167,7 @@ STATIC clean_gen()
STATIC bool same_target(l,defnr) static bool same_target(line_p l, short defnr)
line_p l;
short defnr;
{ {
/* See if l defines the same variable as def */ /* See if l defines the same variable as def */
@@ -200,9 +196,7 @@ STATIC bool same_target(l,defnr)
STATIC rem_prev_defs(l,gen_p) static void rem_prev_defs(line_p l, cset *gen_p)
line_p l;
cset *gen_p;
{ {
/* Remove all definitions in gen that define the /* Remove all definitions in gen that define the
* same variable as l. * same variable as l.
@@ -223,9 +217,7 @@ STATIC rem_prev_defs(l,gen_p)
STATIC impl_globl_defs(p,gen_p) static void impl_globl_defs(proc_p p, cset *gen_p)
proc_p p;
cset *gen_p;
{ {
/* Add all definitions of global variables /* Add all definitions of global variables
* that are generated implicitly by a call * that are generated implicitly by a call
@@ -249,9 +241,7 @@ STATIC impl_globl_defs(p,gen_p)
STATIC impl_gen_defs(l,gen_p) static void impl_gen_defs(line_p l, cset *gen_p)
line_p l;
cset *gen_p;
{ {
/* Add all definitions generated implicitly by instruction l /* Add all definitions generated implicitly by instruction l
* to gen_p. l may be a call or some kind of indirect * to gen_p. l may be a call or some kind of indirect
@@ -287,16 +277,15 @@ STATIC impl_gen_defs(l,gen_p)
gen_sets(p) void gen_sets(proc_p p)
proc_p p;
{ {
/* Compute for every basic block b of p the /* Compute for every basic block b of p the
* set GEN(b) of definitions in b (explicit as * set GEN(b) of definitions in b (explicit as
* well as implicit) that reach the end of b. * well as implicit) that reach the end of b.
*/ */
register bblock_p b; bblock_p b;
register line_p l; line_p l;
short defnr = 1; short defnr = 1;
init_gen(nrdefs); /* compute all_globl_defs and all_indir_defs */ init_gen(nrdefs); /* compute all_globl_defs and all_indir_defs */
@@ -329,9 +318,7 @@ gen_sets(p)
STATIC killed_defs(v,b) static void killed_defs(short v, bblock_p b)
short v;
bblock_p b;
{ {
/* Put all definitions of v occurring outside b /* Put all definitions of v occurring outside b
* in KILL(b). In fact, we also put explicit * in KILL(b). In fact, we also put explicit
@@ -355,8 +342,7 @@ STATIC killed_defs(v,b)
kill_sets(p) void kill_sets(proc_p p)
proc_p p;
{ {
/* For every basic block b of p compute the set /* For every basic block b of p compute the set
* KILL(b) of definitions outside b that define * KILL(b) of definitions outside b that define
@@ -365,7 +351,7 @@ kill_sets(p)
* definitions. * definitions.
*/ */
register bblock_p b; bblock_p b;
Cindex i; Cindex i;
short v; short v;

View File

@@ -13,22 +13,22 @@ extern short nrexpldefs; /* number of explicit definitions */
extern line_p *defs; /* map of explicit definitions */ extern line_p *defs; /* map of explicit definitions */
extern cset *vardefs; /* set of explicit defs. of all variables */ 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[] /* Compute defs[], vardefs[]
* and CHGVARS(b) (for every b). * and CHGVARS(b) (for every b).
*/ */
extern gen_sets(); /* (proc_p p) void gen_sets(proc_p p);
* Compute GEN(b) (for every b). /* Compute GEN(b) (for every b).
*/ */
extern kill_sets(); /* (proc_p p) void kill_sets(proc_p p);
*Compute KILL(b) (for every b). /*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 /* See if instruction l does an explicit
* definition (e.g. a STL). * 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 /* See if instruction l does an implicit
* definition (e.g. a CAL). * definition (e.g. a CAL).
*/ */

View File

@@ -13,15 +13,15 @@ static char rcsid[] = "$Id$";
#include "ranlib.h" #include "ranlib.h"
#include "const.h" #include "const.h"
#include "debug.h" #include "debug.h"
#include "defs.h"
#include "memory.h" #include "memory.h"
#include "defs.h"
#define ENDLIB ((long)0) #define ENDLIB ((long)0)
extern ind_t hard_alloc();
static struct ar_hdr arhdr; static struct ar_hdr arhdr;
static void notelib(long pos);
/* /*
* First read a long telling how many ranlib structs there are, then * First read a long telling how many ranlib structs there are, then
* the structs themselves. Second read a long telling how many chars there are * the structs themselves. Second read a long telling how many chars there are
@@ -29,25 +29,24 @@ static struct ar_hdr arhdr;
* We keep only one ranlib table in core, so this table always starts at offset * We keep only one ranlib table in core, so this table always starts at offset
* (ind_t)0 from its base. * (ind_t)0 from its base.
*/ */
static long static long getsymdeftable()
getsymdeftable()
{ {
register ind_t off; ind_t off;
register struct ranlib *ran; struct ranlib *ran;
register long count; long count;
register long nran, nchar; long nran, nchar;
extern long rd_long(); extern long rd_long();
extern int infile; extern int infile;
count = nran = rd_long(infile); count = nran = rd_long(infile);
debug("%ld ranlib structs, ", nran, 0, 0, 0); debug("%ld ranlib structs, ", nran);
off = hard_alloc(ALLORANL, nran * sizeof(struct ranlib)); off = hard_alloc(ALLORANL, nran * sizeof(struct ranlib));
if (off == BADOFF) if (off == BADOFF)
fatal("no space for ranlib structs"); fatal("no space for ranlib structs");
ran = (struct ranlib *)address(ALLORANL, off); ran = (struct ranlib *)address(ALLORANL, off);
rd_ranlib(infile, ran, count); rd_ranlib(infile, ran, count);
nchar = rd_long(infile); nchar = rd_long(infile);
debug("%ld ranlib chars\n", nchar, 0, 0, 0); debug("%ld ranlib chars\n", nchar);
if ((off = hard_alloc(ALLORANL, nchar)) == BADOFF) if ((off = hard_alloc(ALLORANL, nchar)) == BADOFF)
fatal("no space for ranlib strings"); fatal("no space for ranlib strings");
rd_bytes(infile, address(ALLORANL, off), nchar); rd_bytes(infile, address(ALLORANL, off), nchar);
@@ -77,7 +76,7 @@ extern char *modulname;
* scan the table again. We perform these actions as long as new symbols * scan the table again. We perform these actions as long as new symbols
* are defined. * are defined.
*/ */
arch() void arch()
{ {
long nran; long nran;
bool resolved; bool resolved;
@@ -89,7 +88,7 @@ arch()
register ind_t ranindex; register ind_t ranindex;
register long count; register long count;
debug("(re)scan ranlib table\n", 0, 0, 0, 0); debug("(re)scan ranlib table\n");
ranindex = (ind_t)0; ranindex = (ind_t)0;
count = nran; count = nran;
resolved = FALSE; resolved = FALSE;
@@ -112,7 +111,7 @@ arch()
seek(ran->ran_pos); seek(ran->ran_pos);
get_archive_header(&arhdr); get_archive_header(&arhdr);
modulname = arhdr.ar_name; modulname = arhdr.ar_name;
verbose("defines %s", string, 0, 0, 0); verbose("defines %s", string);
resolved = TRUE; resolved = TRUE;
/* /*
* This archive member is going to be linked, * This archive member is going to be linked,
@@ -139,10 +138,9 @@ arch()
* An archive member that will be loaded is remembered by storing its position * An archive member that will be loaded is remembered by storing its position
* in the archive into the table of positions. * in the archive into the table of positions.
*/ */
notelib(pos) static void notelib(long pos)
long pos;
{ {
register ind_t off; ind_t off;
if ((off = hard_alloc(ALLOARCH, (long)sizeof(long))) == BADOFF) if ((off = hard_alloc(ALLOARCH, (long)sizeof(long))) == BADOFF)
fatal("no space for archive position"); fatal("no space for archive position");
@@ -161,10 +159,10 @@ static ind_t posindex = (ind_t)0;
* that we've processed all needed modules in this archive. Each group of * that we've processed all needed modules in this archive. Each group of
* positions of an archive is terminated with ENDLIB. * positions of an archive is terminated with ENDLIB.
*/ */
arch2() void arch2()
{ {
register long *pos; long *pos;
register ind_t localpos; ind_t localpos;
localpos = posindex; localpos = posindex;
for ( pos = (long *)address(ALLOARCH, localpos); for ( pos = (long *)address(ALLOARCH, localpos);
@@ -174,7 +172,7 @@ arch2()
seek(*pos); seek(*pos);
get_archive_header(&arhdr); get_archive_header(&arhdr);
modulname = arhdr.ar_name; modulname = arhdr.ar_name;
debug("%s: archive member\n", modulname, 0, 0, 0); debug("%s: archive member\n", modulname);
finish(); finish();
} }
localpos += sizeof(long); /* Skip ENDLIB. */ localpos += sizeof(long); /* Skip ENDLIB. */

View File

@@ -6,14 +6,14 @@
#ifdef NDEBUG #ifdef NDEBUG
#define debug(s, a1, a2, a3, a4) #define debug(s)
#else #else
extern int DEB; extern int DEB;
#define debug(s, a1, a2, a3, a4) (DEB && printf(s, a1, a2, a3, a4)) #define debug(s...) (DEB && printf(s))
#endif #endif
extern int Verbose; extern int Verbose;
#define verbose(s, a1, a2, a3, a4) (Verbose && do_verbose(s, a1, a2, a3, a4)) #define verbose(s...) (Verbose && do_verbose(s))

View File

@@ -12,3 +12,73 @@
#define ISCOMMON(n) (((n)->on_type & (S_COM | S_EXT)) == (S_COM | S_EXT)) #define ISCOMMON(n) (((n)->on_type & (S_COM | S_EXT)) == (S_COM | S_EXT))
#define mustsavelocal(name) (!((name)->on_type & S_SCT)) #define mustsavelocal(name) (!((name)->on_type & S_SCT))
/* archive.c */
void arch();
void arch2();
/* extract.c */
void extract();
void namerelocate(struct outname *name);
/* finish.c */
void finish();
void do_crs(struct outname *base, unsigned int count);
/* main.c */
bool setbit(int indx, char *string);
void addbase(struct outname *name);
/* output.c */
void endoutput();
void beginoutput();
/* error.c */
void stop();
void fatal(char *format, ...);
void warning(char *format, ...);
void error(char *format, ...);
int do_verbose(char *format, ...);
/* read.c */
void rd_fatal();
/* write.c */
void wr_fatal();
void begin_write();
void end_write();
void wrt_emit(char *emit, int sectindex, long cnt);
void wrt_nulls(int sectindex, long cnt);
void wrt_name(struct outname *name, int writename);
/* sym.c */
void init_symboltable();
struct outname *searchname(char *string, int hashval);
void entername(struct outname *name, int hashval);
unsigned int indexof(struct outname *name);
int hash(char *p);
/* save.c */
void savemagic();
void savehdr(struct ar_hdr * hdr);
ind_t savechar(int piece, ind_t off);
void savelocal(struct outname *name);
/* relocate.c */
void relocate(struct outhead *head, char *emit, struct outname names[], struct outrelo *relo, long off);
/* scan.c */
int getfile(char *filename);
void closefile(char *filename);
void get_archive_header(struct ar_hdr *archive_header);
void get_modul();
void seek(long pos);
void skip_modul(struct outhead *head);
void startrelo(struct outhead *head);
struct outrelo *nextrelo();
char *getemit(struct outhead *head, struct outsect *sects, int sectindex);
char *getblk(long totalsz, long *pblksz, int sectindex);
void endemit(char *emit);
/* --- */

View File

@@ -15,7 +15,7 @@ static char rcsid[] = "$Id$";
static short nerrors = 0; static short nerrors = 0;
static void diag(char *, char *, va_list); static void diag(char *, char *, va_list);
stop() void stop()
{ {
extern char *outputname; extern char *outputname;
extern int exitstatus; extern int exitstatus;
@@ -29,8 +29,7 @@ stop()
} }
/* VARARGS1 */ /* VARARGS1 */
void void fatal(char *format, ...)
fatal(char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@@ -40,8 +39,7 @@ fatal(char *format, ...)
} }
/* VARARGS1 */ /* VARARGS1 */
void void warning(char *format, ...)
warning(char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@@ -50,8 +48,7 @@ warning(char *format, ...)
} }
/* VARARGS1 */ /* VARARGS1 */
void void error(char *format, ...)
error(char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
@@ -61,17 +58,16 @@ error(char *format, ...)
} }
/* VARARGS1 */ /* VARARGS1 */
void int do_verbose(char *format, ...)
do_verbose(char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
diag((char *) 0, format, ap); diag((char *) 0, format, ap);
va_end(ap); va_end(ap);
return (0==0);
} }
static void static void diag(char *tail, char *format, va_list ap)
diag(char *tail, char *format, va_list ap)
{ {
extern char *progname, *archname, *modulname; extern char *progname, *archname, *modulname;

View File

@@ -8,25 +8,25 @@ static char rcsid[] = "$Id$";
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "arch.h"
#include "out.h" #include "out.h"
#include "const.h" #include "const.h"
#include "debug.h" #include "debug.h"
#include "defs.h"
#include "memory.h" #include "memory.h"
#include "orig.h" #include "orig.h"
#include "scan.h" #include "scan.h"
#include "defs.h"
static get_names(); static void get_names(struct outhead *head);
static process(); static void process(struct outhead *head);
static getexternal(); static void getexternal(struct outname *name);
static redefine(); static void redefine(struct outname *new, struct outname *old);
static transfer(); static void transfer(struct outname *src, struct outname *dst);
extern ind_t savechar();
/* /*
* Get section sizes and symboltable information from present module. * Get section sizes and symboltable information from present module.
*/ */
extract() void extract()
{ {
struct outhead head; struct outhead head;
@@ -49,9 +49,7 @@ unsigned short NGlobals = 0; /* Number of global names. */
* appear in the final output file if this module is linked. * appear in the final output file if this module is linked.
* That number will be returned. * That number will be returned.
*/ */
static static void get_names(struct outhead *head)
get_names(head)
register struct outhead *head;
{ {
register int nnames; register int nnames;
register ind_t nameindex, charindex; register ind_t nameindex, charindex;
@@ -105,14 +103,12 @@ get_names(head)
extern struct orig relorig[]; extern struct orig relorig[];
static static void process(struct outhead *head)
process(head)
register struct outhead *head;
{ {
register struct outsect *sects; struct outsect *sects;
register struct outsect *outsp; struct outsect *outsp;
register int nsect; int nsect;
register struct orig *orig = relorig; struct orig *orig = relorig;
extern struct outhead outhead; extern struct outhead outhead;
extern struct outsect outsect[]; extern struct outsect outsect[];
@@ -149,11 +145,10 @@ process(head)
* Otherwise we just add the accumulated size of all normal parts in preceding * Otherwise we just add the accumulated size of all normal parts in preceding
* sections with the same size. * sections with the same size.
*/ */
namerelocate(name) void namerelocate(struct outname *name)
register struct outname *name;
{ {
register int type = name->on_type; int type = name->on_type;
register int sct = type & S_TYP; int sct = type & S_TYP;
if (sct == S_UND || sct == S_ABS || sct == S_CRS) if (sct == S_UND || sct == S_ABS || sct == S_CRS)
return; return;
@@ -170,9 +165,7 @@ namerelocate(name)
* we might need it later on. Otherwise it must confirm to what we already * we might need it later on. Otherwise it must confirm to what we already
* know about it, and eventually add to that knowledge. * know about it, and eventually add to that knowledge.
*/ */
static static void getexternal(struct outname *name)
getexternal(name)
register struct outname *name;
{ {
register char *string; register char *string;
register int h; register int h;
@@ -213,9 +206,7 @@ getexternal(name)
* greatest value so that the common declared name always has enough space. * greatest value so that the common declared name always has enough space.
* If a common is defined as a not-common, the old definition is ignored. * If a common is defined as a not-common, the old definition is ignored.
*/ */
static static void redefine(struct outname *new, struct outname *old)
redefine(new, old)
register struct outname *new, *old;
{ {
if (!ISCOMMON(old)) { if (!ISCOMMON(old)) {
if (!ISCOMMON(new)) if (!ISCOMMON(new))
@@ -241,11 +232,9 @@ redefine(new, old)
/* /*
* Transfer things we want to know from `src' to `dst'. * Transfer things we want to know from `src' to `dst'.
*/ */
static static void transfer(struct outname *src, struct outname *dst)
transfer(src, dst)
register struct outname *src, *dst;
{ {
debug("%s defined here\n", src->on_mptr, 0, 0, 0); debug("%s defined here\n", src->on_mptr);
dst->on_valu = src->on_valu; dst->on_valu = src->on_valu;
dst->on_type = src->on_type; dst->on_type = src->on_type;
dst->on_desc = src->on_desc; dst->on_desc = src->on_desc;

View File

@@ -8,28 +8,29 @@ static char rcsid[] = "$Id$";
#include <out.h> #include <out.h>
#include "const.h" #include "const.h"
#include "defs.h" #include "arch.h"
#include "memory.h" #include "memory.h"
#include "defs.h"
#include "orig.h" #include "orig.h"
#include "scan.h" #include "scan.h"
extern bool incore; extern bool incore;
extern unsigned short NLocals; extern unsigned short NLocals;
extern int flagword; extern int flagword;
extern struct outname *searchname();
static adjust_names(); static void adjust_names(struct outname *name, struct outhead *head, char *chars);
static handle_relos(); static void handle_relos(struct outhead *head, struct outsect *sects, struct outname *names);
static put_locals(); static void put_locals(struct outname *name, unsigned int nnames);
static compute_origins(); static void compute_origins(struct outsect *sect, unsigned int nsect);
static put_dbug(long offdbug);
/* /*
* We know all there is to know about the current module. * We know all there is to know about the current module.
* Now we relocate the values in the emitted bytes and write * Now we relocate the values in the emitted bytes and write
* those to the final output file. Then we compute the relative origins * those to the final output file. Then we compute the relative origins
* for the next module. * for the next module.
*/ */
finish() void finish()
{ {
struct outhead *head; struct outhead *head;
struct outsect *sects; struct outsect *sects;
@@ -56,14 +57,10 @@ finish()
/* /*
* Adjust all local names for the move into core. * Adjust all local names for the move into core.
*/ */
static static void adjust_names(struct outname *name, struct outhead *head, char *chars)
adjust_names(name, head, chars)
register struct outname *name;
struct outhead *head;
register char *chars;
{ {
register int cnt; int cnt;
register long charoff; long charoff;
struct outname *base = name; struct outname *base = name;
cnt = head->oh_nname; cnt = head->oh_nname;
@@ -78,11 +75,9 @@ adjust_names(name, head, chars)
} }
} }
do_crs(base, count) void do_crs(struct outname *base, unsigned int count)
struct outname *base;
unsigned count;
{ {
register struct outname *name = base; struct outname *name = base;
while (count--) { while (count--) {
if ((name->on_type & S_TYP) == S_CRS) { if ((name->on_type & S_TYP) == S_CRS) {
@@ -113,16 +108,12 @@ do_crs(base, count)
* the relocation table again, because the relocation entries of one section * the relocation table again, because the relocation entries of one section
* need not be consecutive. * need not be consecutive.
*/ */
static static void handle_relos(struct outhead *head, struct outsect *sects, struct outname *names)
handle_relos(head, sects, names)
struct outhead *head;
struct outsect *sects;
struct outname *names;
{ {
register struct outrelo *relo; struct outrelo *relo;
register int sectindex; int sectindex;
register int nrelo; int nrelo;
register char *emit; char *emit;
extern char *getemit(); extern char *getemit();
extern struct outrelo *nextrelo(); extern struct outrelo *nextrelo();
static long zeros[MAXSECT]; static long zeros[MAXSECT];
@@ -206,10 +197,7 @@ handle_relos(head, sects, names)
/* /*
* Write out the local names that must be saved. * Write out the local names that must be saved.
*/ */
static static void put_locals(struct outname *name, unsigned int nnames)
put_locals(name, nnames)
struct outname *name;
register unsigned nnames;
{ {
register struct outname *oname = name; register struct outname *oname = name;
register struct outname *iname = oname; register struct outname *iname = oname;
@@ -230,10 +218,7 @@ put_locals(name, nnames)
* Add all flen's and all (size - flen == zero)'s of preceding sections * Add all flen's and all (size - flen == zero)'s of preceding sections
* with the same number. * with the same number.
*/ */
static static void compute_origins(struct outsect *sect, unsigned int nsect)
compute_origins(sect, nsect)
register struct outsect *sect;
register unsigned nsect;
{ {
extern struct orig relorig[]; extern struct orig relorig[];
register struct orig *orig = relorig; register struct orig *orig = relorig;
@@ -250,13 +235,11 @@ compute_origins(sect, nsect)
* Write out what is after the string area. This is likely to be * Write out what is after the string area. This is likely to be
* debugging information. * debugging information.
*/ */
static static put_dbug(long offdbug)
put_dbug(offdbug)
long offdbug;
{ {
char buf[512]; char buf[512];
register int nbytes; int nbytes;
register long dbugsize; long dbugsize;
extern long objectsize; extern long objectsize;
dbugsize = objectsize - offdbug; dbugsize = objectsize - offdbug;

View File

@@ -14,8 +14,9 @@ static char rcsid[] = "$Id$";
#include <out.h> #include <out.h>
#include "const.h" #include "const.h"
#include "debug.h" #include "debug.h"
#include "defs.h" #include "arch.h"
#include "memory.h" #include "memory.h"
#include "defs.h"
#include "orig.h" #include "orig.h"
extern bool incore; extern bool incore;
@@ -27,27 +28,26 @@ int DEB = 0;
#endif #endif
int Verbose = 0; int Verbose = 0;
static initializations(); static void initializations(int argc, char *argv[]);
static first_pass(); static void first_pass(char *argv[]);
static long number(); static long number(char *s);
static setlign(); static void setlign(int sectno, bool lign);
static setbase(); static void setbase(int sectno, long base);
static struct outname *makename(); static struct outname *makename(char *string);
static pass1(); static void pass1(char *file);
static evaluate(); static void evaluate();
static norm_commons(); static void norm_commons();
static complete_sections(); static void complete_sections();
static change_names(); static void change_names();
static bool tstbit(); static bool tstbit(int indx, char *string);
static second_pass(); static void second_pass(char *argv[]);
static pass2(); static void pass2(char *file);
#ifndef NOSTATISTICS #ifndef NOSTATISTICS
static do_statistics(); static void do_statistics();
#endif #endif
main(argc, argv)
int argc; int main(int argc, char *argv[])
char **argv;
{ {
initializations(argc, argv); initializations(argc, argv);
first_pass(argv); first_pass(argv);
@@ -60,13 +60,14 @@ main(argc, argv)
second_pass(argv); second_pass(argv);
endoutput(); endoutput();
stop(); stop();
return 0;
} }
#ifndef NOSTATISTICS #ifndef NOSTATISTICS
static static void do_statistics()
do_statistics()
{ {
register struct memory *m = mems; struct memory *m = mems;
while (m <= &mems[NMEMS-1]) { while (m <= &mems[NMEMS-1]) {
fprintf(stderr, "mem %d: full %lx, free %lx\n", fprintf(stderr, "mem %d: full %lx, free %lx\n",
@@ -84,10 +85,7 @@ struct outhead outhead; /* Header of final output file. */
struct outsect outsect[MAXSECT];/* Its section table. */ struct outsect outsect[MAXSECT];/* Its section table. */
/* ARGSUSED */ /* ARGSUSED */
static static void initializations(int argc, char *argv[])
initializations(argc, argv)
int argc;
char *argv[];
{ {
/* /*
* Avoid malloc()s. * Avoid malloc()s.
@@ -115,11 +113,9 @@ int exitstatus = 0;
* If the argument starts with a '-', it's a flag, else it is either * If the argument starts with a '-', it's a flag, else it is either
* a plain file to be loaded, or an archive. * a plain file to be loaded, or an archive.
*/ */
static static void first_pass(char *argv[])
first_pass(argv)
register char **argv;
{ {
register char *argp; char *argp;
int sectno; int sectno;
int h; int h;
extern int atoi(); extern int atoi();
@@ -249,13 +245,11 @@ first_pass(argv)
* else if it starts with 0, it's octal, * else if it starts with 0, it's octal,
* else it's decimal. * else it's decimal.
*/ */
static long static long number(char *s)
number(s)
register char *s;
{ {
register int digit; int digit;
register long value = 0; long value = 0;
register int radix = 10; int radix = 10;
if (*s == '0') { if (*s == '0') {
radix = 8; radix = 8;
@@ -268,7 +262,7 @@ number(s)
s++; s++;
} }
} }
while (digit = *s++) { while ((digit = *s++)) {
if (digit >= 'A' && digit <= 'F') if (digit >= 'A' && digit <= 'F')
digit = digit - 'A' + 10; digit = digit - 'A' + 10;
else if (digit >= 'a' && digit <= 'f') else if (digit >= 'a' && digit <= 'f')
@@ -293,18 +287,12 @@ static long sect_base[MAXSECT];
static char lignmap[MAXSECT / WIDTH]; static char lignmap[MAXSECT / WIDTH];
static long sect_lign[MAXSECT]; static long sect_lign[MAXSECT];
/*
/* /*
* Set the alignment of section `sectno' to `lign', if this doesn't * Set the alignment of section `sectno' to `lign', if this doesn't
* conflict with earlier alignment. * conflict with earlier alignment.
*/ */
static static void setlign(int sectno, bool lign)
setlign(sectno, lign)
register int sectno;
register long lign;
{ {
extern bool setbit();
if (setbit(sectno, lignmap) && sect_lign[sectno] != lign) if (setbit(sectno, lignmap) && sect_lign[sectno] != lign)
fatal("section has different alignments"); fatal("section has different alignments");
if (lign == (long)0) if (lign == (long)0)
@@ -316,10 +304,7 @@ setlign(sectno, lign)
* Set the base of section `sectno' to `base', if no other base has been * Set the base of section `sectno' to `base', if no other base has been
* given yet. * given yet.
*/ */
static static void setbase(int sectno, long base)
setbase(sectno, base)
register int sectno;
register long base;
{ {
extern bool setbit(); extern bool setbit();
@@ -328,9 +313,7 @@ setbase(sectno, base)
sect_base[sectno] = base; sect_base[sectno] = base;
} }
static struct outname * static struct outname *makename(char *string)
makename(string)
char *string;
{ {
static struct outname namebuf; static struct outname namebuf;
@@ -346,16 +329,14 @@ makename(string)
* extracted. If it is an archive it is examined to see if it defines any * extracted. If it is an archive it is examined to see if it defines any
* undefined symbols. * undefined symbols.
*/ */
static static void pass1(char *file)
pass1(file)
char *file;
{ {
if (getfile(file) == PLAIN) { if (getfile(file) == PLAIN) {
debug("%s: plain file\n", file, 0, 0, 0); debug("%s: plain file\n", file);
extract(); extract();
} else { } else {
/* It must be an archive. */ /* It must be an archive. */
debug("%s: archive\n", file, 0, 0, 0); debug("%s: archive\n", file);
arch(); arch();
} }
closefile(file); closefile(file);
@@ -370,8 +351,7 @@ pass1(file)
* sections. We then add the section bases to the values of names in * sections. We then add the section bases to the values of names in
* corresponding sections. * corresponding sections.
*/ */
static static void evaluate()
evaluate()
{ {
norm_commons(); norm_commons();
complete_sections(); complete_sections();
@@ -395,12 +375,11 @@ long sect_comm[MAXSECT];
* just like "normal" names. We also count the total size of common names * just like "normal" names. We also count the total size of common names
* within each section to be able to compute the final size in the machine. * within each section to be able to compute the final size in the machine.
*/ */
static static void norm_commons()
norm_commons()
{ {
register struct outname *name; struct outname *name;
register int cnt; int cnt;
register int und = FALSE; int und = FALSE;
name = (struct outname *)address(ALLOGLOB, (ind_t)0); name = (struct outname *)address(ALLOGLOB, (ind_t)0);
cnt = NGlobals; cnt = NGlobals;
@@ -433,8 +412,8 @@ norm_commons()
cnt = NGlobals; cnt = NGlobals;
while (cnt-- > 0) { while (cnt-- > 0) {
if (!ISABSOLUTE(name) && ISCOMMON(name)) { if (!ISABSOLUTE(name) && ISCOMMON(name)) {
register long size; long size;
register int sectindex; int sectindex;
size = name->on_valu; /* XXX rounding? */ size = name->on_valu; /* XXX rounding? */
sectindex = (name->on_type & S_TYP) - S_MIN; sectindex = (name->on_type & S_TYP) - S_MIN;
@@ -454,13 +433,12 @@ struct orig relorig[MAXSECT];
* Compute the offsets in file and machine that the sections will have. * Compute the offsets in file and machine that the sections will have.
* Also set the origins to 0. * Also set the origins to 0.
*/ */
static static void complete_sections()
complete_sections()
{ {
register long base = 0; long base = 0;
register long foff; long foff;
register struct outsect *sc; struct outsect *sc;
register int sectindex; int sectindex;
foff = SZ_HEAD + outhead.oh_nsect * SZ_SECT; foff = SZ_HEAD + outhead.oh_nsect * SZ_SECT;
for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++) { for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++) {
@@ -492,11 +470,10 @@ complete_sections()
* For each name we add the base of its section to its value, unless * For each name we add the base of its section to its value, unless
* the output has to be able to be linked again, as indicated by RFLAG. * the output has to be able to be linked again, as indicated by RFLAG.
*/ */
static static void change_names()
change_names()
{ {
register int cnt; int cnt;
register struct outname *name; struct outname *name;
name = (struct outname *)address(ALLOGLOB, (ind_t)0); name = (struct outname *)address(ALLOGLOB, (ind_t)0);
cnt = NGlobals; cnt = NGlobals;
@@ -523,10 +500,7 @@ change_names()
* This function sets a bit with index `indx' in string. * This function sets a bit with index `indx' in string.
* It returns whether it was already set. * It returns whether it was already set.
*/ */
bool bool setbit(int indx, char *string)
setbit(indx, string)
int indx;
char string[];
{ {
register int byte_index, bit_index; register int byte_index, bit_index;
register int byte; register int byte;
@@ -546,10 +520,7 @@ setbit(indx, string)
/* /*
* This function returns whether the bit given by `indx' is set in `string'. * This function returns whether the bit given by `indx' is set in `string'.
*/ */
static bool static bool tstbit(int indx, char *string)
tstbit(indx, string)
int indx;
char string[];
{ {
register int byte_index, bit_index; register int byte_index, bit_index;
register int byte; register int byte;
@@ -565,8 +536,7 @@ tstbit(indx, string)
/* /*
* Add the base of the section of a name to its value. * Add the base of the section of a name to its value.
*/ */
addbase(name) void addbase(struct outname *name)
struct outname *name;
{ {
register int type = name->on_type & S_TYP; register int type = name->on_type & S_TYP;
register int sectindex = type - S_MIN; register int sectindex = type - S_MIN;
@@ -581,7 +551,7 @@ addbase(name)
address((name->on_type & S_EXT) ? ALLOGCHR : ALLOLCHR, address((name->on_type & S_EXT) ? ALLOGCHR : ALLOLCHR,
(ind_t)name->on_foff (ind_t)name->on_foff
), ),
name->on_type, name->on_valu, 0 name->on_type, name->on_valu
); );
} }
@@ -590,9 +560,7 @@ addbase(name)
/* /*
* Flags have already been processed, so we ignore them here. * Flags have already been processed, so we ignore them here.
*/ */
static static void second_pass(char *argv[])
second_pass(argv)
char **argv;
{ {
passnumber = SECOND; passnumber = SECOND;
while (*++argv) { while (*++argv) {
@@ -611,16 +579,14 @@ second_pass(argv)
} }
} }
static static void pass2(char *file)
pass2(file)
char *file;
{ {
if (getfile(file) == PLAIN) { if (getfile(file) == PLAIN) {
debug("%s: plain file\n", file, 0, 0, 0); debug("%s: plain file\n", file);
finish(); finish();
} else { } else {
/* It must be an archive. */ /* It must be an archive. */
debug("%s: archive\n", file, 0, 0, 0); debug("%s: archive\n", file);
arch2(); arch2();
} }
closefile(file); closefile(file);

View File

@@ -26,11 +26,15 @@ static char rcsid[] = "$Id$";
#include "const.h" #include "const.h"
#include "assert.h" #include "assert.h"
#include "debug.h" #include "debug.h"
#include "arch.h"
#include "memory.h" #include "memory.h"
#include "defs.h"
static copy_down(); static ind_t move_up(int piece, ind_t incr);
static copy_up(); static bool compact(int piece, ind_t incr, int flag);
static free_saved_moduls(); static void copy_down(struct memory *mem, ind_t dist);
static void copy_up(struct memory *mem, ind_t dist);
static void free_saved_moduls();
struct memory mems[NMEMS]; struct memory mems[NMEMS];
@@ -42,10 +46,9 @@ ind_t core_position = (ind_t)0; /* Index of current module. */
static char *BASE; static char *BASE;
static ind_t refused; static ind_t refused;
sbreak(incr) int sbreak(ind_t incr)
ind_t incr;
{ {
unsigned int inc; unsigned int inc;
incr = (incr + (GRANULE - 1)) & ~(GRANULE - 1); incr = (incr + (GRANULE - 1)) & ~(GRANULE - 1);
@@ -66,11 +69,11 @@ sbreak(incr)
* Initialize some pieces of core. We hope that this will be our last * Initialize some pieces of core. We hope that this will be our last
* real allocation, meaning we've made the right choices. * real allocation, meaning we've made the right choices.
*/ */
init_core() void init_core()
{ {
register char *base; char *base;
register ind_t total_size; ind_t total_size;
register struct memory *mem; struct memory *mem;
extern char *sbrk(); extern char *sbrk();
#include "mach.c" #include "mach.c"
@@ -134,17 +137,14 @@ init_core()
* higher than `piece' up with the size of the block. * higher than `piece' up with the size of the block.
* Move up as much as possible, if "incr" fails. * Move up as much as possible, if "incr" fails.
*/ */
static ind_t static ind_t move_up(int piece, ind_t incr)
move_up(piece, incr)
register int piece;
register ind_t incr;
{ {
register struct memory *mem; register struct memory *mem;
#ifndef NOSTATISTICS #ifndef NOSTATISTICS
extern int statistics; extern int statistics;
#endif #endif
debug("move_up(%d, %d)\n", piece, (int)incr, 0, 0); debug("move_up(%d, %d)\n", piece, (int)incr);
while (incr > 0 && sbreak(incr) == -1) while (incr > 0 && sbreak(incr) == -1)
incr -= INCRSIZE; incr -= INCRSIZE;
@@ -171,23 +171,20 @@ extern int passnumber;
* bytes of all higher pieces and move them up. We return whether we have * bytes of all higher pieces and move them up. We return whether we have
* enough bytes, the first or the second time. * enough bytes, the first or the second time.
*/ */
static bool
compact(piece, incr, flag)
register int piece;
register ind_t incr;
#define NORMAL 0 #define NORMAL 0
#define FREEZE 1 #define FREEZE 1
#define FORCED 2 #define FORCED 2
static bool compact(int piece, ind_t incr, int flag)
{ {
register ind_t gain, size; ind_t gain, size;
register struct memory *mem; struct memory *mem;
int min = piece, max = piece; int min = piece, max = piece;
#define SHIFT_COUNT 2 /* let pieces only contribute if their free #define SHIFT_COUNT 2 /* let pieces only contribute if their free
memory is more than 1/2**SHIFT_COUNT * 100 % memory is more than 1/2**SHIFT_COUNT * 100 %
of its occupied memory of its occupied memory
*/ */
debug("compact(%d, %d, %d)\n", piece, (int)incr, flag, 0); debug("compact(%d, %d, %d)\n", piece, (int)incr, flag);
for (mem = &mems[0]; mem < &mems[NMEMS - 1]; mem++) { for (mem = &mems[0]; mem < &mems[NMEMS - 1]; mem++) {
assert(mem->mem_base + mem->mem_full + mem->mem_left == (mem+1)->mem_base); assert(mem->mem_base + mem->mem_full + mem->mem_left == (mem+1)->mem_base);
} }
@@ -278,7 +275,7 @@ compact(piece, incr, flag)
mem->mem_left = 0; mem->mem_left = 0;
if (gain < incr) { if (gain < incr) {
register ind_t up = (ind_t)0; ind_t up = (ind_t)0;
for (mem = &mems[max]; mem > &mems[piece]; mem--) { for (mem = &mems[max]; mem > &mems[piece]; mem--) {
/* Here memory is appended after a piece. */ /* Here memory is appended after a piece. */
@@ -312,14 +309,11 @@ compact(piece, incr, flag)
* overlap with the old area, but we do not want to overwrite them before they * overlap with the old area, but we do not want to overwrite them before they
* are copied. * are copied.
*/ */
static static void copy_down(struct memory *mem, ind_t dist)
copy_down(mem, dist)
register struct memory *mem;
ind_t dist;
{ {
register char *old; char *old;
register char *new; char *new;
register ind_t size; ind_t size;
size = mem->mem_full; size = mem->mem_full;
old = mem->mem_base; old = mem->mem_base;
@@ -335,14 +329,11 @@ copy_down(mem, dist)
* overlap with the old area, but we do not want to overwrite them before they * overlap with the old area, but we do not want to overwrite them before they
* are copied. * are copied.
*/ */
static static void copy_up(struct memory *mem, ind_t dist)
copy_up(mem, dist)
register struct memory *mem;
ind_t dist;
{ {
register char *old; char *old;
register char *new; char *new;
register ind_t size; ind_t size;
size = mem->mem_full; size = mem->mem_full;
old = mem->mem_base + size; old = mem->mem_base + size;
@@ -361,14 +352,11 @@ static int alloctype = NORMAL;
* how many times the area is moved, because of another allocate, this offset * how many times the area is moved, because of another allocate, this offset
* remains valid. * remains valid.
*/ */
ind_t ind_t alloc(int piece, long size)
alloc(piece, size)
int piece;
register long size;
{ {
register ind_t incr = 0; ind_t incr = 0;
ind_t left = mems[piece].mem_left; ind_t left = mems[piece].mem_left;
register ind_t full = mems[piece].mem_full; ind_t full = mems[piece].mem_full;
assert(passnumber == FIRST || (!incore && piece == ALLOMODL)); assert(passnumber == FIRST || (!incore && piece == ALLOMODL));
if (size == (long)0) if (size == (long)0)
@@ -401,13 +389,10 @@ alloc(piece, size)
* Same as alloc() but for a piece which really needs it. If the first * Same as alloc() but for a piece which really needs it. If the first
* attempt fails, release the space occupied by other pieces and try again. * attempt fails, release the space occupied by other pieces and try again.
*/ */
ind_t ind_t hard_alloc(int piece, long size)
hard_alloc(piece, size)
register int piece;
register long size;
{ {
register ind_t ret; ind_t ret;
register int i; int i;
if (size != (ind_t)size) if (size != (ind_t)size)
return BADOFF; return BADOFF;
@@ -449,12 +434,11 @@ hard_alloc(piece, size)
* at the start of the piece allocated for module contents, thereby * at the start of the piece allocated for module contents, thereby
* overwriting the saved modules, and release its space. * overwriting the saved modules, and release its space.
*/ */
static static void free_saved_moduls()
free_saved_moduls()
{ {
register ind_t size; ind_t size;
register char *old, *new; char *old, *new;
register struct memory *mem = &mems[ALLOMODL]; struct memory *mem = &mems[ALLOMODL];
size = mem->mem_full - core_position; size = mem->mem_full - core_position;
new = mem->mem_base; new = mem->mem_base;
@@ -470,8 +454,7 @@ free_saved_moduls()
* The piece of memory with index `piece' is no longer needed. * The piece of memory with index `piece' is no longer needed.
* We take care that it can be used by compact() later, if needed. * We take care that it can be used by compact() later, if needed.
*/ */
dealloc(piece) void dealloc(int piece)
register int piece;
{ {
/* /*
* Some pieces need their memory throughout the program. * Some pieces need their memory throughout the program.
@@ -484,10 +467,7 @@ dealloc(piece)
mems[piece].mem_full = (ind_t)0; mems[piece].mem_full = (ind_t)0;
} }
char * char *core_alloc(int piece, long size)
core_alloc(piece, size)
register int piece;
register long size;
{ {
register ind_t off; register ind_t off;
@@ -496,22 +476,20 @@ core_alloc(piece, size)
return address(piece, off); return address(piece, off);
} }
core_free(piece, p) void core_free(int piece, char *p)
int piece;
char *p;
{ {
char *q = address(piece, mems[piece].mem_full); char *q = address(piece, mems[piece].mem_full);
assert(p < q); assert(p < q);
switch(sizeof(unsigned) == sizeof(char *)) { if (sizeof(unsigned) == sizeof(char *))
case 1: {
mems[piece].mem_full -= (unsigned) (q - p); mems[piece].mem_full -= (unsigned) (q - p);
mems[piece].mem_left += (unsigned) (q - p); mems[piece].mem_left += (unsigned) (q - p);
break; }
default: else
{
mems[piece].mem_full -= (ind_t) q - (ind_t) p; mems[piece].mem_full -= (ind_t) q - (ind_t) p;
mems[piece].mem_left += (ind_t) q - (ind_t) p; mems[piece].mem_left += (ind_t) q - (ind_t) p;
break;
} }
} }
@@ -519,9 +497,9 @@ core_free(piece, p)
* Reset index into piece of memory for modules and * Reset index into piece of memory for modules and
* take care that the allocated pieces will not be moved. * take care that the allocated pieces will not be moved.
*/ */
freeze_core() void freeze_core()
{ {
register int i; int i;
core_position = (ind_t)0; core_position = (ind_t)0;
@@ -549,11 +527,11 @@ freeze_core()
* To transform the various pieces of the output in core to the file format, * To transform the various pieces of the output in core to the file format,
* we must order the bytes in the unsigned shorts and longs as ACK prescribes. * we must order the bytes in the unsigned shorts and longs as ACK prescribes.
*/ */
write_bytes() void write_bytes()
{ {
unsigned short nsect; unsigned short nsect;
long offchar; long offchar;
register struct memory *mem; struct memory *mem;
extern unsigned short NLocals, NGlobals; extern unsigned short NLocals, NGlobals;
extern long NLChars, NGChars; extern long NLChars, NGChars;
extern int flagword; extern int flagword;
@@ -607,10 +585,7 @@ write_bytes()
} }
} }
namecpy(name, nname, offchar) void namecpy(struct outname *name, unsigned int nname, long offchar)
register struct outname *name;
register unsigned nname;
register long offchar;
{ {
while (nname--) { while (nname--) {
if (name->on_foff) if (name->on_foff)

View File

@@ -38,5 +38,13 @@ extern struct memory mems[];
#define int_align(sz) (((sz)+(sizeof(int)-1))&~(int)(sizeof(int)-1)) #define int_align(sz) (((sz)+(sizeof(int)-1))&~(int)(sizeof(int)-1))
extern ind_t core_position; extern ind_t core_position;
extern ind_t hard_alloc();
extern ind_t alloc(); void init_core();
ind_t hard_alloc(int piece, long size);
ind_t alloc(int piece, long size);
void dealloc(int piece);
char *core_alloc(int piece, long size);
void core_free(int piece, char *p);
void freeze_core();
void write_bytes();
void namecpy(struct outname *name, unsigned int nname, long offchar);

View File

@@ -10,7 +10,7 @@ static char rcsid[] = "$Id$";
#include "const.h" #include "const.h"
#include "memory.h" #include "memory.h"
static generate_section_names(); static void generate_section_names();
extern struct outhead outhead; extern struct outhead outhead;
extern bool incore; extern bool incore;
@@ -22,7 +22,7 @@ extern int flagword;
* flag was given. * flag was given.
* If this flag is given we don't need the string table either. * If this flag is given we don't need the string table either.
*/ */
beginoutput() void beginoutput()
{ {
extern unsigned short NLocals, NGlobals; extern unsigned short NLocals, NGlobals;
extern long NLChars, NGChars; extern long NLChars, NGChars;
@@ -51,12 +51,11 @@ beginoutput()
* Generate names for all sections and put them after the global names. * Generate names for all sections and put them after the global names.
* Section names are used for relocation. * Section names are used for relocation.
*/ */
static static void generate_section_names()
generate_section_names()
{ {
register struct outname *name; struct outname *name;
register int sectindex; int sectindex;
register long size; long size;
extern struct outsect outsect[]; extern struct outsect outsect[];
extern char *core_alloc(); extern char *core_alloc();
@@ -78,7 +77,7 @@ generate_section_names()
* written out, and we just finish that. * written out, and we just finish that.
* If we did, we write out our pieces of core. * If we did, we write out our pieces of core.
*/ */
endoutput() void endoutput()
{ {
if (!incore) { if (!incore) {
if (!(flagword & SFLAG)) if (!(flagword & SFLAG))

View File

@@ -6,9 +6,18 @@
static char rcsid[] = "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <stdio.h>
#include <out.h>
#include "const.h"
#include "assert.h"
#include "debug.h"
#include "arch.h"
#include "memory.h"
#include "defs.h"
int infile; /* The current input file. */ int infile; /* The current input file. */
rd_fatal() void rd_fatal()
{ {
fatal("read error"); fatal("read error");
} }

View File

@@ -11,19 +11,22 @@ static char rcsid[] = "$Id$";
#include "out.h" #include "out.h"
#include "const.h" #include "const.h"
#include "debug.h" #include "debug.h"
#include "memory.h"
#include "arch.h"
#include "defs.h" #include "defs.h"
#include "orig.h" #include "orig.h"
#define UBYTE(x) ((x) & BYTEMASK) #define UBYTE(x) ((x) & BYTEMASK)
static long getvalu(char addr[], char type);
static void putvalu(long valu, char addr[], char type);
static unsigned int addrelo(struct outrelo *relo, struct outname *names, long *valu_out);
/* /*
* The bits in type indicate how many bytes the value occupies and what * The bits in type indicate how many bytes the value occupies and what
* significance should be attributed to each byte. * significance should be attributed to each byte.
*/ */
static long static long getvalu(char addr[], char type)
getvalu(addr, type)
char addr[];
char type;
{ {
unsigned short word0, word1; unsigned short word0, word1;
@@ -51,6 +54,7 @@ getvalu(addr, type)
fatal("bad relocation size"); fatal("bad relocation size");
} }
/* NOTREACHED */ /* NOTREACHED */
return 0;
} }
/* /*
@@ -58,11 +62,7 @@ getvalu(addr, type)
* significance should be attributed to each byte. * significance should be attributed to each byte.
* We do not check for overflow. * We do not check for overflow.
*/ */
static static void putvalu(long valu, char addr[], char type)
putvalu(valu, addr, type)
long valu;
char addr[];
char type;
{ {
unsigned short word0, word1; unsigned short word0, word1;
@@ -120,24 +120,20 @@ extern struct orig relorig[];
* Second case: we must update the value by the change * Second case: we must update the value by the change
* in position of the section of local. * in position of the section of local.
*/ */
static unsigned static unsigned int addrelo(struct outrelo *relo, struct outname *names, long *valu_out)
addrelo(relo, names, valu_out)
struct outrelo *relo;
struct outname *names;
long *valu_out; /* Out variable. */
{ {
register struct outname *local = &names[relo->or_nami]; struct outname *local = &names[relo->or_nami];
register unsigned short index = NLocals; unsigned short index = NLocals;
register long valu = *valu_out; long valu = *valu_out;
if ((local->on_type & S_SCT)) { if ((local->on_type & S_SCT)) {
register int sectindex = (local->on_type & S_TYP) - S_MIN; int sectindex = (local->on_type & S_TYP) - S_MIN;
valu += relorig[sectindex].org_size; valu += relorig[sectindex].org_size;
valu += outsect[sectindex].os_base; valu += outsect[sectindex].os_base;
index += NGlobals + sectindex; index += NGlobals + sectindex;
} else { } else {
register struct outname *name; struct outname *name;
extern int hash(); extern int hash();
extern struct outname *searchname(); extern struct outname *searchname();
extern unsigned indexof(); extern unsigned indexof();
@@ -147,7 +143,7 @@ addrelo(relo, names, valu_out)
if (name == (struct outname *)0) if (name == (struct outname *)0)
fatal("name %s not found in pass 2", local->on_mptr); fatal("name %s not found in pass 2", local->on_mptr);
if (ISCOMMON(name) || ISUNDEFINED(name)) { if (ISCOMMON(name) || ISUNDEFINED(name)) {
debug("can't relocate from %s\n",local->on_mptr,0,0,0); debug("can't relocate from %s\n",local->on_mptr);
index += indexof(name); index += indexof(name);
} else { } else {
valu += name->on_valu; valu += name->on_valu;
@@ -167,12 +163,7 @@ addrelo(relo, names, valu_out)
* which the header is pointed to by `head'. Relocation is relative to the * which the header is pointed to by `head'. Relocation is relative to the
* names in `names'; `relo' tells how to relocate. * names in `names'; `relo' tells how to relocate.
*/ */
relocate(head, emit, names, relo, off) void relocate(struct outhead *head, char *emit, struct outname names[], struct outrelo *relo, long off)
struct outhead *head;
char *emit;
struct outname names[];
struct outrelo *relo;
long off;
{ {
long valu; long valu;
int sectindex = relo->or_sect - S_MIN; int sectindex = relo->or_sect - S_MIN;

View File

@@ -18,13 +18,13 @@ static char rcsid[] = "$Id$";
#include "const.h" #include "const.h"
#include "assert.h" #include "assert.h"
#include "memory.h" #include "memory.h"
#include "defs.h"
extern bool incore; extern bool incore;
extern char *core_alloc();
savemagic() void savemagic()
{ {
register char *p; char *p;
if (!incore) if (!incore)
return; return;
@@ -35,10 +35,9 @@ savemagic()
} }
} }
savehdr(hdr) void savehdr(struct ar_hdr * hdr)
struct ar_hdr *hdr;
{ {
register char *p; char *p;
if (!incore) if (!incore)
return; return;
@@ -57,15 +56,10 @@ long NGChars = 0; /* Idem for global names. */
* Return its offset in this area. We don't use the first char of the string * Return its offset in this area. We don't use the first char of the string
* area, so that empty strings can be distinguished from the first string. * area, so that empty strings can be distinguished from the first string.
*/ */
ind_t ind_t savechar(int piece, ind_t off)
savechar(piece, off)
register int piece;
register ind_t off;
{ {
register long len; long len;
register ind_t newoff; ind_t newoff;
extern ind_t alloc();
extern ind_t hard_alloc();
if (off == (ind_t)0) if (off == (ind_t)0)
return 0; return 0;
@@ -91,8 +85,7 @@ savechar(piece, off)
* allocation, but the string of which name->on_foff is the offset may be * allocation, but the string of which name->on_foff is the offset may be
* destroyed, so we save that first. * destroyed, so we save that first.
*/ */
savelocal(name) void savelocal(struct outname *name)
struct outname *name;
{ {
ind_t savindex; ind_t savindex;
struct outname *new; struct outname *new;

View File

@@ -8,6 +8,7 @@ static char rcsid[] = "$Id$";
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#ifdef SYMDBUG #ifdef SYMDBUG
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@@ -20,6 +21,7 @@ static char rcsid[] = "$Id$";
#include "memory.h" #include "memory.h"
#include "scan.h" #include "scan.h"
#include "debug.h" #include "debug.h"
#include "defs.h"
#define READ 0 #define READ 0
@@ -40,20 +42,21 @@ char *modulname; /* Name of object module. */
long objectsize; long objectsize;
#endif /* SYMDBUG */ #endif /* SYMDBUG */
static long align(); static long align(long size);
static char *modulbase; static char *modulbase;
static long modulsize(); static long modulsize(struct outhead *head);
static scan_modul();
static bool all_alloc(); static void scan_modul();
static bool direct_alloc(); static bool all_alloc();
static bool indirect_alloc(); static bool direct_alloc(struct outhead *head);
static bool putemitindex(); static bool indirect_alloc(struct outhead *head);
static bool putreloindex(); static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece);
static bool putreloindex(ind_t relooff, long nrelobytes);
#ifdef SYMDBUG #ifdef SYMDBUG
static bool putdbugindex(); static bool putdbugindex(ind_t dbugoff, long ndbugbytes);
#endif /* SYMDBUG */ #endif /* SYMDBUG */
static get_indirect(); static void get_indirect(struct outhead *head, struct outsect *sect);
static read_modul(); static void read_modul();
/* /*
* Open the file with name `filename' (if necessary) and examine the first * Open the file with name `filename' (if necessary) and examine the first
@@ -61,9 +64,7 @@ static read_modul();
* In case of a plain file, the file pointer is repositioned after the * In case of a plain file, the file pointer is repositioned after the
* examination. Otherwise it is at the beginning of the table of contents. * examination. Otherwise it is at the beginning of the table of contents.
*/ */
int int getfile(char *filename)
getfile(filename)
char *filename;
{ {
unsigned int rd_unsigned2(); unsigned int rd_unsigned2();
struct ar_hdr archive_header; struct ar_hdr archive_header;
@@ -113,18 +114,17 @@ getfile(filename)
fatal("%s: wrong magic number", filename); fatal("%s: wrong magic number", filename);
} }
/* NOTREACHED */ /* NOTREACHED */
return 0;
} }
/* ARGSUSED */ /* ARGSUSED */
closefile(filename) void closefile(char *filename)
char *filename;
{ {
if (passnumber == FIRST || !incore) if (passnumber == FIRST || !incore)
close(infile); close(infile);
} }
get_archive_header(archive_header) void get_archive_header(struct ar_hdr *archive_header)
register struct ar_hdr *archive_header;
{ {
if (passnumber == FIRST || !incore) { if (passnumber == FIRST || !incore) {
rd_arhdr(infile, archive_header); rd_arhdr(infile, archive_header);
@@ -139,7 +139,7 @@ get_archive_header(archive_header)
#endif /* SYMDBUG */ #endif /* SYMDBUG */
} }
get_modul() void get_modul()
{ {
if (passnumber == FIRST) { if (passnumber == FIRST) {
rd_fdopen(infile); rd_fdopen(infile);
@@ -155,8 +155,7 @@ get_modul()
* to keep everything in core is abandoned, but we will always put the header, * to keep everything in core is abandoned, but we will always put the header,
* the section table, and the name and string table into core. * the section table, and the name and string table into core.
*/ */
static static void scan_modul()
scan_modul()
{ {
bool space; bool space;
struct outhead *head; struct outhead *head;
@@ -187,8 +186,7 @@ scan_modul()
* If possible, allocate space for the rest of the module. Return whether * If possible, allocate space for the rest of the module. Return whether
* this was possible. * this was possible.
*/ */
static bool static bool all_alloc()
all_alloc()
{ {
struct outhead head; struct outhead head;
extern ind_t hard_alloc(); extern ind_t hard_alloc();
@@ -208,12 +206,10 @@ all_alloc()
* First allocate the section table and read it in, then allocate the rest * First allocate the section table and read it in, then allocate the rest
* and return whether this succeeded. * and return whether this succeeded.
*/ */
static bool static bool direct_alloc(struct outhead *head)
direct_alloc(head)
struct outhead *head;
{ {
ind_t sectindex = IND_SECT(*head); ind_t sectindex = IND_SECT(*head);
register struct outsect *sects; struct outsect *sects;
unsigned short nsect = head->oh_nsect; unsigned short nsect = head->oh_nsect;
long size, rest; long size, rest;
extern ind_t hard_alloc(); extern ind_t hard_alloc();
@@ -247,11 +243,9 @@ direct_alloc(head)
* Allocate space for the indirectly accessed pieces: the section contents and * Allocate space for the indirectly accessed pieces: the section contents and
* the relocation table, and put their indices in the right place. * the relocation table, and put their indices in the right place.
*/ */
static bool static bool indirect_alloc(struct outhead *head)
indirect_alloc(head)
struct outhead *head;
{ {
register int allopiece; int allopiece;
unsigned short nsect = head->oh_nsect; unsigned short nsect = head->oh_nsect;
unsigned short nrelo = head->oh_nrelo; unsigned short nrelo = head->oh_nrelo;
ind_t sectindex = IND_SECT(*head); ind_t sectindex = IND_SECT(*head);
@@ -284,17 +278,13 @@ indirect_alloc(head)
* at offset `sectindex'. Put the offset of the allocated piece at offset * at offset `sectindex'. Put the offset of the allocated piece at offset
* `emitoff'. * `emitoff'.
*/ */
static bool static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece)
putemitindex(sectindex, emitoff, allopiece)
ind_t sectindex;
ind_t emitoff;
int allopiece;
{ {
long flen; long flen;
ind_t emitindex; ind_t emitindex;
extern ind_t alloc(); extern ind_t alloc();
static long zeros[MAXSECT]; static long zeros[MAXSECT];
register long zero = zeros[allopiece - ALLOEMIT]; long zero = zeros[allopiece - ALLOEMIT];
/* /*
* Notice that "sectindex" is not a section number! * Notice that "sectindex" is not a section number!
@@ -306,9 +296,9 @@ putemitindex(sectindex, emitoff, allopiece)
flen = ((struct outsect *)modulptr(sectindex))->os_flen; flen = ((struct outsect *)modulptr(sectindex))->os_flen;
if (flen && zero) { if (flen && zero) {
if ((emitindex = alloc(allopiece, zero)) != BADOFF){ if ((emitindex = alloc(allopiece, zero)) != BADOFF){
register char *p = address(allopiece, emitindex); char *p = address(allopiece, emitindex);
debug("Zeros %ld\n", zero, 0,0,0); debug("Zeros %ld\n", zero);
while (zero--) *p++ = 0; while (zero--) *p++ = 0;
} }
else return FALSE; else return FALSE;
@@ -327,10 +317,7 @@ putemitindex(sectindex, emitoff, allopiece)
* Allocate space for a relocation table with `nrelobytes' bytes, and put the * Allocate space for a relocation table with `nrelobytes' bytes, and put the
* offset at `relooff'. * offset at `relooff'.
*/ */
static bool static bool putreloindex(ind_t relooff, long nrelobytes)
putreloindex(relooff, nrelobytes)
ind_t relooff;
long nrelobytes;
{ {
ind_t reloindex; ind_t reloindex;
extern ind_t alloc(); extern ind_t alloc();
@@ -345,10 +332,7 @@ putreloindex(relooff, nrelobytes)
/* /*
* Allocate space for debugging information and put the offset at `dbugoff'. * Allocate space for debugging information and put the offset at `dbugoff'.
*/ */
static bool static bool putdbugindex(ind_t dbugoff, long ndbugbytes)
putdbugindex(dbugoff, ndbugbytes)
ind_t relooff;
long ndbugbytes;
{ {
ind_t dbugindex; ind_t dbugindex;
extern ind_t alloc(); extern ind_t alloc();
@@ -365,16 +349,11 @@ putdbugindex(dbugoff, ndbugbytes)
* Compute addresses and read in. Remember that the contents of the sections * Compute addresses and read in. Remember that the contents of the sections
* and also the relocation table are accessed indirectly. * and also the relocation table are accessed indirectly.
*/ */
static static void get_indirect(struct outhead *head, struct outsect *sect)
get_indirect(head, sect)
struct outhead *head; /* not register! Won't compile on
SCO Xenix 386 if it is!
*/
register struct outsect *sect;
{ {
register ind_t *emitindex; ind_t *emitindex;
register int nsect; int nsect;
register int piece; int piece;
ind_t *reloindex; ind_t *reloindex;
emitindex = (ind_t *)modulptr(IND_EMIT(*head)); emitindex = (ind_t *)modulptr(IND_EMIT(*head));
@@ -393,8 +372,7 @@ get_indirect(head, sect)
/* /*
* Set the file pointer at `pos'. * Set the file pointer at `pos'.
*/ */
seek(pos) void seek(long pos)
long pos;
{ {
if (passnumber == FIRST || !incore) if (passnumber == FIRST || !incore)
lseek(infile, pos, 0); lseek(infile, pos, 0);
@@ -405,10 +383,9 @@ seek(pos)
* is not. That's why we do it here. If we don't keep everything in core, * is not. That's why we do it here. If we don't keep everything in core,
* we give the space allocated for a module back. * we give the space allocated for a module back.
*/ */
skip_modul(head) void skip_modul(struct outhead *head)
struct outhead *head;
{ {
register ind_t skip = modulsize(head); ind_t skip = modulsize(head);
if (incore) { if (incore) {
core_position += int_align(skip); core_position += int_align(skip);
@@ -423,11 +400,10 @@ skip_modul(head)
/* /*
* Read in what we need in pass 2, because we couldn't keep it in core. * Read in what we need in pass 2, because we couldn't keep it in core.
*/ */
static static void read_modul()
read_modul()
{ {
struct outhead *head; struct outhead *head;
register struct outsect *sects; struct outsect *sects;
struct outname *names; struct outname *names;
char *chars; char *chars;
ind_t sectindex, nameindex, charindex; ind_t sectindex, nameindex, charindex;
@@ -473,9 +449,7 @@ read_modul()
* Align `size' to a multiple of the size of a double. * Align `size' to a multiple of the size of a double.
* This is assumed to be a power of 2. * This is assumed to be a power of 2.
*/ */
static long static long align(long size)
align(size)
register long size;
{ {
return (size + (sizeof(double) - 1)) & ~(int)(sizeof(double) - 1); return (size + (sizeof(double) - 1)) & ~(int)(sizeof(double) - 1);
} }
@@ -493,9 +467,7 @@ align(size)
* 6. the offset of the debugging information. * 6. the offset of the debugging information.
#endif #endif
*/ */
static long static long modulsize(struct outhead *head)
modulsize(head)
register struct outhead *head;
{ {
return sizeof(struct outhead) + /* 0 */ return sizeof(struct outhead) + /* 0 */
head->oh_nsect * sizeof(struct outsect) + /* 1 */ head->oh_nsect * sizeof(struct outsect) + /* 1 */
@@ -522,10 +494,9 @@ static unsigned short cnt_relos;
static unsigned short relind; static unsigned short relind;
#define _RELSIZ 64 #define _RELSIZ 64
startrelo(head) void startrelo(struct outhead *head)
register struct outhead *head;
{ {
ind_t reloindex; ind_t reloindex;
if (incore) { if (incore) {
reloindex = *(ind_t *)(modulbase + IND_RELO(*head)); reloindex = *(ind_t *)(modulbase + IND_RELO(*head));
@@ -538,8 +509,7 @@ startrelo(head)
} }
} }
struct outrelo * struct outrelo *nextrelo()
nextrelo()
{ {
static struct outrelo relobuf[_RELSIZ]; static struct outrelo relobuf[_RELSIZ];
@@ -562,11 +532,7 @@ nextrelo()
* Get the section contents in core of which the describing struct has index * Get the section contents in core of which the describing struct has index
* `sectindex'. `Head' points to the header of the module. * `sectindex'. `Head' points to the header of the module.
*/ */
char * char *getemit(struct outhead *head, struct outsect *sects, int sectindex)
getemit(head, sects, sectindex)
struct outhead *head;
struct outsect *sects;
int sectindex;
{ {
char *ret; char *ret;
ind_t off; ind_t off;
@@ -588,11 +554,7 @@ getemit(head, sects, sectindex)
return address(ALLOEMIT + sectindex, off); return address(ALLOEMIT + sectindex, off);
} }
char * char *getblk(long totalsz, long *pblksz, int sectindex)
getblk(totalsz, pblksz, sectindex)
long totalsz;
long *pblksz;
int sectindex;
{ {
char *ret; char *ret;
long sz = (1L << 30); long sz = (1L << 30);
@@ -613,8 +575,7 @@ getblk(totalsz, pblksz, sectindex)
return (char *) 0; return (char *) 0;
} }
endemit(emit) void endemit(char *emit)
char *emit;
{ {
core_free(ALLOMODL, emit); core_free(ALLOMODL, emit);
} }

View File

@@ -14,8 +14,10 @@ static char rcsid[] = "$Id$";
#include <stdio.h> #include <stdio.h>
#include "out.h" #include "out.h"
#include "const.h" #include "const.h"
#include "arch.h"
#include "memory.h" #include "memory.h"
#include "debug.h" #include "debug.h"
#include "defs.h"
/* /*
* Symbol table types. Each hash table entry contains the offset of a symbol * Symbol table types. Each hash table entry contains the offset of a symbol
@@ -35,9 +37,9 @@ static ind_t hashtable[NHASH];
/* /*
* Initialize the symbol table. All indices should be noticeably invalid. * Initialize the symbol table. All indices should be noticeably invalid.
*/ */
init_symboltable() void init_symboltable()
{ {
register ind_t *rap; ind_t *rap;
for (rap = hashtable; rap < &hashtable[NHASH]; rap++) for (rap = hashtable; rap < &hashtable[NHASH]; rap++)
*rap = BADOFF; *rap = BADOFF;
@@ -50,35 +52,32 @@ init_symboltable()
* in this element of the list is returned. When a match cannot be found, * in this element of the list is returned. When a match cannot be found,
* NIL is returned. * NIL is returned.
*/ */
struct outname * struct outname *searchname(char *string, int hashval)
searchname(string, hashval)
char *string;
int hashval;
{ {
register char *rcp; char *rcp;
register char *namestring; char *namestring;
register ind_t symindex; ind_t symindex;
register struct outname *name; struct outname *name;
register struct symbol *sym; struct symbol *sym;
symindex = hashtable[hashval]; symindex = hashtable[hashval];
debug("looking for %s %d %ld:", string, hashval, hashtable[hashval], 0); debug("looking for %s %d %ld:", string, hashval, hashtable[hashval]);
while (symindex != BADOFF) { while (symindex != BADOFF) {
sym = (struct symbol *)address(ALLOSYMB, symindex); sym = (struct symbol *)address(ALLOSYMB, symindex);
name = (struct outname *)address(ALLOGLOB, sym->sy_name); name = (struct outname *)address(ALLOGLOB, sym->sy_name);
namestring = address(ALLOGCHR, (ind_t)name->on_foff); namestring = address(ALLOGCHR, (ind_t)name->on_foff);
rcp = string; rcp = string;
debug("comp %s;", namestring, 0, 0, 0); debug("comp %s;", namestring);
while (*rcp == *namestring++) while (*rcp == *namestring++)
if (*rcp++ == '\0') { if (*rcp++ == '\0') {
debug("found %x, %x, %lx\n", debug("found %x, %x, %lx\n",
name->on_type, name->on_desc, name->on_valu, 0); name->on_type, name->on_desc, name->on_valu);
return name; return name;
} }
symindex = sym->sy_next; symindex = sym->sy_next;
} }
/* Not found. */ /* Not found. */
debug("not found\n", 0, 0, 0, 0); debug("not found\n");
return (struct outname *)0; return (struct outname *)0;
} }
@@ -88,22 +87,18 @@ searchname(string, hashval)
* destroyed by allocation. However, the string of which name->on_foff is the * destroyed by allocation. However, the string of which name->on_foff is the
* offset can be destroyed, so we save it first. * offset can be destroyed, so we save it first.
*/ */
entername(name, hashval) void entername(struct outname *name, int hashval)
struct outname *name;
int hashval;
{ {
ind_t savindex; ind_t savindex;
ind_t symindex; ind_t symindex;
ind_t namindex; ind_t namindex;
register struct symbol *sym; struct symbol *sym;
struct outname *newname; struct outname *newname;
extern ind_t savechar();
extern ind_t hard_alloc();
debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc); 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); savindex = savechar(ALLOGCHR, (ind_t)name->on_foff);
symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol)); symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol));
debug("; %ld\n", symindex, 0, 0, 0); debug("; %ld\n", symindex);
namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname)); namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname));
if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF) if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF)
fatal("symbol table overflow"); fatal("symbol table overflow");
@@ -120,9 +115,7 @@ entername(name, hashval)
* Return the index of `name' in the symbol table in the order in which * Return the index of `name' in the symbol table in the order in which
* it was entered. We need a REAL index, not a byte offset. * it was entered. We need a REAL index, not a byte offset.
*/ */
unsigned unsigned int indexof(struct outname *name)
indexof(name)
struct outname *name;
{ {
return name - (struct outname *)address(ALLOGLOB, (ind_t)0); return name - (struct outname *)address(ALLOGLOB, (ind_t)0);
} }
@@ -132,14 +125,12 @@ indexof(name)
* 0 <= hash(p) < NHASH, so it can - and will - be used * 0 <= hash(p) < NHASH, so it can - and will - be used
* as index in a hash table. * as index in a hash table.
*/ */
int int hash(char *p)
hash(p)
register char *p;
{ {
register unsigned short h = 0; unsigned short h = 0;
register int c; int c;
while (c = *p++) { while ((c = *p++)) {
h <<= 2; h <<= 2;
h += c; h += c;
} }

View File

@@ -13,13 +13,16 @@ static char rcsid[] = "$Id$";
#include "const.h" #include "const.h"
#include "assert.h" #include "assert.h"
#include "memory.h" #include "memory.h"
#include "arch.h"
#include "defs.h"
extern struct outhead outhead; extern struct outhead outhead;
extern struct outsect outsect[]; extern struct outsect outsect[];
extern int flagword; extern int flagword;
extern bool incore; extern bool incore;
wr_fatal() static struct outname *sectname(int sectindex);
void wr_fatal()
{ {
fatal("write error"); fatal("write error");
} }
@@ -30,7 +33,7 @@ static long off_char;
* Open the output file according to the chosen strategy. * Open the output file according to the chosen strategy.
* Write away the header and section table: they will not change anymore. * Write away the header and section table: they will not change anymore.
*/ */
begin_write() void begin_write()
{ {
register struct outhead *hd = &outhead; register struct outhead *hd = &outhead;
@@ -40,9 +43,7 @@ begin_write()
off_char = OFF_CHAR(*hd); off_char = OFF_CHAR(*hd);
} }
static struct outname * static struct outname *sectname(int sectindex)
sectname(sectindex)
int sectindex;
{ {
static struct outname namebuf; static struct outname namebuf;
@@ -57,10 +58,10 @@ sectname(sectindex)
/* /*
* Write out the symbol table and the section names. * Write out the symbol table and the section names.
*/ */
end_write() void end_write()
{ {
register struct outname *name; struct outname *name;
register int sectindex; int sectindex;
extern unsigned short NGlobals; extern unsigned short NGlobals;
extern long NGChars; extern long NGChars;
@@ -75,37 +76,31 @@ end_write()
for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++) for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++)
wrt_name(sectname(sectindex), 1); wrt_name(sectname(sectindex), 1);
} }
wrt_emit(emit, sectindex, cnt)
char *emit;
int sectindex;
long cnt;
{
void wrt_emit(char *emit, int sectindex, long cnt)
{
wr_outsect(sectindex); wr_outsect(sectindex);
wr_emit(emit, cnt); wr_emit(emit, cnt);
} }
wrt_nulls(sectindex, cnt) void wrt_nulls(int sectindex, long cnt)
register long cnt;
{ {
static char nullbuf[BUFSIZ]; static char nullbuf[BUFSIZ];
wr_outsect(sectindex); wr_outsect(sectindex);
while (cnt) { while (cnt) {
register int n = cnt >= BUFSIZ ? BUFSIZ : cnt; int n = cnt >= BUFSIZ ? BUFSIZ : cnt;
wr_emit(nullbuf, (long)n); wr_emit(nullbuf, (long)n);
cnt -= n; cnt -= n;
} }
} }
wrt_name(name, writename) void wrt_name(struct outname *name, int writename)
register struct outname *name;
{ {
assert(!incore); assert(!incore);
assert(!(flagword & SFLAG)); assert(!(flagword & SFLAG));
if (name->on_mptr != (char *)0) { if (name->on_mptr != (char *)0) {
register long len = strlen(name->on_mptr) + 1; long len = strlen(name->on_mptr) + 1;
wr_string(name->on_mptr, len); wr_string(name->on_mptr, len);
name->on_foff = off_char; name->on_foff = off_char;

View File

@@ -21,8 +21,9 @@ static struct token aside; /* to put currrent token aside, when a token
int newline, lineno; /* To keep track of linenumbers */ int newline, lineno; /* To keep track of linenumbers */
extern FILE *input; /* file descriptor of machine table */ extern FILE *input; /* file descriptor of machine table */
LLlex() { int LLlex()
register c; {
int c;
if (aside.t_tokno) { /* A token was pushed aside, return it now */ if (aside.t_tokno) { /* A token was pushed aside, return it now */
dot = aside; dot = aside;
@@ -116,7 +117,8 @@ LLlex() {
} }
} }
LLmessage(d) { void LLmessage(int d)
{
static int savlineno; static int savlineno;
if (savlineno != lineno) { if (savlineno != lineno) {

View File

@@ -11,6 +11,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "misc.h" #include "misc.h"
struct hlist { /* linear list of pattern numbers */ struct hlist { /* linear list of pattern numbers */
@@ -23,10 +24,10 @@ static struct hlist *hashtable[129]; /* an array of ptr's to these lists,
* result of hashing * result of hashing
*/ */
static unsigned static unsigned hash(char *string)
hash(string) char *string; { {
register char *p; char *p;
register unsigned i,sum; unsigned int i,sum;
if (strcmp(string,"ANY") == 0) return 128; if (strcmp(string,"ANY") == 0) return 128;
for (sum=i=0,p=string;*p;i += 3) for (sum=i=0,p=string;*p;i += 3)
@@ -35,7 +36,8 @@ hash(string) char *string; {
} }
addtohashtable(s,n) char *s; { void addtohashtable(char *s, int n)
{
/* /*
* Add a new pattern number to the hashtable. * Add a new pattern number to the hashtable.
* s is the key, n the pattern number * s is the key, n the pattern number
@@ -55,8 +57,8 @@ addtohashtable(s,n) char *s; {
hashtable[hval] = p; hashtable[hval] = p;
} }
static static void prhlist(struct hlist *p)
prhlist(p) struct hlist *p; { {
/* /*
* Print a list in reversed order (see comment above) * Print a list in reversed order (see comment above)
*/ */
@@ -67,13 +69,14 @@ prhlist(p) struct hlist *p; {
} }
} }
printhashtable() { void printhashtable()
{
/* /*
* Print the linear lists, and also output an array of * Print the linear lists, and also output an array of
* pointers to them * pointers to them
*/ */
register i; int i;
register struct hlist *p; struct hlist *p;
for (i = 1; i <= 128; i++) { for (i = 1; i <= 128; i++) {
fprintf(genc,"int hash%d[] = { ",i); fprintf(genc,"int hash%d[] = { ",i);

View File

@@ -19,8 +19,8 @@ static int nerrors;
char *linedir = "#line %d \"%s\"\n"; /* format of line directive */ char *linedir = "#line %d \"%s\"\n"; /* format of line directive */
char *inpfile; char *inpfile;
main(argc,argv) char *argv[]; { int main(int argc, char *argv[])
{
newline = 1; newline = 1;
if (argc != 2) { if (argc != 2) {
fprintf(stderr,"Usage : %s targetoptimizerdescription\n",argv[0]); fprintf(stderr,"Usage : %s targetoptimizerdescription\n",argv[0]);
@@ -44,16 +44,16 @@ main(argc,argv) char *argv[]; {
} }
/* VARARGS1 */ /* VARARGS1 */
error(s, s1) char *s, *s1; { void error(char *s, char *s1)
{
nerrors++; nerrors++;
fprintf(stderr,"\"%s\", line %d: ",inpfile,lineno); fprintf(stderr,"\"%s\", line %d: ",inpfile,lineno);
fprintf(stderr,s,s1); fprintf(stderr,s,s1);
putc('\n',stderr); putc('\n',stderr);
} }
onlyspace(s) register char *s; { int onlyspace(char *s)
{
while (*s) { while (*s) {
if (*s != ' ' && *s != '\t' && *s != '\n') return 0; if (*s != ' ' && *s != '\t' && *s != '\n') return 0;
s++; s++;

View File

@@ -12,6 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include "misc.h" #include "misc.h"
#include "symtab.h" #include "symtab.h"
@@ -31,7 +32,8 @@ static struct pattern *pattable, /* ptr to pattern array */
* be allocated * be allocated
*/ */
addpattern(str,l,np,nr) char *str; { void addpattern(char *str, int l, int np, int nr)
{
/* /*
* Just add a pattern to the list. * Just add a pattern to the list.
* "str" is the constraint, "l" is the line number, * "str" is the constraint, "l" is the line number,
@@ -39,7 +41,7 @@ addpattern(str,l,np,nr) char *str; {
* "nr" is the number of instructions in the replacement * "nr" is the number of instructions in the replacement
* Space is allocated in chunks of 50 * Space is allocated in chunks of 50
*/ */
register struct pattern *p; struct pattern *p;
if (!pattable) { /* No space allocated yet */ if (!pattable) { /* No space allocated yet */
pattable = (struct pattern *) malloc(50 * sizeof *pattable); pattable = (struct pattern *) malloc(50 * sizeof *pattable);
@@ -61,13 +63,13 @@ addpattern(str,l,np,nr) char *str; {
p->p_nrepl = nr; p->p_nrepl = nr;
} }
static static void prconstraint(char *str)
prconstraint(str) char *str; { {
/* /*
* prints a constraint, with variable names replaced * prints a constraint, with variable names replaced
*/ */
char c; char c;
register char *p, *q; char *p, *q;
struct symtab *name; struct symtab *name;
p = str; p = str;
@@ -103,13 +105,14 @@ prconstraint(str) char *str; {
} }
} }
printpatterns() { void printpatterns()
{
/* /*
* Prints the pattern_descr table and generates the routine * Prints the pattern_descr table and generates the routine
* "check_constraint" * "check_constraint"
*/ */
register struct pattern *p; struct pattern *p;
register i; int i;
p = pattable; p = pattable;
i = 1; i = 1;