[OCaml] Drop support for 3.12.1 and earlier.
authorPeter Zotov <whitequark@whitequark.org>
Wed, 29 Oct 2014 08:15:54 +0000 (08:15 +0000)
committerPeter Zotov <whitequark@whitequark.org>
Wed, 29 Oct 2014 08:15:54 +0000 (08:15 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220843 91177308-0d34-0410-b5e6-96231b3b80d8

29 files changed:
bindings/ocaml/Makefile.ocaml
bindings/ocaml/all_backends/Makefile
bindings/ocaml/analysis/analysis_ocaml.c
bindings/ocaml/analysis/llvm_analysis.ml
bindings/ocaml/analysis/llvm_analysis.mli
bindings/ocaml/backends/META.llvm_backend.in
bindings/ocaml/backends/backend_ocaml.c
bindings/ocaml/bitreader/bitreader_ocaml.c
bindings/ocaml/bitreader/llvm_bitreader.ml
bindings/ocaml/bitreader/llvm_bitreader.mli
bindings/ocaml/bitwriter/bitwriter_ocaml.c
bindings/ocaml/executionengine/Makefile
bindings/ocaml/executionengine/executionengine_ocaml.c
bindings/ocaml/executionengine/llvm_executionengine.ml
bindings/ocaml/executionengine/llvm_executionengine.mli
bindings/ocaml/irreader/irreader_ocaml.c
bindings/ocaml/irreader/llvm_irreader.ml
bindings/ocaml/linker/linker_ocaml.c
bindings/ocaml/linker/llvm_linker.ml
bindings/ocaml/llvm/META.llvm.in
bindings/ocaml/llvm/Makefile
bindings/ocaml/llvm/llvm.ml
bindings/ocaml/llvm/llvm_ocaml.c
bindings/ocaml/target/llvm_target.ml
bindings/ocaml/target/target_ocaml.c
bindings/ocaml/transforms/ipo/Makefile
bindings/ocaml/transforms/passmgr_builder/passmgr_builder_ocaml.c
bindings/ocaml/transforms/vectorize/Makefile
test/Makefile

index 7b26caf6bb633bb5cf97476593ba1f34434508e3..d069c454cd0ffb6a156f5c6a51c456395488f019 100644 (file)
@@ -61,11 +61,11 @@ ifneq ($(ObjectsO),)
 OCAMLAFLAGS += $(patsubst %,-cclib %, \
                  $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \
                                           $(shell $(LLVM_CONFIG) --ldflags)) \
 OCAMLAFLAGS += $(patsubst %,-cclib %, \
                  $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \
                                           $(shell $(LLVM_CONFIG) --ldflags)) \
-                                          $(UsedLibs))
+                                          $(UsedLibs) $(ExtraLibs))
 else
 OCAMLAFLAGS += $(patsubst %,-cclib %, \
                  $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
 else
 OCAMLAFLAGS += $(patsubst %,-cclib %, \
                  $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \
-                                          $(UsedLibs))
+                                          $(UsedLibs) $(ExtraLibs))
 endif
 endif
 
 endif
 endif
 
@@ -481,6 +481,7 @@ printcamlvars::
        $(Echo) "DestSharedLib: " '$(DestSharedLib)'
        $(Echo) "UsedLibs     : " '$(UsedLibs)'
        $(Echo) "UsedLibNames : " '$(UsedLibNames)'
        $(Echo) "DestSharedLib: " '$(DestSharedLib)'
        $(Echo) "UsedLibs     : " '$(UsedLibs)'
        $(Echo) "UsedLibNames : " '$(UsedLibNames)'
+       $(Echo) "ExtraLibs    : " '$(ExtraLibs)'
 
 .PHONY: printcamlvars   build-cmis \
             clean-a     clean-cmis     clean-cma     clean-cmxa \
 
 .PHONY: printcamlvars   build-cmis \
             clean-a     clean-cmis     clean-cma     clean-cmxa \
index a5ff290fe7bfd5215b83911473d229bef5235b00..f7c8cdbd8c3f1e1ca0f26305575bcacf59cc6c84 100644 (file)
@@ -1,4 +1,4 @@
-##===- bindings/ocaml/all_backends/Makefile ----------------------*- Makefile -*-===##
+##===- bindings/ocaml/all_backends/Makefile ----------------*- Makefile -*-===##
 #
 #                     The LLVM Compiler Infrastructure
 #
 #
 #                     The LLVM Compiler Infrastructure
 #
@@ -7,7 +7,7 @@
 #
 ##===----------------------------------------------------------------------===##
 #
 #
 ##===----------------------------------------------------------------------===##
 #
-# This is the makefile for the Objective Caml Llvm_backends interface.
+# This is the makefile for the Objective Caml Llvm_all_backends interface.
 #
 ##===----------------------------------------------------------------------===##
 
 #
 ##===----------------------------------------------------------------------===##
 
index da822888f984be65960785edcdf0886e55de3c22..44e31970a4b7484de1b3e8eeaf28fcc3f55de828 100644 (file)
@@ -20,7 +20,6 @@
 #include "caml/mlvalues.h"
 #include "caml/memory.h"
 
 #include "caml/mlvalues.h"
 #include "caml/memory.h"
 
