Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/bindings/ocaml/llvm/llvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ external vector_size : lltype -> int = "llvm_vector_size"
(*--... Operations on other types ..........................................--*)
external void_type : llcontext -> lltype = "llvm_void_type"
external label_type : llcontext -> lltype = "llvm_label_type"
external x86_amx_type : llcontext -> lltype = "llvm_x86_amx_type"
external token_type : llcontext -> lltype = "llvm_token_type"
external metadata_type : llcontext -> lltype = "llvm_metadata_type"
external type_by_name : llmodule -> string -> lltype option = "llvm_type_by_name"

external classify_value : llvalue -> ValueKind.t = "llvm_classify_value"
Expand Down
12 changes: 12 additions & 0 deletions llvm/bindings/ocaml/llvm/llvm.mli
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,18 @@ val void_type : llcontext -> lltype
[llvm::Type::LabelTy]. *)
val label_type : llcontext -> lltype

(** [x86_amx_type c] creates an X86 AMX type in the context [c]. See
[llvm::Type::getX86_AMXTy]. *)
val x86_amx_type : llcontext -> lltype

(** [token_type c] creates a token type in the context [c]. See
[llvm::Type::getTokenTy]. *)
val token_type : llcontext -> lltype

(** [metadata_type c] creates a metadata type in the context [c]. See
[llvm::Type::getMetadataTy]. *)
val metadata_type : llcontext -> lltype

(** [type_by_name m name] returns the specified type from the current module
if it exists.
See the method [llvm::Module::getTypeByName] *)
Expand Down
15 changes: 15 additions & 0 deletions llvm/bindings/ocaml/llvm/llvm_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,21 @@ value llvm_label_type(value Context) {
return to_val(LLVMLabelTypeInContext(Context_val(Context)));
}

/* llcontext -> lltype */
value llvm_x86_amx_type(value Context) {
return to_val(LLVMX86AMXTypeInContext(Context_val(Context)));
}

/* llcontext -> lltype */
value llvm_token_type(value Context) {
return to_val(LLVMTokenTypeInContext(Context_val(Context)));
}

/* llcontext -> lltype */
value llvm_metadata_type(value Context) {
return to_val(LLVMMetadataTypeInContext(Context_val(Context)));
}

/* llmodule -> string -> lltype option */
value llvm_type_by_name(value M, value Name) {
return ptr_to_option(LLVMGetTypeByName(Module_val(M), String_val(Name)));
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/Bindings/OCaml/core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ let test_contained_types () =
insist ([| i32_type; i8_type |] = struct_element_types ar)

(*===-- Pointer types ----------------------------------------------------===*)

let test_pointer_types () =
insist (TypeKind.Pointer = classify_type (pointer_type context));
insist (0 = address_space (pointer_type context));
insist (0 = address_space (qualified_pointer_type context 0));
insist (1 = address_space (qualified_pointer_type context 1))

(*===-- Other types ------------------------------------------------------===*)

let test_other_types () =
insist (TypeKind.Void = classify_type void_type);
insist (TypeKind.Label = classify_type (label_type context));
insist (TypeKind.X86_amx = classify_type (x86_amx_type context));
insist (TypeKind.Token = classify_type (token_type context));
insist (TypeKind.Metadata = classify_type (metadata_type context))

(*===-- Conversion --------------------------------------------------------===*)

let test_conversion () =
Expand Down Expand Up @@ -1461,6 +1472,7 @@ let _ =
suite "modules" test_modules;
suite "contained types" test_contained_types;
suite "pointer types" test_pointer_types;
suite "other types" test_other_types;
suite "conversion" test_conversion;
suite "target" test_target;
suite "constants" test_constants;
Expand Down
Loading