1 //===------------------------------------------------------------------------===
4 // This utility may be invoked in the following manner:
5 // dis --help - Output information about command line switches
6 // dis [options] - Read LLVM bytecode from stdin, write assembly to stdout
7 // dis [options] x.bc - Read LLVM bytecode from the x.bc file, write assembly
10 //===------------------------------------------------------------------------===
14 #include "llvm/Module.h"
15 #include "llvm/Assembly/Writer.h"
16 #include "llvm/Bytecode/Reader.h"
17 #include "llvm/Tools/CommandLine.h"
19 int main(int argc, char **argv) {
20 ToolCommandLine Opts(argc, argv, false);
22 // We only support the options that the system parser does... if it left any
23 // then we don't know what to do.
26 for (int i = 1; i < argc; i++) {
27 if (string(argv[i]) != string("--help"))
28 cerr << argv[0] << ": argument not recognized: '" << argv[i] << "'!\n";
31 cerr << argv[0] << " usage:\n"
32 << " " << argv[0] << " --help - Print this usage information\n"
33 << " " << argv[0] << " x.bc - Parse <x.bc> file and output "
34 << "assembly to x.ll\n"
35 << " " << argv[0] << " - Parse stdin and write to stdout.\n";
39 ostream *Out = &cout; // Default to printing to stdout...
41 Module *C = ParseBytecodeFile(Opts.getInputFilename());
43 cerr << "bytecode didn't read correctly.\n";
47 if (Opts.getOutputFilename() != "-") {
48 Out = new ofstream(Opts.getOutputFilename().c_str(),
49 (Opts.getForce() ? 0 : ios::noreplace)|ios::out);
51 cerr << "Error opening " << Opts.getOutputFilename()
52 << ": sending to stdout instead!\n";
57 // All that dis does is write the assembly out to a file... which is exactly
58 // what the writer library is supposed to do...
62 if (Out != &cout) delete Out;