-/*===-- analysis_ocaml.c - LLVM Ocaml Glue ----------------------*- C++ -*-===*\
+/*===-- executionengine_ocaml.c - LLVM Ocaml Glue ---------------*- C++ -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
\*===----------------------------------------------------------------------===*/
#include "llvm-c/ExecutionEngine.h"
+#include "llvm-c/Target.h"
#include "caml/alloc.h"
#include "caml/custom.h"
#include "caml/fail.h"
#include <string.h>
#include <assert.h>
+/* Force the LLVM interpreter and JIT to be linked in. */
+void llvm_initialize(void) {
+ LLVMLinkInInterpreter();
+ LLVMLinkInJIT();
+}
+
+/* unit -> bool */
+CAMLprim value llvm_initialize_native_target(value Unit) {
+ return Val_bool(LLVMInitializeNativeTarget());
+}
/* Can't use the recommended caml_named_value mechanism for backwards
compatibility reasons. This is largely equivalent. */
/*--... Operations on execution engines ....................................--*/
-/* llmoduleprovider -> ExecutionEngine.t */
-CAMLprim LLVMExecutionEngineRef llvm_ee_create(LLVMModuleProviderRef MP) {
+/* llmodule -> ExecutionEngine.t */
+CAMLprim LLVMExecutionEngineRef llvm_ee_create(LLVMModuleRef M) {
LLVMExecutionEngineRef Interp;
char *Error;
- if (LLVMCreateExecutionEngine(&Interp, MP, &Error))
+ if (LLVMCreateExecutionEngineForModule(&Interp, M, &Error))
llvm_raise(llvm_ee_error_exn, Error);
return Interp;
}
-/* llmoduleprovider -> ExecutionEngine.t */
+/* llmodule -> ExecutionEngine.t */
CAMLprim LLVMExecutionEngineRef
-llvm_ee_create_interpreter(LLVMModuleProviderRef MP) {
+llvm_ee_create_interpreter(LLVMModuleRef M) {
LLVMExecutionEngineRef Interp;
char *Error;
- if (LLVMCreateInterpreter(&Interp, MP, &Error))
+ if (LLVMCreateInterpreterForModule(&Interp, M, &Error))
llvm_raise(llvm_ee_error_exn, Error);
return Interp;
}
-/* llmoduleprovider -> ExecutionEngine.t */
+/* llmodule -> ExecutionEngine.t */
+CAMLprim LLVMExecutionEngineRef
+llvm_ee_create_jit(LLVMModuleRef M) {
+ LLVMExecutionEngineRef JIT;
+ char *Error;
+ if (LLVMCreateJITCompilerForModule(&JIT, M, 3, &Error))
+ llvm_raise(llvm_ee_error_exn, Error);
+ return JIT;
+}
+
+/* llmodule -> ExecutionEngine.t */
CAMLprim LLVMExecutionEngineRef
-llvm_ee_create_jit(LLVMModuleProviderRef MP) {
+llvm_ee_create_fast_jit(LLVMModuleRef M) {
LLVMExecutionEngineRef JIT;
char *Error;
- if (LLVMCreateJITCompiler(&JIT, MP, &Error))
+ if (LLVMCreateJITCompiler(&JIT, M, 0, &Error))
llvm_raise(llvm_ee_error_exn, Error);
return JIT;
}
return Val_unit;
}
-/* llmoduleprovider -> ExecutionEngine.t -> unit */
-CAMLprim value llvm_ee_add_mp(LLVMModuleProviderRef MP,
- LLVMExecutionEngineRef EE) {
- LLVMAddModuleProvider(EE, MP);
+/* llmodule -> ExecutionEngine.t -> unit */
+CAMLprim value llvm_ee_add_mp(LLVMModuleRef M, LLVMExecutionEngineRef EE) {
+ LLVMAddModule(EE, M);
return Val_unit;
}
-/* llmoduleprovider -> ExecutionEngine.t -> llmodule */
-CAMLprim LLVMModuleRef llvm_ee_remove_mp(LLVMModuleProviderRef MP,
+/* llmodule -> ExecutionEngine.t -> llmodule */
+CAMLprim LLVMModuleRef llvm_ee_remove_mp(LLVMModuleRef M,
LLVMExecutionEngineRef EE) {
LLVMModuleRef RemovedModule;
char *Error;
- if (LLVMRemoveModuleProvider(EE, MP, &RemovedModule, &Error))
+ if (LLVMRemoveModule(EE, M, &RemovedModule, &Error))
llvm_raise(llvm_ee_error_exn, Error);
return RemovedModule;
}