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