summaryrefslogtreecommitdiffstats
path: root/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
diff options
context:
space:
mode:
authorPeter Zotov <whitequark@whitequark.org>2014-10-29 08:15:54 +0000
committerPeter Zotov <whitequark@whitequark.org>2014-10-29 08:15:54 +0000
commit662538ac404c94ddfb92bd9def67d0e5034b45ec (patch)
treed9c72364adb81b10779fb8f900720d9518027255 /llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
parente447b61c5036a7d0e3ff680ed46a9dfab33c431a (diff)
downloadbcm5719-llvm-662538ac404c94ddfb92bd9def67d0e5034b45ec.tar.gz
bcm5719-llvm-662538ac404c94ddfb92bd9def67d0e5034b45ec.zip
[OCaml] Drop support for 3.12.1 and earlier.
In practice this means: * Always using -g flag. * Embedding -cclib -lstdc++ into the corresponding cma/cmxa file. This also moves -lstdc++ in a single place. * Using caml_named_value instead of a homegrown mechanism. llvm-svn: 220843
Diffstat (limited to 'llvm/bindings/ocaml/executionengine/executionengine_ocaml.c')
-rw-r--r--llvm/bindings/ocaml/executionengine/executionengine_ocaml.c82
1 files changed, 33 insertions, 49 deletions
diff --git a/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c b/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
index 8388233a356..a12cc0091ae 100644
--- a/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
+++ b/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
@@ -15,37 +15,15 @@
|* *|
\*===----------------------------------------------------------------------===*/
+#include <string.h>
+#include <assert.h>
#include "llvm-c/ExecutionEngine.h"
#include "llvm-c/Target.h"
#include "caml/alloc.h"
#include "caml/custom.h"
#include "caml/fail.h"
#include "caml/memory.h"
-#include <string.h>
-#include <assert.h>
-
-/* Force the LLVM interpreter and JIT to be linked in. */
-void llvm_initialize(void) {
- LLVMLinkInInterpreter();
- LLVMLinkInMCJIT();
-}
-
-/* unit -> bool */
-CAMLprim value llvm_initialize_native_target(value Unit) {
- return Val_bool(!LLVMInitializeNativeTarget() &&
- !LLVMInitializeNativeAsmParser() &&
- !LLVMInitializeNativeAsmPrinter());
-}
-
-/* Can't use the recommended caml_named_value mechanism for backwards
- compatibility reasons. This is largely equivalent. */
-static value llvm_ee_error_exn;
-
-CAMLprim value llvm_register_ee_exns(value Error) {
- llvm_ee_error_exn = Field(Error, 0);
- register_global_root(&llvm_ee_error_exn);
- return Val_unit;
-}
+#include "caml/callback.h"
static void llvm_raise(value Prototype, char *Message) {
CAMLparam1(Prototype);
@@ -55,13 +33,9 @@ static void llvm_raise(value Prototype, char *Message) {
LLVMDisposeMessage(Message);
raise_with_arg(Prototype, CamlMessage);
- abort(); /* NOTREACHED */
-#ifdef CAMLnoreturn
- CAMLnoreturn; /* Silences warnings, but is missing in some versions. */
-#endif
+ CAMLnoreturn;
}
-
/*--... Operations on generic values .......................................--*/
#define Genericvalue_val(v) (*(LLVMGenericValueRef *)(Data_custom_val(v)))
@@ -71,15 +45,13 @@ static void llvm_finalize_generic_value(value GenVal) {
}
static struct custom_operations generic_value_ops = {
- (char *) "LLVMGenericValue",
+ (char *) "Llvm_executionengine.GenericValue.t",
llvm_finalize_generic_value,
custom_compare_default,
custom_hash_default,
custom_serialize_default,
- custom_deserialize_default
-#ifdef custom_compare_ext_default
- , custom_compare_ext_default
-#endif
+ custom_deserialize_default,
+ custom_compare_ext_default
};
static value alloc_generic_value(LLVMGenericValueRef Ref) {
@@ -173,12 +145,22 @@ CAMLprim value llvm_genericvalue_as_nativeint(value GenVal) {
/*--... Operations on execution engines ....................................--*/
+/* unit -> bool */
+CAMLprim value llvm_initialize_native_target(value Unit) {
+ LLVMLinkInInterpreter();
+ LLVMLinkInMCJIT();
+
+ return Val_bool(!LLVMInitializeNativeTarget() &&
+ !LLVMInitializeNativeAsmParser() &&
+ !LLVMInitializeNativeAsmPrinter());
+}
+
/* llmodule -> ExecutionEngine.t */
CAMLprim LLVMExecutionEngineRef llvm_ee_create(LLVMModuleRef M) {
LLVMExecutionEngineRef Interp;
char *Error;
if (LLVMCreateExecutionEngineForModule(&Interp, M, &Error))
- llvm_raise(llvm_ee_error_exn, Error);
+ llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
return Interp;
}
@@ -188,7 +170,7 @@ llvm_ee_create_interpreter(LLVMModuleRef M) {
LLVMExecutionEngineRef Interp;
char *Error;
if (LLVMCreateInterpreterForModule(&Interp, M, &Error))
- llvm_raise(llvm_ee_error_exn, Error);
+ llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
return Interp;
}
@@ -198,7 +180,7 @@ llvm_ee_create_jit(LLVMModuleRef M, value OptLevel) {
LLVMExecutionEngineRef JIT;
char *Error;
if (LLVMCreateJITCompilerForModule(&JIT, M, Int_val(OptLevel), &Error))
- llvm_raise(llvm_ee_error_exn, Error);
+ llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
return JIT;
}
@@ -207,16 +189,18 @@ CAMLprim LLVMExecutionEngineRef
llvm_ee_create_mcjit(LLVMModuleRef M, value OptRecord) {
LLVMExecutionEngineRef MCJIT;
char *Error;
- struct LLVMMCJITCompilerOptions Options = {
- .OptLevel = Int_val(Field(OptRecord, 0)),
- .CodeModel = Int_val(Field(OptRecord, 1)),
- .NoFramePointerElim = Int_val(Field(OptRecord, 2)),
- .EnableFastISel = Int_val(Field(OptRecord, 3)),
- .MCJMM = NULL
- };
+ struct LLVMMCJITCompilerOptions Options;
+
+ LLVMInitializeMCJITCompilerOptions(&Options, sizeof(Options));
+ Options.OptLevel = Int_val(Field(OptRecord, 0));
+ Options.CodeModel = Int_val(Field(OptRecord, 1));
+ Options.NoFramePointerElim = Int_val(Field(OptRecord, 2));
+ Options.EnableFastISel = Int_val(Field(OptRecord, 3));
+ Options.MCJMM = NULL;
+
if (LLVMCreateMCJITCompilerForModule(&MCJIT, M, &Options,
sizeof(Options), &Error))
- llvm_raise(llvm_ee_error_exn, Error);
+ llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
return MCJIT;
}
@@ -238,7 +222,7 @@ CAMLprim LLVMModuleRef llvm_ee_remove_module(LLVMModuleRef M,
LLVMModuleRef RemovedModule;
char *Error;
if (LLVMRemoveModule(EE, M, &RemovedModule, &Error))
- llvm_raise(llvm_ee_error_exn, Error);
+ llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
return RemovedModule;
}
@@ -350,9 +334,9 @@ extern value llvm_alloc_data_layout(LLVMTargetDataRef TargetData);
CAMLprim value llvm_ee_get_data_layout(LLVMExecutionEngineRef EE) {
value DataLayout;
LLVMTargetDataRef OrigDataLayout;
- OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);
-
char* TargetDataCStr;
+
+ OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);
TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
LLVMDisposeMessage(TargetDataCStr);
OpenPOWER on IntegriCloud