-
 /* Llvm.llmodule -> string option */
 CAMLprim value llvm_verify_module(LLVMModuleRef M) {
   CAMLparam0();
 /* Llvm.llmodule -> string option */
 CAMLprim value llvm_verify_module(LLVMModuleRef M) {
   CAMLparam0();
index 21088ab6ff4130663c92f9152d6b9e26a91b5559..8c11a63c091f80665377385de01a00a856a5e213 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm_analysis.ml - LLVM OCaml Interface -----------------*- C++ -*-===*
+(*===-- llvm_analysis.ml - LLVM OCaml Interface ---------------*- OCaml -*-===*
  *
  *                     The LLVM Compiler Infrastructure
  *
  *
  *                     The LLVM Compiler Infrastructure
  *
index 1a0af02b387849f1e1ace224525038d5f418334b..03197cd41be63b0dcbd099e5b79261785f415fab 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm_analysis.mli - LLVM OCaml Interface ----------------*- C++ -*-===*
+(*===-- llvm_analysis.mli - LLVM OCaml Interface --------------*- OCaml -*-===*
  *
  *                     The LLVM Compiler Infrastructure
  *
  *
  *                     The LLVM Compiler Infrastructure
  *
index 0d4a6d6846530dfbf4197c739ea81b1750f630f9..6c1e8c472596ed260494560de8c2eaeb012c883c 100644 (file)
@@ -5,4 +5,3 @@ requires = "llvm"
 archive(byte) = "llvm_@TARGET@.cma"
 archive(native) = "llvm_@TARGET@.cmxa"
 directory = "."
 archive(byte) = "llvm_@TARGET@.cma"
 archive(native) = "llvm_@TARGET@.cmxa"
 directory = "."
-linkopts = "-ccopt -lstdc++"
\ No newline at end of file
index 2d4ba852fda5c3a4b7d94046d907c86ff57279f4..3e1a43897c77ca791fed37917ed400c79b9b81c2 100644 (file)
 #include "caml/alloc.h"
 #include "caml/memory.h"
 
 #include "caml/alloc.h"
 #include "caml/memory.h"
 
-// TODO: Figure out how to call these only for targets which support them.
-// LLVMInitialize ## target ## AsmPrinter();
-// LLVMInitialize ## target ## AsmParser();
-// LLVMInitialize ## target ## Disassembler();
+/* TODO: Figure out how to call these only for targets which support them.
+ * LLVMInitialize ## target ## AsmPrinter();
+ * LLVMInitialize ## target ## AsmParser();
+ * LLVMInitialize ## target ## Disassembler();
+ */
 
 #define INITIALIZER1(target) \
   CAMLprim value llvm_initialize_ ## target(value Unit) {  \
 
 #define INITIALIZER1(target) \
   CAMLprim value llvm_initialize_ ## target(value Unit) {  \
index a3f873c8d882e97ad932dc0ef9864f5525576a56..eab3e1ae30e4b7c6504bd255d088c2a1820e0f94 100644 (file)
 #include "caml/alloc.h"
 #include "caml/fail.h"
 #include "caml/memory.h"
 #include "caml/alloc.h"
 #include "caml/fail.h"
 #include "caml/memory.h"
-
-
-/* Can't use the recommended caml_named_value mechanism for backwards
-   compatibility reasons. This is largely equivalent. */
-static value llvm_bitreader_error_exn;
-
-CAMLprim value llvm_register_bitreader_exns(value Error) {
-  llvm_bitreader_error_exn = Field(Error, 0);
-  register_global_root(&llvm_bitreader_error_exn);
-  return Val_unit;
-}
+#include "caml/callback.h"
 
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
 
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
@@ -36,38 +26,29 @@ static void llvm_raise(value Prototype, char *Message) {
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
-  abort(); /* NOTREACHED */
-#ifdef CAMLnoreturn
-  CAMLnoreturn; /* Silences warnings, but is missing in some versions. */
-#endif
+  CAMLnoreturn;
 }
 
 }
 
-
-/*===-- Modules -----------------------------------------------------------===*/
+/*===-- BitReader --------------------------------------------------------===*/
 
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
 
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
-CAMLprim value llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
-  CAMLparam0();
-  CAMLlocal2(Variant, MessageVal);
+CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
+  LLVMModuleRef M;
   char *Message;
 
   char *Message;
 
-  LLVMModuleRef M;
   if (LLVMGetBitcodeModuleInContext(C, MemBuf, &M, &Message))
   if (LLVMGetBitcodeModuleInContext(C, MemBuf, &M, &Message))
-    llvm_raise(llvm_bitreader_error_exn, Message);
+    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message);
 
 
-  CAMLreturn((value) M);
+  return M;
 }
 
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
 }
 
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
-CAMLprim value llvm_parse_bitcode(LLVMContextRef C,
-                                  LLVMMemoryBufferRef MemBuf) {
-  CAMLparam0();
-  CAMLlocal2(Variant, MessageVal);
+CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
   LLVMModuleRef M;
   char *Message;
 
   if (LLVMParseBitcodeInContext(C, MemBuf, &M, &Message))
   LLVMModuleRef M;
   char *Message;
 
   if (LLVMParseBitcodeInContext(C, MemBuf, &M, &Message))
-    llvm_raise(llvm_bitreader_error_exn, Message);
+    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message);
 
 
-  CAMLreturn((value) M);
+  return M;
 }
 }
index 865208c1ec0af53e334ceb87cee0a4867c74e003..b26efdd2c18f49331cfd47a501d34e2d0309b937 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm_bitreader.ml - LLVM OCaml Interface ----------------*- C++ -*-===*
+(*===-- llvm_bitreader.ml - LLVM OCaml Interface --------------*- OCaml -*-===*
  *
  *                     The LLVM Compiler Infrastructure
  *
  *
  *                     The LLVM Compiler Infrastructure
  *
@@ -7,14 +7,13 @@
  *
  *===----------------------------------------------------------------------===*)
 
  *
  *===----------------------------------------------------------------------===*)
 
-
 exception Error of string
 
 exception Error of string
 
-external register_exns : exn -> unit = "llvm_register_bitreader_exns"
-let _ = register_exns (Error "")
-
-external get_module : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
-                    = "llvm_get_module"
+let () = Callback.register_exception "Llvm_bitreader.Error" (Error "")
 
 
-external parse_bitcode : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
-                       = "llvm_parse_bitcode"
+external get_module
+  : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
+  = "llvm_get_module"
+external parse_bitcode
+  : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
+  = "llvm_parse_bitcode"
index ff377b9bc997f65cfb2d3018c5b305559664e1b2..435134337e076d7730dc0731391740f30585cda4 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm_bitreader.mli - LLVM OCaml Interface ---------------*- C++ -*-===*
+(*===-- llvm_bitreader.mli - LLVM OCaml Interface -------------*- OCaml -*-===*
  *
  *                     The LLVM Compiler Infrastructure
  *
  *
  *                     The LLVM Compiler Infrastructure
  *
@@ -20,7 +20,6 @@ exception Error of string
     encountered. See the function [llvm::getBitcodeModule]. *)
 val get_module : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
 
     encountered. See the function [llvm::getBitcodeModule]. *)
 val get_module : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
 
