Skip to content

Commit

Permalink
[OCaml] Refactor Llvm_target interface
Browse files Browse the repository at this point in the history
This commit brings the module structure, argument order and
primitive names in Llvm_target in order with the rest of the bindings,
in preparation for adding TargetMachine API.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194773 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
whitequark committed Nov 15, 2013
1 parent 68f4dae commit 04deb49
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 207 deletions.
18 changes: 13 additions & 5 deletions bindings/ocaml/executionengine/executionengine_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,18 @@ CAMLprim value llvm_ee_free_machine_code(LLVMValueRef F,
return Val_unit;
}

extern value llvm_alloc_target_data(LLVMTargetDataRef TargetData);
extern value llvm_alloc_data_layout(LLVMTargetDataRef TargetData);

/* ExecutionEngine.t -> Llvm_target.TargetData.t */
CAMLprim value llvm_ee_get_target_data(LLVMExecutionEngineRef EE) {
LLVMTargetDataRef TD = LLVMGetExecutionEngineTargetData(EE);
return llvm_alloc_target_data(TD);
/* ExecutionEngine.t -> Llvm_target.DataLayout.t */
CAMLprim value llvm_ee_get_data_layout(LLVMExecutionEngineRef EE) {
value DataLayout;
LLVMTargetDataRef OrigDataLayout;
OrigDataLayout = LLVMGetExecutionEngineTargetData(EE);

char* TargetDataCStr;
TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout);
DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr));
LLVMDisposeMessage(TargetDataCStr);

return DataLayout;
}
4 changes: 2 additions & 2 deletions bindings/ocaml/executionengine/llvm_executionengine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ module ExecutionEngine = struct
external free_machine_code: Llvm.llvalue -> t -> unit
= "llvm_ee_free_machine_code"

external target_data: t -> Llvm_target.DataLayout.t
= "llvm_ee_get_target_data"
external data_layout : t -> Llvm_target.DataLayout.t
= "llvm_ee_get_data_layout"

(* The following are not bound. Patches are welcome.

Expand Down
5 changes: 2 additions & 3 deletions bindings/ocaml/executionengine/llvm_executionengine.mli
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ module ExecutionEngine: sig
used to store the machine code for the function [f]. *)
val free_machine_code : Llvm.llvalue -> t -> unit

(** [target_data ee] is the target data owned by the execution engine
[ee]. *)
val target_data : t -> Llvm_target.DataLayout.t
(** [data_layout ee] is the data layout of the execution engine [ee]. *)
val data_layout : t -> Llvm_target.DataLayout.t
end

val initialize_native_target : unit -> bool
58 changes: 31 additions & 27 deletions bindings/ocaml/target/llvm_target.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,36 @@ end
module DataLayout = struct
type t

external create : string -> t = "llvm_targetdata_create"
external add : t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit
= "llvm_targetdata_add"
external as_string : t -> string = "llvm_targetdata_as_string"
external of_string : string -> t = "llvm_datalayout_of_string"
external as_string : t -> string = "llvm_datalayout_as_string"
external add_to_pass_manager : [<Llvm.PassManager.any]
Llvm.PassManager.t -> t -> unit
= "llvm_datalayout_add_to_pass_manager"
external byte_order : t -> Endian.t = "llvm_datalayout_byte_order"
external pointer_size : t -> int = "llvm_datalayout_pointer_size"
external intptr_type : Llvm.llcontext -> t -> Llvm.lltype
= "llvm_datalayout_intptr_type"
external qualified_pointer_size : int -> t -> int
= "llvm_datalayout_qualified_pointer_size"
external qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
= "llvm_datalayout_qualified_intptr_type"
external size_in_bits : Llvm.lltype -> t -> Int64.t
= "llvm_datalayout_size_in_bits"
external store_size : Llvm.lltype -> t -> Int64.t
= "llvm_datalayout_store_size"
external abi_size : Llvm.lltype -> t -> Int64.t
= "llvm_datalayout_abi_size"
external abi_align : Llvm.lltype -> t -> int
= "llvm_datalayout_abi_align"
external stack_align : Llvm.lltype -> t -> int
= "llvm_datalayout_stack_align"
external preferred_align : Llvm.lltype -> t -> int
= "llvm_datalayout_preferred_align"
external preferred_align_of_global : Llvm.llvalue -> t -> int
= "llvm_datalayout_preferred_align_of_global"
external element_at_offset : Llvm.lltype -> Int64.t -> t -> int
= "llvm_datalayout_element_at_offset"
external offset_of_element : Llvm.lltype -> int -> t -> Int64.t
= "llvm_datalayout_offset_of_element"
end

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"
external abi_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"
external abi_align : DataLayout.t -> Llvm.lltype -> int = "llvm_abi_align"
external stack_align : DataLayout.t -> Llvm.lltype -> int = "llvm_stack_align"
external preferred_align : DataLayout.t -> Llvm.lltype -> int
= "llvm_preferred_align"
external preferred_align_of_global : DataLayout.t -> Llvm.llvalue -> int
= "llvm_preferred_align_of_global"
external element_at_offset : DataLayout.t -> Llvm.lltype -> Int64.t -> int
= "llvm_element_at_offset"
external offset_of_element : DataLayout.t -> Llvm.lltype -> int -> Int64.t
= "llvm_offset_of_element"
151 changes: 71 additions & 80 deletions bindings/ocaml/target/llvm_target.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,84 +21,75 @@ end
module DataLayout : sig
type t

