ack/util/ncgg/iocc.c

233 lines
5 KiB
C
Raw Normal View History

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