-
 (** [parse_bitcode context mb] parses the bitcode for a new module [m] from the
     memory buffer [mb] in the context [context]. Returns [m] if successful, or
     raises [Error msg] otherwise, where [msg] is a description of the error
 (** [parse_bitcode context mb] parses the bitcode for a new module [m] from the
     memory buffer [mb] in the context [context]. Returns [m] if successful, or
     raises [Error msg] otherwise, where [msg] is a description of the error
index a47f7003e7ef16638f9d700fb4c0de7fb7a8be6e..1045c2344a70f5978345ec7869d0b33aa41a50a4 100644 (file)
 #include "caml/mlvalues.h"
 #include "caml/memory.h"
 
 #include "caml/mlvalues.h"
 #include "caml/memory.h"
 
-/*===-- Modules -----------------------------------------------------------===*/
+/*===-- BitWriter ---------------------------------------------------------===*/
 
 /* Llvm.llmodule -> string -> bool */
 
 /* Llvm.llmodule -> string -> bool */
-CAMLprim value llvm_write_bitcode_file(value M, value Path) {
-  int res = LLVMWriteBitcodeToFile((LLVMModuleRef) M, String_val(Path));
-  return Val_bool(res == 0);
+CAMLprim value llvm_write_bitcode_file(LLVMModuleRef M, value Path) {
+  int Result = LLVMWriteBitcodeToFile(M, String_val(Path));
+  return Val_bool(Result == 0);
 }
 
 /* ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool */
 }
 
 /* ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool */
-CAMLprim value llvm_write_bitcode_to_fd(value U, value M, value FD) {
+CAMLprim value llvm_write_bitcode_to_fd(value U, LLVMModuleRef M, value FD) {
   int Unbuffered;
   int Unbuffered;
-  int res;
+  int Result;
 
   if (U == Val_int(0)) {
     Unbuffered = 0;
   } else {
 
   if (U == Val_int(0)) {
     Unbuffered = 0;
   } else {
-    Unbuffered = Bool_val(Field(U,0));
+    Unbuffered = Bool_val(Field(U, 0));
   }
 
   }
 
-  res = LLVMWriteBitcodeToFD((LLVMModuleRef) M, Int_val(FD), 0, Unbuffered);
-  return Val_bool(res == 0);
+  Result = LLVMWriteBitcodeToFD(M, Int_val(FD), 0, Unbuffered);
+  return Val_bool(Result == 0);
 }
 }
index d915a76e1ff97feab8dafc9d947842ff1104bd2a..6c2bd2a8d61d82478cc40b3b0bcff800eadd7063 100644 (file)
@@ -1,4 +1,4 @@
-##===- bindings/ocaml/executionengine/Makefile --------------*- Makefile -*-===##
+##===- bindings/ocaml/executionengine/Makefile -------------*- Makefile -*-===##
 #
 #                     The LLVM Compiler Infrastructure
 #
 #
 #                     The LLVM Compiler Infrastructure
 #
index 8388233a35637f9ee3da91cf220f781add263300..a12cc0091ae7bf0be34bf3cd8bd593665a20c219 100644 (file)
 |*                                                                            *|
 \*===----------------------------------------------------------------------===*/
 
 |*                                                                            *|
 \*===----------------------------------------------------------------------===*/
 
+#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 "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);
 
 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);
   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)))
 /*--... 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 = {
 }
 
 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,
   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) {
 };
 
 static value alloc_generic_value(LLVMGenericValueRef Ref) {
@@ -173,12 +145,22 @@ CAMLprim value llvm_genericvalue_as_nativeint(value GenVal) {
 
 /*--... Operations on execution engines ....................................--*/
 
 
 /*--... 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))
 /* 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;
 }
 
   return Interp;
 }
 
@@ -188,7 +170,7 @@ llvm_ee_create_interpreter(LLVMModuleRef M) {
   LLVMExecutionEngineRef Interp;
   char *Error;
   if (LLVMCreateInterpreterForModule(&Interp, M, &Error))
   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;
 }
 
   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))
   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;
 }
 
   return JIT;
 }
 
@@ -207,16 +189,18 @@ CAMLprim LLVMExecutionEngineRef
 llvm_ee_create_mcjit(LLVMModuleRef M, value OptRecord) {
   LLVMExecutionEngineRef MCJIT;
   char *Error;
 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))
   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;
 }
 
   return MCJIT;
 }
 
@@ -238,7 +222,7 @@ CAMLprim LLVMModuleRef llvm_ee_remove_module(LLVMModuleRef M,
   LLVMModuleRef RemovedModule;
   char *Error;
   if (LLVMRemoveModule(EE, M, &RemovedModule, &Error))
   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;
 }
 
   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;
 CAMLprim value llvm_ee_get_data_layout(LLVMExecutionEngineRef EE) {
   value DataLayout;
   LLVMTargetDataRef OrigDataLayout;
-  OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);
-
   char* TargetDataCStr;
   char* TargetDataCStr;
+
+  OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);
   TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
   DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
   LLVMDisposeMessage(TargetDataCStr);
   TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
   DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
   LLVMDisposeMessage(TargetDataCStr);
index 2165533c13796899147a1fe860fd012d9ac92e8b..f61195337ca1fb691fa8adf5b02e67a1b9890d18 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm_executionengine.ml - LLVM OCaml Interface ----------*- C++ -*-===*
+(*===-- llvm_executionengine.ml - LLVM OCaml Interface --------*- OCaml -*-===*
  *
  *                     The LLVM Compiler Infrastructure
  *
  *
  *                     The LLVM Compiler Infrastructure
  *
@@ -7,21 +7,18 @@
  *
  *===----------------------------------------------------------------------===*)
 
  *
  *===----------------------------------------------------------------------===*)
 
-
 exception Error of string
 
 exception Error of string
 
-external register_exns: exn -> unit
-  = "llvm_register_ee_exns"
-
+let () = Callback.register_exception "Llvm_executionengine.Error" (Error "")
 
 module CodeModel = struct
   type t =
 
 module CodeModel = struct
   type t =
-    | Default
-    | JIT_default
-    | Small
-    | Kernel
-    | Medium
-    | Large
+  | Default
+  | JIT_default
+  | Small
+  | Kernel
+  | Medium
+  | Large
 end
 
 module GenericValue = struct
 end
 
 module GenericValue = struct
@@ -71,14 +68,6 @@ module ExecutionEngine = struct
     no_framepointer_elim = false;
     enable_fast_isel = false }
 
     no_framepointer_elim = false;
     enable_fast_isel = false }
 
-  (* FIXME: Ocaml is not running this setup code unless we use 'val' in the
-            interface, which causes the emission of a stub for each function;
-            using 'external' in the module allows direct calls into
-            ocaml_executionengine.c. This is hardly fatal, but it is unnecessary
-            overhead on top of the two stubs that are already invoked for each
-            call into LLVM. *)
-  let _ = register_exns (Error "")
-
   external create: Llvm.llmodule -> t
     = "llvm_ee_create"
   external create_interpreter: Llvm.llmodule -> t
   external create: Llvm.llmodule -> t
     = "llvm_ee_create"
   external create_interpreter: Llvm.llmodule -> t
index 0b55193b6e5208802501282e6fd2b137fe3e6dff..772e2e574b80715ed09d66a07656e5e93cdc37ef 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm_executionengine.mli - LLVM OCaml Interface ---------*- C++ -*-===*
+(*===-- llvm_executionengine.mli - LLVM OCaml Interface -------*- OCaml -*-===*
  *
  *                     The LLVM Compiler Infrastructure
  *
  *
  *                     The LLVM Compiler Infrastructure
  *
 (** JIT Interpreter.
 
     This interface provides an OCaml API for LLVM execution engine (JIT/
 (** JIT Interpreter.
 
     This interface provides an OCaml API for LLVM execution engine (JIT/
-    interpreter), the classes in the ExecutionEngine library. *)
+    interpreter), the classes in the [ExecutionEngine] library. *)
 
 exception Error of string
 
 (** The JIT code model. See [llvm::CodeModel::Model]. *)
 module CodeModel : sig
   type t =
 
 exception Error of string
 
 (** The JIT code model. See [llvm::CodeModel::Model]. *)
 module CodeModel : sig
   type t =
-    | Default
-    | JIT_default
-    | Small
-    | Kernel
-    | Medium
-    | Large
+  | Default
+  | JIT_default
+  | Small
+  | Kernel
+  | Medium
+  | Large
 end
 
 module GenericValue: sig
 end
 
 module GenericValue: sig
index 30c10c7b8b0ac1469036cfd23de79be2c118ff5f..d9f7a50c52d0ee11b9bde68b4510be368bbda549 100644 (file)
 #include "caml/alloc.h"
 #include "caml/fail.h"
 #include "caml/memory.h"
 #include "caml/alloc.h"
 #include "caml/fail.h"
 #include "caml/memory.h"
-
-/* Can't use the recommended caml_named_value mechanism for backwards
-   compatibility reasons. This is largely equivalent. */
-static value llvm_irreader_error_exn;
-
-CAMLprim value llvm_register_irreader_exns(value Error) {
-  llvm_irreader_error_exn = Field(Error, 0);
-  register_global_root(&llvm_irreader_error_exn);
-  return Val_unit;
-}
+#include "caml/callback.h"
 
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
 
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
@@ -35,14 +26,10 @@ static void llvm_raise(value Prototype, char *Message) {
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
-  abort(); /* NOTREACHED */
-#ifdef CAMLnoreturn
-  CAMLnoreturn; /* Silences warnings, but is missing in some versions. */
-#endif
+  CAMLnoreturn;
 }
 
 }
 
