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