1 (*===-- llvm_target.mli - LLVM OCaml Interface -----------------*- OCaml -*-===*
3 * The LLVM Compiler Infrastructure
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
8 *===----------------------------------------------------------------------===*)
10 (** Target Information.
12 This interface provides an OCaml API for LLVM target information,
13 the classes in the Target library. *)
21 module CodeGenOptLevel : sig
29 module RelocMode : sig
37 module CodeModel : sig
47 module CodeGenFileType : sig
55 exception Error of string
57 (** {6 Data Layout} *)
59 module DataLayout : sig
62 (** [of_string rep] parses the data layout string representation [rep].
63 See the constructor [llvm::DataLayout::DataLayout]. *)
64 val of_string : string -> t
66 (** [as_string dl] is the string representation of the data layout [dl].
67 See the method [llvm::DataLayout::getStringRepresentation]. *)
68 val as_string : t -> string
70 (** [add_to_pass_manager dl pm] adds the target data [dl] to
71 the pass manager [pm].
72 See the method [llvm::PassManagerBase::add]. *)
73 val add_to_pass_manager : [<Llvm.PassManager.any] Llvm.PassManager.t ->
76 (** Returns the byte order of a target, either [Endian.Big] or
78 See the method [llvm::DataLayout::isLittleEndian]. *)
79 val byte_order : t -> Endian.t
81 (** Returns the pointer size in bytes for a target.
82 See the method [llvm::DataLayout::getPointerSize]. *)
83 val pointer_size : t -> int
85 (** Returns the integer type that is the same size as a pointer on a target.
86 See the method [llvm::DataLayout::getIntPtrType]. *)
87 val intptr_type : Llvm.llcontext -> t -> Llvm.lltype
89 (** Returns the pointer size in bytes for a target in a given address space.
90 See the method [llvm::DataLayout::getPointerSize]. *)
91 val qualified_pointer_size : int -> t -> int
93 (** Returns the integer type that is the same size as a pointer on a target
94 in a given address space.
95 See the method [llvm::DataLayout::getIntPtrType]. *)
96 val qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
98 (** Computes the size of a type in bits for a target.
99 See the method [llvm::DataLayout::getTypeSizeInBits]. *)
100 val size_in_bits : Llvm.lltype -> t -> Int64.t
102 (** Computes the storage size of a type in bytes for a target.
103 See the method [llvm::DataLayout::getTypeStoreSize]. *)
104 val store_size : Llvm.lltype -> t -> Int64.t
106 (** Computes the ABI size of a type in bytes for a target.
107 See the method [llvm::DataLayout::getTypeAllocSize]. *)
108 val abi_size : Llvm.lltype -> t -> Int64.t
110 (** Computes the ABI alignment of a type in bytes for a target.
111 See the method [llvm::DataLayout::getTypeABISize]. *)
112 val abi_align : Llvm.lltype -> t -> int
114 (** Computes the call frame alignment of a type in bytes for a target.
115 See the method [llvm::DataLayout::getTypeABISize]. *)
116 val stack_align : Llvm.lltype -> t -> int
118 (** Computes the preferred alignment of a type in bytes for a target.
119 See the method [llvm::DataLayout::getTypeABISize]. *)
120 val preferred_align : Llvm.lltype -> t -> int
122 (** Computes the preferred alignment of a global variable in bytes for
123 a target. See the method [llvm::DataLayout::getPreferredAlignment]. *)
124 val preferred_align_of_global : Llvm.llvalue -> t -> int
126 (** Computes the structure element that contains the byte offset for a target.
127 See the method [llvm::StructLayout::getElementContainingOffset]. *)
128 val element_at_offset : Llvm.lltype -> Int64.t -> t -> int
130 (** Computes the byte offset of the indexed struct element for a target.
131 See the method [llvm::StructLayout::getElementContainingOffset]. *)
132 val offset_of_element : Llvm.lltype -> int -> t -> Int64.t
140 (** [default_triple ()] returns the default target triple for current
142 val default_triple : unit -> string
144 (** [first ()] returns the first target in the registered targets
146 val first : unit -> t option
148 (** [succ t] returns the next target after [t], or [None]
149 if [t] was the last target. *)
150 val succ : t -> t option
152 (** [all ()] returns a list of known targets. *)
153 val all : unit -> t list
155 (** [by_name name] returns [Some t] if a target [t] named [name] is
156 registered, or [None] otherwise. *)
157 val by_name : string -> t option
159 (** [by_triple triple] returns a target for a triple [triple], or raises
160 [Error] if [triple] does not correspond to a registered target. *)
161 val by_triple : string -> t
163 (** Returns the name of a target. See [llvm::Target::getName]. *)
164 val name : t -> string
166 (** Returns the description of a target.
167 See [llvm::Target::getDescription]. *)
168 val description : t -> string
170 (** Returns [true] if the target has a JIT. *)
171 val has_jit : t -> bool
173 (** Returns [true] if the target has a target machine associated. *)
174 val has_target_machine : t -> bool
176 (** Returns [true] if the target has an ASM backend (required for
178 val has_asm_backend : t -> bool
181 (** {6 Target Machine} *)
183 module TargetMachine : sig
186 (** Creates a new target machine.
187 See [llvm::Target::createTargetMachine]. *)
188 val create : triple:string -> ?cpu:string -> ?features:string ->
189 ?level:CodeGenOptLevel.t -> ?reloc_mode:RelocMode.t ->
190 ?code_model:CodeModel.t -> Target.t -> t
192 (** Returns the Target used in a TargetMachine *)
193 val target : t -> Target.t
195 (** Returns the triple used while creating this target machine. See
196 [llvm::TargetMachine::getTriple]. *)
197 val triple : t -> string
199 (** Returns the CPU used while creating this target machine. See
200 [llvm::TargetMachine::getCPU]. *)
201 val cpu : t -> string
203 (** Returns the feature string used while creating this target machine. See
204 [llvm::TargetMachine::getFeatureString]. *)
205 val features : t -> string
207 (** Returns the data layout of this target machine. *)
208 val data_layout : t -> DataLayout.t
210 (** Sets the assembly verbosity of this target machine.
211 See [llvm::TargetMachine::setAsmVerbosity]. *)
212 val set_verbose_asm : bool -> t -> unit
214 (** Emits assembly or object data for the given module to the given
215 file or raise [Error]. *)
216 val emit_to_file : Llvm.llmodule -> CodeGenFileType.t -> string -> t -> unit
218 (** Emits assembly or object data for the given module to a fresh memory
219 buffer or raise [Error]. *)
220 val emit_to_memory_buffer : Llvm.llmodule -> CodeGenFileType.t -> t ->