DebugInfo: Require a DebugLoc in DIBuilder::insertDeclare()
[oota-llvm.git] / bindings / ocaml / bitreader / bitreader_ocaml.c
index 87477f6312d24b9e4f00c825b27f968af9f74a58..15ebd5f635fda966236612914f34e278fd6ef67c 100644 (file)
@@ -1,61 +1,43 @@
-/*===-- bitwriter_ocaml.c - LLVM Ocaml Glue ---------------------*- C++ -*-===*\
+/*===-- bitwriter_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
 |*                                                                            *|
 |*                     The LLVM Compiler Infrastructure                       *|
 |*                                                                            *|
-|* This file was developed by Gordon Henriksen and is distributed under the   *|
-|* University of Illinois Open Source License. See LICENSE.TXT for details.   *|
+|* This file is distributed under the University of Illinois Open Source      *|
+|* License. See LICENSE.TXT for details.                                      *|
 |*                                                                            *|
 |*===----------------------------------------------------------------------===*|
 |*                                                                            *|
-|* This file glues LLVM's ocaml interface to its C interface. These functions *|
+|* This file glues LLVM's OCaml interface to its C interface. These functions *|
 |* are by and large transparent wrappers to the corresponding C functions.    *|
 |*                                                                            *|
 \*===----------------------------------------------------------------------===*/
 
 #include "llvm-c/BitReader.h"
 #include "caml/alloc.h"
-#include "caml/mlvalues.h"
+#include "caml/fail.h"
 #include "caml/memory.h"
-#include <stdio.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"
 
 void llvm_raise(value Prototype, char *Message);
 
+/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
+CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
+  LLVMModuleRef M;
+  char *Message;
 
-/*===-- Modules -----------------------------------------------------------===*/
+  if (LLVMGetBitcodeModuleInContext(C, MemBuf, &M, &Message))
+    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message);
 
-/* Llvm.llmemorybuffer -> Llvm.module */
-CAMLprim value llvm_get_module_provider(LLVMMemoryBufferRef MemBuf) {
-  CAMLparam0();
-  CAMLlocal2(Variant, MessageVal);
-  char *Message;
-  
-  LLVMModuleProviderRef MP;
-  if (LLVMGetBitcodeModuleProvider(MemBuf, &MP, &Message))
-    llvm_raise(llvm_bitreader_error_exn, Message);
-  
-  CAMLreturn((value) MemBuf);
+  return M;
 }
 
-/* Llvm.llmemorybuffer -> Llvm.llmodule */
-CAMLprim value llvm_parse_bitcode(LLVMMemoryBufferRef MemBuf) {
-  CAMLparam0();
-  CAMLlocal2(Variant, MessageVal);
+/* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
+CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
   LLVMModuleRef M;
   char *Message;
-  
-  if (LLVMParseBitcode(MemBuf, &M, &Message))
-    llvm_raise(llvm_bitreader_error_exn, Message);
-  
-  CAMLreturn((value) M);
+
+  if (LLVMParseBitcodeInContext(C, MemBuf, &M, &Message))
+    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), Message);
+
+  return M;
 }