factor some utility functions/data in util.c

This commit is contained in:
Quentin Carbonneaux 2015-10-05 17:23:54 -04:00
parent cb4d738c36
commit e30fab31e1
7 changed files with 97 additions and 101 deletions

View file

@ -8,8 +8,6 @@ enum {
NCon = 256,
};
Ins insb[NIns], *curi;
OpDesc opdesc[NOp] = {
/* NAME NM */
[OAdd] = { "add", 2 },
@ -55,9 +53,6 @@ OpDesc opdesc[NOp] = {
#undef X
};
Typ typ[NTyp];
static int ntyp;
typedef enum {
PXXX,
PLbl,
@ -117,31 +112,9 @@ static Blk *curb;
static Blk **blink;
static int nblk;
static int rcls;
static int ntyp;
void *
alloc(size_t n)
{
void *p;
/* todo, export in util.c */
if (n == 0)
return 0;
p = calloc(1, n);
if (!p)
abort();
return p;
}
void
diag(char *s)
{
/* todo, export in util.c */
fputs(s, stderr);
fputc('\n', stderr);
abort();
}
static void
err(char *s)
{
@ -318,18 +291,6 @@ expect(int t)
err(buf);
}
Blk *
blocka()
{
static Blk zblock;
Blk *b;
b = alloc(sizeof *b);
*b = zblock;
b->id = nblk++;
return b;
}
static Ref
tmpref(char *v, int use)
{
@ -452,6 +413,7 @@ findblk(char *name)
err("too many blocks");
if (!bmap[i]) {
bmap[i] = blocka();
nblk++;
strcpy(bmap[i]->name, name);
}
return bmap[i];