1 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_bitreader.cmxa llvm_bitwriter.cmxa %s -o %t
3 * RUN: llvm-dis < %t.bc | grep caml_int_ty
6 (* Note that this takes a moment to link, so it's best to keep the number of
7 individual tests low. *)
9 let context = Llvm.global_context ()
11 let test x = if not x then exit 1 else ()
14 let fn = Sys.argv.(1) in
15 let m = Llvm.create_module context "ocaml_test_module" in
17 ignore (Llvm.define_type_name "caml_int_ty" (Llvm.i32_type context) m);
19 test (Llvm_bitwriter.write_bitcode_file m fn);
21 Llvm.dispose_module m;
25 let mb = Llvm.MemoryBuffer.of_file fn in
27 let m = Llvm_bitreader.parse_bitcode context mb in
30 Llvm.MemoryBuffer.dispose mb;
35 (* MemoryBuffer.of_file *)
37 let mb = Llvm.MemoryBuffer.of_file (fn ^ ".bogus") in
38 Llvm.MemoryBuffer.dispose mb;
40 with Llvm.IoError _ ->
46 let mb = Llvm.MemoryBuffer.of_file fn in
48 Llvm_bitreader.get_module context mb
50 Llvm.MemoryBuffer.dispose mb;
56 (* corrupt the bitcode *)
57 let fn = fn ^ ".txt" in
58 begin let oc = open_out fn in
59 output_string oc "not a bitcode file\n";
63 (* test get_module exceptions *)
66 let mb = Llvm.MemoryBuffer.of_file fn in
68 Llvm_bitreader.get_module context mb
70 Llvm.MemoryBuffer.dispose mb;
73 Llvm.dispose_module m;
75 with Llvm_bitreader.Error _ ->