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 | 268b0f4781a47645c2738e08cfb2da4ae5e4599f (patch) | |
tree | aa49a2a339561ccb9c94ee959dc96cd39f4e437b /llvm/tools/llc/llc.cpp | |
parent | 796b5122d936a798bbef4c7aae558aca7400a152 (diff) | |
download | bcm5719-llvm-268b0f4781a47645c2738e08cfb2da4ae5e4599f.tar.gz bcm5719-llvm-268b0f4781a47645c2738e08cfb2da4ae5e4599f.zip |
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.
llvm-svn: 111603
Diffstat (limited to 'llvm/tools/llc/llc.cpp')
-rw-r--r-- | llvm/tools/llc/llc.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index a7d1fa0311e..208d9f75ef6 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/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; } |