blob: 837c6a6ddee6ffc105a5447cd04decce7159d34c [file] [log] [blame]
Reid Spencerddc6fb12004-06-08 05:56:58 +00001//===-- llvm-abcd.cpp - Analysis of Byte Code Dumper ----------------------===//
Reid Spencerdb5c86d2004-06-07 17:53:43 +00002//
3// The LLVM Compiler Infrastructure
4//
Reid Spencerddc6fb12004-06-08 05:56:58 +00005// 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 Spencerdb5c86d2004-06-07 17:53:43 +00007//
8//===----------------------------------------------------------------------===//
9//
Reid Spencerddc6fb12004-06-08 05:56:58 +000010// 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 Spencerdb5c86d2004-06-07 17:53:43 +000013//
Reid Spencerddc6fb12004-06-08 05:56:58 +000014// 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 Spencerdb5c86d2004-06-07 17:53:43 +000027//===----------------------------------------------------------------------===//
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
35using namespace llvm;
36
37static cl::opt<std::string>
38 InputFilename(cl::Positional, cl::desc("<input bytecode>"), cl::init("-"));
39
Reid Spencerddc6fb12004-06-08 05:56:58 +000040static cl::opt<bool> Detailed ("details", cl::desc("Detailed output"));
41static cl::opt<bool> Dump ("dump", cl::desc("Detailed output"));
Reid Spencerdb5c86d2004-06-07 17:53:43 +000042
43int
44main(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 Spencerddc6fb12004-06-08 05:56:58 +000056 /// Determine what to generate
57 bca.dumpBytecode = Dump;
58 bca.detailedResults = Detailed;
59
Reid Spencerdb5c86d2004-06-07 17:53:43 +000060 /// 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 Spencerdb5c86d2004-06-07 17:53:43 +000069 // All that abcd does is write the gathered statistics to the output
Reid Spencerdb5c86d2004-06-07 17:53:43 +000070 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