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
|
|
|
|
|
2006-07-18 17:18:42 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1985-01-08 09:59:28 +00:00
|
|
|
#include "param.h"
|
|
|
|
#include "reg.h"
|
|
|
|
#include "lookup.h"
|
|
|
|
#include "property.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "set.h"
|
|
|
|
#include "varinfo.h"
|
|
|
|
#include "instruct.h"
|
|
|
|
#include "token.h"
|
|
|
|
#include "regvar.h"
|
|
|
|
#include <cgg_cg.h>
|
2017-10-14 16:40:04 +00:00
|
|
|
#include <em_reg.h>
|
2019-05-10 17:17:24 +00:00
|
|
|
#include "subr.h"
|
|
|
|
#include "hall.h"
|
1985-01-08 09:59:28 +00:00
|
|
|
#include "extern.h"
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
extern int npatbytes;
|
|
|
|
extern set_t l_sets[];
|
|
|
|
|
|
|
|
|
|
|
|
void n_proc(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, symproc, newsymbol);
|
1987-01-16 13:51:42 +00:00
|
|
|
sy_p->sy_value.syv_procoff = npatbytes + 1;
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
struct varinfo * make_erase(char *name)
|
|
|
|
{
|
|
|
|
expr_t e;
|
1985-01-08 09:59:28 +00:00
|
|
|
struct varinfo *result;
|
|
|
|
|
|
|
|
e = ident_expr(name);
|
|
|
|
if (e.ex_typ != TYPREG)
|
|
|
|
error("Register name required here");
|
2019-05-10 17:17:24 +00:00
|
|
|
NEW(result, struct varinfo);
|
1985-01-08 09:59:28 +00:00
|
|
|
result->vi_next = VI_NULL;
|
|
|
|
result->vi_int[0] = e.ex_index;
|
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
|
|
|
void n_instr(char *name, char *asname, operand *oplist, struct varinfo *eraselist,
|
|
|
|
struct varinfo *cost)
|
1985-01-08 09:59:28 +00:00
|
|
|
{
|
2019-05-10 17:17:24 +00:00
|
|
|
register int instrno;
|
|
|
|
register int cc_count;
|
1985-01-08 09:59:28 +00:00
|
|
|
register instr_p ip;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
instrno = NEXT(ninstr, MAXINSTR, "Instructions");
|
1985-01-08 09:59:28 +00:00
|
|
|
ip = &l_instr[instrno];
|
|
|
|
ip->i_name = name;
|
2019-05-10 17:17:24 +00:00
|
|
|
ip->i_asname = strlookup(asname != 0 ? asname : name);
|
1985-01-08 09:59:28 +00:00
|
|
|
ip->i_nops = 0;
|
|
|
|
ip->i_oplist = oplist;
|
|
|
|
ip->i_erases = eraselist;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (cost == 0)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
ip->i_cost.ct_space = 0;
|
|
|
|
ip->i_cost.ct_time = 0;
|
2019-05-10 17:17:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
ip->i_cost.ct_space = cost->vi_int[0];
|
|
|
|
ip->i_cost.ct_space = cost->vi_int[1];
|
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
for (cc_count = 0; oplist != 0; oplist = oplist->o_next)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
ip->i_nops++;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (oplist->o_adorn & AD_CC)
|
1985-01-08 09:59:28 +00:00
|
|
|
cc_count++;
|
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
while (eraselist != VI_NULL )
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
if (eraselist->vi_int[0] == -1 && cc_count)
|
|
|
|
error("Instruction can't both set and break the condition codes");
|
2019-05-10 17:17:24 +00:00
|
|
|
eraselist = eraselist->vi_next;
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
if (cc_count > 1)
|
1985-01-08 09:59:28 +00:00
|
|
|
error("No instruction can set condition codes more than once");
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_set(char *name, int number)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register symbol *sy_p;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
sy_p = lookup(name, symset, newsymbol);
|
1985-01-08 09:59:28 +00:00
|
|
|
sy_p->sy_value.syv_setno = number;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_tok(char *name, struct varinfo *atts, int size,
|
|
|
|
struct varinfo *cost, struct varinfo *format)
|
1985-01-08 09:59:28 +00:00
|
|
|
{
|
|
|
|
register symbol *sy_p;
|
|
|
|
register token_p tp;
|
|
|
|
register struct varinfo *vip;
|
|
|
|
int i;
|
|
|
|
int tokno;
|
1986-05-21 15:08:57 +00:00
|
|
|
int thistokensize;
|
2019-05-10 17:17:24 +00:00
|
|
|
char formstr[50], smallstr[2];
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
sy_p = lookup(name, symtok, newsymbol);
|
|
|
|
NEW(tp, token_t);
|
|
|
|
tokno = NEXT(ntokens, MAXTOKENS, "Tokens");
|
1985-01-08 09:59:28 +00:00
|
|
|
sy_p->sy_value.syv_tokno = tokno;
|
|
|
|
l_tokens[tokno] = tp;
|
|
|
|
tp->tk_name = sy_p->sy_name;
|
|
|
|
tp->tk_size = size;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (cost != 0)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
tp->tk_cost.ct_space = cost->vi_int[0];
|
2019-05-10 17:17:24 +00:00
|
|
|
tp->tk_cost.ct_time = cost->vi_int[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
tp->tk_cost.ct_space = 0;
|
2019-05-10 17:17:24 +00:00
|
|
|
tp->tk_cost.ct_time = 0;
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0, vip = atts; i < MAXATT && vip != 0; i++, vip = vip->vi_next)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
tp->tk_att[i].ta_type = vip->vi_int[0];
|
|
|
|
tp->tk_att[i].ta_name = vip->vi_str[0];
|
2019-05-10 17:17:24 +00:00
|
|
|
vip->vi_str[0] = 0;
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
thistokensize = i;
|
|
|
|
if (i > maxtokensize)
|
|
|
|
maxtokensize = i;
|
|
|
|
if (vip != 0)
|
|
|
|
error("More then %d attributes, rest discarded", MAXATT);
|
|
|
|
for (; i < MAXATT; i++)
|
|
|
|
tp->tk_att[i].ta_type = -3;
|
|
|
|
if (format != 0)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
formstr[0] = 0;
|
2019-05-10 17:17:24 +00:00
|
|
|
for (vip = format; vip != 0; vip = vip->vi_next)
|
|
|
|
{
|
|
|
|
if (vip->vi_int[0] == 0)
|
|
|
|
strcat(formstr, vip->vi_str[0]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < thistokensize; i++)
|
|
|
|
{
|
|
|
|
if (strcmp(vip->vi_str[0], tp->tk_att[i].ta_name) == 0)
|
|
|
|
{
|
|
|
|
smallstr[0] = i + 1;
|
1985-01-08 09:59:28 +00:00
|
|
|
smallstr[1] = 0;
|
2019-05-10 17:17:24 +00:00
|
|
|
strcat(formstr, smallstr);
|
1985-01-08 09:59:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
if (i == thistokensize)
|
|
|
|
error("%s not a known attribute", vip->vi_str[0]);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tp->tk_format = strlookup(formstr);
|
2019-05-10 17:17:24 +00:00
|
|
|
}
|
|
|
|
else
|
1985-01-08 09:59:28 +00:00
|
|
|
tp->tk_format = -1;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void checkprintformat(int n)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register short *s;
|
2019-05-10 17:17:24 +00:00
|
|
|
register int i;
|
|
|
|
|
|
|
|
s = l_sets[n].set_val;
|
|
|
|
for (i = nregs; i < nregs + ntokens; i++)
|
|
|
|
if (BIT(s,i) && l_tokens[i - nregs]->tk_format < 0)
|
1985-01-08 09:59:28 +00:00
|
|
|
error("Token %s in set does not have printformat",
|
2019-05-10 17:17:24 +00:00
|
|
|
l_tokens[i - nregs]->tk_name);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_prop(char *name, int size)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
int propno;
|
|
|
|
register symbol *sp;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
propno = NEXT(nprops, MAXPROPS, "Properties");
|
|
|
|
sp = lookup(name, symprop, newsymbol);
|
1985-01-08 09:59:28 +00:00
|
|
|
sp->sy_value.syv_propno = propno;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (size <= 0)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
error("Size of property must be >0");
|
|
|
|
size = wordsize;
|
|
|
|
}
|
|
|
|
l_props[propno].pr_size = size;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void prophall(int n)
|
|
|
|
{
|
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
short hallset[SETSIZE];
|
2019-05-10 17:17:24 +00:00
|
|
|
|
|
|
|
if (n < 0)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < SETSIZE; i++)
|
|
|
|
hallset[i] = i < SZOFSET(MAXREGS) ? l_props[n].pr_regset[i] : 0;
|
1985-01-08 09:59:28 +00:00
|
|
|
nexthall(hallset);
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int n_reg(char *name, char *printstring, int nmemb, int member1, int member2)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register symbol *sy_p;
|
|
|
|
register reginfo *ri_p;
|
|
|
|
int regno;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
sy_p = lookup(name, symreg, newsymbol);
|
|
|
|
sy_p->sy_value.syv_regno = regno = NEXT(nregs, MAXREGS,
|
|
|
|
"Number of registers");
|
1985-01-08 09:59:28 +00:00
|
|
|
ri_p = &l_regs[regno];
|
|
|
|
ri_p->ri_name = mystrcpy(name);
|
2019-05-10 17:17:24 +00:00
|
|
|
ri_p->ri_repr = printstring != 0 ? mystrcpy(printstring) : ri_p->ri_name;
|
1985-01-08 09:59:28 +00:00
|
|
|
ri_p->ri_memb[0] = member1;
|
|
|
|
ri_p->ri_memb[1] = member2;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (nmemb > maxmembers)
|
|
|
|
maxmembers = nmemb;
|
|
|
|
return (regno);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void make_const(void)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
|
|
|
|
wordsize = cmustbeset("EM_WSIZE");
|
|
|
|
pointersize = cmustbeset("EM_PSIZE");
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int cmustbeset(char *ident)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
return (lookup(ident, symconst, mustexist)->sy_value.syv_cstval);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_const(char *ident, int val)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register symbol *sy_p;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
sy_p = lookup(ident, symconst, newsymbol);
|
1985-01-08 09:59:28 +00:00
|
|
|
sy_p->sy_value.syv_cstval = val;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void n_sconst(char *ident, char *val)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register symbol *sy_p;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
sy_p = lookup(ident, symsconst, newsymbol);
|
1985-01-08 09:59:28 +00:00
|
|
|
sy_p->sy_value.syv_stringno = strlookup(val);
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
static void add_regvar(int rvnum, reginfo *regp, int rv)
|
2017-10-14 16:40:04 +00:00
|
|
|
{
|
|
|
|
int overlap, wrong;
|
|
|
|
|
|
|
|
overlap = wrong = 0;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (regp->ri_memb[0] != 0)
|
|
|
|
{
|
2017-10-14 16:40:04 +00:00
|
|
|
/* reglap: float may overlap with one subregister */
|
2019-05-10 17:17:24 +00:00
|
|
|
if (rv == reg_float && regp->ri_memb[1] == 0)
|
2017-10-14 16:40:04 +00:00
|
|
|
overlap = 1;
|
|
|
|
else
|
|
|
|
wrong = 1;
|
|
|
|
}
|
|
|
|
if (wrong)
|
|
|
|
error("Register variables may not have subregisters");
|
|
|
|
|
|
|
|
rvused |= ANY_REGVAR;
|
|
|
|
if (regp->ri_size == wordsize)
|
|
|
|
rvused |= SL_REGVAR;
|
2019-05-10 17:17:24 +00:00
|
|
|
else if (regp->ri_size == 2 * wordsize)
|
2017-10-14 16:40:04 +00:00
|
|
|
rvused |= DL_REGVAR;
|
|
|
|
|
|
|
|
wrong = 0;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (overlap)
|
|
|
|
{
|
2017-10-14 16:40:04 +00:00
|
|
|
/* reglap = size of overlap float */
|
2019-05-10 17:17:24 +00:00
|
|
|
if (reglap == 0)
|
|
|
|
{
|
2017-10-14 16:40:04 +00:00
|
|
|
reglap = regp->ri_size;
|
2017-10-19 02:00:12 +00:00
|
|
|
if (reglap == rvsize[reg_float])
|
|
|
|
error("Two sizes of reg_float can't be same size");
|
2019-05-10 17:17:24 +00:00
|
|
|
}
|
|
|
|
else if (reglap != regp->ri_size)
|
2017-10-14 16:40:04 +00:00
|
|
|
wrong = 1;
|
2019-05-10 17:17:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nregvar[rv] == 0)
|
2017-10-14 16:40:04 +00:00
|
|
|
rvsize[rv] = regp->ri_size;
|
2019-05-10 17:17:24 +00:00
|
|
|
else if (rvsize[rv] != regp->ri_size)
|
2017-10-14 16:40:04 +00:00
|
|
|
wrong = 1;
|
|
|
|
}
|
|
|
|
if (wrong)
|
|
|
|
error("All register variables of one type must have the same size");
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (overlap)
|
|
|
|
{
|
2017-10-14 16:40:04 +00:00
|
|
|
reginfo *member_p = &l_regs[regp->ri_memb[0]];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reglap: Remove member_p from rvnumbers.
|
|
|
|
* Add reg_p in its place.
|
|
|
|
*/
|
|
|
|
wrong = 1;
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; i < nregvar[rv]; i++)
|
|
|
|
{
|
|
|
|
if (rvnumbers[rv][i] == regp->ri_memb[0])
|
|
|
|
{
|
2017-10-14 16:40:04 +00:00
|
|
|
rvnumbers[rv][i] = rvnum;
|
|
|
|
wrong = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wrong)
|
2019-05-10 17:17:24 +00:00
|
|
|
error("Register variable %s can't overlap %s", regp->ri_name,
|
|
|
|
member_p->ri_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NEXT(nregvar[rv], MAXREGVAR, "Register variable");
|
|
|
|
rvnumbers[rv][nregvar[rv] - 1] = rvnum;
|
2017-10-14 16:40:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void regline(varinfo *rl, varinfo *pl, int rv)
|
|
|
|
{
|
|
|
|
register varinfo *rrl, *rpl;
|
1985-01-08 09:59:28 +00:00
|
|
|
register short *sp;
|
|
|
|
register reginfo *regp;
|
|
|
|
int thissize;
|
|
|
|
int propno;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
for (rrl = rl; rrl != 0; rrl = rrl->vi_next)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
regp = &l_regs[rrl->vi_int[0]];
|
|
|
|
thissize = 0;
|
2019-05-10 17:17:24 +00:00
|
|
|
for (rpl = pl; rpl != 0; rpl = rpl->vi_next)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
propno = rpl->vi_int[0];
|
2019-05-10 17:17:24 +00:00
|
|
|
sp = l_props[propno].pr_regset;
|
|
|
|
BIS(sp, rrl->vi_int[0]);
|
|
|
|
if (thissize == 0)
|
1985-01-08 09:59:28 +00:00
|
|
|
thissize = l_props[propno].pr_size;
|
2019-05-10 17:17:24 +00:00
|
|
|
else if (thissize != -1 && thissize != l_props[propno].pr_size)
|
|
|
|
error("Register %s has no clear size", regp->ri_name);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
regp->ri_size = thissize;
|
|
|
|
regp->ri_class = regclass;
|
|
|
|
regp->ri_rregvar = rv;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (rv >= 0)
|
2017-10-14 16:40:04 +00:00
|
|
|
add_regvar(rrl->vi_int[0], regp, rv);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
regclass++;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void check_reglap(void)
|
|
|
|
{
|
2017-10-19 02:00:12 +00:00
|
|
|
reginfo *regp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (reglap == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* reglap: Check that every reg_float has size == reglap. */
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; i < nregvar[reg_float]; i++)
|
|
|
|
{
|
2017-10-19 02:00:12 +00:00
|
|
|
regp = &l_regs[rvnumbers[reg_float][i]];
|
|
|
|
if (regp->ri_size != reglap)
|
2019-05-10 17:17:24 +00:00
|
|
|
error("Missing reg_float of size %d to contain %s", reglap,
|
|
|
|
regp->ri_name);
|
2017-10-19 02:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void setallreg(struct varinfo *vi)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
nallreg = 0;
|
|
|
|
for (; vi != 0; vi = vi->vi_next)
|
|
|
|
{
|
|
|
|
if (vi->vi_int[0] < 0)
|
1985-01-08 09:59:28 +00:00
|
|
|
continue;
|
|
|
|
allreg[nallreg++] = vi->vi_int[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
void freevi(register struct varinfo *vip)
|
|
|
|
{
|
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (vip == 0)
|
1985-01-08 09:59:28 +00:00
|
|
|
return;
|
|
|
|
freevi(vip->vi_next);
|
|
|
|
freevi(vip->vi_vi);
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; i < VI_NSTR; i++)
|
2006-07-23 19:38:13 +00:00
|
|
|
free((char *) vip->vi_str[i]);
|
1985-01-08 09:59:28 +00:00
|
|
|
free(vip);
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int myatoi(register char *s)
|
|
|
|
{
|
|
|
|
register int base = 10;
|
|
|
|
register int sum = 0;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (*s == '0')
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
base = 8;
|
|
|
|
s++;
|
2019-05-10 17:17:24 +00:00
|
|
|
if (*s == 'x')
|
|
|
|
{
|
|
|
|
base = 16;
|
1985-01-08 09:59:28 +00:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
switch (*s)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return (sum);
|
|
|
|
case '8':
|
|
|
|
case '9':
|
|
|
|
if (base == 8)
|
|
|
|
error("Bad digit in octal number");
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
sum = sum * base + *s++ - '0';
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
case 'b':
|
|
|
|
case 'c':
|
|
|
|
case 'd':
|
|
|
|
case 'e':
|
|
|
|
case 'f':
|
|
|
|
if (base != 16)
|
|
|
|
error("Hexletter in number not expected");
|
|
|
|
sum = sum * base + 10 + *s++ - 'a';
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
case 'B':
|
|
|
|
case 'C':
|
|
|
|
case 'D':
|
|
|
|
case 'E':
|
|
|
|
case 'F':
|
|
|
|
if (base != 16)
|
|
|
|
error("Hexletter in number not expected");
|
|
|
|
sum = sum * base + 10 + *s++ - 'A';
|
|
|
|
break;
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
char *mystrcpy(char *s)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
register char *p;
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
p = myalloc(strlen(s) + 1);
|
|
|
|
strcpy(p, s);
|
|
|
|
return (p);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
char *myalloc(register int n)
|
|
|
|
{
|
|
|
|
register char *p, *result;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
result = p = malloc(n);
|
|
|
|
if (p == (char *) 0)
|
1985-01-08 09:59:28 +00:00
|
|
|
fatal("Out of memory");
|
2019-05-10 17:17:24 +00:00
|
|
|
do
|
|
|
|
*p++ = 0;
|
|
|
|
while (--n);
|
|
|
|
return (result);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int chkincl(int value, int lwb, int upb)
|
|
|
|
{
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
if (value < lwb || value > upb)
|
|
|
|
error("Number %d should have been between %d and %d", value, lwb, upb);
|
|
|
|
return (value);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int subset(short *sp1, short *sp2, int setsize)
|
|
|
|
{
|
|
|
|
register int i;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
for (i = 0; i < setsize; i++)
|
|
|
|
if ((sp1[i] | sp2[i]) != sp2[i])
|
|
|
|
return (0);
|
|
|
|
return (1);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
int vilength(register struct varinfo *vip)
|
|
|
|
{
|
|
|
|
register int l = 0;
|
1985-01-08 09:59:28 +00:00
|
|
|
|
2019-05-10 17:17:24 +00:00
|
|
|
while (vip != 0)
|
|
|
|
{
|
|
|
|
vip = vip->vi_next;
|
1985-01-08 09:59:28 +00:00
|
|
|
l++;
|
|
|
|
}
|
2019-05-10 17:17:24 +00:00
|
|
|
return (l);
|
1985-01-08 09:59:28 +00:00
|
|
|
}
|