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