[OCaml] De-duplicate llvm_raise and llvm_string_of_message.
authorPeter Zotov <whitequark@whitequark.org>
Thu, 30 Oct 2014 08:29:29 +0000 (08:29 +0000)
committerPeter Zotov <whitequark@whitequark.org>
Thu, 30 Oct 2014 08:29:29 +0000 (08:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220898 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/ocaml/bitreader/bitreader_ocaml.c
bindings/ocaml/bitwriter/bitwriter_ocaml.c
bindings/ocaml/executionengine/executionengine_ocaml.c
bindings/ocaml/irreader/irreader_ocaml.c
bindings/ocaml/linker/linker_ocaml.c
bindings/ocaml/llvm/llvm_ocaml.c
bindings/ocaml/target/target_ocaml.c

index eab3e1ae30e4b7c6504bd255d088c2a1820e0f94..15ebd5f635fda966236612914f34e278fd6ef67c 100644 (file)
 #include "caml/memory.h"
 #include "caml/callback.h"
 
-static void llvm_raise(value Prototype, char *Message) {
-  CAMLparam1(Prototype);
-  CAMLlocal1(CamlMessage);
-
-  CamlMessage = copy_string(Message);
-  LLVMDisposeMessage(Message);
-
-  raise_with_arg(Prototype, CamlMessage);
-  CAMLnoreturn;
-}
-
-/*===-- BitReader --------------------------------------------------------===*/
+void llvm_raise(value Prototype, char *Message);
 
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
 CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
index f20fd59fd31afc80cfa24f3770315cdc01cc11c0..04fd61917dc6205979d36b64c8c314bcb5effc94 100644 (file)
@@ -21,8 +21,6 @@
 #include "caml/mlvalues.h"
 #include "caml/memory.h"
 
-/*===-- BitWriter ---------------------------------------------------------===*/
-
 /* Llvm.llmodule -> string -> bool */
 CAMLprim value llvm_write_bitcode_file(LLVMModuleRef M, value Path) {
   int Result = LLVMWriteBitcodeToFile(M, String_val(Path));
index a12cc0091ae7bf0be34bf3cd8bd593665a20c219..c647d23133c3be504b942163212eba0ed4616a7b 100644 (file)
 #include "caml/memory.h"
 #include "caml/callback.h"
 
-static void llvm_raise(value Prototype, char *Message) {
-  CAMLparam1(Prototype);
-  CAMLlocal1(CamlMessage);
-
-  CamlMessage = copy_string(Message);
-  LLVMDisposeMessage(Message);
-
-  raise_with_arg(Prototype, CamlMessage);
-  CAMLnoreturn;
-}
+void llvm_raise(value Prototype, char *Message);
 
 /*--... Operations on generic values .......................................--*/
 
index d9f7a50c52d0ee11b9bde68b4510be368bbda549..ce593db80a8ea89c43806e9d38698655ffe08183 100644 (file)
 #include "caml/memory.h"
 #include "caml/callback.h"
 
-static void llvm_raise(value Prototype, char *Message) {
-  CAMLparam1(Prototype);
-  CAMLlocal1(CamlMessage);
-
-  CamlMessage = copy_string(Message);
-  LLVMDisposeMessage(Message);
-
-  raise_with_arg(Prototype, CamlMessage);
-  CAMLnoreturn;
-}
-
-/*===-- IRReader ----------------------------------------------------------===*/
+void llvm_raise(value Prototype, char *Message);
 
 /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
 CAMLprim value llvm_parse_ir(LLVMContextRef C,
index 553fbd91fe31f89cc2435a84096669bdac925476..ade0fbb56d912862a918f7d928bc6646e4371a63 100644 (file)
 #include "caml/fail.h"
 #include "caml/callback.h"
 
-static void llvm_raise(value Prototype, char *Message) {
-  CAMLparam1(Prototype);
-  CAMLlocal1(CamlMessage);
-
-  CamlMessage = copy_string(Message);
-  LLVMDisposeMessage(Message);
-
-  raise_with_arg(Prototype, CamlMessage);
-  CAMLnoreturn;
-}
+void llvm_raise(value Prototype, char *Message);
 
 /* llmodule -> llmodule -> Mode.t -> unit */
 CAMLprim value llvm_link_modules(LLVMModuleRef Dst, LLVMModuleRef Src, value Mode) {
index 4b146332c943170f165b3429b027e4973a3ec740..2348b6d16999b4660f772f7e80d79db91f0b9561 100644 (file)
 #include "caml/fail.h"
 #include "caml/callback.h"
 
-static void llvm_raise(value Prototype, char *Message) {
-  CAMLparam1(Prototype);
-  CAMLlocal1(CamlMessage);
-
-  CamlMessage = copy_string(Message);
+value llvm_string_of_message(char* Message) {
+  value String = caml_copy_string(Message);
   LLVMDisposeMessage(Message);
 
-  raise_with_arg(Prototype, CamlMessage);
+  return String;
+}
+
+void llvm_raise(value Prototype, char *Message) {
+  CAMLparam1(Prototype);
+  raise_with_arg(Prototype, llvm_string_of_message(Message));
   CAMLnoreturn;
 }
 
index efb5d9bd51e55fd8620059b6dc46c6fc2452d6b8..8f77cb46f13234a50d7fc8a0fc8f8847e6548359 100644 (file)
 #include "caml/custom.h"
 #include "caml/callback.h"
 
-/*===---- Exceptions ------------------------------------------------------===*/
-
-static void llvm_raise(value Prototype, char *Message) {
-  CAMLparam1(Prototype);
-  CAMLlocal1(CamlMessage);
-
-  CamlMessage = copy_string(Message);
-  LLVMDisposeMessage(Message);
-
-  raise_with_arg(Prototype, CamlMessage);
-  CAMLnoreturn;
-}
-
-static value llvm_string_of_message(char* Message) {
-  value String = caml_copy_string(Message);
-  LLVMDisposeMessage(Message);
-
-  return String;
-}
+void llvm_raise(value Prototype, char *Message);
+value llvm_string_of_message(char* Message);
 
 /*===---- Data Layout -----------------------------------------------------===*/