diff options
author | Torok Edwin <edwintorok@gmail.com> | 2011-10-06 12:13:11 +0000 |
---|---|---|
committer | Torok Edwin <edwintorok@gmail.com> | 2011-10-06 12:13:11 +0000 |
commit | 4f661ab0fb87f97c4a12912249c3c366df882102 (patch) | |
tree | 673ddc9c55602ec3fcd07f6c1687718620e8b002 /bindings/ocaml/llvm/llvm_ocaml.c | |
parent | c44943ed4f4f2d44b6668e6b51eb355f8310660c (diff) |
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/ocaml/llvm/llvm_ocaml.c')
-rw-r--r-- | bindings/ocaml/llvm/llvm_ocaml.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c index 28f0977aba..14bdbdd068 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 */ |