More prototypes, less register in mach/proto/ncg

Files that #include "equiv.h" must do so after including "data.h", now
that a function prototype in equiv.h uses type rl_p from data.h.

Adjust style, changing some `for(...)` to `for (...)`.  The style in
mach/proto/ncg is less than consistent; the big annoyance now is that
some files want tabs at 4 spaces, others want tabs at 8 spaces.
This commit is contained in:
George Koehler 2017-11-13 12:44:17 -05:00
parent 909b0d5bf3
commit e04166b85d
23 changed files with 184 additions and 166 deletions

View file

@ -27,13 +27,6 @@ static char rcsid[] = "$Id$";
byte startupcode[] = { DO_NEXTEM };
byte* nextem();
unsigned costcalc();
unsigned docoerc();
unsigned stackupto();
string tostring();
string ad2str();
#ifdef NDEBUG
#define DEBUG(string)
#else
@ -124,7 +117,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
byte* bp;
int n;
unsigned mindistance, dist;
register i;
int i;
int cindex;
int npos, pos[MAXRULE];
unsigned mincost, t;
@ -295,8 +288,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
DEBUG("XXMATCH");
case DO_XMATCH:
{
register i;
int temp;
int i, temp;
DEBUG("XMATCH");
tokpatlen = (codep[-1] >> 5) & 07;
@ -306,8 +298,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
}
case DO_MATCH:
{
register i;
int j;
int i, j;
unsigned mincost, t;
token_p tp;
int size, lsize;
@ -603,8 +594,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
case DO_KILLREG:
case DO_RREMOVE:
{ /* register remove */
register i;
int nodeno;
int i, nodeno;
token_p tp;
tkdef_p tdp;
result_t result;
@ -650,7 +640,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
}
case DO_DEALLOCATE:
{
register i;
int i;
tkdef_p tdp;
int tinstno;
token_t token;
@ -684,8 +674,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
}
case DO_ALLOCATE:
{
register i;
int j;
int i, j;
int tinstno;
int npos, npos2, pos[NREGS], pos2[NREGS];
unsigned mincost, t;
@ -844,8 +833,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
}
case DO_INSTR:
{
register i;
int n;
int i, n;
int tinstno;
token_t token;
int stringno;
@ -933,7 +921,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
}
case DO_TOKREPLACE:
{
register i;
int i;
int tinstno;
int repllen;
token_t reptoken[MAXREPLLEN];
@ -969,8 +957,7 @@ unsigned codegen(byte* codep, int ply, int toplevel, unsigned costlimit, int for
}
case DO_EMREPLACE:
{
register i;
int j;
int i, j;
int nodeno;
result_t result[MAXEMREPLLEN];
int emrepllen, eminstr;
@ -1093,10 +1080,10 @@ doreturn:
return (totalcost);
}
readcodebytes()
void readcodebytes(void)
{
#ifndef CODEINC
register fd;
int fd;
extern int ncodebytes;
if ((fd = open("code", 0)) < 0)
@ -1108,11 +1095,11 @@ readcodebytes()
error("Short read from code");
}
close(fd);
#endif
#endif /* CODEINC */
}
#ifdef TABLEDEBUG
initlset(f) char* f;
void initlset(char *f)
{
set_flag = f;
@ -1123,7 +1110,7 @@ initlset(f) char* f;
read(set_fd, set_val, set_size);
}
termlset()
void termlset(void)
{
if (set_fd)
@ -1133,7 +1120,7 @@ termlset()
close(set_fd);
if (set_flag[0] == 'u')
{
register i;
int i;
fprintf(stderr, "Unused code rules:\n\n");
for (i = 0; i < 8 * set_size; i++)
@ -1142,4 +1129,4 @@ termlset()
}
}
}
#endif
#endif /* TABLEDEBUG */

View file

