Erick Tryzelaar | e623050 | 2010-03-06 00:30:06 +0000 | [diff] [blame] | 1 | (* RUN: %ocamlopt -warn-error A unix.cmxa llvm.cmxa llvm_bitwriter.cmxa %s -o %t |
Bob Wilson | 2a7d731 | 2010-08-20 14:20:17 +0000 | [diff] [blame] | 2 | * RUN: %t %t.bc |
Nick Lewycky | b4f6095 | 2011-07-09 18:55:51 +0000 | [diff] [blame] | 3 | * RUN: llvm-dis < %t.bc |
Daniel Dunbar | 874f021 | 2010-09-09 15:50:19 +0000 | [diff] [blame] | 4 | * XFAIL: vg_leak |
Gordon Henriksen | 8ef426b | 2007-09-18 12:49:39 +0000 | [diff] [blame] | 5 | *) |
| 6 | |
| 7 | (* Note that this takes a moment to link, so it's best to keep the number of |
| 8 | individual tests low. *) |
| 9 | |
Erick Tryzelaar | b02b878 | 2009-08-19 17:32:24 +0000 | [diff] [blame] | 10 | let context = Llvm.global_context () |
| 11 | |
Gordon Henriksen | 8ef426b | 2007-09-18 12:49:39 +0000 | [diff] [blame] | 12 | let test x = if not x then exit 1 else () |
| 13 | |
Erick Tryzelaar | e623050 | 2010-03-06 00:30:06 +0000 | [diff] [blame] | 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 |
| 18 | |
| 19 | test ((input ic buf 0 len) = len); |
| 20 | |
| 21 | close_in ic; |
| 22 | |
| 23 | buf |
| 24 | |
| 25 | let temp_bitcode ?unbuffered m = |
| 26 | let temp_name, temp_oc = Filename.open_temp_file ~mode:[Open_binary] "" "" in |
| 27 | |
| 28 | test (Llvm_bitwriter.output_bitcode ?unbuffered temp_oc m); |
| 29 | flush temp_oc; |
| 30 | |
| 31 | let temp_buf = read_file temp_name in |
| 32 | |
| 33 | close_out temp_oc; |
| 34 | |
| 35 | temp_buf |
| 36 | |
Gordon Henriksen | 8ef426b | 2007-09-18 12:49:39 +0000 | [diff] [blame] | 37 | let _ = |
Erick Tryzelaar | b02b878 | 2009-08-19 17:32:24 +0000 | [diff] [blame] | 38 | let m = Llvm.create_module context "ocaml_test_module" in |
Gordon Henriksen | 8ef426b | 2007-09-18 12:49:39 +0000 | [diff] [blame] | 39 | |
Erick Tryzelaar | e623050 | 2010-03-06 00:30:06 +0000 | [diff] [blame] | 40 | test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1)); |
| 41 | let file_buf = read_file Sys.argv.(1) in |
| 42 | |
| 43 | test (file_buf = temp_bitcode m); |
| 44 | test (file_buf = temp_bitcode ~unbuffered:false m); |
| 45 | test (file_buf = temp_bitcode ~unbuffered:true m) |