-
-/*===-- Modules -----------------------------------------------------------===*/
+/*===-- IRReader ----------------------------------------------------------===*/
 
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
 CAMLprim value llvm_parse_ir(LLVMContextRef C,
 
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
 CAMLprim value llvm_parse_ir(LLVMContextRef C,
@@ -53,7 +40,7 @@ CAMLprim value llvm_parse_ir(LLVMContextRef C,
   char *Message;
 
   if (LLVMParseIRInContext(C, MemBuf, &M, &Message))
   char *Message;
 
   if (LLVMParseIRInContext(C, MemBuf, &M, &Message))
-    llvm_raise(llvm_irreader_error_exn, Message);
+    llvm_raise(*caml_named_value("Llvm_irreader.Error"), Message);
 
   CAMLreturn((value) M);
 }
 
   CAMLreturn((value) M);
 }
index 455b1fae032e7c3128437bee805cff40b3b17f75..f757d629939c0f6f8a3607b37ed452fa878bd552 100644 (file)
@@ -10,8 +10,7 @@
 
 exception Error of string
 
 
 exception Error of string
 
-external register_exns : exn -> unit = "llvm_register_irreader_exns"
-let _ = register_exns (Error "")
+let _ = Callback.register_exception "Llvm_irreader.Error" (Error "")
 
 external parse_ir : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
                   = "llvm_parse_ir"
 
 external parse_ir : Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule
                   = "llvm_parse_ir"
index 2491e3b8fa4ac0f01a6887bdf69d00fec3ddb211..553fbd91fe31f89cc2435a84096669bdac925476 100644 (file)
 #include "caml/alloc.h"
 #include "caml/memory.h"
 #include "caml/fail.h"
 #include "caml/alloc.h"
 #include "caml/memory.h"
 #include "caml/fail.h"
-
-static value llvm_linker_error_exn;
-
-CAMLprim value llvm_register_linker_exns(value Error) {
-  llvm_linker_error_exn = Field(Error, 0);
-  register_global_root(&llvm_linker_error_exn);
-  return Val_unit;
-}
+#include "caml/callback.h"
 
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
 
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
@@ -36,19 +29,15 @@ static void llvm_raise(value Prototype, char *Message) {
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
-  abort(); /* NOTREACHED */
-#ifdef CAMLnoreturn
-  CAMLnoreturn; /* Silences warnings, but is missing in some versions. */
-#endif
+  CAMLnoreturn;
 }
 
 }
 
-/* llmodule -> llmodule -> Mode.t -> unit
-   raises Error msg on error */
+/* llmodule -> llmodule -> Mode.t -> unit */
 CAMLprim value llvm_link_modules(LLVMModuleRef Dst, LLVMModuleRef Src, value Mode) {
   char* Message;
 
   if (LLVMLinkModules(Dst, Src, Int_val(Mode), &Message))
 CAMLprim value llvm_link_modules(LLVMModuleRef Dst, LLVMModuleRef Src, value Mode) {
   char* Message;
 
   if (LLVMLinkModules(Dst, Src, Int_val(Mode), &Message))
-    llvm_raise(llvm_linker_error_exn, Message);
+    llvm_raise(*caml_named_value("Llvm_linker.Error"), Message);
 
   return Val_unit;
 }
 
   return Val_unit;
 }
