X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=bindings%2Focaml%2Fexecutionengine%2Fexecutionengine_ocaml.c;h=32f6c5907ccaebc39b20c8894c3082458f05509c;hb=e5de63c7de04c81d7d8484e5b64f47941143c739;hp=a7b455c90ba27e42704c5e5af303456187805070;hpb=234d529e582963ad4b5d83b911cd057fe99d1435;p=oota-llvm.git diff --git a/bindings/ocaml/executionengine/executionengine_ocaml.c b/bindings/ocaml/executionengine/executionengine_ocaml.c index a7b455c90ba..32f6c5907cc 100644 --- a/bindings/ocaml/executionengine/executionengine_ocaml.c +++ b/bindings/ocaml/executionengine/executionengine_ocaml.c @@ -1,4 +1,4 @@ -/*===-- analysis_ocaml.c - LLVM Ocaml Glue ----------------------*- C++ -*-===*\ +/*===-- executionengine_ocaml.c - LLVM OCaml Glue ---------------*- C++ -*-===*\ |* *| |* The LLVM Compiler Infrastructure *| |* *| @@ -7,7 +7,7 @@ |* *| |*===----------------------------------------------------------------------===*| |* *| -|* This file glues LLVM's ocaml interface to its C interface. These functions *| +|* This file glues LLVM's OCaml interface to its C interface. These functions *| |* are by and large transparent wrappers to the corresponding C functions. *| |* *| |* Note that these functions intentionally take liberties with the CAMLparamX *| @@ -16,6 +16,7 @@ \*===----------------------------------------------------------------------===*/ #include "llvm-c/ExecutionEngine.h" +#include "llvm-c/Target.h" #include "caml/alloc.h" #include "caml/custom.h" #include "caml/fail.h" @@ -23,6 +24,16 @@ #include #include +/* 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. */ @@ -43,7 +54,9 @@ static void llvm_raise(value Prototype, char *Message) { raise_with_arg(Prototype, CamlMessage); abort(); /* NOTREACHED */ - CAMLnoreturn; +#ifdef CAMLnoreturn + CAMLnoreturn; /* Silences warnings, but is missing in some versions. */ +#endif } @@ -62,6 +75,9 @@ static struct custom_operations generic_value_ops = { custom_hash_default, custom_serialize_default, custom_deserialize_default +#ifdef custom_compare_ext_default + , custom_compare_ext_default +#endif }; static value alloc_generic_value(LLVMGenericValueRef Ref) { @@ -78,7 +94,7 @@ CAMLprim value llvm_genericvalue_of_float(LLVMTypeRef Ty, value N) { } /* 'a -> t */ -CAMLprim value llvm_genericvalue_of_value(value V) { +CAMLprim value llvm_genericvalue_of_pointer(value V) { CAMLparam1(V); CAMLreturn(alloc_generic_value(LLVMCreateGenericValueOfPointer(Op_val(V)))); } @@ -117,7 +133,7 @@ CAMLprim value llvm_genericvalue_as_float(LLVMTypeRef Ty, value GenVal) { } /* t -> 'a */ -CAMLprim value llvm_genericvalue_as_value(value GenVal) { +CAMLprim value llvm_genericvalue_as_pointer(value GenVal) { return Val_op(LLVMGenericValueToPointer(Genericvalue_val(GenVal))); } @@ -155,31 +171,31 @@ CAMLprim value llvm_genericvalue_as_nativeint(value GenVal) { /*--... 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 -> int -> ExecutionEngine.t */ CAMLprim LLVMExecutionEngineRef -llvm_ee_create_jit(LLVMModuleProviderRef MP) { +llvm_ee_create_jit(LLVMModuleRef M, value OptLevel) { LLVMExecutionEngineRef JIT; char *Error; - if (LLVMCreateJITCompiler(&JIT, MP, &Error)) + if (LLVMCreateJITCompilerForModule(&JIT, M, Int_val(OptLevel), &Error)) llvm_raise(llvm_ee_error_exn, Error); return JIT; } @@ -190,19 +206,18 @@ CAMLprim value llvm_ee_dispose(LLVMExecutionEngineRef EE) { 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_module(LLVMModuleRef M, LLVMExecutionEngineRef EE) { + LLVMAddModule(EE, M); return Val_unit; } -/* llmoduleprovider -> ExecutionEngine.t -> llmodule */ -CAMLprim LLVMModuleRef llvm_ee_remove_mp(LLVMModuleProviderRef MP, - LLVMExecutionEngineRef EE) { +/* llmodule -> ExecutionEngine.t -> llmodule */ +CAMLprim LLVMModuleRef llvm_ee_remove_module(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; } @@ -214,7 +229,7 @@ CAMLprim value llvm_ee_find_function(value Name, LLVMExecutionEngineRef EE) { LLVMValueRef Found; if (LLVMFindFunction(EE, String_val(Name), &Found)) CAMLreturn(Val_unit); - Option = alloc(1, 1); + Option = alloc(1, 0); Field(Option, 0) = Val_op(Found); CAMLreturn(Option); }