Merge branch 'nasm-2.03.x'
[platform/upstream/nasm.git] / raa.h
1 #ifndef NASM_RAA_H
2 #define NASM_RAA_H 1
3
4 #include "compiler.h"
5
6 /*
7  * Routines to manage a dynamic random access array of int64_ts which
8  * may grow in size to be more than the largest single malloc'able
9  * chunk.
10  */
11
12 #define RAA_BLKSHIFT    15      /* 2**this many longs allocated at once */
13 #define RAA_BLKSIZE     (1 << RAA_BLKSHIFT)
14 #define RAA_LAYERSHIFT  15      /* 2**this many _pointers_ allocated */
15 #define RAA_LAYERSIZE   (1 << RAA_LAYERSHIFT)
16
17 typedef struct RAA RAA;
18 typedef union RAA_UNION RAA_UNION;
19 typedef struct RAA_LEAF RAA_LEAF;
20 typedef struct RAA_BRANCH RAA_BRANCH;
21
22 struct RAA {
23     /*
24      * Number of layers below this one to get to the real data. 0
25      * means this structure is a leaf, holding RAA_BLKSIZE real
26      * data items; 1 and above mean it's a branch, holding
27      * RAA_LAYERSIZE pointers to the next level branch or leaf
28      * structures.
29      */
30     int layers;
31
32     /*
33      * Number of real data items spanned by one position in the
34      * `data' array at this level. This number is 0 trivially, for
35      * a leaf (level 0): for a level 1 branch it should be
36      * RAA_BLKSHIFT, and for a level 2 branch it's
37      * RAA_LAYERSHIFT+RAA_BLKSHIFT.
38      */
39     int shift;
40
41     union RAA_UNION {
42         struct RAA_LEAF {
43             int64_t data[RAA_BLKSIZE];
44         } l;
45         struct RAA_BRANCH {
46             struct RAA *data[RAA_LAYERSIZE];
47         } b;
48     } u;
49 };
50
51 struct RAA *raa_init(void);
52 void raa_free(struct RAA *);
53 int64_t raa_read(struct RAA *, int32_t);
54 struct RAA *raa_write(struct RAA *r, int32_t posn, int64_t value);
55
56 #endif /* NASM_RAA_H */