Source

TyLLVM / src / LLVM_types.ml

type _ f =
  | Ret : 'a t -> 'a t f
  | App : 'a t * 'b f -> ('a * 'b) f

and _ t =
  | Int : int -> int t
  | Array : int * 'a t -> 'a value list t
  | Pointer : 'a t -> 'a t t
  | FunctionPointer : 'a f -> 'a f t

and 'a value = 'a t * string

type 'a either =
  | Value of 'a value
  | Type of 'a t

let rec to_string : type a. a t -> string = fun data ->
  let rec aux : type a. string -> a f -> string = fun acc -> function
    | Ret t -> to_string t ^ " @(" ^ acc ^ ") *"
    | App (t, f) -> aux (acc ^ ", " ^ to_string t) f (* FALSE ! Also before *)
  in
  match data with
    | Int i -> "i" ^ string_of_int i
    | Array (i, t) ->
        "[" ^ string_of_int i ^ " x " ^ to_string t ^ "]"
    | Pointer t -> to_string t ^ "*"
    | FunctionPointer f -> aux "" f

let value_to_string (t, value) = to_string t ^ " " ^ value

let int x value = (Int x, string_of_int value)
let array n t value =
  (Array (n, t), "[" ^ String.concat ", " (List.map value_to_string value) ^ "]")
let pointer t value = (Pointer t, to_string value)