| (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_bitreader.cmxa llvm_bitwriter.cmxa %s -o %t |
| (* Note that this takes a moment to link, so it's best to keep the number of |
| let context = Llvm.global_context () |
| let test x = if not x then exit 1 else () |
| let m = Llvm.create_module context "ocaml_test_module" in |
| test (Llvm_bitwriter.write_bitcode_file m fn); |
| let mb = Llvm.MemoryBuffer.of_file fn in |
| let m = Llvm_bitreader.parse_bitcode context mb in |
| Llvm.MemoryBuffer.dispose mb; |
| (* MemoryBuffer.of_file *) |
| let mb = Llvm.MemoryBuffer.of_file (fn ^ ".bogus") in |
| Llvm.MemoryBuffer.dispose mb; |
| let mb = Llvm.MemoryBuffer.of_file fn in |
| Llvm_bitreader.get_module context mb |
| Llvm.MemoryBuffer.dispose mb; |
| (* corrupt the bitcode *) |
| begin let oc = open_out fn in |
| output_string oc "not a bitcode file\n"; |
| (* test get_module exceptions *) |
| let mb = Llvm.MemoryBuffer.of_file fn in |
| Llvm_bitreader.get_module context mb |
| Llvm.MemoryBuffer.dispose mb; |
| with Llvm_bitreader.Error _ -> |