blob: e956dbebaffe77ac8aca9b048e9f05c3d2f98001 [file] [log] [blame]
Gordon Henriksen2a8cd892007-12-23 16:59:28 +00001//===-- ExecutionEngineBindings.cpp - C bindings for EEs ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Gordon Henriksen2a8cd892007-12-23 16:59:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the C bindings for the ExecutionEngine library.
11//
12//===----------------------------------------------------------------------===//
13
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000014#include "llvm-c/ExecutionEngine.h"
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000015#include "llvm/ExecutionEngine/ExecutionEngine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "llvm/ExecutionEngine/GenericValue.h"
Filip Pizlo3fdbaff2013-05-22 02:46:43 +000017#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
Filip Pizlodec20e42013-05-01 20:59:00 +000018#include "llvm/IR/DerivedTypes.h"
19#include "llvm/IR/Module.h"
Duncan P. N. Exon Smith3f7f8832016-02-13 22:58:43 +000020#include "llvm/Support/CodeGenCWrappers.h"
Torok Edwin56d06592009-07-11 20:10:48 +000021#include "llvm/Support/ErrorHandling.h"
Sanjay Pateld9fb62e2015-06-01 21:56:56 +000022#include "llvm/Target/TargetOptions.h"
Anton Korobeynikov579f0712008-02-20 11:08:44 +000023#include <cstring>
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000024
25using namespace llvm;
26
Chandler Carruthf58e3762014-04-22 03:04:17 +000027#define DEBUG_TYPE "jit"
28
Eric Christopher04d4e932013-04-22 22:47:22 +000029// Wrapping the C bindings types.
Filip Pizlodec20e42013-05-01 20:59:00 +000030DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue, LLVMGenericValueRef)
Eric Christopher04d4e932013-04-22 22:47:22 +000031
Eric Christopher04d4e932013-04-22 22:47:22 +000032
Diego Novillocd973c42015-07-27 18:27:23 +000033static LLVMTargetMachineRef wrap(const TargetMachine *P) {
Juergen Ributzka5fe955c2014-01-23 19:23:28 +000034 return
35 reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
36}
37
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000038/*===-- Operations on generic values --------------------------------------===*/
39
40LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
41 unsigned long long N,
Chris Lattner25963c62010-01-09 22:27:07 +000042 LLVMBool IsSigned) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000043 GenericValue *GenVal = new GenericValue();
44 GenVal->IntVal = APInt(unwrap<IntegerType>(Ty)->getBitWidth(), N, IsSigned);
45 return wrap(GenVal);
46}
47
48LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P) {
49 GenericValue *GenVal = new GenericValue();
50 GenVal->PointerVal = P;
51 return wrap(GenVal);
52}
53
54LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef TyRef, double N) {
55 GenericValue *GenVal = new GenericValue();
56 switch (unwrap(TyRef)->getTypeID()) {
57 case Type::FloatTyID:
58 GenVal->FloatVal = N;
59 break;
60 case Type::DoubleTyID:
61 GenVal->DoubleVal = N;
62 break;
63 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +000064 llvm_unreachable("LLVMGenericValueToFloat supports only float and double.");
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000065 }
66 return wrap(GenVal);
67}
68
69unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef) {
70 return unwrap(GenValRef)->IntVal.getBitWidth();
71}
72
73unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenValRef,
Chris Lattner25963c62010-01-09 22:27:07 +000074 LLVMBool IsSigned) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000075 GenericValue *GenVal = unwrap(GenValRef);
76 if (IsSigned)
77 return GenVal->IntVal.getSExtValue();
78 else
79 return GenVal->IntVal.getZExtValue();
80}
81
82void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal) {
83 return unwrap(GenVal)->PointerVal;
84}
85
86double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal) {
87 switch (unwrap(TyRef)->getTypeID()) {
88 case Type::FloatTyID:
89 return unwrap(GenVal)->FloatVal;
90 case Type::DoubleTyID:
91 return unwrap(GenVal)->DoubleVal;
92 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +000093 llvm_unreachable("LLVMGenericValueToFloat supports only float and double.");
Gordon Henriksen2a8cd892007-12-23 16:59:28 +000094 }
95}
96
97void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal) {
98 delete unwrap(GenVal);
99}
100
101/*===-- Operations on execution engines -----------------------------------===*/
102
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000103LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
104 LLVMModuleRef M,
105 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000106 std::string Error;
Rafael Espindola2a8a2792014-08-19 04:04:25 +0000107 EngineBuilder builder(std::unique_ptr<Module>(unwrap(M)));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000108 builder.setEngineKind(EngineKind::Either)
109 .setErrorStr(&Error);
110 if (ExecutionEngine *EE = builder.create()){
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000111 *OutEE = wrap(EE);
112 return 0;
113 }
114 *OutError = strdup(Error.c_str());
115 return 1;
116}
117
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000118LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
119 LLVMModuleRef M,
120 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000121 std::string Error;
Rafael Espindola2a8a2792014-08-19 04:04:25 +0000122 EngineBuilder builder(std::unique_ptr<Module>(unwrap(M)));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000123 builder.setEngineKind(EngineKind::Interpreter)
124 .setErrorStr(&Error);
125 if (ExecutionEngine *Interp = builder.create()) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000126 *OutInterp = wrap(Interp);
127 return 0;
128 }
129 *OutError = strdup(Error.c_str());
130 return 1;
131}
132
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000133LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
134 LLVMModuleRef M,
135 unsigned OptLevel,
136 char **OutError) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000137 std::string Error;
Rafael Espindola2a8a2792014-08-19 04:04:25 +0000138 EngineBuilder builder(std::unique_ptr<Module>(unwrap(M)));
Reid Klecknerfc8a2d52009-07-18 00:42:18 +0000139 builder.setEngineKind(EngineKind::JIT)
140 .setErrorStr(&Error)
141 .setOptLevel((CodeGenOpt::Level)OptLevel);
142 if (ExecutionEngine *JIT = builder.create()) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000143 *OutJIT = wrap(JIT);
144 return 0;
145 }
146 *OutError = strdup(Error.c_str());
147 return 1;
148}
149
Filip Pizlo85e0d272013-05-01 22:58:00 +0000150void LLVMInitializeMCJITCompilerOptions(LLVMMCJITCompilerOptions *PassedOptions,
151 size_t SizeOfPassedOptions) {
152 LLVMMCJITCompilerOptions options;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000153 memset(&options, 0, sizeof(options)); // Most fields are zero by default.
Filip Pizlo85e0d272013-05-01 22:58:00 +0000154 options.CodeModel = LLVMCodeModelJITDefault;
Filip Pizlo85e0d272013-05-01 22:58:00 +0000155
156 memcpy(PassedOptions, &options,
157 std::min(sizeof(options), SizeOfPassedOptions));
158}
159
160LLVMBool LLVMCreateMCJITCompilerForModule(
161 LLVMExecutionEngineRef *OutJIT, LLVMModuleRef M,
162 LLVMMCJITCompilerOptions *PassedOptions, size_t SizeOfPassedOptions,
163 char **OutError) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000164 LLVMMCJITCompilerOptions options;
165 // If the user passed a larger sized options struct, then they were compiled
166 // against a newer LLVM. Tell them that something is wrong.
167 if (SizeOfPassedOptions > sizeof(options)) {
168 *OutError = strdup(
Filip Pizlo85e0d272013-05-01 22:58:00 +0000169 "Refusing to use options struct that is larger than my own; assuming "
170 "LLVM library mismatch.");
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000171 return 1;
172 }
173
174 // Defend against the user having an old version of the API by ensuring that
175 // any fields they didn't see are cleared. We must defend against fields being
176 // set to the bitwise equivalent of zero, and assume that this means "do the
177 // default" as if that option hadn't been available.
Filip Pizlo85e0d272013-05-01 22:58:00 +0000178 LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000179 memcpy(&options, PassedOptions, SizeOfPassedOptions);
180
181 TargetOptions targetOptions;
Filip Pizlo85e0d272013-05-01 22:58:00 +0000182 targetOptions.EnableFastISel = options.EnableFastISel;
Akira Hatanakaddf76aa2015-05-23 01:14:08 +0000183 std::unique_ptr<Module> Mod(unwrap(M));
184
185 if (Mod)
186 // Set function attribute "no-frame-pointer-elim" based on
187 // NoFramePointerElim.
Akira Hatanakae36505c2015-05-26 20:17:20 +0000188 for (auto &F : *Mod) {
189 auto Attrs = F.getAttributes();
Mehdi Amini7419e942016-10-01 06:22:04 +0000190 StringRef Value(options.NoFramePointerElim ? "true" : "false");
Reid Klecknerb5180542017-03-21 16:57:19 +0000191 Attrs = Attrs.addAttribute(F.getContext(), AttributeList::FunctionIndex,
Akira Hatanakae36505c2015-05-26 20:17:20 +0000192 "no-frame-pointer-elim", Value);
193 F.setAttributes(Attrs);
194 }
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000195
196 std::string Error;
Akira Hatanakaddf76aa2015-05-23 01:14:08 +0000197 EngineBuilder builder(std::move(Mod));
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000198 builder.setEngineKind(EngineKind::JIT)
199 .setErrorStr(&Error)
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000200 .setOptLevel((CodeGenOpt::Level)options.OptLevel)
Filip Pizlo85e0d272013-05-01 22:58:00 +0000201 .setCodeModel(unwrap(options.CodeModel))
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000202 .setTargetOptions(targetOptions);
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000203 if (options.MCJMM)
Lang Hames4a5697e2014-12-03 00:51:19 +0000204 builder.setMCJITMemoryManager(
205 std::unique_ptr<RTDyldMemoryManager>(unwrap(options.MCJMM)));
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000206 if (ExecutionEngine *JIT = builder.create()) {
207 *OutJIT = wrap(JIT);
208 return 0;
209 }
210 *OutError = strdup(Error.c_str());
211 return 1;
212}
213
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000214void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE) {
215 delete unwrap(EE);
216}
217
218void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE) {
Amaury Sechet74f4ce62016-01-15 00:23:34 +0000219 unwrap(EE)->finalizeObject();
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000220 unwrap(EE)->runStaticConstructorsDestructors(false);
221}
222
223void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE) {
Amaury Sechet74f4ce62016-01-15 00:23:34 +0000224 unwrap(EE)->finalizeObject();
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000225 unwrap(EE)->runStaticConstructorsDestructors(true);
226}
227
228int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
229 unsigned ArgC, const char * const *ArgV,
230 const char * const *EnvP) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000231 unwrap(EE)->finalizeObject();
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +0000232
233 std::vector<std::string> ArgVec(ArgV, ArgV + ArgC);
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000234 return unwrap(EE)->runFunctionAsMain(unwrap<Function>(F), ArgVec, EnvP);
235}
236
237LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
238 unsigned NumArgs,
239 LLVMGenericValueRef *Args) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000240 unwrap(EE)->finalizeObject();
241
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000242 std::vector<GenericValue> ArgVec;
243 ArgVec.reserve(NumArgs);
244 for (unsigned I = 0; I != NumArgs; ++I)
245 ArgVec.push_back(*unwrap(Args[I]));
246
247 GenericValue *Result = new GenericValue();
248 *Result = unwrap(EE)->runFunction(unwrap<Function>(F), ArgVec);
249 return wrap(Result);
250}
251
252void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000253}
254
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000255void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M){
Rafael Espindola2a8a2792014-08-19 04:04:25 +0000256 unwrap(EE)->addModule(std::unique_ptr<Module>(unwrap(M)));
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000257}
258
Erick Tryzelaarad0e0cb2010-03-02 23:58:54 +0000259LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
260 LLVMModuleRef *OutMod, char **OutError) {
261 Module *Mod = unwrap(M);
262 unwrap(EE)->removeModule(Mod);
263 *OutMod = wrap(Mod);
264 return 0;
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000265}
266
Chris Lattner25963c62010-01-09 22:27:07 +0000267LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name,
268 LLVMValueRef *OutFn) {
Gordon Henriksen2a8cd892007-12-23 16:59:28 +0000269 if (Function *F = unwrap(EE)->FindFunctionNamed(Name)) {
270 *OutFn = wrap(F);
271 return 0;
272 }
273 return 1;
274}
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000275
Filip Pizlo85e0d272013-05-01 22:58:00 +0000276void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE,
277 LLVMValueRef Fn) {
Eric Christopher79cc1e32014-09-02 22:28:02 +0000278 return nullptr;
Duncan Sands330134b2010-07-19 09:33:13 +0000279}
280
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000281LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE) {
Mehdi Aminia3fcefb2015-07-16 16:34:23 +0000282 return wrap(&unwrap(EE)->getDataLayout());
Erick Tryzelaar8ac07c22008-03-27 00:27:14 +0000283}
Gordon Henriksen9f337542008-06-20 02:16:11 +0000284
Juergen Ributzka5fe955c2014-01-23 19:23:28 +0000285LLVMTargetMachineRef
286LLVMGetExecutionEngineTargetMachine(LLVMExecutionEngineRef EE) {
287 return wrap(unwrap(EE)->getTargetMachine());
288}
289
Gordon Henriksen9f337542008-06-20 02:16:11 +0000290void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
291 void* Addr) {
292 unwrap(EE)->addGlobalMapping(unwrap<GlobalValue>(Global), Addr);
293}
Chris Lattner41b43da2009-01-21 18:11:10 +0000294
295void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global) {
Andrew Kaylor31be5ef2013-04-29 17:49:40 +0000296 unwrap(EE)->finalizeObject();
297
Chris Lattner41b43da2009-01-21 18:11:10 +0000298 return unwrap(EE)->getPointerToGlobal(unwrap<GlobalValue>(Global));
299}
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000300
Peter Zotovc433cd72014-12-22 18:53:11 +0000301uint64_t LLVMGetGlobalValueAddress(LLVMExecutionEngineRef EE, const char *Name) {
302 return unwrap(EE)->getGlobalValueAddress(Name);
303}
304
305uint64_t LLVMGetFunctionAddress(LLVMExecutionEngineRef EE, const char *Name) {
306 return unwrap(EE)->getFunctionAddress(Name);
307}
308
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000309/*===-- Operations on memory managers -------------------------------------===*/
310
311namespace {
312
313struct SimpleBindingMMFunctions {
Anders Waldenborg9515b312013-09-30 19:11:32 +0000314 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection;
315 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection;
316 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory;
317 LLVMMemoryManagerDestroyCallback Destroy;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000318};
319
320class SimpleBindingMemoryManager : public RTDyldMemoryManager {
321public:
322 SimpleBindingMemoryManager(const SimpleBindingMMFunctions& Functions,
323 void *Opaque);
Alexander Kornienkof817c1c2015-04-11 02:11:45 +0000324 ~SimpleBindingMemoryManager() override;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000325
Craig Topperb51ff602014-03-08 07:51:20 +0000326 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
327 unsigned SectionID,
328 StringRef SectionName) override;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000329
Craig Topperb51ff602014-03-08 07:51:20 +0000330 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
331 unsigned SectionID, StringRef SectionName,
332 bool isReadOnly) override;
333
334 bool finalizeMemory(std::string *ErrMsg) override;
335
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000336private:
337 SimpleBindingMMFunctions Functions;
338 void *Opaque;
339};
340
341SimpleBindingMemoryManager::SimpleBindingMemoryManager(
342 const SimpleBindingMMFunctions& Functions,
343 void *Opaque)
344 : Functions(Functions), Opaque(Opaque) {
345 assert(Functions.AllocateCodeSection &&
346 "No AllocateCodeSection function provided!");
347 assert(Functions.AllocateDataSection &&
348 "No AllocateDataSection function provided!");
349 assert(Functions.FinalizeMemory &&
350 "No FinalizeMemory function provided!");
351 assert(Functions.Destroy &&
352 "No Destroy function provided!");
353}
354
355SimpleBindingMemoryManager::~SimpleBindingMemoryManager() {
356 Functions.Destroy(Opaque);
357}
358
359uint8_t *SimpleBindingMemoryManager::allocateCodeSection(
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000360 uintptr_t Size, unsigned Alignment, unsigned SectionID,
361 StringRef SectionName) {
362 return Functions.AllocateCodeSection(Opaque, Size, Alignment, SectionID,
363 SectionName.str().c_str());
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000364}
365
366uint8_t *SimpleBindingMemoryManager::allocateDataSection(
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000367 uintptr_t Size, unsigned Alignment, unsigned SectionID,
368 StringRef SectionName, bool isReadOnly) {
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000369 return Functions.AllocateDataSection(Opaque, Size, Alignment, SectionID,
Filip Pizlo7aa695e02013-10-02 00:59:25 +0000370 SectionName.str().c_str(),
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000371 isReadOnly);
372}
373
374bool SimpleBindingMemoryManager::finalizeMemory(std::string *ErrMsg) {
Craig Topper2617dcc2014-04-15 06:32:26 +0000375 char *errMsgCString = nullptr;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000376 bool result = Functions.FinalizeMemory(Opaque, &errMsgCString);
377 assert((result || !errMsgCString) &&
378 "Did not expect an error message if FinalizeMemory succeeded");
379 if (errMsgCString) {
380 if (ErrMsg)
381 *ErrMsg = errMsgCString;
382 free(errMsgCString);
383 }
384 return result;
385}
386
387} // anonymous namespace
388
389LLVMMCJITMemoryManagerRef LLVMCreateSimpleMCJITMemoryManager(
390 void *Opaque,
Anders Waldenborg9515b312013-09-30 19:11:32 +0000391 LLVMMemoryManagerAllocateCodeSectionCallback AllocateCodeSection,
392 LLVMMemoryManagerAllocateDataSectionCallback AllocateDataSection,
393 LLVMMemoryManagerFinalizeMemoryCallback FinalizeMemory,
394 LLVMMemoryManagerDestroyCallback Destroy) {
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000395
396 if (!AllocateCodeSection || !AllocateDataSection || !FinalizeMemory ||
397 !Destroy)
Craig Topper2617dcc2014-04-15 06:32:26 +0000398 return nullptr;
Filip Pizlo3fdbaff2013-05-22 02:46:43 +0000399
400 SimpleBindingMMFunctions functions;
401 functions.AllocateCodeSection = AllocateCodeSection;
402 functions.AllocateDataSection = AllocateDataSection;
403 functions.FinalizeMemory = FinalizeMemory;
404 functions.Destroy = Destroy;
405 return wrap(new SimpleBindingMemoryManager(functions, Opaque));
406}
407
408void LLVMDisposeMCJITMemoryManager(LLVMMCJITMemoryManagerRef MM) {
409 delete unwrap(MM);
410}
411