summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'bindings')
-rw-r--r--bindings/ocaml/llvm/llvm.ml2
-rw-r--r--bindings/ocaml/llvm/llvm.mli5
-rw-r--r--bindings/ocaml/llvm/llvm_ocaml.c12
3 files changed, 19 insertions, 0 deletions
diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml
index a8ecb3d8cf..c317a80458 100644
--- a/bindings/ocaml/llvm/llvm.ml
+++ b/bindings/ocaml/llvm/llvm.ml
@@ -165,6 +165,8 @@ external define_type_name : string -> lltype -> llmodule -> bool
= "llvm_add_type_name"
external delete_type_name : string -> llmodule -> unit
= "llvm_delete_type_name"
+external type_by_name : llmodule -> string -> lltype option
+ = "llvm_type_by_name"
external dump_module : llmodule -> unit = "llvm_dump_module"
(*===-- Types -------------------------------------------------------------===*)
diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli
index 06ffed52cf..7025f85b54 100644
--- a/bindings/ocaml/llvm/llvm.mli
+++ b/bindings/ocaml/llvm/llvm.mli
@@ -274,6 +274,11 @@ external define_type_name : string -> lltype -> llmodule -> bool
external delete_type_name : string -> llmodule -> unit
= "llvm_delete_type_name"
+(** [type_by_name m n] returns the type in the module [m] named [n], or [None]
+ if it does not exist. See the method [llvm::Module::getTypeByName]. *)
+external type_by_name : llmodule -> string -> lltype option
+ = "llvm_type_by_name"
+
(** [dump_module m] prints the .ll representation of the module [m] to standard
error. See the method [llvm::Module::dump]. *)
external dump_module : llmodule -> unit = "llvm_dump_module"
diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c
index d97523d60c..b06f688904 100644
--- a/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/bindings/ocaml/llvm/llvm_ocaml.c
@@ -164,6 +164,18 @@ CAMLprim value llvm_delete_type_name(value Name, LLVMModuleRef M) {
return Val_unit;
}
+/* llmodule -> string -> lltype option */
+CAMLprim value llvm_type_by_name(LLVMModuleRef M, value Name) {
+ CAMLparam1(Name);
+ LLVMTypeRef T;
+ if ((T = LLVMGetTypeByName(M, String_val(Name)))) {
+ value Option = alloc(1, 0);
+ Field(Option, 0) = (value) T;
+ CAMLreturn(Option);
+ }
+ CAMLreturn(Val_int(0));
+}
+
/* llmodule -> unit */
CAMLprim value llvm_dump_module(LLVMModuleRef M) {
LLVMDumpModule(M);