ANSI C conversion and add procedure declarations.

This commit is contained in:
carl 2019-05-11 01:17:24 +08:00
parent 0301827482
commit 472654c366
24 changed files with 2035 additions and 1518 deletions

View file

@ -14,6 +14,9 @@ static char rcsid[]= "$Id$";
#include "iocc.h"
#include "instruct.h"
#include "expr.h"
#include "coerc.h"
#include "hall.h"
#include "subr.h"
#include "extern.h"
#include <cgg_cg.h>
#include <em_reg.h>
@ -49,6 +52,14 @@ iocc_t subr_iocc(),tokm_iocc(),ident_iocc(),all_iocc(),percident_iocc(), descr_i
extern int narexpr;
extern expr_t arexp[];
extern void skipupto(int tok,char *str);
extern void outpatterns(void);
extern void dopattern(int stackcoerc, varinfo *kills, varinfo *allocates,
varinfo *generates, varinfo *yields, varinfo *leaving);
extern int yylex(void);
extern int argtyp(int mn);
extern void yyerror (char const *s);
int niops;
iocc_t iops[20];
%}

View file

@ -14,6 +14,9 @@ static char rcsid[]= "$Id$";
#include "token.h"
#include "varinfo.h"
#include "iocc.h"
#include "subr.h"
#include "hall.h"
#include "coerc.h"
#include <cgg_cg.h>
#include "pseudo.h"
#include "extern.h"
@ -24,10 +27,15 @@ int nmoves;
move_t l_moves[MAXMOVES];
short posmoves[MAXREGS + MAXTOKENS][SETSIZE];
void
n_move(s1,e1,s2,e2,vi) struct varinfo *vi; {
void n_split(int , int, struct varinfo *, struct varinfo *, struct varinfo *, int);
extern void dopattern(int stackcoerc, varinfo *kills, varinfo *allocates,
varinfo *generates, varinfo *yields, varinfo *leaving);;
void n_move(int s1, int e1, int s2, int e2, struct varinfo *vi)
{
register move_p mp;
register i,j;
register int i, j;
NEXT(nmoves, MAXMOVES, "Moves");
mp = &l_moves[nmoves - 1];
@ -45,8 +53,9 @@ n_move(s1,e1,s2,e2,vi) struct varinfo *vi; {
posmoves[i][j] |= l_sets[mp->m_set2].set_val[j];
}
existmove(from,sp) iocc_t from; short *sp; {
register i;
int existmove(iocc_t from, short *sp)
{
register int i;
for (i = 0; i < MAXREGS + MAXTOKENS; i++)
if (BIT(from.in_set, i))
@ -55,19 +64,22 @@ existmove(from,sp) iocc_t from; short *sp; {
return (1);
}
existalmove(from,prpno) iocc_t from; {
int existalmove(iocc_t from, int prpno)
{
short s[SETSIZE];
register i;
register int i;
for (i = 0; i < SETSIZE; i++)
s[i] = i < SZOFSET(MAXREGS) ? l_props[prpno].pr_regset[i] : 0;
return (existmove(from, s));
}
struct varinfo *gen_move(from,to) iocc_t from,to; {
struct varinfo *gen_move(iocc_t from, iocc_t to)
{
register struct varinfo *vp;
if (existmove(from,to.in_set)==0) {
if (existmove(from, to.in_set) == 0)
{
error("No such move defined");
return (VI_NULL );
}
@ -82,10 +94,10 @@ int ntests;
test_t l_tests[MAXTESTS];
short postests[SETSIZE];
void
n_test(s,e,vi) struct varinfo *vi; {
void n_test(int s, int e, struct varinfo *vi)
{
register test_p tp;
register i;
register int i;
NEXT(ntests, MAXTESTS, "Tests");
tp = &l_tests[ntests - 1];
@ -99,10 +111,12 @@ n_test(s,e,vi) struct varinfo *vi; {
postests[i] |= l_sets[tp->t_set].set_val[i];
}
struct varinfo *gen_test(from) iocc_t from; {
struct varinfo *gen_test(iocc_t from)
{
register struct varinfo *vp;
if (!subset(from.in_set,postests,SETSIZE)) {
if (!subset(from.in_set, postests, SETSIZE))
{
error("No such test");
return (0);
}
@ -112,7 +126,8 @@ struct varinfo *gen_test(from) iocc_t from; {
return (vp);
}
struct varinfo *gen_label(arg) int arg; {
struct varinfo *gen_label(int arg)
{
register struct varinfo *vp;
NEW(vp, struct varinfo);
@ -121,7 +136,8 @@ struct varinfo *gen_label(arg) int arg; {
return (vp);
}
struct varinfo *gen_preturn() {
struct varinfo *gen_preturn(void)
{
register struct varinfo *vp;
NEW(vp, struct varinfo);
@ -129,7 +145,8 @@ struct varinfo *gen_preturn() {
return (vp);
}
struct varinfo *gen_tlab(n) {
struct varinfo *gen_tlab(int n)
{
register struct varinfo *vp;
assert(n >= 0 && n <= 9);
@ -143,10 +160,11 @@ int nstacks;
c1_t l_stacks[MAXSTACKS];
set_t ustackset, cstackset;
n_stack(s,e,p,vi) struct varinfo *vi; {
void n_stack(int s, int e, int p, struct varinfo *vi)
{
register c1_p c1p;
register short *sp;
register i;
register int i;
NEXT(nstacks, MAXSTACKS, "Stacks");
c1p = &l_stacks[nstacks - 1];
@ -164,15 +182,16 @@ n_stack(s,e,p,vi) struct varinfo *vi; {
sp[i] |= l_sets[s].set_val[i];
}
void
checkstacking(sp) register short *sp; {
register i;
void checkstacking(register short *sp)
{
register int i;
register short *chkset;
char *warn;
if (subset(sp, ustackset.set_val, SETSIZE))
return;
chkset = ustackset.set_val; warn = "";
chkset = ustackset.set_val;
warn = "";
for (i = 1; i < nregs; i++)
if (BIT(sp,i) && !BIT(chkset, i))
error("No %sstacking rule for register %s", warn,
@ -189,25 +208,32 @@ set_t unstackset;
/*VARARGS5*/
void
n_coerc(ti,be,al,ge,rp,in) struct varinfo *al,*ge,*rp; iocc_t in; {
void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in)
{
register c3_p c3p;
register i;
register int i;
register struct varinfo *vi;
if (ti!=0) {
if (ti != 0)
{
for (i = 0, vi = rp; vi != 0; vi = vi->vi_next, i++)
;
if (i>1) {
if (i > 1)
{
n_split(ti, be, al, ge, rp, i);
return;
} else {
if (i==0) {
}
else
{
if (i == 0)
{
error("Coercion should have a result!");
return;
}
}
} else {
}
else
{
NEW(rp, struct varinfo);
rp->vi_next = 0;
rp->vi_int[0] = in.in_index;
@ -228,9 +254,10 @@ n_coerc(ti,be,al,ge,rp,in) struct varinfo *al,*ge,*rp; iocc_t in; {
freevi(rp);
}
checkunstacking(setno) {
void checkunstacking(int setno)
{
register short *sp;
register i;
register int i;
short hallset[SETSIZE];
sp = l_sets[setno].set_val;
@ -242,18 +269,21 @@ checkunstacking(setno) {
int nsplit, maxsplit;
c2_t l_split[MAXSPLCOERC];
n_split(ti,be,al,ge,rp,n) struct varinfo *al,*ge,*rp; {
void n_split(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, int n)
{
register c2_p c2p;
register i;
register int i;
register struct varinfo *vi;
NEXT(nsplit, MAXSPLCOERC, "Splitting coercions");
c2p = &l_split[nsplit - 1];
if (n>MAXSPLIT) {
if (n > MAXSPLIT)
{
error("Maximum split factor is %d", MAXSPLIT);
n = MAXSPLIT;
}
if (n>maxsplit) maxsplit=n;
if (n > maxsplit)
maxsplit = n;
c2p->c2_texpno = ti;
c2p->c2_expr = be;
if (nallreg)

30
util/ncgg/coerc.h Normal file
View file

@ -0,0 +1,30 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-05-03
*
*/
#ifndef COERC_H_
#define COERC_H_
#include "iocc.h"
struct varinfo;
void n_move(int s1, int e1, int s2, int e2, struct varinfo *vi);
int existalmove(iocc_t from, int prpno);
struct varinfo *gen_move(iocc_t from, iocc_t to);
void n_test(int s, int e, struct varinfo *vi);
struct varinfo *gen_test(iocc_t from);
struct varinfo *gen_label(int arg);
struct varinfo *gen_preturn(void);
struct varinfo *gen_tlab(int n);
void n_stack(int s, int e, int p, struct varinfo *vi);
void checkstacking(register short *sp);
/* cgg.y is buggy!!! it has one less parameter.. */
/*void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in);*/
void checkunstacking(int setno);
#endif /* COERC_H_ */

View file

@ -18,29 +18,38 @@ extern char em_mnem[][4];
#define HASHSIZE (2*(sp_lmnem-sp_fmnem))
struct emhashmnem {
struct emhashmnem
{
char h_name[3];
char h_value;
} emhashmnem[HASHSIZE];
initemhash() {
register i;
/* Forward declarations */
static void enter(char *, int);
static unsigned emhash(register char *);
void initemhash(void)
{
register int i;
for (i = 0; i <= sp_lmnem - sp_fmnem; i++)
enter(em_mnem[i], i + sp_fmnem);
enter("lab", op_lab);
}
unsigned emhash(name) register char *name; {
register unsigned sum;
register i;
static unsigned emhash(register char *name)
{
register unsigned int sum;
register int i;
for (sum = i = 0; *name; i += 3)
sum ^= (*name++) << (i & 07);
return (sum);
}
enter(name,value) char *name; {
static void enter(char *name, int value)
{
register unsigned h;
h = emhash(name) % HASHSIZE;
@ -50,21 +59,24 @@ enter(name,value) char *name; {
emhashmnem[h].h_value = value;
}
int mlookup(name) char *name; {
int mlookup(char *name)
{
register unsigned h;
h = emhash(name) % HASHSIZE;
while (strncmp(emhashmnem[h].h_name,name,3) != 0 &&
emhashmnem[h].h_name[0] != 0)
while (strncmp(emhashmnem[h].h_name, name, 3) != 0
&& emhashmnem[h].h_name[0] != 0)
h = (h + 1) % HASHSIZE;
return (emhashmnem[h].h_value & 0xFF); /* 0 if not found */
}
extern char em_flag[];
argtyp(mn) {
int argtyp(int mn)
{
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
switch (em_flag[mn - sp_fmnem] & EM_PAR)
{
case PAR_W:
case PAR_S:
case PAR_Z:

View file

@ -13,12 +13,12 @@ static char rcsid[]= "$Id$";
int nerrors=0;
yyerror(s) char *s; {
void yyerror(char *s)
{
error("Parser gives %s",s);
}
goodbye() {
void goodbye(void) {
error("This was fatal, goodbye!");
#ifndef NDEBUG
@ -60,7 +60,8 @@ void error(const char* s, ...)
va_end(ap);
}
tabovf(string) char *string; {
int tabovf(char *string)
{
fatal("%s overflow",string);
return 0;
}

View file

@ -24,20 +24,23 @@ static char rcsid[]= "$Id$";
extern set_t l_sets[];
i_expr(e) expr_t e; {
int i_expr(expr_t e)
{
if (e.ex_typ != TYPINT)
error("Expression should be integer");
return (e.ex_index);
}
b_expr(e) expr_t e; {
int b_expr(expr_t e)
{
if (e.ex_typ != TYPBOOL)
error("Expression should be boolean");
return (e.ex_index);
}
expr_t make_expr(type,operator,op1,op2) {
expr_t make_expr(int type, int operator, int op1, int op2)
{
expr_t result;
result.ex_typ = type;
@ -45,9 +48,10 @@ expr_t make_expr(type,operator,op1,op2) {
return (result);
}
expr_t regno_expr(regno) {
expr_t regno_expr(int regno)
{
expr_t result;
register i;
register int i;
result.ex_typ = TYPREG;
result.ex_index = ex_lookup(EX_REG, regno, 0);
@ -57,7 +61,8 @@ expr_t regno_expr(regno) {
return (result);
}
expr_t ident_expr(name) char *name; {
expr_t ident_expr(char *name)
{
register symbol *sy_p;
sy_p = lookup(name, symany, mustexist);
@ -72,7 +77,8 @@ expr_t ident_expr(name) char *name; {
return (regno_expr(sy_p->sy_value.syv_regno));
}
expr_t subreg_expr(tokarg,subreg) {
expr_t subreg_expr(int tokarg, int subreg)
{
expr_t result;
result.ex_typ = TYPREG;
@ -82,75 +88,92 @@ expr_t subreg_expr(tokarg,subreg) {
return (result);
}
subregset(sp,subreg,regset) register short *sp; register short *regset; {
register i;
void subregset(register short *sp, int subreg, register short *regset)
{
register int i;
register reginfo *rp;
for (i = 0; i < SZOFSET(MAXREGS); i++)
regset[i] = 0;
for (i=1;i<nregs;i++) if (BIT(sp,i)) {
if(subreg) {
for (i = 1; i < nregs; i++)
if (BIT(sp, i))
{
if (subreg)
{
rp = &l_regs[i];
if (rp->ri_memb[subreg - 1] == 0)
error("Register %s in set has no member %d",
rp->ri_name,subreg);
error("Register %s in set has no member %d", rp->ri_name,
subreg);
BIS(regset, rp->ri_memb[subreg - 1]);
} else
}
else
BIS(regset, i);
}
for(;i<nregs+MAXTOKENS;i++) if(BIT(sp,i))
for (; i < nregs + MAXTOKENS; i++)
if (BIT(sp, i))
error("Set contains %s, which is not a register",
l_tokens[i - nregs]->tk_name);
}
membset(setno,name,regset,appearance,restyp,typp)
char *name,*appearance;
short *regset;
int *typp;
int membset(int setno, char *name, short *regset, char *appearance, int restyp, int *typp)
{
register short *sp;
register token_p tp;
register i,j,k;
register int i, j, k;
int thistyp;
int typesdiffer = 0;
int res_j = -1;
if (setno < 0) return 0;
if (setno < 0)
return 0;
sp = l_sets[setno].set_val;
for (i=1;i<nregs;i++) if (BIT(sp,i)) {
error("Set in %s contains %s, which is not a token",
appearance,l_regs[i].ri_name);
for (i = 1; i < nregs; i++)
if (BIT(sp, i))
{
error("Set in %s contains %s, which is not a token", appearance,
l_regs[i].ri_name);
break;
}
for (i = 0; i < SZOFSET(MAXREGS); i++)
regset[i] = 0;
for (i=nregs;i<nregs+MAXTOKENS;i++) if (BIT(sp,i)) {
for (i = nregs; i < nregs + MAXTOKENS; i++)
if (BIT(sp, i))
{
tp = l_tokens[i - nregs];
for(j=0;j<MAXATT &&
(tp->tk_att[j].ta_type == -3 ||
strcmp(tp->tk_att[j].ta_name,name));j++)
for (j = 0;
j < MAXATT
&& (tp->tk_att[j].ta_type == -3
|| strcmp(tp->tk_att[j].ta_name, name));
j++)
;
if (j == MAXATT)
error("Token %s does not contain %s", tp->tk_name, name);
else if (j != res_j && res_j != -1)
typesdiffer = 1;
else {
else
{
res_j = j;
thistyp = tp->tk_att[j].ta_type;
if (thistyp== -2) {
if (thistyp == -2)
{
if (restyp != TYPADDR && restyp != 0)
typesdiffer = 1;
else
restyp = TYPADDR;
} else if (thistyp== -1) {
}
else if (thistyp == -1)
{
if (restyp != TYPINT && restyp != 0)
typesdiffer = 1;
else
restyp = TYPINT;
} else {
}
else
{
if (restyp != TYPREG && restyp != 0)
typesdiffer = 1;
else {
else
{
restyp = TYPREG;
for (k = 0; k < SZOFSET(MAXREGS); k++)
regset[k] |=
@ -166,16 +189,19 @@ int *typp;
return (res_j == -1 ? 0 : res_j);
}
expr_t memb_expr(setno,name,appearance,tokarg) char *name,*appearance; {
expr_t memb_expr(int setno, char *name, char *appearance, int tokarg)
{
expr_t result;
int res_j;
res_j = membset(setno,name,result.ex_regset,appearance,0,&result.ex_typ);
res_j = membset(setno, name, result.ex_regset, appearance, 0,
&result.ex_typ);
result.ex_index = ex_lookup(EX_TOKFIELD, tokarg, res_j + 1);
return (result);
}
expr_t tokm_expr(tokarg,name) char *name; {
expr_t tokm_expr(int tokarg, char *name)
{
char app[100];
int tokarg1 = tokarg > 0 ? tokarg : 1;
@ -183,16 +209,18 @@ expr_t tokm_expr(tokarg,name) char *name; {
return (memb_expr(tokpatset[tokarg1 - 1], name, app, tokarg));
}
expr_t perc_ident_expr(name) char *name; {
expr_t perc_ident_expr(char *name)
{
char app[100];
sprintf(app, "%%%s", name);
return (memb_expr(cursetno, name, app, 0));
}
expr_t all_expr(all_no,subreg) {
expr_t all_expr(int all_no, int subreg)
{
set_t localset;
register i;
register int i;
register short *sp;
expr_t result;
@ -205,12 +233,15 @@ expr_t all_expr(all_no,subreg) {
return (result);
}
eq2expr(e1,e2) expr_t e1,e2; {
int eq2expr(expr_t e1, expr_t e2)
{
if (e1.ex_typ != e2.ex_typ)
error("Expressions around == should have equal type");
switch (e1.ex_typ) {
default: assert(0);
switch (e1.ex_typ)
{
default:
assert(0);
case TYPBOOL:
error("== on booleans not implemented");
case TYPINT:
@ -222,12 +253,15 @@ eq2expr(e1,e2) expr_t e1,e2; {
}
}
ne2expr(e1,e2) expr_t e1,e2; {
int ne2expr(expr_t e1, expr_t e2)
{
if (e1.ex_typ != e2.ex_typ)
error("Expressions around != should have equal type");
switch (e1.ex_typ) {
default: assert(0);
switch (e1.ex_typ)
{
default:
assert(0);
case TYPBOOL:
error("!= on booleans not implemented");
case TYPINT:
@ -239,25 +273,33 @@ ne2expr(e1,e2) expr_t e1,e2; {
}
}
expr_t sum_expr(e1,e2) expr_t e1,e2; {
expr_t sum_expr(expr_t e1, expr_t e2)
{
int operator, op1, op2;
expr_t result;
operator = EX_CAT; op1 = e1.ex_index; op2 = e2.ex_index;
if (e1.ex_typ==e2.ex_typ) {
operator = EX_CAT;
op1 = e1.ex_index;
op2 = e2.ex_index;
if (e1.ex_typ == e2.ex_typ)
{
result.ex_typ = e1.ex_typ;
if (e1.ex_typ == TYPINT)
operator = EX_PLUS;
else if (e1.ex_typ != TYPADDR)
error("+ is not implemented on this type");
} else {
}
else
{
result.ex_typ = TYPADDR;
if (e1.ex_typ != TYPADDR) {
if (e1.ex_typ != TYPADDR)
{
if (e1.ex_typ != TYPINT)
error("Wrong left operand of +");
op1 = ex_lookup(EX_TOSTRING, op1, 0);
}
if (e2.ex_typ != TYPADDR) {
if (e2.ex_typ != TYPADDR)
{
if (e2.ex_typ != TYPINT)
error("Wrong right operand of +");
op2 = ex_lookup(EX_TOSTRING, op2, 0);
@ -267,7 +309,8 @@ expr_t sum_expr(e1,e2) expr_t e1,e2; {
return (result);
}
expr_t iextoaddr(e) expr_t e; {
expr_t iextoaddr(expr_t e)
{
expr_t result;
result.ex_typ = TYPADDR;
@ -275,12 +318,14 @@ expr_t iextoaddr(e) expr_t e; {
return (result);
}
expr_t regvar_expr(e,regtyp,regsiz) expr_t e; {
expr_t regvar_expr(expr_t e, int regtyp, int regsiz)
{
expr_t result;
int i, regno, s, two_sizes;
two_sizes = (regtyp == reg_float && reglap != 0);
if (regsiz == -1) {
if (regsiz == -1)
{
/* reglap: Can't guess between 2 sizes of reg_float. */
if (two_sizes && regsiz == -1)
error("Must use regvar_w() or regvar_d()");
@ -294,13 +339,16 @@ expr_t regvar_expr(e,regtyp,regsiz) expr_t e; {
/* s = the size of the registers in rvnumbers[regtyp] */
s = two_sizes ? reglap : rvsize[regtyp];
if (s == regsiz) {
if (s == regsiz)
{
for (i = 0; i < nregvar[regtyp]; i++)
BIS(result.ex_regset, rvnumbers[regtyp][i]);
}
/* reglap: Also check the 2nd size of reg_float. */
if (two_sizes && rvsize[regtyp] == regsiz) {
for(i=0;i<nregvar[regtyp];i++) {
if (two_sizes && rvsize[regtyp] == regsiz)
{
for (i = 0; i < nregvar[regtyp]; i++)
{
/* regno = first subregister */
regno = l_regs[rvnumbers[regtyp][i]].ri_memb[0];
if (regno != 0)
@ -317,7 +365,8 @@ expr_t regvar_expr(e,regtyp,regsiz) expr_t e; {
node_t nodes[MAXNODES];
int nnodes = 0;
initnodes() {
void initnodes(void)
{
nodes[0].ex_operator = EX_CON;
nodes[0].ex_lnode = 0;
@ -325,10 +374,12 @@ initnodes() {
nnodes++;
}
ex_lookup(operator,lnode,rnode) {
int ex_lookup(int operator, int lnode, int rnode)
{
register node_p p;
for(p=nodes+1;p< &nodes[nnodes];p++) {
for (p = nodes + 1; p < &nodes[nnodes]; p++)
{
if (p->ex_operator != operator)
continue;
if (p->ex_lnode != lnode)

View file

@ -3,6 +3,8 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#ifndef EXPR_H_
#define EXPR_H_
typedef struct expr {
int ex_typ;
@ -15,6 +17,27 @@ typedef struct expr {
#define TYPADDR 3
#define TYPREG 4
int ex_lookup(int operator, int lnode, int rnode);
void initnodes(void);
expr_t regvar_expr(expr_t e, int regtyp, int regsiz);
expr_t iextoaddr(expr_t e);
expr_t sum_expr(expr_t e1, expr_t e2);
int ne2expr(expr_t e1, expr_t e2);
int eq2expr(expr_t e1, expr_t e2);
expr_t all_expr(int all_no, int subreg);
expr_t perc_ident_expr(char *name);
expr_t tokm_expr(int tokarg, char *name);
int membset(int setno, char *name, short *regset, char *appearance, int restyp, int *typp);
void subregset(register short *sp, int subreg, register short *regset);
expr_t subreg_expr(int tokarg, int subreg);
expr_t ident_expr(char *name);
expr_t make_expr(int type, int operator, int op1, int op2);
int b_expr(expr_t e);
int i_expr(expr_t e);
/* When the type is register the regset contains the set of
possible registers for checking purposes only.
*/
#endif /* EXPR_H_ */

View file

@ -38,9 +38,8 @@ extern int maxtokensize;
extern int nprocargs, maxprocargs;
extern int use_tes;
extern char *mystrcpy();
extern char *myalloc();
extern void error(const char* s, ...);
extern void fatal(const char* s, ...);
extern int tabovf(char *string);
extern int strlookup(char *str);
extern void errorexit(void);

View file

@ -10,11 +10,12 @@ static char rcsid[]= "$Id$";
#include "param.h"
#include "set.h"
#include "extern.h"
#include "hall.h"
#include <stdio.h>
/*
* This file implements the marriage thesis from Hall.
* The thesis says that given a number, say N, of subsets from
* The thesis says that givoid hallverbose(void)ven a number, say N, of subsets from
* a finite set, it is possible to create a set with cardinality N,
* that contains one member for each of the subsets,
* iff for each number, say M, of subsets from 2 to N the union of
@ -32,25 +33,33 @@ short hallsets[MAXHALL][SETSIZE];
int nhallsets = -1;
int hallfreq[MAXHALL][2];
hallverbose() {
register i;
register max;
int recurhall(int, short [][SETSIZE]);
void unite(register short *, short *);
void hallverbose(void)
{
register int i;
register int max;
fprintf(stderr, "Table of hall frequencies\n # pre post\n");
for (max=MAXHALL-1;hallfreq[max][0]==0 && hallfreq[max][1]==0;max--)
for (max = MAXHALL - 1; hallfreq[max][0] == 0 && hallfreq[max][1] == 0;
max--)
;
for (i = 0; i <= max; i++)
fprintf(stderr, "%3d%6d%6d\n", i, hallfreq[i][0], hallfreq[i][1]);
}
inithall() {
void inithall(void)
{
assert(nhallsets == -1);
nhallsets = 0;
}
nexthall(sp) register short *sp; {
register i;
void nexthall(register short *sp)
{
register int i;
assert(nhallsets >= 0);
for (i = 0; i < SETSIZE; i++)
@ -58,8 +67,9 @@ nexthall(sp) register short *sp; {
nhallsets++;
}
card(sp) register short *sp; {
register sum,i;
int card(register short *sp)
{
register int sum, i;
sum = 0;
for (i = 0; i < 8 * sizeof(short) * SETSIZE; i++)
@ -68,15 +78,16 @@ card(sp) register short *sp; {
return (sum);
}
checkhall() {
void checkhall(void)
{
assert(nhallsets >= 0);
if (!hall())
error("Hall says: \"You can't have those registers\"");
}
hall() {
register i,j,k;
int hall(void)
{
register int i, j, k;
int ok;
hallfreq[nhallsets][0]++;
@ -86,14 +97,15 @@ hall() {
* But then nhallsets is less, so this step can be re-applied.
*/
do {
do
{
ok = 0;
for (i = 0; i < nhallsets; i++)
if (card(hallsets[i])>=nhallsets) {
if (card(hallsets[i]) >= nhallsets)
{
for (j = i + 1; j < nhallsets; j++)
for (k = 0; k < SETSIZE; k++)
hallsets[j-1][k] =
hallsets[j][k];
hallsets[j - 1][k] = hallsets[j][k];
nhallsets--;
ok = 1;
break;
@ -110,10 +122,11 @@ hall() {
return (ok);
}
recurhall(nhallsets,hallsets) short hallsets[][SETSIZE]; {
int recurhall(int nhallsets, short hallsets[][SETSIZE])
{
short copysets[MAXHALL][SETSIZE];
short setsum[SETSIZE];
register i,j,k,ncopys;
register int i, j, k, ncopys;
/*
* First check cardinality of union of all
@ -128,9 +141,12 @@ recurhall(nhallsets,hallsets) short hallsets[][SETSIZE]; {
* Now check the hall property of everything but one set,
* for all sets
*/
for(i=0;i<nhallsets;i++) {
for (i = 0; i < nhallsets; i++)
{
ncopys = 0;
for(j=0;j<nhallsets;j++) if (j!=i) {
for (j = 0; j < nhallsets; j++)
if (j != i)
{
for (k = 0; k < SETSIZE; k++)
copysets[ncopys][k] = hallsets[j][k];
ncopys++;
@ -142,8 +158,9 @@ recurhall(nhallsets,hallsets) short hallsets[][SETSIZE]; {
return (1);
}
unite(sp,into) register short *sp,*into; {
register i;
void unite(register short *sp, short *into)
{
register int i;
for (i = 0; i < SETSIZE; i++)
into[i] |= sp[i];

17
util/ncgg/hall.h Normal file
View file

@ -0,0 +1,17 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-05-03
*
*/
#ifndef HALL_H_
#define HALL_H_
void hallverbose(void);
void inithall(void);
int hall(void);
void checkhall(void);
void nexthall(register short *sp);
#endif /* HALL_H_ */

View file

@ -14,19 +14,21 @@ static char rcsid[]= "$Id$";
#include "set.h"
#include "expr.h"
#include "iocc.h"
#include "subr.h"
#include <cgg_cg.h>
#include "extern.h"
extern int niops;
extern iocc_t iops[];
extern inproc;
extern int inproc;
extern set_t l_sets[];
extern inst_t l_instances[];
extern expr_t subreg_expr(), regno_expr();
struct varinfo * setcoco(n) {
static struct varinfo * setcoco(int n)
{
struct varinfo *vi;
NEW(vi, struct varinfo);
@ -36,7 +38,8 @@ struct varinfo * setcoco(n) {
return (vi);
}
struct varinfo * generase(n) {
static struct varinfo * generase(int n)
{
struct varinfo *vi;
NEW(vi, struct varinfo);
@ -46,7 +49,8 @@ struct varinfo * generase(n) {
return (vi);
}
struct varinfo * genremove(n) {
static struct varinfo * genremove(int n)
{
struct varinfo *vi;
NEW(vi, struct varinfo);
@ -56,11 +60,13 @@ struct varinfo * genremove(n) {
return (vi);
}
onlyreg(argno) {
register bitno;
static int onlyreg(int argno)
{
register int bitno;
register short *sp;
if (! argno) argno++;
if (!argno)
argno++;
sp = l_sets[tokpatset[argno - 1]].set_val;
for (bitno = nregs; bitno < nregs + ntokens; bitno++)
if (BIT(sp, bitno))
@ -68,10 +74,12 @@ onlyreg(argno) {
return (1);
}
makescratch(argno) {
static void makescratch(int argno)
{
set_t s;
if (! argno) argno++;
if (!argno)
argno++;
if (tokpatro[argno - 1])
error("Instruction destroys %%%d, not allowed here", argno);
s = l_sets[tokpatset[argno - 1]];
@ -79,25 +87,29 @@ makescratch(argno) {
tokpatset[argno - 1] = setlookup(s);
}
struct varinfo *gen_inst(ident,star) char *ident; {
struct varinfo *gen_inst(char *ident, int star)
{
register struct varinfo *vi, *retval, *eravi;
register instr_p ip;
register struct operand *op;
register i;
register int i;
register inst_p insta;
if (star && !inproc)
error("Variable instruction only allowed inside proc");
for (ip=l_instr;ip<l_instr+ninstr;ip++) {
for (ip = l_instr; ip < l_instr + ninstr; ip++)
{
if (strcmp(ident, ip->i_name))
continue;
if (ip->i_nops != niops)
continue;
for(i=0,op=ip->i_oplist;i<niops;i++,op=op->o_next) {
for (i = 0, op = ip->i_oplist; i < niops; i++, op = op->o_next)
{
if (!subset(iops[i].in_set, l_sets[op->o_setno].set_val, SETSIZE))
goto cont;
}
goto found; /* oh well, one more won't hurt */
goto found;
/* oh well, one more won't hurt */
cont: ;
}
error("Such an \"%s\" does not exist", ident);
@ -108,19 +120,23 @@ found:
vi->vi_int[1] = star;
vi->vi_next = 0;
retval = vi;
for(i=0;i<niops;i++) {
for (i = 0; i < niops; i++)
{
NEW(vi->vi_vi, struct varinfo);
vi = vi->vi_vi;
vi->vi_int[0] = iops[i].in_index;
}
vi->vi_vi = 0;
vi = retval;
for(i=0,op=ip->i_oplist;i<niops;i++,op=op->o_next) {
if(op->o_adorn&AD_CC) {
for (i = 0, op = ip->i_oplist; i < niops; i++, op = op->o_next)
{
if (op->o_adorn & AD_CC)
{
vi->vi_next = setcoco(iops[i].in_index);
vi = vi->vi_next;
}
switch(op->o_adorn&AD_RWMASK) {
switch (op->o_adorn & AD_RWMASK)
{
default:
/* Nothing possible to do */
break;
@ -133,48 +149,36 @@ found:
case AD_WO:
/* Treated the same for now */
insta = &l_instances[iops[i].in_index];
switch(insta->in_which) {
switch (insta->in_which)
{
case IN_COPY:
if(insta->in_info[1]==0 && !onlyreg(insta->in_info[0]))
if (insta->in_info[1] == 0
&& !onlyreg(insta->in_info[0]))
break;
makescratch(insta->in_info[0]);
vi->vi_next = generase(
ex_lookup(
EX_SUBREG,insta->in_info[0],
insta->in_info[1]
)
);
vi->vi_next = generase(ex_lookup(
EX_SUBREG, insta->in_info[0], insta->in_info[1]));
vi = vi->vi_next;
break;
case IN_MEMB:
vi->vi_next = generase(
ex_lookup(
EX_TOKFIELD,insta->in_info[0],
insta->in_info[1]
)
);
vi->vi_next = generase(ex_lookup(
EX_TOKFIELD, insta->in_info[0], insta->in_info[1]));
vi = vi->vi_next;
break;
case IN_RIDENT:
vi->vi_next = generase(
ex_lookup(
EX_REG,insta->in_info[0],0
)
);
vi->vi_next = generase(ex_lookup(
EX_REG, insta->in_info[0], 0));
vi = vi->vi_next;
break;
case IN_ALLOC:
vi->vi_next = generase(
ex_lookup(
EX_ALLREG,insta->in_info[0]+1,
insta->in_info[1]
)
);
vi->vi_next = generase(ex_lookup(
EX_ALLREG, insta->in_info[0] + 1, insta->in_info[1]));
vi = vi->vi_next;
break;
case IN_S_DESCR:
case IN_D_DESCR:
{ int temp;
{
int temp;
if (insta->in_which == IN_S_DESCR)
temp = wordsize;
@ -191,10 +195,12 @@ found:
break;
}
}
for (eravi=ip->i_erases;eravi != VI_NULL;eravi=eravi->vi_next) {
for (eravi = ip->i_erases; eravi != VI_NULL ; eravi = eravi->vi_next)
{
if (eravi->vi_int[0] < 0)
vi->vi_next = setcoco(0);
else {
else
{
vi->vi_next = generase(eravi->vi_int[0]);
vi = vi->vi_next;
vi->vi_next = genremove(eravi->vi_int[0]);

View file

@ -3,6 +3,8 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#ifndef INSTRUCT_H_
#define INSTRUCT_H_
#ifndef _COST_
#include "cost.h"
@ -39,3 +41,8 @@ extern instr_t l_instr[];
* if it contains the same information and is allowed as an operand
* in this place. Too difficult for now.
*/
struct varinfo;
struct varinfo *gen_inst(char *ident, int star);
#endif /* INSTRUCT_H_ */

View file

@ -14,6 +14,7 @@ static char rcsid[]= "$Id$";
#include "set.h"
#include "expr.h"
#include "lookup.h"
#include "subr.h"
#include "token.h"
#include "property.h"
#include "iocc.h"
@ -28,20 +29,26 @@ expr_t arexp[MAXATT];
expr_t iextoaddr();
iocc_t subr_iocc(tokarg,subreg) {
/* Forward declarations */
static int instalookup(inst_t, int);
iocc_t subr_iocc(int tokarg, int subreg)
{
inst_t insta;
iocc_t result;
register i;
register int i;
insta.in_which = IN_COPY;
insta.in_info[0] = tokarg;
insta.in_info[1] = subreg;
result.in_index = instalookup(insta, 2);
if (tokarg < 1) tokarg = 1;
if (tokarg < 1)
tokarg = 1;
if (subreg == 0)
for (i = 0; i < SETSIZE; i++)
result.in_set[i] = l_sets[tokpatset[tokarg - 1]].set_val[i];
else {
else
{
for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0;
subregset(l_sets[tokpatset[tokarg - 1]].set_val, subreg, result.in_set);
@ -49,10 +56,11 @@ iocc_t subr_iocc(tokarg,subreg) {
return (result);
}
iocc_t tokm_iocc(tokarg,ident) char *ident; {
iocc_t tokm_iocc(int tokarg, char *ident)
{
iocc_t result;
inst_t insta;
register i;
register int i;
char app[100];
int dummy;
@ -60,18 +68,21 @@ iocc_t tokm_iocc(tokarg,ident) char *ident; {
result.in_set[i] = 0;
insta.in_which = IN_MEMB;
insta.in_info[0] = tokarg;
if (tokarg < 1) tokarg = 1;
if (tokarg < 1)
tokarg = 1;
sprintf(app, "%%%d.%s", tokarg, ident);
insta.in_info[1] = 1+membset(tokpatset[tokarg-1],ident,result.in_set,
app,TYPREG,&dummy);
insta.in_info[1] = 1
+ membset(tokpatset[tokarg - 1], ident, result.in_set, app, TYPREG,
&dummy);
result.in_index = instalookup(insta, 2);
return (result);
}
iocc_t percident_iocc(ident) char *ident; {
iocc_t percident_iocc(char *ident)
{
iocc_t result;
inst_t insta;
register i;
register int i;
char app[100];
int dummy;
@ -80,16 +91,17 @@ iocc_t percident_iocc(ident) char *ident; {
insta.in_which = IN_MEMB;
insta.in_info[0] = 0;
sprintf(app, "%%%s", ident);
insta.in_info[1] = 1+membset(cursetno,ident,result.in_set,
app,TYPREG,&dummy);
insta.in_info[1] = 1
+ membset(cursetno, ident, result.in_set, app, TYPREG, &dummy);
result.in_index = instalookup(insta, 2);
return (result);
}
iocc_t ident_iocc(ident) char *ident; {
iocc_t ident_iocc(char *ident)
{
iocc_t result;
inst_t insta;
register i;
register int i;
register symbol *sy_p;
for (i = 0; i < SETSIZE; i++)
@ -102,10 +114,11 @@ iocc_t ident_iocc(ident) char *ident; {
return (result);
}
iocc_t all_iocc(all_no,subreg) {
iocc_t all_iocc(int all_no, int subreg)
{
iocc_t result;
inst_t insta;
register i;
register int i;
set_t localset;
register short *sp;
@ -122,12 +135,13 @@ iocc_t all_iocc(all_no,subreg) {
return (result);
}
iocc_t descr_iocc(ident) char *ident; {
iocc_t descr_iocc(char *ident)
{
iocc_t result;
inst_t insta;
register symbol *sy_p;
register token_p tp;
register i;
register int i;
int typerr;
for (i = 0; i < SETSIZE; i++)
@ -141,20 +155,24 @@ iocc_t descr_iocc(ident) char *ident; {
else if (rvused & DL_REGVAR && strcmp(ident, "DLOCAL") == 0)
insta.in_which = IN_D_DESCR;
insta.in_info[0] = sy_p->sy_value.syv_tokno;
for (i=0;i<MAXATT;i++) {
if (tp->tk_att[i].ta_type == -3) {
for (i = 0; i < MAXATT; i++)
{
if (tp->tk_att[i].ta_type == -3)
{
if (narexpr > i)
error("token %s initialized with too many attributes", ident);
break;
}
if (i>= narexpr) {
error("token %s initialized with too few attributes",
ident);
if (i >= narexpr)
{
error("token %s initialized with too few attributes", ident);
break;
}
typerr = 0;
switch(arexp[i].ex_typ) {
default: assert(0);
switch (arexp[i].ex_typ)
{
default:
assert(0);
case TYPINT:
if (tp->tk_att[i].ta_type != -1)
if (tp->tk_att[i].ta_type == -2)
@ -163,7 +181,8 @@ iocc_t descr_iocc(ident) char *ident; {
typerr++;
break;
case TYPBOOL:
typerr++; break;
typerr++;
break;
case TYPADDR:
if (tp->tk_att[i].ta_type != -2)
typerr++;
@ -178,8 +197,8 @@ iocc_t descr_iocc(ident) char *ident; {
break;
}
if (typerr)
error("Attribute %s.%s given wrong type of value",
ident,tp->tk_att[i].ta_name);
error("Attribute %s.%s given wrong type of value", ident,
tp->tk_att[i].ta_name);
insta.in_info[i + 1] = arexp[i].ex_index;
}
result.in_index = instalookup(insta, i + 1);
@ -191,12 +210,14 @@ iocc_t descr_iocc(ident) char *ident; {
int ninstances = 1;
inst_t l_instances[MAXINSTANCES];
instalookup(insta,filled) inst_t insta; {
register i,j;
static int instalookup(inst_t insta, int filled)
{
register int i, j;
for (j = filled; j <= MAXATT; j++)
insta.in_info[j] = 0;
for (i=0;i<ninstances;i++) {
for (i = 0; i < ninstances; i++)
{
if (insta.in_which != l_instances[i].in_which)
continue;
for (j = 0; j <= MAXATT; j++)

View file

@ -3,8 +3,14 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#ifndef IOCC_H_
#define IOCC_H_
#include "param.h"
typedef struct iocc {
short in_set[SETSIZE];
int in_index;
} iocc_t,*iocc_p;
#endif

View file

@ -11,23 +11,26 @@ static char rcsid[]= "$Id$";
#include "param.h"
#include "lookup.h"
#include "extern.h"
#include "subr.h"
char *myalloc();
char *mystrcpy();
;
symbol dumsym; /* dummy to return in case of error */
symbol *lookup(name,type,style)
char *name;
symtype type;
lookupstyle style;
/* Forward declarations */
static int hashvalue(register char *);
symbol *lookup(char *name, symtype type, lookupstyle style)
{
symbol *sy_p, **sy_pp;
for (sy_pp = &symhash[hashvalue(name)];(sy_p= *sy_pp) != 0;sy_pp= &sy_p->sy_next) {
for (sy_pp = &symhash[hashvalue(name)]; (sy_p = *sy_pp) != 0;
sy_pp = &sy_p->sy_next)
{
if (strcmp(sy_p->sy_name, name) != 0)
continue;
switch(style) {
switch (style)
{
default:
assert(0);
case justlooking:
@ -41,7 +44,8 @@ lookupstyle style;
return (&dumsym);
}
}
switch(style) {
switch (style)
{
default:
assert(0);
case justlooking:
@ -61,9 +65,10 @@ lookupstyle style;
}
}
hashvalue(s) register char *s; {
static int hashvalue(register char *s)
{
register unsigned sum = 0;
register i;
register int i;
for (i = 0; *s; s++, i = (i + 3) & 07)
sum += *s << i;

View file

@ -3,6 +3,8 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#ifndef LOOKUP_H_
#define LOOKUP_H_
typedef enum {
justlooking,mustexist,newsymbol,makeexist
@ -30,4 +32,7 @@ typedef struct symbol {
#define NSYMHASH 61
extern symbol *symhash[NSYMHASH]; /* chained hashtable */
extern symbol *lookup();
symbol *lookup(char *name, symtype type, lookupstyle style);
#endif /* LOOKUP_H_ */

View file

@ -8,18 +8,31 @@ static char rcsid[]= "$Id$";
#include <stdlib.h>
#include <stdio.h>
#include "param.h"
#include "hall.h"
#include "expr.h"
#include "extern.h"
char *filename;
main(argc,argv) char **argv; {
extern void enterkeyw(void);
extern void initio(void);
extern void initemhash(void);
extern void finishio(void);
extern void statistics(void);
extern int yyparse(void);
int main(int argc, char **argv)
{
extern int nerrors;
extern int code_in_c;
extern int tabledebug;
extern int verbose;
while (argc >1 && argv[1][0]=='-') {
switch(argv[1][1]) {
while (argc > 1 && argv[1][0] == '-')
{
switch (argv[1][1])
{
case 'c':
code_in_c = 0;
break;
@ -32,30 +45,38 @@ main(argc,argv) char **argv; {
default:
error("Unknown flag -%c", argv[1][1]);
}
argc--; argv++;
argc--;
argv++;
}
if (argc==2) {
if (freopen(argv[1],"r",stdin)==NULL) {
if (argc == 2)
{
if (freopen(argv[1], "r", stdin) == NULL)
{
error("Can't open %s", argv[1]);
exit(-1);
}
filename = argv[1];
}
else if (argc == 1) {
else if (argc == 1)
{
filename = "";
} else
}
else
error("Usage: %s [-c] [-d] [-v] [table]", argv[0]);
initemhash();
enterkeyw();
initnodes();
initio();
yyparse();
if (nerrors==0) {
if (nerrors == 0)
{
finishio();
statistics();
if (verbose)
hallverbose();
} else {
}
else
{
errorexit();
}
exit(nerrors == 0 ? 0 : -1);

View file

@ -2,7 +2,7 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* #define CODEDEBUG /* print readable code */
/* #define CODEDEBUG *//* print readable code */
#ifdef CODEDEBUG
int code_in_c=0; /* put readable code in "code" */
int tabledebug=1; /* generate code for table debugging */
@ -23,13 +23,13 @@ static char rcsid[]= "$Id$";
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include "varinfo.h"
#include "param.h"
#include "reg.h"
#include "property.h"
#include "token.h"
#include "set.h"
#include "subr.h"
#include "instruct.h"
#include "lookup.h"
#include <cgg_cg.h>
@ -67,21 +67,44 @@ int maxallreg=0;
int maxregvars = 0;
int setsize;
opnfile(f,s) FILE **f; char *s; {
int prevind = 0;
int npatbytes = -1;
char pattern[MAXPATBYTES];
int pathash[256];
extern int npatterns;
extern int patindex[];
extern int empatlen;
extern int emmnem[];
extern int empatexpr;
extern node_t nodes[];
extern int nnodes;
extern char * filename;
/* Forward declarations */
static void patbyte(int);
static void patshort(int);
static void pat(int);
void opnfile(FILE **f, char *s)
{
if ((*f = fopen(s, "w")) == NULL)
fatal("Can't create %s", s);
}
unlfile(f,s) FILE *f; char *s; {
if (f) fclose(f);
if (unlink(s)<0)
void unlfile(FILE *f, char *s)
{
if (f)
fclose(f);
if (remove(s) < 0)
error("%s incorrect, must be removed!!", s);
}
initio() {
extern char *myalloc();
void initio(void)
{
opnfile(&ctable, c_file);
opnfile(&htable, h_file);
@ -94,27 +117,32 @@ initio() {
lineset = (short *) myalloc(SZOFSET(MAXSOURCELINES) * sizeof(short));
}
finishcode() {
void finishcode(void)
{
if (code_in_c)
fprintf(ctable, "\n};\n\n");
fprintf(ctable, "int allsetno = %d;\n", allsetno);
if (tabledebug) {
int fd;
if (tabledebug)
{
FILE *fd;
int sz;
if ((fd=creat("lineset",0666))>=0) {
fd = fopen("lineset","wb");
if (fd != NULL)
{
sz = SZOFSET(maxline) * 2;
write(fd,&sz,sizeof(int));
write(fd,lineset,sz);
close(fd);
} else
fwrite(&sz,1,sizeof(int),fd);
fwrite(lineset,1,sz,fd);
fclose(fd);
}
else
error("Can't create lineset");
}
}
errorexit() {
void errorexit(void)
{
unlfile(ctable, c_file);
unlfile(htable, h_file);
if (!code_in_c)
@ -131,7 +159,8 @@ errorexit() {
#define codenl()
#define code8nl(x) code8(x)
code8(x) {
void code8(int x)
{
codeindex++;
if (code_in_c)
@ -140,37 +169,33 @@ code8(x) {
putc(x, code);
}
code53(x,y) {
void code53(int x, int y)
{
code8(x + (y << 5));
}
codeint(x) {
void codeint(int x)
{
assert(x >= 0 && x <= 32767);
if (x<128) {
if (x < 128)
{
code8(x);
} else {
}
else
{
code8(x / 256 + 128);
code8(x % 256);
}
}
#endif
int prevind=0;
int npatbytes= -1;
char pattern[MAXPATBYTES];
int pathash[256];
outpatterns() {
extern int npatterns;
extern int patindex[];
extern int empatlen;
extern int emmnem[];
extern int empatexpr;
register i;
void outpatterns(void)
{
register int i;
if (!inproc) {
if (!inproc)
{
patbyte(0);
patshort(prevind);
prevind = npatbytes - 2;
@ -179,42 +204,51 @@ outpatterns() {
patbyte(emmnem[i]);
pat(empatexpr);
}
if (callproc==0) {
if (callproc == 0)
{
patbyte(npatterns);
for (i = 0; i < npatterns; i++)
pat(patindex[i]);
} else {
}
else
{
patbyte(0);
pat(callproc);
pat(nprocargs);
for (i = 0; i < nprocargs; i++) pat(procarg[i]);
for (i = 0; i < nprocargs; i++)
pat(procarg[i]);
}
}
pat(n) {
static void pat(int n)
{
assert(n >= 0);
if (n < 128)
patbyte(n);
else {
else
{
patbyte(n / 256 + 128);
patbyte(n % 256);
}
}
patshort(n) {
static void patshort(int n)
{
patbyte(n % 256);
patbyte(n / 256);
}
patbyte(n) {
static void patbyte(int n)
{
NEXT(npatbytes, MAXPATBYTES, "Pattern bytes");
pattern[npatbytes] = n;
}
hashpatterns() {
void hashpatterns(void)
{
short index;
register char *bp, *tp;
register short i;
@ -222,17 +256,20 @@ hashpatterns() {
int patlen;
index = prevind;
while (index != 0) {
while (index != 0)
{
bp = &pattern[index];
tp = &bp[PO_MATCH];
i = *tp++ & BMASK;
if (i==BMASK) {
if (i == BMASK)
{
i = *tp++ & BMASK;
i |= (*tp++ & BMASK) << BSHIFT;
}
patlen = i;
hashvalue = 0;
switch(patlen) {
switch (patlen)
{
default: /* 3 or more */
hashvalue = (hashvalue << 4) ^ (*tp++ & BMASK);
case 2:
@ -251,7 +288,8 @@ hashpatterns() {
}
}
outincludes() {
void outincludes(void)
{
fprintf(ctable, "#include \"param.h\"\n");
fprintf(ctable, "#include \"tables.h\"\n");
@ -260,22 +298,24 @@ outincludes() {
fprintf(ctable, "#include \"data.h\"\n");
}
outregs() {
register i,j,k;
void outregs(void)
{
register int i, j, k;
short rset[SZOFSET(MAXREGS)];
short clashlist[MAXREGS * MAXREGS];
int iclashlist = 0;
int t, ready;
fprintf(ctable, "char stregclass[] = {\n");
for (i = 0; i < nregs; i++)
fprintf(ctable, "\t%d,\n", l_regs[i].ri_class);
fprintf(ctable, "};\n\nstruct reginfo machregs[] = {\n{0},\n");
for (i=1;i<nregs;i++) {
for (i = 1; i < nregs; i++)
{
fprintf(ctable, "{%d,%d", strlookup(l_regs[i].ri_repr),
l_regs[i].ri_size);
if (maxmembers!=0) {
if (maxmembers != 0)
{
fprintf(ctable, ",{");
for (j = 0; j < maxmembers; j++)
fprintf(ctable, "%d,", l_regs[i].ri_memb[j]);
@ -287,23 +327,27 @@ outregs() {
for (j = 0; j < SZOFSET(MAXREGS); j++)
rset[j] = 0;
BIS(rset, i);
do {
do
{
ready = 1;
for (j = 1; j < nregs; j++)
if (BIT(rset, j))
for (k = 0; k < 2; k++)
if ((t=l_regs[j].ri_memb[k])!=0) {
if ((t = l_regs[j].ri_memb[k]) != 0)
{
if (BIT(rset,t) == 0)
ready = 0;
BIS(rset, t);
}
} while (!ready);
do {
do
{
ready = 1;
for (j = 1; j < nregs; j++)
for (k = 0; k < 2; k++)
if ((t = l_regs[j].ri_memb[k]) != 0)
if (BIT(rset,t)) {
if (BIT(rset, t))
{
if (BIT(rset,j) == 0)
ready = 0;
BIS(rset, j);
@ -313,8 +357,10 @@ outregs() {
for (j = 0; j < SZOFSET(nregs); j++)
fprintf(ctable, "0%o,", rset[j] & 0xFFFF);
fprintf(ctable, "}, %d", iclashlist);
for (j = 1; j < nregs; j++) {
if (BIT(rset, j)) clashlist[iclashlist++] = j;
for (j = 1; j < nregs; j++)
{
if (BIT(rset, j))
clashlist[iclashlist++] = j;
}
clashlist[iclashlist++] = 0;
}
@ -330,22 +376,26 @@ outregs() {
fprintf(ctable, "},\n");
}
fprintf(ctable, "};\n\n short clashlist[] = {\n\t");
for (i = 0; i < iclashlist; i++) {
for (i = 0; i < iclashlist; i++)
{
fprintf(ctable, "%d, ", clashlist[i]);
if (clashlist[i] == 0) fprintf(ctable, "\n\t");
if (clashlist[i] == 0)
fprintf(ctable, "\n\t");
}
fprintf(ctable, "0};\n\n");
}
outregvars() {
register i,j;
void outregvars(void)
{
register int i, j;
fprintf(htable, "#define REGVARS\n");
if (reglap != 0)
fprintf(htable, "#define REGLAP\n");
fprintf(ctable, "#include \"regvar.h\"\n");
fprintf(ctable, "int nregvar[4] = { ");
for (i=0;i<4;i++) {
for (i = 0; i < 4; i++)
{
fprintf(ctable, "%d, ", nregvar[i]);
if (nregvar[i] > maxregvars)
maxregvars = nregvar[i];
@ -353,9 +403,10 @@ outregvars() {
fprintf(ctable, "};\n");
for (i = 0; i < 4; i++)
if (nregvar[i] > 0)
fprintf(ctable,"struct regassigned ratar%d[%d];\n",
i,nregvar[i]);
for (i=0;i<4;i++) if (nregvar[i]>0) {
fprintf(ctable, "struct regassigned ratar%d[%d];\n", i, nregvar[i]);
for (i = 0; i < 4; i++)
if (nregvar[i] > 0)
{
fprintf(ctable, "int rvtar%d[] = {", i);
for (j = 0; j < nregvar[i]; j++)
fprintf(ctable, "%d,", rvnumbers[i][j]);
@ -376,77 +427,97 @@ outregvars() {
fprintf(ctable, "};\n");
}
typeconv(n) {
int typeconv(int n)
{
if (n>=0) return(2);
if (n== -1) return(1);
if (n== -2) return(3);
if (n >= 0)
return (2);
if (n == -1)
return (1);
if (n == -2)
return (3);
assert(n == -3);
return (0);
}
outfmt(p)
register char *p;
static int is_ascii(int c)
{
if ((c >= 0) && (c <= 127))
return 1;
return 0;
}
void outfmt(register char *p)
{
register int c;
fprintf(ctable, "\"");
while ((c= (*p++&0377))!=0) {
if (! isascii(c) || iscntrl(c)) {
fprintf(ctable,"\\%c%c%c",
((c&~0300)>>6) + '0', ((c&070)>>3)+'0',
(c&07)+'0');
while ((c = (*p++ & 0377)) != 0)
{
if (!is_ascii(c) || iscntrl(c))
{
fprintf(ctable, "\\%c%c%c", ((c & ~0300) >> 6) + '0',
((c & 070) >> 3) + '0', (c & 07) + '0');
}
else fprintf(ctable, "%c",c);
else
fprintf(ctable, "%c", c);
}
fprintf(ctable, "\"");
}
outtokens() {
register tokno,i;
void outtokens(void)
{
register int tokno, i;
register token_p tp;
fprintf(ctable, "tkdef_t tokens[] = {{0},\n");
for (tokno=1;tokno<ntokens;tokno++) {
for (tokno = 1; tokno < ntokens; tokno++)
{
tp = l_tokens[tokno];
fprintf(ctable,"/* %3d */{%d,{%d,%d},{", tokno,
tp->tk_size, tp->tk_cost.ct_space, tp->tk_cost.ct_time);
fprintf(ctable, "/* %3d */{%d,{%d,%d},{", tokno, tp->tk_size,
tp->tk_cost.ct_space, tp->tk_cost.ct_time);
for (i = 0; i < maxtokensize; i++)
fprintf(ctable, "%d,", typeconv(tp->tk_att[i].ta_type));
fprintf(ctable, "},%d},\t/* ", tp->tk_format);
if (tp->tk_format >= 0) outfmt(l_strings[tp->tk_format]);
else fprintf(ctable, "(no format)");
if (tp->tk_format >= 0)
outfmt(l_strings[tp->tk_format]);
else
fprintf(ctable, "(no format)");
fprintf(ctable, " */\n");
}
fprintf(ctable, "{0}};\n\n");
}
outenodes() {
void outenodes(void)
{
register node_p np;
extern node_t nodes[];
extern int nnodes;
fprintf(ctable, "node_t enodes[] = {\n");
for (np = nodes; np < &nodes[nnodes]; np++)
fprintf(ctable,"{%d,%d,%d},\n",
np->ex_operator,np->ex_lnode,np->ex_rnode);
fprintf(ctable, "{%d,%d,%d},\n", np->ex_operator, np->ex_lnode,
np->ex_rnode);
fprintf(ctable, "};\n\n");
}
outstrings() {
register i;
void outstrings(void)
{
register int i;
#if 0
register char *p;
register int c;
extern char * filename;
#endif
if (tabledebug)
fprintf(ctable, "char *tablename = \"%s\";\n", filename);
fprintf(ctable, "string codestrings[] = {\n");
for(i=0;i<nstrings;i++) {
for (i = 0; i < nstrings; i++)
{
fprintf(ctable, "\t");
outfmt(l_strings[i]);
#if 0
while ((c= (*p++&0377))!=0) {
if (! isascii(c) || iscntrl(c)) {
while ((c= (*p++&0377))!=0)
{
if (! isascii(c) || iscntrl(c))
{
fprintf(ctable,"\\%c%c%c",
((c&~0300)>>6) + '0', ((c&070)>>3)+'0',
(c&07)+'0');
@ -462,13 +533,16 @@ outstrings() {
extern set_t unstackset;
outsets() {
register i;
void outsets(void)
{
register int i;
register set_p sp;
fprintf(ctable, "set_t machsets[] = {\n");
for (sp=l_sets;sp< &l_sets[nsets]; sp++) {
fprintf(ctable,"/* %3ld */ {%3d,{",(long)(sp-l_sets),sp->set_size);
for (sp = l_sets; sp < &l_sets[nsets]; sp++)
{
fprintf(ctable, "/* %3ld */ {%3d,{", (long) (sp - l_sets),
sp->set_size);
for (i = 0; i < setsize; i++)
fprintf(ctable, "0x%x,", sp->set_val[i] & 0xFFFF);
fprintf(ctable, "}},\n");
@ -481,12 +555,14 @@ outsets() {
fprintf(ctable, "}};\n\n");
}
outinstances() {
void outinstances(void)
{
register inst_p ip;
register i;
register int i;
fprintf(ctable, "inst_t tokeninstances[] = {\n");
for (ip=l_instances;ip< &l_instances[ninstances]; ip++) {
for (ip = l_instances; ip < &l_instances[ninstances]; ip++)
{
fprintf(ctable, "{ %d, {", ip->in_which);
for (i = 0; i <= maxtokensize; i++)
fprintf(ctable, "%d,", ip->in_info[i]);
@ -495,48 +571,48 @@ outinstances() {
fprintf(ctable, "};\n\n");
}
outmoves() {
void outmoves(void)
{
register move_p mp;
fprintf(ctable, "move_t moves[] = {\n");
for (mp = l_moves; mp < &l_moves[nmoves]; mp++)
fprintf(ctable,"{%d,%d,%d,%d,%d},\n",
mp->m_set1, mp->m_expr1,
mp->m_set2, mp->m_expr2,
mp->m_cindex);
fprintf(ctable, "{%d,%d,%d,%d,%d},\n", mp->m_set1, mp->m_expr1,
mp->m_set2, mp->m_expr2, mp->m_cindex);
fprintf(ctable, "{-1}\n};\n\n");
}
outtests() {
void outtests(void)
{
register test_p tp;
fprintf(ctable, "test_t tests[] = {\n");
for (tp = l_tests; tp < &l_tests[ntests]; tp++)
fprintf(ctable,"{%d,%d,%d},\n",
tp->t_set, tp->t_expr,
tp->t_cindex);
fprintf(ctable, "{%d,%d,%d},\n", tp->t_set, tp->t_expr, tp->t_cindex);
fprintf(ctable, "{-1}\n};\n\n");
}
outstacks() {
void outstacks(void)
{
register c1_p cp;
fprintf(ctable, "c1_t c1coercs[] = {\n");
for (cp = l_stacks; cp < &l_stacks[nstacks]; cp++)
fprintf(ctable,"{%d,%d,%d,%d},\n",
cp->c1_texpno, cp->c1_expr,
fprintf(ctable, "{%d,%d,%d,%d},\n", cp->c1_texpno, cp->c1_expr,
cp->c1_prop, cp->c1_codep);
fprintf(ctable, "{-1}\n};\n\n");
}
outsplits() {
void outsplits(void)
{
register c2_p cp;
register i;
register int i;
fprintf(ctable, "c2_t c2coercs[] = {\n");
for (cp=l_split; cp< &l_split[nsplit]; cp++) {
fprintf(ctable,"{%d,%d,%d,{",
cp->c2_texpno, cp->c2_expr, cp->c2_nsplit);
for (cp = l_split; cp < &l_split[nsplit]; cp++)
{
fprintf(ctable, "{%d,%d,%d,{", cp->c2_texpno, cp->c2_expr,
cp->c2_nsplit);
for (i = 0; i < maxsplit; i++)
fprintf(ctable, "%d,", cp->c2_repl[i]);
fprintf(ctable, "},%d},\n", cp->c2_codep);
@ -544,22 +620,24 @@ outsplits() {
fprintf(ctable, "{-1}\n};\n\n");
}
outcoercs() {
void outcoercs(void)
{
register c3_p cp;
fprintf(ctable, "c3_t c3coercs[] = {\n");
for (cp = l_coercs; cp < &l_coercs[ncoercs]; cp++)
fprintf(ctable,"{%d,%d,%d,%d,%d},\n",
cp->c3_texpno, cp->c3_expr,
fprintf(ctable, "{%d,%d,%d,%d,%d},\n", cp->c3_texpno, cp->c3_expr,
cp->c3_prop, cp->c3_repl, cp->c3_codep);
fprintf(ctable, "{-1}\n};\n\n");
}
outproplists() {
register propno;
register regno;
void outproplists(void)
{
register int propno;
register int regno;
for(propno=0;propno<nprops;propno++) {
for (propno = 0; propno < nprops; propno++)
{
fprintf(ctable, "struct reginfo *rlist%d[] = {\n", propno);
for (regno = 1; regno < nregs; regno++)
if (BIT(l_props[propno].pr_regset, regno))
@ -572,7 +650,8 @@ outproplists() {
fprintf(ctable, "};\n\n");
}
outconsts() {
void outconsts(void)
{
fprintf(ctable, "unsigned cc1 = %u;\n", fc1);
fprintf(ctable, "unsigned cc2 = %u;\n", fc2);
@ -580,19 +659,22 @@ outconsts() {
fprintf(ctable, "unsigned cc4 = %u;\n", fc4);
}
cdef(s,n) char *s; {
void cdef(char *s, int n)
{
fprintf(htable, "#define %s %d\n", s, n);
}
passon(s) char *s; {
void passon(char *s)
{
char buf[32];
sprintf(buf, "T%s", s);
cdef(buf, cmustbeset(s));
}
outdefs() {
void outdefs(void)
{
register symbol *sy_p;
extern int maxempatlen, maxrule;
char *wrdfmt;
@ -600,7 +682,8 @@ outdefs() {
passon("EM_WSIZE");
passon("EM_PSIZE");
passon("EM_BSIZE");
if ((sy_p=lookup("FORMAT",symsconst,justlooking))!=0) {
if ((sy_p = lookup("FORMAT", symsconst, justlooking)) != 0)
{
wrdfmt = l_strings[sy_p->sy_value.syv_stringno];
fprintf(htable, "#define WRD_FMT \"%s\"\n", wrdfmt);
}
@ -616,7 +699,8 @@ outdefs() {
cdef("MAXEMREPLLEN", maxemrepllen);
cdef("MAXPROCARG", maxprocargs);
cdef("MAXRULE", maxrule < 16 ? 16 : maxrule);
if (nsplit>0) {
if (nsplit > 0)
{
cdef("MAXSPLIT", maxsplit);
}
if (tabledebug)
@ -625,28 +709,33 @@ outdefs() {
cdef("USE_TES", 1);
}
outars() {
register i;
void outars(void)
{
register int i;
if (code_in_c)
fprintf(htable, "#define CODEINC 1\n");
else {
else
{
fprintf(ctable, "char coderules[%d];\n", codeindex);
fprintf(ctable, "int ncodebytes=%d;\n", codeindex);
}
fprintf(ctable, "char pattern[%d]={\n", npatbytes + 1);
for(i=0;i<=npatbytes;i++) {
for (i = 0; i <= npatbytes; i++)
{
fprintf(ctable, "%d,%c", pattern[i] & BMASK, i % 16 == 15 ? '\n' : ' ');
}
fprintf(ctable, "};\n\n");
fprintf(ctable, "int pathash[256]={\n");
for(i=0;i<256;i++) {
for (i = 0; i < 256; i++)
{
fprintf(ctable, "%d,%c", pathash[i] & 0xFFFF, i % 10 == 9 ? '\n' : ' ');
}
fprintf(ctable, "};\n");
}
finishio() {
void finishio(void)
{
extern int nregs;
finishcode();
@ -673,8 +762,8 @@ finishio() {
outars();
}
void
codecoco(cocono) {
void codecoco(int cocono)
{
if (cocono == -1)
return;
@ -683,10 +772,10 @@ codecoco(cocono) {
codenl();
}
dopattern(stackcoerc,kills,allocates,generates,yields,leaving)
varinfo *kills,*allocates,*generates,*yields,*leaving;
void dopattern(int stackcoerc, varinfo *kills, varinfo *allocates,
varinfo *generates, varinfo *yields, varinfo *leaving)
{
register i;
register int i;
int n, nops;
register struct varinfo *vp, *vivp;
register instr_p instp;
@ -706,25 +795,31 @@ varinfo *kills,*allocates,*generates,*yields,*leaving;
#endif
if (code_in_c)
fprintf(ctable, "\n/* \"%s\", line %d */ ", filename, lineno);
if (tabledebug) {
if (tabledebug)
{
code8(DO_DLINE);
codeint(startline);
codenl();
if (startline<MAXSOURCELINES) {
if (startline < MAXSOURCELINES)
{
if (startline > maxline)
maxline = startline;
BIS(lineset, startline);
} else {
}
else
{
static int beenhere = 0;
if (!beenhere) {
if (!beenhere)
{
beenhere++;
error("Too many source lines for table debug");
}
}
}
/* MATCH part */
if (tokpatlen) {
if (tokpatlen)
{
if (optexact)
if (optstack)
code53(DO_XXMATCH, tokpatlen);
@ -735,59 +830,77 @@ varinfo *kills,*allocates,*generates,*yields,*leaving;
for (i = 0; i < tokpatlen; i++)
codeint(tokpatset[i]);
codenl();
} else if (stackcoerc)
}
else if (stackcoerc)
code8nl(DO_COERC);
if (optstack) {
if (optstack)
{
code53(DO_TOSTACK, 0);
codeint(allsetno);
codenl();
}
/* The kills */
for (vp=kills;vp!=0;vp=vp->vi_next) {
if (vp->vi_int[1] != 0) {
for (vp = kills; vp != 0; vp = vp->vi_next)
{
if (vp->vi_int[1] != 0)
{
code53(DO_REMOVE, 1);
codeint(vp->vi_int[0]);
codeint(vp->vi_int[1]);
} else if (vp->vi_int[0] >= 0) {
}
else if (vp->vi_int[0] >= 0)
{
code53(DO_REMOVE, 0);
codeint(vp->vi_int[0]);
} else {
}
else
{
code8(DO_KILLREG);
codeint(-vp->vi_int[0] - 1);
}
codenl();
} codenl();
}
nremoves = 0;
for(vp=generates;vp!=0;vp=vp->vi_next) {
for (vp = generates; vp != 0; vp = vp->vi_next)
{
if (vp->vi_int[0] != INSREMOVE)
continue;
for (i = 0; i < nremoves; i++)
if (vp->vi_int[1] == removelist[i])
break;
if (i==nremoves) {
if (i == nremoves)
{
assert(nremoves < (sizeof(removelist) / sizeof(int)));
removelist[nremoves++] = vp->vi_int[1];
}
}
for(i=0;i<nremoves;i++) {
for (i = 0; i < nremoves; i++)
{
code8(DO_RREMOVE);
codeint(removelist[i]);
codenl();
}
/* allocate part */
deal=0;al=0;
for (vp=allocates;vp!=0;vp=vp->vi_next) {
if (vp->vi_int[0] == -1) { /* Deallocate */
deal = 0;
al = 0;
for (vp = allocates; vp != 0; vp = vp->vi_next)
{
if (vp->vi_int[0] == -1)
{ /* Deallocate */
deal++;
code8(DO_DEALLOCATE);
codeint(vp->vi_int[1]);
codenl();
} else {
if (vp->vi_int[1]==0) {
}
else
{
if (vp->vi_int[1] == 0)
{
code53(DO_ALLOCATE, 0);
codeint(vp->vi_int[0]);
codenl();
} else {
}
else
{
code53(DO_ALLOCATE, 1);
codeint(vp->vi_int[0]);
codeint(vp->vi_int[1]);
@ -802,21 +915,27 @@ varinfo *kills,*allocates,*generates,*yields,*leaving;
maxallreg = al;
totcost.ct_space = 0;
totcost.ct_time = 0;
for(vp=generates;vp!=0;vp=vp->vi_next) {
for (vp = generates; vp != 0; vp = vp->vi_next)
{
n = vp->vi_int[0];
switch(n) {
switch (n)
{
default:
assert(n >= 0);
instp = &l_instr[n];
nops = instp->i_nops;
code53(DO_INSTR, nops);
if (vp->vi_int[1]==0) {
if (vp->vi_int[1] == 0)
{
codeint(instp->i_asname);
} else {
}
else
{
codeint(10000 + vp->vi_int[1]);
}
vivp = vp->vi_vi;
for(i=0;i<nops;i++) {
for (i = 0; i < nops; i++)
{
codeint(vivp->vi_int[0]);
vivp = vivp->vi_vi;
}
@ -868,23 +987,26 @@ varinfo *kills,*allocates,*generates,*yields,*leaving;
}
codecoco(cocono);
vil = vilength(yields);
if (vil!=0 || tokpatlen!=0 || allocates!=0) {
if (vil != 0 || tokpatlen != 0 || allocates != 0)
{
code53(DO_TOKREPLACE, vilength(yields));
for(vp=yields;vp!=0;vp=vp->vi_next) {
for (vp = yields; vp != 0; vp = vp->vi_next)
{
codeint(vp->vi_int[0]);
} codenl();
}
codenl();
}
if (leaving!=0) {
if (leaving != 0)
{
code53(DO_EMREPLACE, vilength(leaving));
while (leaving!=0) {
while (leaving != 0)
{
codeint(leaving->vi_int[0]);
codeint(leaving->vi_int[1]);
leaving = leaving->vi_next;
} codenl();
}
codenl();
}
if (totcost.ct_space!=0 || totcost.ct_time!=0) {
if (totcost.ct_space != 0 || totcost.ct_time != 0)
{
code8(DO_COST);
codeint(totcost.ct_space);
codeint(totcost.ct_time);
@ -896,13 +1018,15 @@ varinfo *kills,*allocates,*generates,*yields,*leaving;
code8nl(DO_NEXTEM);
}
used(resource,use,max) char *resource; {
void used(char *resource, int use, int max)
{
if (verbose || 4 * use > 3 * max)
fprintf(stderr, "%s %d(%d)\n", resource, use, max);
}
statistics() {
void statistics(void)
{
extern int nnodes, maxempatlen, maxrule;
used("Registers", nregs, MAXREGS);

View file

@ -15,14 +15,14 @@ static char rcsid2[]= "$Id$";
#include "instruct.h"
#include "expr.h"
#include "extern.h"
#include "subr.h"
#include <cgg_cg.h>
#include <em_reg.h>
#include "y.tab.h"
extern int emhere;
char *mystrcpy();
int myatoi();
extern int mlookup(char *name);
int lineno=1;
extern char *filename;
@ -101,7 +101,7 @@ extern char *filename;
%%
int skipping=0;
yywrap() {
int yywrap(void) {
if (skipping)
fatal("EOF reached during error recovery");
@ -113,8 +113,8 @@ yywrap() {
#define yytext_ptr yytext
skipupto(tok,str) char *str; {
register i;
void skipupto(int tok,char *str) {
register int i;
skipping=1;
while (yylex()!=tok)

View file

@ -12,17 +12,22 @@ static char rcsid[]= "$Id$";
#include "token.h"
#include "lookup.h"
#include "reg.h"
#include "subr.h"
#include <cgg_cg.h>
#include "extern.h"
extern set_t l_sets[];
set_t emptyset;
setlookup(s) set_t s; {
int setlookup(set_t s)
{
register set_p p;
register i;
register int i;
int setno;
for(p=l_sets;p<&l_sets[nsets];p++) {
for (p = l_sets; p < &l_sets[nsets]; p++)
{
if (p->set_size != s.set_size)
continue;
for (i = 0; i < SETSIZE; i++)
@ -36,9 +41,10 @@ setlookup(s) set_t s; {
return (setno);
}
make_std_sets() {
void make_std_sets(void)
{
set_t s;
register i;
register int i;
for (i = 0; i < SETSIZE; i++)
s.set_val[i] = 0;
@ -49,17 +55,17 @@ make_std_sets() {
n_set("ALL", allsetno);
}
set_t emptyset;
set_t ident_to_set(name) char *name; {
set_t ident_to_set(char *name)
{
register symbol *sy_p;
register i;
register int i;
register struct propinfo *pp;
int bitno;
set_t result;
sy_p = lookup(name, symany, mustexist);
switch(sy_p->sy_type) {
switch (sy_p->sy_type)
{
default:
error("%s is wrong kind of symbol", name);
return (emptyset);
@ -85,35 +91,43 @@ set_t ident_to_set(name) char *name; {
return (result);
}
static void
checksize(s)
register set_p s;
static void checksize(register set_p s)
{
register int i;
register int size = -1;
s->set_size = 0;
for (i = 1; i <= nregs; i++) {
if (BIT(s->set_val, i)) {
for (i = 1; i <= nregs; i++)
{
if (BIT(s->set_val, i))
{
register int sz = l_regs[i].ri_size;
if (size == -1) size = sz;
else if (size != sz) return;
if (size == -1)
size = sz;
else if (size != sz)
return;
}
}
for (i = 1; i <= ntokens; i++) {
if (BIT(s->set_val, i+nregs)) {
for (i = 1; i <= ntokens; i++)
{
if (BIT(s->set_val, i + nregs))
{
register int sz = l_tokens[i]->tk_size;
if (size == -1) size = sz;
else if (size != sz) return;
if (size == -1)
size = sz;
else if (size != sz)
return;
}
}
if (size != -1) s->set_size = size;
if (size != -1)
s->set_size = size;
}
set_t setproduct(s1,s2) set_t s1,s2; {
set_t setproduct(set_t s1, set_t s2)
{
set_t result;
register i;
register int i;
for (i = 0; i < SETSIZE; i++)
result.set_val[i] = s1.set_val[i] & s2.set_val[i];
@ -121,9 +135,10 @@ set_t setproduct(s1,s2) set_t s1,s2; {
return (result);
}
set_t setsum(s1,s2) set_t s1,s2; {
set_t setsum(set_t s1, set_t s2)
{
set_t result;
register i;
register int i;
if (s1.set_size == s2.set_size)
result.set_size = s1.set_size;
@ -134,17 +149,20 @@ set_t setsum(s1,s2) set_t s1,s2; {
return (result);
}
set_t setdiff(s1,s2) set_t s1,s2; {
set_t setdiff(set_t s1, set_t s2)
{
set_t result;
register i;
register int i;
for (i = 0; i < SETSIZE; i++)
result.set_val[i] = s1.set_val[i] & ~s2.set_val[i];
/* make sure that we don't loose the lowest bit of the set, which
indicates that it contains registers
*/
for (i=1;i <= nregs; i++) {
if (BIT(result.set_val, i)) {
for (i = 1; i <= nregs; i++)
{
if (BIT(result.set_val, i))
{
BIS(result.set_val, 0);
break;
}

View file

@ -3,7 +3,21 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Id$ */
#ifndef SET_H_
#define SET_H_
#include <cgg_cg.h>
#define BIS(sp,n) (sp)[(n)>>4] |= 1<<((n)&0xF)
#define BIC(sp,n) (sp)[(n)>>4] &= ~(1<<((n)&0xF))
#define BIT(sp,n) (((sp)[(n)>>4]&(1<<((n)&0xF)))!=0)
int setlookup(set_t s);
void make_std_sets(void);
set_t ident_to_set(char *name);
set_t setproduct(set_t s1, set_t s2);
set_t setsum(set_t s1, set_t s2);
set_t setdiff(set_t s1, set_t s2);
#endif /* SET_H_ */

View file

@ -8,14 +8,15 @@ static char rcsid[]= "$Id$";
#include <string.h>
#include "param.h"
#include "subr.h"
#include "extern.h"
int nstrings = 0;
char *l_strings[MAXSTRINGS];
strlookup(str) char *str; {
register i;
extern char *mystrcpy();
int strlookup(char *str)
{
register int i;
for (i = 0; i < nstrings; i++)
if (strcmp(str, l_strings[i]) == 0)

View file

@ -20,19 +20,25 @@ static char rcsid[]= "$Id$";
#include "regvar.h"
#include <cgg_cg.h>
#include <em_reg.h>
#include "subr.h"
#include "hall.h"
#include "extern.h"
n_proc(name) char *name; {
register symbol *sy_p;
extern int npatbytes;
extern set_t l_sets[];
void n_proc(char *name)
{
register symbol *sy_p;
sy_p = lookup(name, symproc, newsymbol);
sy_p->sy_value.syv_procoff = npatbytes + 1;
}
struct varinfo *
make_erase(name) char *name; {
expr_t e,ident_expr();
struct varinfo * make_erase(char *name)
{
expr_t e;
struct varinfo *result;
e = ident_expr(name);
@ -44,13 +50,11 @@ make_erase(name) char *name; {
return (result);
}
n_instr(name,asname,oplist,eraselist,cost)
char *name,*asname;
operand *oplist;
struct varinfo *eraselist,*cost;
void n_instr(char *name, char *asname, operand *oplist, struct varinfo *eraselist,
struct varinfo *cost)
{
register instrno;
register cc_count;
register int instrno;
register int cc_count;
register instr_p ip;
instrno = NEXT(ninstr, MAXINSTR, "Instructions");
@ -60,19 +64,24 @@ struct varinfo *eraselist,*cost;
ip->i_nops = 0;
ip->i_oplist = oplist;
ip->i_erases = eraselist;
if (cost==0) {
if (cost == 0)
{
ip->i_cost.ct_space = 0;
ip->i_cost.ct_time = 0;
} else {
}
else
{
ip->i_cost.ct_space = cost->vi_int[0];
ip->i_cost.ct_space = cost->vi_int[1];
}
for (cc_count=0; oplist!=0; oplist = oplist->o_next) {
for (cc_count = 0; oplist != 0; oplist = oplist->o_next)
{
ip->i_nops++;
if (oplist->o_adorn & AD_CC)
cc_count++;
}
while (eraselist!=VI_NULL) {
while (eraselist != VI_NULL )
{
if (eraselist->vi_int[0] == -1 && cc_count)
error("Instruction can't both set and break the condition codes");
eraselist = eraselist->vi_next;
@ -81,16 +90,16 @@ struct varinfo *eraselist,*cost;
error("No instruction can set condition codes more than once");
}
n_set(name,number) char *name; {
void n_set(char *name, int number)
{
register symbol *sy_p;
sy_p = lookup(name, symset, newsymbol);
sy_p->sy_value.syv_setno = number;
}
n_tok(name,atts,size,cost,format)
char *name;
struct varinfo *atts,*cost,*format;
void n_tok(char *name, struct varinfo *atts, int size,
struct varinfo *cost, struct varinfo *format)
{
register symbol *sy_p;
register token_p tp;
@ -107,14 +116,18 @@ struct varinfo *atts,*cost,*format;
l_tokens[tokno] = tp;
tp->tk_name = sy_p->sy_name;
tp->tk_size = size;
if (cost != 0) {
if (cost != 0)
{
tp->tk_cost.ct_space = cost->vi_int[0];
tp->tk_cost.ct_time = cost->vi_int[1];
} else {
}
else
{
tp->tk_cost.ct_space = 0;
tp->tk_cost.ct_time = 0;
}
for(i=0,vip=atts;i<MAXATT && vip!=0;i++,vip=vip->vi_next) {
for (i = 0, vip = atts; i < MAXATT && vip != 0; i++, vip = vip->vi_next)
{
tp->tk_att[i].ta_type = vip->vi_int[0];
tp->tk_att[i].ta_name = vip->vi_str[0];
vip->vi_str[0] = 0;
@ -126,14 +139,19 @@ struct varinfo *atts,*cost,*format;
error("More then %d attributes, rest discarded", MAXATT);
for (; i < MAXATT; i++)
tp->tk_att[i].ta_type = -3;
if (format!=0) {
if (format != 0)
{
formstr[0] = 0;
for (vip=format;vip!=0;vip=vip->vi_next) {
for (vip = format; vip != 0; vip = vip->vi_next)
{
if (vip->vi_int[0] == 0)
strcat(formstr, vip->vi_str[0]);
else {
for(i=0;i<thistokensize;i++) {
if (strcmp(vip->vi_str[0],tp->tk_att[i].ta_name)==0) {
else
{
for (i = 0; i < thistokensize; i++)
{
if (strcmp(vip->vi_str[0], tp->tk_att[i].ta_name) == 0)
{
smallstr[0] = i + 1;
smallstr[1] = 0;
strcat(formstr, smallstr);
@ -141,19 +159,19 @@ struct varinfo *atts,*cost,*format;
}
}
if (i == thistokensize)
error("%s not a known attribute",
vip->vi_str[0]);
error("%s not a known attribute", vip->vi_str[0]);
}
}
tp->tk_format = strlookup(formstr);
} else
}
else
tp->tk_format = -1;
}
checkprintformat(n) {
void checkprintformat(int n)
{
register short *s;
register i;
extern set_t l_sets[];
register int i;
s = l_sets[n].set_val;
for (i = nregs; i < nregs + ntokens; i++)
@ -162,38 +180,43 @@ checkprintformat(n) {
l_tokens[i - nregs]->tk_name);
}
n_prop(name,size) char *name; int size; {
void n_prop(char *name, int size)
{
int propno;
register symbol *sp;
propno = NEXT(nprops, MAXPROPS, "Properties");
sp = lookup(name, symprop, newsymbol);
sp->sy_value.syv_propno = propno;
if (size <= 0) {
if (size <= 0)
{
error("Size of property must be >0");
size = wordsize;
}
l_props[propno].pr_size = size;
}
void
prophall(n) {
register i;
void prophall(int n)
{
register int i;
short hallset[SETSIZE];
if (n < 0) return;
if (n < 0)
return;
for (i = 0; i < SETSIZE; i++)
hallset[i] = i < SZOFSET(MAXREGS) ? l_props[n].pr_regset[i] : 0;
nexthall(hallset);
}
n_reg(name,printstring,nmemb,member1,member2) char *name,*printstring; {
int n_reg(char *name, char *printstring, int nmemb, int member1, int member2)
{
register symbol *sy_p;
register reginfo *ri_p;
int regno;
sy_p = lookup(name, symreg, newsymbol);
sy_p->sy_value.syv_regno = regno = NEXT(nregs,MAXREGS,"Number of registers");
sy_p->sy_value.syv_regno = regno = NEXT(nregs, MAXREGS,
"Number of registers");
ri_p = &l_regs[regno];
ri_p->ri_name = mystrcpy(name);
ri_p->ri_repr = printstring != 0 ? mystrcpy(printstring) : ri_p->ri_name;
@ -204,38 +227,42 @@ n_reg(name,printstring,nmemb,member1,member2) char *name,*printstring; {
return (regno);
}
make_const() {
void make_const(void)
{
wordsize = cmustbeset("EM_WSIZE");
pointersize = cmustbeset("EM_PSIZE");
}
cmustbeset(ident) char *ident; {
int cmustbeset(char *ident)
{
return (lookup(ident, symconst, mustexist)->sy_value.syv_cstval);
}
n_const(ident,val) char *ident; {
void n_const(char *ident, int val)
{
register symbol *sy_p;
sy_p = lookup(ident, symconst, newsymbol);
sy_p->sy_value.syv_cstval = val;
}
n_sconst(ident,val) char *ident,*val; {
void n_sconst(char *ident, char *val)
{
register symbol *sy_p;
sy_p = lookup(ident, symsconst, newsymbol);
sy_p->sy_value.syv_stringno = strlookup(val);
}
static void
add_regvar(int rvnum, reginfo *regp, int rv)
static void add_regvar(int rvnum, reginfo *regp, int rv)
{
int overlap, wrong;
overlap = wrong = 0;
if (regp->ri_memb[0]!=0) {
if (regp->ri_memb[0] != 0)
{
/* reglap: float may overlap with one subregister */
if (rv == reg_float && regp->ri_memb[1] == 0)
overlap = 1;
@ -252,15 +279,20 @@ add_regvar(int rvnum, reginfo *regp, int rv)
rvused |= DL_REGVAR;
wrong = 0;
if (overlap) {
if (overlap)
{
/* reglap = size of overlap float */
if (reglap==0) {
if (reglap == 0)
{
reglap = regp->ri_size;
if (reglap == rvsize[reg_float])
error("Two sizes of reg_float can't be same size");
} else if (reglap!=regp->ri_size)
}
else if (reglap != regp->ri_size)
wrong = 1;
} else {
}
else
{
if (nregvar[rv] == 0)
rvsize[rv] = regp->ri_size;
else if (rvsize[rv] != regp->ri_size)
@ -269,7 +301,8 @@ add_regvar(int rvnum, reginfo *regp, int rv)
if (wrong)
error("All register variables of one type must have the same size");
if (overlap) {
if (overlap)
{
reginfo *member_p = &l_regs[regp->ri_memb[0]];
int i;
@ -278,42 +311,47 @@ add_regvar(int rvnum, reginfo *regp, int rv)
* Add reg_p in its place.
*/
wrong = 1;
for (i = 0; i < nregvar[rv]; i++) {
if (rvnumbers[rv][i] == regp->ri_memb[0]) {
for (i = 0; i < nregvar[rv]; i++)
{
if (rvnumbers[rv][i] == regp->ri_memb[0])
{
rvnumbers[rv][i] = rvnum;
wrong = 0;
break;
}
}
if (wrong)
error("Register variable %s can't overlap %s",
regp->ri_name, member_p->ri_name);
} else {
error("Register variable %s can't overlap %s", regp->ri_name,
member_p->ri_name);
}
else
{
NEXT(nregvar[rv], MAXREGVAR, "Register variable");
rvnumbers[rv][nregvar[rv] - 1] = rvnum;
}
}
void
regline(rl,pl,rv) varinfo *rl,*pl; {
void regline(varinfo *rl, varinfo *pl, int rv)
{
register varinfo *rrl, *rpl;
register short *sp;
register reginfo *regp;
int thissize;
int propno;
for(rrl=rl;rrl!=0;rrl=rrl->vi_next) {
for (rrl = rl; rrl != 0; rrl = rrl->vi_next)
{
regp = &l_regs[rrl->vi_int[0]];
thissize = 0;
for(rpl=pl;rpl!=0;rpl=rpl->vi_next) {
for (rpl = pl; rpl != 0; rpl = rpl->vi_next)
{
propno = rpl->vi_int[0];
sp = l_props[propno].pr_regset;
BIS(sp, rrl->vi_int[0]);
if (thissize == 0)
thissize = l_props[propno].pr_size;
else if (thissize != -1 && thissize != l_props[propno].pr_size)
error("Register %s has no clear size",
regp->ri_name);
error("Register %s has no clear size", regp->ri_name);
}
regp->ri_size = thissize;
regp->ri_class = regclass;
@ -324,8 +362,8 @@ regline(rl,pl,rv) varinfo *rl,*pl; {
regclass++;
}
void
check_reglap() {
void check_reglap(void)
{
reginfo *regp;
int i;
@ -333,27 +371,30 @@ check_reglap() {
return;
/* reglap: Check that every reg_float has size == reglap. */
for (i = 0; i < nregvar[reg_float]; i++) {
for (i = 0; i < nregvar[reg_float]; i++)
{
regp = &l_regs[rvnumbers[reg_float][i]];
if (regp->ri_size != reglap)
error("Missing reg_float of size %d to contain %s",
reglap, regp->ri_name);
error("Missing reg_float of size %d to contain %s", reglap,
regp->ri_name);
}
}
setallreg(vi) struct varinfo *vi; {
void setallreg(struct varinfo *vi)
{
nallreg = 0;
for(;vi!=0;vi=vi->vi_next) {
for (; vi != 0; vi = vi->vi_next)
{
if (vi->vi_int[0] < 0)
continue;
allreg[nallreg++] = vi->vi_int[0];
}
}
void
freevi(vip) register struct varinfo *vip; {
register i;
void freevi(register struct varinfo *vip)
{
register int i;
if (vip == 0)
return;
@ -364,24 +405,31 @@ freevi(vip) register struct varinfo *vip; {
free(vip);
}
int myatoi(s) register char *s; {
int myatoi(register char *s)
{
register int base = 10;
register sum=0;
register int sum = 0;
if (*s=='0') {
if (*s == '0')
{
base = 8;
s++;
if (*s=='x') {
if (*s == 'x')
{
base = 16;
s++;
}
}
for (;;) {
switch (*s) {
default: return(sum);
for (;;)
{
switch (*s)
{
default:
return (sum);
case '8':
case '9':
if (base==8) error("Bad digit in octal number");
if (base == 8)
error("Bad digit in octal number");
case '0':
case '1':
case '2':
@ -398,7 +446,8 @@ int myatoi(s) register char *s; {
case 'd':
case 'e':
case 'f':
if (base!=16) error("Hexletter in number not expected");
if (base != 16)
error("Hexletter in number not expected");
sum = sum * base + 10 + *s++ - 'a';
break;
case 'A':
@ -407,42 +456,47 @@ int myatoi(s) register char *s; {
case 'D':
case 'E':
case 'F':
if (base!=16) error("Hexletter in number not expected");
if (base != 16)
error("Hexletter in number not expected");
sum = sum * base + 10 + *s++ - 'A';
break;
}
}
}
char *mystrcpy(s) char *s; {
char *mystrcpy(char *s)
{
register char *p;
char *myalloc();
p = myalloc(strlen(s) + 1);
strcpy(p, s);
return (p);
}
char *myalloc(n) register n; {
char *myalloc(register int n)
{
register char *p, *result;
result = p = malloc(n);
if (p == (char *) 0)
fatal("Out of memory");
do *p++=0; while (--n);
do
*p++ = 0;
while (--n);
return (result);
}
chkincl(value,lwb,upb) {
int chkincl(int value, int lwb, int upb)
{
if (value < lwb || value > upb)
error("Number %d should have been between %d and %d",
value,lwb,upb);
error("Number %d should have been between %d and %d", value, lwb, upb);
return (value);
}
subset(sp1,sp2,setsize) short *sp1,*sp2; {
register i;
int subset(short *sp1, short *sp2, int setsize)
{
register int i;
for (i = 0; i < setsize; i++)
if ((sp1[i] | sp2[i]) != sp2[i])
@ -450,10 +504,12 @@ subset(sp1,sp2,setsize) short *sp1,*sp2; {
return (1);
}
vilength(vip) register struct varinfo *vip; {
register l=0;
int vilength(register struct varinfo *vip)
{
register int l = 0;
while(vip!=0) {
while (vip != 0)
{
vip = vip->vi_next;
l++;
}

42
util/ncgg/subr.h Normal file
View file

@ -0,0 +1,42 @@
/* Copyright (c) 2019 ACK Project.
* See the copyright notice in the ACK home directory,
* in the file "Copyright".
*
* Created on: 2019-05-02
*
*/
#ifndef SUBR_H_
#define SUBR_H_
#include "instruct.h"
struct varinfo;
void n_proc(char *name);
struct varinfo * make_erase(char *name);
void n_instr(char *name, char *asname, operand *oplist, struct varinfo *eraselist,
struct varinfo *cost);
void n_set(char *name, int number);
void n_tok(char *name, struct varinfo *atts, int size,
struct varinfo *cost, struct varinfo *format);
void checkprintformat(int n);
void n_prop(char *name, int size);
void prophall(int n);
int n_reg(char *name, char *printstring, int nmemb, int member1, int member2);
void make_const(void);
int cmustbeset(char *ident);
void n_const(char *ident, int val);
void n_sconst(char *ident, char *val);
void regline(struct varinfo *rl, struct varinfo *pl, int rv);
void check_reglap(void);
void setallreg(struct varinfo *vi);
void freevi(register struct varinfo *vip);
int myatoi(register char *s);
char *mystrcpy(char *s);
char *myalloc(register int n);
int chkincl(int value, int lwb, int upb);
int subset(short *sp1, short *sp2, int setsize);
int vilength(register struct varinfo *vip);
#endif /* SUBR_H_ */