@ -35,7 +35,7 @@ static char rcsid[] = "$Id$";
#define LLDEF LLEAF|LDEF
#define RLDEF RLEAF|RDEF
char opdesc[] = {
static const char opdesc[] = {
0, /* EX_TOKFIELD */
0, /* EX_ARG */
0, /* EX_CON */
@ -121,10 +121,9 @@ string tostring(word n) {
return(mystrcpy(buf));
}
void
compute(node, presult) register node_p node; register result_t *presult; {
void compute(node_p node, result_t *presult) {
result_t leaf1,leaf2;
register token_p tp;
token_p tp;
int desc;
long mask,tmp;
int i,tmpreg;

View file

@ -72,6 +72,18 @@ typedef struct {
int rl_list[NREGS];
} rl_t,*rl_p;
/* gencode.c */
void genstr(int);
string ad2str(address_t);
void gennl(void);
void prtoken(token_p, int);
#ifdef USE_TES
void printlabel(int);
#endif
/* move.c */
int move(token_p, token_p, int, int, unsigned);
void setcc(token_p);
int test(token_p, int, int, unsigned);
/* subr.c */
int match(token_p, set_p, int);
void instance(int, token_p);

View file

@ -5,12 +5,12 @@ static char rcsid[] = "$Id$";
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "equiv.h"
#include "param.h"
#include "tables.h"
#include "types.h"
#include <cgg_cg.h>
#include "data.h"
#include "equiv.h"
#include "result.h"
#include "extern.h"
@ -29,11 +29,10 @@ static struct perm *perms;
static void permute(int);
struct perm *
tuples(regls,nregneeded) rl_p *regls; {
struct perm *tuples(rl_p *regls, int nregneeded) {
int class=0;
register i,j;
register struct reginfo *rp;
int i,j;
struct reginfo *rp;
/*
* First compute equivalence classes of registers.

View file

@ -10,3 +10,5 @@ struct perm {
struct perm *p_next;
int p_rar[MAXCREG];
};
struct perm *tuples(rl_p *, int);

View file

@ -54,6 +54,3 @@ extern int *rvnumbers[]; /* lists of numbers */
#endif
extern FILE *codefile;
extern void error(const char *s, ...);
extern void fatal(const char *s, ...);

View file

@ -17,6 +17,7 @@ static char rcsid2[] = "$Id$";
#include "types.h"
#include <cgg_cg.h>
#include "data.h"
#include "glosym.h"
#include "result.h"
#ifdef REGVARS
#include "regvar.h"
@ -103,7 +104,7 @@ static string holstr(word);
/* Own version of atol that continues computing on overflow.
We don't know that about the ANSI C one.
*/
long our_atol(char *s) {
static long our_atol(char *s) {
long total = 0;
unsigned digit;
int minus = 0;
@ -235,13 +236,12 @@ void fillemlines(void) {
void
dopseudo() {
register b,t;
register full n;
register long save;
int b,t;
full n;
long save;
word romcont[MAXROM+1];
int nromwords;
int rombit,rommask;
unsigned stackupto();
if (nextispseu==0 || nemlines>0)
error("No table entry for %d",emlines[0].em_instr);
@ -680,7 +680,7 @@ static long con(int t) {
extern char *segname[];
swtxt() {
void swtxt(void) {
switchseg(SEGTXT);
}

View file

@ -4,6 +4,7 @@ static char rcsid[] = "$Id$";
#include <assert.h>
#include <stdio.h>
#include <unistd.h> /* isatty */
#include "param.h"
#include "tables.h"
#include "types.h"
@ -24,7 +25,7 @@ static char rcsid[] = "$Id$";
FILE *codefile;
out_init(filename) char *filename; {
void out_init(char *filename) {
#ifndef NDEBUG
static char stderrbuff[BUFSIZ];
@ -45,7 +46,7 @@ out_init(filename) char *filename; {
#endif
}
out_finish() {
void out_finish(void) {
#ifndef NDEBUG
if (Debug)
@ -58,18 +59,18 @@ out_finish() {
#endif
}
tstoutput() {
void tstoutput(void) {
if (ferror(codefile))
error("Write error on output");
}
genstr(stringno) {
void genstr(int stringno) {
fputs(codestrings[stringno],codefile);
}
string ad2str(ad) address_t ad; {
string ad2str(address_t ad) {
static char buf[100];
if (ad.ea_str==0)
@ -84,7 +85,7 @@ string ad2str(ad) address_t ad; {
return(mystrcpy(buf));
}
praddr(ad) address_t ad; {
static void praddr(address_t ad) {
if (ad.ea_str==0 || *(ad.ea_str) == '\0')
fprintf(codefile,WRD_FMT,ad.ea_off);
@ -101,15 +102,14 @@ praddr(ad) address_t ad; {
}
}
gennl() {
void gennl(void) {
putc('\n',codefile);
}
void
prtoken(tp,leadingchar) token_p tp; {
register c;
register char *code;
register tkdef_p tdp;
void prtoken(token_p tp, int leadingchar) {
int c;
char *code;
tkdef_p tdp;
putc(leadingchar,codefile);
if (tp->t_token == -1) {
@ -142,9 +142,7 @@ prtoken(tp,leadingchar) token_p tp; {
}
#ifdef USE_TES
printlabel(labnum)
int labnum;
{
void printlabel(int labnum) {
newilb(dollar[labnum].e_v.e_addr.ea_str);
}
#endif

View file

@ -18,9 +18,9 @@ static char rcsid[] = "$Id$";
static glosym_p glolist= (glosym_p) 0;
enterglo(name,romp) string name; word *romp; {
register glosym_p gp;
register i;
void enterglo(string name, word *romp) {
glosym_p gp;
int i;
gp = (glosym_p) myalloc(sizeof *gp);
gp->gl_next = glolist;
@ -31,8 +31,8 @@ enterglo(name,romp) string name; word *romp; {
glolist = gp;
}
glosym_p lookglo(name) string name; {
register glosym_p gp;
glosym_p lookglo(string name) {
glosym_p gp;
for (gp=glolist;gp != (glosym_p) 0; gp=gp->gl_next)
if (strcmp(gp->gl_name,name)==0)

View file

@ -10,4 +10,5 @@ typedef struct glosym {
word gl_rom[MAXROM+1];
} glosym_t,*glosym_p;
glosym_p lookglo();
void enterglo(string, word *);
glosym_p lookglo(string);

View file

@ -6,10 +6,9 @@
static label_p label_list = (label_p)0;
void
add_label(num, height, flth)
void add_label(num, height, flth)
{
register label_p lbl = (label_p)0;
label_p lbl = (label_p)0;
if (height <= 0) return;
if (flth != TRUE && flth != FALSE)
@ -23,10 +22,9 @@ add_label(num, height, flth)
label_list = lbl;
}
label_p get_label(num)
register word num;
label_p get_label(word num)
{
register label_p tmp = label_list;
label_p tmp = label_list;
while (tmp != (label_p)0) {
if (tmp->lb_number == num) return tmp;
@ -35,7 +33,7 @@ register word num;
return (label_p)0;
}
kill_labels()
void kill_labels(void)
{
label_p tmp;

View file

@ -14,4 +14,6 @@ struct label {
short lb_fallthrough;
};
extern label_p get_label();
void add_label(int, int, int);
label_p get_label(word);
void kill_labels(void);

View file

@ -2,9 +2,10 @@
static char rcsid[] = "$Id$";
#endif
#include <stdlib.h> /* atoi */
#include "param.h"
#include "tables.h"
#include "types.h" /* byte, codegen */
#include "types.h"
#include "mach.h"
/*
@ -22,16 +23,11 @@ int Debug=0;
char *strtdebug="";
#endif
/* fillem.c */
void in_init(char *);
void in_start(void);
/* subr.c */
void itokcost(void);
static unsigned ggd(unsigned, unsigned);
main(argc,argv) char **argv; {
register unsigned n;
extern unsigned cc1,cc2,cc3,cc4;
unsigned ggd();
int main(int argc, char **argv) {
unsigned n;
extern unsigned cc1,cc2,cc3,cc4; /* tables.c */
progname = argv[0];
while (--argc && **++argv == '-') {
@ -90,8 +86,8 @@ main(argc,argv) char **argv; {
error("Bombed out of codegen");
}
unsigned ggd(a,b) register unsigned a,b; {
register unsigned c;
unsigned ggd(unsigned a, unsigned b) {
unsigned c;
do {
c = a%b; a=b; b=c;

View file

@ -20,11 +20,11 @@ static char rcsid[] = "$Id$";
* Author: Hans van Staveren
*/
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
register move_p mp;
int move(token_p tp1, token_p tp2, int ply, int toplevel, unsigned maxcost) {
move_p mp;
unsigned t;
register struct reginfo *rp;
register byte *tdpb;
struct reginfo *rp;
byte *tdpb;
int i;
if (eqtoken(tp1,tp2))
@ -96,13 +96,13 @@ move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
#define cocoreg machregs[0].r_contents
setcc(tp) token_p tp; {
void setcc(token_p tp) {
cocoreg = *tp;
}
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
register test_p mp;
int test(token_p tp, int ply, int toplevel, unsigned maxcost) {
test_p mp;
unsigned t;
if (cocoreg.t_token!=0) {

View file

@ -27,11 +27,10 @@ static char rcsid[] = "$Id$";
extern char em_mnem[][4];
#endif
/* fillem.c */
void fillemlines(void);
static int argtyp(int);
byte *trypat(bp,len) register byte *bp; {
register patlen,i;
static byte *trypat(byte *bp, int len) {
int patlen,i;
result_t result;
getint(patlen,bp);
@ -88,7 +87,7 @@ byte *trypat(bp,len) register byte *bp; {
extern char em_flag[];
argtyp(mn) {
static int argtyp(int mn) {
/* op_lab is a special opcode which represents a label definition. It's
* not actually a real EM instruction. Therefore if we try to look it
@ -113,13 +112,13 @@ argtyp(mn) {
}
}
byte *nextem(toplevel) {
register i;
byte *nextem(int toplevel) {
int i;
short hash[3];
register byte *bp;
byte *bp;
byte *cp;
int index;
register struct emline *ep;
struct emline *ep;
if (toplevel) {
if (nemlines && emp>emlines) {

View file

@ -20,10 +20,10 @@ static char rcsid[] = "$Id$";
* Author: Hans van Staveren
*/
chrefcount(regno,amount,tflag) {
register struct reginfo *rp;
void chrefcount(int regno, int amount, int tflag) {
struct reginfo *rp;
#if MAXMEMBERS != 0
register i, tmp;
int i, tmp;
#endif
rp= &machregs[regno];
@ -42,10 +42,10 @@ chrefcount(regno,amount,tflag) {
#endif
}
getrefcount(regno, tflag) {
register struct reginfo *rp;
int getrefcount(int regno, int tflag) {
struct reginfo *rp;
#if MAXMEMBERS != 0
register i,maxcount, tmp;
int i,maxcount, tmp;
#endif
rp= &machregs[regno];
@ -66,10 +66,10 @@ getrefcount(regno, tflag) {
#endif
}
erasereg(regno) {
register struct reginfo *rp = &machregs[regno];
register int i;
register byte *tdpb;
void erasereg(int regno) {
struct reginfo *rp = &machregs[regno];
int i;
byte *tdpb;
#if MAXMEMBERS==0
rp->r_contents.t_token = 0;
@ -108,7 +108,7 @@ erasereg(regno) {
}
#else
extern short clashlist[];
register short *sp = &clashlist[rp->r_iclash];
short *sp = &clashlist[rp->r_iclash];
rp->r_contents.t_token = 0;
while (*sp) {
@ -151,9 +151,9 @@ erasereg(regno) {
#endif
}
cleanregs() {
register struct reginfo *rp;
register i;
void cleanregs(void) {
struct reginfo *rp;
int i;
for (rp=machregs;rp<machregs+NREGS;rp++) {
rp->r_contents.t_token = 0;
@ -163,9 +163,9 @@ cleanregs() {
}
#ifndef NDEBUG
inctcount(regno) {
register struct reginfo *rp;
register i;
static void inctcount(int regno) {
struct reginfo *rp;
int i;
rp = &machregs[regno];
#if MAXMEMBERS!=0
@ -181,10 +181,10 @@ inctcount(regno) {
#endif
}
chkregs() {
register struct reginfo *rp;
register token_p tp;
register byte *tdpb;
void chkregs(void) {
struct reginfo *rp;
token_p tp;
byte *tdpb;
int i;
for (rp=machregs+1;rp<machregs+NREGS;rp++) {

View file

@ -26,9 +26,8 @@ static char rcsid[] = "$Id$";
*/
static struct regvar *rvlist;
struct regvar *
linkreg(long of, int sz, int tp, int sc) {
register struct regvar *rvlp;
struct regvar *linkreg(long of, int sz, int tp, int sc) {
struct regvar *rvlp;
rvlp= (struct regvar *) myalloc(sizeof *rvlp);
rvlp->rv_next = rvlist;
@ -41,11 +40,10 @@ linkreg(long of, int sz, int tp, int sc) {
return(rvlp);
}
void
tryreg(struct regvar *rvlp, int typ) {
void tryreg(struct regvar *rvlp, int typ) {
int score;
register i;
register struct regassigned *ra;
int i;
struct regassigned *ra;
struct regvar *save;
if (typ != reg_any && nregvar[typ]!=0) {
@ -99,8 +97,7 @@ tryreg(struct regvar *rvlp, int typ) {
}
}
void
fixregvars(int saveall) {
void fixregvars(int saveall) {
struct reginfo *rp, *rp2;
struct regvar *rv;
int i, regno, rvtyp;
@ -145,9 +142,8 @@ fixregvars(int saveall) {
f_regsave();
}
int
isregvar(long off) {
register struct regvar *rvlp;
int isregvar(long off) {
struct regvar *rvlp;
for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
if(rvlp->rv_off == off)
@ -156,8 +152,7 @@ isregvar(long off) {
}
#ifdef REGLAP
int
isregvar_size(long off, int size) {
int isregvar_size(long off, int size) {
int regno = isregvar(off);
/*
* A reg_float may have two sizes. If this register has the
@ -175,9 +170,8 @@ isregvar_size(long off, int size) {
}
#endif /* REGLAP */
int
isregtyp(long off) {
register struct regvar *rvlp;
int isregtyp(long off) {
struct regvar *rvlp;
for (rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next)
if (rvlp->rv_off == off)
@ -185,10 +179,9 @@ isregtyp(long off) {
return(-1);
}
void
unlinkregs(void) {
register struct regvar *rvlp,*t;
register struct regassigned *ra;
void unlinkregs(void) {
struct regvar *rvlp,*t;
struct regassigned *ra;
int rvtyp,i;
for (rvlp=rvlist;rvlp!=0;rvlp=t) {

View file

@ -19,3 +19,6 @@ struct result {
#define EV_ADDR 3
typedef struct result result_t;
/* compute.c */
void compute(node_p, result_t *);

View file

@ -35,7 +35,7 @@ int nstab=0;
static void chkstr(string, char *);
string myalloc(size) {
register string p;
string p;
p = (string) calloc((unsigned)size, 1);
if (p==0)
@ -66,7 +66,9 @@ char *salloc(int size) {
return(p);
}
static int compar(char **p1, char **p2) {
static int compar(const void *v1, const void *v2) {
char *const *p1 = v1;
char *const *p2 = v2;
assert(*p1 != *p2);
if (*p1 < *p2)

View file

@ -23,9 +23,9 @@ static char rcsid[] = "$Id$";
extern int nstab; /* salloc.c */
void bmove();
static void bmove(short *, short *, int);
savestatus(sp) register state_p sp; {
void savestatus(state_p sp) {
sp->st_sh = stackheight;
bmove((short *)fakestack,(short *)sp->st_fs,stackheight*sizeof(token_t));
@ -42,7 +42,7 @@ savestatus(sp) register state_p sp; {
sp->st_ns = nstab;
}
restorestatus(sp) register state_p sp; {
void restorestatus(state_p sp) {
stackheight = sp->st_sh;
bmove((short *)sp->st_fs,(short *)fakestack,stackheight*sizeof(token_t));
@ -59,8 +59,7 @@ restorestatus(sp) register state_p sp; {
popstr(sp->st_ns);
}
void
bmove(from,to,nbytes) register short *from,*to; register nbytes; {
static void bmove(short *from, short *to, int nbytes) {
if (nbytes<=0)
return;

View file

@ -20,3 +20,7 @@ typedef struct state {
int st_tl; /* tokpatlen */
int st_ns; /* nstab */
} state_t,*state_p;
/* state.c */
void savestatus(state_p);
void restorestatus(state_p);

View file

@ -6,6 +6,7 @@ static char rcsid[] = "$Id$";
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* strcmp */
#include "param.h"
#include "tables.h"
#include "types.h"
@ -562,8 +563,8 @@ unsigned stackupto(token_p limit, int ply, int toplevel) {
int tpl; /* saved tokpatlen */
int nareg; /* saved nareg */
int areg[MAXALLREG];
register c1_p cp;
register token_p tp;
c1_p cp;
token_p tp;
unsigned totalcost=0;
struct reginfo *rp,**rpp;
@ -620,10 +621,10 @@ unsigned stackupto(token_p limit, int ply, int toplevel) {
}
c3_p findcoerc(token_p tp, set_p tep) {
register c3_p cp;
c3_p cp;
token_t rtoken;
register i;
register struct reginfo **rpp;
int i;
struct reginfo **rpp;
for (cp=c3coercs;cp->c3_texpno>=0; cp++) {
if (tp!=(token_p) 0) {

View file

@ -31,12 +31,38 @@ typedef char * string;
/* codegen.c */
unsigned codegen(byte *, int, int, unsigned, int);
void readcodebytes(void);
#ifdef TABLEDEBUG
void initlset(char *);
void termlset(void);
#endif
/* compute.c */
string mystrcpy(string);
string tostring(word);
/* fillem.c */
void in_init(char *);
void in_start(void);
void fillemlines(void);
void swtxt(void);
/* gencode.c */
void out_init(char *);
void out_finish(void);
void tstoutput(void);
/* nextem.c */
byte *nextem(int);
/* reg.c */
void chrefcount(int, int, int);
int getrefcount(int, int);
void erasereg(int);
void cleanregs(void);
void chkregs(void);
/* salloc.c */
string myalloc(int);
void myfree(string);
void popstr(int);
char *salloc(int);
void garbage_collect(void);
/* subr.c */
void itokcost(void);
void error(const char *s, ...);
void fatal(const char *s, ...);