diff options
author | Dan Gohman <gohman@apple.com> | 2009-07-15 17:29:42 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-07-15 17:29:42 +0000 |
commit | a1bdcedc3879510a874d24c450e07feb170d9cd6 (patch) | |
tree | 87232c6e8e70de1345065d6e50540c4577f68dc3 /tools/llc | |
parent | 2286f8dc4cec0625f7d7a14e2570926cf8599646 (diff) |
Add a Force option to raw_fd_ostream to specify whether opening
an existing file is considered an error. Convert several tools
to use raw_fd_ostream instead of std::ostream, and to use this
new option instead of doing a manual check.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75801 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llc')
-rw-r--r-- | tools/llc/llc.cpp | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 9acfcd29000..c4bb41e1f06 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -41,8 +41,6 @@ #include "llvm/Config/config.h" #include "llvm/LinkAllVMCore.h" #include "llvm/Target/TargetSelect.h" -#include <fstream> -#include <iostream> #include <memory> using namespace llvm; @@ -133,28 +131,22 @@ static formatted_raw_ostream *GetOutputStream(const char *ProgName) { if (OutputFilename == "-") return &fouts(); - // Specified an output filename? - if (!Force && std::ifstream(OutputFilename.c_str())) { - // If force is not specified, make sure not to overwrite a file! - errs() << ProgName << ": error opening '" << OutputFilename - << "': file exists!\n" - << "Use -f command line argument to force output\n"; - return 0; - } // Make sure that the Out file gets unlinked from the disk if we get a // SIGINT sys::RemoveFileOnSignal(sys::Path(OutputFilename)); std::string error; raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(), - true, error); - formatted_raw_ostream *Out = - new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM); + /*Binary=*/true, Force, error); if (!error.empty()) { errs() << error << '\n'; - delete Out; + if (!Force) + errs() << "Use -f command line argument to force output\n"; + delete FDOut; return 0; } + formatted_raw_ostream *Out = + new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM); return Out; } @@ -189,29 +181,24 @@ static formatted_raw_ostream *GetOutputStream(const char *ProgName) { break; } - if (!Force && std::ifstream(OutputFilename.c_str())) { - // If force is not specified, make sure not to overwrite a file! - errs() << ProgName << ": error opening '" << OutputFilename - << "': file exists!\n" - << "Use -f command line argument to force output\n"; - return 0; - } - // Make sure that the Out file gets unlinked from the disk if we get a // SIGINT sys::RemoveFileOnSignal(sys::Path(OutputFilename)); std::string error; raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(), - Binary, error); - formatted_raw_ostream *Out = - new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM); + Binary, Force, error); if (!error.empty()) { errs() << error << '\n'; - delete Out; + if (!Force) + errs() << "Use -f command line argument to force output\n"; + delete FDOut; return 0; } + formatted_raw_ostream *Out = + new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM); + return Out; } |