5e3ab4bf93547c8979f7894177fc3920b18f6f09
[oota-llvm.git] / test / Bindings / Ocaml / target.ml
1 (* RUN: %ocamlopt -warn-error A llvm.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_target
12
13
14 let context = global_context ()
15 let i32_type = Llvm.i32_type context
16 let i64_type = Llvm.i64_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 (*===-- Target Data -------------------------------------------------------===*)
34
35 let test_target_data () =
36   let td = TargetData.create (target_triple m) in
37   let sty = struct_type context [| i32_type; i64_type |] in
38   
39   ignore (TargetData.as_string td);
40   ignore (TargetData.invalidate_struct_layout td sty);
41   ignore (byte_order td);
42   ignore (pointer_size td);
43   ignore (intptr_type td);
44   ignore (size_in_bits td sty);
45   ignore (store_size td sty);
46   ignore (abi_size td sty);
47   ignore (stack_align td sty);
48   ignore (preferred_align td sty);
49   ignore (preferred_align_of_global td (declare_global sty "g" m));
50   ignore (element_at_offset td sty (Int64.of_int 1));
51   ignore (offset_of_element td sty 1);
52   
53   TargetData.dispose td
54
55
56 (*===-- Driver ------------------------------------------------------------===*)
57
58 let _ =
59   suite "target data" test_target_data;
60   dispose_module m