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
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 ignore
(Llvm.define_type_name
"caml_int_ty" (Llvm.i32_type
context) m);
20 test (Llvm_bitwriter.write_bitcode_file
m fn);
22 Llvm.dispose_module
m;
26 let mb = Llvm.MemoryBuffer.of_file
fn in
28 let m = Llvm_bitreader.parse_bitcode
context mb in
31 Llvm.MemoryBuffer.dispose
mb;
36 (* MemoryBuffer.of_file *)
38 let mb = Llvm.MemoryBuffer.of_file
(fn ^
".bogus") in
39 Llvm.MemoryBuffer.dispose
mb;
41 with Llvm.IoError
_ ->
47 let mb = Llvm.MemoryBuffer.of_file
fn in
49 Llvm_bitreader.get_module
context mb
51 Llvm.MemoryBuffer.dispose
mb;
57 (* corrupt the bitcode *)
58 let fn = fn ^
".txt" in
59 begin let oc = open_out
fn in
60 output_string
oc "not a bitcode file\n";
64 (* test get_module exceptions *)
67 let mb = Llvm.MemoryBuffer.of_file
fn in
69 Llvm_bitreader.get_module
context mb
71 Llvm.MemoryBuffer.dispose
mb;
74 Llvm.dispose_module
m;
76 with Llvm_bitreader.Error
_ ->