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

@ -3,7 +3,7 @@
* 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".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h> #include <assert.h>
@ -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"
@ -22,165 +25,181 @@ extern set_t l_sets[];
int nmoves; 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];
mp->m_set1 = s1; mp->m_set1 = s1;
mp->m_expr1 = e1; mp->m_expr1 = e1;
mp->m_set2 = s2; mp->m_set2 = s2;
mp->m_expr2 = e2; mp->m_expr2 = e2;
mp->m_cindex = codeindex; mp->m_cindex = codeindex;
dopattern(0,VI_NULL,VI_NULL,vi,VI_NULL,VI_NULL); dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL);
if (mp->m_expr1!=0 || mp->m_expr2!=0) if (mp->m_expr1 != 0 || mp->m_expr2 != 0)
return; return;
for (i=0;i<MAXREGS+MAXTOKENS;i++) for (i = 0; i < MAXREGS + MAXTOKENS; i++)
if (BIT(l_sets[mp->m_set1].set_val,i)) if (BIT(l_sets[mp->m_set1].set_val, i))
for(j=0;j<SETSIZE;j++) for (j = 0; j < SETSIZE; j++)
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))
if (!subset(sp,posmoves[i],SETSIZE)) if (!subset(sp, posmoves[i], SETSIZE))
return(0); return (0);
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 );
} }
NEW(vp,struct varinfo); NEW(vp, struct varinfo);
vp->vi_int[0] = INSMOVE; vp->vi_int[0] = INSMOVE;
vp->vi_int[1] = from.in_index; vp->vi_int[1] = from.in_index;
vp->vi_int[2] = to.in_index; vp->vi_int[2] = to.in_index;
return(vp); return (vp);
} }
int ntests; 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];
tp->t_set = s; tp->t_set = s;
tp->t_expr = e; tp->t_expr = e;
tp->t_cindex = codeindex; tp->t_cindex = codeindex;
dopattern(0,VI_NULL,VI_NULL,vi,VI_NULL,VI_NULL); dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL);
if (tp->t_expr!=0) if (tp->t_expr != 0)
return; return;
for(i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
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);
} }
NEW(vp,struct varinfo); NEW(vp, struct varinfo);
vp->vi_int[0] = INSTEST; vp->vi_int[0] = INSTEST;
vp->vi_int[1] = from.in_index; 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; register struct varinfo *vp;
NEW(vp,struct varinfo); NEW(vp, struct varinfo);
vp->vi_int[0] = INSLABDEF; vp->vi_int[0] = INSLABDEF;
vp->vi_int[1] = arg; vp->vi_int[1] = 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);
vp->vi_int[0] = INSPRETURN; vp->vi_int[0] = INSPRETURN;
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);
NEW(vp,struct varinfo); NEW(vp, struct varinfo);
vp->vi_int[0] = INSTLAB; vp->vi_int[0] = INSTLAB;
vp->vi_int[1] = n; vp->vi_int[1] = n;
return(vp); return (vp);
} }
int nstacks; 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];
c1p->c1_texpno = s; c1p->c1_texpno = s;
c1p->c1_expr = e; c1p->c1_expr = e;
c1p->c1_prop = p; c1p->c1_prop = p;
c1p->c1_codep = codeindex; 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; sp = ustackset.set_val;
else else
sp = cstackset.set_val; sp = cstackset.set_val;
for(i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
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;
for (i=1;i<nregs;i++) warn = "";
if (BIT(sp,i) && !BIT(chkset,i)) for (i = 1; i < nregs; i++)
error("No %sstacking rule for register %s",warn, if (BIT(sp,i) && !BIT(chkset, i))
error("No %sstacking rule for register %s", warn,
l_regs[i].ri_name); l_regs[i].ri_name);
for(;i<nregs+MAXTOKENS;i++) for (; i < nregs + MAXTOKENS; i++)
if (BIT(sp,i) && !BIT(chkset,i)) if (BIT(sp,i) && !BIT(chkset, i))
error("No %sstacking rule for token %s",warn, error("No %sstacking rule for token %s", warn,
l_tokens[i-nregs]->tk_name); l_tokens[i - nregs]->tk_name);
} }
int ncoercs; int ncoercs;
@ -189,78 +208,89 @@ 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 { }
NEW(rp,struct varinfo); else
{
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;
} }
if (nallreg>1) if (nallreg > 1)
error("More than 1 register may not be allocated"); error("More than 1 register may not be allocated");
NEXT(ncoercs,MAXCOERCS,"Coercions"); NEXT(ncoercs, MAXCOERCS, "Coercions");
c3p = & l_coercs[ncoercs-1]; c3p = &l_coercs[ncoercs - 1];
c3p->c3_texpno = ti; c3p->c3_texpno = ti;
c3p->c3_expr = be; 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_repl = rp->vi_int[0];
c3p->c3_codep = codeindex; c3p->c3_codep = codeindex;
dopattern(ti==0,VI_NULL,al,ge,rp,VI_NULL); dopattern(ti == 0, VI_NULL, al, ge, rp, VI_NULL);
if (ti==0) if (ti == 0)
for(i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
unstackset.set_val[i] |= in.in_set[i]; unstackset.set_val[i] |= in.in_set[i];
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;
for (i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
hallset[i]=sp[i]&unstackset.set_val[i]; hallset[i] = sp[i] & unstackset.set_val[i];
nexthall(hallset); nexthall(hallset);
} }
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)
error("No register uses allowed in splitting coercion"); error("No register uses allowed in splitting coercion");
c2p->c2_nsplit = n; 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_repl[i] = vi->vi_int[0];
c2p->c2_codep = codeindex; 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". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -18,53 +18,65 @@ 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 *);
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); 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;
while (emhashmnem[h].h_name[0] != 0) while (emhashmnem[h].h_name[0] != 0)
h = (h+1)%HASHSIZE; h = (h + 1) % HASHSIZE;
strncpy(emhashmnem[h].h_name,name,3); strncpy(emhashmnem[h].h_name, name, 3);
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:
@ -74,8 +86,8 @@ argtyp(mn) {
case PAR_F: case PAR_F:
case PAR_R: case PAR_R:
case PAR_C: case PAR_C:
return(TYPINT); return (TYPINT);
default: default:
return(TYPADDR); return (TYPADDR);
} }
} }

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

