summaryrefslogtreecommitdiff
path: root/tools/llvm-dis
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-23 02:51:22 +0000
committerChris Lattner <sabre@nondot.org>2009-08-23 02:51:22 +0000
commit17e9edc4a7bbeadf756494cf39fcacc9eff72202 (patch)
tree9aace188da0c44dfbbedde8b592702b9dcbc2cc0 /tools/llvm-dis
parent1d7fb4eae53c7ec5f9c5c18d603b50dfb9425862 (diff)
downloadllvm-17e9edc4a7bbeadf756494cf39fcacc9eff72202.tar.gz
llvm-17e9edc4a7bbeadf756494cf39fcacc9eff72202.tar.bz2
llvm-17e9edc4a7bbeadf756494cf39fcacc9eff72202.tar.xz
Change raw_fd_ostream to take flags as an optional bitmask
instead of as two bools. Use this to add a F_Append flag which has the obvious behavior. Other unrelated changes conflated into this patch: 1. REmove EH stuff from llvm-dis and llvm-as, the try blocks are dead. 2. Simplify the filename inference code in llvm-as/llvm-dis, because raw_fd_ostream does the right thing with '-'. 3. Switch machine verifier to use raw_ostream instead of ostream (Which is the thing that needed append in the first place). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79807 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-dis')
-rw-r--r--tools/llvm-dis/llvm-dis.cpp134
1 files changed, 57 insertions, 77 deletions
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 65e97c37df..2066fffd29 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -50,90 +50,70 @@ int main(int argc, char **argv) {
LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
- try {
- cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
-
- raw_ostream *Out = &outs(); // Default to printing to stdout.
- std::string ErrorMessage;
+
+
+ cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
- std::auto_ptr<Module> M;
-
- if (MemoryBuffer *Buffer
- = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
- M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage));
- delete Buffer;
- }
+ std::string ErrorMessage;
+ std::auto_ptr<Module> M;
+
+ if (MemoryBuffer *Buffer
+ = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage)) {
+ M.reset(ParseBitcodeFile(Buffer, Context, &ErrorMessage));
+ delete Buffer;
+ }
- if (M.get() == 0) {
- errs() << argv[0] << ": ";
- if (ErrorMessage.size())
- errs() << ErrorMessage << "\n";
- else
- errs() << "bitcode didn't read correctly.\n";
- return 1;
- }
-
- if (DontPrint) {
- // Just use stdout. We won't actually print anything on it.
- } else if (OutputFilename != "") { // Specified an output filename?
- if (OutputFilename != "-") { // Not stdout?
- std::string ErrorInfo;
- Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
- Force, ErrorInfo);
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
- if (!Force)
- errs() << "Use -f command line argument to force output\n";
- delete Out;
- return 1;
- }
- }
+ if (M.get() == 0) {
+ errs() << argv[0] << ": ";
+ if (ErrorMessage.size())
+ errs() << ErrorMessage << "\n";
+ else
+ errs() << "bitcode didn't read correctly.\n";
+ return 1;
+ }
+
+ // Just use stdout. We won't actually print anything on it.
+ if (DontPrint)
+ OutputFilename = "-";
+
+ if (OutputFilename.empty()) { // Unspecified output, infer it.
+ if (InputFilename == "-") {
+ OutputFilename = "-";
} else {
- if (InputFilename == "-") {
- OutputFilename = "-";
- } else {
- 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 = std::string(IFN.begin(), IFN.end()-3)+".ll";
- } else {
- OutputFilename = IFN+".ll";
- }
-
- std::string ErrorInfo;
- Out = new raw_fd_ostream(OutputFilename.c_str(), /*Binary=*/false,
- Force, ErrorInfo);
- if (!ErrorInfo.empty()) {
- errs() << ErrorInfo << '\n';
- if (!Force)
- 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
- // SIGINT
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
- }
+ const std::string &IFN = InputFilename;
+ int Len = IFN.length();
+ // If the source ends in .bc, strip it off.
+ if (IFN[Len-3] == '.' && IFN[Len-2] == 'b' && IFN[Len-1] == 'c')
+ OutputFilename = std::string(IFN.begin(), IFN.end()-3)+".ll";
+ else
+ OutputFilename = IFN+".ll";
}
+ }
+
+ std::string ErrorInfo;
+ std::auto_ptr<raw_fd_ostream>
+ Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
+ (Force?raw_fd_ostream::F_Force : 0) |
+ raw_fd_ostream::F_Binary));
+ if (!ErrorInfo.empty()) {
+ errs() << ErrorInfo << '\n';
+ if (!Force)
+ errs() << "Use -f command line argument to force output\n";
+ return 1;
+ }
- // All that llvm-dis does is write the assembly to a file.
- if (!DontPrint) {
- PassManager Passes;
- Passes.add(createPrintModulePass(Out));
- Passes.run(*M.get());
- }
+ // Make sure that the Out file gets unlinked from the disk if we get a
+ // SIGINT.
+ if (OutputFilename != "-")
+ sys::RemoveFileOnSignal(sys::Path(OutputFilename));
- if (Out != &outs())
- delete Out;
- return 0;
- } catch (const std::string& msg) {
- errs() << argv[0] << ": " << msg << "\n";
- } catch (...) {
- errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
+ // All that llvm-dis does is write the assembly to a file.
+ if (!DontPrint) {
+ PassManager Passes;
+ Passes.add(createPrintModulePass(Out.get()));
+ Passes.run(*M.get());
}
- return 1;
+ return 0;
}