Add support for use to ocaml.
[oota-llvm.git] / test / Bindings / Ocaml / target.ml
1 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_target.cmxa %s -o %t
2  *)
3
4 (* Note: It takes several seconds for ocamlopt 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_target
10
11 let context = global_context ()
12 let i32_type = Llvm.i32_type context
13 let i64_type = Llvm.i64_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
26
27 (*===-- Target Data -------------------------------------------------------===*)
28
29 let test_target_data () =
30   let td = TargetData.create (target_triple m) in
31   let sty = struct_type context [| i32_type; i64_type |] in
32   
33   ignore (TargetData.as_string td);
34   ignore (TargetData.invalidate_struct_layout td sty);
35   ignore (byte_order td);
36   ignore (pointer_size td);
37   ignore (intptr_type td);
38   ignore (size_in_bits td sty);
39   ignore (store_size td sty);
40   ignore (abi_size td sty);
41   ignore (stack_align td sty);
42   ignore (preferred_align td sty);
43   ignore (preferred_align_of_global td (declare_global sty "g" m));
44   ignore (element_at_offset td sty (Int64.of_int 1));
45   ignore (offset_of_element td sty 1);
46   
47   TargetData.dispose td
48
49
50 (*===-- Driver ------------------------------------------------------------===*)
51
52 let _ =
53   suite "target data" test_target_data;
54   dispose_module m