Skip to content

Commit

Permalink
[OCaml] Add missing Llvm_target functions
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194382 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
whitequark committed Nov 11, 2013
1 parent 786a43e commit fa6ab43
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bindings/ocaml/target/llvm_target.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
external intptr_type : DataLayout.t -> Llvm.llcontext -> Llvm.lltype
= "llvm_intptr_type"
external qualified_pointer_size : DataLayout.t -> int -> int
= "llvm_qualified_pointer_size"
external qualified_intptr_type : DataLayout.t -> Llvm.llcontext ->
int -> Llvm.lltype
= "llvm_qualified_intptr_type"
external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
= "llvm_size_in_bits"
external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
Expand Down
12 changes: 12 additions & 0 deletions bindings/ocaml/target/llvm_target.mli
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
external intptr_type : DataLayout.t -> Llvm.llcontext -> Llvm.lltype
= "llvm_intptr_type"

(** Returns the pointer size in bytes for a target in a given address space.
See the method llvm::DataLayout::getPointerSize. *)
external qualified_pointer_size : DataLayout.t -> int -> int
= "llvm_qualified_pointer_size"

(** Returns the integer type that is the same size as a pointer on a target
in a given address space.
See the method llvm::DataLayout::getIntPtrType. *)
external qualified_intptr_type : DataLayout.t -> Llvm.llcontext ->
int -> Llvm.lltype
= "llvm_qualified_intptr_type"

(** Computes the size of a type in bits for a target.
See the method llvm::DataLayout::getTypeSizeInBits. *)
external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
Expand Down
11 changes: 11 additions & 0 deletions bindings/ocaml/target/target_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ CAMLprim LLVMTypeRef llvm_intptr_type(value TD, LLVMContextRef C) {
return LLVMIntPtrTypeInContext(C, TargetData_val(TD));;
}

/* DataLayout.t -> int -> int */
CAMLprim value llvm_qualified_pointer_size(LLVMTargetDataRef TD, value AS) {
return Val_int(LLVMPointerSizeForAS(TargetData_val(TD), Int_val(AS)));
}

/* DataLayout.t -> int -> Llvm.lltype */
CAMLprim LLVMTypeRef llvm_qualified_intptr_type(LLVMTargetDataRef TD,
LLVMContextRef C, value AS) {
return LLVMIntPtrTypeForASInContext(C, TargetData_val(TD), Int_val(AS));
}

/* DataLayout.t -> Llvm.lltype -> Int64.t */
CAMLprim value llvm_size_in_bits(value TD, LLVMTypeRef Ty) {
return caml_copy_int64(LLVMSizeOfTypeInBits(TargetData_val(TD), Ty));
Expand Down
2 changes: 2 additions & 0 deletions test/Bindings/Ocaml/target.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ let test_target_data () =
assert_equal (byte_order td) Endian.Little;
assert_equal (pointer_size td) 4;
assert_equal (intptr_type td context) i32_type;
assert_equal (qualified_pointer_size td 0) 4;
assert_equal (qualified_intptr_type td context 0) i32_type;
assert_equal (size_in_bits td sty) (Int64.of_int 96);
assert_equal (store_size td sty) (Int64.of_int 12);
assert_equal (abi_size td sty) (Int64.of_int 12);
Expand Down

0 comments on commit fa6ab43

Please sign in to comment.