(* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_analysis.cmxa llvm_bitwriter.cmxa %s -o %t
* RUN: %t %t.bc
* RUN: llvm-dis < %t.bc > %t.ll
* XFAIL: vg_leak
*)
(* Note: It takes several seconds for ocamlopt to link an executable with
libLLVMCore.a, so it's better to write a big test than a bunch of
little ones. *)
open Llvm
open Llvm_bitwriter
(* Tiny unit test framework - really just to help find which line is busted *)
let exit_status = ref 0
let suite_name = ref ""
let group_name = ref ""
let case_num = ref 0
let print_checkpoints = false
let context = global_context ()
let i1_type = Llvm.i1_type context
let i8_type = Llvm.i8_type context
let i16_type = Llvm.i16_type context
let i32_type = Llvm.i32_type context
let i64_type = Llvm.i64_type context
let void_type = Llvm.void_type context
let float_type = Llvm.float_type context
let double_type = Llvm.double_type context
let fp128_type = Llvm.fp128_type context
let group name =
group_name := !suite_name ^ "/" ^ name;
case_num := 0;
if print_checkpoints then
prerr_endline (" " ^ name ^ "...")
let insist cond =
incr case_num;
if not cond then
exit_status := 10;
match print_checkpoints, cond with
| false, true -> ()
| false, false ->
prerr_endline ("FAILED: " ^ !suite_name ^ "/" ^ !group_name ^ " #" ^ (string_of_int !case_num))
| true, true ->
prerr_endline (" " ^ (string_of_int !case_num))
| true, false ->
prerr_endline (" " ^ (string_of_int !case_num) ^ " FAIL")
let suite name f =
suite_name := name;
if print_checkpoints then
prerr_endline (name ^ ":");
f ()
(*===-- Fixture -----------------------------------------------------------===*)
let filename = Sys.argv.(1)
let m = create_module context filename
(*===-- Target ------------------------------------------------------------===*)
let test_target () =
begin group "triple";
(* RUN: grep "i686-apple-darwin8" < %t.ll
*)
let trip = "i686-apple-darwin8" in
set_target_triple trip m;
insist (trip = target_triple m)
end;
begin group "layout";
(* RUN: grep "bogus" < %t.ll
*)
let layout = "bogus" in
set_data_layout layout m;
insist (layout = data_layout m)
end
(*===-- Constants ---------------------------------------------------------===*)
let test_constants () =
(* RUN: grep "const_int.*i32.*-1" < %t.ll
*)
group "int";
let c = const_int i32_type (-1) in
ignore (define_global "const_int" c m);
insist (i32_type = type_of c);
insist (is_constant c);
(* RUN: grep "const_sext_int.*i64.*-1" < %t.ll
*)
group "sext int";
let c = const_int i64_type (-1) in