Use tool_output_file in llvm-extract and llvm-link too.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2010-08-20 01:12:13 +00:00
parent d5826a33a5
commit 2df9504fec
2 changed files with 13 additions and 18 deletions

View File

@ -116,14 +116,9 @@ int main(int argc, char **argv) {
Passes.add(createDeadTypeEliminationPass()); // Remove dead types... Passes.add(createDeadTypeEliminationPass()); // Remove dead types...
Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
// Make sure that the Output file gets unlinked from the disk if we get a
// SIGINT
if (OutputFilename != "-")
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
std::string ErrorInfo; std::string ErrorInfo;
raw_fd_ostream Out(OutputFilename.c_str(), ErrorInfo, tool_output_file Out(OutputFilename.c_str(), ErrorInfo,
raw_fd_ostream::F_Binary); raw_fd_ostream::F_Binary);
if (!ErrorInfo.empty()) { if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n'; errs() << ErrorInfo << '\n';
return 1; return 1;
@ -136,5 +131,8 @@ int main(int argc, char **argv) {
Passes.run(*M.get()); Passes.run(*M.get());
// Declare success.
Out.keep();
return 0; return 0;
} }

View File

@ -116,19 +116,13 @@ int main(int argc, char **argv) {
if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite; if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
std::string ErrorInfo; std::string ErrorInfo;
std::auto_ptr<raw_ostream> tool_output_file Out(OutputFilename.c_str(), ErrorInfo,
Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, raw_fd_ostream::F_Binary);
raw_fd_ostream::F_Binary));
if (!ErrorInfo.empty()) { if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n'; errs() << ErrorInfo << '\n';
return 1; return 1;
} }
// Make sure that the Out file gets unlinked from the disk if we get a
// SIGINT
if (OutputFilename != "-")
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
if (verifyModule(*Composite)) { if (verifyModule(*Composite)) {
errs() << argv[0] << ": linked module is broken!\n"; errs() << argv[0] << ": linked module is broken!\n";
return 1; return 1;
@ -136,9 +130,12 @@ int main(int argc, char **argv) {
if (Verbose) errs() << "Writing bitcode...\n"; if (Verbose) errs() << "Writing bitcode...\n";
if (OutputAssembly) { if (OutputAssembly) {
*Out << *Composite; Out << *Composite;
} else if (Force || !CheckBitcodeOutputToConsole(*Out, true)) } else if (Force || !CheckBitcodeOutputToConsole(Out, true))
WriteBitcodeToFile(Composite.get(), *Out); WriteBitcodeToFile(Composite.get(), Out);
// Declare success.
Out.keep();
return 0; return 0;
} }