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