X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-dis%2Fdis.cpp;h=166a178d5745e480ab08cf2ce59e3d8bb20cf4a7;hb=fe4f677a9752f90d6bd3d17cd513220d7fa09ec3;hp=361564c8e54e9674bf8b2e21892df1ea10dfe21b;hpb=5ff62e90d0bc321206023897edc1e2691cb0fbb6;p=oota-llvm.git diff --git a/tools/llvm-dis/dis.cpp b/tools/llvm-dis/dis.cpp index 361564c8e54..166a178d574 100644 --- a/tools/llvm-dis/dis.cpp +++ b/tools/llvm-dis/dis.cpp @@ -12,13 +12,14 @@ //===----------------------------------------------------------------------===// #include "llvm/Module.h" +#include "llvm/PassManager.h" #include "llvm/Bytecode/Reader.h" -#include "llvm/Support/CFG.h" +#include "llvm/Assembly/CWriter.h" +#include "llvm/Assembly/PrintModulePass.h" #include "Support/CommandLine.h" #include "Support/Signals.h" -#include "llvm/Assembly/CWriter.h" #include -#include +#include using std::cerr; // OutputMode - The different orderings to print basic blocks in... @@ -27,10 +28,10 @@ enum OutputMode { c, // Generate C code }; -static cl::opt +static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::init("-")); -static cl::opt +static cl::opt OutputFilename("o", cl::desc("Override output filename"), cl::value_desc("filename")); @@ -48,17 +49,17 @@ int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, " llvm .bc -> .ll disassembler\n"); std::ostream *Out = &std::cout; // Default to printing to stdout... - Module *M = ParseBytecodeFile(InputFilename); - if (M == 0) { - cerr << "bytecode didn't read correctly.\n"; + std::auto_ptr M(ParseBytecodeFile(InputFilename)); + if (M.get() == 0) { + cerr << argv[0] << ": bytecode didn't read correctly.\n"; return 1; } if (OutputFilename != "") { // Specified an output filename? 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"; + cerr << argv[0] << ": error opening '" << OutputFilename + << "': file exists! Sending to standard output.\n"; } else { Out = new std::ofstream(OutputFilename.c_str()); } @@ -81,8 +82,8 @@ int main(int argc, char **argv) { 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"; + cerr << argv[0] << ": error opening '" << OutputFilename + << "': file exists! Sending to standard output.\n"; } else { Out = new std::ofstream(OutputFilename.c_str()); @@ -94,24 +95,30 @@ int main(int argc, char **argv) { } if (!Out->good()) { - cerr << "Error opening " << OutputFilename + cerr << argv[0] << ": error opening " << OutputFilename << ": sending to stdout instead!\n"; Out = &std::cout; } // All that dis does is write the assembly or C out to a file... // + PassManager Passes; + switch (WriteMode) { - case llvm: - (*Out) << M; // Output LLVM assembly + case llvm: // Output LLVM assembly + Passes.add(new PrintModulePass(Out)); break; - case c: - WriteToC(M, *Out); // Convert LLVM to C + case c: // Convert LLVM to C + Passes.add(createWriteToCPass(*Out)); break; } - delete M; - if (Out != &std::cout) delete Out; + Passes.run(*M.get()); + + if (Out != &std::cout) { + ((std::ofstream*)Out)->close(); + delete Out; + } return 0; }