Home | History | Annotate | Download | only in Ocaml
      1 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_ipo.cmxa llvm_target.cmxa %s -o %t
      2  * RUN: %t %t.bc
      3  * XFAIL: vg_leak
      4  *)
      5 
      6 (* Note: It takes several seconds for ocamlopt to link an executable with
      7          libLLVMCore.a, so it's better to write a big test than a bunch of
      8          little ones. *)
      9 
     10 open Llvm
     11 open Llvm_ipo
     12 open Llvm_target
     13 
     14 let context = global_context ()
     15 let void_type = Llvm.void_type context
     16 let i8_type = Llvm.i8_type context
     17 
     18 (* Tiny unit test framework - really just to help find which line is busted *)
     19 let print_checkpoints = false
     20 
     21 let suite name f =
     22   if print_checkpoints then
     23     prerr_endline (name ^ ":");
     24   f ()
     25 
     26 
     27 (*===-- Fixture -----------------------------------------------------------===*)
     28 
     29 let filename = Sys.argv.(1)
     30 let m = create_module context filename
     31 
     32 
     33 (*===-- Transforms --------------------------------------------------------===*)
     34 
     35 let test_transforms () =
     36   let (++) x f = ignore (f x); x in
     37 
     38   let fty = function_type i8_type [| |] in
     39   let fn = define_function "fn" fty m in
     40   let fn2 = define_function "fn2" fty m in begin
     41       ignore (build_ret (const_int i8_type 4) (builder_at_end context (entry_block fn)));
     42       let b = builder_at_end context  (entry_block fn2) in
     43       ignore (build_ret (build_call fn [| |] "" b) b);
     44   end;
     45 
     46   let td = TargetData.create (target_triple m) in
     47   
     48   ignore (PassManager.create ()
     49            ++ TargetData.add td
     50            ++ add_argument_promotion
     51            ++ add_constant_merge
     52            ++ add_dead_arg_elimination
     53            ++ add_function_attrs
     54            ++ add_function_inlining
     55            ++ add_global_dce
     56            ++ add_global_optimizer
     57            ++ add_ipc_propagation
     58            ++ add_prune_eh
     59            ++ add_ipsccp
     60            ++ add_internalize
     61            ++ add_strip_dead_prototypes
     62            ++ add_strip_symbols
     63            ++ PassManager.run_module m
     64            ++ PassManager.dispose);
     65 
     66   TargetData.dispose td
     67 
     68 
     69 (*===-- Driver ------------------------------------------------------------===*)
     70 
     71 let _ =
     72   suite "transforms" test_transforms;
     73   dispose_module m
     74