Source

ocaml-llvm-phantom / examples / double_phantom.ml

Full commit
open Llvm_phantom.Std

let (&) = (@@)

let context = Llvm.global_context () 

(* We only use one context, so just include it and available globally. *)
include Create(struct let context = context end)

open Type
open Value

(* We only use one module, so just include it and available globally. *)
include CreateModule(struct
  let name = "mymodule"
  let opt = true
end)

let double = build & func1 "double" (* function name *)
  ~dump:true 
  i32 (* return type *)
  ("param", i32) (* the parameter *)
  & fun _self x -> x *! (Const.i32_of_int 2) (* the code *)

let run_double = ExecutionEngine.run_function1 double

let run_double_ocaml x = Genvalue.as_int (run_double (Genvalue.of_int i32 x))

let () = Printf.eprintf "double(21)=%d\n" (run_double_ocaml 21)