[NFC][OCaml] Simplify llvm_global_initializer using ptr_to_option

This diff uses ptr_to_option to convert a nullable C pointer to an
OCaml option instead of the redundant implementation in
llvm_global_initializer.

Differential Revision: https://reviews.llvm.org/D99391
This commit is contained in:
Josh Berdine 2021-03-25 23:07:46 +00:00
parent 1622731c2d
commit 511d90318d

View File

@ -1349,14 +1349,7 @@ CAMLprim value llvm_delete_global(LLVMValueRef GlobalVar) {
/* llvalue -> llvalue option */
CAMLprim value llvm_global_initializer(LLVMValueRef GlobalVar) {
CAMLparam0();
LLVMValueRef Init;
if ((Init = LLVMGetInitializer(GlobalVar))) {
value Option = alloc(1, 0);
Field(Option, 0) = (value) Init;
CAMLreturn(Option);
}
CAMLreturn(Val_int(0));
return ptr_to_option(LLVMGetInitializer(GlobalVar));
}
/* llvalue -> llvalue -> unit */