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