| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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" |
| 23 |
#include "llvm_ocaml.h" |
| 24 |
|
| 25 |
|
| 26 |
value llvm_verify_module(LLVMModuleRef M) { |
| 27 |
CAMLparam0(); |
| 28 |
CAMLlocal2(String, Option); |
| 29 |
|
| 30 |
char *Message; |
| 31 |
int Result = LLVMVerifyModule(M, LLVMReturnStatusAction, &Message); |
| 32 |
|
| 33 |
if (0 == Result) { |
| 34 |
Option = Val_none; |
| 35 |
} else { |
| 36 |
String = copy_string(Message); |
| 37 |
Option = caml_alloc_some(String); |
| 38 |
} |
| 39 |
|
| 40 |
LLVMDisposeMessage(Message); |
| 41 |
|
| 42 |
CAMLreturn(Option); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
value llvm_verify_function(LLVMValueRef Fn) { |
| 47 |
return Val_bool(LLVMVerifyFunction(Fn, LLVMReturnStatusAction) == 0); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
value llvm_assert_valid_module(LLVMModuleRef M) { |
| 52 |
LLVMVerifyModule(M, LLVMAbortProcessAction, 0); |
| 53 |
return Val_unit; |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
value llvm_assert_valid_function(LLVMValueRef Fn) { |
| 58 |
LLVMVerifyFunction(Fn, LLVMAbortProcessAction); |
| 59 |
return Val_unit; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
value llvm_view_function_cfg(LLVMValueRef Fn) { |
| 64 |
LLVMViewFunctionCFG(Fn); |
| 65 |
return Val_unit; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
value llvm_view_function_cfg_only(LLVMValueRef Fn) { |
| 70 |
LLVMViewFunctionCFGOnly(Fn); |
| 71 |
return Val_unit; |
| 72 |
} |