Skip to content

Commit

Permalink
[OCaml] Add functions for accessing metadata nodes.
Browse files Browse the repository at this point in the history
Patch by Xinyu Zhuang.

Differential Revision: http://reviews.llvm.org/D19309

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273370 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
whitequark committed Jun 22, 2016
1 parent 06dbef9 commit 98c9164
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bindings/ocaml/llvm/llvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions bindings/ocaml/llvm/llvm.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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]. *)
Expand Down
11 changes: 11 additions & 0 deletions bindings/ocaml/llvm/llvm_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions test/Bindings/OCaml/core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 98c9164

Please sign in to comment.