Commits

camlspotter committed ba20d05

cleanup

Comments (0)

Files changed (9)

examples/double_phantom.ml

 open Llvm_phantom.Std
 
+let (&) = (@@)
+
 let context = Llvm.global_context () 
 
 include Create(struct let context = context end)
   let opt = true
 end)
 
-let double = build 
-  (func1 "double" ~dump:true i32 ("param", i32)
-     (fun _self -> mul (Const.i32_of_int 2)))
+let double = build & func1 "double" (* function name *)
+  ~dump:true 
+  i32 (* return type *)
+  ("param", i32) (* the parameter *)
+  & fun _self -> mul (Const.i32_of_int 2) (* the code *)
 
 let run_double = ExecutionEngine.run_function1 double
 
           let visited = ty :: visited in
           let s, recs =  
             match classify_type ty with
-            | TypeKind.Integer -> 
+            | Integer -> 
                 "i" ^ string_of_int (integer_bitwidth ty), []
-            | TypeKind.Pointer -> 
+            | Pointer -> 
                 let s, recs = string_of_lltype visited (element_type ty) in
                 s ^ "*", recs
-            | TypeKind.Struct ->
+            | Struct ->
                 let name_recs = List.map (string_of_lltype visited) (Array.to_list (struct_element_types ty)) in
                 let s = "{ " ^ String.concat ", " (List.map fst name_recs) ^ " }" in
                 let recs = List.concat (List.map snd name_recs) in
                 if is_packed ty
                 then "<" ^ s ^ ">", recs
                 else s, recs
-            | TypeKind.Array -> 
+            | Array -> 
                 let s, recs = string_of_lltype visited (element_type ty) in
                 "[" ^ (string_of_int (array_length ty)) ^ " x " ^ s ^ "]", recs
-            | TypeKind.Vector -> 
+            | Vector -> 
                 let s, recs = string_of_lltype visited (element_type ty) in
                 "<" ^ (string_of_int (vector_size ty)) ^ " x " ^ s ^ ">", recs
 (* gone in 3.2
-            | TypeKind.Opaque -> "opaque", []
+            | Opaque -> "opaque", []
 *)
-            | TypeKind.Function -> 
+            | Function -> 
                 let name_recs = List.map (string_of_lltype visited) (Array.to_list (param_types ty)) in
                 let s = String.concat ", " (List.map fst name_recs) in
                 let recs = List.concat (List.map snd name_recs) in
                 let ret, recs_ret = string_of_lltype visited (return_type ty) in
                 ret ^ " (" ^ s ^ ")", recs_ret @ recs
-            | TypeKind.Label -> "label", []
-            | TypeKind.Ppc_fp128 -> "ppc_fp128", []
-            | TypeKind.Fp128 -> "fp128", []
-            | TypeKind.X86fp80 -> "x86_fp80", []
-            | TypeKind.Double -> "double", []
-            | TypeKind.Float -> "float", []
-            | TypeKind.Void -> "void", []
-            | TypeKind.Metadata -> "metadata", []
+            | Label -> "label", []
+            | Ppc_fp128 -> "ppc_fp128", []
+            | Fp128 -> "fp128", []
+            | X86fp80 -> "x86_fp80", []
+            | Double -> "double", []
+            | Float -> "float", []
+            | Void -> "void", []
+            | Metadata -> "metadata", []
             | Half -> assert false (* New in 3.2 *)
           in
           try 
 open Phantom.Open
