-
Notifications
You must be signed in to change notification settings - Fork 11
/
idxdata.c
35 lines (31 loc) · 795 Bytes
/
idxdata.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Indexed data. We keep various random little vectors attached to
* things in order to track stuff like array sizes and struct fields
*
* This manages them
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "compiler.h"
static unsigned idxmem[IDX_SIZE];
static unsigned *idxptr = idxmem;
/*
* Simple for now - we may well be able to brk() this pool although
* we will have to decide if we fix the pool or the symbol table size..
*/
unsigned *idx_get(unsigned len)
{
/* len is in words */
unsigned *p = idxptr;
idxptr += len;
if (idxptr >= idxmem + IDX_SIZE)
fatal("out of index memory");
return p;
}
unsigned *idx_copy(unsigned *p, unsigned n)
{
unsigned *r = idx_get(n);
memcpy(r, p, n * sizeof(unsigned));
return r;
}