2014-10-30 08:29:45 +00:00
|
|
|
(* RUN: cp %s %T/bitwriter.ml
|
2015-07-17 17:33:23 +00:00
|
|
|
* RUN: %ocamlc -g -w -3 -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitwriter.ml -o %t
|
2014-11-03 09:50:53 +00:00
|
|
|
* RUN: %t %t.bc
|
2015-07-17 17:33:23 +00:00
|
|
|
* RUN: %ocamlopt -g -w -3 -w +A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitwriter.ml -o %t
|
2010-08-20 14:20:17 +00:00
|
|
|
* RUN: %t %t.bc
|
2011-07-09 18:55:51 +00:00
|
|
|
* RUN: llvm-dis < %t.bc
|
2010-09-09 15:50:19 +00:00
|
|
|
* XFAIL: vg_leak
|
2007-09-18 12:49:39 +00:00
|
|
|
*)
|
|
|
|
|
|
|
|
(* Note that this takes a moment to link, so it's best to keep the number of
|
|
|
|
individual tests low. *)
|
|
|
|
|
2009-08-19 17:32:24 +00:00
|
|
|
let context = Llvm.global_context ()
|
|
|
|
|
2007-09-18 12:49:39 +00:00
|
|
|
let test x = if not x then exit 1 else ()
|
|
|
|
|
2010-03-06 00:30:06 +00:00
|
|
|
let read_file name =
|
|
|
|
let ic = open_in_bin name in
|
|
|
|
let len = in_channel_length ic in
|
|
|
|
let buf = String.create len in
|
|
|
|
|
|
|
|
test ((input ic buf 0 len) = len);
|
|
|
|
|
|
|
|
close_in ic;
|
|
|
|
|
|
|
|
buf
|
|
|
|
|
|
|
|
let temp_bitcode ?unbuffered m =
|
|
|
|
let temp_name, temp_oc = Filename.open_temp_file ~mode:[Open_binary] "" "" in
|
|
|
|
|
|
|
|
test (Llvm_bitwriter.output_bitcode ?unbuffered temp_oc m);
|
|
|
|
flush temp_oc;
|
|
|
|
|
|
|
|
let temp_buf = read_file temp_name in
|
|
|
|
|
|
|
|
close_out temp_oc;
|
|
|
|
|
|
|
|
temp_buf
|
|
|
|
|
2007-09-18 12:49:39 +00:00
|
|
|
let _ =
|
2009-08-19 17:32:24 +00:00
|
|
|
let m = Llvm.create_module context "ocaml_test_module" in
|
2014-10-28 22:39:42 +00:00
|
|
|
|
2010-03-06 00:30:06 +00:00
|
|
|
test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1));
|
|
|
|
let file_buf = read_file Sys.argv.(1) in
|
|
|
|
|
|
|
|
test (file_buf = temp_bitcode m);
|
|
|
|
test (file_buf = temp_bitcode ~unbuffered:false m);
|
2014-10-29 08:16:01 +00:00
|
|
|
test (file_buf = temp_bitcode ~unbuffered:true m);
|
|
|
|
test (file_buf = Llvm.MemoryBuffer.as_string (Llvm_bitwriter.write_bitcode_to_memory_buffer m))
|