on master help sign in
GC GMP-allocated memory
commitacce7da398375c0f0f7a02b0bd97302fea2fca3f authorBenjamin Saunders <besaunde@sfu.ca> dateThu 27 Jun 2013, 17:44 (13 years ago) parent6489978
3 files changed+28−3
llvm/Makefile+1−1 llvm/defs.c+12 src/IRTS/CodegenLLVM.hs+15−2
llvm/Makefile+1−1
@@ -1,6 +1,6 @@
11include ../config.mk
22
3−CFLAGS=-c -O2 -Wall -Wextra -fPIC
3+CFLAGS=-c -O2 -Wall -Wextra -fPIC -Wno-unused-parameter
44SOURCES=defs.c
55OBJECTS=$(SOURCES:.c=.o)
66LIB=libidris_rts.a
llvm/defs.c+12
@@ -134,3 +134,15 @@ void idris_poke(void* ptr, size_t offset, uint8_t data) {
134134void idris_memmove(void* dest, void* src, size_t dest_offset, size_t src_offset, size_t size) {
135135 memmove(dest + dest_offset, src + src_offset, size);
136136}
137+
138+void *__idris_gmpMalloc(size_t size) {
139+ return GC_malloc(size);
140+}
141+
142+void *__idris_gmpRealloc(void *ptr, size_t oldSize, size_t size) {
143+ return GC_realloc(ptr, size);
144+}
145+
146+void __idris_gmpFree(void *ptr, size_t oldSize) {
147+ GC_free(ptr);
148+}
src/IRTS/CodegenLLVM.hs+15−2
@@ -91,8 +91,13 @@ mainDef =
9191 , G.name = Name "main"
9292 , G.basicBlocks =
9393 [ BasicBlock (UnName 0)
94− [ UnName 1 := simpleCall "GC_init" []
95− , UnName 2 := idrCall "{runMain0}" [] ] -- TODO: Set GMP memory functions
94+ [ Do $ simpleCall "GC_init" [] -- Initialize Boehm GC
95+ , Do $ simpleCall "__gmp_set_memory_functions"
96+ [ ConstantOperand . C.GlobalReference . Name $ "__idris_gmpMalloc"
97+ , ConstantOperand . C.GlobalReference . Name $ "__idris_gmpRealloc"
98+ , ConstantOperand . C.GlobalReference . Name $ "__idris_gmpFree"
99+ ]
100+ , UnName 1 := idrCall "{runMain0}" [] ]
96101 (Do $ Ret (Just (ConstantOperand (C.Int 32 0))) [])
97102 ]}
98103
@@ -137,6 +142,11 @@ initDefs tgt =
137142 , exfun "GC_init" VoidType [] False
138143 , exfun "GC_malloc" ptrI8 [intPtr] False
139144 , exfun "GC_malloc_atomic" ptrI8 [intPtr] False
145+ , exfun "__gmp_set_memory_functions" VoidType
146+ [ PointerType (FunctionType ptrI8 [intPtr] False) (AddrSpace 0)
147+ , PointerType (FunctionType ptrI8 [ptrI8, intPtr, intPtr] False) (AddrSpace 0)
148+ , PointerType (FunctionType VoidType [ptrI8, intPtr] False) (AddrSpace 0)
149+ ] False
140150 , exfun "__gmpz_init" VoidType [pmpz] False
141151 , exfun "__gmpz_init_set_str" (IntegerType 32) [pmpz, ptrI8, IntegerType 32] False
142152 , exfun "__gmpz_get_str" ptrI8 [ptrI8, IntegerType 32, pmpz] False
@@ -146,6 +156,9 @@ initDefs tgt =
146156 , exfun "mpz_init_set_sll" VoidType [pmpz, IntegerType 64] False
147157 , exfun "__idris_strCons" ptrI8 [IntegerType 8, ptrI8] False
148158 , exfun "__idris_readStr" ptrI8 [ptrI8] False -- Actually pointer to FILE, but it's opaque anyway
159+ , exfun "__idris_gmpMalloc" ptrI8 [intPtr] False
160+ , exfun "__idris_gmpRealloc" ptrI8 [ptrI8, intPtr, intPtr] False
161+ , exfun "__idris_gmpFree" VoidType [ptrI8, intPtr] False
149162 , exfun "strtoll" (IntegerType 64) [ptrI8, PointerType ptrI8 (AddrSpace 0), IntegerType 32] False
150163 , exVar "stdin" ptrI8
151164 , exVar "stdout" ptrI8