From ee462ca1943f609c78a1e5238a5dc62e20046e3b Mon Sep 17 00:00:00 2001 From: Peter Zotov Date: Wed, 22 Jun 2016 03:30:24 +0000 Subject: [PATCH] [OCaml] Add functions for accessing metadata nodes. Patch by Xinyu Zhuang. Differential Revision: http://reviews.llvm.org/D19309 llvm-svn: 273370 --- llvm/bindings/ocaml/llvm/llvm.ml | 2 ++ llvm/bindings/ocaml/llvm/llvm.mli | 4 ++++ llvm/bindings/ocaml/llvm/llvm_ocaml.c | 11 +++++++++++ llvm/test/Bindings/OCaml/core.ml | 1 + 4 files changed, 18 insertions(+) diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml index 5e149d44c411..513fe0c96870 100644 --- a/llvm/bindings/ocaml/llvm/llvm.ml +++ b/llvm/bindings/ocaml/llvm/llvm.ml @@ -483,6 +483,8 @@ external mdstring : llcontext -> string -> llvalue = "llvm_mdstring" external mdnode : llcontext -> llvalue array -> llvalue = "llvm_mdnode" external mdnull : llcontext -> llvalue = "llvm_mdnull" external get_mdstring : llvalue -> string option = "llvm_get_mdstring" +external get_mdnode_operands : llvalue -> llvalue array + = "llvm_get_mdnode_operands" external get_named_metadata : llmodule -> string -> llvalue array = "llvm_get_namedmd" external add_named_metadata_operand : llmodule -> string -> llvalue -> unit diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli index 8c0686198387..0f973000f754 100644 --- a/llvm/bindings/ocaml/llvm/llvm.mli +++ b/llvm/bindings/ocaml/llvm/llvm.mli @@ -852,6 +852,10 @@ val mdnull : llcontext -> llvalue See the method [llvm::MDString::getString] *) val get_mdstring : llvalue -> string option +(** [get_mdnode_operands v] returns the operands in the MDNode. *) +(* See the method [llvm::MDNode::getOperand] *) +val get_mdnode_operands : llvalue -> llvalue array + (** [get_named_metadata m name] returns all the MDNodes belonging to the named metadata (if any). See the method [llvm::NamedMDNode::getOperand]. *) diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c index 665842d0b6c3..f968db8efd03 100644 --- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c +++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c @@ -734,6 +734,17 @@ CAMLprim value llvm_get_mdstring(LLVMValueRef V) { CAMLreturn(Val_int(0)); } +CAMLprim value llvm_get_mdnode_operands(LLVMValueRef V) { + CAMLparam0(); + CAMLlocal1(Operands); + unsigned int n; + + n = LLVMGetMDNodeNumOperands(V); + Operands = alloc(n, 0); + LLVMGetMDNodeOperands(V, (LLVMValueRef *) Operands); + CAMLreturn(Operands); +} + /* llmodule -> string -> llvalue array */ CAMLprim value llvm_get_namedmd(LLVMModuleRef M, value Name) { diff --git a/llvm/test/Bindings/OCaml/core.ml b/llvm/test/Bindings/OCaml/core.ml index 78feae10b087..ee8281f111aa 100644 --- a/llvm/test/Bindings/OCaml/core.ml +++ b/llvm/test/Bindings/OCaml/core.ml @@ -1122,6 +1122,7 @@ let test_builder () = insist ((has_metadata i) = true); insist ((metadata i kind) = Some md); + insist ((get_mdnode_operands md) = [| m1; m2 |]); clear_metadata i kind;