Skip to content

Commit 0550c32

Browse files
authored
[OCaml] Add bindings for x86_amx, token, and metadata types (#120638)
1 parent f39ecb7 commit 0550c32

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

llvm/bindings/ocaml/llvm/llvm.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ external vector_size : lltype -> int = "llvm_vector_size"
525525
(*--... Operations on other types ..........................................--*)
526526
external void_type : llcontext -> lltype = "llvm_void_type"
527527
external label_type : llcontext -> lltype = "llvm_label_type"
528+
external x86_amx_type : llcontext -> lltype = "llvm_x86_amx_type"
529+
external token_type : llcontext -> lltype = "llvm_token_type"
530+
external metadata_type : llcontext -> lltype = "llvm_metadata_type"
528531
external type_by_name : llmodule -> string -> lltype option = "llvm_type_by_name"
529532

530533
external classify_value : llvalue -> ValueKind.t = "llvm_classify_value"

llvm/bindings/ocaml/llvm/llvm.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,18 @@ val void_type : llcontext -> lltype
766766
[llvm::Type::LabelTy]. *)
767767
val label_type : llcontext -> lltype
768768

769+
(** [x86_amx_type c] creates an X86 AMX type in the context [c]. See
770+
[llvm::Type::getX86_AMXTy]. *)
771+
val x86_amx_type : llcontext -> lltype
772+
773+
(** [token_type c] creates a token type in the context [c]. See
774+
[llvm::Type::getTokenTy]. *)
775+
val token_type : llcontext -> lltype
776+
777+
(** [metadata_type c] creates a metadata type in the context [c]. See
778+
[llvm::Type::getMetadataTy]. *)
779+
val metadata_type : llcontext -> lltype
780+
769781
(** [type_by_name m name] returns the specified type from the current module
770782
if it exists.
771783
See the method [llvm::Module::getTypeByName] *)

llvm/bindings/ocaml/llvm/llvm_ocaml.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,21 @@ value llvm_label_type(value Context) {
686686
return to_val(LLVMLabelTypeInContext(Context_val(Context)));
687687
}
688688

689+
/* llcontext -> lltype */
690+
value llvm_x86_amx_type(value Context) {
691+
return to_val(LLVMX86AMXTypeInContext(Context_val(Context)));
692+
}
693+
694+
/* llcontext -> lltype */
695+
value llvm_token_type(value Context) {
696+
return to_val(LLVMTokenTypeInContext(Context_val(Context)));
697+
}
698+
699+
/* llcontext -> lltype */
700+
value llvm_metadata_type(value Context) {
701+
return to_val(LLVMMetadataTypeInContext(Context_val(Context)));
702+
}
703+
689704
/* llmodule -> string -> lltype option */
690705
value llvm_type_by_name(value M, value Name) {
691706
return ptr_to_option(LLVMGetTypeByName(Module_val(M), String_val(Name)));

llvm/test/Bindings/OCaml/core.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,22 @@ let test_contained_types () =
4848
insist ([| i32_type; i8_type |] = struct_element_types ar)
4949

5050
(*===-- Pointer types ----------------------------------------------------===*)
51+
5152
let test_pointer_types () =
53+
insist (TypeKind.Pointer = classify_type (pointer_type context));
5254
insist (0 = address_space (pointer_type context));
5355
insist (0 = address_space (qualified_pointer_type context 0));
5456
insist (1 = address_space (qualified_pointer_type context 1))
5557

58+
(*===-- Other types ------------------------------------------------------===*)
59+
60+
let test_other_types () =
61+
insist (TypeKind.Void = classify_type void_type);
62+
insist (TypeKind.Label = classify_type (label_type context));
63+
insist (TypeKind.X86_amx = classify_type (x86_amx_type context));
64+
insist (TypeKind.Token = classify_type (token_type context));
65+
insist (TypeKind.Metadata = classify_type (metadata_type context))
66+
5667
(*===-- Conversion --------------------------------------------------------===*)
5768

5869
let test_conversion () =
@@ -1461,6 +1472,7 @@ let _ =
14611472
suite "modules" test_modules;
14621473
suite "contained types" test_contained_types;
14631474
suite "pointer types" test_pointer_types;
1475+
suite "other types" test_other_types;
14641476
suite "conversion" test_conversion;
14651477
suite "target" test_target;
14661478
suite "constants" test_constants;

0 commit comments

Comments
 (0)