summaryrefslogtreecommitdiff
path: root/raa.h
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-09 17:40:16 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-09 17:40:16 -0700
commitfcb8909749b2a159ba7f32fec7df8e465a974f77 (patch)
tree59a257a1d223ca0ed0f3e410830b0cc8544804d0 /raa.h
parent35d620d2fdd6bfb1502c7db60ad8331edf74354e (diff)
downloadnasm-fcb8909749b2a159ba7f32fec7df8e465a974f77.tar.gz
nasm-fcb8909749b2a159ba7f32fec7df8e465a974f77.tar.bz2
nasm-fcb8909749b2a159ba7f32fec7df8e465a974f77.zip
Move all the RAA code out of nasmlib
The RAA code doesn't have to be in nasmlib; it is only used by nasm itself, and is better handled in a separate module.
Diffstat (limited to 'raa.h')
-rw-r--r--raa.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/raa.h b/raa.h
new file mode 100644
index 0000000..665e728
--- /dev/null
+++ b/raa.h
@@ -0,0 +1,56 @@
+#ifndef NASM_RAA_H
+#define NASM_RAA_H 1
+
+#include "compiler.h"
+
+/*
+ * Routines to manage a dynamic random access array of int64_ts which
+ * may grow in size to be more than the largest single malloc'able
+ * chunk.
+ */
+
+#define RAA_BLKSHIFT 15 /* 2**this many longs allocated at once */
+#define RAA_BLKSIZE (1 << RAA_BLKSHIFT)
+#define RAA_LAYERSHIFT 15 /* 2**this many _pointers_ allocated */
+#define RAA_LAYERSIZE (1 << RAA_LAYERSHIFT)
+
+typedef struct RAA RAA;
+typedef union RAA_UNION RAA_UNION;
+typedef struct RAA_LEAF RAA_LEAF;
+typedef struct RAA_BRANCH RAA_BRANCH;
+
+struct RAA {
+ /*
+ * Number of layers below this one to get to the real data. 0
+ * means this structure is a leaf, holding RAA_BLKSIZE real
+ * data items; 1 and above mean it's a branch, holding
+ * RAA_LAYERSIZE pointers to the next level branch or leaf
+ * structures.
+ */
+ int layers;
+
+ /*
+ * Number of real data items spanned by one position in the
+ * `data' array at this level. This number is 0 trivially, for
+ * a leaf (level 0): for a level 1 branch it should be
+ * RAA_BLKSHIFT, and for a level 2 branch it's
+ * RAA_LAYERSHIFT+RAA_BLKSHIFT.
+ */
+ int shift;
+
+ union RAA_UNION {
+ struct RAA_LEAF {
+ int64_t data[RAA_BLKSIZE];
+ } l;
+ struct RAA_BRANCH {
+ struct RAA *data[RAA_LAYERSIZE];
+ } b;
+ } u;
+};
+
+struct RAA *raa_init(void);
+void raa_free(struct RAA *);
+int64_t raa_read(struct RAA *, int32_t);
+struct RAA *raa_write(struct RAA *r, int32_t posn, int64_t value);
+
+#endif /* NASM_RAA_H */