Fixed some bugs.
[llvm/zpu.git] / test / Bindings / Ocaml / bitwriter.ml
blob3f55fb9fa1d449e4cc6018865c285df2f988b045
1 (* RUN: %ocamlopt -warn-error A unix.cmxa llvm.cmxa llvm_bitwriter.cmxa %s -o %t
2 * RUN: %t %t.bc
3 * RUN: llvm-dis < %t.bc | grep caml_int_ty
4 * XFAIL: vg_leak
5 *)
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 ()
14 let read_file name =
15 let ic = open_in_bin name in
16 let len = in_channel_length ic in
17 let buf = String.create len in
19 test ((input ic buf 0 len) = len);
21 close_in ic;
23 buf
25 let temp_bitcode ?unbuffered m =
26 let temp_name, temp_oc = Filename.open_temp_file ~mode:[Open_binary] "" "" in
28 test (Llvm_bitwriter.output_bitcode ?unbuffered temp_oc m);
29 flush temp_oc;
31 let temp_buf = read_file temp_name in
33 close_out temp_oc;
35 temp_buf
37 let _ =
38 let m = Llvm.create_module context "ocaml_test_module" in
40 ignore (Llvm.define_type_name "caml_int_ty" (Llvm.i32_type context) m);
42 test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1));
43 let file_buf = read_file Sys.argv.(1) in
45 test (file_buf = temp_bitcode m);
46 test (file_buf = temp_bitcode ~unbuffered:false m);
47 test (file_buf = temp_bitcode ~unbuffered:true m)