index 2b73e2e9c4e90b0f3ebb2f0803659412ed893607..5854d70bb525b62ccca422a0635f6891c3fadf91 100644 (file)
@@ -9,8 +9,7 @@
 
 exception Error of string
 
 
 exception Error of string
 
-external register_exns : exn -> unit = "llvm_register_linker_exns"
-let _ = register_exns (Error "")
+let () = Callback.register_exception "Llvm_linker.Error" (Error "")
 
 module Mode = struct
   type t =
 
 module Mode = struct
   type t =
@@ -19,4 +18,4 @@ module Mode = struct
 end
 
 external link_modules : Llvm.llmodule -> Llvm.llmodule -> Mode.t -> unit
 end
 
 external link_modules : Llvm.llmodule -> Llvm.llmodule -> Mode.t -> unit
-                      = "llvm_link_modules"
\ No newline at end of file
+                      = "llvm_link_modules"
index edb84e0af0dc4663b9fe1697cd7ff2a3719af1fb..6449480ae9eff77a76e8494c3852d69f7ba8790c 100644 (file)
@@ -4,7 +4,6 @@ description = "LLVM OCaml bindings"
 archive(byte) = "llvm.cma"
 archive(native) = "llvm.cmxa"
 directory = "."
 archive(byte) = "llvm.cma"
 archive(native) = "llvm.cmxa"
 directory = "."
