• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1(* RUN: 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
3 * RUN: %t %t.bc
4 * RUN: %ocamlopt -g -w -3 -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitwriter.ml -o %t
5 * RUN: %t %t.bc
6 * RUN: llvm-dis < %t.bc
7 * XFAIL: vg_leak
8 *)
9
10(* Note that this takes a moment to link, so it's best to keep the number of
11   individual tests low. *)
12
13let context = Llvm.global_context ()
14
15let test x = if not x then exit 1 else ()
16
17let read_file name =
18  let ic = open_in_bin name in
19  let len = in_channel_length ic in
20  let buf = String.create len in
21
22  test ((input ic buf 0 len) = len);
23
24  close_in ic;
25
26  buf
27
28let temp_bitcode ?unbuffered m =
29  let temp_name, temp_oc = Filename.open_temp_file ~mode:[Open_binary] "" "" in
30
31  test (Llvm_bitwriter.output_bitcode ?unbuffered temp_oc m);
32  flush temp_oc;
33
34  let temp_buf = read_file temp_name in
35
36  close_out temp_oc;
37
38  temp_buf
39
40let _ =
41  let m = Llvm.create_module context "ocaml_test_module" in
42
43  test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1));
44  let file_buf = read_file Sys.argv.(1) in
45
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))
50