1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1985-01-08 09:59:28 +00:00
|
|
|
#ifndef NORCSID
|
2019-05-10 17:17:24 +00:00
|
|
|
static char rcsid[] = "$Id$";
|
1985-01-08 09:59:28 +00:00
|
|
|
#endif
|
|
|
|
|
2017-11-10 03:22:13 +00:00
|
|
|
#include <assert.h>
|
1985-01-08 09:59:28 +00:00
|
|
|
#include "param.h"
|
|
|
|
#include "set.h"
|
|
|
|
#include "property.h"
|
|
|
|
#include "reg.h"
|
|
|
|
#include "token.h"
|
|
|
|
#include "varinfo.h"
|
|
|
|
#include "iocc.h"
|
2019-05-10 17:17:24 +00:00
|
|
|
#include "subr.h"
|
|
|
|
#include "hall.h"
|
|
|
|
#include "coerc.h"
|
1985-01-08 09:59:28 +00:00
|
|
|
#include <cgg_cg.h>
|
|
|
|
#include "pseudo.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
extern set_t l_sets[];
|
|
|
|
|
|
|
|
int nmoves;
|
|
|
|
move_t l_moves[MAXMOVES];
|
2019-05-10 17:17:24 +00:00
|
|
|
short posmoves[MAXREGS + MAXTOKENS][SETSIZE];
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
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)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register move_p mp;
|
2019-05-10 17:17:24 +00:00
|
|
|
register int i, j;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
NEXT(nmoves, MAXMOVES, "Moves");
|
|
|
|
mp = &l_moves[nmoves - 1];
|
1985-01-08 09:59:28 +00:00
|
|
|
mp->m_set1 = s1;
|
|
|
|
mp->m_expr1 = e1;
|
|
|
|
mp->m_set2 = s2;
|
|
|
|
mp->m_expr2 = e2;
|
|
|
|
mp->m_cindex = codeindex;
|
2019-05-10 17:17:24 +00:00
|
|
|
dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL);
|
|
|
|
if (mp->m_expr1 != 0 || mp->m_expr2 != 0)
|
1985-01-08 09:59:28 +00:00
|
|
|
return;
|
2019-05-10 17:17:24 +00:00
|
|
|
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];
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int existmove(iocc_t from, short *sp)
|
|
|
|
{
|
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; i < MAXREGS + MAXTOKENS; i++)
|
|
|
|
if (BIT(from.in_set, i))
|
|
|
|
if (!subset(sp, posmoves[i], SETSIZE))
|
|
|
|
return (0);
|
|
|
|
return (1);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int existalmove(iocc_t from, int prpno)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
short s[SETSIZE];
|
2019-05-10 17:17:24 +00:00
|
|
|
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));
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
struct varinfo *gen_move(iocc_t from, iocc_t to)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register struct varinfo *vp;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (existmove(from, to.in_set) == 0)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
error("No such move defined");
|
2019-05-10 17:17:24 +00:00
|
|
|
return (VI_NULL );
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
NEW(vp, struct varinfo);
|
1985-01-08 09:59:28 +00:00
|
|
|
vp->vi_int[0] = INSMOVE;
|
|
|
|
vp->vi_int[1] = from.in_index;
|
|
|
|
vp->vi_int[2] = to.in_index;
|
2019-05-10 17:17:24 +00:00
|
|
|
return (vp);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ntests;
|
|
|
|
test_t l_tests[MAXTESTS];
|
|
|
|
short postests[SETSIZE];
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_test(int s, int e, struct varinfo *vi)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register test_p tp;
|
2019-05-10 17:17:24 +00:00
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
NEXT(ntests, MAXTESTS, "Tests");
|
|
|
|
tp = &l_tests[ntests - 1];
|
1985-01-08 09:59:28 +00:00
|
|
|
tp->t_set = s;
|
2019-05-10 17:17:24 +00:00
|
|
|
tp->t_expr = e;
|
1985-01-08 09:59:28 +00:00
|
|
|
tp->t_cindex = codeindex;
|
2019-05-10 17:17:24 +00:00
|
|
|
dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL);
|
|
|
|
if (tp->t_expr != 0)
|
1985-01-08 09:59:28 +00:00
|
|
|
return;
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; i < SETSIZE; i++)
|
1985-01-08 09:59:28 +00:00
|
|
|
postests[i] |= l_sets[tp->t_set].set_val[i];
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
struct varinfo *gen_test(iocc_t from)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register struct varinfo *vp;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (!subset(from.in_set, postests, SETSIZE))
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
error("No such test");
|
2019-05-10 17:17:24 +00:00
|
|
|
return (0);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
NEW(vp, struct varinfo);
|
1985-01-08 09:59:28 +00:00
|
|
|
vp->vi_int[0] = INSTEST;
|
|
|
|
vp->vi_int[1] = from.in_index;
|
2019-05-10 17:17:24 +00:00
|
|
|
return (vp);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
struct varinfo *gen_label(int arg)
|
|
|
|
{
|
1990-07-18 14:53:19 +00:00
|
|
|
register struct varinfo *vp;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
NEW(vp, struct varinfo);
|
1990-07-18 14:53:19 +00:00
|
|
|
vp->vi_int[0] = INSLABDEF;
|
|
|
|
vp->vi_int[1] = arg;
|
2019-05-10 17:17:24 +00:00
|
|
|
return (vp);
|
1990-07-18 14:53:19 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
struct varinfo *gen_preturn(void)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register struct varinfo *vp;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
NEW(vp, struct varinfo);
|
1985-01-08 09:59:28 +00:00
|
|
|
vp->vi_int[0] = INSPRETURN;
|
2019-05-10 17:17:24 +00:00
|
|
|
return (vp);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
struct varinfo *gen_tlab(int n)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register struct varinfo *vp;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
assert(n >= 0 && n <= 9);
|
|
|
|
NEW(vp, struct varinfo);
|
1985-01-08 09:59:28 +00:00
|
|
|
vp->vi_int[0] = INSTLAB;
|
|
|
|
vp->vi_int[1] = n;
|
2019-05-10 17:17:24 +00:00
|
|
|
return (vp);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int nstacks;
|
|
|
|
c1_t l_stacks[MAXSTACKS];
|
2019-05-10 17:17:24 +00:00
|
|
|
set_t ustackset, cstackset;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_stack(int s, int e, int p, struct varinfo *vi)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register c1_p c1p;
|
|
|
|
register short *sp;
|
2019-05-10 17:17:24 +00:00
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
NEXT(nstacks, MAXSTACKS, "Stacks");
|
|
|
|
c1p = &l_stacks[nstacks - 1];
|
1985-01-08 09:59:28 +00:00
|
|
|
c1p->c1_texpno = s;
|
|
|
|
c1p->c1_expr = e;
|
|
|
|
c1p->c1_prop = p;
|
|
|
|
c1p->c1_codep = codeindex;
|
2019-05-10 17:17:24 +00:00
|
|
|
dopattern(0, VI_NULL, VI_NULL, vi, VI_NULL, VI_NULL);
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (e == 0 && p == -1)
|
1985-01-08 09:59:28 +00:00
|
|
|
sp = ustackset.set_val;
|
|
|
|
else
|
|
|
|
sp = cstackset.set_val;
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; i < SETSIZE; i++)
|
1985-01-08 09:59:28 +00:00
|
|
|
sp[i] |= l_sets[s].set_val[i];
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void checkstacking(register short *sp)
|
|
|
|
{
|
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
register short *chkset;
|
|
|
|
char *warn;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (subset(sp, ustackset.set_val, SETSIZE))
|
1985-01-08 09:59:28 +00:00
|
|
|
return;
|
2019-05-10 17:17:24 +00:00
|
|
|
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);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ncoercs;
|
|
|
|
c3_t l_coercs[MAXCOERCS];
|
|
|
|
set_t unstackset;
|
|
|
|
|
|
|
|
/*VARARGS5*/
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_coerc(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, iocc_t in)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register c3_p c3p;
|
2019-05-10 17:17:24 +00:00
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
register struct varinfo *vi;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (ti != 0)
|
|
|
|
{
|
|
|
|
for (i = 0, vi = rp; vi != 0; vi = vi->vi_next, i++)
|
1985-01-08 09:59:28 +00:00
|
|
|
;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (i > 1)
|
|
|
|
{
|
|
|
|
n_split(ti, be, al, ge, rp, i);
|
1985-01-08 09:59:28 +00:00
|
|
|
return;
|
2019-05-10 17:17:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
error("Coercion should have a result!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NEW(rp, struct varinfo);
|
1985-01-08 09:59:28 +00:00
|
|
|
rp->vi_next = 0;
|
|
|
|
rp->vi_int[0] = in.in_index;
|
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
if (nallreg > 1)
|
1985-01-08 09:59:28 +00:00
|
|
|
error("More than 1 register may not be allocated");
|
2019-05-10 17:17:24 +00:00
|
|
|
NEXT(ncoercs, MAXCOERCS, "Coercions");
|
|
|
|
c3p = &l_coercs[ncoercs - 1];
|
1985-01-08 09:59:28 +00:00
|
|
|
c3p->c3_texpno = ti;
|
|
|
|
c3p->c3_expr = be;
|
2019-05-10 17:17:24 +00:00
|
|
|
c3p->c3_prop = nallreg == 0 ? -1 : allreg[0];
|
1985-01-08 09:59:28 +00:00
|
|
|
c3p->c3_repl = rp->vi_int[0];
|
|
|
|
c3p->c3_codep = codeindex;
|
2019-05-10 17:17:24 +00:00
|
|
|
dopattern(ti == 0, VI_NULL, al, ge, rp, VI_NULL);
|
|
|
|
if (ti == 0)
|
|
|
|
for (i = 0; i < SETSIZE; i++)
|
1985-01-08 09:59:28 +00:00
|
|
|
unstackset.set_val[i] |= in.in_set[i];
|
|
|
|
freevi(rp);
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void checkunstacking(int setno)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register short *sp;
|
2019-05-10 17:17:24 +00:00
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
short hallset[SETSIZE];
|
2019-05-10 17:17:24 +00:00
|
|
|
|
1985-01-08 09:59:28 +00:00
|
|
|
sp = l_sets[setno].set_val;
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; i < SETSIZE; i++)
|
|
|
|
hallset[i] = sp[i] & unstackset.set_val[i];
|
1985-01-08 09:59:28 +00:00
|
|
|
nexthall(hallset);
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int nsplit, maxsplit;
|
1985-01-08 09:59:28 +00:00
|
|
|
c2_t l_split[MAXSPLCOERC];
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_split(int ti, int be, struct varinfo *al, struct varinfo *ge, struct varinfo *rp, int n)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register c2_p c2p;
|
2019-05-10 17:17:24 +00:00
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
register struct varinfo *vi;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
NEXT(nsplit, MAXSPLCOERC, "Splitting coercions");
|
|
|
|
c2p = &l_split[nsplit - 1];
|
|
|
|
if (n > MAXSPLIT)
|
|
|
|
{
|
|
|
|
error("Maximum split factor is %d", MAXSPLIT);
|
1985-01-08 09:59:28 +00:00
|
|
|
n = MAXSPLIT;
|
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
if (n > maxsplit)
|
|
|
|
maxsplit = n;
|
1985-01-08 09:59:28 +00:00
|
|
|
c2p->c2_texpno = ti;
|
|
|
|
c2p->c2_expr = be;
|
|
|
|
if (nallreg)
|
|
|
|
error("No register uses allowed in splitting coercion");
|
|
|
|
c2p->c2_nsplit = n;
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0, vi = rp; i < n; i++, vi = vi->vi_next)
|
1985-01-08 09:59:28 +00:00
|
|
|
c2p->c2_repl[i] = vi->vi_int[0];
|
|
|
|
c2p->c2_codep = codeindex;
|
2019-05-10 17:17:24 +00:00
|
|
|
dopattern(0, VI_NULL, al, ge, rp, VI_NULL);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|