diff options
author | Dan Gohman <gohman@apple.com> | 2010-08-20 01:07:01 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-08-20 01:07:01 +0000 |
commit | d5826a33a5a7c298a8934541d11cda042028be3b (patch) | |
tree | 56249c802243407a71acb23ba3bcf59eb0d58b2b /tools/llc | |
parent | 52fdaeda759b2ef3b9048ab8651b024f864b3858 (diff) | |
download | external_llvm-d5826a33a5a7c298a8934541d11cda042028be3b.zip external_llvm-d5826a33a5a7c298a8934541d11cda042028be3b.tar.gz external_llvm-d5826a33a5a7c298a8934541d11cda042028be3b.tar.bz2 |
Use the new tool_output_file in several tools. This fixes a variety
of problems with output files being left behind or output streams
being left unclosed. Fix llvm-mc to respect the -o option in all
modes, rather than hardcoding outs() in some cases.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111603 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llc')
-rw-r--r-- | tools/llc/llc.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index a7d1fa0..208d9f7 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -124,9 +124,9 @@ GetFileNameRoot(const std::string &InputFilename) { return outputFilename; } -static formatted_raw_ostream *GetOutputStream(const char *TargetName, - Triple::OSType OS, - const char *ProgName) { +static formatted_tool_output_file *GetOutputStream(const char *TargetName, + Triple::OSType OS, + const char *ProgName) { // If we don't yet have an output filename, make one. if (OutputFilename.empty()) { if (InputFilename == "-") @@ -172,25 +172,21 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName, break; } - // Make sure that the Out file gets unlinked from the disk if we get a - // SIGINT - if (OutputFilename != "-") - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - // Open the file. std::string error; unsigned OpenFlags = 0; if (Binary) OpenFlags |= raw_fd_ostream::F_Binary; - raw_fd_ostream *FDOut = new raw_fd_ostream(OutputFilename.c_str(), error, - OpenFlags); + tool_output_file *FDOut = new tool_output_file(OutputFilename.c_str(), error, + OpenFlags); if (!error.empty()) { errs() << error << '\n'; delete FDOut; return 0; } - formatted_raw_ostream *Out = - new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM); + formatted_tool_output_file *Out = + new formatted_tool_output_file(*FDOut, + formatted_raw_ostream::DELETE_STREAM); return Out; } @@ -283,9 +279,9 @@ int main(int argc, char **argv) { TargetMachine &Target = *target.get(); // Figure out where we are going to send the output... - formatted_raw_ostream *Out = GetOutputStream(TheTarget->getName(), - TheTriple.getOS(), argv[0]); - if (Out == 0) return 1; + OwningPtr<formatted_tool_output_file> Out + (GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0])); + if (!Out) return 1; CodeGenOpt::Level OLvl = CodeGenOpt::Default; switch (OptLevel) { @@ -335,16 +331,13 @@ int main(int argc, char **argv) { DisableVerify)) { errs() << argv[0] << ": target does not support generation of this" << " file type!\n"; - delete Out; - // And the Out file is empty and useless, so remove it now. - sys::Path(OutputFilename).eraseFromDisk(); return 1; } PM.run(mod); - // Delete the ostream. - delete Out; + // Declare success. + Out->keep(); return 0; } |