From e5135b07e892e8ac76866c5aea60803b74866f3c Mon Sep 17 00:00:00 2001 From: Torok Edwin Date: Thu, 6 Oct 2011 12:13:28 +0000 Subject: [PATCH] ocaml/C bindings: type->isSized() llvm-svn: 141288 --- bindings/ocaml/llvm/llvm.ml | 1 + bindings/ocaml/llvm/llvm.mli | 5 +++++ bindings/ocaml/llvm/llvm_ocaml.c | 4 ++++ include/llvm-c/Core.h | 1 + lib/VMCore/Core.cpp | 5 +++++ 5 files changed, 16 insertions(+) diff --git a/bindings/ocaml/llvm/llvm.ml b/bindings/ocaml/llvm/llvm.ml index 1f7809e4dae..eaca48d8496 100644 --- a/bindings/ocaml/llvm/llvm.ml +++ b/bindings/ocaml/llvm/llvm.ml @@ -167,6 +167,7 @@ external set_module_inline_asm : llmodule -> string -> unit (*===-- Types -------------------------------------------------------------===*) external classify_type : lltype -> TypeKind.t = "llvm_classify_type" external type_context : lltype -> llcontext = "llvm_type_context" +external type_is_sized : lltype -> bool = "llvm_type_is_sized" (*--... Operations on integer types ........................................--*) external i1_type : llcontext -> lltype = "llvm_i1_type" diff --git a/bindings/ocaml/llvm/llvm.mli b/bindings/ocaml/llvm/llvm.mli index a5e5c850d6f..0f1e9a90170 100644 --- a/bindings/ocaml/llvm/llvm.mli +++ b/bindings/ocaml/llvm/llvm.mli @@ -271,6 +271,11 @@ val set_module_inline_asm : llmodule -> string -> unit See the method [llvm::Type::getTypeID]. *) val classify_type : lltype -> TypeKind.t +(** [type_is_sized ty] returns whether the type has a size or not. + * If it doesn't then it is not safe to call the [TargetData::] methods on it. + * *) +val type_is_sized : lltype -> bool + (** [type_context ty] returns the {!llcontext} corresponding to the type [ty]. See the method [llvm::Type::getContext]. *) val type_context : lltype -> llcontext diff --git a/bindings/ocaml/llvm/llvm_ocaml.c b/bindings/ocaml/llvm/llvm_ocaml.c index d6849cd193a..dd8cb16544c 100644 --- a/bindings/ocaml/llvm/llvm_ocaml.c +++ b/bindings/ocaml/llvm/llvm_ocaml.c @@ -172,6 +172,10 @@ CAMLprim value llvm_classify_type(LLVMTypeRef Ty) { return Val_int(LLVMGetTypeKind(Ty)); } +CAMLprim value llvm_type_is_sized(LLVMTypeRef Ty) { + return Val_bool(LLVMTypeIsSized(Ty)); +} + /* lltype -> llcontext */ CAMLprim LLVMContextRef llvm_type_context(LLVMTypeRef Ty) { return LLVMGetTypeContext(Ty); diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index 83fe89cbcfe..4d14af1e06b 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -355,6 +355,7 @@ LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M); /** See llvm::LLVMTypeKind::getTypeID. */ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty); +LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty); /** See llvm::LLVMType::getContext. */ LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty); diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index b8d2baf1e36..a6f04aed1f3 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -167,6 +167,11 @@ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) { } } +LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty) +{ + return unwrap(Ty)->isSized(); +} + LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) { return wrap(&unwrap(Ty)->getContext()); }