1 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_bitreader.cmxa llvm_bitwriter.cmxa %s -o %t
3 * RUN: llvm-dis < %t.bc
7 (* Note that this takes a moment to link, so it's best to keep the number of
8 individual tests low. *)
10 let context = Llvm.global_context
()
12 let test x
= if not x
then exit
1 else ()
15 let fn = Sys.argv
.(1) in
16 let m = Llvm.create_module
context "ocaml_test_module" in
18 test (Llvm_bitwriter.write_bitcode_file
m fn);
20 Llvm.dispose_module
m;
24 let mb = Llvm.MemoryBuffer.of_file
fn in
26 let m = Llvm_bitreader.parse_bitcode
context mb in
29 Llvm.MemoryBuffer.dispose
mb;
34 (* MemoryBuffer.of_file *)
36 let mb = Llvm.MemoryBuffer.of_file
(fn ^
".bogus") in
37 Llvm.MemoryBuffer.dispose
mb;
39 with Llvm.IoError
_ ->
45 let mb = Llvm.MemoryBuffer.of_file
fn in
47 Llvm_bitreader.get_module
context mb
49 Llvm.MemoryBuffer.dispose
mb;
55 (* corrupt the bitcode *)
56 let fn = fn ^
".txt" in
57 begin let oc = open_out
fn in
58 output_string
oc "not a bitcode file\n";
62 (* test get_module exceptions *)
65 let mb = Llvm.MemoryBuffer.of_file
fn in
67 Llvm_bitreader.get_module
context mb
69 Llvm.MemoryBuffer.dispose
mb;
72 Llvm.dispose_module
m;
74 with Llvm_bitreader.Error
_ ->