Bindings for the verifier.
[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   match verify_module m with
27     Some msg -> bomb "valid module failed verification!"
28   | None -> ();
29   
30   if not (verify_function fn) then bomb "valid function failed verification!";
31   
32   
33   (* Test that invalid constructs do not verify.
34      A basic block can contain only one terminator instruction. *)
35   ignore (build_ret_void at_entry);
36   
37   match verify_module m with
38     Some msg -> ()
39   | None -> bomb "invalid module passed verification!";
40   
41   if verify_function fn then bomb "invalid function passed verification!";
42   
43   
44   dispose_module m
45   
46   (* Don't bother to test assert_valid_{module,function}. *)