[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / test / Bindings / OCaml / irreader.ml
blob7d8e4a97e38dc638dd219de60d0783a208fa5e18
1 (* RUN: rm -rf %t && mkdir -p %t && cp %s %t/irreader.ml
2 * RUN: %ocamlc -g -w +A -package llvm.irreader -linkpkg %t/irreader.ml -o %t/executable
3 * RUN: %t/executable
4 * RUN: %ocamlopt -g -w +A -package llvm.irreader -linkpkg %t/irreader.ml -o %t/executable
5 * RUN: %t/executable
6 * XFAIL: vg_leak
7 *)
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. *)
13 open Llvm
14 open Llvm_irreader
16 let context = global_context ()
18 (* Tiny unit test framework - really just to help find which line is busted *)
19 let print_checkpoints = false
21 let suite name f =
22 if print_checkpoints then
23 prerr_endline (name ^ ":");
24 f ()
26 let _ =
27 Printexc.record_backtrace true
29 let insist cond =
30 if not cond then failwith "insist"
33 (*===-- IR Reader ---------------------------------------------------------===*)
35 let test_irreader () =
36 begin
37 let buf = MemoryBuffer.of_string "@foo = global i32 42" in
38 let m = parse_ir context buf in
39 match lookup_global "foo" m with
40 | Some foo ->
41 insist ((global_initializer foo) = (Some (const_int (i32_type context) 42)))
42 | None ->
43 failwith "global"
44 end;
46 begin
47 let buf = MemoryBuffer.of_string "@foo = global garble" in
48 try
49 ignore (parse_ir context buf);
50 failwith "parsed"
51 with Llvm_irreader.Error _ ->
53 end
56 (*===-- Driver ------------------------------------------------------------===*)
58 let _ =
59 suite "irreader" test_irreader