[llvm][ocaml] Replace deprecated C functions in OCaml bindings
Follow-up to D135524, to replace two more deprecated C functions in the OCaml bindings. const_in_bounds_gep now accepts the source element type as argument, and const_element has been changed into aggregate_element, which works on a wider range of constants and returns an option. Differential Revision: https://reviews.llvm.org/D136914
This commit is contained in:
parent
d5e59e99f4
commit
181ede0ebd
|
@ -629,7 +629,8 @@ external const_packed_struct : llcontext -> llvalue array -> llvalue
|
||||||
= "llvm_const_packed_struct"
|
= "llvm_const_packed_struct"
|
||||||
external const_vector : llvalue array -> llvalue = "llvm_const_vector"
|
external const_vector : llvalue array -> llvalue = "llvm_const_vector"
|
||||||
external string_of_const : llvalue -> string option = "llvm_string_of_const"
|
external string_of_const : llvalue -> string option = "llvm_string_of_const"
|
||||||
external const_element : llvalue -> int -> llvalue = "llvm_const_element"
|
external aggregate_element : llvalue -> int -> llvalue option
|
||||||
|
= "llvm_aggregate_element"
|
||||||
|
|
||||||
(*--... Constant expressions ...............................................--*)
|
(*--... Constant expressions ...............................................--*)
|
||||||
external align_of : lltype -> llvalue = "LLVMAlignOf"
|
external align_of : lltype -> llvalue = "LLVMAlignOf"
|
||||||
|
@ -659,7 +660,7 @@ external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr"
|
||||||
external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
|
external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr"
|
||||||
external const_gep : lltype -> llvalue -> llvalue array -> llvalue
|
external const_gep : lltype -> llvalue -> llvalue array -> llvalue
|
||||||
= "llvm_const_gep"
|
= "llvm_const_gep"
|
||||||
external const_in_bounds_gep : llvalue -> llvalue array -> llvalue
|
external const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
|
||||||
= "llvm_const_in_bounds_gep"
|
= "llvm_const_in_bounds_gep"
|
||||||
external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
|
external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc"
|
||||||
external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
|
external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt"
|
||||||
|
|
|
@ -1044,9 +1044,11 @@ val const_vector : llvalue array -> llvalue
|
||||||
or [None] if this is not a string constant. *)
|
or [None] if this is not a string constant. *)
|
||||||
val string_of_const : llvalue -> string option
|
val string_of_const : llvalue -> string option
|
||||||
|
|
||||||
(** [const_element c] returns a constant for a specified index's element.
|
(** [aggregate_element c idx] returns [Some elt] where [elt] is the element of
|
||||||
See the method ConstantDataSequential::getElementAsConstant. *)
|
constant aggregate [c] at the specified index [idx], or [None] if [idx] is
|
||||||
val const_element : llvalue -> int -> llvalue
|
out of range or it's not possible to determine the element.
|
||||||
|
See the method [llvm::Constant::getAggregateElement]. *)
|
||||||
|
val aggregate_element : llvalue -> int -> llvalue option
|
||||||
|
|
||||||
|
|
||||||
(** {7 Constant expressions} *)
|
(** {7 Constant expressions} *)
|
||||||
|
@ -1169,10 +1171,10 @@ val const_ashr : llvalue -> llvalue -> llvalue
|
||||||
See the method [llvm::ConstantExpr::getGetElementPtr]. *)
|
See the method [llvm::ConstantExpr::getGetElementPtr]. *)
|
||||||
val const_gep : lltype -> llvalue -> llvalue array -> llvalue
|
val const_gep : lltype -> llvalue -> llvalue array -> llvalue
|
||||||
|
|
||||||
(** [const_in_bounds_gep pc indices] returns the constant [getElementPtr] of [pc]
|
(** [const_in_bounds_gep ty pc indices] returns the constant [getElementPtr] of
|
||||||
with the constant integers indices from the array [indices].
|
[pc] with the constant integers indices from the array [indices].
|
||||||
See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
|
See the method [llvm::ConstantExpr::getInBoundsGetElementPtr]. *)
|
||||||
val const_in_bounds_gep : llvalue -> llvalue array -> llvalue
|
val const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
|
||||||
|
|
||||||
(** [const_trunc c ty] returns the constant truncation of integer constant [c]
|
(** [const_trunc c ty] returns the constant truncation of integer constant [c]
|
||||||
to the smaller integer type [ty].
|
to the smaller integer type [ty].
|
||||||
|
|
|
@ -968,9 +968,9 @@ value llvm_string_of_const(LLVMValueRef Const) {
|
||||||
return cstr_to_string_option(CStr, Len);
|
return cstr_to_string_option(CStr, Len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* llvalue -> int -> llvalue */
|
/* llvalue -> int -> llvalue option */
|
||||||
LLVMValueRef llvm_const_element(LLVMValueRef Const, value N) {
|
value llvm_aggregate_element(LLVMValueRef Const, value N) {
|
||||||
return LLVMGetElementAsConstant(Const, Int_val(N));
|
return ptr_to_option(LLVMGetAggregateElement(Const, Int_val(N)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--... Constant expressions ...............................................--*/
|
/*--... Constant expressions ...............................................--*/
|
||||||
|
@ -995,8 +995,9 @@ LLVMValueRef llvm_const_gep(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* llvalue -> llvalue array -> llvalue */
|
/* llvalue -> llvalue array -> llvalue */
|
||||||
LLVMValueRef llvm_const_in_bounds_gep(LLVMValueRef ConstantVal, value Indices) {
|
LLVMValueRef llvm_const_in_bounds_gep(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
|
||||||
return LLVMConstInBoundsGEP(ConstantVal, (LLVMValueRef *)Op_val(Indices),
|
value Indices) {
|
||||||
|
return LLVMConstInBoundsGEP2(Ty, ConstantVal, (LLVMValueRef *)Op_val(Indices),
|
||||||
Wosize_val(Indices));
|
Wosize_val(Indices));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,8 +185,9 @@ let test_constants () =
|
||||||
let c = const_array i32_type [| three; four |] in
|
let c = const_array i32_type [| three; four |] in
|
||||||
ignore (define_global "const_array" c m);
|
ignore (define_global "const_array" c m);
|
||||||
insist ((array_type i32_type 2) = (type_of c));
|
insist ((array_type i32_type 2) = (type_of c));
|
||||||
insist (three = (const_element c 0));
|
insist (Some three = (aggregate_element c 0));
|
||||||
insist (four = (const_element c 1));
|
insist (Some four = (aggregate_element c 1));
|
||||||
|
insist (None = (aggregate_element c 2));
|
||||||
|
|
||||||
(* CHECK: const_vector{{.*}}<i16 1, i16 2{{.*}}>
|
(* CHECK: const_vector{{.*}}<i16 1, i16 2{{.*}}>
|
||||||
*)
|
*)
|
||||||
|
|
Loading…
Reference in New Issue