1 (* RUN: rm -rf %t && mkdir -p %t && cp %s %t/bitreader.ml
2 * RUN: %ocamlc -g -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %t/bitreader.ml -o %t/executable
3 * RUN: %t/executable %t/bitcode.bc
4 * RUN: %ocamlopt -g -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %t/bitreader.ml -o %t/executable
5 * RUN: %t/executable %t/bitcode.bc
6 * RUN: llvm-dis < %t/bitcode.bc
10 (* Note that this takes a moment to link, so it's best to keep the number of
11 individual tests low. *)
13 let context = Llvm.global_context
()
15 let diagnostic_handler _
= ()
17 let test x
= if not x
then exit
1 else ()
20 Llvm.set_diagnostic_handler
context (Some
diagnostic_handler);
22 let fn = Sys.argv
.(1) in
23 let m = Llvm.create_module
context "ocaml_test_module" in
25 test (Llvm_bitwriter.write_bitcode_file
m fn);
27 Llvm.dispose_module
m;
31 let mb = Llvm.MemoryBuffer.of_file
fn in
33 let m = Llvm_bitreader.parse_bitcode
context mb in
36 Llvm.MemoryBuffer.dispose
mb;
41 (* MemoryBuffer.of_file *)
43 let mb = Llvm.MemoryBuffer.of_file
(fn ^
".bogus") in
44 Llvm.MemoryBuffer.dispose
mb;
46 with Llvm.IoError
_ ->
52 let mb = Llvm.MemoryBuffer.of_file
fn in
54 Llvm_bitreader.get_module
context mb
56 Llvm.MemoryBuffer.dispose
mb;
62 (* corrupt the bitcode *)
63 let fn = fn ^
".txt" in
64 begin let oc = open_out
fn in
65 output_string
oc "not a bitcode file\n";
69 (* test get_module exceptions *)
72 let mb = Llvm.MemoryBuffer.of_file
fn in
74 Llvm_bitreader.get_module
context mb
76 Llvm.MemoryBuffer.dispose
mb;
79 Llvm.dispose_module
m;
81 with Llvm_bitreader.Error
_ ->