1 /*===-- llvm_ocaml.h - LLVM OCaml Glue --------------------------*- C++ -*-===*\ 2 |* *| 3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *| 4 |* Exceptions. *| 5 |* See https://llvm.org/LICENSE.txt for license information. *| 6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *| 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 |* Note that these functions intentionally take liberties with the CAMLparamX *| 14 |* macros, since most of the parameters are not GC heap objects. *| 15 |* *| 16 \*===----------------------------------------------------------------------===*/ 17 18 #ifndef LLVM_LLVM_OCAML_H 19 #define LLVM_LLVM_OCAML_H 20 21 #include "caml/alloc.h" 22 #include "caml/custom.h" 23 #include "caml/version.h" 24 25 #if OCAML_VERSION < 41200 26 /* operations on OCaml option values, defined by OCaml 4.12 */ 27 #define Val_none Val_int(0) 28 #define Some_val(v) Field(v, 0) 29 #define Tag_some 0 30 #define Is_none(v) ((v) == Val_none) 31 #define Is_some(v) Is_block(v) 32 value caml_alloc_some(value); 33 #endif 34 35 /* Convert a C pointer to an OCaml option */ 36 value ptr_to_option(void *Ptr); 37 38 /* Convert a C string into an OCaml string */ 39 value cstr_to_string(const char *Str, mlsize_t Len); 40 41 #endif // LLVM_LLVM_OCAML_H 42