[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / test / Bindings / OCaml / bitwriter.ml
blob17111bd3b51e050b3a76575a52f85fa46b56d8e1
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
7 * XFAIL: vg_leak
8 *)
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 ()
17 let read_file name =
18 let ic = open_in_bin name in
19 let len = in_channel_length ic in
20 let buf = Bytes.create len in
22 test ((input ic buf 0 len) = len);
24 close_in ic;
26 buf
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);
32 flush temp_oc;
34 let temp_buf = read_file temp_name in
36 close_out temp_oc;
38 temp_buf
40 let _ =
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 = Bytes.of_string (Llvm.MemoryBuffer.as_string (Llvm_bitwriter.write_bitcode_to_memory_buffer m)))