Allow passing around LLVMContext in ocaml.
[oota-llvm.git] / test / Bindings / Ocaml / scalar_opts.ml
1 (* RUN: %ocamlc -warn-error A llvm.cma llvm_scalar_opts.cma llvm_target.cma %s -o %t 2> /dev/null
2  *)
3
4 (* Note: It takes several seconds for ocamlc to link an executable with
5          libLLVMCore.a, so it's better to write a big test than a bunch of
6          little ones. *)
7
8 open Llvm
9 open Llvm_scalar_opts
10 open Llvm_target
11
12
13 (* Tiny unit test framework - really just to help find which line is busted *)
14 let suite name f =
15   prerr_endline (name ^ ":");
16   f ()
17
18
19 (*===-- Fixture -----------------------------------------------------------===*)
20
21 let filename = Sys.argv.(1)
22 let m = create_module (global_context ()) filename
23 let mp = ModuleProvider.create m
24
25
26 (*===-- Transforms --------------------------------------------------------===*)
27
28 let test_transforms () =
29   let (++) x f = ignore (f x); x in
30
31   let fty = function_type void_type [| |] in
32   let fn = define_function "fn" fty m in
33   ignore (build_ret_void (builder_at_end (global_context ()) (entry_block fn)));
34   
35   let td = TargetData.create (target_triple m) in
36   
37   ignore (PassManager.create_function mp
38            ++ TargetData.add td
39            ++ add_instruction_combining
40            ++ add_reassociation
41            ++ add_gvn
42            ++ add_cfg_simplification
43            ++ add_constant_propagation
44            ++ PassManager.initialize
45            ++ PassManager.run_function fn
46            ++ PassManager.finalize
47            ++ PassManager.dispose);
48   
49   TargetData.dispose td
50
51
52 (*===-- Driver ------------------------------------------------------------===*)
53
54 let _ =
55   suite "transforms" test_transforms;
56   ModuleProvider.dispose mp