1 (* RUN: %ocamlc -warn-error A llvm.cma llvm_bitreader.cma llvm_bitwriter.cma %s -o %t 2> /dev/null
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 test x
= if not x
then exit
1 else ()
12 let fn = Sys.argv
.(1) in
13 let m = Llvm.create_module
"ocaml_test_module" in
15 ignore
(Llvm.define_type_name
"caml_int_ty" Llvm.i32_type
m);
17 test (Llvm_bitwriter.write_bitcode_file
m fn);
19 Llvm.dispose_module
m;
23 let mb = Llvm.MemoryBuffer.of_file
fn in
25 let m = Llvm_bitreader.parse_bitcode
mb in
28 Llvm.MemoryBuffer.dispose
mb;
33 (* MemoryBuffer.of_file *)
35 let mb = Llvm.MemoryBuffer.of_file
(fn ^
".bogus") in
36 Llvm.MemoryBuffer.dispose
mb;
38 with Llvm.IoError
_ ->
42 (* get_module_provider *)
44 let mb = Llvm.MemoryBuffer.of_file
fn in
46 Llvm_bitreader.get_module_provider
mb
48 Llvm.MemoryBuffer.dispose
mb;
51 Llvm.ModuleProvider.dispose
mp
54 (* corrupt the bitcode *)
55 let fn = fn ^
".txt" in
56 begin let oc = open_out
fn in
57 output_string
oc "not a bitcode file\n";
61 (* test get_module_provider exceptions *)
64 let mb = Llvm.MemoryBuffer.of_file
fn in
66 Llvm_bitreader.get_module_provider
mb
68 Llvm.MemoryBuffer.dispose
mb;
71 Llvm.ModuleProvider.dispose
mp;
73 with Llvm_bitreader.Error
_ ->