1 /*===-- bitwriter_ocaml.c - LLVM OCaml Glue ---------------------*- C++ -*-===*\
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
8 |*===----------------------------------------------------------------------===*|
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. *|
13 |* Note that these functions intentionally take liberties with the CAMLparamX *|
14 |* macros, since most of the parameters are not GC heap objects. *|
16 \*===----------------------------------------------------------------------===*/
18 #include "caml/alloc.h"
19 #include "caml/memory.h"
20 #include "caml/mlvalues.h"
21 #include "llvm_ocaml.h"
22 #include "llvm-c/BitWriter.h"
23 #include "llvm-c/Core.h"
25 /* Llvm.llmodule -> string -> bool */
26 value
llvm_write_bitcode_file(value M
, value Path
) {
27 int Result
= LLVMWriteBitcodeToFile(Module_val(M
), String_val(Path
));
28 return Val_bool(Result
== 0);
31 /* ?unbuffered:bool -> Llvm.llmodule -> Unix.file_descr -> bool */
32 value
llvm_write_bitcode_to_fd(value U
, value M
, value FD
) {
36 if (U
== Val_int(0)) {
39 Unbuffered
= Bool_val(Field(U
, 0));
42 Result
= LLVMWriteBitcodeToFD(Module_val(M
), Int_val(FD
), 0, Unbuffered
);
43 return Val_bool(Result
== 0);
46 /* Llvm.llmodule -> Llvm.llmemorybuffer */
47 value
llvm_write_bitcode_to_memory_buffer(value M
) {
48 return to_val(LLVMWriteBitcodeToMemoryBuffer(Module_val(M
)));