aboutsummaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorTorok Edwin <edwintorok@gmail.com>2011-10-06 12:13:11 +0000
committerTorok Edwin <edwintorok@gmail.com>2011-10-06 12:13:11 +0000
commit4f661ab0fb87f97c4a12912249c3c366df882102 (patch)
tree673ddc9c55602ec3fcd07f6c1687718620e8b002 /bindings
parentc44943ed4f4f2d44b6668e6b51eb355f8310660c (diff)
downloadexternal_llvm-4f661ab0fb87f97c4a12912249c3c366df882102.zip
external_llvm-4f661ab0fb87f97c4a12912249c3c366df882102.tar.gz
external_llvm-4f661ab0fb87f97c4a12912249c3c366df882102.tar.bz2
ocaml/C bindings: getmdstring, add num_op, get_op should work on metadata too
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141286 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/ocaml/llvm/llvm.ml2
-rw-r--r--bindings/ocaml/llvm/llvm.mli8
-rw-r--r--bindings/ocaml/llvm/llvm_ocaml.c27
3 files changed, 37 insertions, 0 deletions
diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml
index e46ea04..f68ab8d 100644
--- a/bindings/ocaml/llvm/llvm.ml
+++ b/bindings/ocaml/llvm/llvm.ml
@@ -281,6 +281,8 @@ external clear_metadata : llvalue -> int -> unit = "llvm_clear_metadata"
(*--... Operations on metadata .......,.....................................--*)
external mdstring : llcontext -> string -> llvalue = "llvm_mdstring"
external mdnode : llcontext -> llvalue array -> llvalue = "llvm_mdnode"
+external get_mdstring : llvalue -> string option = "llvm_get_mdstring"
+external get_named_metadata : llmodule -> string -> llvalue array = "llvm_get_namedmd"
(*--... Operations on scalar constants .....................................--*)
external const_int : lltype -> int -> llvalue = "llvm_const_int"
diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli
index c070170..b4b9622 100644
--- a/bindings/ocaml/llvm/llvm.mli
+++ b/bindings/ocaml/llvm/llvm.mli
@@ -571,6 +571,14 @@ val mdstring : llcontext -> string -> llvalue
See the method [llvm::MDNode::get]. *)
val mdnode : llcontext -> llvalue array -> llvalue
+(** [get_mdstring v] returns the MDString.
+ * See the method [llvm::MDString::getString] *)
+val get_mdstring : llvalue -> string option
+
+(** [get_named_metadata m name] return all the MDNodes belonging to the named
+ * metadata (if any).
+ * See the method [llvm::NamedMDNode::getOperand]. *)
+val get_named_metadata : llmodule -> string -> llvalue array
(** {7 Operations on scalar constants} *)
diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c
index 28f0977..14bdbdd 100644
--- a/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/bindings/ocaml/llvm/llvm_ocaml.c
@@ -24,6 +24,7 @@
#include "llvm/Config/config.h"
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
/* Can't use the recommended caml_named_value mechanism for backwards
@@ -468,6 +469,32 @@ CAMLprim LLVMValueRef llvm_mdnode(LLVMContextRef C, value ElementVals) {
Wosize_val(ElementVals));
}
+/* llvalue -> string option */
+CAMLprim value llvm_get_mdstring(LLVMValueRef V) {
+ CAMLparam0();
+ const char *S;
+ unsigned Len;
+
+ if ((S = LLVMGetMDString(V, &Len))) {
+ CAMLlocal2(Option, Str);
+
+ Str = caml_alloc_string(Len);
+ memcpy(String_val(Str), S, Len);
+ Option = alloc(1,0);
+ Store_field(Option, 0, Str);
+ CAMLreturn(Option);
+ }
+ CAMLreturn(Val_int(0));
+}
+
+CAMLprim value llvm_get_namedmd(LLVMModuleRef M, value name)
+{
+ CAMLparam1(name);
+ CAMLlocal1(Nodes);
+ Nodes = alloc(LLVMGetNamedMetadataNumOperands(M, String_val(name)), 0);
+ LLVMGetNamedMetadataOperands(M, String_val(name), (LLVMValueRef *) Nodes);
+ CAMLreturn(Nodes);
+}
/*--... Operations on scalar constants .....................................--*/
/* lltype -> int -> llvalue */