[llvm] r220898 - [OCaml] De-duplicate llvm_raise and llvm_string_of_message.

Peter Zotov whitequark at whitequark.org
Thu Oct 30 01:29:29 PDT 2014


Author: whitequark
Date: Thu Oct 30 03:29:29 2014
New Revision: 220898

URL: http://llvm.org/viewvc/llvm-project?rev=220898&view=rev
Log:
[OCaml] De-duplicate llvm_raise and llvm_string_of_message.

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

Modified: llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c?rev=220898&r1=220897&r2=220898&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/bitreader/bitreader_ocaml.c Thu Oct 30 03:29:29 2014
@@ -18,18 +18,7 @@
 #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) {

Modified: llvm/trunk/bindings/ocaml/bitwriter/bitwriter_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/bitwriter/bitwriter_ocaml.c?rev=220898&r1=220897&r2=220898&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/bitwriter/bitwriter_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/bitwriter/bitwriter_ocaml.c Thu Oct 30 03:29:29 2014
@@ -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));

Modified: llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c?rev=220898&r1=220897&r2=220898&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/executionengine/executionengine_ocaml.c Thu Oct 30 03:29:29 2014
@@ -25,16 +25,7 @@
 #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 .......................................--*/
 

Modified: llvm/trunk/bindings/ocaml/irreader/irreader_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/irreader/irreader_ocaml.c?rev=220898&r1=220897&r2=220898&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/irreader/irreader_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/irreader/irreader_ocaml.c Thu Oct 30 03:29:29 2014
@@ -18,18 +18,7 @@
 #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,

Modified: llvm/trunk/bindings/ocaml/linker/linker_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/linker/linker_ocaml.c?rev=220898&r1=220897&r2=220898&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/linker/linker_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/linker/linker_ocaml.c Thu Oct 30 03:29:29 2014
@@ -21,16 +21,7 @@
 #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) {

Modified: llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c?rev=220898&r1=220897&r2=220898&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c Thu Oct 30 03:29:29 2014
@@ -25,14 +25,16 @@
 #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;
 }
 

Modified: llvm/trunk/bindings/ocaml/target/target_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/target/target_ocaml.c?rev=220898&r1=220897&r2=220898&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/target/target_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/target/target_ocaml.c Thu Oct 30 03:29:29 2014
@@ -23,25 +23,8 @@
 #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 -----------------------------------------------------===*/
 





More information about the llvm-commits mailing list