1(*===-- llvm/llvm.ml - LLVM OCaml Interface -------------------------------===* 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 10 11type llcontext 12type llmodule 13type lltype 14type llvalue 15type lluse 16type llbasicblock 17type llbuilder 18type llmemorybuffer 19type llmdkind 20 21module TypeKind = struct 22 type t = 23 | Void 24 | Half 25 | Float 26 | Double 27 | X86fp80 28 | Fp128 29 | Ppc_fp128 30 | Label 31 | Integer 32 | Function 33 | Struct 34 | Array 35 | Pointer 36 | Vector 37 | Metadata 38 | X86_mmx 39end 40 41module Linkage = struct 42 type t = 43 | External 44 | Available_externally 45 | Link_once 46 | Link_once_odr 47 | Link_once_odr_auto_hide 48 | Weak 49 | Weak_odr 50 | Appending 51 | Internal 52 | Private 53 | Dllimport 54 | Dllexport 55 | External_weak 56 | Ghost 57 | Common 58 | Linker_private 59 | Linker_private_weak 60end 61 62module Visibility = struct 63 type t = 64 | Default 65 | Hidden 66 | Protected 67end 68 69module DLLStorageClass = struct 70 type t = 71 | Default 72 | DLLImport 73 | DLLExport 74end 75 76module CallConv = struct 77 let c = 0 78 let fast = 8 79 let cold = 9 80 let x86_stdcall = 64 81 let x86_fastcall = 65 82end 83 84module Attribute = struct 85 type t = 86 | Zext 87 | Sext 88 | Noreturn 89 | Inreg 90 | Structret 91 | Nounwind 92 | Noalias 93 | Byval 94 | Nest 95 | Readnone 96 | Readonly 97 | Noinline 98 | Alwaysinline 99 | Optsize 100 | Ssp 101 | Sspreq 102 | Alignment of int 103 | Nocapture 104 | Noredzone 105 | Noimplicitfloat 106 | Naked 107 | Inlinehint 108 | Stackalignment of int 109 | ReturnsTwice 110 | UWTable 111 | NonLazyBind 112end 113 114module Icmp = struct 115 type t = 116 | Eq 117 | Ne 118 | Ugt 119 | Uge 120 | Ult 121 | Ule 122 | Sgt 123 | Sge 124 | Slt 125 | Sle 126end 127 128module Fcmp = struct 129 type t = 130 | False 131 | Oeq 132 | Ogt 133 | Oge 134 | Olt 135 | Ole 136 | One 137 | Ord 138 | Uno 139 | Ueq 140 | Ugt 141 | Uge 142 | Ult 143 | Ule 144 | Une 145 | True 146end 147 148module Opcode = struct 149 type t = 150 | Invalid (* not an instruction *) 151 (* Terminator Instructions *) 152 | Ret 153 | Br 154 | Switch 155 | IndirectBr 156 | Invoke 157 | Invalid2 158 | Unreachable 159 (* Standard Binary Operators *) 160 | Add 161 | FAdd 162 | Sub 163 | FSub 164 | Mul 165 | FMul 166 | UDiv 167 | SDiv 168 | FDiv 169 | URem 170 | SRem 171 | FRem 172 (* Logical Operators *) 173 | Shl 174 | LShr 175 | AShr 176 | And 177 | Or 178 | Xor 179 (* Memory Operators *) 180 | Alloca 181 | Load 182 | Store 183 | GetElementPtr 184 (* Cast Operators *) 185 | Trunc 186 | ZExt 187 | SExt 188 | FPToUI 189 | FPToSI 190 | UIToFP 191 | SIToFP 192 | FPTrunc 193 | FPExt 194 | PtrToInt 195 | IntToPtr 196 | BitCast 197 (* Other Operators *) 198 | ICmp 199 | FCmp 200 | PHI 201 | Call 202 | Select 203 | UserOp1 204 | UserOp2 205 | VAArg 206 | ExtractElement 207 | InsertElement 208 | ShuffleVector 209 | ExtractValue 210 | InsertValue 211 | Fence 212 | AtomicCmpXchg 213 | AtomicRMW 214 | Resume 215 | LandingPad 216end 217 218module LandingPadClauseTy = struct 219 type t = 220 | Catch 221 | Filter 222end 223 224module ThreadLocalMode = struct 225 type t = 226 | None 227 | GeneralDynamic 228 | LocalDynamic 229 | InitialExec 230 | LocalExec 231end 232 233module AtomicOrdering = struct 234 type t = 235 | NotAtomic 236 | Unordered 237 | Monotonic 238 | Invalid 239 | Acquire 240 | Release 241 | AcqiureRelease 242 | SequentiallyConsistent 243end 244 245module AtomicRMWBinOp = struct 246 type t = 247 | Xchg 248 | Add 249 | Sub 250 | And 251 | Nand 252 | Or 253 | Xor 254 | Max 255 | Min 256 | UMax 257 | UMin 258end 259 260module ValueKind = struct 261 type t = 262 | NullValue 263 | Argument 264 | BasicBlock 265 | InlineAsm 266 | MDNode 267 | MDString 268 | BlockAddress 269 | ConstantAggregateZero 270 | ConstantArray 271 | ConstantDataArray 272 | ConstantDataVector 273 | ConstantExpr 274 | ConstantFP 275 | ConstantInt 276 | ConstantPointerNull 277 | ConstantStruct 278 | ConstantVector 279 | Function 280 | GlobalAlias 281 | GlobalVariable 282 | UndefValue 283 | Instruction of Opcode.t 284end 285 286module DiagnosticSeverity = struct 287 type t = 288 | Error 289 | Warning 290 | Remark 291 | Note 292end 293 294exception IoError of string 295 296let () = Callback.register_exception "Llvm.IoError" (IoError "") 297 298external install_fatal_error_handler : (string -> unit) -> unit 299 = "llvm_install_fatal_error_handler" 300external reset_fatal_error_handler : unit -> unit 301 = "llvm_reset_fatal_error_handler" 302external enable_pretty_stacktrace : unit -> unit 303 = "llvm_enable_pretty_stacktrace" 304external parse_command_line_options : ?overview:string -> string array -> unit 305 = "llvm_parse_command_line_options" 306 307type ('a, 'b) llpos = 308| At_end of 'a 309| Before of 'b 310 311type ('a, 'b) llrev_pos = 312| At_start of 'a 313| After of 'b 314 315 316(*===-- Context error handling --------------------------------------------===*) 317module Diagnostic = struct 318 type t 319 320 external description : t -> string = "llvm_get_diagnostic_description" 321 external severity : t -> DiagnosticSeverity.t 322 = "llvm_get_diagnostic_severity" 323end 324 325external set_diagnostic_handler 326 : llcontext -> (Diagnostic.t -> unit) option -> unit 327 = "llvm_set_diagnostic_handler" 328 329(*===-- Contexts ----------------------------------------------------------===*) 330external create_context : unit -> llcontext = "llvm_create_context" 331external dispose_context : llcontext -> unit = "llvm_dispose_context" 332external global_context : unit -> llcontext = "llvm_global_context" 333external mdkind_id : llcontext -> string -> llmdkind = "llvm_mdkind_id" 334 335(*===-- Modules -----------------------------------------------------------===*) 336external create_module : llcontext -> string -> llmodule = "llvm_create_module" 337external dispose_module : llmodule -> unit = "llvm_dispose_module" 338external target_triple: llmodule -> string 339 = "llvm_target_triple" 340external set_target_triple: string -> llmodule -> unit 341 = "llvm_set_target_triple" 342external data_layout: llmodule -> string 343 = "llvm_data_layout" 344external set_data_layout: string -> llmodule -> unit 345 = "llvm_set_data_layout" 346external dump_module : llmodule -> unit = "llvm_dump_module" 347external print_module : string -> llmodule -> unit = "llvm_print_module" 348external string_of_llmodule : llmodule -> string = "llvm_string_of_llmodule" 349external set_module_inline_asm : llmodule -> string -> unit 350 = "llvm_set_module_inline_asm" 351external module_context : llmodule -> llcontext = "LLVMGetModuleContext" 352 353(*===-- Types -------------------------------------------------------------===*) 354external classify_type : lltype -> TypeKind.t = "llvm_classify_type" 355external type_context : lltype -> llcontext = "llvm_type_context" 356external type_is_sized : lltype -> bool = "llvm_type_is_sized" 357external dump_type : lltype -> unit = "llvm_dump_type" 358external string_of_lltype : lltype -> string = "llvm_string_of_lltype" 359 360(*--... Operations on integer types ........................................--*) 361external i1_type : llcontext -> lltype = "llvm_i1_type" 362external i8_type : llcontext -> lltype = "llvm_i8_type" 363external i16_type : llcontext -> lltype = "llvm_i16_type" 364external i32_type : llcontext -> lltype = "llvm_i32_type" 365external i64_type : llcontext -> lltype = "llvm_i64_type" 366 367external integer_type : llcontext -> int -> lltype = "llvm_integer_type" 368external integer_bitwidth : lltype -> int = "llvm_integer_bitwidth" 369 370(*--... Operations on real types ...........................................--*) 371external float_type : llcontext -> lltype = "llvm_float_type" 372external double_type : llcontext -> lltype = "llvm_double_type" 373external x86fp80_type : llcontext -> lltype = "llvm_x86fp80_type" 374external fp128_type : llcontext -> lltype = "llvm_fp128_type" 375external ppc_fp128_type : llcontext -> lltype = "llvm_ppc_fp128_type" 376 377(*--... Operations on function types .......................................--*) 378external function_type : lltype -> lltype array -> lltype = "llvm_function_type" 379external var_arg_function_type : lltype -> lltype array -> lltype 380 = "llvm_var_arg_function_type" 381external is_var_arg : lltype -> bool = "llvm_is_var_arg" 382external return_type : lltype -> lltype = "LLVMGetReturnType" 383external param_types : lltype -> lltype array = "llvm_param_types" 384 385(*--... Operations on struct types .........................................--*) 386external struct_type : llcontext -> lltype array -> lltype = "llvm_struct_type" 387external packed_struct_type : llcontext -> lltype array -> lltype 388 = "llvm_packed_struct_type" 389external struct_name : lltype -> string option = "llvm_struct_name" 390external named_struct_type : llcontext -> string -> lltype = 391 "llvm_named_struct_type" 392external struct_set_body : lltype -> lltype array -> bool -> unit = 393 "llvm_struct_set_body" 394external struct_element_types : lltype -> lltype array 395 = "llvm_struct_element_types" 396external is_packed : lltype -> bool = "llvm_is_packed" 397external is_opaque : lltype -> bool = "llvm_is_opaque" 398 399(*--... Operations on pointer, vector, and array types .....................--*) 400external array_type : lltype -> int -> lltype = "llvm_array_type" 401external pointer_type : lltype -> lltype = "llvm_pointer_type" 402external qualified_pointer_type : lltype -> int -> lltype 403 = "llvm_qualified_pointer_type" 404external vector_type : lltype -> int -> lltype = "llvm_vector_type" 405 406external element_type : lltype -> lltype = "LLVMGetElementType" 407external array_length : lltype -> int = "llvm_array_length" 408external address_space : lltype -> int = "llvm_address_space" 409external vector_size : lltype -> int = "llvm_vector_size" 410 411(*--... Operations on other types ..........................................--*) 412external void_type : llcontext -> lltype = "llvm_void_type" 413external label_type : llcontext -> lltype = "llvm_label_type" 414external x86_mmx_type : llcontext -> lltype = "llvm_x86_mmx_type" 415external type_by_name : llmodule -> string -> lltype option = "llvm_type_by_name" 416 417external classify_value : llvalue -> ValueKind.t = "llvm_classify_value" 418(*===-- Values ------------------------------------------------------------===*) 419external type_of : llvalue -> lltype = "llvm_type_of" 420external value_name : llvalue -> string = "llvm_value_name" 421external set_value_name : string -> llvalue -> unit = "llvm_set_value_name" 422external dump_value : llvalue -> unit = "llvm_dump_value" 423external string_of_llvalue : llvalue -> string = "llvm_string_of_llvalue" 424external replace_all_uses_with : llvalue -> llvalue -> unit 425 = "llvm_replace_all_uses_with" 426 427(*--... Operations on uses .................................................--*) 428external use_begin : llvalue -> lluse option = "llvm_use_begin" 429external use_succ : lluse -> lluse option = "llvm_use_succ" 430external user : lluse -> llvalue = "llvm_user" 431external used_value : lluse -> llvalue = "llvm_used_value" 432 433let iter_uses f v = 434 let rec aux = function 435 | None -> () 436 | Some u -> 437 f u; 438 aux (use_succ u) 439 in 440 aux (use_begin v) 441 442let fold_left_uses f init v = 443 let rec aux init u = 444 match u with 445 | None -> init 446 | Some u -> aux (f init u) (use_succ u) 447 in 448 aux init (use_begin v) 449 450let fold_right_uses f v init = 451 let rec aux u init = 452 match u with 453 | None -> init 454 | Some u -> f u (aux (use_succ u) init) 455 in 456 aux (use_begin v) init 457 458 459(*--... Operations on users ................................................--*) 460external operand : llvalue -> int -> llvalue = "llvm_operand" 461external operand_use : llvalue -> int -> lluse = "llvm_operand_use" 462external set_operand : llvalue -> int -> llvalue -> unit = "llvm_set_operand" 463external num_operands : llvalue -> int = "llvm_num_operands" 464 465(*--... Operations on constants of (mostly) any type .......................--*) 466external is_constant : llvalue -> bool = "llvm_is_constant" 467external const_null : lltype -> llvalue = "LLVMConstNull" 468external const_all_ones : (*int|vec*)lltype -> llvalue = "LLVMConstAllOnes" 469external const_pointer_null : lltype -> llvalue = "LLVMConstPointerNull" 470external undef : lltype -> llvalue = "LLVMGetUndef" 471external is_null : llvalue -> bool = "llvm_is_null" 472external is_undef : llvalue -> bool = "llvm_is_undef" 473external constexpr_opcode : llvalue -> Opcode.t = "llvm_constexpr_get_opcode" 474 475(*--... Operations on instructions .........................................--*) 476external has_metadata : llvalue -> bool = "llvm_has_metadata" 477external metadata : llvalue -> llmdkind -> llvalue option = "llvm_metadata" 478external set_metadata : llvalue -> llmdkind -> llvalue -> unit = "llvm_set_metadata" 479external clear_metadata : llvalue -> llmdkind -> unit = "llvm_clear_metadata" 480 481(*--... Operations on metadata .......,.....................................--*) 482external mdstring : llcontext -> string -> llvalue = "llvm_mdstring" 483external mdnode : llcontext -> llvalue array -> llvalue = "llvm_mdnode" 484external mdnull : llcontext -> llvalue = "llvm_mdnull" 485external get_mdstring : llvalue -> string option = "llvm_get_mdstring" 486external get_mdnode_operands : llvalue -> llvalue array 487 = "llvm_get_mdnode_operands" 488external get_named_metadata : llmodule -> string -> llvalue array 489 = "llvm_get_namedmd" 490external add_named_metadata_operand : llmodule -> string -> llvalue -> unit 491 = "llvm_append_namedmd" 492 493(*--... Operations on scalar constants .....................................--*) 494external const_int : lltype -> int -> llvalue = "llvm_const_int" 495external const_of_int64 : lltype -> Int64.t -> bool -> llvalue 496 = "llvm_const_of_int64" 497external int64_of_const : llvalue -> Int64.t option 498 = "llvm_int64_of_const" 499external const_int_of_string : lltype -> string -> int -> llvalue 500 = "llvm_const_int_of_string" 501external const_float : lltype -> float -> llvalue = "llvm_const_float" 502external float_of_const : llvalue -> float option 503 = "llvm_float_of_const" 504external const_float_of_string : lltype -> string -> llvalue 505 = "llvm_const_float_of_string" 506 507(*--... Operations on composite constants ..................................--*) 508external const_string : llcontext -> string -> llvalue = "llvm_const_string" 509external const_stringz : llcontext -> string -> llvalue = "llvm_const_stringz" 510external const_array : lltype -> llvalue array -> llvalue = "llvm_const_array" 511external const_struct : llcontext -> llvalue array -> llvalue 512 = "llvm_const_struct" 513external const_named_struct : lltype -> llvalue array -> llvalue 514 = "llvm_const_named_struct" 515external const_packed_struct : llcontext -> llvalue array -> llvalue 516 = "llvm_const_packed_struct" 517external const_vector : llvalue array -> llvalue = "llvm_const_vector" 518external string_of_const : llvalue -> string option = "llvm_string_of_const" 519external const_element : llvalue -> int -> llvalue = "llvm_const_element" 520 521(*--... Constant expressions ...............................................--*) 522external align_of : lltype -> llvalue = "LLVMAlignOf" 523external size_of : lltype -> llvalue = "LLVMSizeOf" 524external const_neg : llvalue -> llvalue = "LLVMConstNeg" 525external const_nsw_neg : llvalue -> llvalue = "LLVMConstNSWNeg" 526external const_nuw_neg : llvalue -> llvalue = "LLVMConstNUWNeg" 527external const_fneg : llvalue -> llvalue = "LLVMConstFNeg" 528external const_not : llvalue -> llvalue = "LLVMConstNot" 529external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd" 530external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd" 531external const_nuw_add : llvalue -> llvalue -> llvalue = "LLVMConstNUWAdd" 532external const_fadd : llvalue -> llvalue -> llvalue = "LLVMConstFAdd" 533external const_sub : llvalue -> llvalue -> llvalue = "LLVMConstSub" 534external const_nsw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNSWSub" 535external const_nuw_sub : llvalue -> llvalue -> llvalue = "LLVMConstNUWSub" 536external const_fsub : llvalue -> llvalue -> llvalue = "LLVMConstFSub" 537external const_mul : llvalue -> llvalue -> llvalue = "LLVMConstMul" 538external const_nsw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNSWMul" 539external const_nuw_mul : llvalue -> llvalue -> llvalue = "LLVMConstNUWMul" 540external const_fmul : llvalue -> llvalue -> llvalue = "LLVMConstFMul" 541external const_udiv : llvalue -> llvalue -> llvalue = "LLVMConstUDiv" 542external const_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstSDiv" 543external const_exact_sdiv : llvalue -> llvalue -> llvalue = "LLVMConstExactSDiv" 544external const_fdiv : llvalue -> llvalue -> llvalue = "LLVMConstFDiv" 545external const_urem : llvalue -> llvalue -> llvalue = "LLVMConstURem" 546external const_srem : llvalue -> llvalue -> llvalue = "LLVMConstSRem" 547external const_frem : llvalue -> llvalue -> llvalue = "LLVMConstFRem" 548external const_and : llvalue -> llvalue -> llvalue = "LLVMConstAnd" 549external const_or : llvalue -> llvalue -> llvalue = "LLVMConstOr" 550external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor" 551external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue 552 = "llvm_const_icmp" 553external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue 554 = "llvm_const_fcmp" 555external const_shl : llvalue -> llvalue -> llvalue = "LLVMConstShl" 556external const_lshr : llvalue -> llvalue -> llvalue = "LLVMConstLShr" 557external const_ashr : llvalue -> llvalue -> llvalue = "LLVMConstAShr" 558external const_gep : llvalue -> llvalue array -> llvalue = "llvm_const_gep" 559external const_in_bounds_gep : llvalue -> llvalue array -> llvalue 560 = "llvm_const_in_bounds_gep" 561external const_trunc : llvalue -> lltype -> llvalue = "LLVMConstTrunc" 562external const_sext : llvalue -> lltype -> llvalue = "LLVMConstSExt" 563external const_zext : llvalue -> lltype -> llvalue = "LLVMConstZExt" 564external const_fptrunc : llvalue -> lltype -> llvalue = "LLVMConstFPTrunc" 565external const_fpext : llvalue -> lltype -> llvalue = "LLVMConstFPExt" 566external const_uitofp : llvalue -> lltype -> llvalue = "LLVMConstUIToFP" 567external const_sitofp : llvalue -> lltype -> llvalue = "LLVMConstSIToFP" 568external const_fptoui : llvalue -> lltype -> llvalue = "LLVMConstFPToUI" 569external const_fptosi : llvalue -> lltype -> llvalue = "LLVMConstFPToSI" 570external const_ptrtoint : llvalue -> lltype -> llvalue = "LLVMConstPtrToInt" 571external const_inttoptr : llvalue -> lltype -> llvalue = "LLVMConstIntToPtr" 572external const_bitcast : llvalue -> lltype -> llvalue = "LLVMConstBitCast" 573external const_zext_or_bitcast : llvalue -> lltype -> llvalue 574 = "LLVMConstZExtOrBitCast" 575external const_sext_or_bitcast : llvalue -> lltype -> llvalue 576 = "LLVMConstSExtOrBitCast" 577external const_trunc_or_bitcast : llvalue -> lltype -> llvalue 578 = "LLVMConstTruncOrBitCast" 579external const_pointercast : llvalue -> lltype -> llvalue 580 = "LLVMConstPointerCast" 581external const_intcast : llvalue -> lltype -> is_signed:bool -> llvalue 582 = "llvm_const_intcast" 583external const_fpcast : llvalue -> lltype -> llvalue = "LLVMConstFPCast" 584external const_select : llvalue -> llvalue -> llvalue -> llvalue 585 = "LLVMConstSelect" 586external const_extractelement : llvalue -> llvalue -> llvalue 587 = "LLVMConstExtractElement" 588external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue 589 = "LLVMConstInsertElement" 590external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue 591 = "LLVMConstShuffleVector" 592external const_extractvalue : llvalue -> int array -> llvalue 593 = "llvm_const_extractvalue" 594external const_insertvalue : llvalue -> llvalue -> int array -> llvalue 595 = "llvm_const_insertvalue" 596external const_inline_asm : lltype -> string -> string -> bool -> bool -> 597 llvalue 598 = "llvm_const_inline_asm" 599external block_address : llvalue -> llbasicblock -> llvalue = "LLVMBlockAddress" 600 601(*--... Operations on global variables, functions, and aliases (globals) ...--*) 602external global_parent : llvalue -> llmodule = "LLVMGetGlobalParent" 603external is_declaration : llvalue -> bool = "llvm_is_declaration" 604external linkage : llvalue -> Linkage.t = "llvm_linkage" 605external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage" 606external unnamed_addr : llvalue -> bool = "llvm_unnamed_addr" 607external set_unnamed_addr : bool -> llvalue -> unit = "llvm_set_unnamed_addr" 608external section : llvalue -> string = "llvm_section" 609external set_section : string -> llvalue -> unit = "llvm_set_section" 610external visibility : llvalue -> Visibility.t = "llvm_visibility" 611external set_visibility : Visibility.t -> llvalue -> unit = "llvm_set_visibility" 612external dll_storage_class : llvalue -> DLLStorageClass.t = "llvm_dll_storage_class" 613external set_dll_storage_class : DLLStorageClass.t -> llvalue -> unit = "llvm_set_dll_storage_class" 614external alignment : llvalue -> int = "llvm_alignment" 615external set_alignment : int -> llvalue -> unit = "llvm_set_alignment" 616external is_global_constant : llvalue -> bool = "llvm_is_global_constant" 617external set_global_constant : bool -> llvalue -> unit 618 = "llvm_set_global_constant" 619 620(*--... Operations on global variables .....................................--*) 621external declare_global : lltype -> string -> llmodule -> llvalue 622 = "llvm_declare_global" 623external declare_qualified_global : lltype -> string -> int -> llmodule -> 624 llvalue 625 = "llvm_declare_qualified_global" 626external define_global : string -> llvalue -> llmodule -> llvalue 627 = "llvm_define_global" 628external define_qualified_global : string -> llvalue -> int -> llmodule -> 629 llvalue 630 = "llvm_define_qualified_global" 631external lookup_global : string -> llmodule -> llvalue option 632 = "llvm_lookup_global" 633external delete_global : llvalue -> unit = "llvm_delete_global" 634external global_initializer : llvalue -> llvalue = "LLVMGetInitializer" 635external set_initializer : llvalue -> llvalue -> unit = "llvm_set_initializer" 636external remove_initializer : llvalue -> unit = "llvm_remove_initializer" 637external is_thread_local : llvalue -> bool = "llvm_is_thread_local" 638external set_thread_local : bool -> llvalue -> unit = "llvm_set_thread_local" 639external thread_local_mode : llvalue -> ThreadLocalMode.t 640 = "llvm_thread_local_mode" 641external set_thread_local_mode : ThreadLocalMode.t -> llvalue -> unit 642 = "llvm_set_thread_local_mode" 643external is_externally_initialized : llvalue -> bool 644 = "llvm_is_externally_initialized" 645external set_externally_initialized : bool -> llvalue -> unit 646 = "llvm_set_externally_initialized" 647external global_begin : llmodule -> (llmodule, llvalue) llpos 648 = "llvm_global_begin" 649external global_succ : llvalue -> (llmodule, llvalue) llpos 650 = "llvm_global_succ" 651external global_end : llmodule -> (llmodule, llvalue) llrev_pos 652 = "llvm_global_end" 653external global_pred : llvalue -> (llmodule, llvalue) llrev_pos 654 = "llvm_global_pred" 655 656let rec iter_global_range f i e = 657 if i = e then () else 658 match i with 659 | At_end _ -> raise (Invalid_argument "Invalid global variable range.") 660 | Before bb -> 661 f bb; 662 iter_global_range f (global_succ bb) e 663 664let iter_globals f m = 665 iter_global_range f (global_begin m) (At_end m) 666 667let rec fold_left_global_range f init i e = 668 if i = e then init else 669 match i with 670 | At_end _ -> raise (Invalid_argument "Invalid global variable range.") 671 | Before bb -> fold_left_global_range f (f init bb) (global_succ bb) e 672 673let fold_left_globals f init m = 674 fold_left_global_range f init (global_begin m) (At_end m) 675 676let rec rev_iter_global_range f i e = 677 if i = e then () else 678 match i with 679 | At_start _ -> raise (Invalid_argument "Invalid global variable range.") 680 | After bb -> 681 f bb; 682 rev_iter_global_range f (global_pred bb) e 683 684let rev_iter_globals f m = 685 rev_iter_global_range f (global_end m) (At_start m) 686 687let rec fold_right_global_range f i e init = 688 if i = e then init else 689 match i with 690 | At_start _ -> raise (Invalid_argument "Invalid global variable range.") 691 | After bb -> fold_right_global_range f (global_pred bb) e (f bb init) 692 693let fold_right_globals f m init = 694 fold_right_global_range f (global_end m) (At_start m) init 695 696(*--... Operations on aliases ..............................................--*) 697external add_alias : llmodule -> lltype -> llvalue -> string -> llvalue 698 = "llvm_add_alias" 699 700(*--... Operations on functions ............................................--*) 701external declare_function : string -> lltype -> llmodule -> llvalue 702 = "llvm_declare_function" 703external define_function : string -> lltype -> llmodule -> llvalue 704 = "llvm_define_function" 705external lookup_function : string -> llmodule -> llvalue option 706 = "llvm_lookup_function" 707external delete_function : llvalue -> unit = "llvm_delete_function" 708external is_intrinsic : llvalue -> bool = "llvm_is_intrinsic" 709external function_call_conv : llvalue -> int = "llvm_function_call_conv" 710external set_function_call_conv : int -> llvalue -> unit 711 = "llvm_set_function_call_conv" 712external gc : llvalue -> string option = "llvm_gc" 713external set_gc : string option -> llvalue -> unit = "llvm_set_gc" 714external function_begin : llmodule -> (llmodule, llvalue) llpos 715 = "llvm_function_begin" 716external function_succ : llvalue -> (llmodule, llvalue) llpos 717 = "llvm_function_succ" 718external function_end : llmodule -> (llmodule, llvalue) llrev_pos 719 = "llvm_function_end" 720external function_pred : llvalue -> (llmodule, llvalue) llrev_pos 721 = "llvm_function_pred" 722 723let rec iter_function_range f i e = 724 if i = e then () else 725 match i with 726 | At_end _ -> raise (Invalid_argument "Invalid function range.") 727 | Before fn -> 728 f fn; 729 iter_function_range f (function_succ fn) e 730 731let iter_functions f m = 732 iter_function_range f (function_begin m) (At_end m) 733 734let rec fold_left_function_range f init i e = 735 if i = e then init else 736 match i with 737 | At_end _ -> raise (Invalid_argument "Invalid function range.") 738 | Before fn -> fold_left_function_range f (f init fn) (function_succ fn) e 739 740let fold_left_functions f init m = 741 fold_left_function_range f init (function_begin m) (At_end m) 742 743let rec rev_iter_function_range f i e = 744 if i = e then () else 745 match i with 746 | At_start _ -> raise (Invalid_argument "Invalid function range.") 747 | After fn -> 748 f fn; 749 rev_iter_function_range f (function_pred fn) e 750 751let rev_iter_functions f m = 752 rev_iter_function_range f (function_end m) (At_start m) 753 754let rec fold_right_function_range f i e init = 755 if i = e then init else 756 match i with 757 | At_start _ -> raise (Invalid_argument "Invalid function range.") 758 | After fn -> fold_right_function_range f (function_pred fn) e (f fn init) 759 760let fold_right_functions f m init = 761 fold_right_function_range f (function_end m) (At_start m) init 762 763external llvm_add_function_attr : llvalue -> int32 -> unit 764 = "llvm_add_function_attr" 765external llvm_remove_function_attr : llvalue -> int32 -> unit 766 = "llvm_remove_function_attr" 767external llvm_function_attr : llvalue -> int32 = "llvm_function_attr" 768 769let pack_attr (attr:Attribute.t) : int32 = 770 match attr with 771 Attribute.Zext -> Int32.shift_left 1l 0 772 | Attribute.Sext -> Int32.shift_left 1l 1 773 | Attribute.Noreturn -> Int32.shift_left 1l 2 774 | Attribute.Inreg -> Int32.shift_left 1l 3 775 | Attribute.Structret -> Int32.shift_left 1l 4 776 | Attribute.Nounwind -> Int32.shift_left 1l 5 777 | Attribute.Noalias -> Int32.shift_left 1l 6 778 | Attribute.Byval -> Int32.shift_left 1l 7 779 | Attribute.Nest -> Int32.shift_left 1l 8 780 | Attribute.Readnone -> Int32.shift_left 1l 9 781 | Attribute.Readonly -> Int32.shift_left 1l 10 782 | Attribute.Noinline -> Int32.shift_left 1l 11 783 | Attribute.Alwaysinline -> Int32.shift_left 1l 12 784 | Attribute.Optsize -> Int32.shift_left 1l 13 785 | Attribute.Ssp -> Int32.shift_left 1l 14 786 | Attribute.Sspreq -> Int32.shift_left 1l 15 787 | Attribute.Alignment n -> Int32.shift_left (Int32.of_int n) 16 788 | Attribute.Nocapture -> Int32.shift_left 1l 21 789 | Attribute.Noredzone -> Int32.shift_left 1l 22 790 | Attribute.Noimplicitfloat -> Int32.shift_left 1l 23 791 | Attribute.Naked -> Int32.shift_left 1l 24 792 | Attribute.Inlinehint -> Int32.shift_left 1l 25 793 | Attribute.Stackalignment n -> Int32.shift_left (Int32.of_int n) 26 794 | Attribute.ReturnsTwice -> Int32.shift_left 1l 29 795 | Attribute.UWTable -> Int32.shift_left 1l 30 796 | Attribute.NonLazyBind -> Int32.shift_left 1l 31 797 798let unpack_attr (a : int32) : Attribute.t list = 799 let l = ref [] in 800 let check attr = 801 Int32.logand (pack_attr attr) a in 802 let checkattr attr = 803 if (check attr) <> 0l then begin 804 l := attr :: !l 805 end 806 in 807 checkattr Attribute.Zext; 808 checkattr Attribute.Sext; 809 checkattr Attribute.Noreturn; 810 checkattr Attribute.Inreg; 811 checkattr Attribute.Structret; 812 checkattr Attribute.Nounwind; 813 checkattr Attribute.Noalias; 814 checkattr Attribute.Byval; 815 checkattr Attribute.Nest; 816 checkattr Attribute.Readnone; 817 checkattr Attribute.Readonly; 818 checkattr Attribute.Noinline; 819 checkattr Attribute.Alwaysinline; 820 checkattr Attribute.Optsize; 821 checkattr Attribute.Ssp; 822 checkattr Attribute.Sspreq; 823 let align = Int32.logand (Int32.shift_right_logical a 16) 31l in 824 if align <> 0l then 825 l := Attribute.Alignment (Int32.to_int align) :: !l; 826 checkattr Attribute.Nocapture; 827 checkattr Attribute.Noredzone; 828 checkattr Attribute.Noimplicitfloat; 829 checkattr Attribute.Naked; 830 checkattr Attribute.Inlinehint; 831 let stackalign = Int32.logand (Int32.shift_right_logical a 26) 7l in 832 if stackalign <> 0l then 833 l := Attribute.Stackalignment (Int32.to_int stackalign) :: !l; 834 checkattr Attribute.ReturnsTwice; 835 checkattr Attribute.UWTable; 836 checkattr Attribute.NonLazyBind; 837 !l;; 838 839let add_function_attr llval attr = 840 llvm_add_function_attr llval (pack_attr attr) 841 842external add_target_dependent_function_attr 843 : llvalue -> string -> string -> unit 844 = "llvm_add_target_dependent_function_attr" 845 846let remove_function_attr llval attr = 847 llvm_remove_function_attr llval (pack_attr attr) 848 849let function_attr f = unpack_attr (llvm_function_attr f) 850 851(*--... Operations on params ...............................................--*) 852external params : llvalue -> llvalue array = "llvm_params" 853external param : llvalue -> int -> llvalue = "llvm_param" 854external llvm_param_attr : llvalue -> int32 = "llvm_param_attr" 855let param_attr p = unpack_attr (llvm_param_attr p) 856external param_parent : llvalue -> llvalue = "LLVMGetParamParent" 857external param_begin : llvalue -> (llvalue, llvalue) llpos = "llvm_param_begin" 858external param_succ : llvalue -> (llvalue, llvalue) llpos = "llvm_param_succ" 859external param_end : llvalue -> (llvalue, llvalue) llrev_pos = "llvm_param_end" 860external param_pred : llvalue -> (llvalue, llvalue) llrev_pos ="llvm_param_pred" 861 862let rec iter_param_range f i e = 863 if i = e then () else 864 match i with 865 | At_end _ -> raise (Invalid_argument "Invalid parameter range.") 866 | Before p -> 867 f p; 868 iter_param_range f (param_succ p) e 869 870let iter_params f fn = 871 iter_param_range f (param_begin fn) (At_end fn) 872 873let rec fold_left_param_range f init i e = 874 if i = e then init else 875 match i with 876 | At_end _ -> raise (Invalid_argument "Invalid parameter range.") 877 | Before p -> fold_left_param_range f (f init p) (param_succ p) e 878 879let fold_left_params f init fn = 880 fold_left_param_range f init (param_begin fn) (At_end fn) 881 882let rec rev_iter_param_range f i e = 883 if i = e then () else 884 match i with 885 | At_start _ -> raise (Invalid_argument "Invalid parameter range.") 886 | After p -> 887 f p; 888 rev_iter_param_range f (param_pred p) e 889 890let rev_iter_params f fn = 891 rev_iter_param_range f (param_end fn) (At_start fn) 892 893let rec fold_right_param_range f init i e = 894 if i = e then init else 895 match i with 896 | At_start _ -> raise (Invalid_argument "Invalid parameter range.") 897 | After p -> fold_right_param_range f (f p init) (param_pred p) e 898 899let fold_right_params f fn init = 900 fold_right_param_range f init (param_end fn) (At_start fn) 901 902external llvm_add_param_attr : llvalue -> int32 -> unit 903 = "llvm_add_param_attr" 904external llvm_remove_param_attr : llvalue -> int32 -> unit 905 = "llvm_remove_param_attr" 906 907let add_param_attr llval attr = 908 llvm_add_param_attr llval (pack_attr attr) 909 910let remove_param_attr llval attr = 911 llvm_remove_param_attr llval (pack_attr attr) 912 913external set_param_alignment : llvalue -> int -> unit 914 = "llvm_set_param_alignment" 915 916(*--... Operations on basic blocks .........................................--*) 917external value_of_block : llbasicblock -> llvalue = "LLVMBasicBlockAsValue" 918external value_is_block : llvalue -> bool = "llvm_value_is_block" 919external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock" 920external block_parent : llbasicblock -> llvalue = "LLVMGetBasicBlockParent" 921external basic_blocks : llvalue -> llbasicblock array = "llvm_basic_blocks" 922external entry_block : llvalue -> llbasicblock = "LLVMGetEntryBasicBlock" 923external delete_block : llbasicblock -> unit = "llvm_delete_block" 924external remove_block : llbasicblock -> unit = "llvm_remove_block" 925external move_block_before : llbasicblock -> llbasicblock -> unit 926 = "llvm_move_block_before" 927external move_block_after : llbasicblock -> llbasicblock -> unit 928 = "llvm_move_block_after" 929external append_block : llcontext -> string -> llvalue -> llbasicblock 930 = "llvm_append_block" 931external insert_block : llcontext -> string -> llbasicblock -> llbasicblock 932 = "llvm_insert_block" 933external block_begin : llvalue -> (llvalue, llbasicblock) llpos 934 = "llvm_block_begin" 935external block_succ : llbasicblock -> (llvalue, llbasicblock) llpos 936 = "llvm_block_succ" 937external block_end : llvalue -> (llvalue, llbasicblock) llrev_pos 938 = "llvm_block_end" 939external block_pred : llbasicblock -> (llvalue, llbasicblock) llrev_pos 940 = "llvm_block_pred" 941external block_terminator : llbasicblock -> llvalue option = 942 "llvm_block_terminator" 943 944let rec iter_block_range f i e = 945 if i = e then () else 946 match i with 947 | At_end _ -> raise (Invalid_argument "Invalid block range.") 948 | Before bb -> 949 f bb; 950 iter_block_range f (block_succ bb) e 951 952let iter_blocks f fn = 953 iter_block_range f (block_begin fn) (At_end fn) 954 955let rec fold_left_block_range f init i e = 956 if i = e then init else 957 match i with 958 | At_end _ -> raise (Invalid_argument "Invalid block range.") 959 | Before bb -> fold_left_block_range f (f init bb) (block_succ bb) e 960 961let fold_left_blocks f init fn = 962 fold_left_block_range f init (block_begin fn) (At_end fn) 963 964let rec rev_iter_block_range f i e = 965 if i = e then () else 966 match i with 967 | At_start _ -> raise (Invalid_argument "Invalid block range.") 968 | After bb -> 969 f bb; 970 rev_iter_block_range f (block_pred bb) e 971 972let rev_iter_blocks f fn = 973 rev_iter_block_range f (block_end fn) (At_start fn) 974 975let rec fold_right_block_range f init i e = 976 if i = e then init else 977 match i with 978 | At_start _ -> raise (Invalid_argument "Invalid block range.") 979 | After bb -> fold_right_block_range f (f bb init) (block_pred bb) e 980 981let fold_right_blocks f fn init = 982 fold_right_block_range f init (block_end fn) (At_start fn) 983 984(*--... Operations on instructions .........................................--*) 985external instr_parent : llvalue -> llbasicblock = "LLVMGetInstructionParent" 986external instr_begin : llbasicblock -> (llbasicblock, llvalue) llpos 987 = "llvm_instr_begin" 988external instr_succ : llvalue -> (llbasicblock, llvalue) llpos 989 = "llvm_instr_succ" 990external instr_end : llbasicblock -> (llbasicblock, llvalue) llrev_pos 991 = "llvm_instr_end" 992external instr_pred : llvalue -> (llbasicblock, llvalue) llrev_pos 993 = "llvm_instr_pred" 994 995external instr_opcode : llvalue -> Opcode.t = "llvm_instr_get_opcode" 996external icmp_predicate : llvalue -> Icmp.t option = "llvm_instr_icmp_predicate" 997external fcmp_predicate : llvalue -> Fcmp.t option = "llvm_instr_fcmp_predicate" 998external instr_clone : llvalue -> llvalue = "llvm_instr_clone" 999 1000let rec iter_instrs_range f i e = 1001 if i = e then () else 1002 match i with 1003 | At_end _ -> raise (Invalid_argument "Invalid instruction range.") 1004 | Before i -> 1005 f i; 1006 iter_instrs_range f (instr_succ i) e 1007 1008let iter_instrs f bb = 1009 iter_instrs_range f (instr_begin bb) (At_end bb) 1010 1011let rec fold_left_instrs_range f init i e = 1012 if i = e then init else 1013 match i with 1014 | At_end _ -> raise (Invalid_argument "Invalid instruction range.") 1015 | Before i -> fold_left_instrs_range f (f init i) (instr_succ i) e 1016 1017let fold_left_instrs f init bb = 1018 fold_left_instrs_range f init (instr_begin bb) (At_end bb) 1019 1020let rec rev_iter_instrs_range f i e = 1021 if i = e then () else 1022 match i with 1023 | At_start _ -> raise (Invalid_argument "Invalid instruction range.") 1024 | After i -> 1025 f i; 1026 rev_iter_instrs_range f (instr_pred i) e 1027 1028let rev_iter_instrs f bb = 1029 rev_iter_instrs_range f (instr_end bb) (At_start bb) 1030 1031let rec fold_right_instr_range f i e init = 1032 if i = e then init else 1033 match i with 1034 | At_start _ -> raise (Invalid_argument "Invalid instruction range.") 1035 | After i -> fold_right_instr_range f (instr_pred i) e (f i init) 1036 1037let fold_right_instrs f bb init = 1038 fold_right_instr_range f (instr_end bb) (At_start bb) init 1039 1040 1041(*--... Operations on call sites ...........................................--*) 1042external instruction_call_conv: llvalue -> int 1043 = "llvm_instruction_call_conv" 1044external set_instruction_call_conv: int -> llvalue -> unit 1045 = "llvm_set_instruction_call_conv" 1046 1047external llvm_add_instruction_param_attr : llvalue -> int -> int32 -> unit 1048 = "llvm_add_instruction_param_attr" 1049external llvm_remove_instruction_param_attr : llvalue -> int -> int32 -> unit 1050 = "llvm_remove_instruction_param_attr" 1051 1052let add_instruction_param_attr llval i attr = 1053 llvm_add_instruction_param_attr llval i (pack_attr attr) 1054 1055let remove_instruction_param_attr llval i attr = 1056 llvm_remove_instruction_param_attr llval i (pack_attr attr) 1057 1058(*--... Operations on call instructions (only) .............................--*) 1059external is_tail_call : llvalue -> bool = "llvm_is_tail_call" 1060external set_tail_call : bool -> llvalue -> unit = "llvm_set_tail_call" 1061 1062(*--... Operations on load/store instructions (only) .......................--*) 1063external is_volatile : llvalue -> bool = "llvm_is_volatile" 1064external set_volatile : bool -> llvalue -> unit = "llvm_set_volatile" 1065 1066(*--... Operations on terminators ..........................................--*) 1067 1068let is_terminator llv = 1069 let open ValueKind in 1070 let open Opcode in 1071 match classify_value llv with 1072 | Instruction (Br | IndirectBr | Invoke | Resume | Ret | Switch | Unreachable) 1073 -> true 1074 | _ -> false 1075 1076external successor : llvalue -> int -> llbasicblock = "llvm_successor" 1077external set_successor : llvalue -> int -> llbasicblock -> unit 1078 = "llvm_set_successor" 1079external num_successors : llvalue -> int = "llvm_num_successors" 1080 1081let successors llv = 1082 if not (is_terminator llv) then 1083 raise (Invalid_argument "Llvm.successors can only be used on terminators") 1084 else 1085 Array.init (num_successors llv) (successor llv) 1086 1087let iter_successors f llv = 1088 if not (is_terminator llv) then 1089 raise (Invalid_argument "Llvm.iter_successors can only be used on terminators") 1090 else 1091 for i = 0 to num_successors llv - 1 do 1092 f (successor llv i) 1093 done 1094 1095let fold_successors f llv z = 1096 if not (is_terminator llv) then 1097 raise (Invalid_argument "Llvm.fold_successors can only be used on terminators") 1098 else 1099 let n = num_successors llv in 1100 let rec aux i acc = 1101 if i >= n then acc 1102 else begin 1103 let llb = successor llv i in 1104 aux (i+1) (f llb acc) 1105 end 1106 in aux 0 z 1107 1108 1109(*--... Operations on branches .............................................--*) 1110external condition : llvalue -> llvalue = "llvm_condition" 1111external set_condition : llvalue -> llvalue -> unit 1112 = "llvm_set_condition" 1113external is_conditional : llvalue -> bool = "llvm_is_conditional" 1114 1115let get_branch llv = 1116 if classify_value llv <> ValueKind.Instruction Opcode.Br then 1117 None 1118 else if is_conditional llv then 1119 Some (`Conditional (condition llv, successor llv 0, successor llv 1)) 1120 else 1121 Some (`Unconditional (successor llv 0)) 1122 1123(*--... Operations on phi nodes ............................................--*) 1124external add_incoming : (llvalue * llbasicblock) -> llvalue -> unit 1125 = "llvm_add_incoming" 1126external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming" 1127 1128external delete_instruction : llvalue -> unit = "llvm_delete_instruction" 1129 1130(*===-- Instruction builders ----------------------------------------------===*) 1131external builder : llcontext -> llbuilder = "llvm_builder" 1132external position_builder : (llbasicblock, llvalue) llpos -> llbuilder -> unit 1133 = "llvm_position_builder" 1134external insertion_block : llbuilder -> llbasicblock = "llvm_insertion_block" 1135external insert_into_builder : llvalue -> string -> llbuilder -> unit 1136 = "llvm_insert_into_builder" 1137 1138let builder_at context ip = 1139 let b = builder context in 1140 position_builder ip b; 1141 b 1142 1143let builder_before context i = builder_at context (Before i) 1144let builder_at_end context bb = builder_at context (At_end bb) 1145 1146let position_before i = position_builder (Before i) 1147let position_at_end bb = position_builder (At_end bb) 1148 1149 1150(*--... Metadata ...........................................................--*) 1151external set_current_debug_location : llbuilder -> llvalue -> unit 1152 = "llvm_set_current_debug_location" 1153external clear_current_debug_location : llbuilder -> unit 1154 = "llvm_clear_current_debug_location" 1155external current_debug_location : llbuilder -> llvalue option 1156 = "llvm_current_debug_location" 1157external set_inst_debug_location : llbuilder -> llvalue -> unit 1158 = "llvm_set_inst_debug_location" 1159 1160 1161(*--... Terminators ........................................................--*) 1162external build_ret_void : llbuilder -> llvalue = "llvm_build_ret_void" 1163external build_ret : llvalue -> llbuilder -> llvalue = "llvm_build_ret" 1164external build_aggregate_ret : llvalue array -> llbuilder -> llvalue 1165 = "llvm_build_aggregate_ret" 1166external build_br : llbasicblock -> llbuilder -> llvalue = "llvm_build_br" 1167external build_cond_br : llvalue -> llbasicblock -> llbasicblock -> llbuilder -> 1168 llvalue = "llvm_build_cond_br" 1169external build_switch : llvalue -> llbasicblock -> int -> llbuilder -> llvalue 1170 = "llvm_build_switch" 1171external build_malloc : lltype -> string -> llbuilder -> llvalue = 1172 "llvm_build_malloc" 1173external build_array_malloc : lltype -> llvalue -> string -> llbuilder -> 1174 llvalue = "llvm_build_array_malloc" 1175external build_free : llvalue -> llbuilder -> llvalue = "llvm_build_free" 1176external add_case : llvalue -> llvalue -> llbasicblock -> unit 1177 = "llvm_add_case" 1178external switch_default_dest : llvalue -> llbasicblock = 1179 "LLVMGetSwitchDefaultDest" 1180external build_indirect_br : llvalue -> int -> llbuilder -> llvalue 1181 = "llvm_build_indirect_br" 1182external add_destination : llvalue -> llbasicblock -> unit 1183 = "llvm_add_destination" 1184external build_invoke : llvalue -> llvalue array -> llbasicblock -> 1185 llbasicblock -> string -> llbuilder -> llvalue 1186 = "llvm_build_invoke_bc" "llvm_build_invoke_nat" 1187external build_landingpad : lltype -> llvalue -> int -> string -> llbuilder -> 1188 llvalue = "llvm_build_landingpad" 1189external set_cleanup : llvalue -> bool -> unit = "llvm_set_cleanup" 1190external add_clause : llvalue -> llvalue -> unit = "llvm_add_clause" 1191external build_resume : llvalue -> llbuilder -> llvalue = "llvm_build_resume" 1192external build_unreachable : llbuilder -> llvalue = "llvm_build_unreachable" 1193 1194(*--... Arithmetic .........................................................--*) 1195external build_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1196 = "llvm_build_add" 1197external build_nsw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1198 = "llvm_build_nsw_add" 1199external build_nuw_add : llvalue -> llvalue -> string -> llbuilder -> llvalue 1200 = "llvm_build_nuw_add" 1201external build_fadd : llvalue -> llvalue -> string -> llbuilder -> llvalue 1202 = "llvm_build_fadd" 1203external build_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1204 = "llvm_build_sub" 1205external build_nsw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1206 = "llvm_build_nsw_sub" 1207external build_nuw_sub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1208 = "llvm_build_nuw_sub" 1209external build_fsub : llvalue -> llvalue -> string -> llbuilder -> llvalue 1210 = "llvm_build_fsub" 1211external build_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1212 = "llvm_build_mul" 1213external build_nsw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1214 = "llvm_build_nsw_mul" 1215external build_nuw_mul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1216 = "llvm_build_nuw_mul" 1217external build_fmul : llvalue -> llvalue -> string -> llbuilder -> llvalue 1218 = "llvm_build_fmul" 1219external build_udiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1220 = "llvm_build_udiv" 1221external build_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1222 = "llvm_build_sdiv" 1223external build_exact_sdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1224 = "llvm_build_exact_sdiv" 1225external build_fdiv : llvalue -> llvalue -> string -> llbuilder -> llvalue 1226 = "llvm_build_fdiv" 1227external build_urem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1228 = "llvm_build_urem" 1229external build_srem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1230 = "llvm_build_srem" 1231external build_frem : llvalue -> llvalue -> string -> llbuilder -> llvalue 1232 = "llvm_build_frem" 1233external build_shl : llvalue -> llvalue -> string -> llbuilder -> llvalue 1234 = "llvm_build_shl" 1235external build_lshr : llvalue -> llvalue -> string -> llbuilder -> llvalue 1236 = "llvm_build_lshr" 1237external build_ashr : llvalue -> llvalue -> string -> llbuilder -> llvalue 1238 = "llvm_build_ashr" 1239external build_and : llvalue -> llvalue -> string -> llbuilder -> llvalue 1240 = "llvm_build_and" 1241external build_or : llvalue -> llvalue -> string -> llbuilder -> llvalue 1242 = "llvm_build_or" 1243external build_xor : llvalue -> llvalue -> string -> llbuilder -> llvalue 1244 = "llvm_build_xor" 1245external build_neg : llvalue -> string -> llbuilder -> llvalue 1246 = "llvm_build_neg" 1247external build_nsw_neg : llvalue -> string -> llbuilder -> llvalue 1248 = "llvm_build_nsw_neg" 1249external build_nuw_neg : llvalue -> string -> llbuilder -> llvalue 1250 = "llvm_build_nuw_neg" 1251external build_fneg : llvalue -> string -> llbuilder -> llvalue 1252 = "llvm_build_fneg" 1253external build_not : llvalue -> string -> llbuilder -> llvalue 1254 = "llvm_build_not" 1255 1256(*--... Memory .............................................................--*) 1257external build_alloca : lltype -> string -> llbuilder -> llvalue 1258 = "llvm_build_alloca" 1259external build_array_alloca : lltype -> llvalue -> string -> llbuilder -> 1260 llvalue = "llvm_build_array_alloca" 1261external build_load : llvalue -> string -> llbuilder -> llvalue 1262 = "llvm_build_load" 1263external build_store : llvalue -> llvalue -> llbuilder -> llvalue 1264 = "llvm_build_store" 1265external build_atomicrmw : AtomicRMWBinOp.t -> llvalue -> llvalue -> 1266 AtomicOrdering.t -> bool -> string -> llbuilder -> 1267 llvalue 1268 = "llvm_build_atomicrmw_bytecode" 1269 "llvm_build_atomicrmw_native" 1270external build_gep : llvalue -> llvalue array -> string -> llbuilder -> llvalue 1271 = "llvm_build_gep" 1272external build_in_bounds_gep : llvalue -> llvalue array -> string -> 1273 llbuilder -> llvalue = "llvm_build_in_bounds_gep" 1274external build_struct_gep : llvalue -> int -> string -> llbuilder -> llvalue 1275 = "llvm_build_struct_gep" 1276 1277external build_global_string : string -> string -> llbuilder -> llvalue 1278 = "llvm_build_global_string" 1279external build_global_stringptr : string -> string -> llbuilder -> llvalue 1280 = "llvm_build_global_stringptr" 1281 1282(*--... Casts ..............................................................--*) 1283external build_trunc : llvalue -> lltype -> string -> llbuilder -> llvalue 1284 = "llvm_build_trunc" 1285external build_zext : llvalue -> lltype -> string -> llbuilder -> llvalue 1286 = "llvm_build_zext" 1287external build_sext : llvalue -> lltype -> string -> llbuilder -> llvalue 1288 = "llvm_build_sext" 1289external build_fptoui : llvalue -> lltype -> string -> llbuilder -> llvalue 1290 = "llvm_build_fptoui" 1291external build_fptosi : llvalue -> lltype -> string -> llbuilder -> llvalue 1292 = "llvm_build_fptosi" 1293external build_uitofp : llvalue -> lltype -> string -> llbuilder -> llvalue 1294 = "llvm_build_uitofp" 1295external build_sitofp : llvalue -> lltype -> string -> llbuilder -> llvalue 1296 = "llvm_build_sitofp" 1297external build_fptrunc : llvalue -> lltype -> string -> llbuilder -> llvalue 1298 = "llvm_build_fptrunc" 1299external build_fpext : llvalue -> lltype -> string -> llbuilder -> llvalue 1300 = "llvm_build_fpext" 1301external build_ptrtoint : llvalue -> lltype -> string -> llbuilder -> llvalue 1302 = "llvm_build_prttoint" 1303external build_inttoptr : llvalue -> lltype -> string -> llbuilder -> llvalue 1304 = "llvm_build_inttoptr" 1305external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1306 = "llvm_build_bitcast" 1307external build_zext_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1308 llvalue = "llvm_build_zext_or_bitcast" 1309external build_sext_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1310 llvalue = "llvm_build_sext_or_bitcast" 1311external build_trunc_or_bitcast : llvalue -> lltype -> string -> llbuilder -> 1312 llvalue = "llvm_build_trunc_or_bitcast" 1313external build_pointercast : llvalue -> lltype -> string -> llbuilder -> llvalue 1314 = "llvm_build_pointercast" 1315external build_intcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1316 = "llvm_build_intcast" 1317external build_fpcast : llvalue -> lltype -> string -> llbuilder -> llvalue 1318 = "llvm_build_fpcast" 1319 1320(*--... Comparisons ........................................................--*) 1321external build_icmp : Icmp.t -> llvalue -> llvalue -> string -> 1322 llbuilder -> llvalue = "llvm_build_icmp" 1323external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string -> 1324 llbuilder -> llvalue = "llvm_build_fcmp" 1325 1326(*--... Miscellaneous instructions .........................................--*) 1327external build_phi : (llvalue * llbasicblock) list -> string -> llbuilder -> 1328 llvalue = "llvm_build_phi" 1329external build_empty_phi : lltype -> string -> llbuilder -> llvalue 1330 = "llvm_build_empty_phi" 1331external build_call : llvalue -> llvalue array -> string -> llbuilder -> llvalue 1332 = "llvm_build_call" 1333external build_select : llvalue -> llvalue -> llvalue -> string -> llbuilder -> 1334 llvalue = "llvm_build_select" 1335external build_va_arg : llvalue -> lltype -> string -> llbuilder -> llvalue 1336 = "llvm_build_va_arg" 1337external build_extractelement : llvalue -> llvalue -> string -> llbuilder -> 1338 llvalue = "llvm_build_extractelement" 1339external build_insertelement : llvalue -> llvalue -> llvalue -> string -> 1340 llbuilder -> llvalue = "llvm_build_insertelement" 1341external build_shufflevector : llvalue -> llvalue -> llvalue -> string -> 1342 llbuilder -> llvalue = "llvm_build_shufflevector" 1343external build_extractvalue : llvalue -> int -> string -> llbuilder -> llvalue 1344 = "llvm_build_extractvalue" 1345external build_insertvalue : llvalue -> llvalue -> int -> string -> llbuilder -> 1346 llvalue = "llvm_build_insertvalue" 1347 1348external build_is_null : llvalue -> string -> llbuilder -> llvalue 1349 = "llvm_build_is_null" 1350external build_is_not_null : llvalue -> string -> llbuilder -> llvalue 1351 = "llvm_build_is_not_null" 1352external build_ptrdiff : llvalue -> llvalue -> string -> llbuilder -> llvalue 1353 = "llvm_build_ptrdiff" 1354 1355 1356(*===-- Memory buffers ----------------------------------------------------===*) 1357 1358module MemoryBuffer = struct 1359 external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file" 1360 external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin" 1361 external of_string : ?name:string -> string -> llmemorybuffer 1362 = "llvm_memorybuffer_of_string" 1363 external as_string : llmemorybuffer -> string = "llvm_memorybuffer_as_string" 1364 external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose" 1365end 1366 1367 1368(*===-- Pass Manager ------------------------------------------------------===*) 1369 1370module PassManager = struct 1371 type 'a t 1372 type any = [ `Module | `Function ] 1373 external create : unit -> [ `Module ] t = "llvm_passmanager_create" 1374 external create_function : llmodule -> [ `Function ] t 1375 = "LLVMCreateFunctionPassManager" 1376 external run_module : llmodule -> [ `Module ] t -> bool 1377 = "llvm_passmanager_run_module" 1378 external initialize : [ `Function ] t -> bool = "llvm_passmanager_initialize" 1379 external run_function : llvalue -> [ `Function ] t -> bool 1380 = "llvm_passmanager_run_function" 1381 external finalize : [ `Function ] t -> bool = "llvm_passmanager_finalize" 1382 external dispose : [< any ] t -> unit = "llvm_passmanager_dispose" 1383end 1384