summaryrefslogtreecommitdiff
path: root/compiler_and_linker/FrontEnd/Common
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-01-13 01:38:15 +0000
committerAsh Wolf <ninji@wuffs.org>2023-01-13 01:38:15 +0000
commit08d21a052b9afc37292ec3fad390502610e2cb32 (patch)
tree270737c790f5d1bb05f68498f8233640ada6a0c5 /compiler_and_linker/FrontEnd/Common
parent54628993e0038c7bea9c064491974985b6699502 (diff)
parent9d985413ce2b60a1a8cf001913ee8dac81c03aac (diff)
downloadMWCC-08d21a052b9afc37292ec3fad390502610e2cb32.tar.gz
MWCC-08d21a052b9afc37292ec3fad390502610e2cb32.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '')
-rw-r--r--compiler_and_linker/FrontEnd/Common/CompilerTools.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/compiler_and_linker/FrontEnd/Common/CompilerTools.c b/compiler_and_linker/FrontEnd/Common/CompilerTools.c
index fff4809..272cd81 100644
--- a/compiler_and_linker/FrontEnd/Common/CompilerTools.c
+++ b/compiler_and_linker/FrontEnd/Common/CompilerTools.c
@@ -53,6 +53,69 @@ unsigned char *CTool_CtoPstr(char *cstr) {
return (unsigned char *) cstr;
}
+#ifdef CW_64_BIT_SUPPORT
+enum { PoolCapacity = 64 };
+typedef struct ITPPool {
+ void *pointers[PoolCapacity];
+ UInt32 baseIndex;
+ UInt32 size;
+ struct ITPPool *next;
+} ITPPool;
+static ITPPool *poolHead;
+static ITPPool *poolTail;
+
+void *CTool_ResolveIndexToPointer(UInt32 index) {
+ ITPPool *pool = poolHead;
+
+ if (index == 0)
+ return NULL;
+
+ while (pool && index >= PoolCapacity) {
+ pool = pool->next;
+ index -= PoolCapacity;
+ }
+
+ if (pool && index < pool->size)
+ return pool->pointers[index];
+ else
+ return NULL;
+}
+
+UInt32 CTool_CreateIndexFromPointer(void *ptr) {
+ ITPPool *pool = poolTail;
+ UInt32 index;
+
+ if (ptr == NULL)
+ return 0;
+
+ if (!pool || pool->size >= PoolCapacity) {
+ pool = lalloc(sizeof(ITPPool));
+ pool->size = 0;
+ if (poolTail) {
+ pool->baseIndex = poolTail->baseIndex + PoolCapacity;
+ poolTail->next = pool;
+ } else {
+ pool->baseIndex = 0;
+ // always reserve index 0 for NULL
+ pool->pointers[0] = NULL;
+ pool->size = 1;
+ poolHead = pool;
+ }
+ poolTail = pool;
+ }
+
+ index = pool->baseIndex + pool->size;
+ pool->pointers[pool->size] = ptr;
+ pool->size++;
+ return index;
+}
+
+static void CTool_ResetPointerPool(void) {
+ poolHead = NULL;
+ poolTail = NULL;
+}
+#endif
+
static void GListError(void) {
if (GListErrorProc)
GListErrorProc();
@@ -845,6 +908,10 @@ void freelheap(void) {
blockp->blockfree = blockp->blocksize - sizeof(HeapBlock);
blockp = blockp->next;
}
+
+#ifdef CW_64_BIT_SUPPORT
+ CTool_ResetPointerPool();
+#endif
}
}