@ -3,7 +3,7 @@
* 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".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h> #include <assert.h>
@ -24,135 +24,158 @@ 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;
result.ex_index=ex_lookup(operator,op1,op2); result.ex_index = ex_lookup(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);
for (i=0;i<SZOFSET(MAXREGS);i++) for (i = 0; i < SZOFSET(MAXREGS); i++)
result.ex_regset[i] = 0; result.ex_regset[i] = 0;
BIS(result.ex_regset,regno); BIS(result.ex_regset, 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);
if (sy_p->sy_type==symconst) if (sy_p->sy_type == symconst)
return(make_expr(TYPINT,EX_CON, return (make_expr(TYPINT, EX_CON,
(int) (sy_p->sy_value.syv_cstval&0xFFFF), (int) (sy_p->sy_value.syv_cstval & 0xFFFF),
(int) (sy_p->sy_value.syv_cstval>>16))); (int) (sy_p->sy_value.syv_cstval >> 16)));
else if (sy_p->sy_type==symsconst) else if (sy_p->sy_type == symsconst)
return(make_expr(TYPADDR,EX_STRING,sy_p->sy_value.syv_stringno,0)); return (make_expr(TYPADDR, EX_STRING, sy_p->sy_value.syv_stringno, 0));
else if (sy_p->sy_type!=symreg) else if (sy_p->sy_type != symreg)
error("Wrong type of identifier %s",name); error("Wrong type of identifier %s", 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;
subregset(l_sets[tokpatset[tokarg > 0 ? tokarg-1 : tokarg]].set_val, subregset(l_sets[tokpatset[tokarg > 0 ? tokarg - 1 : tokarg]].set_val,
subreg,result.ex_regset); subreg, result.ex_regset);
result.ex_index = ex_lookup(EX_SUBREG,tokarg,subreg); result.ex_index = ex_lookup(EX_SUBREG, 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
BIS(regset,i);
} }
for(;i<nregs+MAXTOKENS;i++) if(BIT(sp,i)) else
BIS(regset, 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++)
tp = l_tokens[i-nregs]; if (BIT(sp, i))
for(j=0;j<MAXATT && {
(tp->tk_att[j].ta_type == -3 || tp = l_tokens[i - nregs];
strcmp(tp->tk_att[j].ta_name,name));j++) for (j = 0;
j < MAXATT
&& (tp->tk_att[j].ta_type == -3
|| strcmp(tp->tk_att[j].ta_name, name));
j++)
; ;
if (j==MAXATT) 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) {
typesdiffer=1; if (restyp != TYPADDR && restyp != 0)
typesdiffer = 1;
else else
restyp=TYPADDR; restyp = TYPADDR;
} else if (thistyp== -1) { }
if (restyp!=TYPINT && restyp!=0) else if (thistyp == -1)
typesdiffer=1; {
if (restyp != TYPINT && restyp != 0)
typesdiffer = 1;
else else
restyp=TYPINT; restyp = TYPINT;
} else { }
if (restyp!=TYPREG && restyp!=0) else
typesdiffer=1; {
else { if (restyp != TYPREG && restyp != 0)
restyp=TYPREG; typesdiffer = 1;
for(k=0;k<SZOFSET(MAXREGS);k++) else
{
restyp = TYPREG;
for (k = 0; k < SZOFSET(MAXREGS); k++)
regset[k] |= regset[k] |=
l_props[tp->tk_att[j].ta_type].pr_regset[k]; l_props[tp->tk_att[j].ta_type].pr_regset[k];
} }
@ -162,125 +185,147 @@ int *typp;
if (typesdiffer) if (typesdiffer)
error("%s is not a valid expression; types differ in the set", error("%s is not a valid expression; types differ in the set",
appearance); appearance);
*typp = restyp==0 ? TYPINT : restyp; *typp = restyp == 0 ? TYPINT : restyp;
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_index = ex_lookup(EX_TOKFIELD,tokarg,res_j+1); &result.ex_typ);
return(result); 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]; char app[100];
int tokarg1 = tokarg > 0 ? tokarg : 1; int tokarg1 = tokarg > 0 ? tokarg : 1;
sprintf(app,"%%%d.%s",tokarg1,name); sprintf(app, "%%%d.%s", tokarg1, 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;
sp = l_props[allreg[all_no]].pr_regset; sp = l_props[allreg[all_no]].pr_regset;
for (i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
localset.set_val[i] = i<SZOFSET(MAXREGS) ? sp[i] : 0; localset.set_val[i] = i < SZOFSET(MAXREGS) ? sp[i] : 0;
subregset(localset.set_val,subreg,result.ex_regset); subregset(localset.set_val, subreg, result.ex_regset);
result.ex_typ = TYPREG; result.ex_typ = TYPREG;
result.ex_index = ex_lookup(EX_ALLREG,all_no+1,subreg); result.ex_index = ex_lookup(EX_ALLREG, all_no + 1, 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:
return(EX_NCPEQ); return (EX_NCPEQ);
case TYPADDR: case TYPADDR:
return(EX_SCPEQ); return (EX_SCPEQ);
case TYPREG: case TYPREG:
return(EX_RCPEQ); 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) 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:
return(EX_NCPNE); return (EX_NCPNE);
case TYPADDR: case TYPADDR:
return(EX_SCPNE); return (EX_SCPNE);
case TYPREG: case TYPREG:
return(EX_RCPNE); return (EX_RCPNE);
} }
} }
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);
} }
} }
result.ex_index=ex_lookup(operator,op1,op2); result.ex_index = ex_lookup(operator, op1, op2);
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;
result.ex_index = ex_lookup(EX_TOSTRING,e.ex_index,0); result.ex_index = ex_lookup(EX_TOSTRING, e.ex_index, 0);
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()");
@ -288,26 +333,29 @@ expr_t regvar_expr(e,regtyp,regsiz) expr_t e; {
regsiz = rvsize[regtyp]; regsiz = rvsize[regtyp];
} }
result = make_expr(TYPREG,EX_REGVAR,i_expr(e),regsiz); result = make_expr(TYPREG, EX_REGVAR, i_expr(e), regsiz);
for(i=0;i<SZOFSET(MAXREGS);i++) for (i = 0; i < SZOFSET(MAXREGS); i++)
result.ex_regset[i]=0; result.ex_regset[i] = 0;
/* 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++) {
BIS(result.ex_regset,rvnumbers[regtyp][i]); for (i = 0; i < nregvar[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)
BIS(result.ex_regset, regno); BIS(result.ex_regset, regno);
} }
} }
return(result); return (result);
} }
/* /*
@ -315,9 +363,10 @@ 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,21 +374,23 @@ 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)
continue; continue;
if (p->ex_rnode != rnode) if (p->ex_rnode != rnode)
continue; continue;
return(p-nodes); return (p - nodes);
} }
NEXT(nnodes,MAXNODES,"Node"); NEXT(nnodes, MAXNODES, "Node");
p->ex_operator = operator; p->ex_operator = operator;
p->ex_lnode = lnode; p->ex_lnode = lnode;
p->ex_rnode = rnode; 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". * 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

@ -3,18 +3,19 @@
* 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".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h> #include <assert.h>
#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
@ -29,54 +30,64 @@ static char rcsid[]= "$Id$";
#define MAXHALL (TOKPATMAX+MAXALLREG) #define MAXHALL (TOKPATMAX+MAXALLREG)
short hallsets[MAXHALL][SETSIZE]; 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;
fprintf(stderr,"Table of hall frequencies\n # pre post\n");
for (max=MAXHALL-1;hallfreq[max][0]==0 && hallfreq[max][1]==0;max--) 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++) 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++)
hallsets[nhallsets][i] = sp[i]; hallsets[nhallsets][i] = sp[i];
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++)
if (BIT(sp,i)) if (BIT(sp, i))
sum++; sum++;
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(k=0;k<SETSIZE;k++) for (j = i + 1; j < nhallsets; j++)
hallsets[j-1][k] = for (k = 0; k < SETSIZE; k++)
hallsets[j][k]; hallsets[j - 1][k] = hallsets[j][k];
nhallsets--; nhallsets--;
ok = 1; ok = 1;
break; break;
@ -105,47 +117,52 @@ hall() {
*/ */
hallfreq[nhallsets][1]++; hallfreq[nhallsets][1]++;
ok=recurhall(nhallsets,hallsets); ok = recurhall(nhallsets, hallsets);
nhallsets = -1; nhallsets = -1;
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
*/ */
for(k=0;k<SETSIZE;k++) for (k = 0; k < SETSIZE; k++)
setsum[k]=0; setsum[k] = 0;
for(i=0;i<nhallsets;i++) for (i = 0; i < nhallsets; i++)
unite(hallsets[i],setsum); unite(hallsets[i], setsum);
if (card(setsum)<nhallsets) if (card(setsum) < nhallsets)
return(0); return (0);
/* /*
* 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; {
for(j=0;j<nhallsets;j++) if (j!=i) { ncopys = 0;
for(k=0;k<SETSIZE;k++) for (j = 0; j < nhallsets; j++)
if (j != i)
{
for (k = 0; k < SETSIZE; k++)
copysets[ncopys][k] = hallsets[j][k]; copysets[ncopys][k] = hallsets[j][k];
ncopys++; ncopys++;
} }
assert(ncopys == nhallsets-1); assert(ncopys == nhallsets - 1);
if (!recurhall(ncopys,copysets)) if (!recurhall(ncopys, copysets))
return(0); return (0);
} }
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

@ -3,7 +3,7 @@
* 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".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <string.h> #include <string.h>
@ -14,113 +14,129 @@ 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);
vi->vi_next = VI_NULL; vi->vi_next = VI_NULL;
vi->vi_int[0] = INSSETCC; vi->vi_int[0] = INSSETCC;
vi->vi_int[1] = n; vi->vi_int[1] = 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);
vi->vi_next = VI_NULL; vi->vi_next = VI_NULL;
vi->vi_int[0] = INSERASE; vi->vi_int[0] = INSERASE;
vi->vi_int[1] = n; vi->vi_int[1] = 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);
vi->vi_next = VI_NULL; vi->vi_next = VI_NULL;
vi->vi_int[0] = INSREMOVE; vi->vi_int[0] = INSREMOVE;
vi->vi_int[1] = n; vi->vi_int[1] = 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)
sp = l_sets[tokpatset[argno-1]].set_val; argno++;
for(bitno=nregs;bitno<nregs+ntokens;bitno++) sp = l_sets[tokpatset[argno - 1]].set_val;
if (BIT(sp,bitno)) for (bitno = nregs; bitno < nregs + ntokens; bitno++)
return(0); if (BIT(sp, bitno))
return(1); return (0);
return (1);
} }
makescratch(argno) { static void makescratch(int argno)
{
set_t s; set_t s;
if (! argno) argno++; if (!argno)
if (tokpatro[argno-1]) argno++;
error("Instruction destroys %%%d, not allowed here",argno); if (tokpatro[argno - 1])
s = l_sets[tokpatset[argno-1]]; error("Instruction destroys %%%d, not allowed here", argno);
BIC(s.set_val,0); s = l_sets[tokpatset[argno - 1]];
tokpatset[argno-1] = setlookup(s); BIC(s.set_val, 0);
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;
cont:; /* oh well, one more won't hurt */
cont: ;
} }
error("Such an \"%s\" does not exist",ident); error("Such an \"%s\" does not exist", ident);
return(0); return (0);
found: found:
NEW(vi,struct varinfo); NEW(vi, struct varinfo);
vi->vi_int[0] = ip-l_instr; vi->vi_int[0] = ip - l_instr;
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); {
vi=vi->vi_vi; NEW(vi->vi_vi, struct varinfo);
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,54 +149,42 @@ 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], vi = vi->vi_next;
insta->in_info[1]
)
);
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;
else else
temp = 2 * wordsize; temp = 2 * wordsize;
temp=ex_lookup(EX_REGVAR,insta->in_info[1],temp); temp = ex_lookup(EX_REGVAR, insta->in_info[1], temp);
vi->vi_next = generase(temp); vi->vi_next = generase(temp);
vi = vi->vi_next; vi = vi->vi_next;
vi->vi_next = genremove(temp); vi->vi_next = genremove(temp);
@ -191,15 +195,17 @@ 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]);
} }
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". * 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

