remove attributions from the rest of the llvm makefiles.
[oota-llvm.git] / bindings / ocaml / bitreader / bitreader_ocaml.c
1 /*===-- bitwriter_ocaml.c - LLVM Ocaml Glue ---------------------*- C++ -*-===*\
2 |*                                                                            *|
3 |*                     The LLVM Compiler Infrastructure                       *|
4 |*                                                                            *|
5 |* This file was developed by Gordon Henriksen and is distributed under the   *|
6 |* University of Illinois Open Source License. See LICENSE.TXT for details.   *|
7 |*                                                                            *|
8 |*===----------------------------------------------------------------------===*|
9 |*                                                                            *|
10 |* This file glues LLVM's ocaml interface to its C interface. These functions *|
11 |* are by and large transparent wrappers to the corresponding C functions.    *|
12 |*                                                                            *|
13 \*===----------------------------------------------------------------------===*/
14
15 #include "llvm-c/BitReader.h"
16 #include "caml/alloc.h"
17 #include "caml/fail.h"
18 #include "caml/memory.h"
19
20
21 /* Can't use the recommended caml_named_value mechanism for backwards
22    compatibility reasons. This is largely equivalent. */
23 static value llvm_bitreader_error_exn;
24
25 CAMLprim value llvm_register_bitreader_exns(value Error) {
26   llvm_bitreader_error_exn = Field(Error, 0);
27   register_global_root(&llvm_bitreader_error_exn);
28   return Val_unit;
29 }
30
31 static void llvm_raise(value Prototype, char *Message) {
32   CAMLparam1(Prototype);
33   CAMLlocal1(CamlMessage);
34   
35   CamlMessage = copy_string(Message);
36   LLVMDisposeMessage(Message);
37   
38   raise_with_arg(Prototype, CamlMessage);
39   abort(); /* NOTREACHED */
40   CAMLnoreturn;
41 }
42
43
44 /*===-- Modules -----------------------------------------------------------===*/
45
46 /* Llvm.llmemorybuffer -> Llvm.module */
47 CAMLprim value llvm_get_module_provider(LLVMMemoryBufferRef MemBuf) {
48   CAMLparam0();
49   CAMLlocal2(Variant, MessageVal);
50   char *Message;
51   
52   LLVMModuleProviderRef MP;
53   if (LLVMGetBitcodeModuleProvider(MemBuf, &MP, &Message))
54     llvm_raise(llvm_bitreader_error_exn, Message);
55   
56   CAMLreturn((value) MemBuf);
57 }
58
59 /* Llvm.llmemorybuffer -> Llvm.llmodule */
60 CAMLprim value llvm_parse_bitcode(LLVMMemoryBufferRef MemBuf) {
61   CAMLparam0();
62   CAMLlocal2(Variant, MessageVal);
63   LLVMModuleRef M;
64   char *Message;
65   
66   if (LLVMParseBitcode(MemBuf, &M, &Message))
67     llvm_raise(llvm_bitreader_error_exn, Message);
68   
69   CAMLreturn((value) M);
70 }