1 /*===-- analysis_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 "llvm-c/Analysis.h"
19 #include "llvm-c/Core.h"
20 #include "caml/alloc.h"
21 #include "caml/mlvalues.h"
22 #include "caml/memory.h"
24 /* Llvm.llmodule -> string option */
25 CAMLprim value
llvm_verify_module(LLVMModuleRef M
) {
27 CAMLlocal2(String
, Option
);
30 int Result
= LLVMVerifyModule(M
, LLVMReturnStatusAction
, &Message
);
36 String
= copy_string(Message
);
37 Store_field(Option
, 0, String
);
40 LLVMDisposeMessage(Message
);
45 /* Llvm.llvalue -> bool */
46 CAMLprim value
llvm_verify_function(LLVMValueRef Fn
) {
47 return Val_bool(LLVMVerifyFunction(Fn
, LLVMReturnStatusAction
) == 0);
50 /* Llvm.llmodule -> unit */
51 CAMLprim value
llvm_assert_valid_module(LLVMModuleRef M
) {
52 LLVMVerifyModule(M
, LLVMAbortProcessAction
, 0);
56 /* Llvm.llvalue -> unit */
57 CAMLprim value
llvm_assert_valid_function(LLVMValueRef Fn
) {
58 LLVMVerifyFunction(Fn
, LLVMAbortProcessAction
);
62 /* Llvm.llvalue -> unit */
63 CAMLprim value
llvm_view_function_cfg(LLVMValueRef Fn
) {
64 LLVMViewFunctionCFG(Fn
);
68 /* Llvm.llvalue -> unit */
69 CAMLprim value
llvm_view_function_cfg_only(LLVMValueRef Fn
) {
70 LLVMViewFunctionCFGOnly(Fn
);