-(* open Value *)
 
 type ('a, 'final, 'res) t = 
     { k : [`int of int | `llvalue of Llvm.llvalue] list -> 'res; 
 let mem7 st k = k { st with rev = `int 7  :: st.rev }
 let mem8 st k = k { st with rev = `int 8  :: st.rev }
 let mem9 st k = k { st with rev = `int 9  :: st.rev }
-
 module P = Phantom
 open P.Open
 
-module E = Llvm_executionengine
-module T = Llvm_target
-module S = Llvm_scalar_opts
+module ExecutionEngine = Llvm_executionengine.ExecutionEngine
+module DataLayout = Llvm_target.DataLayout
+module Scalar_opts = Llvm_scalar_opts
 
 module Make(A : sig 
   val context : Context.t
 
   let module_ = Llvm.create_module context name
 
-  (* Create the JIT. *)
-  let engine = E.ExecutionEngine.create module_
+  (* Create the JI *)
+  let engine = ExecutionEngine.create module_
 
   let fpm = Llvm.PassManager.create_function module_
     
     if opt then begin
       (* Set up the optimizer pipeline.  Start with registering info about how the
        * target lays out data structures. *)
-      T.DataLayout.add (E.ExecutionEngine.target_data engine) fpm;
+      DataLayout.add (ExecutionEngine.target_data engine) fpm;
       (* Do simple "peephole" optimizations and bit-twiddling optzn. *)
-      S.add_instruction_combination fpm;
+      Scalar_opts.add_instruction_combination fpm;
       (* reassociate expressions. *)
-      S.add_reassociation fpm;
+      Scalar_opts.add_reassociation fpm;
       (* Eliminate Common SubExpressions. *)
-      S.add_gvn fpm;
+      Scalar_opts.add_gvn fpm;
       (* Simplify the control flow graph (deleting unreachable blocks, etc). *)
-      S.add_cfg_simplification fpm;
+      Scalar_opts.add_cfg_simplification fpm;
       ignore (Llvm.PassManager.initialize fpm)
     end
 
   module ExecutionEngine = struct
     let run_function (lv : ('args -> 'b) pointer v) (args : 'args Genvalue.vs) : 'b Genvalue.v = 
       P.unsafe & 
-        E.ExecutionEngine.run_function !<lv (P.List.to_array args) engine
+        ExecutionEngine.run_function !<lv (P.List.to_array args) engine
     let run_function0 lv () = run_function lv P.c0
     let run_function1 lv a0 = run_function lv (P.c1 a0)
     let run_function2 lv a0 a1 = run_function lv (P.c2 a0 a1)
 (* llvm type algebra *)
 
 open Llvm
-(* open Spotlib.Spot *)
-
-module P = Phantom
-(* open P.Open *)
 
 (** phantom *)
-type 'a typ = ('a, lltype) P.t 
-type 'a typs = ('a, lltype) P.ts
+type 'a typ = ('a, lltype) Phantom.t 
+type 'a typs = ('a, lltype) Phantom.ts
 
 (** descriptors *)
 
 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]
+type ('a, 'sizetag) array_ = [`array of 'a * 'sizetag | `container of 'a]
 type 'a pointer = [`pointer of 'a | `container of 'a]
 type ('a, 'sizetag) vector = [`vector of 'a * 'sizetag | `container of 'a]
 type label
 (* llvm type algebra *)
 
 open Llvm
-(* open Type *)
 
 open Spotlib.Spot
 module P = Phantom
   (** descriptors *)
   
   type void = unit
-  type i1 = [`int | `i1]
-  type i8 = [`int | `i8]
+  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 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]
 
   (** {7 Operations on integer types} *)
 
-  val i1 : i1 typ
-  val i8 : i8 typ
+  val i1  : i1  typ
+  val i8  : i8  typ
   val i16 : i16 typ
   val i32 : i32 typ
   val i64 : i64 typ
 
   (** {7 Operations on real types} *)
 
-  val float : float_ typ
-  val double : double typ
-  val x86fp80 : x86fp80 typ
-  val fp128 : fp128 typ
+  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} *)

lib/value_intf.ml

 open Type
 open Spotlib.Spot
-(* open Spotlib.Spot.Phantom.Open *)
 
 module type S0 = sig
   (** phantom *)
-(* open Spotlib.Spot *)
-
 (* We require [initialize_native_target] to make the engine real JIT.
    Otherwise it fails to create a JIT and fall back to an interpreter,
    which fails to find external symbols
 *)
-let _ = Llvm_executionengine.initialize_native_target ()
+let _bool = Llvm_executionengine.initialize_native_target ()
+(* CR jfuruse: check the returned bool *)
 
 module Create(A : sig 
   val context : Context.t