[OCaml] Expose Llvm_bitwriter.write_bitcode_to_memory_buffer.
authorPeter Zotov <whitequark@whitequark.org>
Wed, 29 Oct 2014 08:16:01 +0000 (08:16 +0000)
committerPeter Zotov <whitequark@whitequark.org>
Wed, 29 Oct 2014 08:16:01 +0000 (08:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220844 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/ocaml/bitwriter/bitwriter_ocaml.c
bindings/ocaml/bitwriter/llvm_bitwriter.ml
bindings/ocaml/bitwriter/llvm_bitwriter.mli
test/Bindings/Ocaml/bitwriter.ml

index 1045c2344a70f5978345ec7869d0b33aa41a50a4..f20fd59fd31afc80cfa24f3770315cdc01cc11c0 100644 (file)
@@ -43,3 +43,8 @@ CAMLprim value llvm_write_bitcode_to_fd(value U, LLVMModuleRef M, value FD) {
   Result = LLVMWriteBitcodeToFD(M, Int_val(FD), 0, Unbuffered);
   return Val_bool(Result == 0);
 }
+
+/* Llvm.llmodule -> Llvm.llmemorybuffer */
+CAMLprim LLVMMemoryBufferRef llvm_write_bitcode_to_memory_buffer(LLVMModuleRef M) {
+  return LLVMWriteBitcodeToMemoryBuffer(M);
+}
index fac85538dbab9b61d766ca2f81c25d921895e413..fca6efa4a75b2af6fdb6f412ec7f222c9209dee5 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm_bitwriter.ml - LLVM OCaml Interface ----------------*- C++ -*-===*
+(*===-- llvm_bitwriter.ml - LLVM OCaml Interface --------------*- OCaml -*-===*
  *
  *                     The LLVM Compiler Infrastructure
  *
  *
  *===----------------------------------------------------------------------===*)
 
+external write_bitcode_file
+  : Llvm.llmodule -> string -> bool
+  = "llvm_write_bitcode_file"
 
-(* Writes the bitcode for module the given path. Returns true if successful. *)
-external write_bitcode_file : Llvm.llmodule -> string -> bool
-                            = "llvm_write_bitcode_file"
+external write_bitcode_to_fd
+  : ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool
+  = "llvm_write_bitcode_to_fd"
 
-external write_bitcode_to_fd : ?unbuffered:bool -> Llvm.llmodule
-                               -> Unix.file_descr -> bool
-                             = "llvm_write_bitcode_to_fd"
+external write_bitcode_to_memory_buffer
+  : Llvm.llmodule -> Llvm.llmemorybuffer
+  = "llvm_write_bitcode_to_memory_buffer"
 
 let output_bitcode ?unbuffered channel m =
   write_bitcode_to_fd ?unbuffered m (Unix.descr_of_out_channel channel)
index bb3e3b89456000f285f39aeb90494a55aef3cd22..3d0f7808225727a0dccb20515f65c9d1357f2ab1 100644 (file)
@@ -1,4 +1,4 @@
-(*===-- llvm_bitwriter.mli - LLVM OCaml Interface ---------------*- C++ -*-===*
+(*===-- llvm_bitwriter.mli - LLVM OCaml Interface -------------*- OCaml -*-===*
  *
  *                     The LLVM Compiler Infrastructure
  *
 
 (** [write_bitcode_file m path] writes the bitcode for module [m] to the file at
     [path]. Returns [true] if successful, [false] otherwise. *)
-external write_bitcode_file : Llvm.llmodule -> string -> bool
-                            = "llvm_write_bitcode_file"
+external write_bitcode_file
+  : Llvm.llmodule -> string -> bool
+  = "llvm_write_bitcode_file"
 
 (** [write_bitcode_to_fd ~unbuffered fd m] writes the bitcode for module
     [m] to the channel [c]. If [unbuffered] is [true], after every write the fd
     will be flushed. Returns [true] if successful, [false] otherwise. *)
-external write_bitcode_to_fd : ?unbuffered:bool -> Llvm.llmodule
-                               -> Unix.file_descr -> bool
-                             = "llvm_write_bitcode_to_fd"
+external write_bitcode_to_fd
+  : ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool
+  = "llvm_write_bitcode_to_fd"
+
+(** [write_bitcode_to_memory_buffer m] returns a memory buffer containing
+    the bitcode for module [m]. *)
+external write_bitcode_to_memory_buffer
+  : Llvm.llmodule -> Llvm.llmemorybuffer
+  = "llvm_write_bitcode_to_memory_buffer"
 
 (** [output_bitcode ~unbuffered c m] writes the bitcode for module [m]
     to the channel [c]. If [unbuffered] is [true], after every write the fd
index 8ede44b597caf5ff1ffd5d0af210021117c899a2..98c04172a26eab5ef9120c475dc2531cfa5382b0 100644 (file)
@@ -45,4 +45,5 @@ let _ =
 
   test (file_buf = temp_bitcode m);
   test (file_buf = temp_bitcode ~unbuffered:false m);
-  test (file_buf = temp_bitcode ~unbuffered:true m)
+  test (file_buf = temp_bitcode ~unbuffered:true m);
+  test (file_buf = Llvm.MemoryBuffer.as_string (Llvm_bitwriter.write_bitcode_to_memory_buffer m))