simplify output file selection, fixing two FIXMEs about binary output

llvm-svn: 79808
This commit is contained in:
Chris Lattner 2009-08-23 02:56:05 +00:00
parent f16d8ade4f
commit 1992ea13a1
2 changed files with 22 additions and 35 deletions

View File

@ -110,29 +110,20 @@ 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
raw_ostream *Out = 0; std::string ErrorInfo;
std::auto_ptr<raw_fd_ostream>
if (OutputFilename != "-") { // Not stdout? Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
std::string ErrorInfo; raw_fd_ostream::F_Binary |
Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, (Force ? raw_fd_ostream::F_Force : 0)));
raw_fd_ostream::F_Binary | if (!ErrorInfo.empty()) {
(Force ? raw_fd_ostream::F_Force : 0)); errs() << ErrorInfo << '\n';
if (!ErrorInfo.empty()) { if (!Force)
errs() << ErrorInfo << '\n'; errs() << "Use -f command line argument to force output\n";
if (!Force) return 1;
errs() << "Use -f command line argument to force output\n";
delete Out;
return 1;
}
} else { // Specified stdout
// FIXME: outs() is not binary!
Out = &outs();
} }
Passes.add(createBitcodeWriterPass(*Out)); Passes.add(createBitcodeWriterPass(*Out));
Passes.run(*M.get()); Passes.run(*M.get());
if (Out != &outs())
delete Out;
return 0; return 0;
} }

View File

@ -118,25 +118,22 @@ int main(int argc, char **argv) {
if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite.get(); if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite.get();
// FIXME: outs() is not binary! std::string ErrorInfo;
raw_ostream *Out = &outs(); // Default to printing to stdout... std::auto_ptr<raw_ostream>
if (OutputFilename != "-") { Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
std::string ErrorInfo; raw_fd_ostream::F_Binary |
Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, (Force ? raw_fd_ostream::F_Force : 0)));
raw_fd_ostream::F_Binary | if (!ErrorInfo.empty()) {
(Force ? raw_fd_ostream::F_Force : 0)); errs() << ErrorInfo << '\n';
if (!ErrorInfo.empty()) { if (!Force)
errs() << ErrorInfo << '\n'; errs() << "Use -f command line argument to force output\n";
if (!Force) return 1;
errs() << "Use -f command line argument to force output\n"; }
delete Out;
return 1;
}
// Make sure that the Out file gets unlinked from the disk if we get a // Make sure that the Out file gets unlinked from the disk if we get a
// SIGINT // SIGINT
if (OutputFilename != "-")
sys::RemoveFileOnSignal(sys::Path(OutputFilename)); sys::RemoveFileOnSignal(sys::Path(OutputFilename));
}
if (verifyModule(*Composite.get())) { if (verifyModule(*Composite.get())) {
errs() << argv[0] << ": linked module is broken!\n"; errs() << argv[0] << ": linked module is broken!\n";
@ -146,6 +143,5 @@ int main(int argc, char **argv) {
if (Verbose) errs() << "Writing bitcode...\n"; if (Verbose) errs() << "Writing bitcode...\n";
WriteBitcodeToFile(Composite.get(), *Out); WriteBitcodeToFile(Composite.get(), *Out);
if (Out != &outs()) delete Out;
return 0; return 0;
} }