-linkopts = "-ccopt -lstdc++"
 
 package "analysis" (
     requires = "llvm"
 
 package "analysis" (
     requires = "llvm"
index 134d4855ddf233fad0994619e6fed2311de89b39..c0785a154d2220ad1a2a30fc27fe4c28869e2fad 100644 (file)
@@ -15,6 +15,7 @@ LEVEL := ../../..
 LIBRARYNAME := llvm
 UsedComponents := core
 UsedOcamlLibs := llvm
 LIBRARYNAME := llvm
 UsedComponents := core
 UsedOcamlLibs := llvm
+ExtraLibs := -lstdc++
 
 include ../Makefile.ocaml
 
 
 include ../Makefile.ocaml
 
index 9f27b2dc4905cbdfb299193a1ca9cec4c0f36cb5..ef3c5b5b57cb80b1d28313edb5b06fe0973b202f 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm/llvm.ml - LLVM Ocaml Interface --------------------------------===*
+(*===-- llvm/llvm.ml - LLVM OCaml Interface -------------------------------===*
  *
  *                     The LLVM Compiler Infrastructure
  *
  *
  *                     The LLVM Compiler Infrastructure
  *
@@ -278,8 +278,7 @@ end
 
 exception IoError of string
 
 
 exception IoError of string
 
-external register_exns : exn -> unit = "llvm_register_core_exns"
-let _ = register_exns (IoError "")
+let () = Callback.register_exception "Llvm.IoError" (IoError "")
 
 external install_fatal_error_handler : (string -> unit) -> unit
                                      = "llvm_install_fatal_error_handler"
 
 external install_fatal_error_handler : (string -> unit) -> unit
                                      = "llvm_install_fatal_error_handler"
index 7eb88aa62e88517124782319c3d9f9c5f15da733..7f762e0ce03d0c7e32465f7e3ae68e2d2a290a5b 100644 (file)
 |*                                                                            *|
 \*===----------------------------------------------------------------------===*/
 
 |*                                                                            *|
 \*===----------------------------------------------------------------------===*/
 
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
 #include "llvm-c/Core.h"
 #include "caml/alloc.h"
 #include "caml/custom.h"
 #include "caml/memory.h"
 #include "caml/fail.h"
 #include "caml/callback.h"
 #include "llvm-c/Core.h"
 #include "caml/alloc.h"
 #include "caml/custom.h"
 #include "caml/memory.h"
 #include "caml/fail.h"
 #include "caml/callback.h"
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-/* Can't use the recommended caml_named_value mechanism for backwards
-   compatibility reasons. This is largely equivalent. */
-static value llvm_ioerror_exn;
-
-CAMLprim value llvm_register_core_exns(value IoError) {
-  llvm_ioerror_exn = Field(IoError, 0);
-  register_global_root(&llvm_ioerror_exn);
-
-  return Val_unit;
-}
 
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
 
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
@@ -45,10 +33,7 @@ static void llvm_raise(value Prototype, char *Message) {
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
-  abort(); /* NOTREACHED */
-#ifdef CAMLnoreturn
-  CAMLnoreturn; /* Silences warnings, but is missing in some versions. */
-#endif
+  CAMLnoreturn;
 }
 
 static value llvm_fatal_error_handler;
 }
 
 static value llvm_fatal_error_handler;
@@ -186,22 +171,24 @@ CAMLprim value llvm_dump_module(LLVMModuleRef M) {
 /* string -> llmodule -> unit */
 CAMLprim value llvm_print_module(value Filename, LLVMModuleRef M) {
   char* Message;
 /* string -> llmodule -> unit */
 CAMLprim value llvm_print_module(value Filename, LLVMModuleRef M) {
   char* Message;
-  if(LLVMPrintModuleToFile(M, String_val(Filename), &Message)) {
-    llvm_raise(llvm_ioerror_exn, Message);
-  }
+
+  if(LLVMPrintModuleToFile(M, String_val(Filename), &Message))
+    llvm_raise(*caml_named_value("Llvm.IoError"), Message);
 
   return Val_unit;
 }
 
 /* llmodule -> string */
 CAMLprim value llvm_string_of_llmodule(LLVMModuleRef M) {
 
   return Val_unit;
 }
 
 /* llmodule -> string */
 CAMLprim value llvm_string_of_llmodule(LLVMModuleRef M) {
+  CAMLparam0();
+  CAMLlocal1(ModuleStr);
   char* ModuleCStr;
   char* ModuleCStr;
-  ModuleCStr = LLVMPrintModuleToString(M);
 
 
-  value ModuleStr = caml_copy_string(ModuleCStr);
+  ModuleCStr = LLVMPrintModuleToString(M);
+  ModuleStr = caml_copy_string(ModuleCStr);
   LLVMDisposeMessage(ModuleCStr);
 
   LLVMDisposeMessage(ModuleCStr);
 
-  return ModuleStr;
+  CAMLreturn(ModuleStr);
 }
 
 /* llmodule -> string -> unit */
 }
 
 /* llmodule -> string -> unit */
@@ -234,13 +221,15 @@ CAMLprim value llvm_dump_type(LLVMTypeRef Val) {
 
 /* lltype -> string */
 CAMLprim value llvm_string_of_lltype(LLVMTypeRef M) {
 
 /* lltype -> string */
 CAMLprim value llvm_string_of_lltype(LLVMTypeRef M) {
+  CAMLparam0();
+  CAMLlocal1(TypeStr);
   char* TypeCStr;
   char* TypeCStr;
-  TypeCStr = LLVMPrintTypeToString(M);
 
 
-  value TypeStr = caml_copy_string(TypeCStr);
+  TypeCStr = LLVMPrintTypeToString(M);
+  TypeStr = caml_copy_string(TypeCStr);
   LLVMDisposeMessage(TypeCStr);
 
   LLVMDisposeMessage(TypeCStr);
 
-  return TypeStr;
+  CAMLreturn(TypeStr);
 }
 
 /*--... Operations on integer types ........................................--*/
 }
 
 /*--... Operations on integer types ........................................--*/
@@ -554,13 +543,15 @@ CAMLprim value llvm_dump_value(LLVMValueRef Val) {
 
 /* llvalue -> string */
 CAMLprim value llvm_string_of_llvalue(LLVMValueRef M) {
 
 /* llvalue -> string */
 CAMLprim value llvm_string_of_llvalue(LLVMValueRef M) {
+  CAMLparam0();
+  CAMLlocal1(ValueStr);
   char* ValueCStr;
   char* ValueCStr;
-  ValueCStr = LLVMPrintValueToString(M);
 
 
-  value ValueStr = caml_copy_string(ValueCStr);
+  ValueCStr = LLVMPrintValueToString(M);
+  ValueStr = caml_copy_string(ValueCStr);
   LLVMDisposeMessage(ValueCStr);
 
   LLVMDisposeMessage(ValueCStr);
 
-  return ValueStr;
+  CAMLreturn(ValueStr);
 }
 
 /* llvalue -> llvalue -> unit */
 }
 
 /* llvalue -> llvalue -> unit */
@@ -738,16 +729,22 @@ CAMLprim LLVMValueRef llvm_const_float(LLVMTypeRef RealTy, value N) {
 /* llvalue -> float */
 CAMLprim value llvm_float_of_const(LLVMValueRef Const)
 {
 /* llvalue -> float */
 CAMLprim value llvm_float_of_const(LLVMValueRef Const)
 {
+  CAMLparam0();
+  CAMLlocal1(Option);
+  LLVMBool LosesInfo;
+  double Result;
+
   if (LLVMIsAConstantFP(Const)) {
   if (LLVMIsAConstantFP(Const)) {
-    LLVMBool LosesInfo;
-    double res = LLVMConstRealGetDouble(Const, &LosesInfo);
+    Result = LLVMConstRealGetDouble(Const, &LosesInfo);
     if (LosesInfo)
         return Val_int(0);
     if (LosesInfo)
         return Val_int(0);
-    value Option = alloc(1, 0);
-    Field(Option, 0) = caml_copy_double(res);
-    return Option;
+
+    Option = alloc(1, 0);
+    Field(Option, 0) = caml_copy_double(Result);
+    CAMLreturn(Option);
   }
   }
-  return Val_int(0);
+
+  CAMLreturn(Val_int(0));
 }
 
 /* lltype -> string -> llvalue */
 }
 
 /* lltype -> string -> llvalue */
@@ -1536,15 +1533,13 @@ static void llvm_finalize_builder(value B) {
 }
 
 static struct custom_operations builder_ops = {
 }
 
 static struct custom_operations builder_ops = {
-  (char *) "LLVMIRBuilder",
+  (char *) "Llvm.llbuilder",
   llvm_finalize_builder,
   custom_compare_default,
   custom_hash_default,
   custom_serialize_default,
   llvm_finalize_builder,
   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_builder(LLVMBuilderRef B) {
 };
 
 static value alloc_builder(LLVMBuilderRef B) {
@@ -2254,7 +2249,7 @@ CAMLprim value llvm_memorybuffer_of_file(value Path) {
 
   if (LLVMCreateMemoryBufferWithContentsOfFile(String_val(Path),
                                                &MemBuf, &Message))
 
   if (LLVMCreateMemoryBufferWithContentsOfFile(String_val(Path),
                                                &MemBuf, &Message))
-    llvm_raise(llvm_ioerror_exn, Message);
+    llvm_raise(*caml_named_value("Llvm.IoError"), Message);
 
   CAMLreturn((value) MemBuf);
 }
 
   CAMLreturn((value) MemBuf);
 }
@@ -2266,20 +2261,21 @@ CAMLprim LLVMMemoryBufferRef llvm_memorybuffer_of_stdin(value Unit) {
   LLVMMemoryBufferRef MemBuf;
 
   if (LLVMCreateMemoryBufferWithSTDIN(&MemBuf, &Message))
   LLVMMemoryBufferRef MemBuf;
 
   if (LLVMCreateMemoryBufferWithSTDIN(&MemBuf, &Message))
-    llvm_raise(llvm_ioerror_exn, Message);
+    llvm_raise(*caml_named_value("Llvm.IoError"), Message);
 
   return MemBuf;
 }
 
 /* ?name:string -> string -> llmemorybuffer */
 CAMLprim LLVMMemoryBufferRef llvm_memorybuffer_of_string(value Name, value String) {
 
   return MemBuf;
 }
 
 /* ?name:string -> string -> llmemorybuffer */
 CAMLprim LLVMMemoryBufferRef llvm_memorybuffer_of_string(value Name, value String) {
+  LLVMMemoryBufferRef MemBuf;
   const char *NameCStr;
   const char *NameCStr;
+
   if(Name == Val_int(0))
     NameCStr = "";
   else
     NameCStr = String_val(Field(Name, 0));
 
   if(Name == Val_int(0))
     NameCStr = "";
   else
     NameCStr = String_val(Field(Name, 0));
 
-  LLVMMemoryBufferRef MemBuf;
   MemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(
                 String_val(String), caml_string_length(String), NameCStr);
 
   MemBuf = LLVMCreateMemoryBufferWithMemoryRangeCopy(
                 String_val(String), caml_string_length(String), NameCStr);
 
index 974bd49c2813bc10529ae5c22c38cad08df2bbe6..aadd90f5518af1fbca715ef553d6c4ff30d91cd6 100644 (file)
@@ -47,8 +47,7 @@ end
 
 exception Error of string
 
 
 exception Error of string
 
-external register_exns : exn -> unit = "llvm_register_target_exns"
-let _ = register_exns (Error "")
+let () = Callback.register_exception "Llvm_target.Error" (Error "")
 
 module DataLayout = struct
   type t
 
 module DataLayout = struct
   type t
index 74e8185827145cd8046d5cb99167c6142e589c84..fea3eff174ae62b8d58949793836ea023e87c7c6 100644 (file)
 #include "caml/fail.h"
 #include "caml/memory.h"
 #include "caml/custom.h"
 #include "caml/fail.h"
 #include "caml/memory.h"
 #include "caml/custom.h"
+#include "caml/callback.h"
 
 /*===---- Exceptions ------------------------------------------------------===*/
 
 
 /*===---- Exceptions ------------------------------------------------------===*/
 
-static value llvm_target_error_exn;
-
-CAMLprim value llvm_register_target_exns(value Error) {
-  llvm_target_error_exn = Field(Error, 0);
-  register_global_root(&llvm_target_error_exn);
-  return Val_unit;
-}
-
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
   CAMLlocal1(CamlMessage);
 static void llvm_raise(value Prototype, char *Message) {
   CAMLparam1(Prototype);
   CAMLlocal1(CamlMessage);
@@ -40,10 +33,7 @@ static void llvm_raise(value Prototype, char *Message) {
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
   LLVMDisposeMessage(Message);
 
   raise_with_arg(Prototype, CamlMessage);
-  abort(); /* NOTREACHED */
-#ifdef CAMLnoreturn
-  CAMLnoreturn; /* Silences warnings, but is missing in some versions. */
-#endif
+  CAMLnoreturn;
 }
 
 static value llvm_string_of_message(char* Message) {
 }
 
 static value llvm_string_of_message(char* Message) {
@@ -62,15 +52,13 @@ static void llvm_finalize_data_layout(value DataLayout) {
 }
 
 static struct custom_operations llvm_data_layout_ops = {
 }
 
 static struct custom_operations llvm_data_layout_ops = {
-  (char *) "LLVMDataLayout",
+  (char *) "Llvm_target.DataLayout.t",
   llvm_finalize_data_layout,
   custom_compare_default,
   custom_hash_default,
   custom_serialize_default,
   llvm_finalize_data_layout,
   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
 };
 
 value llvm_alloc_data_layout(LLVMTargetDataRef DataLayout) {
 };
 
 value llvm_alloc_data_layout(LLVMTargetDataRef DataLayout) {
@@ -219,7 +207,7 @@ CAMLprim LLVMTargetRef llvm_target_by_triple(value Triple) {
   char *Error;
 
   if(LLVMGetTargetFromTriple(String_val(Triple), &T, &Error))
   char *Error;
 
   if(LLVMGetTargetFromTriple(String_val(Triple), &T, &Error))
-    llvm_raise(llvm_target_error_exn, Error);
+    llvm_raise(*caml_named_value("Llvm_target.Error"), Error);
 
   return T;
 }
 
   return T;
 }
@@ -258,15 +246,13 @@ static void llvm_finalize_target_machine(value Machine) {
 }
 
 static struct custom_operations llvm_target_machine_ops = {
 }
 
 static struct custom_operations llvm_target_machine_ops = {
-  (char *) "LLVMTargetMachine",
+  (char *) "Llvm_target.TargetMachine.t",
   llvm_finalize_target_machine,
   custom_compare_default,
   custom_hash_default,
   custom_serialize_default,
   llvm_finalize_target_machine,
   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 llvm_alloc_targetmachine(LLVMTargetMachineRef Machine) {
 };
 
 static value llvm_alloc_targetmachine(LLVMTargetMachineRef Machine) {
@@ -337,6 +323,7 @@ CAMLprim value llvm_targetmachine_features(value Machine) {
 CAMLprim value llvm_targetmachine_data_layout(value Machine) {
   CAMLparam1(Machine);
   CAMLlocal1(DataLayout);
 CAMLprim value llvm_targetmachine_data_layout(value Machine) {
   CAMLparam1(Machine);
   CAMLlocal1(DataLayout);
+  char *TargetDataCStr;
 
   /* LLVMGetTargetMachineData returns a pointer owned by the TargetMachine,
      so it is impossible to wrap it with llvm_alloc_target_data, which assumes
 
   /* LLVMGetTargetMachineData returns a pointer owned by the TargetMachine,
      so it is impossible to wrap it with llvm_alloc_target_data, which assumes
@@ -344,7 +331,6 @@ CAMLprim value llvm_targetmachine_data_layout(value Machine) {
   LLVMTargetDataRef OrigDataLayout;
   OrigDataLayout = LLVMGetTargetMachineData(TargetMachine_val(Machine));
 
   LLVMTargetDataRef OrigDataLayout;
   OrigDataLayout = LLVMGetTargetMachineData(TargetMachine_val(Machine));
 
-  char* TargetDataCStr;
   TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
   DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
   LLVMDisposeMessage(TargetDataCStr);
   TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
   DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
   LLVMDisposeMessage(TargetDataCStr);
@@ -361,12 +347,12 @@ CAMLprim value llvm_targetmachine_set_verbose_asm(value Verb, value Machine) {
 /* Llvm.llmodule -> CodeGenFileType.t -> string -> TargetMachine.t -> unit */
 CAMLprim value llvm_targetmachine_emit_to_file(LLVMModuleRef Module,
                             value FileType, value FileName, value Machine) {
 /* Llvm.llmodule -> CodeGenFileType.t -> string -> TargetMachine.t -> unit */
 CAMLprim value llvm_targetmachine_emit_to_file(LLVMModuleRef Module,
                             value FileType, value FileName, value Machine) {
-  charErrorMessage;
+  char *ErrorMessage;
 
   if(LLVMTargetMachineEmitToFile(TargetMachine_val(Machine), Module,
                                  String_val(FileName), Int_val(FileType),
                                  &ErrorMessage)) {
 
   if(LLVMTargetMachineEmitToFile(TargetMachine_val(Machine), Module,
                                  String_val(FileName), Int_val(FileType),
                                  &ErrorMessage)) {
-    llvm_raise(llvm_target_error_exn, ErrorMessage);
+    llvm_raise(*caml_named_value("Llvm_target.Error"), ErrorMessage);
   }
 
   return Val_unit;
   }
 
   return Val_unit;
@@ -377,13 +363,13 @@ CAMLprim value llvm_targetmachine_emit_to_file(LLVMModuleRef Module,
 CAMLprim LLVMMemoryBufferRef llvm_targetmachine_emit_to_memory_buffer(
                                 LLVMModuleRef Module, value FileType,
                                 value Machine) {
 CAMLprim LLVMMemoryBufferRef llvm_targetmachine_emit_to_memory_buffer(
                                 LLVMModuleRef Module, value FileType,
                                 value Machine) {
-  charErrorMessage;
+  char *ErrorMessage;
   LLVMMemoryBufferRef Buffer;
 
   if(LLVMTargetMachineEmitToMemoryBuffer(TargetMachine_val(Machine), Module,
                                          Int_val(FileType), &ErrorMessage,
                                          &Buffer)) {
   LLVMMemoryBufferRef Buffer;
 
   if(LLVMTargetMachineEmitToMemoryBuffer(TargetMachine_val(Machine), Module,
                                          Int_val(FileType), &ErrorMessage,
                                          &Buffer)) {
-    llvm_raise(llvm_target_error_exn, ErrorMessage);
+    llvm_raise(*caml_named_value("Llvm_target.Error"), ErrorMessage);
   }
 
   return Buffer;
   }
 
   return Buffer;
index ed67a7cb3a0d000ba88f77e8c1685fc8b094a77c..f54bc4e39e420c82a3de52b6941600074aea3dfa 100644 (file)
@@ -1,4 +1,4 @@
-##===- bindings/ocaml/transforms/scalar/Makefile -----------*- Makefile -*-===##
+##===- bindings/ocaml/transforms/ipo/Makefile --------------*- Makefile -*-===##
 #
 #                     The LLVM Compiler Infrastructure
 #
 #
 #                     The LLVM Compiler Infrastructure
 #
@@ -7,7 +7,7 @@
 #
 ##===----------------------------------------------------------------------===##
 #
 #
 ##===----------------------------------------------------------------------===##
 #
-# This is the makefile for the Objective Caml Llvm_scalar_opts interface.
+# This is the makefile for the Objective Caml Llvm_ipo interface.
 #
 ##===----------------------------------------------------------------------===##
 
 #
 ##===----------------------------------------------------------------------===##
 
index a707856b822b9cd5f4dd3f2f5962dd2001b0d2ae..a43863cea69112a7581600984bcaa55ac5496202 100644 (file)
@@ -27,15 +27,13 @@ static void llvm_finalize_pmbuilder(value PMB) {
 }
 
 static struct custom_operations pmbuilder_ops = {
 }
 
 static struct custom_operations pmbuilder_ops = {
-  (char *) "LLVMPassManagerBuilder",
+  (char *) "Llvm_passmgr_builder.t",
   llvm_finalize_pmbuilder,
   custom_compare_default,
   custom_hash_default,
   custom_serialize_default,
   llvm_finalize_pmbuilder,
   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_pmbuilder(LLVMPassManagerBuilderRef Ref) {
 };
 
 static value alloc_pmbuilder(LLVMPassManagerBuilderRef Ref) {
index 5a854d17805b1bbfdbc254741f190772801d6e29..64ac5c3d030eef9a3019fd9286751e61ca9ea400 100644 (file)
@@ -7,7 +7,7 @@
 #
 ##===----------------------------------------------------------------------===##
 #
 #
 ##===----------------------------------------------------------------------===##
 #
-# This is the makefile for the Objective Caml Llvm_vectorize_opts interface.
+# This is the makefile for the Objective Caml Llvm_vectorize interface.
 #
 ##===----------------------------------------------------------------------===##
 
 #
 ##===----------------------------------------------------------------------===##
 
index d2aa21075810b4a41eab238922f38fee0af85d87..40fcd616ab2a1c9f986545fecc51ba75e79d7d48 100644 (file)
@@ -129,7 +129,7 @@ lit.site.cfg: FORCE
        @$(ECHOPATH) s=@PYTHON_EXECUTABLE@=$(PYTHON)=g >> lit.tmp
        @$(ECHOPATH) s=@OCAMLC@=$(OCAMLC)=g >> lit.tmp
        @$(ECHOPATH) s=@OCAMLOPT@=$(OCAMLOPT)=g >> lit.tmp
        @$(ECHOPATH) s=@PYTHON_EXECUTABLE@=$(PYTHON)=g >> lit.tmp
        @$(ECHOPATH) s=@OCAMLC@=$(OCAMLC)=g >> lit.tmp
        @$(ECHOPATH) s=@OCAMLOPT@=$(OCAMLOPT)=g >> lit.tmp
-       @$(ECHOPATH) s=@OCAMLFLAGS@=-cclib -lstdc++ -cclib -L$(LibDir) -I $(LibDir)/ocaml $(addprefix -cclib ,$(LDFLAGS))=g >> lit.tmp
+       @$(ECHOPATH) s=@OCAMLFLAGS@=-cclib -L$(LibDir) -I $(LibDir)/ocaml $(addprefix -cclib ,$(LDFLAGS))=g >> lit.tmp
        @$(ECHOPATH) s=@GO_EXECUTABLE@=$(GO)=g >> lit.tmp
        @$(ECHOPATH) s!@HOST_CC@!$(CC)!g >> lit.tmp
        @$(ECHOPATH) s!@HOST_CXX@!$(CXX)!g >> lit.tmp
        @$(ECHOPATH) s=@GO_EXECUTABLE@=$(GO)=g >> lit.tmp
        @$(ECHOPATH) s!@HOST_CC@!$(CC)!g >> lit.tmp
        @$(ECHOPATH) s!@HOST_CXX@!$(CXX)!g >> lit.tmp