Mercurial > projects > ldc
comparison gen/toobj.cpp @ 1380:98d435fa2a2d
Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Sun, 17 May 2009 14:40:09 +0200 |
parents | d430a41fbb45 |
children | 402bffb1b356 |
comparison
equal
deleted
inserted
replaced
1379:d430a41fbb45 | 1380:98d435fa2a2d |
---|---|
208 LLPath bcpath = LLPath(filename); | 208 LLPath bcpath = LLPath(filename); |
209 bcpath.eraseSuffix(); | 209 bcpath.eraseSuffix(); |
210 bcpath.appendSuffix(std::string(global.bc_ext)); | 210 bcpath.appendSuffix(std::string(global.bc_ext)); |
211 Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str()); | 211 Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str()); |
212 std::ofstream bos(bcpath.c_str(), std::ios::binary); | 212 std::ofstream bos(bcpath.c_str(), std::ios::binary); |
213 if (bos.fail()) | |
214 { | |
215 error("cannot write LLVM bitcode, failed to open file '%s'", bcpath.c_str()); | |
216 fatal(); | |
217 } | |
213 llvm::WriteBitcodeToFile(m, bos); | 218 llvm::WriteBitcodeToFile(m, bos); |
214 } | 219 } |
215 | 220 |
216 // write LLVM IR | 221 // write LLVM IR |
217 if (global.params.output_ll) { | 222 if (global.params.output_ll) { |
218 LLPath llpath = LLPath(filename); | 223 LLPath llpath = LLPath(filename); |
219 llpath.eraseSuffix(); | 224 llpath.eraseSuffix(); |
220 llpath.appendSuffix(std::string(global.ll_ext)); | 225 llpath.appendSuffix(std::string(global.ll_ext)); |
221 Logger::println("Writing LLVM asm to: %s\n", llpath.c_str()); | 226 Logger::println("Writing LLVM asm to: %s\n", llpath.c_str()); |
222 std::ofstream aos(llpath.c_str()); | 227 std::ofstream aos(llpath.c_str()); |
228 if (aos.fail()) | |
229 { | |
230 error("cannot write LLVM asm, failed to open file '%s'", llpath.c_str()); | |
231 fatal(); | |
232 } | |
223 m->print(aos, NULL); | 233 m->print(aos, NULL); |
224 } | 234 } |
225 | 235 |
226 // write native assembly | 236 // write native assembly |
227 if (global.params.output_s || global.params.output_o) { | 237 if (global.params.output_s || global.params.output_o) { |