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

View file

@ -72,6 +72,18 @@ typedef struct {
int rl_list[NREGS]; int rl_list[NREGS];
} rl_t,*rl_p; } 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 */ /* subr.c */
int match(token_p, set_p, int); int match(token_p, set_p, int);
void instance(int, token_p); void instance(int, token_p);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -10,4 +10,5 @@ typedef struct glosym {
word gl_rom[MAXROM+1]; word gl_rom[MAXROM+1];
} glosym_t,*glosym_p; } 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; static label_p label_list = (label_p)0;
void void add_label(num, height, flth)
add_label(num, height, flth)
{ {
register label_p lbl = (label_p)0; label_p lbl = (label_p)0;
if (height <= 0) return; if (height <= 0) return;
if (flth != TRUE && flth != FALSE) if (flth != TRUE && flth != FALSE)
@ -23,10 +22,9 @@ add_label(num, height, flth)
label_list = lbl; label_list = lbl;
} }
label_p get_label(num) label_p get_label(word num)
register word num;
{ {
register label_p tmp = label_list; label_p tmp = label_list;
while (tmp != (label_p)0) { while (tmp != (label_p)0) {
if (tmp->lb_number == num) return tmp; if (tmp->lb_number == num) return tmp;
@ -35,7 +33,7 @@ register word num;
return (label_p)0; return (label_p)0;
} }
kill_labels() void kill_labels(void)
{ {
label_p tmp; label_p tmp;

View file

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

View file

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

View file

@ -27,11 +27,10 @@ static char rcsid[] = "$Id$";
extern char em_mnem[][4]; extern char em_mnem[][4];
#endif #endif
/* fillem.c */ static int argtyp(int);
void fillemlines(void);
byte *trypat(bp,len) register byte *bp; { static byte *trypat(byte *bp, int len) {
register patlen,i; int patlen,i;
result_t result; result_t result;
getint(patlen,bp); getint(patlen,bp);
@ -42,7 +41,7 @@ byte *trypat(bp,len) register byte *bp; {
if (patlen != len) if (patlen != len)
return(0); return(0);
} }
for(i=0;i<patlen;i++) for (i=0;i<patlen;i++)
if (emp[i].em_instr != (*bp++&BMASK)) if (emp[i].em_instr != (*bp++&BMASK))
return(0); return(0);
for (i=0;i<patlen;i++) for (i=0;i<patlen;i++)
@ -88,7 +87,7 @@ byte *trypat(bp,len) register byte *bp; {
extern char em_flag[]; extern char em_flag[];
argtyp(mn) { static int argtyp(int mn) {
/* op_lab is a special opcode which represents a label definition. It's /* 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 * not actually a real EM instruction. Therefore if we try to look it
@ -97,7 +96,7 @@ argtyp(mn) {
if (mn == op_lab) if (mn == op_lab)
return EV_UNDEF; return EV_UNDEF;
switch(em_flag[mn-sp_fmnem]&EM_PAR) { switch (em_flag[mn-sp_fmnem]&EM_PAR) {
case PAR_W: case PAR_W:
case PAR_S: case PAR_S:
case PAR_Z: case PAR_Z:
@ -113,13 +112,13 @@ argtyp(mn) {
} }
} }
byte *nextem(toplevel) { byte *nextem(int toplevel) {
register i; int i;
short hash[3]; short hash[3];
register byte *bp; byte *bp;
byte *cp; byte *cp;
int index; int index;
register struct emline *ep; struct emline *ep;
if (toplevel) { if (toplevel) {
if (nemlines && emp>emlines) { if (nemlines && emp>emlines) {

View file

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

View file

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

View file

@ -19,3 +19,6 @@ struct result {
#define EV_ADDR 3 #define EV_ADDR 3
typedef struct result result_t; 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 *); static void chkstr(string, char *);
string myalloc(size) { string myalloc(size) {
register string p; string p;
p = (string) calloc((unsigned)size, 1); p = (string) calloc((unsigned)size, 1);
if (p==0) if (p==0)
@ -66,7 +66,9 @@ char *salloc(int size) {
return(p); 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); assert(*p1 != *p2);
if (*p1 < *p2) if (*p1 < *p2)
@ -88,7 +90,7 @@ void garbage_collect(void) {
qsort((char *)stab,nstab,sizeof (char *),compar); qsort((char *)stab,nstab,sizeof (char *),compar);
for (i=0;i<nstab;i++) for (i=0;i<nstab;i++)
used[i]= FALSE; used[i]= FALSE;
for(emlp=emlines;emlp<emlines+nemlines;emlp++) for (emlp=emlines;emlp<emlines+nemlines;emlp++)
chkstr(emlp->em_soper,used); chkstr(emlp->em_soper,used);
for (tp= fakestack;tp<&fakestack[stackheight];tp++) { for (tp= fakestack;tp<&fakestack[stackheight];tp++) {
if (tp->t_token== -1) if (tp->t_token== -1)

View file

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

View file

@ -20,3 +20,7 @@ typedef struct state {
int st_tl; /* tokpatlen */ int st_tl; /* tokpatlen */
int st_ns; /* nstab */ int st_ns; /* nstab */
} state_t,*state_p; } 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 <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> /* strcmp */
#include "param.h" #include "param.h"
#include "tables.h" #include "tables.h"
#include "types.h" #include "types.h"
@ -562,8 +563,8 @@ unsigned stackupto(token_p limit, int ply, int toplevel) {
int tpl; /* saved tokpatlen */ int tpl; /* saved tokpatlen */
int nareg; /* saved nareg */ int nareg; /* saved nareg */
int areg[MAXALLREG]; int areg[MAXALLREG];
register c1_p cp; c1_p cp;
register token_p tp; token_p tp;
unsigned totalcost=0; unsigned totalcost=0;
struct reginfo *rp,**rpp; 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) { c3_p findcoerc(token_p tp, set_p tep) {
register c3_p cp; c3_p cp;
token_t rtoken; token_t rtoken;
register i; int i;
register struct reginfo **rpp; struct reginfo **rpp;
for (cp=c3coercs;cp->c3_texpno>=0; cp++) { for (cp=c3coercs;cp->c3_texpno>=0; cp++) {
if (tp!=(token_p) 0) { if (tp!=(token_p) 0) {

View file

@ -31,12 +31,38 @@ typedef char * string;
/* codegen.c */ /* codegen.c */
unsigned codegen(byte *, int, int, unsigned, int); unsigned codegen(byte *, int, int, unsigned, int);
void readcodebytes(void);
#ifdef TABLEDEBUG
void initlset(char *);
void termlset(void);
#endif
/* compute.c */ /* compute.c */
string mystrcpy(string); string mystrcpy(string);
string tostring(word); 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 */ /* salloc.c */
string myalloc(int); string myalloc(int);
void myfree(string); void myfree(string);
void popstr(int); void popstr(int);
char *salloc(int); char *salloc(int);
void garbage_collect(void); void garbage_collect(void);
/* subr.c */
void itokcost(void);
void error(const char *s, ...);
void fatal(const char *s, ...);