blob: b879cf807071f360792e4710c0b10f3331e943e6 [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 Spencerb3a4e0b2004-06-10 18:38:44 +00005// This file was developed by Reid Spencer and is distributed under the
Reid Spencerddc6fb12004-06-08 05:56:58 +00006// 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:
Reid Spencerb3a4e0b2004-06-10 18:38:44 +000015// --help - Output information about command line switches
16// --nodetails - Don't print out detailed informaton about individual
17// blocks and functions
18// --dump - Dump low-level bytecode structure in readable format
Reid Spencerddc6fb12004-06-08 05:56:58 +000019//
20// This tool provides analytical information about a bytecode file. It is
21// intended as an aid to developers of bytecode reading and writing software. It
22// produces on std::out a summary of the bytecode file that shows various
Reid Spencerb3a4e0b2004-06-10 18:38:44 +000023// statistics about the contents of the file. By default this information is
24// detailed and contains information about individual bytecode blocks and the
25// functions in the module. To avoid this more detailed output, use the
26// -nodetails option to limit the output to just module level information.
27// The tool is also able to print a bytecode file in a straight forward text
28// format that shows the containment and relationships of the information in
29// the bytecode file (-dump option).
Reid Spencerdb5c86d2004-06-07 17:53:43 +000030//===----------------------------------------------------------------------===//
31
32#include "llvm/Bytecode/Analyzer.h"
33#include "Support/CommandLine.h"
34#include "llvm/System/Signals.h"
35#include <fstream>
36#include <iostream>
37
38using namespace llvm;
39
40static cl::opt<std::string>
41 InputFilename(cl::Positional, cl::desc("<input bytecode>"), cl::init("-"));
42
Reid Spencerb3a4e0b2004-06-10 18:38:44 +000043static cl::opt<bool> NoDetails ("nodetails", cl::desc("Skip detailed output"));
44static cl::opt<bool> Dump ("dump", cl::desc("Detailed output"));
Reid Spencerdb5c86d2004-06-07 17:53:43 +000045
46int
47main(int argc, char **argv)
48{
49 cl::ParseCommandLineOptions(argc, argv,
50 " llvm-abcd Analysis of ByteCode Dumper\n");
51
52 PrintStackTraceOnErrorSignal();
53
54 std::ostream* Out = &std::cout; // Default to printing to stdout...
55 std::istream* In = &std::cin; // Default to reading stdin
56 std::string ErrorMessage;
57 BytecodeAnalysis bca;
58
Reid Spencerddc6fb12004-06-08 05:56:58 +000059 /// Determine what to generate
60 bca.dumpBytecode = Dump;
Reid Spencerb3a4e0b2004-06-10 18:38:44 +000061 bca.detailedResults = !NoDetails;
Reid Spencerddc6fb12004-06-08 05:56:58 +000062
Reid Spencerdb5c86d2004-06-07 17:53:43 +000063 /// Analyze the bytecode file
64 AnalyzeBytecodeFile(InputFilename, bca, &ErrorMessage);
65
66 // If there was an error, print it and stop.
67 if ( ErrorMessage.size() ) {
68 std::cerr << argv[0] << ": " << ErrorMessage << "\n";
69 return 1;
70 }
71
Reid Spencerdb5c86d2004-06-07 17:53:43 +000072 // All that abcd does is write the gathered statistics to the output
Reid Spencerdb5c86d2004-06-07 17:53:43 +000073 PrintBytecodeAnalysis(bca,*Out);
74
75 if (Out != &std::cout) {
76 ((std::ofstream*)Out)->close();
77 delete Out;
78 }
79 return 0;
80}
81
82// vim: sw=2