d2cace92643920b0bcd213fcf9c25fc924bc031b
[oota-llvm.git] / test / Bindings / Ocaml / target.ml
1 (* RUN: rm -rf %t.builddir
2  * RUN: mkdir -p %t.builddir
3  * RUN: cp %s %t.builddir
4  * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_target.cmxa %t.builddir/target.ml -o %t
5  * RUN: %t %t.bc
6  * XFAIL: vg_leak
7  *)
8
9 (* Note: It takes several seconds for ocamlopt to link an executable with
10          libLLVMCore.a, so it's better to write a big test than a bunch of
11          little ones. *)
12
13 open Llvm
14 open Llvm_target
15
16
17 let context = global_context ()
18 let i32_type = Llvm.i32_type context
19 let i64_type = Llvm.i64_type context
20
21 (* Tiny unit test framework - really just to help find which line is busted *)
22 let print_checkpoints = false
23
24 let suite name f =
25   if print_checkpoints then
26     prerr_endline (name ^ ":");
27   f ()
28
29
30 (*===-- Fixture -----------------------------------------------------------===*)
31
32 let filename = Sys.argv.(1)
33 let m = create_module context filename
34
35
36 (*===-- Target Data -------------------------------------------------------===*)
37
38 let test_target_data () =
39   let td = DataLayout.create (target_triple m) in
40   let sty = struct_type context [| i32_type; i64_type |] in
41   
42   ignore (DataLayout.as_string td);
43   ignore (byte_order td);
44   ignore (pointer_size td);
45   ignore (intptr_type td);
46   ignore (size_in_bits td sty);
47   ignore (store_size td sty);
48   ignore (abi_size td sty);
49   ignore (stack_align td sty);
50   ignore (preferred_align td sty);
51   ignore (preferred_align_of_global td (declare_global sty "g" m));
52   ignore (element_at_offset td sty (Int64.of_int 1));
53   ignore (offset_of_element td sty 1);
54   
55   DataLayout.dispose td
56
57
58 (*===-- Driver ------------------------------------------------------------===*)
59
60 let _ =
61   suite "target data" test_target_data;
62   dispose_module m