summaryrefslogtreecommitdiff
path: root/tools/llvm-dis/llvm-dis.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-01-20 22:54:45 +0000
committerChris Lattner <sabre@nondot.org>2002-01-20 22:54:45 +0000
commit697954c15da58bd8b186dbafdedd8b06db770201 (patch)
treee119a71f09b5c2513c8c270161ae2a858c6f3b96 /tools/llvm-dis/llvm-dis.cpp
parent13c4659220bc78a0a3529f4d9e57546e898088e3 (diff)
downloadllvm-697954c15da58bd8b186dbafdedd8b06db770201.tar.gz
llvm-697954c15da58bd8b186dbafdedd8b06db770201.tar.bz2
llvm-697954c15da58bd8b186dbafdedd8b06db770201.tar.xz
Changes to build successfully with GCC 3.02
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1503 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-dis/llvm-dis.cpp')
-rw-r--r--tools/llvm-dis/llvm-dis.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 2a7eb4e06e..55e8d5d669 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -24,6 +24,8 @@
#include "Support/PostOrderIterator.h"
#include "Support/CommandLine.h"
#include <fstream>
+#include <iostream>
+using std::cerr;
// OutputMode - The different orderings to print basic blocks in...
enum OutputMode {
@@ -47,7 +49,7 @@ cl::EnumFlags<enum OutputMode> WriteMode(cl::NoFlags,
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n");
- ostream *Out = &cout; // Default to printing to stdout...
+ std::ostream *Out = &std::cout; // Default to printing to stdout...
Module *C = ParseBytecodeFile(InputFilename);
if (C == 0) {
@@ -56,31 +58,41 @@ int main(int argc, char **argv) {
}
if (OutputFilename != "") { // Specified an output filename?
- Out = new ofstream(OutputFilename.c_str(),
- (Force ? 0 : ios::noreplace)|ios::out);
+ if (!Force && !std::ifstream(OutputFilename.c_str())) {
+ // If force is not specified, make sure not to overwrite a file!
+ cerr << "Error opening '" << OutputFilename
+ << "': File exists! Sending to standard output.\n";
+ } else {
+ Out = new std::ofstream(OutputFilename.c_str());
+ }
} else {
if (InputFilename == "-") {
OutputFilename = "-";
- Out = &cout;
} else {
- string IFN = InputFilename;
+ std::string IFN = InputFilename;
int Len = IFN.length();
if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c') {
// Source ends in .bc
- OutputFilename = string(IFN.begin(), IFN.end()-3);
+ OutputFilename = std::string(IFN.begin(), IFN.end()-3);
} else {
OutputFilename = IFN; // Append a .ll to it
}
OutputFilename += ".ll";
- Out = new ofstream(OutputFilename.c_str(),
- (Force ? 0 : ios::noreplace)|ios::out);
+
+ if (!Force && !std::ifstream(OutputFilename.c_str())) {
+ // If force is not specified, make sure not to overwrite a file!
+ cerr << "Error opening '" << OutputFilename
+ << "': File exists! Sending to standard output.\n";
+ } else {
+ Out = new std::ofstream(OutputFilename.c_str());
+ }
}
}
if (!Out->good()) {
cerr << "Error opening " << OutputFilename
<< ": sending to stdout instead!\n";
- Out = &cout;
+ Out = &std::cout;
}
// All that dis does is write the assembly out to a file... which is exactly
@@ -100,20 +112,20 @@ int main(int argc, char **argv) {
switch (WriteMode) {
case dfo: // Depth First ordering
copy(df_begin(M), df_end(M),
- ostream_iterator<BasicBlock*>(*Out, "\n"));
+ std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case rdfo: // Reverse Depth First ordering
copy(df_begin(M, true), df_end(M),
- ostream_iterator<BasicBlock*>(*Out, "\n"));
+ std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case po: // Post Order
copy(po_begin(M), po_end(M),
- ostream_iterator<BasicBlock*>(*Out, "\n"));
+ std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
case rpo: { // Reverse Post Order
ReversePostOrderTraversal RPOT(M);
copy(RPOT.begin(), RPOT.end(),
- ostream_iterator<BasicBlock*>(*Out, "\n"));
+ std::ostream_iterator<BasicBlock*>(*Out, "\n"));
break;
}
default:
@@ -124,6 +136,6 @@ int main(int argc, char **argv) {
}
delete C;
- if (Out != &cout) delete Out;
+ if (Out != &std::cout) delete Out;
return 0;
}