Commits

camlspotter  committed e916202

null fix and void return fix

  • Participants
  • Parent commits 2d19bb0

Comments (0)

Files changed (3)

       (f : ('args -> 'ret) pointer v)
       (args : 'args vs)
       : 'ret v m = 
+    (* If its return type is void, we erase the name *)
+    let name = 
+      match classify (function_return (element (type_of f))) with
+      | Llvm.TypeKind.Void -> ""
+      | _ -> name
+    in
     unsafeM (Llvm.build_call !=<f (Value.to_array args) name)
 
   let call_va_args
       (args : 'args vs)
       (va_args : unknown v list)
       : 'ret v m = 
+    let name = 
+      match classify (function_return (element (type_of f))) with
+      | Llvm.TypeKind.Void -> ""
+      | _ -> name
+    in
     unsafeM (Llvm.build_call !=<f (Array.of_list (Value.to_list args 
                                             @ List.map (!=<) va_args)) name)
 
 
   let exec =
     let cntr = ref 0 in
-    fun (v : 'a v m) ->
+    fun (v : unit m) ->
       incr cntr;
       let name = Printf.sprintf "lbuilder.exec%d" !cntr in
       let f : (unit -> void) pointer v =
       in
 
       (* Create a new basic block to start insertion into. *)
-      perform
+      Monad.run (perform
         let bb = Block.append ~name:"entry" f in
         Block.position_at_end bb;
-  
-        _v <-- v; (* create the code *)
-  
-        ret_void;
-        (* Optimize the function *)
-        \ Module.PassManager.run_function_if_opt f;
-        \ Analysis.assert_valid_function f;
-        \ Format.eprintf "Now running %s@." name;
-        \ ignore (Module.ExecutionEngine.run_function f [||]);
-        \ Format.eprintf "Done running %s@." name;
-        return ()
+        v; (* create the code *)
+        ret_void);
+      (* Optimize the function *)
+      Module.PassManager.run_function_if_opt f;
+      Analysis.assert_valid_function f;
+      Format.eprintf "Now running %s@." name;
+      ignore (Module.ExecutionEngine.run_function f [||]);
+      Format.eprintf "Done running %s@." name;
 end

File lbuilder_intf.ml

   val return_void : void v m 
     (** for functions returning void *)
   val if_then_else : bool v m -> 'a v m -> 'a v m -> 'a v m
+
+  val exec : unit m -> unit
 end

File lvalue_intf.ml

     val bitcast : 'a v -> 'ty typ -> 'ty v
     val intcast : 'a v -> 'ty typ -> 'ty v
     val ptrtoint : 'a pointer v -> 'ty typ -> 'ty v
-    val null : 'ty typ -> 'ty pointer v
+    val null : 'ty typ -> 'ty v
+      (* Note that it can take non pointer type! *)
     val unsafe_gep : 'a pointer v -> int list -> 'unsafe pointer v
   end