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 "iocc.h"
#include "instruct.h" #include "instruct.h"
#include "expr.h" #include "expr.h"
#include "coerc.h"
#include "hall.h"
#include "subr.h"
#include "extern.h" #include "extern.h"
#include <cgg_cg.h> #include <cgg_cg.h>
#include <em_reg.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 int narexpr;
extern expr_t arexp[]; 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; int niops;
iocc_t iops[20]; iocc_t iops[20];
%} %}

View file

@ -14,6 +14,9 @@ static char rcsid[]= "$Id$";
#include "token.h" #include "token.h"
#include "varinfo.h" #include "varinfo.h"
#include "iocc.h" #include "iocc.h"
#include "subr.h"
#include "hall.h"
#include "coerc.h"
#include <cgg_cg.h> #include <cgg_cg.h>
#include "pseudo.h" #include "pseudo.h"
#include "extern.h" #include "extern.h"
@ -24,10 +27,15 @@ int nmoves;
move_t l_moves[MAXMOVES]; move_t l_moves[MAXMOVES];
short posmoves[MAXREGS + MAXTOKENS][SETSIZE]; short posmoves[MAXREGS + MAXTOKENS][SETSIZE];
void void n_split(int , int, struct varinfo *, struct varinfo *, struct varinfo *, int);
n_move(s1,e1,s2,e2,vi) struct varinfo *vi; {
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 move_p mp;
register i,j; register int i, j;
NEXT(nmoves, MAXMOVES, "Moves"); NEXT(nmoves, MAXMOVES, "Moves");
mp = &l_moves[nmoves - 1]; 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]; posmoves[i][j] |= l_sets[mp->m_set2].set_val[j];
} }
existmove(from,sp) iocc_t from; short *sp; { int existmove(iocc_t from, short *sp)
register i; {
register int i;
for (i = 0; i < MAXREGS + MAXTOKENS; i++) for (i = 0; i < MAXREGS + MAXTOKENS; i++)
if (BIT(from.in_set, i)) if (BIT(from.in_set, i))
@ -55,19 +64,22 @@ existmove(from,sp) iocc_t from; short *sp; {
return (1); return (1);
} }
existalmove(from,prpno) iocc_t from; { int existalmove(iocc_t from, int prpno)
{
short s[SETSIZE]; short s[SETSIZE];
register i; register int i;
for (i = 0; i < SETSIZE; i++) for (i = 0; i < SETSIZE; i++)
s[i] = i < SZOFSET(MAXREGS) ? l_props[prpno].pr_regset[i] : 0; s[i] = i < SZOFSET(MAXREGS) ? l_props[prpno].pr_regset[i] : 0;
return (existmove(from, s)); 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; register struct varinfo *vp;
if (existmove(from,to.in_set)==0) { if (existmove(from, to.in_set) == 0)
{
error("No such move defined"); error("No such move defined");
return (VI_NULL ); return (VI_NULL );
} }
@ -82,10 +94,10 @@ int ntests;
test_t l_tests[MAXTESTS]; test_t l_tests[MAXTESTS];
short postests[SETSIZE]; short postests[SETSIZE];
void void n_test(int s, int e, struct varinfo *vi)
n_test(s,e,vi) struct varinfo *vi; { {
register test_p tp; register test_p tp;
register i; register int i;
NEXT(ntests, MAXTESTS, "Tests"); NEXT(ntests, MAXTESTS, "Tests");
tp = &l_tests[ntests - 1]; 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]; 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; register struct varinfo *vp;
if (!subset(from.in_set,postests,SETSIZE)) { if (!subset(from.in_set, postests, SETSIZE))
{
error("No such test"); error("No such test");
return (0); return (0);
} }
@ -112,7 +126,8 @@ struct varinfo *gen_test(from) iocc_t from; {
return (vp); return (vp);
} }
struct varinfo *gen_label(arg) int arg; { struct varinfo *gen_label(int arg)
{
register struct varinfo *vp; register struct varinfo *vp;
NEW(vp, struct varinfo); NEW(vp, struct varinfo);
@ -121,7 +136,8 @@ struct varinfo *gen_label(arg) int arg; {
return (vp); return (vp);
} }
struct varinfo *gen_preturn() { struct varinfo *gen_preturn(void)
{
register struct varinfo *vp; register struct varinfo *vp;
NEW(vp, struct varinfo); NEW(vp, struct varinfo);
@ -129,7 +145,8 @@ struct varinfo *gen_preturn() {
return (vp); return (vp);
} }
struct varinfo *gen_tlab(n) { struct varinfo *gen_tlab(int n)
{
register struct varinfo *vp; register struct varinfo *vp;
assert(n >= 0 && n <= 9); assert(n >= 0 && n <= 9);
@ -143,10 +160,11 @@ int nstacks;
c1_t l_stacks[MAXSTACKS]; c1_t l_stacks[MAXSTACKS];
set_t ustackset, cstackset; 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 c1_p c1p;
register short *sp; register short *sp;
register i; register int i;
NEXT(nstacks, MAXSTACKS, "Stacks"); NEXT(nstacks, MAXSTACKS, "Stacks");
c1p = &l_stacks[nstacks - 1]; 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]; sp[i] |= l_sets[s].set_val[i];
} }
void void checkstacking(register short *sp)
checkstacking(sp) register short *sp; { {
register i; register int i;
register short *chkset; register short *chkset;
char *warn; char *warn;
if (subset(sp, ustackset.set_val, SETSIZE)) if (subset(sp, ustackset.set_val, SETSIZE))
return; return;
chkset = ustackset.set_val; warn = ""; chkset = ustackset.set_val;
warn = "";
for (i = 1; i < nregs; i++) for (i = 1; i < nregs; i++)
if (BIT(sp,i) && !BIT(chkset, i)) if (BIT(sp,i) && !BIT(chkset, i))
error("No %sstacking rule for register %s", warn, error("No %sstacking rule for register %s", warn,
@ -189,25 +208,32 @@ set_t unstackset;
/*VARARGS5*/ /*VARARGS5*/
void void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in)
n_coerc(ti,be,al,ge,rp,in) struct varinfo *al,*ge,*rp; iocc_t in; { {
register c3_p c3p; register c3_p c3p;
register i; register int i;
register struct varinfo *vi; register struct varinfo *vi;
if (ti!=0) { if (ti != 0)
{
for (i = 0, vi = rp; vi != 0; vi = vi->vi_next, i++) 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); n_split(ti, be, al, ge, rp, i);
return; return;
} else { }
if (i==0) { else
{
if (i == 0)
{
error("Coercion should have a result!"); error("Coercion should have a result!");
return; return;
} }
} }
} else { }
else
{
NEW(rp, struct varinfo); NEW(rp, struct varinfo);
rp->vi_next = 0; rp->vi_next = 0;
rp->vi_int[0] = in.in_index; 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); freevi(rp);
} }
checkunstacking(setno) { void checkunstacking(int setno)
{
register short *sp; register short *sp;
register i; register int i;
short hallset[SETSIZE]; short hallset[SETSIZE];
sp = l_sets[setno].set_val; sp = l_sets[setno].set_val;
@ -242,18 +269,21 @@ checkunstacking(setno) {
int nsplit, maxsplit; int nsplit, maxsplit;
c2_t l_split[MAXSPLCOERC]; 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 c2_p c2p;
register i; register int i;
register struct varinfo *vi; register struct varinfo *vi;
NEXT(nsplit, MAXSPLCOERC, "Splitting coercions"); NEXT(nsplit, MAXSPLCOERC, "Splitting coercions");
c2p = &l_split[nsplit - 1]; c2p = &l_split[nsplit - 1];
if (n>MAXSPLIT) { if (n > MAXSPLIT)
{
error("Maximum split factor is %d", MAXSPLIT); error("Maximum split factor is %d", MAXSPLIT);
n = MAXSPLIT; n = MAXSPLIT;
} }
if (n>maxsplit) maxsplit=n; if (n > maxsplit)
maxsplit = n;
c2p->c2_texpno = ti; c2p->c2_texpno = ti;
c2p->c2_expr = be; c2p->c2_expr = be;
if (nallreg) 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)) #define HASHSIZE (2*(sp_lmnem-sp_fmnem))
struct emhashmnem { struct emhashmnem
{
char h_name[3]; char h_name[3];
char h_value; char h_value;
} emhashmnem[HASHSIZE]; } emhashmnem[HASHSIZE];
initemhash() { /* Forward declarations */
register i; 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++) for (i = 0; i <= sp_lmnem - sp_fmnem; i++)
enter(em_mnem[i], i + sp_fmnem); enter(em_mnem[i], i + sp_fmnem);
enter("lab", op_lab); enter("lab", op_lab);
} }
unsigned emhash(name) register char *name; { static unsigned emhash(register char *name)
register unsigned sum; {
register i; register unsigned int sum;
register int i;
for (sum = i = 0; *name; i += 3) for (sum = i = 0; *name; i += 3)
sum ^= (*name++) << (i & 07); sum ^= (*name++) << (i & 07);
return (sum); return (sum);
} }
enter(name,value) char *name; { static void enter(char *name, int value)
{
register unsigned h; register unsigned h;
h = emhash(name) % HASHSIZE; h = emhash(name) % HASHSIZE;
@ -50,21 +59,24 @@ enter(name,value) char *name; {
emhashmnem[h].h_value = value; emhashmnem[h].h_value = value;
} }
int mlookup(name) char *name; { int mlookup(char *name)
{
register unsigned h; register unsigned h;
h = emhash(name) % HASHSIZE; h = emhash(name) % HASHSIZE;
while (strncmp(emhashmnem[h].h_name,name,3) != 0 && while (strncmp(emhashmnem[h].h_name, name, 3) != 0
emhashmnem[h].h_name[0] != 0) && emhashmnem[h].h_name[0] != 0)
h = (h + 1) % HASHSIZE; h = (h + 1) % HASHSIZE;
return (emhashmnem[h].h_value & 0xFF); /* 0 if not found */ return (emhashmnem[h].h_value & 0xFF); /* 0 if not found */
} }
extern char em_flag[]; 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_W:
case PAR_S: case PAR_S:
case PAR_Z: case PAR_Z:

View file

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

View file

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

View file

@ -3,6 +3,8 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/* $Id$ */ /* $Id$ */
#ifndef EXPR_H_
#define EXPR_H_
typedef struct expr { typedef struct expr {
int ex_typ; int ex_typ;
@ -15,6 +17,27 @@ typedef struct expr {
#define TYPADDR 3 #define TYPADDR 3
#define TYPREG 4 #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 /* When the type is register the regset contains the set of
possible registers for checking purposes only. possible registers for checking purposes only.
*/ */
#endif /* EXPR_H_ */

View file

@ -38,9 +38,8 @@ extern int maxtokensize;
extern int nprocargs, maxprocargs; extern int nprocargs, maxprocargs;
extern int use_tes; extern int use_tes;
extern char *mystrcpy();
extern char *myalloc();
extern void error(const char* s, ...); extern void error(const char* s, ...);
extern void fatal(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 "param.h"
#include "set.h" #include "set.h"
#include "extern.h" #include "extern.h"
#include "hall.h"
#include <stdio.h> #include <stdio.h>
/* /*
* This file implements the marriage thesis from Hall. * 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, * a finite set, it is possible to create a set with cardinality N,
* that contains one member for each of the subsets, * that contains one member for each of the subsets,
* iff for each number, say M, of subsets from 2 to N the union of * 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 nhallsets = -1;
int hallfreq[MAXHALL][2]; int hallfreq[MAXHALL][2];
hallverbose() { int recurhall(int, short [][SETSIZE]);
register i; void unite(register short *, short *);
register max;
void hallverbose(void)
{
register int i;
register int max;
fprintf(stderr, "Table of hall frequencies\n # pre post\n"); 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++) for (i = 0; i <= max; i++)
fprintf(stderr, "%3d%6d%6d\n", i, hallfreq[i][0], hallfreq[i][1]); fprintf(stderr, "%3d%6d%6d\n", i, hallfreq[i][0], hallfreq[i][1]);
} }
inithall() { void inithall(void)
{
assert(nhallsets == -1); assert(nhallsets == -1);
nhallsets = 0; nhallsets = 0;
} }
nexthall(sp) register short *sp; { void nexthall(register short *sp)
register i; {
register int i;
assert(nhallsets >= 0); assert(nhallsets >= 0);
for (i = 0; i < SETSIZE; i++) for (i = 0; i < SETSIZE; i++)
@ -58,8 +67,9 @@ nexthall(sp) register short *sp; {
nhallsets++; nhallsets++;
} }
card(sp) register short *sp; { int card(register short *sp)
register sum,i; {
register int sum, i;
sum = 0; sum = 0;
for (i = 0; i < 8 * sizeof(short) * SETSIZE; i++) for (i = 0; i < 8 * sizeof(short) * SETSIZE; i++)
@ -68,15 +78,16 @@ card(sp) register short *sp; {
return (sum); return (sum);
} }
checkhall() { void checkhall(void)
{
assert(nhallsets >= 0); assert(nhallsets >= 0);
if (!hall()) if (!hall())
error("Hall says: \"You can't have those registers\""); error("Hall says: \"You can't have those registers\"");
} }
hall() { int hall(void)
register i,j,k; {
register int i, j, k;
int ok; int ok;
hallfreq[nhallsets][0]++; hallfreq[nhallsets][0]++;
@ -86,14 +97,15 @@ hall() {
* But then nhallsets is less, so this step can be re-applied. * But then nhallsets is less, so this step can be re-applied.
*/ */
do { do
{
ok = 0; ok = 0;
for (i = 0; i < nhallsets; i++) for (i = 0; i < nhallsets; i++)
if (card(hallsets[i])>=nhallsets) { if (card(hallsets[i]) >= nhallsets)
{
for (j = i + 1; j < nhallsets; j++) for (j = i + 1; j < nhallsets; j++)
for (k = 0; k < SETSIZE; k++) for (k = 0; k < SETSIZE; k++)
hallsets[j-1][k] = hallsets[j - 1][k] = hallsets[j][k];
hallsets[j][k];
nhallsets--; nhallsets--;
ok = 1; ok = 1;
break; break;
@ -110,10 +122,11 @@ hall() {
return (ok); return (ok);
} }
recurhall(nhallsets,hallsets) short hallsets[][SETSIZE]; { int recurhall(int nhallsets, short hallsets[][SETSIZE])
{
short copysets[MAXHALL][SETSIZE]; short copysets[MAXHALL][SETSIZE];
short setsum[SETSIZE]; short setsum[SETSIZE];
register i,j,k,ncopys; register int i, j, k, ncopys;
/* /*
* First check cardinality of union of all * 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, * Now check the hall property of everything but one set,
* for all sets * for all sets
*/ */
for(i=0;i<nhallsets;i++) { for (i = 0; i < nhallsets; i++)
{
ncopys = 0; 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++) for (k = 0; k < SETSIZE; k++)
copysets[ncopys][k] = hallsets[j][k]; copysets[ncopys][k] = hallsets[j][k];
ncopys++; ncopys++;
@ -142,8 +158,9 @@ recurhall(nhallsets,hallsets) short hallsets[][SETSIZE]; {
return (1); return (1);
} }
unite(sp,into) register short *sp,*into; { void unite(register short *sp, short *into)
register i; {
register int i;
for (i = 0; i < SETSIZE; i++) for (i = 0; i < SETSIZE; i++)
into[i] |= sp[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 "set.h"
#include "expr.h" #include "expr.h"
#include "iocc.h" #include "iocc.h"
#include "subr.h"
#include <cgg_cg.h> #include <cgg_cg.h>
#include "extern.h" #include "extern.h"
extern int niops; extern int niops;
extern iocc_t iops[]; extern iocc_t iops[];
extern inproc; extern int inproc;
extern set_t l_sets[]; extern set_t l_sets[];
extern inst_t l_instances[]; extern inst_t l_instances[];
extern expr_t subreg_expr(), regno_expr(); extern expr_t subreg_expr(), regno_expr();
struct varinfo * setcoco(n) { static struct varinfo * setcoco(int n)
{
struct varinfo *vi; struct varinfo *vi;
NEW(vi, struct varinfo); NEW(vi, struct varinfo);
@ -36,7 +38,8 @@ struct varinfo * setcoco(n) {
return (vi); return (vi);
} }
struct varinfo * generase(n) { static struct varinfo * generase(int n)
{
struct varinfo *vi; struct varinfo *vi;
NEW(vi, struct varinfo); NEW(vi, struct varinfo);
@ -46,7 +49,8 @@ struct varinfo * generase(n) {
return (vi); return (vi);
} }
struct varinfo * genremove(n) { static struct varinfo * genremove(int n)
{
struct varinfo *vi; struct varinfo *vi;
NEW(vi, struct varinfo); NEW(vi, struct varinfo);
@ -56,11 +60,13 @@ struct varinfo * genremove(n) {
return (vi); return (vi);
} }
onlyreg(argno) { static int onlyreg(int argno)
register bitno; {
register int bitno;
register short *sp; register short *sp;
if (! argno) argno++; if (!argno)
argno++;
sp = l_sets[tokpatset[argno - 1]].set_val; sp = l_sets[tokpatset[argno - 1]].set_val;
for (bitno = nregs; bitno < nregs + ntokens; bitno++) for (bitno = nregs; bitno < nregs + ntokens; bitno++)
if (BIT(sp, bitno)) if (BIT(sp, bitno))
@ -68,10 +74,12 @@ onlyreg(argno) {
return (1); return (1);
} }
makescratch(argno) { static void makescratch(int argno)
{
set_t s; set_t s;
if (! argno) argno++; if (!argno)
argno++;
if (tokpatro[argno - 1]) if (tokpatro[argno - 1])
error("Instruction destroys %%%d, not allowed here", argno); error("Instruction destroys %%%d, not allowed here", argno);
s = l_sets[tokpatset[argno - 1]]; s = l_sets[tokpatset[argno - 1]];
@ -79,25 +87,29 @@ makescratch(argno) {
tokpatset[argno - 1] = setlookup(s); 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 struct varinfo *vi, *retval, *eravi;
register instr_p ip; register instr_p ip;
register struct operand *op; register struct operand *op;
register i; register int i;
register inst_p insta; register inst_p insta;
if (star && !inproc) if (star && !inproc)
error("Variable instruction only allowed inside proc"); 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)) if (strcmp(ident, ip->i_name))
continue; continue;
if (ip->i_nops != niops) if (ip->i_nops != niops)
continue; 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)) if (!subset(iops[i].in_set, l_sets[op->o_setno].set_val, SETSIZE))
goto cont; goto cont;
} }
goto found; /* oh well, one more won't hurt */ goto found;
/* oh well, one more won't hurt */
cont: ; cont: ;
} }
error("Such an \"%s\" does not exist", ident); error("Such an \"%s\" does not exist", ident);
@ -108,19 +120,23 @@ found:
vi->vi_int[1] = star; vi->vi_int[1] = star;
vi->vi_next = 0; vi->vi_next = 0;
retval = vi; retval = vi;
for(i=0;i<niops;i++) { for (i = 0; i < niops; i++)
{
NEW(vi->vi_vi, struct varinfo); NEW(vi->vi_vi, struct varinfo);
vi = vi->vi_vi; vi = vi->vi_vi;
vi->vi_int[0] = iops[i].in_index; vi->vi_int[0] = iops[i].in_index;
} }
vi->vi_vi = 0; vi->vi_vi = 0;
vi = retval; vi = retval;
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(op->o_adorn&AD_CC) { {
if (op->o_adorn & AD_CC)
{
vi->vi_next = setcoco(iops[i].in_index); vi->vi_next = setcoco(iops[i].in_index);
vi = vi->vi_next; vi = vi->vi_next;
} }
switch(op->o_adorn&AD_RWMASK) { switch (op->o_adorn & AD_RWMASK)
{
default: default:
/* Nothing possible to do */ /* Nothing possible to do */
break; break;
@ -133,48 +149,36 @@ found:
case AD_WO: case AD_WO:
/* Treated the same for now */ /* Treated the same for now */
insta = &l_instances[iops[i].in_index]; insta = &l_instances[iops[i].in_index];
switch(insta->in_which) { switch (insta->in_which)
{
case IN_COPY: 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; break;
makescratch(insta->in_info[0]); makescratch(insta->in_info[0]);
vi->vi_next = generase( vi->vi_next = generase(ex_lookup(
ex_lookup( EX_SUBREG, insta->in_info[0], insta->in_info[1]));
EX_SUBREG,insta->in_info[0],
insta->in_info[1]
)
);
vi = vi->vi_next; vi = vi->vi_next;
break; break;
case IN_MEMB: case IN_MEMB:
vi->vi_next = generase( vi->vi_next = generase(ex_lookup(
ex_lookup( EX_TOKFIELD, insta->in_info[0], insta->in_info[1]));
EX_TOKFIELD,insta->in_info[0],
insta->in_info[1]
)
);
vi = vi->vi_next; vi = vi->vi_next;
break; break;
case IN_RIDENT: case IN_RIDENT:
vi->vi_next = generase( vi->vi_next = generase(ex_lookup(
ex_lookup( EX_REG, insta->in_info[0], 0));
EX_REG,insta->in_info[0],0
)
);
vi = vi->vi_next; vi = vi->vi_next;
break; break;
case IN_ALLOC: case IN_ALLOC:
vi->vi_next = generase( vi->vi_next = generase(ex_lookup(
ex_lookup( EX_ALLREG, insta->in_info[0] + 1, insta->in_info[1]));
EX_ALLREG,insta->in_info[0]+1,
insta->in_info[1]
)
);
vi = vi->vi_next; vi = vi->vi_next;
break; break;
case IN_S_DESCR: case IN_S_DESCR:
case IN_D_DESCR: case IN_D_DESCR:
{ int temp; {
int temp;
if (insta->in_which == IN_S_DESCR) if (insta->in_which == IN_S_DESCR)
temp = wordsize; temp = wordsize;
@ -191,10 +195,12 @@ found:
break; 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) if (eravi->vi_int[0] < 0)
vi->vi_next = setcoco(0); vi->vi_next = setcoco(0);
else { else
{
vi->vi_next = generase(eravi->vi_int[0]); vi->vi_next = generase(eravi->vi_int[0]);
vi = vi->vi_next; vi = vi->vi_next;
vi->vi_next = genremove(eravi->vi_int[0]); 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". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/* $Id$ */ /* $Id$ */
#ifndef INSTRUCT_H_
#define INSTRUCT_H_
#ifndef _COST_ #ifndef _COST_
#include "cost.h" #include "cost.h"
@ -39,3 +41,8 @@ extern instr_t l_instr[];
* if it contains the same information and is allowed as an operand * if it contains the same information and is allowed as an operand
* in this place. Too difficult for now. * 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 "set.h"
#include "expr.h" #include "expr.h"
#include "lookup.h" #include "lookup.h"
#include "subr.h"
#include "token.h" #include "token.h"
#include "property.h" #include "property.h"
#include "iocc.h" #include "iocc.h"
@ -28,20 +29,26 @@ expr_t arexp[MAXATT];
expr_t iextoaddr(); 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; inst_t insta;
iocc_t result; iocc_t result;
register i; register int i;
insta.in_which = IN_COPY; insta.in_which = IN_COPY;
insta.in_info[0] = tokarg; insta.in_info[0] = tokarg;
insta.in_info[1] = subreg; insta.in_info[1] = subreg;
result.in_index = instalookup(insta, 2); result.in_index = instalookup(insta, 2);
if (tokarg < 1) tokarg = 1; if (tokarg < 1)
tokarg = 1;
if (subreg == 0) if (subreg == 0)
for (i = 0; i < SETSIZE; i++) for (i = 0; i < SETSIZE; i++)
result.in_set[i] = l_sets[tokpatset[tokarg - 1]].set_val[i]; result.in_set[i] = l_sets[tokpatset[tokarg - 1]].set_val[i];
else { else
{
for (i = 0; i < SETSIZE; i++) for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0; result.in_set[i] = 0;
subregset(l_sets[tokpatset[tokarg - 1]].set_val, subreg, result.in_set); subregset(l_sets[tokpatset[tokarg - 1]].set_val, subreg, result.in_set);
@ -49,10 +56,11 @@ iocc_t subr_iocc(tokarg,subreg) {
return (result); return (result);
} }
iocc_t tokm_iocc(tokarg,ident) char *ident; { iocc_t tokm_iocc(int tokarg, char *ident)
{
iocc_t result; iocc_t result;
inst_t insta; inst_t insta;
register i; register int i;
char app[100]; char app[100];
int dummy; int dummy;
@ -60,18 +68,21 @@ iocc_t tokm_iocc(tokarg,ident) char *ident; {
result.in_set[i] = 0; result.in_set[i] = 0;
insta.in_which = IN_MEMB; insta.in_which = IN_MEMB;
insta.in_info[0] = tokarg; insta.in_info[0] = tokarg;
if (tokarg < 1) tokarg = 1; if (tokarg < 1)
tokarg = 1;
sprintf(app, "%%%d.%s", tokarg, ident); sprintf(app, "%%%d.%s", tokarg, ident);
insta.in_info[1] = 1+membset(tokpatset[tokarg-1],ident,result.in_set, insta.in_info[1] = 1
app,TYPREG,&dummy); + membset(tokpatset[tokarg - 1], ident, result.in_set, app, TYPREG,
&dummy);
result.in_index = instalookup(insta, 2); result.in_index = instalookup(insta, 2);
return (result); return (result);
} }
iocc_t percident_iocc(ident) char *ident; { iocc_t percident_iocc(char *ident)
{
iocc_t result; iocc_t result;
inst_t insta; inst_t insta;
register i; register int i;
char app[100]; char app[100];
int dummy; int dummy;
@ -80,16 +91,17 @@ iocc_t percident_iocc(ident) char *ident; {
insta.in_which = IN_MEMB; insta.in_which = IN_MEMB;
insta.in_info[0] = 0; insta.in_info[0] = 0;
sprintf(app, "%%%s", ident); sprintf(app, "%%%s", ident);
insta.in_info[1] = 1+membset(cursetno,ident,result.in_set, insta.in_info[1] = 1
app,TYPREG,&dummy); + membset(cursetno, ident, result.in_set, app, TYPREG, &dummy);
result.in_index = instalookup(insta, 2); result.in_index = instalookup(insta, 2);
return (result); return (result);
} }
iocc_t ident_iocc(ident) char *ident; { iocc_t ident_iocc(char *ident)
{
iocc_t result; iocc_t result;
inst_t insta; inst_t insta;
register i; register int i;
register symbol *sy_p; register symbol *sy_p;
for (i = 0; i < SETSIZE; i++) for (i = 0; i < SETSIZE; i++)
@ -102,10 +114,11 @@ iocc_t ident_iocc(ident) char *ident; {
return (result); return (result);
} }
iocc_t all_iocc(all_no,subreg) { iocc_t all_iocc(int all_no, int subreg)
{
iocc_t result; iocc_t result;
inst_t insta; inst_t insta;
register i; register int i;
set_t localset; set_t localset;
register short *sp; register short *sp;
@ -122,12 +135,13 @@ iocc_t all_iocc(all_no,subreg) {
return (result); return (result);
} }
iocc_t descr_iocc(ident) char *ident; { iocc_t descr_iocc(char *ident)
{
iocc_t result; iocc_t result;
inst_t insta; inst_t insta;
register symbol *sy_p; register symbol *sy_p;
register token_p tp; register token_p tp;
register i; register int i;
int typerr; int typerr;
for (i = 0; i < SETSIZE; i++) 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) else if (rvused & DL_REGVAR && strcmp(ident, "DLOCAL") == 0)
insta.in_which = IN_D_DESCR; insta.in_which = IN_D_DESCR;
insta.in_info[0] = sy_p->sy_value.syv_tokno; insta.in_info[0] = sy_p->sy_value.syv_tokno;
for (i=0;i<MAXATT;i++) { for (i = 0; i < MAXATT; i++)
if (tp->tk_att[i].ta_type == -3) { {
if (tp->tk_att[i].ta_type == -3)
{
if (narexpr > i) if (narexpr > i)
error("token %s initialized with too many attributes", ident); error("token %s initialized with too many attributes", ident);
break; break;
} }
if (i>= narexpr) { if (i >= narexpr)
error("token %s initialized with too few attributes", {
ident); error("token %s initialized with too few attributes", ident);
break; break;
} }
typerr = 0; typerr = 0;
switch(arexp[i].ex_typ) { switch (arexp[i].ex_typ)
default: assert(0); {
default:
assert(0);
case TYPINT: case TYPINT:
if (tp->tk_att[i].ta_type != -1) if (tp->tk_att[i].ta_type != -1)
if (tp->tk_att[i].ta_type == -2) if (tp->tk_att[i].ta_type == -2)
@ -163,7 +181,8 @@ iocc_t descr_iocc(ident) char *ident; {
typerr++; typerr++;
break; break;
case TYPBOOL: case TYPBOOL:
typerr++; break; typerr++;
break;
case TYPADDR: case TYPADDR:
if (tp->tk_att[i].ta_type != -2) if (tp->tk_att[i].ta_type != -2)
typerr++; typerr++;
@ -178,8 +197,8 @@ iocc_t descr_iocc(ident) char *ident; {
break; break;
} }
if (typerr) if (typerr)
error("Attribute %s.%s given wrong type of value", error("Attribute %s.%s given wrong type of value", ident,
ident,tp->tk_att[i].ta_name); tp->tk_att[i].ta_name);
insta.in_info[i + 1] = arexp[i].ex_index; insta.in_info[i + 1] = arexp[i].ex_index;
} }
result.in_index = instalookup(insta, i + 1); result.in_index = instalookup(insta, i + 1);
@ -191,12 +210,14 @@ iocc_t descr_iocc(ident) char *ident; {
int ninstances = 1; int ninstances = 1;
inst_t l_instances[MAXINSTANCES]; inst_t l_instances[MAXINSTANCES];
instalookup(insta,filled) inst_t insta; { static int instalookup(inst_t insta, int filled)
register i,j; {
register int i, j;
for (j = filled; j <= MAXATT; j++) for (j = filled; j <= MAXATT; j++)
insta.in_info[j] = 0; 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) if (insta.in_which != l_instances[i].in_which)
continue; continue;
for (j = 0; j <= MAXATT; j++) 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". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/* $Id$ */ /* $Id$ */
#ifndef IOCC_H_
#define IOCC_H_
#include "param.h"
typedef struct iocc { typedef struct iocc {
short in_set[SETSIZE]; short in_set[SETSIZE];
int in_index; int in_index;
} iocc_t,*iocc_p; } iocc_t,*iocc_p;
#endif

View file

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

View file

@ -3,6 +3,8 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/* $Id$ */ /* $Id$ */
#ifndef LOOKUP_H_
#define LOOKUP_H_
typedef enum { typedef enum {
justlooking,mustexist,newsymbol,makeexist justlooking,mustexist,newsymbol,makeexist
@ -30,4 +32,7 @@ typedef struct symbol {
#define NSYMHASH 61 #define NSYMHASH 61
extern symbol *symhash[NSYMHASH]; /* chained hashtable */ 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 <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "param.h"
#include "hall.h"
#include "expr.h"
#include "extern.h" #include "extern.h"
char *filename; 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 nerrors;
extern int code_in_c; extern int code_in_c;
extern int tabledebug; extern int tabledebug;
extern int verbose; extern int verbose;
while (argc >1 && argv[1][0]=='-') { while (argc > 1 && argv[1][0] == '-')
switch(argv[1][1]) { {
switch (argv[1][1])
{
case 'c': case 'c':
code_in_c = 0; code_in_c = 0;
break; break;
@ -32,30 +45,38 @@ main(argc,argv) char **argv; {
default: default:
error("Unknown flag -%c", argv[1][1]); error("Unknown flag -%c", argv[1][1]);
} }
argc--; argv++; argc--;
argv++;
} }
if (argc==2) { if (argc == 2)
if (freopen(argv[1],"r",stdin)==NULL) { {
if (freopen(argv[1], "r", stdin) == NULL)
{
error("Can't open %s", argv[1]); error("Can't open %s", argv[1]);
exit(-1); exit(-1);
} }
filename = argv[1]; filename = argv[1];
} }
else if (argc == 1) { else if (argc == 1)
{
filename = ""; filename = "";
} else }
else
error("Usage: %s [-c] [-d] [-v] [table]", argv[0]); error("Usage: %s [-c] [-d] [-v] [table]", argv[0]);
initemhash(); initemhash();
enterkeyw(); enterkeyw();
initnodes(); initnodes();
initio(); initio();
yyparse(); yyparse();
if (nerrors==0) { if (nerrors == 0)
{
finishio(); finishio();
statistics(); statistics();
if (verbose) if (verbose)
hallverbose(); hallverbose();
} else { }
else
{
errorexit(); errorexit();
} }
exit(nerrors == 0 ? 0 : -1); exit(nerrors == 0 ? 0 : -1);

View file

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

View file

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

View file

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

View file

@ -3,7 +3,21 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
/* $Id$ */ /* $Id$ */
#ifndef SET_H_
#define SET_H_
#include <cgg_cg.h>
#define BIS(sp,n) (sp)[(n)>>4] |= 1<<((n)&0xF) #define BIS(sp,n) (sp)[(n)>>4] |= 1<<((n)&0xF)
#define BIC(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) #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 <string.h>
#include "param.h" #include "param.h"
#include "subr.h"
#include "extern.h" #include "extern.h"
int nstrings = 0; int nstrings = 0;
char *l_strings[MAXSTRINGS]; char *l_strings[MAXSTRINGS];
strlookup(str) char *str; { int strlookup(char *str)
register i; {
extern char *mystrcpy(); register int i;
for (i = 0; i < nstrings; i++) for (i = 0; i < nstrings; i++)
if (strcmp(str, l_strings[i]) == 0) if (strcmp(str, l_strings[i]) == 0)

View file

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