summaryrefslogtreecommitdiff
path: root/tools/opt
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-08-18 17:40:10 +0000
committerDan Gohman <gohman@apple.com>2010-08-18 17:40:10 +0000
commit86cbc1bb11c1de74afcd96a421f74429faca4c2f (patch)
tree5e84139a7ff32f0c83fd1f5c01d84b1f01db71f8 /tools/opt
parent510cea0f908e27bff181d3a5fa8fa76f652bb631 (diff)
Don't translate "-" to outs() manually; raw_ostream does that automatically.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111371 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt')
-rw-r--r--tools/opt/opt.cpp54
1 files changed, 23 insertions, 31 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index f6b829fde93..8783061dd4f 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -53,7 +53,7 @@ InputFilename(cl::Positional, cl::desc("<input bitcode file>"),
static cl::opt<std::string>
OutputFilename("o", cl::desc("Override output filename"),
- cl::value_desc("filename"), cl::init("-"));
+ cl::value_desc("filename"));
static cl::opt<bool>
Force("f", cl::desc("Enable binary output on terminals"));
@@ -381,34 +381,27 @@ int main(int argc, char **argv) {
// Figure out what stream we are supposed to write to...
raw_ostream *Out = 0;
- bool DeleteStream = false;
- if (!NoOutput && !AnalyzeOnly) {
- if (OutputFilename == "-") {
- // Print to stdout.
- Out = &outs();
- // If we're printing a bitcode file, switch stdout to binary mode.
- // FIXME: This switches outs() globally, not just for the bitcode output.
- if (!OutputAssembly)
- sys::Program::ChangeStdoutToBinary();
- } else {
- if (NoOutput || AnalyzeOnly) {
- errs() << "WARNING: The -o (output filename) option is ignored when\n"
- "the --disable-output or --analyze options are used.\n";
- } else {
- // Make sure that the Output file gets unlinked from the disk if we get
- // a SIGINT.
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-
- std::string ErrorInfo;
- Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary);
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
- delete Out;
- return 1;
- }
- DeleteStream = true;
- }
+ if (NoOutput || AnalyzeOnly) {
+ if (!OutputFilename.empty())
+ errs() << "WARNING: The -o (output filename) option is ignored when\n"
+ "the --disable-output or --analyze options are used.\n";
+ } else {
+ // Default to standard output.
+ if (OutputFilename.empty())
+ OutputFilename = "-";
+
+ // 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;
+ Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+ raw_fd_ostream::F_Binary);
+ if (!ErrorInfo.empty()) {
+ errs() << ErrorInfo << '\n';
+ delete Out;
+ return 1;
}
}
@@ -553,7 +546,6 @@ int main(int argc, char **argv) {
Passes.run(*M.get());
// Delete the raw_fd_ostream.
- if (DeleteStream)
- delete Out;
+ delete Out;
return 0;
}