Add prototypes to functions in subr.c
Put the declarations in "data.h", because that header declares the types cost_t and token_p. Also #include <cgg_cg.h> from "data.h" to get types c3_p and set_p, and guard <cgg_cg.h> against multiple inclusion.
This commit is contained in:
parent
ba2a45180c
commit
909b0d5bf3
|
@ -4,6 +4,9 @@
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef __CGG_CG_H_INCLUDED
|
||||||
|
#define __CGG_CG_H_INCLUDED
|
||||||
|
|
||||||
/* offsets of interesting fields in EM-pattern */
|
/* offsets of interesting fields in EM-pattern */
|
||||||
|
|
||||||
#define PO_HASH 0
|
#define PO_HASH 0
|
||||||
|
@ -165,3 +168,5 @@ typedef struct { /* one to one coercions */
|
||||||
if ((a=((*(b)++)&BMASK)) >= 128) {\
|
if ((a=((*(b)++)&BMASK)) >= 128) {\
|
||||||
a = ((a-128)<<BSHIFT) | (*(b)++&BMASK); \
|
a = ((a-128)<<BSHIFT) | (*(b)++&BMASK); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* __CGG_CG_H_INCLUDED */
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include <cgg_cg.h> /* set_p, c3_p */
|
||||||
|
|
||||||
typedef struct cost {
|
typedef struct cost {
|
||||||
short ct_space;
|
short ct_space;
|
||||||
short ct_time;
|
short ct_time;
|
||||||
|
@ -69,3 +71,20 @@ typedef struct {
|
||||||
int rl_n; /* number in list */
|
int rl_n; /* number in list */
|
||||||
int rl_list[NREGS];
|
int rl_list[NREGS];
|
||||||
} rl_t,*rl_p;
|
} rl_t,*rl_p;
|
||||||
|
|
||||||
|
/* subr.c */
|
||||||
|
int match(token_p, set_p, int);
|
||||||
|
void instance(int, token_p);
|
||||||
|
int eqtoken(token_p, token_p);
|
||||||
|
int distance(int);
|
||||||
|
unsigned costcalc(cost_t);
|
||||||
|
int ssize(int);
|
||||||
|
int tsize(token_p);
|
||||||
|
void tref(token_p, int);
|
||||||
|
int in_stack(int);
|
||||||
|
#ifdef MAXSPLIT
|
||||||
|
int split(token_p, int *, int, int);
|
||||||
|
#endif
|
||||||
|
unsigned docoerc(token_p, c3_p, int, int, int);
|
||||||
|
unsigned stackupto(token_p, int, int);
|
||||||
|
c3_p findcoerc(token_p, set_p);
|
||||||
|
|
|
@ -4,6 +4,7 @@ static char rcsid[] = "$Id$";
|
||||||
|
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
|
#include "types.h" /* byte, codegen */
|
||||||
#include "mach.h"
|
#include "mach.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -14,8 +15,7 @@ static char rcsid[] = "$Id$";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *progname;
|
char *progname;
|
||||||
extern char startupcode[];
|
extern byte startupcode[]; /* codegen.c */
|
||||||
extern unsigned codegen();
|
|
||||||
int maxply=1;
|
int maxply=1;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
int Debug=0;
|
int Debug=0;
|
||||||
|
@ -25,6 +25,8 @@ char *strtdebug="";
|
||||||
/* fillem.c */
|
/* fillem.c */
|
||||||
void in_init(char *);
|
void in_init(char *);
|
||||||
void in_start(void);
|
void in_start(void);
|
||||||
|
/* subr.c */
|
||||||
|
void itokcost(void);
|
||||||
|
|
||||||
main(argc,argv) char **argv; {
|
main(argc,argv) char **argv; {
|
||||||
register unsigned n;
|
register unsigned n;
|
||||||
|
|
|
@ -26,7 +26,6 @@ move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
|
||||||
register struct reginfo *rp;
|
register struct reginfo *rp;
|
||||||
register byte *tdpb;
|
register byte *tdpb;
|
||||||
int i;
|
int i;
|
||||||
unsigned codegen();
|
|
||||||
|
|
||||||
if (eqtoken(tp1,tp2))
|
if (eqtoken(tp1,tp2))
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -105,7 +104,6 @@ setcc(tp) token_p tp; {
|
||||||
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
|
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
|
||||||
register test_p mp;
|
register test_p mp;
|
||||||
unsigned t;
|
unsigned t;
|
||||||
unsigned codegen();
|
|
||||||
|
|
||||||
if (cocoreg.t_token!=0) {
|
if (cocoreg.t_token!=0) {
|
||||||
if (eqtoken(tp,&cocoreg))
|
if (eqtoken(tp,&cocoreg))
|
||||||
|
|
|
@ -24,10 +24,13 @@ static char rcsid[] = "$Id$";
|
||||||
* Author: Hans van Staveren
|
* Author: Hans van Staveren
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned codegen();
|
static int from_stack(set_p);
|
||||||
|
#ifdef TABLEDEBUG
|
||||||
|
static void ruletrace(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
int match(token_p tp, set_p tep, int optexp) {
|
||||||
register bitno;
|
int bitno;
|
||||||
token_p ct;
|
token_p ct;
|
||||||
result_t result;
|
result_t result;
|
||||||
|
|
||||||
|
@ -52,11 +55,10 @@ match(tp,tep,optexp) register token_p tp; register set_p tep; {
|
||||||
return(result.e_v.e_con);
|
return(result.e_v.e_con);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void instance(int instno, token_p token) {
|
||||||
instance(instno,token) register token_p token; {
|
inst_p inp;
|
||||||
register inst_p inp;
|
|
||||||
int i;
|
int i;
|
||||||
register token_p tp;
|
token_p tp;
|
||||||
#if MAXMEMBERS != 0
|
#if MAXMEMBERS != 0
|
||||||
struct reginfo *rp;
|
struct reginfo *rp;
|
||||||
#endif
|
#endif
|
||||||
|
@ -70,7 +72,7 @@ instance(instno,token) register token_p token; {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
inp= &tokeninstances[instno];
|
inp= &tokeninstances[instno];
|
||||||
switch(inp->in_which) {
|
switch (inp->in_which) {
|
||||||
default:
|
default:
|
||||||
assert(FALSE);
|
assert(FALSE);
|
||||||
case IN_COPY:
|
case IN_COPY:
|
||||||
|
@ -151,9 +153,8 @@ instance(instno,token) register token_p token; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void cinstance(int instno, token_p token, token_p tp, int regno) {
|
||||||
cinstance(instno,token,tp,regno) register token_p token,tp; {
|
inst_p inp;
|
||||||
register inst_p inp;
|
|
||||||
int i;
|
int i;
|
||||||
#if MAXMEMBERS != 0
|
#if MAXMEMBERS != 0
|
||||||
struct reginfo *rp;
|
struct reginfo *rp;
|
||||||
|
@ -163,7 +164,7 @@ cinstance(instno,token,tp,regno) register token_p token,tp; {
|
||||||
|
|
||||||
assert(instno!=0);
|
assert(instno!=0);
|
||||||
inp= &tokeninstances[instno];
|
inp= &tokeninstances[instno];
|
||||||
switch(inp->in_which) {
|
switch (inp->in_which) {
|
||||||
default:
|
default:
|
||||||
assert(FALSE);
|
assert(FALSE);
|
||||||
case IN_COPY:
|
case IN_COPY:
|
||||||
|
@ -249,9 +250,9 @@ cinstance(instno,token,tp,regno) register token_p token,tp; {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eqtoken(tp1,tp2) token_p tp1,tp2; {
|
int eqtoken(token_p tp1, token_p tp2) {
|
||||||
register i;
|
int i;
|
||||||
register tkdef_p tdp;
|
tkdef_p tdp;
|
||||||
|
|
||||||
if (tp1->t_token!=tp2->t_token)
|
if (tp1->t_token!=tp2->t_token)
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -285,10 +286,10 @@ eqtoken(tp1,tp2) token_p tp1,tp2; {
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
distance(cindex) {
|
int distance(int cindex) {
|
||||||
register char *bp;
|
char *bp;
|
||||||
register i;
|
int i;
|
||||||
register token_p tp;
|
token_p tp;
|
||||||
int tokexp,tpl;
|
int tokexp,tpl;
|
||||||
int expsize,toksize,exact;
|
int expsize,toksize,exact;
|
||||||
int xsekt=0;
|
int xsekt=0;
|
||||||
|
@ -301,7 +302,7 @@ distance(cindex) {
|
||||||
getint(i,bp);
|
getint(i,bp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
switch( (*bp)&037 ) {
|
switch ( (*bp)&037 ) {
|
||||||
default:
|
default:
|
||||||
return(stackheight==0 ? 0 : 100);
|
return(stackheight==0 ? 0 : 100);
|
||||||
case DO_MATCH:
|
case DO_MATCH:
|
||||||
|
@ -362,31 +363,29 @@ distance(cindex) {
|
||||||
return(20-2*exact+fromstackneeded);
|
return(20-2*exact+fromstackneeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern set_t unstackset;
|
extern set_t unstackset; /* tables.c */
|
||||||
|
|
||||||
int from_stack(s1)
|
static int from_stack(set_p s1) {
|
||||||
register set_p s1;
|
set_p s2 = &unstackset;
|
||||||
{
|
int i;
|
||||||
register set_p s2 = &unstackset;
|
|
||||||
register int i;
|
|
||||||
for (i = 0; i < SETSIZE; i++) {
|
for (i = 0; i < SETSIZE; i++) {
|
||||||
if ((s1->set_val[i] & s2->set_val[i]) != 0) return 1;
|
if ((s1->set_val[i] & s2->set_val[i]) != 0) return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned costcalc(cost) cost_t cost; {
|
unsigned costcalc(cost_t cost) {
|
||||||
extern unsigned cc1,cc2,cc3,cc4;
|
extern unsigned cc1,cc2,cc3,cc4; /* tables.c */
|
||||||
|
|
||||||
return(cost.ct_space*cc1/cc2 + cost.ct_time*cc3/cc4);
|
return(cost.ct_space*cc1/cc2 + cost.ct_time*cc3/cc4);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize(tokexpno) {
|
int ssize(int tokexpno) {
|
||||||
|
|
||||||
return(machsets[tokexpno].set_size);
|
return(machsets[tokexpno].set_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsize(tp) register token_p tp; {
|
int tsize(token_p tp) {
|
||||||
|
|
||||||
if (tp->t_token==-1)
|
if (tp->t_token==-1)
|
||||||
return(machregs[tp->t_att[0].ar].r_size);
|
return(machregs[tp->t_att[0].ar].r_size);
|
||||||
|
@ -394,12 +393,12 @@ tsize(tp) register token_p tp; {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MAXSPLIT
|
#ifdef MAXSPLIT
|
||||||
instsize(tinstno,tp) token_p tp; {
|
static int instsize(int tinstno, token_p tp) {
|
||||||
inst_p inp;
|
inst_p inp;
|
||||||
struct reginfo *rp;
|
struct reginfo *rp;
|
||||||
|
|
||||||
inp = &tokeninstances[tinstno];
|
inp = &tokeninstances[tinstno];
|
||||||
switch(inp->in_which) {
|
switch (inp->in_which) {
|
||||||
default:
|
default:
|
||||||
assert(FALSE);
|
assert(FALSE);
|
||||||
case IN_COPY:
|
case IN_COPY:
|
||||||
|
@ -427,9 +426,9 @@ instsize(tinstno,tp) token_p tp; {
|
||||||
}
|
}
|
||||||
#endif /* MAXSPLIT */
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
tref(tp,amount) register token_p tp; {
|
void tref(token_p tp, int amount) {
|
||||||
register i;
|
int i;
|
||||||
register byte *tdpb;
|
byte *tdpb;
|
||||||
|
|
||||||
if (tp->t_token==-1)
|
if (tp->t_token==-1)
|
||||||
chrefcount(tp->t_att[0].ar,amount,FALSE);
|
chrefcount(tp->t_att[0].ar,amount,FALSE);
|
||||||
|
@ -446,10 +445,10 @@ tref(tp,amount) register token_p tp; {
|
||||||
restore it and check whether a certain register is present in the
|
restore it and check whether a certain register is present in the
|
||||||
saved stack
|
saved stack
|
||||||
*/
|
*/
|
||||||
token_t aside[MAXSAVE] ;
|
static token_t aside[MAXSAVE] ;
|
||||||
int aside_length = -1 ;
|
static int aside_length = -1 ;
|
||||||
|
|
||||||
save_stack(tp) register token_p tp ; {
|
static void save_stack(token_p tp) {
|
||||||
int i ;
|
int i ;
|
||||||
token_p tmp = &fakestack[stackheight - 1];
|
token_p tmp = &fakestack[stackheight - 1];
|
||||||
|
|
||||||
|
@ -467,10 +466,10 @@ save_stack(tp) register token_p tp ; {
|
||||||
stackheight -= aside_length;
|
stackheight -= aside_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_stack(reg) {
|
int in_stack(int reg) {
|
||||||
register token_p tp ;
|
token_p tp ;
|
||||||
register i ;
|
int i ;
|
||||||
register tkdef_p tdp ;
|
tkdef_p tdp ;
|
||||||
|
|
||||||
for ( i=0, tp=aside ; i<aside_length ; i++, tp++ )
|
for ( i=0, tp=aside ; i<aside_length ; i++, tp++ )
|
||||||
if (tp->t_token==-1) {
|
if (tp->t_token==-1) {
|
||||||
|
@ -493,8 +492,8 @@ gotone:
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
rest_stack() {
|
static void rest_stack(void) {
|
||||||
register int i ;
|
int i ;
|
||||||
|
|
||||||
assert(aside_length!= -1);
|
assert(aside_length!= -1);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -508,11 +507,11 @@ rest_stack() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MAXSPLIT
|
#ifdef MAXSPLIT
|
||||||
split(tp,ip,ply,toplevel) token_p tp; register int *ip; {
|
int split(token_p tp, int *ip, int ply, int toplevel) {
|
||||||
register c2_p cp;
|
c2_p cp;
|
||||||
token_t savestack[MAXSAVE];
|
token_t savestack[MAXSAVE];
|
||||||
int ok;
|
int ok;
|
||||||
register i;
|
int i;
|
||||||
int diff;
|
int diff;
|
||||||
token_p stp;
|
token_p stp;
|
||||||
int tpl;
|
int tpl;
|
||||||
|
@ -542,7 +541,7 @@ found:
|
||||||
}
|
}
|
||||||
#endif /* MAXSPLIT */
|
#endif /* MAXSPLIT */
|
||||||
|
|
||||||
unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; register c3_p cp; {
|
unsigned docoerc(token_p tp, c3_p cp, int ply, int toplevel, int forced) {
|
||||||
unsigned cost;
|
unsigned cost;
|
||||||
int tpl; /* saved tokpatlen */
|
int tpl; /* saved tokpatlen */
|
||||||
|
|
||||||
|
@ -556,7 +555,7 @@ unsigned docoerc(tp,cp,ply,toplevel,forced) token_p tp; register c3_p cp; {
|
||||||
return(cost);
|
return(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
unsigned stackupto(token_p limit, int ply, int toplevel) {
|
||||||
token_t savestack[MAXFSTACK];
|
token_t savestack[MAXFSTACK];
|
||||||
token_p stp;
|
token_p stp;
|
||||||
int i,diff;
|
int i,diff;
|
||||||
|
@ -620,7 +619,7 @@ unsigned stackupto(limit,ply,toplevel) token_p limit; {
|
||||||
return(totalcost);
|
return(totalcost);
|
||||||
}
|
}
|
||||||
|
|
||||||
c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
c3_p findcoerc(token_p tp, set_p tep) {
|
||||||
register c3_p cp;
|
register c3_p cp;
|
||||||
token_t rtoken;
|
token_t rtoken;
|
||||||
register i;
|
register i;
|
||||||
|
@ -657,8 +656,8 @@ c3_p findcoerc(tp,tep) token_p tp; set_p tep; {
|
||||||
return(0); /* nothing found */
|
return(0); /* nothing found */
|
||||||
}
|
}
|
||||||
|
|
||||||
itokcost() {
|
void itokcost(void) {
|
||||||
register tkdef_p tdp;
|
tkdef_p tdp;
|
||||||
|
|
||||||
for(tdp=tokens+1;tdp->t_size!=0;tdp++)
|
for(tdp=tokens+1;tdp->t_size!=0;tdp++)
|
||||||
tdp->t_cost.ct_space = costcalc(tdp->t_cost);
|
tdp->t_cost.ct_space = costcalc(tdp->t_cost);
|
||||||
|
@ -695,8 +694,8 @@ void fatal(const char *s, ...) {
|
||||||
|
|
||||||
#ifdef TABLEDEBUG
|
#ifdef TABLEDEBUG
|
||||||
|
|
||||||
ruletrace() {
|
static void ruletrace(void) {
|
||||||
register i;
|
int i;
|
||||||
extern int tablelines[MAXTDBUG];
|
extern int tablelines[MAXTDBUG];
|
||||||
extern int ntableline;
|
extern int ntableline;
|
||||||
extern char *tablename;
|
extern char *tablename;
|
||||||
|
|
|
@ -29,6 +29,8 @@ typedef char * string;
|
||||||
#define WRD_FMT "%ld"
|
#define WRD_FMT "%ld"
|
||||||
#endif /* WRD_FMT */
|
#endif /* WRD_FMT */
|
||||||
|
|
||||||
|
/* codegen.c */
|
||||||
|
unsigned codegen(byte *, int, int, unsigned, int);
|
||||||
/* compute.c */
|
/* compute.c */
|
||||||
string mystrcpy(string);
|
string mystrcpy(string);
|
||||||
string tostring(word);
|
string tostring(word);
|
||||||
|
|
Loading…
Reference in a new issue