Cleanup some comments in the OCaml bindings.
[oota-llvm.git] / bindings / ocaml / llvm / llvm.mli
index ac83e428098ea9f4463691cdbe65d394b909b45e..3ed9d273293c4fbb5f071bed375d1161bdb0986f 100644 (file)
@@ -1,9 +1,9 @@
-(*===-- tools/ml/llvm.ml - LLVM Ocaml Interface ---------------------------===*
+(*===-- llvm/llvm.mli - LLVM Ocaml Interface -------------------------------===*
  *
  *                     The LLVM Compiler Infrastructure
  *
- * This file was developed by Gordon Henriksen and is distributed under the
- * University of Illinois Open Source License. See LICENSE.TXT for details.
+ * This file is distributed under the University of Illinois Open Source
+ * License. See LICENSE.TXT for details.
  *
  *===----------------------------------------------------------------------===
  *
@@ -40,91 +40,113 @@ type llbasicblock
     class. **)
 type llbuilder
 
+(** Used to provide a module to JIT or interpreter.
+    See the [llvm::ModuleProvider] class. **)
+type llmoduleprovider
+
+(** Used to efficiently handle large buffers of read-only binary data.
+    See the [llvm::MemoryBuffer] class. **)
+type llmemorybuffer
+
 (** The kind of an [lltype], the result of [classify_type ty]. See the 
     [llvm::Type::TypeID] enumeration. **)
-type type_kind =
-  Void_type
-| Float_type
-| Double_type
-| X86fp80_type
-| Fp128_type
-| Ppc_fp128_type
-| Label_type
-| Integer_type
-| Function_type
-| Struct_type
-| Array_type
-| Pointer_type
-| Opaque_type
-| Vector_type
+module TypeKind : sig
+  type t =
+    Void
+  | Float
+  | Double
+  | X86fp80
+  | Fp128
+  | Ppc_fp128
+  | Label
+  | Integer
+  | Function
+  | Struct
+  | Array
+  | Pointer
+  | Opaque
+  | Vector
+end
 
 (** The linkage of a global value, accessed with [linkage gv] and
     [set_linkage l gv]. See [llvm::GlobalValue::LinkageTypes]. **)
-type linkage =
-  External_linkage
-| Link_once_linkage
-| Weak_linkage
-| Appending_linkage
-| Internal_linkage
-| Dllimport_linkage
-| Dllexport_linkage
-| External_weak_linkage
-| Ghost_linkage
+module Linkage : sig
+  type t =
+    External
+  | Link_once
+  | Weak
+  | Appending
+  | Internal
+  | Dllimport
+  | Dllexport
+  | External_weak
+  | Ghost
+end
 
 (** The linker visibility of a global value, accessed with [visibility gv] and
     [set_visibility v gv]. See [llvm::GlobalValue::VisibilityTypes]. **)
-type visibility =
-  Default_visibility
-| Hidden_visibility
-| Protected_visibility
+module Visibility : sig
+  type t =
+    Default
+  | Hidden
+  | Protected
+end
 
 (* The following calling convention values may be accessed with
    [function_call_conv f] and [set_function_call_conv conv f]. Calling
    conventions are open-ended. *)
-val ccc : int             (** [ccc] is the C calling convention. **)
-val fastcc : int          (** [fastcc] is the calling convention to allow LLVM
+module CallConv : sig
+  val c : int             (** [c] is the C calling convention. **)
+  val fast : int          (** [fast] is the calling convention to allow LLVM
                               maximum optimization opportunities. Use only with
                               internal linkage. **)
-val coldcc : int          (** [coldcc] is the calling convention for
+  val cold : int          (** [cold] is the calling convention for
                               callee-save. **)
-val x86_stdcallcc : int   (** [x86_stdcallcc] is the familiar stdcall calling
+  val x86_stdcall : int   (** [x86_stdcall] is the familiar stdcall calling
                               convention from C. **)
-val x86_fastcallcc : int  (** [x86_fastcallcc] is the familiar fastcall calling
+  val x86_fastcall : int  (** [x86_fastcall] is the familiar fastcall calling
                               convention from C. **)
+end
 
 (** The predicate for an integer comparison ([icmp]) instruction.
     See the [llvm::ICmpInst::Predicate] enumeration. **)
-type int_predicate =
-  Icmp_eq
-| Icmp_ne
-| Icmp_ugt
-| Icmp_uge
-| Icmp_ult
-| Icmp_ule
-| Icmp_sgt
-| Icmp_sge
-| Icmp_slt
-| Icmp_sle
+module Icmp : sig
+  type t =
+  | Eq
+  | Ne
+  | Ugt
+  | Uge
+  | Ult
+  | Ule
+  | Sgt
+  | Sge
+  | Slt
+  | Sle
+end
 
 (** The predicate for a floating-point comparison ([fcmp]) instruction.
     See the [llvm::FCmpInst::Predicate] enumeration. **)
-type real_predicate =
-  Fcmp_false
-| Fcmp_oeq
-| Fcmp_ogt
-| Fcmp_oge
-| Fcmp_olt
-| Fcmp_ole
-| Fcmp_one
-| Fcmp_ord
-| Fcmp_uno
-| Fcmp_ueq
-| Fcmp_ugt
-| Fcmp_uge
-| Fcmp_ult
-| Fcmp_ule
-| Fcmp_une
-| Fcmp_true
+module Fcmp : sig
+  type t =
+  | False
+  | Oeq
+  | Ogt
+  | Oge
+  | Olt
+  | Ole
+  | One
+  | Ord
+  | Uno
+  | Ueq
+  | Ugt
+  | Uge
+  | Ult
+  | Ule
+  | Une
+  | True
+end
+
+exception IoError of string
 
 
 (*===-- Modules -----------------------------------------------------------===*)
@@ -140,6 +162,27 @@ external create_module : string -> llmodule = "llvm_create_module"
     [llvm::Module::~Module]. **)
 external dispose_module : llmodule -> unit = "llvm_dispose_module"
 
+(** [target_triple m] is the target specifier for the module [m], something like
+    [i686-apple-darwin8]. See the method [llvm::Module::getTargetTriple]. **)
+external target_triple: llmodule -> string
+                      = "llvm_target_triple"
+
+(** [target_triple triple m] changes the target specifier for the module [m] to
+    the string [triple]. See the method [llvm::Module::setTargetTriple]. **)
+external set_target_triple: string -> llmodule -> unit
+                          = "llvm_set_target_triple"
+
+(** [data_layout m] is the data layout specifier for the module [m], something
+    like [e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-...-a0:0:64-f80:128:128]. See the
+    method [llvm::Module::getDataLayout]. **)
+external data_layout: llmodule -> string
+                    = "llvm_data_layout"
+
+(** [set_data_layout s m] changes the data layout specifier for the module [m]
+    to the string [s]. See the method [llvm::Module::setDataLayout]. **)
+external set_data_layout: string -> llmodule -> unit
+                        = "llvm_set_data_layout"
+
 (** [define_type_name name ty m] adds a named type to the module's symbol table.
     Returns [true] if successful. If such a name already exists, then no entry
     is added and [false] is returned. See the [llvm::Module::addTypeName]
@@ -157,7 +200,7 @@ external delete_type_name : string -> llmodule -> unit
 
 (** [classify_type ty] returns the [type_kind] corresponding to the type [ty].
     See the method [llvm::Type::getTypeID]. **)
-external classify_type : lltype -> type_kind = "llvm_classify_type"
+external classify_type : lltype -> TypeKind.t = "llvm_classify_type"
 
 (** [string_of_lltype ty] returns a string describing the type [ty]. **)
 val string_of_lltype : lltype -> string
@@ -255,8 +298,15 @@ external is_packed : lltype -> bool = "llvm_is_packed"
 external array_type : lltype -> int -> lltype = "llvm_array_type"
 
 (** [pointer_type ty] returns the pointer type referencing objects of type
-    [ty]. See the method [llvm::PointerType::get]. **)
-external pointer_type : lltype -> lltype = "LLVMPointerType"
+    [ty] in the default address space (0).
+    See the method [llvm::PointerType::getUnqual]. **)
+external pointer_type : lltype -> lltype = "llvm_pointer_type"
+
+(** [qualified_pointer_type ty as] returns the pointer type referencing objects
+    of type [ty] in address space [as].
+    See the method [llvm::PointerType::get]. **)
+external qualified_pointer_type : lltype -> int -> lltype
+                                = "llvm_qualified_pointer_type"
 
 (** [vector_type ty n] returns the array type containing [n] elements of the
     primitive type [ty]. See the method [llvm::ArrayType::get]. **)
@@ -270,6 +320,10 @@ external element_type : lltype -> lltype = "LLVMGetElementType"
     See the method [llvm::ArrayType::getNumElements]. **)
 external array_length : lltype -> int = "llvm_array_length"
 
+(** [address_space pty] returns the address space qualifier of the pointer type
+    [pty]. See the method [llvm::PointerType::getAddressSpace]. **)
+external address_space : lltype -> int = "llvm_address_space"
+
 (** [element_type ty] returns the element count of the vector type [ty].
     See the method [llvm::VectorType::getNumElements]. **)
 external vector_size : lltype -> int = "llvm_vector_size"
@@ -483,13 +537,13 @@ external const_xor : llvalue -> llvalue -> llvalue = "LLVMConstXor"
 (** [const_icmp pred c1 c2] returns the constant comparison of two integer
     constants, [c1 pred c2].
     See the method [llvm::ConstantExpr::getICmp]. **)
-external const_icmp : int_predicate -> llvalue -> llvalue -> llvalue
+external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
                     = "llvm_const_icmp"
 
 (** [const_fcmp pred c1 c2] returns the constant comparison of two floating
     point constants, [c1 pred c2].
     See the method [llvm::ConstantExpr::getFCmp]. **)
-external const_fcmp : real_predicate -> llvalue -> llvalue -> llvalue
+external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
                     = "llvm_const_fcmp"
 
 (** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
@@ -610,11 +664,11 @@ external is_declaration : llvalue -> bool = "llvm_is_declaration"
 
 (** [linkage g] returns the linkage of the global value [g].
     See the method [llvm::GlobalValue::getLinkage]. **)
-external linkage : llvalue -> linkage = "llvm_linkage"
+external linkage : llvalue -> Linkage.t = "llvm_linkage"
 
 (** [set_linkage l g] sets the linkage of the global value [g] to [l].
     See the method [llvm::GlobalValue::setLinkage]. **)
-external set_linkage : linkage -> llvalue -> unit = "llvm_set_linkage"
+external set_linkage : Linkage.t -> llvalue -> unit = "llvm_set_linkage"
 
 (** [section g] returns the linker section of the global value [g].
     See the method [llvm::GlobalValue::getSection]. **)
@@ -626,11 +680,12 @@ external set_section : string -> llvalue -> unit = "llvm_set_section"
 
 (** [visibility g] returns the linker visibility of the global value [g].
     See the method [llvm::GlobalValue::getVisibility]. **)
-external visibility : llvalue -> visibility = "llvm_visibility"
+external visibility : llvalue -> Visibility.t = "llvm_visibility"
 
 (** [set_visibility v g] sets the linker visibility of the global value [g] to
     [v]. See the method [llvm::GlobalValue::setVisibility]. **)
-external set_visibility : visibility -> llvalue -> unit = "llvm_set_visibility"
+external set_visibility : Visibility.t -> llvalue -> unit
+                        = "llvm_set_visibility"
 
 (** [alignment g] returns the required alignment of the global value [g].
     See the method [llvm::GlobalValue::getAlignment]. **)
@@ -754,6 +809,15 @@ external function_call_conv : llvalue -> int = "llvm_function_call_conv"
 external set_function_call_conv : int -> llvalue -> unit
                                 = "llvm_set_function_call_conv"
 
+(** [collector f] returns [Some name] if the function [f] has a garbage
+    collection algorithm specified and [None] otherwise.
+    See the method [llvm::Function::getCollector]. **)
+external collector : llvalue -> string option = "llvm_collector"
+
+(** [set_collector gc f] sets the collection algorithm for the function [f] to
+    [gc]. See the method [llvm::Function::setCollector]. **)
+external set_collector : string option -> llvalue -> unit = "llvm_set_collector"
+
 (*--... Operations on basic blocks .........................................--*)
 
 (** [basic_blocks fn] returns the basic blocks of the function [f].
@@ -790,6 +854,20 @@ external value_is_block : llvalue -> bool = "llvm_value_is_block"
 (** [block_of_value v] losslessly casts [v] to an [llbasicblock]. **)
 external block_of_value : llvalue -> llbasicblock = "LLVMValueAsBasicBlock"
 
+(*--... Operations on call sites ...........................................--*)
+
+(** [inst_call_conv ci] is the calling convention for the call or invoke
+    instruction [ci], which may be one of the values from the module [CallConv].
+    See the method [CallSite:: **)
+external instruction_call_conv: llvalue -> int
+                              = "llvm_instruction_call_conv"
+
+(** [set_inst_call_conv cc ci] sets the calling convention for the call or
+    invoke instruction [ci] to the integer [cc], which can be one of the values
+    from the module [CallConv]. See the method [CallSite::]. **)
+external set_instruction_call_conv: int -> llvalue -> unit
+                                  = "llvm_set_instruction_call_conv"
+
 (*--... Operations on phi nodes ............................................--*)
 
 (** [add_incoming (v, bb) pn] adds the value [v] to the phi node [pn] for use
@@ -804,6 +882,12 @@ external incoming : llvalue -> (llvalue * llbasicblock) list = "llvm_incoming"
 
 (*===-- Instruction builders ----------------------------------------------===*)
 
+(** [builder] creates an instruction builder with no position. It is invalid to
+    use this builder until its position is set with [position_before] or
+    [position_at_end]. See the constructor for [llvm::LLVMBuilder]. **)
+external builder: unit-> llbuilder
+                = "llvm_builder"
+
 (** [builder_before ins] creates an instruction builder positioned before the
     instruction [isn]. See the constructor for [llvm::LLVMBuilder]. **)
 external builder_before : llvalue -> llbuilder = "llvm_builder_before"
@@ -1048,7 +1132,7 @@ external build_load : llvalue -> string -> llbuilder -> llvalue
 external build_store : llvalue -> llvalue -> llbuilder -> llvalue
                      = "llvm_build_store"
 
-(** [build_store p indices name b] creates a
+(** [build_gep p indices name b] creates a
     [%name = gep %p, indices...]
     instruction at the position specified by the instruction builder [b].
     See the method [llvm::LLVMBuilder::CreateGetElementPtr]. **)
@@ -1147,14 +1231,14 @@ external build_bitcast : llvalue -> lltype -> string -> llbuilder -> llvalue
     [%name = icmp %pred %x, %y]
     instruction at the position specified by the instruction builder [b].
     See the method [llvm::LLVMBuilder::CreateICmp]. **)
-external build_icmp : int_predicate -> llvalue -> llvalue -> string ->
+external build_icmp : Icmp.t -> llvalue -> llvalue -> string ->
                       llbuilder -> llvalue = "llvm_build_icmp"
 
 (** [build_fcmp pred x y name b] creates a
     [%name = fcmp %pred %x, %y]
     instruction at the position specified by the instruction builder [b].
     See the method [llvm::LLVMBuilder::CreateFCmp]. **)
-external build_fcmp : real_predicate -> llvalue -> llvalue -> string ->
+external build_fcmp : Fcmp.t -> llvalue -> llvalue -> string ->
                       llbuilder -> llvalue = "llvm_build_fcmp"
 
 (*--... Miscellaneous instructions .........................................--*)
@@ -1208,3 +1292,34 @@ external build_insertelement : llvalue -> llvalue -> llvalue -> string ->
     See the method [llvm::LLVMBuilder::CreateShuffleVector]. **)
 external build_shufflevector : llvalue -> llvalue -> llvalue -> string ->
                                llbuilder -> llvalue = "llvm_build_shufflevector"
+
+
+(*===-- Module providers --------------------------------------------------===*)
+
+module ModuleProvider : sig
+  (** [create_module_provider m] encapsulates [m] in a module provider and takes
+      ownership of the module. See the constructor 
+      [llvm::ExistingModuleProvider::ExistingModuleProvider]. **)
+  external create : llmodule -> llmoduleprovider
+                  = "LLVMCreateModuleProviderForExistingModule"
+
+  (** [dispose_module_provider mp] destroys the module provider [mp] as well as
+      the contained module. **)
+  external dispose : llmoduleprovider -> unit = "llvm_dispose_module_provider"
+end
+  
+
+(*===-- Memory buffers ----------------------------------------------------===*)
+
+module MemoryBuffer : sig
+  (** [of_file p] is the memory buffer containing the contents of the file at 
+      path [p]. If the file could not be read, then [IoError msg] is raised. **)
+  external of_file : string -> llmemorybuffer = "llvm_memorybuffer_of_file"
+  
+  (** [stdin ()] is the memory buffer containing the contents of standard input.
+      If standard input is empty, then [IoError msg] is raised. **)
+  external of_stdin : unit -> llmemorybuffer = "llvm_memorybuffer_of_stdin"
+  
+  (** Disposes of a memory buffer. **)
+  external dispose : llmemorybuffer -> unit = "llvm_memorybuffer_dispose"
+end