Source

ocaml-llvm-phantom / lib / value_intf.ml

open Type
open Spotlib.Spot

module type S0 = sig
  (** phantom *)
  type 'a v = ('a, Llvm.llvalue) Phantom.t
  type 'a vs = ('a, Llvm.llvalue) Phantom.ts

  val unsafe_annotate : Llvm.llvalue -> 'ty typ -> 'ty v 
    (** annotate a type, but unsafe *)

  val dump : 'ty v -> unit
  val type_of : 'ty v -> 'ty typ
  val typs_of : 'tys vs -> 'tys typs
  val set_name : string -> 'ty v -> unit
  val name : 'ty v -> string
  val function_params : ('args -> 'ret) pointer v -> 'args vs
end

module type S = sig
  include S0

  type ('a, 'final, 'res) gep_t (* equal to Gep.t *)

  module Const : sig
    val int : int -> [`int] v
    val nativeint : nativeint -> [`int] v
    val i32 : int32 -> i32 v
    val i32_of_int : int -> i32 v
    val i32_0 : i32 v
    val i32_1 : i32 v
    val i64 : Int64.t -> i64 v
    val double : float -> double v
    val bool : bool -> i1 v
    val bitcast : 'a v -> 'ty typ -> 'ty v
    val intcast : [>`int] v -> ([>`int] as 'a) typ -> 'a v
    val ptrtoint : 'a pointer v -> ([>`int] as 'a) typ -> 'a v
    val null : 'ty typ -> 'ty v
      (* [null ty] returns a null value of type [ty]. 
         Note that it can take non pointer type. 
         It does NOT create a null pointer for [ty pointer]! *)
    val unsafe_gep : 'a pointer v -> int list -> 'unsafe pointer v

    val gep : 'a pointer v -> (('a pointer, 'final, 'final pointer v) gep_t -> 'b) -> 'b

    val offset_of : 'ty typ -> int list -> i32 v (* CR jfuruse: Only for 32bit arch! *)
  end
  
  module Analysis : sig 
    val assert_valid_function : ('a -> 'b) pointer v -> unit 
  end

  val size_i64_of : 'a typ -> i64 v 
  val size_of : 'a typ -> i32 v 
end