-(* RUN: %ocamlc -warn-error A llvm.cma llvm_executionengine.cma %s -o %t
- * RUN: ./%t %t.bc
+(* RUN: rm -rf %t.builddir
+ * RUN: mkdir -p %t.builddir
+ * RUN: cp %s %t.builddir
+ * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_target.cmxa llvm_executionengine.cmxa %t.builddir/executionengine.ml -o %t
+ * RUN: %t
+ * XFAIL: vg_leak
*)
open Llvm
open Llvm_executionengine
+open Llvm_target
(* Note that this takes a moment to link, so it's best to keep the number of
individual tests low. *)
+let context = global_context ()
+let i8_type = Llvm.i8_type context
+let i32_type = Llvm.i32_type context
+let i64_type = Llvm.i64_type context
+let double_type = Llvm.double_type context
+
let bomb msg =
prerr_endline msg;
exit 2
define_function "main" (function_type i32_type [| i32_type;
str_arr_type;
str_arr_type |]) m in
- let b = builder_at_end (entry_block fn) in
+ let b = builder_at_end (global_context ()) (entry_block fn) in
ignore (build_ret (const_int i32_type retval) b);
fn
let define_plus m =
let fn = define_function "plus" (function_type i32_type [| i32_type;
i32_type |]) m in
- let b = builder_at_end (entry_block fn) in
+ let b = builder_at_end (global_context ()) (entry_block fn) in
let add = build_add (param fn 0) (param fn 1) "sum" b in
ignore (build_ret add b)
let test_executionengine () =
(* create *)
- let m = create_module "test_module" in
+ let m = create_module (global_context ()) "test_module" in
let main = define_main_fn m 42 in
- let m2 = create_module "test_module2" in
+ let m2 = create_module (global_context ()) "test_module2" in
define_plus m2;
- let ee = ExecutionEngine.create (ModuleProvider.create m) in
- let mp2 = ModuleProvider.create m2 in
- ExecutionEngine.add_module_provider mp2 ee;
+ let ee = ExecutionEngine.create m in
+ ExecutionEngine.add_module m2 ee;
(* run_static_ctors *)
ExecutionEngine.run_static_ctors ee;
ee in
if 4 != GenericValue.as_int res then bomb "plus did not work";
- (* remove_module_provider *)
- Llvm.dispose_module (ExecutionEngine.remove_module_provider mp2 ee);
+ (* remove_module *)
+ Llvm.dispose_module (ExecutionEngine.remove_module m2 ee);
(* run_static_dtors *)
ExecutionEngine.run_static_dtors ee;
+
+ (* Show that the data layout binding links and runs.*)
+ let dl = ExecutionEngine.data_layout ee in
+
+ (* Demonstrate that a garbage pointer wasn't returned. *)
+ let ty = DataLayout.intptr_type context dl in
+ if ty != i32_type && ty != i64_type then bomb "target_data did not work";
(* dispose *)
ExecutionEngine.dispose ee