xref: /aosp_15_r20/external/llvm/bindings/ocaml/bitreader/bitreader_ocaml.c (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker /*===-- bitwriter_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
2*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
3*9880d681SAndroid Build Coastguard Worker |*                     The LLVM Compiler Infrastructure                       *|
4*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
5*9880d681SAndroid Build Coastguard Worker |* This file is distributed under the University of Illinois Open Source      *|
6*9880d681SAndroid Build Coastguard Worker |* License. See LICENSE.TXT for details.                                      *|
7*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
8*9880d681SAndroid Build Coastguard Worker |*===----------------------------------------------------------------------===*|
9*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
10*9880d681SAndroid Build Coastguard Worker |* This file glues LLVM's OCaml interface to its C interface. These functions *|
11*9880d681SAndroid Build Coastguard Worker |* are by and large transparent wrappers to the corresponding C functions.    *|
12*9880d681SAndroid Build Coastguard Worker |*                                                                            *|
13*9880d681SAndroid Build Coastguard Worker \*===----------------------------------------------------------------------===*/
14*9880d681SAndroid Build Coastguard Worker 
15*9880d681SAndroid Build Coastguard Worker #include "llvm-c/BitReader.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm-c/Core.h"
17*9880d681SAndroid Build Coastguard Worker #include "caml/alloc.h"
18*9880d681SAndroid Build Coastguard Worker #include "caml/fail.h"
19*9880d681SAndroid Build Coastguard Worker #include "caml/memory.h"
20*9880d681SAndroid Build Coastguard Worker #include "caml/callback.h"
21*9880d681SAndroid Build Coastguard Worker 
22*9880d681SAndroid Build Coastguard Worker void llvm_raise(value Prototype, char *Message);
23*9880d681SAndroid Build Coastguard Worker 
24*9880d681SAndroid Build Coastguard Worker /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
llvm_get_module(LLVMContextRef C,LLVMMemoryBufferRef MemBuf)25*9880d681SAndroid Build Coastguard Worker CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
26*9880d681SAndroid Build Coastguard Worker   LLVMModuleRef M;
27*9880d681SAndroid Build Coastguard Worker 
28*9880d681SAndroid Build Coastguard Worker   if (LLVMGetBitcodeModuleInContext2(C, MemBuf, &M))
29*9880d681SAndroid Build Coastguard Worker     llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
30*9880d681SAndroid Build Coastguard Worker 
31*9880d681SAndroid Build Coastguard Worker   return M;
32*9880d681SAndroid Build Coastguard Worker }
33*9880d681SAndroid Build Coastguard Worker 
34*9880d681SAndroid Build Coastguard Worker /* Llvm.llcontext -> Llvm.llmemorybuffer -> Llvm.llmodule */
llvm_parse_bitcode(LLVMContextRef C,LLVMMemoryBufferRef MemBuf)35*9880d681SAndroid Build Coastguard Worker CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef MemBuf) {
36*9880d681SAndroid Build Coastguard Worker   LLVMModuleRef M;
37*9880d681SAndroid Build Coastguard Worker 
38*9880d681SAndroid Build Coastguard Worker   if (LLVMParseBitcodeInContext2(C, MemBuf, &M))
39*9880d681SAndroid Build Coastguard Worker     llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
40*9880d681SAndroid Build Coastguard Worker 
41*9880d681SAndroid Build Coastguard Worker   return M;
42*9880d681SAndroid Build Coastguard Worker }
43