(** [DataLayout.create rep] parses the target data string representation [rep].
See the constructor llvm::DataLayout::DataLayout. *)
external create : string -> t = "llvm_targetdata_create"

(** [add_target_data td pm] adds the target data [td] to the pass manager [pm].
Does not take ownership of the target data.
See the method llvm::PassManagerBase::add. *)
external add : t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit
= "llvm_targetdata_add"

(** [as_string td] is the string representation of the target data [td].
See the constructor llvm::DataLayout::DataLayout. *)
external as_string : t -> string = "llvm_targetdata_as_string"
(** [of_string rep] parses the data layout string representation [rep].
See the constructor [llvm::DataLayout::DataLayout]. *)
val of_string : string -> t

(** [as_string dl] is the string representation of the data layout [dl].
See the method [llvm::DataLayout::getStringRepresentation]. *)
val as_string : t -> string

(** [add_to_pass_manager dl pm] adds the target data [dl] to
the pass manager [pm].
See the method [llvm::PassManagerBase::add]. *)
val add_to_pass_manager : [<Llvm.PassManager.any] Llvm.PassManager.t ->
t -> unit

(** Returns the byte order of a target, either [Endian.Big] or
[Endian.Little].
See the method [llvm::DataLayout::isLittleEndian]. *)
val byte_order : t -> Endian.t

(** Returns the pointer size in bytes for a target.
See the method [llvm::DataLayout::getPointerSize]. *)
val pointer_size : t -> int

(** Returns the integer type that is the same size as a pointer on a target.
See the method [llvm::DataLayout::getIntPtrType]. *)
val intptr_type : Llvm.llcontext -> t -> Llvm.lltype

(** Returns the pointer size in bytes for a target in a given address space.
See the method [llvm::DataLayout::getPointerSize]. *)
val qualified_pointer_size : int -> t -> int

(** 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]. *)
val qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype

(** Computes the size of a type in bits for a target.
See the method [llvm::DataLayout::getTypeSizeInBits]. *)
val size_in_bits : Llvm.lltype -> t -> Int64.t

(** Computes the storage size of a type in bytes for a target.
See the method [llvm::DataLayout::getTypeStoreSize]. *)
val store_size : Llvm.lltype -> t -> Int64.t

(** Computes the ABI size of a type in bytes for a target.
See the method [llvm::DataLayout::getTypeAllocSize]. *)
val abi_size : Llvm.lltype -> t -> Int64.t

(** Computes the ABI alignment of a type in bytes for a target.
See the method [llvm::DataLayout::getTypeABISize]. *)
val abi_align : Llvm.lltype -> t -> int

(** Computes the call frame alignment of a type in bytes for a target.
See the method [llvm::DataLayout::getTypeABISize]. *)
val stack_align : Llvm.lltype -> t -> int

(** Computes the preferred alignment of a type in bytes for a target.
See the method [llvm::DataLayout::getTypeABISize]. *)
val preferred_align : Llvm.lltype -> t -> int

(** Computes the preferred alignment of a global variable in bytes for
a target. See the method [llvm::DataLayout::getPreferredAlignment]. *)
val preferred_align_of_global : Llvm.llvalue -> t -> int

(** Computes the structure element that contains the byte offset for a target.
See the method [llvm::StructLayout::getElementContainingOffset]. *)
val element_at_offset : Llvm.lltype -> Int64.t -> t -> int

(** Computes the byte offset of the indexed struct element for a target.
See the method [llvm::StructLayout::getElementContainingOffset]. *)
val offset_of_element : Llvm.lltype -> int -> t -> Int64.t
end

(** Returns the byte order of a target, either LLVMBigEndian or
LLVMLittleEndian.
See the method llvm::DataLayout::isLittleEndian. *)
external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"

(** Returns the pointer size in bytes for a target.
See the method llvm::DataLayout::getPointerSize. *)
external pointer_size : DataLayout.t -> int = "llvm_pointer_size"

(** Returns the integer type that is the same size as a pointer on a target.
See the method llvm::DataLayout::getIntPtrType. *)
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
= "llvm_size_in_bits"

(** Computes the storage size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeStoreSize. *)
external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"

(** Computes the ABI size of a type in bytes for a target.
See the method llvm::DataLayout::getTypeAllocSize. *)
external abi_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_abi_size"

(** Computes the ABI alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. *)
external abi_align : DataLayout.t -> Llvm.lltype -> int = "llvm_abi_align"

(** Computes the call frame alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. *)
external stack_align : DataLayout.t -> Llvm.lltype -> int = "llvm_stack_align"

(** Computes the preferred alignment of a type in bytes for a target.
See the method llvm::DataLayout::getTypeABISize. *)
external preferred_align : DataLayout.t -> Llvm.lltype -> int
= "llvm_preferred_align"

(** Computes the preferred alignment of a global variable in bytes for a target.
See the method llvm::DataLayout::getPreferredAlignment. *)
external preferred_align_of_global : DataLayout.t -> Llvm.llvalue -> int
= "llvm_preferred_align_of_global"

(** Computes the structure element that contains the byte offset for a target.
See the method llvm::StructLayout::getElementContainingOffset. *)
external element_at_offset : DataLayout.t -> Llvm.lltype -> Int64.t -> int
= "llvm_element_at_offset"

(** Computes the byte offset of the indexed struct element for a target.
See the method llvm::StructLayout::getElementContainingOffset. *)
external offset_of_element : DataLayout.t -> Llvm.lltype -> int -> Int64.t
= "llvm_offset_of_element"
Loading

0 comments on commit 04deb49

Please sign in to comment.