8f6802da76559a5702f565791e8f1e3f2376d27b
[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 let context = global_context ()
13 let void_type = Llvm.void_type context
14
15 (* Tiny unit test framework - really just to help find which line is busted *)
16 let suite name f =
17   prerr_endline (name ^ ":");
18   f ()
19
20
21 (*===-- Fixture -----------------------------------------------------------===*)
22
23 let filename = Sys.argv.(1)
24 let m = create_module context filename
25 let mp = ModuleProvider.create m
26
27
28 (*===-- Transforms --------------------------------------------------------===*)
29
30 let test_transforms () =
31   let (++) x f = ignore (f x); x in
32
33   let fty = function_type void_type [| |] in
34   let fn = define_function "fn" fty m in
35   ignore (build_ret_void (builder_at_end context (entry_block fn)));
36   
37   let td = TargetData.create (target_triple m) in
38   
39   ignore (PassManager.create_function mp
40            ++ TargetData.add td
41            ++ add_instruction_combining
42            ++ add_reassociation
43            ++ add_gvn
44            ++ add_cfg_simplification
45            ++ add_constant_propagation
46            ++ PassManager.initialize
47            ++ PassManager.run_function fn
48            ++ PassManager.finalize
49            ++ PassManager.dispose);
50   
51   TargetData.dispose td
52
53
54 (*===-- Driver ------------------------------------------------------------===*)
55
56 let _ =
57   suite "transforms" test_transforms;
58   ModuleProvider.dispose mp