@ -3,7 +3,7 @@
* 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".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <assert.h> #include <assert.h>
@ -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,133 +29,150 @@ 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)
if (subreg==0) tokarg = 1;
for (i=0;i<SETSIZE;i++) if (subreg == 0)
result.in_set[i] = l_sets[tokpatset[tokarg-1]].set_val[i]; for (i = 0; i < SETSIZE; i++)
else { result.in_set[i] = l_sets[tokpatset[tokarg - 1]].set_val[i];
for (i=0;i<SETSIZE;i++) else
{
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);
} }
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;
for(i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
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)
sprintf(app,"%%%d.%s",tokarg,ident); tokarg = 1;
insta.in_info[1] = 1+membset(tokpatset[tokarg-1],ident,result.in_set, sprintf(app, "%%%d.%s", tokarg, ident);
app,TYPREG,&dummy); insta.in_info[1] = 1
result.in_index = instalookup(insta,2); + membset(tokpatset[tokarg - 1], ident, result.in_set, app, TYPREG,
return(result); &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; iocc_t result;
inst_t insta; inst_t insta;
register i; register int i;
char app[100]; char app[100];
int dummy; int dummy;
for(i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0; result.in_set[i] = 0;
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++)
result.in_set[i] = 0; result.in_set[i] = 0;
insta.in_which = IN_RIDENT; 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; insta.in_info[0] = sy_p->sy_value.syv_regno;
result.in_index = instalookup(insta,1); result.in_index = instalookup(insta, 1);
BIS(result.in_set,sy_p->sy_value.syv_regno); BIS(result.in_set, sy_p->sy_value.syv_regno);
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;
sp = l_props[allreg[all_no]].pr_regset; sp = l_props[allreg[all_no]].pr_regset;
for (i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
localset.set_val[i] = i<SZOFSET(MAXREGS) ? sp[i] : 0; localset.set_val[i] = i < SZOFSET(MAXREGS) ? sp[i] : 0;
for(i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
result.in_set[i] = 0; result.in_set[i] = 0;
insta.in_which = IN_ALLOC; insta.in_which = IN_ALLOC;
insta.in_info[0] = all_no; insta.in_info[0] = all_no;
insta.in_info[1] = subreg; insta.in_info[1] = subreg;
subregset(localset.set_val,subreg,result.in_set); subregset(localset.set_val, subreg, result.in_set);
result.in_index = instalookup(insta,2); result.in_index = instalookup(insta, 2);
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++)
result.in_set[i] = 0; 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]; 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; 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; 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_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 (narexpr>i) if (tp->tk_att[i].ta_type == -3)
error("token %s initialized with too many attributes",ident); {
if (narexpr > i)
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,13 +181,14 @@ 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++;
break; break;
case TYPREG: case TYPREG:
if (tp->tk_att[i].ta_type<0) if (tp->tk_att[i].ta_type < 0)
typerr++; typerr++;
else if (!subset(arexp[i].ex_regset, else if (!subset(arexp[i].ex_regset,
l_props[tp->tk_att[i].ta_type].pr_regset, l_props[tp->tk_att[i].ta_type].pr_regset,
@ -178,34 +197,36 @@ 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);
return(result); return (result);
} }
/* low level instance package */ /* low level instance package */
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++)
if (insta.in_info[j]!= l_instances[i].in_info[j]) if (insta.in_info[j] != l_instances[i].in_info[j])
goto cont; goto cont;
return(i); return (i);
cont:; cont: ;
} }
NEXT(ninstances,MAXINSTANCES,"Instances"); NEXT(ninstances, MAXINSTANCES, "Instances");
l_instances[i] = insta; 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". * 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

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

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

