Index: bindings/ocaml/llvm/llvm.ml =================================================================== --- bindings/ocaml/llvm/llvm.ml +++ bindings/ocaml/llvm/llvm.ml @@ -537,6 +537,7 @@ external operand_use : llvalue -> int -> lluse = "llvm_operand_use" external set_operand : llvalue -> int -> llvalue -> unit = "llvm_set_operand" external num_operands : llvalue -> int = "llvm_num_operands" +external indices : llvalue -> int array = "llvm_indices" (*--... Operations on constants of (mostly) any type .......................--*) external is_constant : llvalue -> bool = "llvm_is_constant" Index: bindings/ocaml/llvm/llvm.mli =================================================================== --- bindings/ocaml/llvm/llvm.mli +++ bindings/ocaml/llvm/llvm.mli @@ -810,6 +810,11 @@ val num_operands : llvalue -> int +(** [indices i] returns the number of indices for the ExtractValue or + InsertValue instruction [i]. + See the [llvm::getIndices] methods. *) +val indices : llvalue -> int array + (** {7 Operations on constants of (mostly) any type} *) (** [is_constant v] returns [true] if the value [v] is a constant, [false] Index: bindings/ocaml/llvm/llvm_ocaml.c =================================================================== --- bindings/ocaml/llvm/llvm_ocaml.c +++ bindings/ocaml/llvm/llvm_ocaml.c @@ -727,6 +727,19 @@ return Val_int(LLVMGetNumOperands(V)); } +/* llvalue -> int array */ +CAMLprim value llvm_indices(LLVMValueRef Instr) { + CAMLparam0(); + CAMLlocal1(Val_indices); + unsigned n = LLVMGetNumIndices(Instr); + const unsigned *Indices = LLVMGetIndices(Instr); + Val_indices = caml_alloc(n, 0); + for (unsigned i = 0; i < n; i++) { + Op_val(Val_indices)[i] = Val_int(Indices[i]); + } + CAMLreturn(Val_indices); +} + /*--... Operations on constants of (mostly) any type .......................--*/ /* llvalue -> bool */