ocaml-llvm-phantom / lib / type_intf.ml

open Spotlib.Spot
(* open Spotlib.Spot.Phantom.Open *)

module type S0 = sig
  (** phantom *)
  type 'a typ = ('a, Llvm.lltype) Phantom.t
  type 'a typs = ('a, Llvm.lltype) Phantom.ts
  
  (** descriptors *)
  
  type void = unit
  type i1 = [`int | `i1]
  type i8 = [`int | `i8]
  type i16 = [`int | `i16]
  type i32 = [`int | `i32]
  type i64 = [`int | `i64]
  type 'a integer
  type float_ = [`floating | `float]
  type double = [`floating | `double]
  type x86fp80 = [`floating | `x86fp80]
  type fp128 = [`floating | `fp128]
  type ppc_fp128 = [`floating | `ppc_fp128]
  type dots
  type 'a struct_ = [`members of 'a | `aligned_struct]
  type 'a packed_struct = [`members of 'a | `packed_struct]
  type ('a, 'sizetag) array_ = [`array of 'a * 'sizetag | `container of 'a] (* use OCaml's array *)
  type 'a pointer = [`pointer of 'a | `container of 'a]  
    (* The definition is to permit recursive definition like:
       type t = (i32 * t pointer) struct_
    *)
  type ('a, 'sizetag) vector = [`vector of 'a * 'sizetag | `container of 'a]
  type label

  (* void pointer is special in LLVM. It is illegal! *)
  type void_pointer = i8 pointer

  type address_space = int
end

module type S = sig
  include S0

  val context : Context.t

  (** {6 Types} *)

  val classify : 'a typ -> Llvm.TypeKind.t
  (* val type_context *)
  val string_of : 'a typ -> string
    (** bugfixed version of string_of_lltype, which can print recursive types :-) *)

  (** {7 Operations on integer types} *)

  val i1 : i1 typ
  val i8 : i8 typ
  val i16 : i16 typ
  val i32 : i32 typ
  val i64 : i64 typ
  val integer : 'tag * int -> 'tag integer typ
  val integer_bitwidth : 'tag integer typ -> int

  (** {7 Operations on real types} *)

  val float : float_ typ
  val double : double typ
  val x86fp80 : x86fp80 typ
  val fp128 : fp128 typ
  val ppc_fp128 : ppc_fp128 typ

  (** {7 Operations on function types} *)

  val function_ : 'ret typ -> 'args typs -> ('args -> 'ret) typ
  val var_arg_function : 'ret typ -> 'args typs -> ('args -> dots -> 'ret) typ
  (* is_var_arg : we do not need it (prbbly). *)
  val function_return : ('args -> 'ret) typ -> 'ret typ
    (** return_type *)
  val function_params : ('args -> 'ret) typ -> 'args typs
    (** param_types : function_ is prefixed to avoid the name clash with Monad.return *)

  (** {7 Operations on struct types} *)

  val struct_ : 'args typs -> 'args struct_ typ
  val packed_struct : 'args typs -> 'args packed_struct typ
  val struct_elements : [>`members of 'args] typ -> 'args typs
  (* is_packed : we do not need it (probably) *)

  (** {7 Operations on pointer, vector, and array types} *)

  val array_ : 'a typ -> 'tag * int -> ('a, 'tag) array_ typ
    (** Unique tag type must be given for each integer. It is programmer's responsibility. 
        I need a dependent type here... :-( *)
  val pointer : 'a typ -> 'a pointer typ
  val qualified_pointer : 'a typ -> address_space -> 'a pointer typ
  val vector : 'a typ -> ('tag * int) -> ('a, 'tag) vector typ
    (** Same remark as [array_] *)
  val element : [>`container of 'a] typ -> 'a typ
  val array_length : ('a, 'tag) array_ typ -> int
    (** 'tag should have the unique type for the size and therefore must correspond with the result,
        but we have no way to express this property in OCaml... :-( *)
  val address_space : 'a pointer typ -> address_space
  val vector_size : ('a, 'tag) vector typ -> int
    (** Same remark as [array_length] *)

  (** {7 Operations on other types} *)

  val recursive : ('a typ -> 'b typ) -> 'b typ
    (** [recursive f] returns a recusive type defined by [f]. *)
  (* val opaque_type : use [recursive]. *)
  val void : void typ
  val label : label typ

  (** {7 Operations on type handles} *)

  (* external handle_to_type : lltype -> lltypehandle = "llvm_handle_to_type"
     external type_of_handle : lltypehandle -> lltype = "llvm_type_of_handle"
     external refine_type : lltype -> lltype -> unit = "llvm_refine_type"

     I do not see we need to use it, for now.
  *)

  (** {7 and Some more...} *)
      
  val pointer_void : void_pointer typ

  val define_name : modname: string -> string -> 'a typ -> unit

  (* size_ofs require Value.v, so defined in Value. They are lated exposed in Wrap.Type.
     val size_i64_of : 'a typ -> i64 v
     val size_of : 'a typ -> i32 v
  *)
end 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.