@ -3,23 +3,36 @@
* 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".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#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;
@ -30,33 +43,41 @@ main(argc,argv) char **argv; {
verbose++; verbose++;
break; break;
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) { {
error("Can't open %s",argv[1]); if (freopen(argv[1], "r", stdin) == NULL)
{
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 }
error("Usage: %s [-c] [-d] [-v] [table]",argv[0]); else
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);
} }

File diff suppressed because it is too large Load diff

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

@ -3,7 +3,7 @@
* 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".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include "param.h" #include "param.h"
@ -12,143 +12,161 @@ 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[];
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 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 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);
case symprop: case symprop:
pp = &l_props[sy_p->sy_value.syv_propno]; pp = &l_props[sy_p->sy_value.syv_propno];
result.set_size = pp->pr_size; result.set_size = pp->pr_size;
for (i=0;i<SZOFSET(MAXREGS);i++) for (i = 0; i < SZOFSET(MAXREGS); i++)
result.set_val[i] = pp->pr_regset[i]; result.set_val[i] = pp->pr_regset[i];
BIS(result.set_val,0); BIS(result.set_val, 0);
for (;i<SETSIZE;i++) for (; i < SETSIZE; i++)
result.set_val[i] = 0; result.set_val[i] = 0;
break; break;
case symtok: case symtok:
bitno = sy_p->sy_value.syv_tokno+nregs; bitno = sy_p->sy_value.syv_tokno + nregs;
for (i=0;i<SETSIZE;i++) for (i = 0; i < SETSIZE; i++)
result.set_val[i] = 0; result.set_val[i] = 0;
BIS(result.set_val,bitno); BIS(result.set_val, bitno);
result.set_size = l_tokens[sy_p->sy_value.syv_tokno]->tk_size; result.set_size = l_tokens[sy_p->sy_value.syv_tokno]->tk_size;
break; break;
case symset: case symset:
return(l_sets[sy_p->sy_value.syv_setno]); return (l_sets[sy_p->sy_value.syv_setno]);
} }
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];
checksize(&result); 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; 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;
else else
result.set_size = 0; 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]; 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; 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)) { {
BIS(result.set_val,0); if (BIT(result.set_val, i))
{
BIS(result.set_val, 0);
break; break;
} }
} }
checksize(&result); 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". * 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

