changeset 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 44c8eef6e6ee
files gen/toobj.cpp
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gen/toobj.cpp	Sun May 17 14:20:27 2009 +0200
+++ b/gen/toobj.cpp	Sun May 17 14:40:09 2009 +0200
@@ -210,6 +210,11 @@
         bcpath.appendSuffix(std::string(global.bc_ext));
         Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str());
         std::ofstream bos(bcpath.c_str(), std::ios::binary);
+        if (bos.fail())
+        {
+            error("cannot write LLVM bitcode, failed to open file '%s'", bcpath.c_str());
+            fatal();
+        }
         llvm::WriteBitcodeToFile(m, bos);
     }
 
@@ -220,6 +225,11 @@
         llpath.appendSuffix(std::string(global.ll_ext));
         Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
         std::ofstream aos(llpath.c_str());
+        if (aos.fail())
+        {
+            error("cannot write LLVM asm, failed to open file '%s'", llpath.c_str());
+            fatal();
+        }
         m->print(aos, NULL);
     }