• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1(*===-- llvm_target.ml - LLVM OCaml Interface ------------------*- OCaml -*-===*
2 *
3 *                     The LLVM Compiler Infrastructure
4 *
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
7 *
8 *===----------------------------------------------------------------------===*)
9
10module Endian = struct
11  type t =
12  | Big
13  | Little
14end
15
16module CodeGenOptLevel = struct
17  type t =
18  | None
19  | Less
20  | Default
21  | Aggressive
22end
23
24module RelocMode = struct
25  type t =
26  | Default
27  | Static
28  | PIC
29  | DynamicNoPIC
30end
31
32module CodeModel = struct
33  type t =
34  | Default
35  | JITDefault
36  | Small
37  | Kernel
38  | Medium
39  | Large
40end
41
42module CodeGenFileType = struct
43  type t =
44  | AssemblyFile
45  | ObjectFile
46end
47
48exception Error of string
49
50external register_exns : exn -> unit = "llvm_register_target_exns"
51let _ = register_exns (Error "")
52
53module DataLayout = struct
54  type t
55
56  external of_string : string -> t = "llvm_datalayout_of_string"
57  external as_string : t -> string = "llvm_datalayout_as_string"
58  external add_to_pass_manager : [<Llvm.PassManager.any]
59                                 Llvm.PassManager.t -> t -> unit
60                               = "llvm_datalayout_add_to_pass_manager"
61  external byte_order : t -> Endian.t = "llvm_datalayout_byte_order"
62  external pointer_size : t -> int = "llvm_datalayout_pointer_size"
63  external intptr_type : Llvm.llcontext -> t -> Llvm.lltype
64                       = "llvm_datalayout_intptr_type"
65  external qualified_pointer_size : int -> t -> int
66                                  = "llvm_datalayout_qualified_pointer_size"
67  external qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype
68                                 = "llvm_datalayout_qualified_intptr_type"
69  external size_in_bits : Llvm.lltype -> t -> Int64.t
70                        = "llvm_datalayout_size_in_bits"
71  external store_size : Llvm.lltype -> t -> Int64.t
72                      = "llvm_datalayout_store_size"
73  external abi_size : Llvm.lltype -> t -> Int64.t
74                    = "llvm_datalayout_abi_size"
75  external abi_align : Llvm.lltype -> t -> int
76                     = "llvm_datalayout_abi_align"
77  external stack_align : Llvm.lltype -> t -> int
78                       = "llvm_datalayout_stack_align"
79  external preferred_align : Llvm.lltype -> t -> int
80                           = "llvm_datalayout_preferred_align"
81  external preferred_align_of_global : Llvm.llvalue -> t -> int
82                                   = "llvm_datalayout_preferred_align_of_global"
83  external element_at_offset : Llvm.lltype -> Int64.t -> t -> int
84                             = "llvm_datalayout_element_at_offset"
85  external offset_of_element : Llvm.lltype -> int -> t -> Int64.t
86                             = "llvm_datalayout_offset_of_element"
87end
88
89module Target = struct
90  type t
91
92  external default_triple : unit -> string = "llvm_target_default_triple"
93  external first : unit -> t option = "llvm_target_first"
94  external succ : t -> t option = "llvm_target_succ"
95  external by_name : string -> t option = "llvm_target_by_name"
96  external by_triple : string -> t = "llvm_target_by_triple"
97  external name : t -> string = "llvm_target_name"
98  external description : t -> string = "llvm_target_description"
99  external has_jit : t -> bool = "llvm_target_has_jit"
100  external has_target_machine : t -> bool = "llvm_target_has_target_machine"
101  external has_asm_backend : t -> bool = "llvm_target_has_asm_backend"
102
103  let all () =
104    let rec step elem lst =
105      match elem with
106      | Some target -> step (succ target) (target :: lst)
107      | None        -> lst
108    in
109    step (first ()) []
110end
111
112module TargetMachine = struct
113  type t
114
115  external create : triple:string -> ?cpu:string -> ?features:string ->
116                    ?level:CodeGenOptLevel.t -> ?reloc_mode:RelocMode.t ->
117                    ?code_model:CodeModel.t -> Target.t -> t
118                  = "llvm_create_targetmachine_bytecode"
119                    "llvm_create_targetmachine_native"
120  external target : t -> Target.t
121                  = "llvm_targetmachine_target"
122  external triple : t -> string
123                  = "llvm_targetmachine_triple"
124  external cpu : t -> string
125               = "llvm_targetmachine_cpu"
126  external features : t -> string
127                    = "llvm_targetmachine_features"
128  external data_layout : t -> DataLayout.t
129                       = "llvm_targetmachine_data_layout"
130  external set_verbose_asm : bool -> t -> unit
131                           = "llvm_targetmachine_set_verbose_asm"
132  external emit_to_file : Llvm.llmodule -> CodeGenFileType.t -> string ->
133                          t -> unit
134                        = "llvm_targetmachine_emit_to_file"
135  external emit_to_memory_buffer : Llvm.llmodule -> CodeGenFileType.t ->
136                                   t -> Llvm.llmemorybuffer
137                                 = "llvm_targetmachine_emit_to_memory_buffer"
138end
139