@ -3,24 +3,25 @@
* 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".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#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)
return(i); return (i);
NEXT(nstrings,MAXSTRINGS,"String table"); NEXT(nstrings, MAXSTRINGS, "String table");
l_strings[i] = mystrcpy(str); 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". * See the copyright notice in the ACK home directory, in the file "Copyright".
*/ */
#ifndef NORCSID #ifndef NORCSID
static char rcsid[]= "$Id$"; static char rcsid[] = "$Id$";
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -20,77 +20,86 @@ 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; { extern int npatbytes;
register symbol *sy_p; extern set_t l_sets[];
extern int npatbytes;
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; 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);
if (e.ex_typ != TYPREG) if (e.ex_typ != TYPREG)
error("Register name required here"); error("Register name required here");
NEW(result,struct varinfo); NEW(result, struct varinfo);
result->vi_next = VI_NULL; result->vi_next = VI_NULL;
result->vi_int[0] = e.ex_index; result->vi_int[0] = e.ex_index;
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");
ip = &l_instr[instrno]; ip = &l_instr[instrno];
ip->i_name = name; 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_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;
} }
if (cc_count>1) if (cc_count > 1)
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;
@ -98,146 +107,164 @@ struct varinfo *atts,*cost,*format;
int i; int i;
int tokno; int tokno;
int thistokensize; int thistokensize;
char formstr[50],smallstr[2]; char formstr[50], smallstr[2];
sy_p = lookup(name,symtok,newsymbol); sy_p = lookup(name, symtok, newsymbol);
NEW(tp,token_t); NEW(tp, token_t);
tokno = NEXT(ntokens,MAXTOKENS,"Tokens"); tokno = NEXT(ntokens, MAXTOKENS, "Tokens");
sy_p->sy_value.syv_tokno = tokno; sy_p->sy_value.syv_tokno = tokno;
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;
} }
thistokensize=i; thistokensize = i;
if (i>maxtokensize) if (i > maxtokensize)
maxtokensize=i; maxtokensize = i;
if (vip!=0) if (vip != 0)
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) {
strcat(formstr,vip->vi_str[0]); if (vip->vi_int[0] == 0)
else { strcat(formstr, vip->vi_str[0]);
for(i=0;i<thistokensize;i++) { else
if (strcmp(vip->vi_str[0],tp->tk_att[i].ta_name)==0) { {
smallstr[0] = i+1; 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; smallstr[1] = 0;
strcat(formstr,smallstr); strcat(formstr, smallstr);
break; break;
} }
} }
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++)
if (BIT(s,i) && l_tokens[i-nregs]->tk_format<0) if (BIT(s,i) && l_tokens[i - nregs]->tk_format < 0)
error("Token %s in set does not have printformat", 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; 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)
for(i=0;i<SETSIZE;i++) return;
hallset[i] = i<SZOFSET(MAXREGS) ? l_props[n].pr_regset[i] : 0; for (i = 0; i < SETSIZE; i++)
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;
ri_p->ri_memb[0] = member1; ri_p->ri_memb[0] = member1;
ri_p->ri_memb[1] = member2; ri_p->ri_memb[1] = member2;
if (nmemb>maxmembers) if (nmemb > maxmembers)
maxmembers=nmemb; maxmembers = nmemb;
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;
else else
wrong = 1; wrong = 1;
@ -248,28 +275,34 @@ add_regvar(int rvnum, reginfo *regp, int rv)
rvused |= ANY_REGVAR; rvused |= ANY_REGVAR;
if (regp->ri_size == wordsize) if (regp->ri_size == wordsize)
rvused |= SL_REGVAR; rvused |= SL_REGVAR;
else if (regp->ri_size == 2*wordsize) else if (regp->ri_size == 2 * wordsize)
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 { }
if (nregvar[rv]==0) else
{
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)
wrong = 1; wrong = 1;
} }
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,54 +311,59 @@ 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 { }
NEXT(nregvar[rv],MAXREGVAR,"Register variable"); else
rvnumbers[rv][nregvar[rv]-1] = rvnum; {
NEXT(nregvar[rv], MAXREGVAR, "Register variable");
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;
regp->ri_rregvar = rv; regp->ri_rregvar = rv;
if (rv>=0) if (rv >= 0)
add_regvar(rrl->vi_int[0], regp, rv); add_regvar(rrl->vi_int[0], regp, rv);
} }
regclass++; regclass++;
} }
void void check_reglap(void)
check_reglap() { {
reginfo *regp; reginfo *regp;
int i; int i;
@ -333,55 +371,65 @@ 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;
freevi(vip->vi_next); freevi(vip->vi_next);
freevi(vip->vi_vi); 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((char *) vip->vi_str[i]);
free(vip); free(vip);
} }
int myatoi(s) register char *s; { int myatoi(register char *s)
register int base=10; {
register sum=0; register int base = 10;
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':
@ -390,7 +438,7 @@ int myatoi(s) register char *s; {
case '5': case '5':
case '6': case '6':
case '7': case '7':
sum = sum*base + *s++ - '0'; sum = sum * base + *s++ - '0';
break; break;
case 'a': case 'a':
case 'b': case 'b':
@ -398,8 +446,9 @@ 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)
sum = sum*base + 10 + *s++ - 'a'; error("Hexletter in number not expected");
sum = sum * base + 10 + *s++ - 'a';
break; break;
case 'A': case 'A':
case 'B': case 'B':
@ -407,55 +456,62 @@ 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)
sum = sum*base + 10 + *s++ - 'A'; error("Hexletter in number not expected");
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
return(result); *p++ = 0;
while (--n);
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])
return(0); return (0);
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++;
} }
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_ */