8d8a1df5b7d1389048df942477a7e4b8598b5b4d
[oota-llvm.git] / test / Bindings / Ocaml / analysis.ml
1 (* RUN: %ocamlc llvm.cma llvm_analysis.cma %s -o %t
2  * RUN: ./%t %t.bc
3  *)
4
5 open Llvm
6 open Llvm_analysis
7
8 (* Note that this takes a moment to link, so it's best to keep the number of
9    individual tests low. *)
10
11 let test x = if not x then exit 1 else ()
12
13 let bomb msg =
14   prerr_endline msg;
15   exit 2
16
17 let _ =
18   let fty = function_type void_type [| |] in
19   let m = create_module "valid_m" in
20   let fn = define_function "valid_fn" fty m in
21   let at_entry = builder_at_end (entry_block fn) in
22   ignore (build_ret_void at_entry);
23   
24   
25   (* Test that valid constructs verify. *)
26   begin match verify_module m with
27     Some msg -> bomb "valid module failed verification!"
28   | None -> ()
29   end;
30   
31   if not (verify_function fn) then bomb "valid function failed verification!";
32   
33   
34   (* Test that invalid constructs do not verify.
35      A basic block can contain only one terminator instruction. *)
36   ignore (build_ret_void at_entry);
37   
38   begin match verify_module m with
39     Some msg -> ()
40   | None -> bomb "invalid module passed verification!"
41   end;
42   
43   if verify_function fn then bomb "invalid function passed verification!";
44   
45   
46   dispose_module m
47   
48   (* Don't bother to test assert_valid_{module,function}. *)