1 (* RUN: rm -rf %t && mkdir -p %t && cp %s %t/bitwriter.ml
2 * RUN: %ocamlc -g -w -3 -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %t/bitwriter.ml -o %t/executable
3 * RUN: %t/executable %t/bitcode.bc
4 * RUN: %ocamlopt -g -w -3 -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %t/bitwriter.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 test x
= if not x
then exit
1 else ()
18 let ic = open_in_bin name
in
19 let len = in_channel_length
ic in
20 let buf = String.create
len in
22 test ((input
ic buf 0 len) = len);
28 let temp_bitcode ?unbuffered m
=
29 let temp_name, temp_oc
= Filename.open_temp_file ~mode
:[Open_binary
] "" "" in
31 test (Llvm_bitwriter.output_bitcode ?unbuffered temp_oc m
);
34 let temp_buf = read_file temp_name in
41 let m = Llvm.create_module
context "ocaml_test_module" in
43 test (Llvm_bitwriter.write_bitcode_file
m Sys.argv
.(1));
44 let file_buf = read_file Sys.argv
.(1) in
46 test (file_buf = temp_bitcode m);
47 test (file_buf = temp_bitcode ~unbuffered
:false m);
48 test (file_buf = temp_bitcode ~unbuffered
:true m);
49 test (file_buf = Llvm.MemoryBuffer.as_string
(Llvm_bitwriter.write_bitcode_to_memory_buffer
m))