Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame^] | 1 | //===-- llvm-abcd.cpp - Analysis of Byte Code Dumper ----------------------===// |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame^] | 5 | // This file was developed by Reid Spencerearch and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame^] | 10 | // This tool may be invoked in the following manner: |
| 11 | // llvm-abcd [options] - Read LLVM bytecode from stdin |
| 12 | // llvm-abcd [options] x.bc - Read LLVM bytecode from the x.bc file |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 13 | // |
Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame^] | 14 | // Options: |
| 15 | // --help - Output information about command line switches |
| 16 | // --details - Provide detailed analysis of individual functions |
| 17 | // --dump - Dump bytecode in readable format |
| 18 | // |
| 19 | // This tool provides analytical information about a bytecode file. It is |
| 20 | // intended as an aid to developers of bytecode reading and writing software. It |
| 21 | // produces on std::out a summary of the bytecode file that shows various |
| 22 | // statistics about the contents of the file. If the -details option is given |
| 23 | // then the output includes detailed information about each function in the |
| 24 | // bytecode file. The tool is also able to print a bytecode file in a straight |
| 25 | // forward text format // that shows the containment and relationships of the |
| 26 | // information in the bytecode file (-dump option). |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | |
| 29 | #include "llvm/Bytecode/Analyzer.h" |
| 30 | #include "Support/CommandLine.h" |
| 31 | #include "llvm/System/Signals.h" |
| 32 | #include <fstream> |
| 33 | #include <iostream> |
| 34 | |
| 35 | using namespace llvm; |
| 36 | |
| 37 | static cl::opt<std::string> |
| 38 | InputFilename(cl::Positional, cl::desc("<input bytecode>"), cl::init("-")); |
| 39 | |
Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame^] | 40 | static cl::opt<bool> Detailed ("details", cl::desc("Detailed output")); |
| 41 | static cl::opt<bool> Dump ("dump", cl::desc("Detailed output")); |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 42 | |
| 43 | int |
| 44 | main(int argc, char **argv) |
| 45 | { |
| 46 | cl::ParseCommandLineOptions(argc, argv, |
| 47 | " llvm-abcd Analysis of ByteCode Dumper\n"); |
| 48 | |
| 49 | PrintStackTraceOnErrorSignal(); |
| 50 | |
| 51 | std::ostream* Out = &std::cout; // Default to printing to stdout... |
| 52 | std::istream* In = &std::cin; // Default to reading stdin |
| 53 | std::string ErrorMessage; |
| 54 | BytecodeAnalysis bca; |
| 55 | |
Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame^] | 56 | /// Determine what to generate |
| 57 | bca.dumpBytecode = Dump; |
| 58 | bca.detailedResults = Detailed; |
| 59 | |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 60 | /// Analyze the bytecode file |
| 61 | AnalyzeBytecodeFile(InputFilename, bca, &ErrorMessage); |
| 62 | |
| 63 | // If there was an error, print it and stop. |
| 64 | if ( ErrorMessage.size() ) { |
| 65 | std::cerr << argv[0] << ": " << ErrorMessage << "\n"; |
| 66 | return 1; |
| 67 | } |
| 68 | |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 69 | // All that abcd does is write the gathered statistics to the output |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 70 | PrintBytecodeAnalysis(bca,*Out); |
| 71 | |
| 72 | if (Out != &std::cout) { |
| 73 | ((std::ofstream*)Out)->close(); |
| 74 | delete Out; |
| 75 | } |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | // vim: sw=2 |