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 50let () = Callback.register_exception "Llvm_target.Error" (Error "") 51 52module DataLayout = struct 53 type t 54 55 external of_string : string -> t = "llvm_datalayout_of_string" 56 external as_string : t -> string = "llvm_datalayout_as_string" 57 external byte_order : t -> Endian.t = "llvm_datalayout_byte_order" 58 external pointer_size : t -> int = "llvm_datalayout_pointer_size" 59 external intptr_type : Llvm.llcontext -> t -> Llvm.lltype 60 = "llvm_datalayout_intptr_type" 61 external qualified_pointer_size : int -> t -> int 62 = "llvm_datalayout_qualified_pointer_size" 63 external qualified_intptr_type : Llvm.llcontext -> int -> t -> Llvm.lltype 64 = "llvm_datalayout_qualified_intptr_type" 65 external size_in_bits : Llvm.lltype -> t -> Int64.t 66 = "llvm_datalayout_size_in_bits" 67 external store_size : Llvm.lltype -> t -> Int64.t 68 = "llvm_datalayout_store_size" 69 external abi_size : Llvm.lltype -> t -> Int64.t 70 = "llvm_datalayout_abi_size" 71 external abi_align : Llvm.lltype -> t -> int 72 = "llvm_datalayout_abi_align" 73 external stack_align : Llvm.lltype -> t -> int 74 = "llvm_datalayout_stack_align" 75 external preferred_align : Llvm.lltype -> t -> int 76 = "llvm_datalayout_preferred_align" 77 external preferred_align_of_global : Llvm.llvalue -> t -> int 78 = "llvm_datalayout_preferred_align_of_global" 79 external element_at_offset : Llvm.lltype -> Int64.t -> t -> int 80 = "llvm_datalayout_element_at_offset" 81 external offset_of_element : Llvm.lltype -> int -> t -> Int64.t 82 = "llvm_datalayout_offset_of_element" 83end 84 85module Target = struct 86 type t 87 88 external default_triple : unit -> string = "llvm_target_default_triple" 89 external first : unit -> t option = "llvm_target_first" 90 external succ : t -> t option = "llvm_target_succ" 91 external by_name : string -> t option = "llvm_target_by_name" 92 external by_triple : string -> t = "llvm_target_by_triple" 93 external name : t -> string = "llvm_target_name" 94 external description : t -> string = "llvm_target_description" 95 external has_jit : t -> bool = "llvm_target_has_jit" 96 external has_target_machine : t -> bool = "llvm_target_has_target_machine" 97 external has_asm_backend : t -> bool = "llvm_target_has_asm_backend" 98 99 let all () = 100 let rec step elem lst = 101 match elem with 102 | Some target -> step (succ target) (target :: lst) 103 | None -> lst 104 in 105 step (first ()) [] 106end 107 108module TargetMachine = struct 109 type t 110 111 external create : triple:string -> ?cpu:string -> ?features:string -> 112 ?level:CodeGenOptLevel.t -> ?reloc_mode:RelocMode.t -> 113 ?code_model:CodeModel.t -> Target.t -> t 114 = "llvm_create_targetmachine_bytecode" 115 "llvm_create_targetmachine_native" 116 external target : t -> Target.t 117 = "llvm_targetmachine_target" 118 external triple : t -> string 119 = "llvm_targetmachine_triple" 120 external cpu : t -> string 121 = "llvm_targetmachine_cpu" 122 external features : t -> string 123 = "llvm_targetmachine_features" 124 external data_layout : t -> DataLayout.t 125 = "llvm_targetmachine_data_layout" 126 external add_analysis_passes : [< Llvm.PassManager.any ] Llvm.PassManager.t -> t -> unit 127 = "llvm_targetmachine_add_analysis_passes" 128 external set_verbose_asm : bool -> t -> unit 129 = "llvm_targetmachine_set_verbose_asm" 130 external emit_to_file : Llvm.llmodule -> CodeGenFileType.t -> string -> 131 t -> unit 132 = "llvm_targetmachine_emit_to_file" 133 external emit_to_memory_buffer : Llvm.llmodule -> CodeGenFileType.t -> 134 t -> Llvm.llmemorybuffer 135 = "llvm_targetmachine_emit_to_memory_buffer" 136end 137