[InstCombine] Signed saturation patterns
[llvm-complete.git] / test / Bindings / OCaml / target.ml
blob900668147b7479b7f88e4597c4cb1216467bb483
1 (* RUN: rm -rf %t && mkdir -p %t && cp %s %t/target.ml
2 * RUN: %ocamlc -g -w +A -package llvm.target -package llvm.all_backends -linkpkg %t/target.ml -o %t/executable
3 * RUN: %ocamlopt -g -w +A -package llvm.target -package llvm.all_backends -linkpkg %t/target.ml -o %t/executable
4 * RUN: %t/executable %t/bitcode.bc
5 * XFAIL: vg_leak
6 *)
8 (* Note: It takes several seconds for ocamlopt to link an executable with
9 libLLVMCore.a, so it's better to write a big test than a bunch of
10 little ones. *)
12 open Llvm
13 open Llvm_target
15 let () = Llvm_all_backends.initialize ()
17 let context = global_context ()
18 let i32_type = Llvm.i32_type context
19 let i64_type = Llvm.i64_type context
21 (* Tiny unit test framework - really just to help find which line is busted *)
22 let print_checkpoints = false
24 let _ =
25 Printexc.record_backtrace true
27 let assert_equal a b =
28 if a <> b then failwith "assert_equal"
31 (*===-- Fixture -----------------------------------------------------------===*)
33 let filename = Sys.argv.(1)
34 let m = create_module context filename
36 let target = Target.by_triple (Target.default_triple ())
38 let machine = TargetMachine.create (Target.default_triple ()) target
40 (*===-- Data Layout -------------------------------------------------------===*)
42 let test_target_data () =
43 let module DL = DataLayout in
44 let layout = "e-p:32:32-f64:32:64-v64:32:64-v128:32:128-n32-S32" in
45 let dl = DL.of_string layout in
46 let sty = struct_type context [| i32_type; i64_type |] in
48 assert_equal (DL.as_string dl) layout;
49 assert_equal (DL.byte_order dl) Endian.Little;
50 assert_equal (DL.pointer_size dl) 4;
51 assert_equal (DL.intptr_type context dl) i32_type;
52 assert_equal (DL.qualified_pointer_size 0 dl) 4;
53 assert_equal (DL.qualified_intptr_type context 0 dl) i32_type;
54 assert_equal (DL.size_in_bits sty dl) (Int64.of_int 96);
55 assert_equal (DL.store_size sty dl) (Int64.of_int 12);
56 assert_equal (DL.abi_size sty dl) (Int64.of_int 12);
57 assert_equal (DL.stack_align sty dl) 4;
58 assert_equal (DL.preferred_align sty dl) 8;
59 assert_equal (DL.preferred_align_of_global (declare_global sty "g" m) dl) 8;
60 assert_equal (DL.element_at_offset sty (Int64.of_int 1) dl) 0;
61 assert_equal (DL.offset_of_element sty 1 dl) (Int64.of_int 4)
64 (*===-- Target ------------------------------------------------------------===*)
66 let test_target () =
67 let module T = Target in
68 ignore (T.succ target);
69 ignore (T.name target);
70 ignore (T.description target);
71 ignore (T.has_jit target);
72 ignore (T.has_target_machine target);
73 ignore (T.has_asm_backend target)
76 (*===-- Target Machine ----------------------------------------------------===*)
78 let test_target_machine () =
79 let module TM = TargetMachine in
80 assert_equal (TM.target machine) target;
81 assert_equal (TM.triple machine) (Target.default_triple ());
82 assert_equal (TM.cpu machine) "";
83 assert_equal (TM.features machine) "";
84 ignore (TM.data_layout machine);
85 TM.set_verbose_asm true machine;
86 let pm = PassManager.create () in
87 TM.add_analysis_passes pm machine
90 (*===-- Code Emission -----------------------------------------------------===*)
92 let test_code_emission () =
93 TargetMachine.emit_to_file m CodeGenFileType.ObjectFile filename machine;
94 try
95 TargetMachine.emit_to_file m CodeGenFileType.ObjectFile
96 "/nonexistent/file" machine;
97 failwith "must raise"
98 with Llvm_target.Error _ ->
99 ();
101 let buf = TargetMachine.emit_to_memory_buffer m CodeGenFileType.ObjectFile
102 machine in
103 Llvm.MemoryBuffer.dispose buf
106 (*===-- Driver ------------------------------------------------------------===*)
108 let _ =
109 test_target_data ();
110 test_target ();
111 test_target_machine ();
112 test_code_emission ();
113 dispose_module m