ANSI C conversion and add procedure declarations.

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

View file

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

View file

@ -3,7 +3,7 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <assert.h>
@ -14,6 +14,9 @@ static char rcsid[]= "$Id$";
#include "token.h"
#include "varinfo.h"
#include "iocc.h"
#include "subr.h"
#include "hall.h"
#include "coerc.h"
#include <cgg_cg.h>
#include "pseudo.h"
#include "extern.h"
@ -22,165 +25,181 @@ extern set_t l_sets[];
int nmoves;
move_t l_moves[MAXMOVES];
short posmoves[MAXREGS+MAXTOKENS][SETSIZE];
short posmoves[MAXREGS + MAXTOKENS][SETSIZE];
void
n_move(s1,e1,s2,e2,vi) struct varinfo *vi; {
void n_split(int , int, struct varinfo *, struct varinfo *, struct varinfo *, int);
extern void dopattern(int stackcoerc, varinfo *kills, varinfo *allocates,
varinfo *generates, varinfo *yields, varinfo *leaving);;
void n_move(int s1, int e1, int s2, int e2, struct varinfo *vi)
{
register move_p mp;
register i,j;
register int i, j;
NEXT(nmoves,MAXMOVES,"Moves");
mp = &l_moves[nmoves-1];
NEXT(nmoves, MAXMOVES, "Moves");
mp = &l_moves[nmoves - 1];
mp->m_set1 = s1;
mp->m_expr1 = e1;
mp->m_set2 = s2;
mp->m_expr2 = e2;
mp->m_cindex = codeindex;
dopattern(0,VI_NULL,VI_NULL,vi,VI_NULL,VI_NULL);
if (mp->m_expr1!=0 || mp->m_expr2!=0)
dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL);
if (mp->m_expr1 != 0 || mp->m_expr2 != 0)
return;
for (i=0;i<MAXREGS+MAXTOKENS;i++)
if (BIT(l_sets[mp->m_set1].set_val,i))
for(j=0;j<SETSIZE;j++)
posmoves[i][j] |= l_sets[mp->m_set2].set_val[j];
for (i = 0; i < MAXREGS + MAXTOKENS; i++)
if (BIT(l_sets[mp->m_set1].set_val, i))
for (j = 0; j < SETSIZE; j++)
posmoves[i][j] |= l_sets[mp->m_set2].set_val[j];
}
existmove(from,sp) iocc_t from; short *sp; {
register i;
int existmove(iocc_t from, short *sp)
{
register int i;
for (i=0;i<MAXREGS+MAXTOKENS;i++)
if(BIT(from.in_set,i))
if (!subset(sp,posmoves[i],SETSIZE))
return(0);
return(1);
for (i = 0; i < MAXREGS + MAXTOKENS; i++)
if (BIT(from.in_set, i))
if (!subset(sp, posmoves[i], SETSIZE))
return (0);
return (1);
}
existalmove(from,prpno) iocc_t from; {
int existalmove(iocc_t from, int prpno)
{
short s[SETSIZE];
register i;
for (i=0;i<SETSIZE;i++)
s[i] = i<SZOFSET(MAXREGS) ? l_props[prpno].pr_regset[i] : 0;
return(existmove(from,s));
register int i;
for (i = 0; i < SETSIZE; i++)
s[i] = i < SZOFSET(MAXREGS) ? l_props[prpno].pr_regset[i] : 0;
return (existmove(from, s));
}
struct varinfo *gen_move(from,to) iocc_t from,to; {
struct varinfo *gen_move(iocc_t from, iocc_t to)
{
register struct varinfo *vp;
if (existmove(from,to.in_set)==0) {
if (existmove(from, to.in_set) == 0)
{
error("No such move defined");
return(VI_NULL);
return (VI_NULL );
}
NEW(vp,struct varinfo);
NEW(vp, struct varinfo);
vp->vi_int[0] = INSMOVE;
vp->vi_int[1] = from.in_index;
vp->vi_int[2] = to.in_index;
return(vp);
return (vp);
}
int ntests;
test_t l_tests[MAXTESTS];
short postests[SETSIZE];
void
n_test(s,e,vi) struct varinfo *vi; {
void n_test(int s, int e, struct varinfo *vi)
{
register test_p tp;
register i;
register int i;
NEXT(ntests,MAXTESTS,"Tests");
tp = &l_tests[ntests-1];
NEXT(ntests, MAXTESTS, "Tests");
tp = &l_tests[ntests - 1];
tp->t_set = s;
tp->t_expr = e;
tp->t_expr = e;
tp->t_cindex = codeindex;
dopattern(0,VI_NULL,VI_NULL,vi,VI_NULL,VI_NULL);
if (tp->t_expr!=0)
dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL);
if (tp->t_expr != 0)
return;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; 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;
if (!subset(from.in_set,postests,SETSIZE)) {
if (!subset(from.in_set, postests, SETSIZE))
{
error("No such test");
return(0);
return (0);
}
NEW(vp,struct varinfo);
NEW(vp, struct varinfo);
vp->vi_int[0] = INSTEST;
vp->vi_int[1] = from.in_index;
return(vp);
return (vp);
}
struct varinfo *gen_label(arg) int arg; {
struct varinfo *gen_label(int arg)
{
register struct varinfo *vp;
NEW(vp,struct varinfo);
NEW(vp, struct varinfo);
vp->vi_int[0] = INSLABDEF;
vp->vi_int[1] = arg;
return(vp);
return (vp);
}
struct varinfo *gen_preturn() {
struct varinfo *gen_preturn(void)
{
register struct varinfo *vp;
NEW(vp,struct varinfo);
NEW(vp, struct varinfo);
vp->vi_int[0] = INSPRETURN;
return(vp);
return (vp);
}
struct varinfo *gen_tlab(n) {
struct varinfo *gen_tlab(int n)
{
register struct varinfo *vp;
assert(n>=0 && n<=9);
NEW(vp,struct varinfo);
assert(n >= 0 && n <= 9);
NEW(vp, struct varinfo);
vp->vi_int[0] = INSTLAB;
vp->vi_int[1] = n;
return(vp);
return (vp);
}
int nstacks;
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 short *sp;
register i;
register int i;
NEXT(nstacks,MAXSTACKS,"Stacks");
c1p= & l_stacks[nstacks-1];
NEXT(nstacks, MAXSTACKS, "Stacks");
c1p = &l_stacks[nstacks - 1];
c1p->c1_texpno = s;
c1p->c1_expr = e;
c1p->c1_prop = p;
c1p->c1_codep = codeindex;
dopattern(0,VI_NULL,VI_NULL,vi,VI_NULL,VI_NULL);
dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL);
if (e==0 && p== -1)
if (e == 0 && p == -1)
sp = ustackset.set_val;
else
sp = cstackset.set_val;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; i++)
sp[i] |= l_sets[s].set_val[i];
}
void
checkstacking(sp) register short *sp; {
register i;
void checkstacking(register short *sp)
{
register int i;
register short *chkset;
char *warn;
if (subset(sp,ustackset.set_val,SETSIZE))
if (subset(sp, ustackset.set_val, SETSIZE))
return;
chkset = ustackset.set_val; warn = "";
for (i=1;i<nregs;i++)
if (BIT(sp,i) && !BIT(chkset,i))
error("No %sstacking rule for register %s",warn,
l_regs[i].ri_name);
for(;i<nregs+MAXTOKENS;i++)
if (BIT(sp,i) && !BIT(chkset,i))
error("No %sstacking rule for token %s",warn,
l_tokens[i-nregs]->tk_name);
chkset = ustackset.set_val;
warn = "";
for (i = 1; i < nregs; i++)
if (BIT(sp,i) && !BIT(chkset, i))
error("No %sstacking rule for register %s", warn,
l_regs[i].ri_name);
for (; i < nregs + MAXTOKENS; i++)
if (BIT(sp,i) && !BIT(chkset, i))
error("No %sstacking rule for token %s", warn,
l_tokens[i - nregs]->tk_name);
}
int ncoercs;
@ -189,78 +208,89 @@ set_t unstackset;
/*VARARGS5*/
void
n_coerc(ti,be,al,ge,rp,in) struct varinfo *al,*ge,*rp; iocc_t in; {
void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in)
{
register c3_p c3p;
register i;
register int i;
register struct varinfo *vi;
if (ti!=0) {
for(i=0,vi=rp;vi!=0;vi=vi->vi_next,i++)
if (ti != 0)
{
for (i = 0, vi = rp; vi != 0; vi = vi->vi_next, i++)
;
if (i>1) {
n_split(ti,be,al,ge,rp,i);
if (i > 1)
{
n_split(ti, be, al, ge, rp, i);
return;
} else {
if (i==0) {
}
else
{
if (i == 0)
{
error("Coercion should have a result!");
return;
}
}
} else {
NEW(rp,struct varinfo);
}
else
{
NEW(rp, struct varinfo);
rp->vi_next = 0;
rp->vi_int[0] = in.in_index;
}
if (nallreg>1)
if (nallreg > 1)
error("More than 1 register may not be allocated");
NEXT(ncoercs,MAXCOERCS,"Coercions");
c3p = & l_coercs[ncoercs-1];
NEXT(ncoercs, MAXCOERCS, "Coercions");
c3p = &l_coercs[ncoercs - 1];
c3p->c3_texpno = ti;
c3p->c3_expr = be;
c3p->c3_prop = nallreg==0 ? -1 : allreg[0];
c3p->c3_prop = nallreg == 0 ? -1 : allreg[0];
c3p->c3_repl = rp->vi_int[0];
c3p->c3_codep = codeindex;
dopattern(ti==0,VI_NULL,al,ge,rp,VI_NULL);
if (ti==0)
for(i=0;i<SETSIZE;i++)
dopattern(ti == 0, VI_NULL, al, ge, rp, VI_NULL);
if (ti == 0)
for (i = 0; i < SETSIZE; i++)
unstackset.set_val[i] |= in.in_set[i];
freevi(rp);
}
checkunstacking(setno) {
void checkunstacking(int setno)
{
register short *sp;
register i;
register int i;
short hallset[SETSIZE];
sp = l_sets[setno].set_val;
for (i=0;i<SETSIZE;i++)
hallset[i]=sp[i]&unstackset.set_val[i];
for (i = 0; i < SETSIZE; i++)
hallset[i] = sp[i] & unstackset.set_val[i];
nexthall(hallset);
}
int nsplit,maxsplit;
int nsplit, maxsplit;
c2_t l_split[MAXSPLCOERC];
n_split(ti,be,al,ge,rp,n) struct varinfo *al,*ge,*rp; {
void n_split(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, int n)
{
register c2_p c2p;
register i;
register int i;
register struct varinfo *vi;
NEXT(nsplit,MAXSPLCOERC,"Splitting coercions");
c2p = &l_split[nsplit-1];
if (n>MAXSPLIT) {
error("Maximum split factor is %d",MAXSPLIT);
NEXT(nsplit, MAXSPLCOERC, "Splitting coercions");
c2p = &l_split[nsplit - 1];
if (n > MAXSPLIT)
{
error("Maximum split factor is %d", MAXSPLIT);
n = MAXSPLIT;
}
if (n>maxsplit) maxsplit=n;
if (n > maxsplit)
maxsplit = n;
c2p->c2_texpno = ti;
c2p->c2_expr = be;
if (nallreg)
error("No register uses allowed in splitting coercion");
c2p->c2_nsplit = n;
for (i=0,vi=rp; i<n; i++,vi=vi->vi_next)
for (i = 0, vi = rp; i < n; i++, vi = vi->vi_next)
c2p->c2_repl[i] = vi->vi_int[0];
c2p->c2_codep = codeindex;
dopattern(0,VI_NULL,al,ge,rp,VI_NULL);
dopattern(0, VI_NULL, al, ge, rp, VI_NULL);
}

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

@ -3,7 +3,7 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <stdlib.h>
@ -18,64 +18,76 @@ extern char em_mnem[][4];
#define HASHSIZE (2*(sp_lmnem-sp_fmnem))
struct emhashmnem {
struct emhashmnem
{
char h_name[3];
char h_value;
} emhashmnem[HASHSIZE];
initemhash() {
register i;
/* Forward declarations */
static void enter(char *, int);
static unsigned emhash(register char *);
for(i=0;i<=sp_lmnem-sp_fmnem;i++)
enter(em_mnem[i],i+sp_fmnem);
void initemhash(void)
{
register int i;
for (i = 0; i <= sp_lmnem - sp_fmnem; i++)
enter(em_mnem[i], i + sp_fmnem);
enter("lab", op_lab);
}
unsigned emhash(name) register char *name; {
register unsigned sum;
register i;
static unsigned emhash(register char *name)
{
register unsigned int sum;
register int i;
for (sum=i=0;*name;i+=3)
sum ^= (*name++)<<(i&07);
return(sum);
for (sum = i = 0; *name; i += 3)
sum ^= (*name++) << (i & 07);
return (sum);
}
enter(name,value) char *name; {
static void enter(char *name, int value)
{
register unsigned h;
h=emhash(name)%HASHSIZE;
h = emhash(name) % HASHSIZE;
while (emhashmnem[h].h_name[0] != 0)
h = (h+1)%HASHSIZE;
strncpy(emhashmnem[h].h_name,name,3);
h = (h + 1) % HASHSIZE;
strncpy(emhashmnem[h].h_name, name, 3);
emhashmnem[h].h_value = value;
}
int mlookup(name) char *name; {
int mlookup(char *name)
{
register unsigned h;
h = emhash(name)%HASHSIZE;
while (strncmp(emhashmnem[h].h_name,name,3) != 0 &&
emhashmnem[h].h_name[0] != 0)
h = (h+1)%HASHSIZE;
return(emhashmnem[h].h_value&0xFF); /* 0 if not found */
h = emhash(name) % HASHSIZE;
while (strncmp(emhashmnem[h].h_name, name, 3) != 0
&& emhashmnem[h].h_name[0] != 0)
h = (h + 1) % HASHSIZE;
return (emhashmnem[h].h_value & 0xFF); /* 0 if not found */
}
extern char em_flag[];
argtyp(mn) {
int argtyp(int mn)
{
switch(em_flag[mn-sp_fmnem]&EM_PAR) {
case PAR_W:
case PAR_S:
case PAR_Z:
case PAR_O:
case PAR_N:
case PAR_L:
case PAR_F:
case PAR_R:
case PAR_C:
return(TYPINT);
default:
return(TYPADDR);
switch (em_flag[mn - sp_fmnem] & EM_PAR)
{
case PAR_W:
case PAR_S:
case PAR_Z:
case PAR_O:
case PAR_N:
case PAR_L:
case PAR_F:
case PAR_R:
case PAR_C:
return (TYPINT);
default:
return (TYPADDR);
}
}

View file

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

View file

@ -3,7 +3,7 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <assert.h>
@ -24,263 +24,308 @@ static char rcsid[]= "$Id$";
extern set_t l_sets[];
i_expr(e) expr_t e; {
int i_expr(expr_t e)
{
if (e.ex_typ != TYPINT)
error("Expression should be integer");
return(e.ex_index);
return (e.ex_index);
}
b_expr(e) expr_t e; {
int b_expr(expr_t e)
{
if (e.ex_typ != TYPBOOL)
error("Expression should be boolean");
return(e.ex_index);
return (e.ex_index);
}
expr_t make_expr(type,operator,op1,op2) {
expr_t make_expr(int type, int operator, int op1, int op2)
{
expr_t result;
result.ex_typ=type;
result.ex_index=ex_lookup(operator,op1,op2);
return(result);
result.ex_typ = type;
result.ex_index = ex_lookup(operator, op1, op2);
return (result);
}
expr_t regno_expr(regno) {
expr_t regno_expr(int regno)
{
expr_t result;
register i;
register int i;
result.ex_typ = TYPREG;
result.ex_index = ex_lookup(EX_REG,regno,0);
for (i=0;i<SZOFSET(MAXREGS);i++)
result.ex_index = ex_lookup(EX_REG, regno, 0);
for (i = 0; i < SZOFSET(MAXREGS); i++)
result.ex_regset[i] = 0;
BIS(result.ex_regset,regno);
return(result);
BIS(result.ex_regset, regno);
return (result);
}
expr_t ident_expr(name) char *name; {
expr_t ident_expr(char *name)
{
register symbol *sy_p;
sy_p = lookup(name,symany,mustexist);
if (sy_p->sy_type==symconst)
return(make_expr(TYPINT,EX_CON,
(int) (sy_p->sy_value.syv_cstval&0xFFFF),
(int) (sy_p->sy_value.syv_cstval>>16)));
else if (sy_p->sy_type==symsconst)
return(make_expr(TYPADDR,EX_STRING,sy_p->sy_value.syv_stringno,0));
else if (sy_p->sy_type!=symreg)
error("Wrong type of identifier %s",name);
return(regno_expr(sy_p->sy_value.syv_regno));
sy_p = lookup(name, symany, mustexist);
if (sy_p->sy_type == symconst)
return (make_expr(TYPINT, EX_CON,
(int) (sy_p->sy_value.syv_cstval & 0xFFFF),
(int) (sy_p->sy_value.syv_cstval >> 16)));
else if (sy_p->sy_type == symsconst)
return (make_expr(TYPADDR, EX_STRING, sy_p->sy_value.syv_stringno, 0));
else if (sy_p->sy_type != symreg)
error("Wrong type of identifier %s", name);
return (regno_expr(sy_p->sy_value.syv_regno));
}
expr_t subreg_expr(tokarg,subreg) {
expr_t subreg_expr(int tokarg, int subreg)
{
expr_t result;
result.ex_typ = TYPREG;
subregset(l_sets[tokpatset[tokarg > 0 ? tokarg-1 : tokarg]].set_val,
subreg,result.ex_regset);
result.ex_index = ex_lookup(EX_SUBREG,tokarg,subreg);
return(result);
subregset(l_sets[tokpatset[tokarg > 0 ? tokarg - 1 : tokarg]].set_val,
subreg, result.ex_regset);
result.ex_index = ex_lookup(EX_SUBREG, tokarg, subreg);
return (result);
}
subregset(sp,subreg,regset) register short *sp; register short *regset; {
register i;
void subregset(register short *sp, int subreg, register short *regset)
{
register int i;
register reginfo *rp;
for (i=0;i<SZOFSET(MAXREGS);i++)
regset[i]=0;
for (i=1;i<nregs;i++) if (BIT(sp,i)) {
if(subreg) {
rp = &l_regs[i];
if (rp->ri_memb[subreg-1]==0)
error("Register %s in set has no member %d",
rp->ri_name,subreg);
BIS(regset,rp->ri_memb[subreg-1]);
} else
BIS(regset,i);
}
for(;i<nregs+MAXTOKENS;i++) if(BIT(sp,i))
error("Set contains %s, which is not a register",
l_tokens[i-nregs]->tk_name);
for (i = 0; i < SZOFSET(MAXREGS); i++)
regset[i] = 0;
for (i = 1; i < nregs; i++)
if (BIT(sp, i))
{
if (subreg)
{
rp = &l_regs[i];
if (rp->ri_memb[subreg - 1] == 0)
error("Register %s in set has no member %d", rp->ri_name,
subreg);
BIS(regset, rp->ri_memb[subreg - 1]);
}
else
BIS(regset, i);
}
for (; i < nregs + MAXTOKENS; i++)
if (BIT(sp, i))
error("Set contains %s, which is not a register",
l_tokens[i - nregs]->tk_name);
}
membset(setno,name,regset,appearance,restyp,typp)
char *name,*appearance;
short *regset;
int *typp;
int membset(int setno, char *name, short *regset, char *appearance, int restyp, int *typp)
{
register short *sp;
register token_p tp;
register i,j,k;
register int i, j, k;
int thistyp;
int typesdiffer=0;
int res_j= -1;
int typesdiffer = 0;
int res_j = -1;
if (setno < 0) return 0;
if (setno < 0)
return 0;
sp = l_sets[setno].set_val;
for (i=1;i<nregs;i++) if (BIT(sp,i)) {
error("Set in %s contains %s, which is not a token",
appearance,l_regs[i].ri_name);
break;
}
for (i=0;i<SZOFSET(MAXREGS);i++)
for (i = 1; i < nregs; i++)
if (BIT(sp, i))
{
error("Set in %s contains %s, which is not a token", appearance,
l_regs[i].ri_name);
break;
}
for (i = 0; i < SZOFSET(MAXREGS); i++)
regset[i] = 0;
for (i=nregs;i<nregs+MAXTOKENS;i++) if (BIT(sp,i)) {
tp = l_tokens[i-nregs];
for(j=0;j<MAXATT &&
(tp->tk_att[j].ta_type == -3 ||
strcmp(tp->tk_att[j].ta_name,name));j++)
;
if (j==MAXATT)
error("Token %s does not contain %s",tp->tk_name,name);
else if (j!=res_j && res_j != -1)
typesdiffer=1;
else {
res_j = j;
thistyp = tp->tk_att[j].ta_type;
if (thistyp== -2) {
if (restyp!=TYPADDR && restyp!=0)
typesdiffer=1;
for (i = nregs; i < nregs + MAXTOKENS; i++)
if (BIT(sp, i))
{
tp = l_tokens[i - nregs];
for (j = 0;
j < MAXATT
&& (tp->tk_att[j].ta_type == -3
|| strcmp(tp->tk_att[j].ta_name, name));
j++)
;
if (j == MAXATT)
error("Token %s does not contain %s", tp->tk_name, name);
else if (j != res_j && res_j != -1)
typesdiffer = 1;
else
{
res_j = j;
thistyp = tp->tk_att[j].ta_type;
if (thistyp == -2)
{
if (restyp != TYPADDR && restyp != 0)
typesdiffer = 1;
else
restyp = TYPADDR;
}
else if (thistyp == -1)
{
if (restyp != TYPINT && restyp != 0)
typesdiffer = 1;
else
restyp = TYPINT;
}
else
restyp=TYPADDR;
} else if (thistyp== -1) {
if (restyp!=TYPINT && restyp!=0)
typesdiffer=1;
else
restyp=TYPINT;
} else {
if (restyp!=TYPREG && restyp!=0)
typesdiffer=1;
else {
restyp=TYPREG;
for(k=0;k<SZOFSET(MAXREGS);k++)
regset[k] |=
l_props[tp->tk_att[j].ta_type].pr_regset[k];
{
if (restyp != TYPREG && restyp != 0)
typesdiffer = 1;
else
{
restyp = TYPREG;
for (k = 0; k < SZOFSET(MAXREGS); k++)
regset[k] |=
l_props[tp->tk_att[j].ta_type].pr_regset[k];
}
}
}
}
}
if (typesdiffer)
error("%s is not a valid expression; types differ in the set",
appearance);
*typp = restyp==0 ? TYPINT : restyp;
return(res_j == -1 ? 0 : res_j);
appearance);
*typp = restyp == 0 ? TYPINT : restyp;
return (res_j == -1 ? 0 : res_j);
}
expr_t memb_expr(setno,name,appearance,tokarg) char *name,*appearance; {
expr_t memb_expr(int setno, char *name, char *appearance, int tokarg)
{
expr_t result;
int res_j;
res_j = membset(setno,name,result.ex_regset,appearance,0,&result.ex_typ);
result.ex_index = ex_lookup(EX_TOKFIELD,tokarg,res_j+1);
return(result);
res_j = membset(setno, name, result.ex_regset, appearance, 0,
&result.ex_typ);
result.ex_index = ex_lookup(EX_TOKFIELD, tokarg, res_j + 1);
return (result);
}
expr_t tokm_expr(tokarg,name) char *name; {
expr_t tokm_expr(int tokarg, char *name)
{
char app[100];
int tokarg1 = tokarg > 0 ? tokarg : 1;
sprintf(app,"%%%d.%s",tokarg1,name);
return(memb_expr(tokpatset[tokarg1-1],name,app,tokarg));
sprintf(app, "%%%d.%s", tokarg1, name);
return (memb_expr(tokpatset[tokarg1 - 1], name, app, tokarg));
}
expr_t perc_ident_expr(name) char *name; {
expr_t perc_ident_expr(char *name)
{
char app[100];
sprintf(app,"%%%s",name);
return(memb_expr(cursetno,name,app,0));
sprintf(app, "%%%s", name);
return (memb_expr(cursetno, name, app, 0));
}
expr_t all_expr(all_no,subreg) {
expr_t all_expr(int all_no, int subreg)
{
set_t localset;
register i;
register int i;
register short *sp;
expr_t result;
sp = l_props[allreg[all_no]].pr_regset;
for (i=0;i<SETSIZE;i++)
localset.set_val[i] = i<SZOFSET(MAXREGS) ? sp[i] : 0;
subregset(localset.set_val,subreg,result.ex_regset);
for (i = 0; i < SETSIZE; i++)
localset.set_val[i] = i < SZOFSET(MAXREGS) ? sp[i] : 0;
subregset(localset.set_val, subreg, result.ex_regset);
result.ex_typ = TYPREG;
result.ex_index = ex_lookup(EX_ALLREG,all_no+1,subreg);
return(result);
result.ex_index = ex_lookup(EX_ALLREG, all_no + 1, subreg);
return (result);
}
eq2expr(e1,e2) expr_t e1,e2; {
int eq2expr(expr_t e1, expr_t e2)
{
if (e1.ex_typ != e2.ex_typ)
error("Expressions around == should have equal type");
switch (e1.ex_typ) {
default: assert(0);
case TYPBOOL:
error("== on booleans not implemented");
case TYPINT:
return(EX_NCPEQ);
case TYPADDR:
return(EX_SCPEQ);
case TYPREG:
return(EX_RCPEQ);
switch (e1.ex_typ)
{
default:
assert(0);
case TYPBOOL:
error("== on booleans not implemented");
case TYPINT:
return (EX_NCPEQ);
case TYPADDR:
return (EX_SCPEQ);
case TYPREG:
return (EX_RCPEQ);
}
}
ne2expr(e1,e2) expr_t e1,e2; {
int ne2expr(expr_t e1, expr_t e2)
{
if (e1.ex_typ != e2.ex_typ)
error("Expressions around != should have equal type");
switch (e1.ex_typ) {
default: assert(0);
case TYPBOOL:
error("!= on booleans not implemented");
case TYPINT:
return(EX_NCPNE);
case TYPADDR:
return(EX_SCPNE);
case TYPREG:
return(EX_RCPNE);
switch (e1.ex_typ)
{
default:
assert(0);
case TYPBOOL:
error("!= on booleans not implemented");
case TYPINT:
return (EX_NCPNE);
case TYPADDR:
return (EX_SCPNE);
case TYPREG:
return (EX_RCPNE);
}
}
expr_t sum_expr(e1,e2) expr_t e1,e2; {
int operator,op1,op2;
expr_t sum_expr(expr_t e1, expr_t e2)
{
int operator, op1, op2;
expr_t result;
operator = EX_CAT; op1 = e1.ex_index; op2 = e2.ex_index;
if (e1.ex_typ==e2.ex_typ) {
operator = EX_CAT;
op1 = e1.ex_index;
op2 = e2.ex_index;
if (e1.ex_typ == e2.ex_typ)
{
result.ex_typ = e1.ex_typ;
if (e1.ex_typ == TYPINT)
operator = EX_PLUS;
else if (e1.ex_typ != TYPADDR)
error("+ is not implemented on this type");
} else {
}
else
{
result.ex_typ = TYPADDR;
if (e1.ex_typ != TYPADDR) {
if (e1.ex_typ!=TYPINT)
if (e1.ex_typ != TYPADDR)
{
if (e1.ex_typ != TYPINT)
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!=TYPINT)
if (e2.ex_typ != TYPADDR)
{
if (e2.ex_typ != TYPINT)
error("Wrong right operand of +");
op2 = ex_lookup(EX_TOSTRING,op2,0);
op2 = ex_lookup(EX_TOSTRING, op2, 0);
}
}
result.ex_index=ex_lookup(operator,op1,op2);
return(result);
result.ex_index = ex_lookup(operator, op1, op2);
return (result);
}
expr_t iextoaddr(e) expr_t e; {
expr_t iextoaddr(expr_t e)
{
expr_t result;
result.ex_typ = TYPADDR;
result.ex_index = ex_lookup(EX_TOSTRING,e.ex_index,0);
return(result);
result.ex_index = ex_lookup(EX_TOSTRING, e.ex_index, 0);
return (result);
}
expr_t regvar_expr(e,regtyp,regsiz) expr_t e; {
expr_t regvar_expr(expr_t e, int regtyp, int regsiz)
{
expr_t result;
int i, regno, s, two_sizes;
two_sizes = (regtyp == reg_float && reglap != 0);
if (regsiz == -1) {
if (regsiz == -1)
{
/* reglap: Can't guess between 2 sizes of reg_float. */
if (two_sizes && regsiz == -1)
error("Must use regvar_w() or regvar_d()");
@ -288,36 +333,40 @@ expr_t regvar_expr(e,regtyp,regsiz) expr_t e; {
regsiz = rvsize[regtyp];
}
result = make_expr(TYPREG,EX_REGVAR,i_expr(e),regsiz);
for(i=0;i<SZOFSET(MAXREGS);i++)
result.ex_regset[i]=0;
result = make_expr(TYPREG, EX_REGVAR, i_expr(e), regsiz);
for (i = 0; i < SZOFSET(MAXREGS); i++)
result.ex_regset[i] = 0;
/* s = the size of the registers in rvnumbers[regtyp] */
s = two_sizes ? reglap : rvsize[regtyp];
if (s == regsiz) {
for(i=0;i<nregvar[regtyp];i++)
BIS(result.ex_regset,rvnumbers[regtyp][i]);
if (s == regsiz)
{
for (i = 0; i < nregvar[regtyp]; i++)
BIS(result.ex_regset, rvnumbers[regtyp][i]);
}
/* reglap: Also check the 2nd size of reg_float. */
if (two_sizes && rvsize[regtyp] == regsiz) {
for(i=0;i<nregvar[regtyp];i++) {
if (two_sizes && rvsize[regtyp] == regsiz)
{
for (i = 0; i < nregvar[regtyp]; i++)
{
/* regno = first subregister */
regno = l_regs[rvnumbers[regtyp][i]].ri_memb[0];
if (regno != 0)
BIS(result.ex_regset, regno);
}
}
return(result);
return (result);
}
/*
* Node table lookup part
*/
node_t nodes[MAXNODES];
int nnodes=0;
int nnodes = 0;
initnodes() {
void initnodes(void)
{
nodes[0].ex_operator = EX_CON;
nodes[0].ex_lnode = 0;
@ -325,21 +374,23 @@ initnodes() {
nnodes++;
}
ex_lookup(operator,lnode,rnode) {
int ex_lookup(int operator, int lnode, int rnode)
{
register node_p p;
for(p=nodes+1;p< &nodes[nnodes];p++) {
for (p = nodes + 1; p < &nodes[nnodes]; p++)
{
if (p->ex_operator != operator)
continue;
if (p->ex_lnode != lnode)
continue;
if (p->ex_rnode != rnode)
continue;
return(p-nodes);
return (p - nodes);
}
NEXT(nnodes,MAXNODES,"Node");
NEXT(nnodes, MAXNODES, "Node");
p->ex_operator = operator;
p->ex_lnode = lnode;
p->ex_rnode = rnode;
return(p-nodes);
return (p - nodes);
}

View file

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

View file

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

View file

@ -3,18 +3,19 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <assert.h>
#include "param.h"
#include "set.h"
#include "extern.h"
#include "hall.h"
#include <stdio.h>
/*
* This file implements the marriage thesis from Hall.
* The thesis says that given a number, say N, of subsets from
* The thesis says that givoid hallverbose(void)ven a number, say N, of subsets from
* a finite set, it is possible to create a set with cardinality N,
* that contains one member for each of the subsets,
* iff for each number, say M, of subsets from 2 to N the union of
@ -29,56 +30,66 @@ static char rcsid[]= "$Id$";
#define MAXHALL (TOKPATMAX+MAXALLREG)
short hallsets[MAXHALL][SETSIZE];
int nhallsets= -1;
int nhallsets = -1;
int hallfreq[MAXHALL][2];
hallverbose() {
register i;
register max;
fprintf(stderr,"Table of hall frequencies\n # pre post\n");
for (max=MAXHALL-1;hallfreq[max][0]==0 && hallfreq[max][1]==0;max--)
int recurhall(int, short [][SETSIZE]);
void unite(register short *, short *);
void hallverbose(void)
{
register int i;
register int max;
fprintf(stderr, "Table of hall frequencies\n # pre post\n");
for (max = MAXHALL - 1; hallfreq[max][0] == 0 && hallfreq[max][1] == 0;
max--)
;
for (i=0;i<=max;i++)
fprintf(stderr,"%3d%6d%6d\n",i,hallfreq[i][0],hallfreq[i][1]);
for (i = 0; i <= max; i++)
fprintf(stderr, "%3d%6d%6d\n", i, hallfreq[i][0], hallfreq[i][1]);
}
inithall() {
void inithall(void)
{
assert(nhallsets == -1);
nhallsets=0;
nhallsets = 0;
}
nexthall(sp) register short *sp; {
register i;
assert(nhallsets>=0);
for(i=0;i<SETSIZE;i++)
void nexthall(register short *sp)
{
register int i;
assert(nhallsets >= 0);
for (i = 0; i < SETSIZE; i++)
hallsets[nhallsets][i] = sp[i];
nhallsets++;
}
card(sp) register short *sp; {
register sum,i;
sum=0;
for(i=0;i<8*sizeof(short)*SETSIZE;i++)
if (BIT(sp,i))
int card(register short *sp)
{
register int sum, i;
sum = 0;
for (i = 0; i < 8 * sizeof(short) * SETSIZE; i++)
if (BIT(sp, i))
sum++;
return(sum);
return (sum);
}
checkhall() {
assert(nhallsets>=0);
void checkhall(void)
{
assert(nhallsets >= 0);
if (!hall())
error("Hall says: \"You can't have those registers\"");
}
hall() {
register i,j,k;
int hall(void)
{
register int i, j, k;
int ok;
hallfreq[nhallsets][0]++;
/*
* If a set has cardinality >= nhallsets it can never be the cause
@ -86,66 +97,72 @@ hall() {
* But then nhallsets is less, so this step can be re-applied.
*/
do {
do
{
ok = 0;
for(i=0;i<nhallsets;i++)
if (card(hallsets[i])>=nhallsets) {
for (j=i+1;j<nhallsets;j++)
for(k=0;k<SETSIZE;k++)
hallsets[j-1][k] =
hallsets[j][k];
for (i = 0; i < nhallsets; i++)
if (card(hallsets[i]) >= nhallsets)
{
for (j = i + 1; j < nhallsets; j++)
for (k = 0; k < SETSIZE; k++)
hallsets[j - 1][k] = hallsets[j][k];
nhallsets--;
ok = 1;
break;
}
} while (ok);
/*
* Now all sets have cardinality < nhallsets
*/
hallfreq[nhallsets][1]++;
ok=recurhall(nhallsets,hallsets);
ok = recurhall(nhallsets, hallsets);
nhallsets = -1;
return(ok);
return (ok);
}
recurhall(nhallsets,hallsets) short hallsets[][SETSIZE]; {
int recurhall(int nhallsets, short hallsets[][SETSIZE])
{
short copysets[MAXHALL][SETSIZE];
short setsum[SETSIZE];
register i,j,k,ncopys;
register int i, j, k, ncopys;
/*
* First check cardinality of union of all
*/
for(k=0;k<SETSIZE;k++)
setsum[k]=0;
for(i=0;i<nhallsets;i++)
unite(hallsets[i],setsum);
if (card(setsum)<nhallsets)
return(0);
for (k = 0; k < SETSIZE; k++)
setsum[k] = 0;
for (i = 0; i < nhallsets; i++)
unite(hallsets[i], setsum);
if (card(setsum) < nhallsets)
return (0);
/*
* Now check the hall property of everything but one set,
* for all sets
*/
for(i=0;i<nhallsets;i++) {
ncopys=0;
for(j=0;j<nhallsets;j++) if (j!=i) {
for(k=0;k<SETSIZE;k++)
copysets[ncopys][k] = hallsets[j][k];
ncopys++;
}
assert(ncopys == nhallsets-1);
if (!recurhall(ncopys,copysets))
return(0);
for (i = 0; i < nhallsets; i++)
{
ncopys = 0;
for (j = 0; j < nhallsets; j++)
if (j != i)
{
for (k = 0; k < SETSIZE; k++)
copysets[ncopys][k] = hallsets[j][k];
ncopys++;
}
assert(ncopys == nhallsets - 1);
if (!recurhall(ncopys, copysets))
return (0);
}
return(1);
return (1);
}
unite(sp,into) register short *sp,*into; {
register i;
for(i=0;i<SETSIZE;i++)
void unite(register short *sp, short *into)
{
register int i;
for (i = 0; i < SETSIZE; i++)
into[i] |= sp[i];
}

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

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

View file

@ -3,7 +3,7 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <string.h>
@ -14,192 +14,198 @@ static char rcsid[]= "$Id$";
#include "set.h"
#include "expr.h"
#include "iocc.h"
#include "subr.h"
#include <cgg_cg.h>
#include "extern.h"
extern int niops;
extern iocc_t iops[];
extern inproc;
extern int inproc;
extern set_t l_sets[];
extern inst_t l_instances[];
extern expr_t subreg_expr(),regno_expr();
extern expr_t subreg_expr(), regno_expr();
struct varinfo * setcoco(n) {
static struct varinfo * setcoco(int n)
{
struct varinfo *vi;
NEW(vi,struct varinfo);
NEW(vi, struct varinfo);
vi->vi_next = VI_NULL;
vi->vi_int[0] = INSSETCC;
vi->vi_int[1] = n;
return(vi);
return (vi);
}
struct varinfo * generase(n) {
static struct varinfo * generase(int n)
{
struct varinfo *vi;
NEW(vi,struct varinfo);
NEW(vi, struct varinfo);
vi->vi_next = VI_NULL;
vi->vi_int[0] = INSERASE;
vi->vi_int[1] = n;
return(vi);
return (vi);
}
struct varinfo * genremove(n) {
static struct varinfo * genremove(int n)
{
struct varinfo *vi;
NEW(vi,struct varinfo);
NEW(vi, struct varinfo);
vi->vi_next = VI_NULL;
vi->vi_int[0] = INSREMOVE;
vi->vi_int[1] = n;
return(vi);
return (vi);
}
onlyreg(argno) {
register bitno;
static int onlyreg(int argno)
{
register int bitno;
register short *sp;
if (! argno) argno++;
sp = l_sets[tokpatset[argno-1]].set_val;
for(bitno=nregs;bitno<nregs+ntokens;bitno++)
if (BIT(sp,bitno))
return(0);
return(1);
if (!argno)
argno++;
sp = l_sets[tokpatset[argno - 1]].set_val;
for (bitno = nregs; bitno < nregs + ntokens; bitno++)
if (BIT(sp, bitno))
return (0);
return (1);
}
makescratch(argno) {
static void makescratch(int argno)
{
set_t s;
if (! argno) argno++;
if (tokpatro[argno-1])
error("Instruction destroys %%%d, not allowed here",argno);
s = l_sets[tokpatset[argno-1]];
BIC(s.set_val,0);
tokpatset[argno-1] = setlookup(s);
if (!argno)
argno++;
if (tokpatro[argno - 1])
error("Instruction destroys %%%d, not allowed here", argno);
s = l_sets[tokpatset[argno - 1]];
BIC(s.set_val, 0);
tokpatset[argno - 1] = setlookup(s);
}
struct varinfo *gen_inst(ident,star) char *ident; {
register struct varinfo *vi,*retval,*eravi;
struct varinfo *gen_inst(char *ident, int star)
{
register struct varinfo *vi, *retval, *eravi;
register instr_p ip;
register struct operand *op;
register i;
register int i;
register inst_p insta;
if (star && !inproc)
error("Variable instruction only allowed inside proc");
for (ip=l_instr;ip<l_instr+ninstr;ip++) {
if(strcmp(ident,ip->i_name))
for (ip = l_instr; ip < l_instr + ninstr; ip++)
{
if (strcmp(ident, ip->i_name))
continue;
if (ip->i_nops!=niops)
if (ip->i_nops != niops)
continue;
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))
for (i = 0, op = ip->i_oplist; i < niops; i++, op = op->o_next)
{
if (!subset(iops[i].in_set, l_sets[op->o_setno].set_val, SETSIZE))
goto cont;
}
goto found; /* oh well, one more won't hurt */
cont:;
goto found;
/* oh well, one more won't hurt */
cont: ;
}
error("Such an \"%s\" does not exist",ident);
return(0);
found:
NEW(vi,struct varinfo);
vi->vi_int[0] = ip-l_instr;
error("Such an \"%s\" does not exist", ident);
return (0);
found:
NEW(vi, struct varinfo);
vi->vi_int[0] = ip - l_instr;
vi->vi_int[1] = star;
vi->vi_next=0;
vi->vi_next = 0;
retval = vi;
for(i=0;i<niops;i++) {
NEW(vi->vi_vi,struct varinfo);
vi=vi->vi_vi;
for (i = 0; i < niops; i++)
{
NEW(vi->vi_vi, struct varinfo);
vi = vi->vi_vi;
vi->vi_int[0] = iops[i].in_index;
}
vi->vi_vi = 0;
vi = retval;
for(i=0,op=ip->i_oplist;i<niops;i++,op=op->o_next) {
if(op->o_adorn&AD_CC) {
vi->vi_next = setcoco(iops[i].in_index);
vi=vi->vi_next;
}
switch(op->o_adorn&AD_RWMASK) {
default:
/* Nothing possible to do */
break;
case AD_RO:
/* It might be possible to do something
* here but not now.
*/
break;
case AD_RW:
case AD_WO:
/* Treated the same for now */
insta = &l_instances[iops[i].in_index];
switch(insta->in_which) {
case IN_COPY:
if(insta->in_info[1]==0 && !onlyreg(insta->in_info[0]))
break;
makescratch(insta->in_info[0]);
vi->vi_next = generase(
ex_lookup(
EX_SUBREG,insta->in_info[0],
insta->in_info[1]
)
);
for (i = 0, op = ip->i_oplist; i < niops; i++, op = op->o_next)
{
if (op->o_adorn & AD_CC)
{
vi->vi_next = setcoco(iops[i].in_index);
vi = vi->vi_next;
break;
case IN_MEMB:
vi->vi_next = generase(
ex_lookup(
EX_TOKFIELD,insta->in_info[0],
insta->in_info[1]
)
);
vi=vi->vi_next;
break;
case IN_RIDENT:
vi->vi_next = generase(
ex_lookup(
EX_REG,insta->in_info[0],0
)
);
vi = vi->vi_next;
break;
case IN_ALLOC:
vi->vi_next = generase(
ex_lookup(
EX_ALLREG,insta->in_info[0]+1,
insta->in_info[1]
)
);
vi = vi->vi_next;
break;
case IN_S_DESCR:
case IN_D_DESCR:
{ int temp;
if (insta->in_which == IN_S_DESCR)
temp = wordsize;
else
temp = 2 * wordsize;
temp=ex_lookup(EX_REGVAR,insta->in_info[1],temp);
vi->vi_next = generase(temp);
vi = vi->vi_next;
vi->vi_next = genremove(temp);
vi = vi->vi_next;
break;
}
}
break;
}
switch (op->o_adorn & AD_RWMASK)
{
default:
/* Nothing possible to do */
break;
case AD_RO:
/* It might be possible to do something
* here but not now.
*/
break;
case AD_RW:
case AD_WO:
/* Treated the same for now */
insta = &l_instances[iops[i].in_index];
switch (insta->in_which)
{
case IN_COPY:
if (insta->in_info[1] == 0
&& !onlyreg(insta->in_info[0]))
break;
makescratch(insta->in_info[0]);
vi->vi_next = generase(ex_lookup(
EX_SUBREG, insta->in_info[0], insta->in_info[1]));
vi = vi->vi_next;
break;
case IN_MEMB:
vi->vi_next = generase(ex_lookup(
EX_TOKFIELD, insta->in_info[0], insta->in_info[1]));
vi = vi->vi_next;
break;
case IN_RIDENT:
vi->vi_next = generase(ex_lookup(
EX_REG, insta->in_info[0], 0));
vi = vi->vi_next;
break;
case IN_ALLOC:
vi->vi_next = generase(ex_lookup(
EX_ALLREG, insta->in_info[0] + 1, insta->in_info[1]));
vi = vi->vi_next;
break;
case IN_S_DESCR:
case IN_D_DESCR:
{
int temp;
if (insta->in_which == IN_S_DESCR)
temp = wordsize;
else
temp = 2 * wordsize;
temp = ex_lookup(EX_REGVAR, insta->in_info[1], temp);
vi->vi_next = generase(temp);
vi = vi->vi_next;
vi->vi_next = genremove(temp);
vi = vi->vi_next;
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)
vi->vi_next = setcoco(0);
else {
else
{
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->vi_next;
vi = vi->vi_next;
}
return(retval);
return (retval);
}

View file

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

View file

@ -3,7 +3,7 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <assert.h>
@ -14,6 +14,7 @@ static char rcsid[]= "$Id$";
#include "set.h"
#include "expr.h"
#include "lookup.h"
#include "subr.h"
#include "token.h"
#include "property.h"
#include "iocc.h"
@ -28,184 +29,204 @@ expr_t arexp[MAXATT];
expr_t iextoaddr();
iocc_t subr_iocc(tokarg,subreg) {
/* Forward declarations */
static int instalookup(inst_t, int);
iocc_t subr_iocc(int tokarg, int subreg)
{
inst_t insta;
iocc_t result;
register i;
iocc_t result;
register int i;
insta.in_which = IN_COPY;
insta.in_info[0] = tokarg;
insta.in_info[1] = subreg;
result.in_index = instalookup(insta,2);
if (tokarg < 1) tokarg = 1;
if (subreg==0)
for (i=0;i<SETSIZE;i++)
result.in_set[i] = l_sets[tokpatset[tokarg-1]].set_val[i];
else {
for (i=0;i<SETSIZE;i++)
result.in_index = instalookup(insta, 2);
if (tokarg < 1)
tokarg = 1;
if (subreg == 0)
for (i = 0; i < SETSIZE; i++)
result.in_set[i] = l_sets[tokpatset[tokarg - 1]].set_val[i];
else
{
for (i = 0; i < SETSIZE; i++)
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);
}
return(result);
return (result);
}
iocc_t tokm_iocc(tokarg,ident) char *ident; {
iocc_t tokm_iocc(int tokarg, char *ident)
{
iocc_t result;
inst_t insta;
register i;
register int i;
char app[100];
int dummy;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0;
insta.in_which = IN_MEMB;
insta.in_info[0] = tokarg;
if (tokarg < 1) tokarg = 1;
sprintf(app,"%%%d.%s",tokarg,ident);
insta.in_info[1] = 1+membset(tokpatset[tokarg-1],ident,result.in_set,
app,TYPREG,&dummy);
result.in_index = instalookup(insta,2);
return(result);
if (tokarg < 1)
tokarg = 1;
sprintf(app, "%%%d.%s", tokarg, ident);
insta.in_info[1] = 1
+ membset(tokpatset[tokarg - 1], ident, result.in_set, app, TYPREG,
&dummy);
result.in_index = instalookup(insta, 2);
return (result);
}
iocc_t percident_iocc(ident) char *ident; {
iocc_t percident_iocc(char *ident)
{
iocc_t result;
inst_t insta;
register i;
register int i;
char app[100];
int dummy;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0;
insta.in_which = IN_MEMB;
insta.in_info[0] = 0;
sprintf(app,"%%%s",ident);
insta.in_info[1] = 1+membset(cursetno,ident,result.in_set,
app,TYPREG,&dummy);
result.in_index = instalookup(insta,2);
return(result);
sprintf(app, "%%%s", ident);
insta.in_info[1] = 1
+ membset(cursetno, ident, result.in_set, app, TYPREG, &dummy);
result.in_index = instalookup(insta, 2);
return (result);
}
iocc_t ident_iocc(ident) char *ident; {
iocc_t ident_iocc(char *ident)
{
iocc_t result;
inst_t insta;
register i;
register int i;
register symbol *sy_p;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0;
insta.in_which = IN_RIDENT;
sy_p = lookup(ident,symreg,mustexist);
sy_p = lookup(ident, symreg, mustexist);
insta.in_info[0] = sy_p->sy_value.syv_regno;
result.in_index = instalookup(insta,1);
BIS(result.in_set,sy_p->sy_value.syv_regno);
return(result);
result.in_index = instalookup(insta, 1);
BIS(result.in_set, sy_p->sy_value.syv_regno);
return (result);
}
iocc_t all_iocc(all_no,subreg) {
iocc_t all_iocc(int all_no, int subreg)
{
iocc_t result;
inst_t insta;
register i;
register int i;
set_t localset;
register short *sp;
sp = l_props[allreg[all_no]].pr_regset;
for (i=0;i<SETSIZE;i++)
localset.set_val[i] = i<SZOFSET(MAXREGS) ? sp[i] : 0;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; i++)
localset.set_val[i] = i < SZOFSET(MAXREGS) ? sp[i] : 0;
for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0;
insta.in_which = IN_ALLOC;
insta.in_info[0] = all_no;
insta.in_info[1] = subreg;
subregset(localset.set_val,subreg,result.in_set);
result.in_index = instalookup(insta,2);
return(result);
subregset(localset.set_val, subreg, result.in_set);
result.in_index = instalookup(insta, 2);
return (result);
}
iocc_t descr_iocc(ident) char *ident; {
iocc_t descr_iocc(char *ident)
{
iocc_t result;
inst_t insta;
register symbol *sy_p;
register token_p tp;
register i;
register int i;
int typerr;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0;
sy_p = lookup(ident,symtok,mustexist);
sy_p = lookup(ident, symtok, mustexist);
tp = l_tokens[sy_p->sy_value.syv_tokno];
BIS(result.in_set,sy_p->sy_value.syv_tokno+nregs);
BIS(result.in_set, sy_p->sy_value.syv_tokno + nregs);
insta.in_which = IN_DESCR;
if (rvused&SL_REGVAR && strcmp(ident,"LOCAL")==0)
if (rvused & SL_REGVAR && strcmp(ident, "LOCAL") == 0)
insta.in_which = IN_S_DESCR;
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_info[0] = sy_p->sy_value.syv_tokno;
for (i=0;i<MAXATT;i++) {
if (tp->tk_att[i].ta_type == -3) {
if (narexpr>i)
error("token %s initialized with too many attributes",ident);
for (i = 0; i < MAXATT; i++)
{
if (tp->tk_att[i].ta_type == -3)
{
if (narexpr > i)
error("token %s initialized with too many attributes", ident);
break;
}
if (i>= narexpr) {
error("token %s initialized with too few attributes",
ident);
if (i >= narexpr)
{
error("token %s initialized with too few attributes", ident);
break;
}
typerr = 0;
switch(arexp[i].ex_typ) {
default: assert(0);
case TYPINT:
if (tp->tk_att[i].ta_type != -1)
if (tp->tk_att[i].ta_type == -2)
arexp[i] = iextoaddr(arexp[i]);
else
switch (arexp[i].ex_typ)
{
default:
assert(0);
case TYPINT:
if (tp->tk_att[i].ta_type != -1)
if (tp->tk_att[i].ta_type == -2)
arexp[i] = iextoaddr(arexp[i]);
else
typerr++;
break;
case TYPBOOL:
typerr++;
break;
case TYPADDR:
if (tp->tk_att[i].ta_type != -2)
typerr++;
break;
case TYPBOOL:
typerr++; break;
case TYPADDR:
if (tp->tk_att[i].ta_type != -2)
typerr++;
break;
case TYPREG:
if (tp->tk_att[i].ta_type<0)
typerr++;
else if (!subset(arexp[i].ex_regset,
l_props[tp->tk_att[i].ta_type].pr_regset,
SZOFSET(MAXREGS)))
typerr++;
break;
break;
case TYPREG:
if (tp->tk_att[i].ta_type < 0)
typerr++;
else if (!subset(arexp[i].ex_regset,
l_props[tp->tk_att[i].ta_type].pr_regset,
SZOFSET(MAXREGS)))
typerr++;
break;
}
if (typerr)
error("Attribute %s.%s given wrong type of value",
ident,tp->tk_att[i].ta_name);
insta.in_info[i+1] = arexp[i].ex_index;
error("Attribute %s.%s given wrong type of value", ident,
tp->tk_att[i].ta_name);
insta.in_info[i + 1] = arexp[i].ex_index;
}
result.in_index = instalookup(insta,i+1);
return(result);
result.in_index = instalookup(insta, i + 1);
return (result);
}
/* low level instance package */
int ninstances=1;
int ninstances = 1;
inst_t l_instances[MAXINSTANCES];
instalookup(insta,filled) inst_t insta; {
register i,j;
static int instalookup(inst_t insta, int filled)
{
register int i, j;
for (j=filled;j<=MAXATT;j++)
for (j = filled; j <= MAXATT; j++)
insta.in_info[j] = 0;
for (i=0;i<ninstances;i++) {
for (i = 0; i < ninstances; i++)
{
if (insta.in_which != l_instances[i].in_which)
continue;
for(j=0;j<=MAXATT;j++)
if (insta.in_info[j]!= l_instances[i].in_info[j])
for (j = 0; j <= MAXATT; j++)
if (insta.in_info[j] != l_instances[i].in_info[j])
goto cont;
return(i);
cont:;
return (i);
cont: ;
}
NEXT(ninstances,MAXINSTANCES,"Instances");
NEXT(ninstances, MAXINSTANCES, "Instances");
l_instances[i] = insta;
return(i);
return (i);
}

View file

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

View file

@ -3,7 +3,7 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <assert.h>
@ -11,61 +11,66 @@ static char rcsid[]= "$Id$";
#include "param.h"
#include "lookup.h"
#include "extern.h"
#include "subr.h"
char *myalloc();
char *mystrcpy();
;
symbol dumsym; /* dummy to return in case of error */
symbol dumsym; /* dummy to return in case of error */
symbol *lookup(name,type,style)
char *name;
symtype type;
lookupstyle style;
/* Forward declarations */
static int hashvalue(register char *);
symbol *lookup(char *name, symtype type, lookupstyle style)
{
symbol *sy_p,**sy_pp;
symbol *sy_p, **sy_pp;
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)
for (sy_pp = &symhash[hashvalue(name)]; (sy_p = *sy_pp) != 0;
sy_pp = &sy_p->sy_next)
{
if (strcmp(sy_p->sy_name, name) != 0)
continue;
switch(style) {
switch (style)
{
default:
assert(0);
case justlooking:
case mustexist:
case makeexist:
if (type == symany || type == sy_p->sy_type)
return (sy_p);
continue;
case newsymbol:
error("%s already defined", name);
return (&dumsym);
}
}
switch (style)
{
default:
assert(0);
case justlooking:
return ((symbol *) 0);
case mustexist:
case makeexist:
if (type==symany || type==sy_p->sy_type)
return(sy_p);
continue;
fatal("%s is unknown symbol", name);
/* NOTREACHED */
case newsymbol:
error("%s already defined",name);
return(&dumsym);
}
}
switch(style) {
default:
assert(0);
case justlooking:
return((symbol *) 0);
case mustexist:
fatal("%s is unknown symbol",name);
/* NOTREACHED */
case newsymbol:
case makeexist:
NEW(sy_p,symbol);
sy_p->sy_next = 0;
sy_p->sy_name = mystrcpy(name);
assert(type!=symany);
sy_p->sy_type = type;
*sy_pp = sy_p;
return(sy_p);
case makeexist:
NEW(sy_p, symbol);
sy_p->sy_next = 0;
sy_p->sy_name = mystrcpy(name);
assert(type != symany);
sy_p->sy_type = type;
*sy_pp = sy_p;
return (sy_p);
}
}
hashvalue(s) register char *s; {
register unsigned sum=0;
register i;
static int hashvalue(register char *s)
{
register unsigned sum = 0;
register int i;
for(i=0;*s;s++,i=(i+3)&07)
sum += *s<<i;
return(sum%NSYMHASH);
for (i = 0; *s; s++, i = (i + 3) & 07)
sum += *s << i;
return (sum % NSYMHASH);
}

View file

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

View file

@ -3,60 +3,81 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <stdlib.h>
#include <stdio.h>
#include "param.h"
#include "hall.h"
#include "expr.h"
#include "extern.h"
char *filename;
main(argc,argv) char **argv; {
extern void enterkeyw(void);
extern void initio(void);
extern void initemhash(void);
extern void finishio(void);
extern void statistics(void);
extern int yyparse(void);
int main(int argc, char **argv)
{
extern int nerrors;
extern int code_in_c;
extern int tabledebug;
extern int verbose;
while (argc >1 && argv[1][0]=='-') {
switch(argv[1][1]) {
case 'c':
code_in_c = 0;
break;
case 'd':
tabledebug++;
break;
case 'v':
verbose++;
break;
default:
error("Unknown flag -%c",argv[1][1]);
while (argc > 1 && argv[1][0] == '-')
{
switch (argv[1][1])
{
case 'c':
code_in_c = 0;
break;
case 'd':
tabledebug++;
break;
case 'v':
verbose++;
break;
default:
error("Unknown flag -%c", argv[1][1]);
}
argc--; argv++;
argc--;
argv++;
}
if (argc==2) {
if (freopen(argv[1],"r",stdin)==NULL) {
error("Can't open %s",argv[1]);
if (argc == 2)
{
if (freopen(argv[1], "r", stdin) == NULL)
{
error("Can't open %s", argv[1]);
exit(-1);
}
filename = argv[1];
}
else if (argc == 1) {
else if (argc == 1)
{
filename = "";
} else
error("Usage: %s [-c] [-d] [-v] [table]",argv[0]);
}
else
error("Usage: %s [-c] [-d] [-v] [table]", argv[0]);
initemhash();
enterkeyw();
initnodes();
initio();
yyparse();
if (nerrors==0) {
if (nerrors == 0)
{
finishio();
statistics();
if (verbose)
hallverbose();
} else {
}
else
{
errorexit();
}
exit(nerrors==0 ? 0 : -1);
exit(nerrors == 0 ? 0 : -1);
}

File diff suppressed because it is too large Load diff

View file

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

View file

@ -3,7 +3,7 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include "param.h"
@ -12,143 +12,161 @@ static char rcsid[]= "$Id$";
#include "token.h"
#include "lookup.h"
#include "reg.h"
#include "subr.h"
#include <cgg_cg.h>
#include "extern.h"
extern set_t l_sets[];
setlookup(s) set_t s; {
register set_p p;
register i;
int setno;
for(p=l_sets;p<&l_sets[nsets];p++) {
if (p->set_size != s.set_size)
continue;
for (i=0;i<SETSIZE;i++)
if (p->set_val[i] != s.set_val[i])
goto cont;
return(p-l_sets);
cont:;
}
setno = NEXT(nsets,MAXSETS,"Sets");
l_sets[setno] = s;
return(setno);
}
make_std_sets() {
set_t s;
register i;
for(i=0;i<SETSIZE;i++)
s.set_val[i]=0;
for(i=0;i<nregs+ntokens;i++)
BIS(s.set_val,i);
s.set_size = 0;
allsetno = setlookup(s);
n_set("ALL",allsetno);
}
set_t emptyset;
set_t ident_to_set(name) char *name; {
int setlookup(set_t s)
{
register set_p p;
register int i;
int setno;
for (p = l_sets; p < &l_sets[nsets]; p++)
{
if (p->set_size != s.set_size)
continue;
for (i = 0; i < SETSIZE; i++)
if (p->set_val[i] != s.set_val[i])
goto cont;
return (p - l_sets);
cont: ;
}
setno = NEXT(nsets, MAXSETS, "Sets");
l_sets[setno] = s;
return (setno);
}
void make_std_sets(void)
{
set_t s;
register int i;
for (i = 0; i < SETSIZE; i++)
s.set_val[i] = 0;
for (i = 0; i < nregs + ntokens; i++)
BIS(s.set_val, i);
s.set_size = 0;
allsetno = setlookup(s);
n_set("ALL", allsetno);
}
set_t ident_to_set(char *name)
{
register symbol *sy_p;
register i;
register int i;
register struct propinfo *pp;
int bitno;
set_t result;
sy_p = lookup(name,symany,mustexist);
switch(sy_p->sy_type) {
default:
error("%s is wrong kind of symbol",name);
return(emptyset);
case symprop:
pp = &l_props[sy_p->sy_value.syv_propno];
result.set_size = pp->pr_size;
for (i=0;i<SZOFSET(MAXREGS);i++)
result.set_val[i] = pp->pr_regset[i];
BIS(result.set_val,0);
for (;i<SETSIZE;i++)
result.set_val[i] = 0;
break;
case symtok:
bitno = sy_p->sy_value.syv_tokno+nregs;
for (i=0;i<SETSIZE;i++)
result.set_val[i] = 0;
BIS(result.set_val,bitno);
result.set_size = l_tokens[sy_p->sy_value.syv_tokno]->tk_size;
break;
case symset:
return(l_sets[sy_p->sy_value.syv_setno]);
sy_p = lookup(name, symany, mustexist);
switch (sy_p->sy_type)
{
default:
error("%s is wrong kind of symbol", name);
return (emptyset);
case symprop:
pp = &l_props[sy_p->sy_value.syv_propno];
result.set_size = pp->pr_size;
for (i = 0; i < SZOFSET(MAXREGS); i++)
result.set_val[i] = pp->pr_regset[i];
BIS(result.set_val, 0);
for (; i < SETSIZE; i++)
result.set_val[i] = 0;
break;
case symtok:
bitno = sy_p->sy_value.syv_tokno + nregs;
for (i = 0; i < SETSIZE; i++)
result.set_val[i] = 0;
BIS(result.set_val, bitno);
result.set_size = l_tokens[sy_p->sy_value.syv_tokno]->tk_size;
break;
case symset:
return (l_sets[sy_p->sy_value.syv_setno]);
}
return(result);
return (result);
}
static void
checksize(s)
register set_p s;
static void checksize(register set_p s)
{
register int i;
register int size = -1;
s->set_size = 0;
for (i = 1; i <= nregs; i++) {
if (BIT(s->set_val, i)) {
for (i = 1; i <= nregs; i++)
{
if (BIT(s->set_val, i))
{
register int sz = l_regs[i].ri_size;
if (size == -1) size = sz;
else if (size != sz) return;
if (size == -1)
size = sz;
else if (size != sz)
return;
}
}
for (i = 1; i <= ntokens; i++) {
if (BIT(s->set_val, i+nregs)) {
for (i = 1; i <= ntokens; i++)
{
if (BIT(s->set_val, i + nregs))
{
register int sz = l_tokens[i]->tk_size;
if (size == -1) size = sz;
else if (size != sz) return;
if (size == -1)
size = sz;
else if (size != sz)
return;
}
}
if (size != -1) s->set_size = size;
if (size != -1)
s->set_size = size;
}
set_t setproduct(s1,s2) set_t s1,s2; {
set_t setproduct(set_t s1, set_t s2)
{
set_t result;
register i;
register int i;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; i++)
result.set_val[i] = s1.set_val[i] & s2.set_val[i];
checksize(&result);
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;
register i;
register int i;
if (s1.set_size == s2.set_size)
result.set_size = s1.set_size;
else
result.set_size = 0;
for(i=0;i<SETSIZE;i++)
for (i = 0; i < SETSIZE; i++)
result.set_val[i] = s1.set_val[i] | s2.set_val[i];
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;
register i;
register int i;
for(i=0;i<SETSIZE;i++)
result.set_val[i] = s1.set_val[i] & ~ s2.set_val[i];
for (i = 0; i < SETSIZE; i++)
result.set_val[i] = s1.set_val[i] & ~s2.set_val[i];
/* make sure that we don't loose the lowest bit of the set, which
indicates that it contains registers
*/
for (i=1;i <= nregs; i++) {
if (BIT(result.set_val, i)) {
BIS(result.set_val,0);
indicates that it contains registers
*/
for (i = 1; i <= nregs; i++)
{
if (BIT(result.set_val, i))
{
BIS(result.set_val, 0);
break;
}
}
checksize(&result);
return(result);
return (result);
}

View file

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

View file

@ -3,24 +3,25 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <string.h>
#include "param.h"
#include "subr.h"
#include "extern.h"
int nstrings=0;
int nstrings = 0;
char *l_strings[MAXSTRINGS];
strlookup(str) char *str; {
register i;
extern char *mystrcpy();
int strlookup(char *str)
{
register int i;
for(i=0;i<nstrings;i++)
if (strcmp(str,l_strings[i])==0)
return(i);
NEXT(nstrings,MAXSTRINGS,"String table");
for (i = 0; i < nstrings; i++)
if (strcmp(str, l_strings[i]) == 0)
return (i);
NEXT(nstrings, MAXSTRINGS, "String table");
l_strings[i] = mystrcpy(str);
return(i);
return (i);
}

View file

@ -3,7 +3,7 @@
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
#ifndef NORCSID
static char rcsid[]= "$Id$";
static char rcsid[] = "$Id$";
#endif
#include <stdlib.h>
@ -20,77 +20,86 @@ static char rcsid[]= "$Id$";
#include "regvar.h"
#include <cgg_cg.h>
#include <em_reg.h>
#include "subr.h"
#include "hall.h"
#include "extern.h"
n_proc(name) char *name; {
register symbol *sy_p;
extern int npatbytes;
extern int npatbytes;
extern set_t l_sets[];
sy_p = lookup(name,symproc,newsymbol);
void n_proc(char *name)
{
register symbol *sy_p;
sy_p = lookup(name, symproc, newsymbol);
sy_p->sy_value.syv_procoff = npatbytes + 1;
}
struct varinfo *
make_erase(name) char *name; {
expr_t e,ident_expr();
struct varinfo * make_erase(char *name)
{
expr_t e;
struct varinfo *result;
e = ident_expr(name);
if (e.ex_typ != TYPREG)
error("Register name required here");
NEW(result,struct varinfo);
NEW(result, struct varinfo);
result->vi_next = VI_NULL;
result->vi_int[0] = e.ex_index;
return(result);
return (result);
}
n_instr(name,asname,oplist,eraselist,cost)
char *name,*asname;
operand *oplist;
struct varinfo *eraselist,*cost;
void n_instr(char *name, char *asname, operand *oplist, struct varinfo *eraselist,
struct varinfo *cost)
{
register instrno;
register cc_count;
register int instrno;
register int cc_count;
register instr_p ip;
instrno = NEXT(ninstr,MAXINSTR,"Instructions");
instrno = NEXT(ninstr, MAXINSTR, "Instructions");
ip = &l_instr[instrno];
ip->i_name = name;
ip->i_asname = strlookup(asname!=0 ? asname : name);
ip->i_asname = strlookup(asname != 0 ? asname : name);
ip->i_nops = 0;
ip->i_oplist = oplist;
ip->i_erases = eraselist;
if (cost==0) {
if (cost == 0)
{
ip->i_cost.ct_space = 0;
ip->i_cost.ct_time = 0;
} else {
}
else
{
ip->i_cost.ct_space = cost->vi_int[0];
ip->i_cost.ct_space = cost->vi_int[1];
}
for (cc_count=0; oplist!=0; oplist = oplist->o_next) {
for (cc_count = 0; oplist != 0; oplist = oplist->o_next)
{
ip->i_nops++;
if(oplist->o_adorn&AD_CC)
if (oplist->o_adorn & AD_CC)
cc_count++;
}
while (eraselist!=VI_NULL) {
while (eraselist != VI_NULL )
{
if (eraselist->vi_int[0] == -1 && cc_count)
error("Instruction can't both set and break the condition codes");
eraselist=eraselist->vi_next;
eraselist = eraselist->vi_next;
}
if (cc_count>1)
if (cc_count > 1)
error("No instruction can set condition codes more than once");
}
n_set(name,number) char *name; {
void n_set(char *name, int number)
{
register symbol *sy_p;
sy_p = lookup(name,symset,newsymbol);
sy_p = lookup(name, symset, newsymbol);
sy_p->sy_value.syv_setno = number;
}
n_tok(name,atts,size,cost,format)
char *name;
struct varinfo *atts,*cost,*format;
void n_tok(char *name, struct varinfo *atts, int size,
struct varinfo *cost, struct varinfo *format)
{
register symbol *sy_p;
register token_p tp;
@ -98,146 +107,164 @@ struct varinfo *atts,*cost,*format;
int i;
int tokno;
int thistokensize;
char formstr[50],smallstr[2];
char formstr[50], smallstr[2];
sy_p = lookup(name,symtok,newsymbol);
NEW(tp,token_t);
tokno = NEXT(ntokens,MAXTOKENS,"Tokens");
sy_p = lookup(name, symtok, newsymbol);
NEW(tp, token_t);
tokno = NEXT(ntokens, MAXTOKENS, "Tokens");
sy_p->sy_value.syv_tokno = tokno;
l_tokens[tokno] = tp;
tp->tk_name = sy_p->sy_name;
tp->tk_size = size;
if (cost != 0) {
if (cost != 0)
{
tp->tk_cost.ct_space = cost->vi_int[0];
tp->tk_cost.ct_time = cost->vi_int[1];
} else {
tp->tk_cost.ct_space = 0;
tp->tk_cost.ct_time = 0;
tp->tk_cost.ct_time = cost->vi_int[1];
}
for(i=0,vip=atts;i<MAXATT && vip!=0;i++,vip=vip->vi_next) {
else
{
tp->tk_cost.ct_space = 0;
tp->tk_cost.ct_time = 0;
}
for (i = 0, vip = atts; i < MAXATT && vip != 0; i++, vip = vip->vi_next)
{
tp->tk_att[i].ta_type = vip->vi_int[0];
tp->tk_att[i].ta_name = vip->vi_str[0];
vip->vi_str[0]=0;
vip->vi_str[0] = 0;
}
thistokensize=i;
if (i>maxtokensize)
maxtokensize=i;
if (vip!=0)
error("More then %d attributes, rest discarded",MAXATT);
for(;i<MAXATT;i++)
tp->tk_att[i].ta_type= -3;
if (format!=0) {
thistokensize = i;
if (i > maxtokensize)
maxtokensize = i;
if (vip != 0)
error("More then %d attributes, rest discarded", MAXATT);
for (; i < MAXATT; i++)
tp->tk_att[i].ta_type = -3;
if (format != 0)
{
formstr[0] = 0;
for (vip=format;vip!=0;vip=vip->vi_next) {
if (vip->vi_int[0]==0)
strcat(formstr,vip->vi_str[0]);
else {
for(i=0;i<thistokensize;i++) {
if (strcmp(vip->vi_str[0],tp->tk_att[i].ta_name)==0) {
smallstr[0] = i+1;
for (vip = format; vip != 0; vip = vip->vi_next)
{
if (vip->vi_int[0] == 0)
strcat(formstr, vip->vi_str[0]);
else
{
for (i = 0; i < thistokensize; i++)
{
if (strcmp(vip->vi_str[0], tp->tk_att[i].ta_name) == 0)
{
smallstr[0] = i + 1;
smallstr[1] = 0;
strcat(formstr,smallstr);
strcat(formstr, smallstr);
break;
}
}
if (i==thistokensize)
error("%s not a known attribute",
vip->vi_str[0]);
if (i == thistokensize)
error("%s not a known attribute", vip->vi_str[0]);
}
}
tp->tk_format = strlookup(formstr);
} else
}
else
tp->tk_format = -1;
}
checkprintformat(n) {
void checkprintformat(int n)
{
register short *s;
register i;
extern set_t l_sets[];
s= l_sets[n].set_val;
for(i=nregs;i<nregs+ntokens;i++)
if (BIT(s,i) && l_tokens[i-nregs]->tk_format<0)
register int i;
s = l_sets[n].set_val;
for (i = nregs; i < nregs + ntokens; i++)
if (BIT(s,i) && l_tokens[i - nregs]->tk_format < 0)
error("Token %s in set does not have printformat",
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;
register symbol *sp;
propno = NEXT(nprops,MAXPROPS,"Properties");
sp = lookup(name,symprop,newsymbol);
propno = NEXT(nprops, MAXPROPS, "Properties");
sp = lookup(name, symprop, newsymbol);
sp->sy_value.syv_propno = propno;
if (size <= 0) {
if (size <= 0)
{
error("Size of property must be >0");
size = wordsize;
}
l_props[propno].pr_size = size;
}
void
prophall(n) {
register i;
void prophall(int n)
{
register int i;
short hallset[SETSIZE];
if (n < 0) return;
for(i=0;i<SETSIZE;i++)
hallset[i] = i<SZOFSET(MAXREGS) ? l_props[n].pr_regset[i] : 0;
if (n < 0)
return;
for (i = 0; i < SETSIZE; i++)
hallset[i] = i < SZOFSET(MAXREGS) ? l_props[n].pr_regset[i] : 0;
nexthall(hallset);
}
n_reg(name,printstring,nmemb,member1,member2) char *name,*printstring; {
int n_reg(char *name, char *printstring, int nmemb, int member1, int member2)
{
register symbol *sy_p;
register reginfo *ri_p;
int regno;
sy_p = lookup(name,symreg,newsymbol);
sy_p->sy_value.syv_regno = regno = NEXT(nregs,MAXREGS,"Number of registers");
sy_p = lookup(name, symreg, newsymbol);
sy_p->sy_value.syv_regno = regno = NEXT(nregs, MAXREGS,
"Number of registers");
ri_p = &l_regs[regno];
ri_p->ri_name = mystrcpy(name);
ri_p->ri_repr = printstring!=0 ? mystrcpy(printstring) : ri_p->ri_name;
ri_p->ri_repr = printstring != 0 ? mystrcpy(printstring) : ri_p->ri_name;
ri_p->ri_memb[0] = member1;
ri_p->ri_memb[1] = member2;
if (nmemb>maxmembers)
maxmembers=nmemb;
return(regno);
if (nmemb > maxmembers)
maxmembers = nmemb;
return (regno);
}
make_const() {
void make_const(void)
{
wordsize = cmustbeset("EM_WSIZE");
pointersize = cmustbeset("EM_PSIZE");
}
cmustbeset(ident) char *ident; {
int cmustbeset(char *ident)
{
return(lookup(ident,symconst,mustexist)->sy_value.syv_cstval);
return (lookup(ident, symconst, mustexist)->sy_value.syv_cstval);
}
n_const(ident,val) char *ident; {
void n_const(char *ident, int val)
{
register symbol *sy_p;
sy_p = lookup(ident,symconst,newsymbol);
sy_p = lookup(ident, symconst, newsymbol);
sy_p->sy_value.syv_cstval = val;
}
n_sconst(ident,val) char *ident,*val; {
void n_sconst(char *ident, char *val)
{
register symbol *sy_p;
sy_p = lookup(ident,symsconst,newsymbol);
sy_p = lookup(ident, symsconst, newsymbol);
sy_p->sy_value.syv_stringno = strlookup(val);
}
static void
add_regvar(int rvnum, reginfo *regp, int rv)
static void add_regvar(int rvnum, reginfo *regp, int rv)
{
int overlap, wrong;
overlap = wrong = 0;
if (regp->ri_memb[0]!=0) {
if (regp->ri_memb[0] != 0)
{
/* reglap: float may overlap with one subregister */
if (rv==reg_float && regp->ri_memb[1]==0)
if (rv == reg_float && regp->ri_memb[1] == 0)
overlap = 1;
else
wrong = 1;
@ -248,28 +275,34 @@ add_regvar(int rvnum, reginfo *regp, int rv)
rvused |= ANY_REGVAR;
if (regp->ri_size == wordsize)
rvused |= SL_REGVAR;
else if (regp->ri_size == 2*wordsize)
else if (regp->ri_size == 2 * wordsize)
rvused |= DL_REGVAR;
wrong = 0;
if (overlap) {
if (overlap)
{
/* reglap = size of overlap float */
if (reglap==0) {
if (reglap == 0)
{
reglap = regp->ri_size;
if (reglap == rvsize[reg_float])
error("Two sizes of reg_float can't be same size");
} else if (reglap!=regp->ri_size)
}
else if (reglap != regp->ri_size)
wrong = 1;
} else {
if (nregvar[rv]==0)
}
else
{
if (nregvar[rv] == 0)
rvsize[rv] = regp->ri_size;
else if (rvsize[rv]!=regp->ri_size)
else if (rvsize[rv] != regp->ri_size)
wrong = 1;
}
if (wrong)
error("All register variables of one type must have the same size");
if (overlap) {
if (overlap)
{
reginfo *member_p = &l_regs[regp->ri_memb[0]];
int i;
@ -278,54 +311,59 @@ add_regvar(int rvnum, reginfo *regp, int rv)
* Add reg_p in its place.
*/
wrong = 1;
for (i = 0; i < nregvar[rv]; i++) {
if (rvnumbers[rv][i] == regp->ri_memb[0]) {
for (i = 0; i < nregvar[rv]; i++)
{
if (rvnumbers[rv][i] == regp->ri_memb[0])
{
rvnumbers[rv][i] = rvnum;
wrong = 0;
break;
}
}
if (wrong)
error("Register variable %s can't overlap %s",
regp->ri_name, member_p->ri_name);
} else {
NEXT(nregvar[rv],MAXREGVAR,"Register variable");
rvnumbers[rv][nregvar[rv]-1] = rvnum;
error("Register variable %s can't overlap %s", regp->ri_name,
member_p->ri_name);
}
else
{
NEXT(nregvar[rv], MAXREGVAR, "Register variable");
rvnumbers[rv][nregvar[rv] - 1] = rvnum;
}
}
void
regline(rl,pl,rv) varinfo *rl,*pl; {
register varinfo *rrl,*rpl;
void regline(varinfo *rl, varinfo *pl, int rv)
{
register varinfo *rrl, *rpl;
register short *sp;
register reginfo *regp;
int thissize;
int propno;
for(rrl=rl;rrl!=0;rrl=rrl->vi_next) {
for (rrl = rl; rrl != 0; rrl = rrl->vi_next)
{
regp = &l_regs[rrl->vi_int[0]];
thissize = 0;
for(rpl=pl;rpl!=0;rpl=rpl->vi_next) {
for (rpl = pl; rpl != 0; rpl = rpl->vi_next)
{
propno = rpl->vi_int[0];
sp= l_props[propno].pr_regset;
BIS(sp,rrl->vi_int[0]);
if (thissize==0)
sp = l_props[propno].pr_regset;
BIS(sp, rrl->vi_int[0]);
if (thissize == 0)
thissize = l_props[propno].pr_size;
else if (thissize!=-1 && thissize!=l_props[propno].pr_size)
error("Register %s has no clear size",
regp->ri_name);
else if (thissize != -1 && thissize != l_props[propno].pr_size)
error("Register %s has no clear size", regp->ri_name);
}
regp->ri_size = thissize;
regp->ri_class = regclass;
regp->ri_rregvar = rv;
if (rv>=0)
if (rv >= 0)
add_regvar(rrl->vi_int[0], regp, rv);
}
regclass++;
}
void
check_reglap() {
void check_reglap(void)
{
reginfo *regp;
int i;
@ -333,129 +371,147 @@ check_reglap() {
return;
/* reglap: Check that every reg_float has size == reglap. */
for (i = 0; i < nregvar[reg_float]; i++) {
for (i = 0; i < nregvar[reg_float]; i++)
{
regp = &l_regs[rvnumbers[reg_float][i]];
if (regp->ri_size != reglap)
error("Missing reg_float of size %d to contain %s",
reglap, regp->ri_name);
error("Missing reg_float of size %d to contain %s", reglap,
regp->ri_name);
}
}
setallreg(vi) struct varinfo *vi; {
void setallreg(struct varinfo *vi)
{
nallreg=0;
for(;vi!=0;vi=vi->vi_next) {
if (vi->vi_int[0]<0)
nallreg = 0;
for (; vi != 0; vi = vi->vi_next)
{
if (vi->vi_int[0] < 0)
continue;
allreg[nallreg++] = vi->vi_int[0];
}
}
void
freevi(vip) register struct varinfo *vip; {
register i;
void freevi(register struct varinfo *vip)
{
register int i;
if (vip==0)
if (vip == 0)
return;
freevi(vip->vi_next);
freevi(vip->vi_vi);
for (i=0;i<VI_NSTR;i++)
for (i = 0; i < VI_NSTR; i++)
free((char *) vip->vi_str[i]);
free(vip);
}
int myatoi(s) register char *s; {
register int base=10;
register sum=0;
int myatoi(register char *s)
{
register int base = 10;
register int sum = 0;
if (*s=='0') {
if (*s == '0')
{
base = 8;
s++;
if (*s=='x') {
base=16;
if (*s == 'x')
{
base = 16;
s++;
}
}
for (;;) {
switch (*s) {
default: return(sum);
case '8':
case '9':
if (base==8) error("Bad digit in octal number");
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
sum = sum*base + *s++ - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
if (base!=16) error("Hexletter in number not expected");
sum = sum*base + 10 + *s++ - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
if (base!=16) error("Hexletter in number not expected");
sum = sum*base + 10 + *s++ - 'A';
break;
for (;;)
{
switch (*s)
{
default:
return (sum);
case '8':
case '9':
if (base == 8)
error("Bad digit in octal number");
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
sum = sum * base + *s++ - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
if (base != 16)
error("Hexletter in number not expected");
sum = sum * base + 10 + *s++ - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
if (base != 16)
error("Hexletter in number not expected");
sum = sum * base + 10 + *s++ - 'A';
break;
}
}
}
char *mystrcpy(s) char *s; {
char *mystrcpy(char *s)
{
register char *p;
char *myalloc();
p=myalloc(strlen(s)+1);
strcpy(p,s);
return(p);
p = myalloc(strlen(s) + 1);
strcpy(p, s);
return (p);
}
char *myalloc(n) register n; {
register char *p,*result;
char *myalloc(register int n)
{
register char *p, *result;
result=p=malloc(n);
if (p== (char *) 0)
result = p = malloc(n);
if (p == (char *) 0)
fatal("Out of memory");
do *p++=0; while (--n);
return(result);
do
*p++ = 0;
while (--n);
return (result);
}
chkincl(value,lwb,upb) {
int chkincl(int value, int lwb, int upb)
{
if (value<lwb || value>upb)
error("Number %d should have been between %d and %d",
value,lwb,upb);
return(value);
if (value < lwb || value > upb)
error("Number %d should have been between %d and %d", value, lwb, upb);
return (value);
}
subset(sp1,sp2,setsize) short *sp1,*sp2; {
register i;
int subset(short *sp1, short *sp2, int setsize)
{
register int i;
for(i=0;i<setsize;i++)
if ( (sp1[i] | sp2[i]) != sp2[i])
return(0);
return(1);
for (i = 0; i < setsize; i++)
if ((sp1[i] | sp2[i]) != sp2[i])
return (0);
return (1);
}
vilength(vip) register struct varinfo *vip; {
register l=0;
int vilength(register struct varinfo *vip)
{
register int l = 0;
while(vip!=0) {
vip=vip->vi_next;
while (vip != 0)
{
vip = vip->vi_next;
l++;
}
return(l);
return (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_ */