aboutsummaryrefslogtreecommitdiffstats
path: root/bindings/ocaml
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/ocaml')
-rw-r--r--bindings/ocaml/llvm/llvm.ml1
-rw-r--r--bindings/ocaml/llvm/llvm.mli4
-rw-r--r--bindings/ocaml/llvm/llvm_ocaml.c14
3 files changed, 19 insertions, 0 deletions
diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml
index e335eb8..e46ea04 100644
--- a/bindings/ocaml/llvm/llvm.ml
+++ b/bindings/ocaml/llvm/llvm.ml
@@ -197,6 +197,7 @@ external param_types : lltype -> lltype array = "llvm_param_types"
external struct_type : llcontext -> lltype array -> lltype = "llvm_struct_type"
external packed_struct_type : llcontext -> lltype array -> lltype
= "llvm_packed_struct_type"
+external struct_name : lltype -> string option = "llvm_struct_name"
external struct_element_types : lltype -> lltype array
= "llvm_struct_element_types"
external is_packed : lltype -> bool = "llvm_is_packed"
diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli
index ef7c986..c070170 100644
--- a/bindings/ocaml/llvm/llvm.mli
+++ b/bindings/ocaml/llvm/llvm.mli
@@ -372,6 +372,10 @@ val struct_type : llcontext -> lltype array -> lltype
[llvm::StructType::get]. *)
val packed_struct_type : llcontext -> lltype array -> lltype
+(** [struct_name ty] returns the name of the named structure type [ty],
+ * or None if the structure type is not named *)
+val struct_name : lltype -> string option
+
(** [struct_element_types sty] returns the constituent types of the struct type
[sty]. See the method [llvm::StructType::getElementType]. *)
diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c
index 1c1a526..28f0977 100644
--- a/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/bindings/ocaml/llvm/llvm_ocaml.c
@@ -287,6 +287,20 @@ CAMLprim LLVMTypeRef llvm_packed_struct_type(LLVMContextRef C,
Wosize_val(ElementTypes), 1);
}
+/* lltype -> string option */
+CAMLprim value llvm_struct_name(LLVMTypeRef Ty)
+{
+ CAMLparam0();
+ const char *C = LLVMGetStructName(Ty);
+ if (C) {
+ CAMLlocal1(result);
+ result = caml_alloc_small(1, 0);
+ Store_field(result, 0, caml_copy_string(C));
+ CAMLreturn(result);
+ }
+ CAMLreturn(Val_int(0));
+}
+
/* lltype -> lltype array */
CAMLprim value llvm_struct_element_types(LLVMTypeRef StructTy) {
value Tys = alloc(LLVMCountStructElementTypes(StructTy), 0);