@@ -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