2014-10-30 08:29:45 +00:00
|
|
|
(* RUN: cp %s %T/bitreader.ml
|
2014-10-30 08:29:57 +00:00
|
|
|
* RUN: %ocamlcomp -g -warn-error A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitreader.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-12-11 00:20:48 +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 06:40:29 +00:00
|
|
|
let context = Llvm.global_context ()
|
|
|
|
|
2007-12-11 00:20:48 +00:00
|
|
|
let test x = if not x then exit 1 else ()
|
|
|
|
|
|
|
|
let _ =
|
|
|
|
let fn = Sys.argv.(1) in
|
2009-08-19 06:40:29 +00:00
|
|
|
let m = Llvm.create_module context "ocaml_test_module" in
|
2014-10-28 22:39:42 +00:00
|
|
|
|
2007-12-11 00:20:48 +00:00
|
|
|
test (Llvm_bitwriter.write_bitcode_file m fn);
|
2014-10-28 22:39:42 +00:00
|
|
|
|
2007-12-11 00:20:48 +00:00
|
|
|
Llvm.dispose_module m;
|
2014-10-28 22:39:42 +00:00
|
|
|
|
2007-12-19 22:30:40 +00:00
|
|
|
(* parse_bitcode *)
|
|
|
|
begin
|
|
|
|
let mb = Llvm.MemoryBuffer.of_file fn in
|
|
|
|
begin try
|
2009-08-19 06:40:29 +00:00
|
|
|
let m = Llvm_bitreader.parse_bitcode context mb in
|
2007-12-19 22:30:40 +00:00
|
|
|
Llvm.dispose_module m
|
|
|
|
with x ->
|
2007-12-22 19:41:30 +00:00
|
|
|
Llvm.MemoryBuffer.dispose mb;
|
2007-12-19 22:30:40 +00:00
|
|
|
raise x
|
|
|
|
end
|
|
|
|
end;
|
2014-10-28 22:39:42 +00:00
|
|
|
|
2007-12-19 22:30:40 +00:00
|
|
|
(* MemoryBuffer.of_file *)
|
|
|
|
test begin try
|
|
|
|
let mb = Llvm.MemoryBuffer.of_file (fn ^ ".bogus") in
|
|
|
|
Llvm.MemoryBuffer.dispose mb;
|
|
|
|
false
|
|
|
|
with Llvm.IoError _ ->
|
|
|
|
true
|
|
|
|
end;
|
2014-10-28 22:39:42 +00:00
|
|
|
|
2010-03-02 23:59:00 +00:00
|
|
|
(* get_module *)
|
2007-12-19 22:30:40 +00:00
|
|
|
begin
|
|
|
|
let mb = Llvm.MemoryBuffer.of_file fn in
|
2010-03-02 23:59:00 +00:00
|
|
|
let m = begin try
|
|
|
|
Llvm_bitreader.get_module context mb
|
2007-12-19 22:30:40 +00:00
|
|
|
with x ->
|
|
|
|
Llvm.MemoryBuffer.dispose mb;
|
|
|
|
raise x
|
|
|
|
end in
|
2010-03-02 23:59:00 +00:00
|
|
|
Llvm.dispose_module m
|
2007-12-19 22:30:40 +00:00
|
|
|
end;
|
2014-10-28 22:39:42 +00:00
|
|
|
|
2007-12-19 22:30:40 +00:00
|
|
|
(* corrupt the bitcode *)
|
|
|
|
let fn = fn ^ ".txt" in
|
|
|
|
begin let oc = open_out fn in
|
|
|
|
output_string oc "not a bitcode file\n";
|
|
|
|
close_out oc
|
|
|
|
end;
|
2014-10-28 22:39:42 +00:00
|
|
|
|
2010-03-02 23:59:00 +00:00
|
|
|
(* test get_module exceptions *)
|
2007-12-19 22:30:40 +00:00
|
|
|
test begin
|
|
|
|
try
|
|
|
|
let mb = Llvm.MemoryBuffer.of_file fn in
|
2010-03-02 23:59:00 +00:00
|
|
|
let m = begin try
|
|
|
|
Llvm_bitreader.get_module context mb
|
2007-12-19 22:30:40 +00:00
|
|
|
with x ->
|
|
|
|
Llvm.MemoryBuffer.dispose mb;
|
|
|
|
raise x
|
|
|
|
end in
|
2010-03-02 23:59:00 +00:00
|
|
|
Llvm.dispose_module m;
|
2007-12-19 22:30:40 +00:00
|
|
|
false
|
|
|
|
with Llvm_bitreader.Error _ ->
|
|
|
|
true
|
|
|
|
end
|