aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Bytecode/Analyzer.h97
-rw-r--r--include/llvm/Instruction.h7
-rw-r--r--lib/Bytecode/Analyzer/Analyzer.cpp242
-rw-r--r--lib/Bytecode/Analyzer/AnalyzerInternals.h65
-rw-r--r--lib/Bytecode/Analyzer/AnalyzerWrappers.cpp208
-rw-r--r--lib/Bytecode/Analyzer/BytecodeHandler.cpp220
-rw-r--r--lib/Bytecode/Analyzer/BytecodeHandler.h247
-rw-r--r--lib/Bytecode/Analyzer/Dumper.cpp311
-rw-r--r--lib/Bytecode/Analyzer/Makefile13
-rw-r--r--lib/Bytecode/Analyzer/Parser.cpp877
-rw-r--r--lib/Bytecode/Analyzer/Parser.h178
-rw-r--r--lib/Bytecode/Analyzer/ReaderPrimitives.h101
-rw-r--r--lib/Bytecode/Makefile2
-rw-r--r--lib/Bytecode/Reader/Analyzer.cpp242
-rw-r--r--lib/Bytecode/Reader/AnalyzerInternals.h65
-rw-r--r--lib/Bytecode/Reader/AnalyzerWrappers.cpp208
-rw-r--r--lib/Bytecode/Reader/Dumper.cpp311
-rw-r--r--lib/Bytecode/Reader/Parser.cpp877
-rw-r--r--lib/Bytecode/Reader/Parser.h178
-rw-r--r--tools/Makefile3
-rw-r--r--tools/llvm-abcd/Makefile13
-rw-r--r--tools/llvm-abcd/llvm-abcd.cpp115
22 files changed, 4577 insertions, 3 deletions
diff --git a/include/llvm/Bytecode/Analyzer.h b/include/llvm/Bytecode/Analyzer.h
new file mode 100644
index 0000000000..d3e1b95503
--- /dev/null
+++ b/include/llvm/Bytecode/Analyzer.h
@@ -0,0 +1,97 @@
+//===-- llvm/Bytecode/Analyzer.h - Analyzer for bytecode files --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This functionality is implemented by the lib/Bytecode/Analysis library.
+// This library is used to read VM bytecode files from an iostream and print
+// out a diagnostic analysis of the contents of the file. It is intended for
+// three uses: (a) understanding the bytecode format, (b) ensuring correctness
+// of bytecode format, (c) statistical analysis of generated bytecode files.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_BYTECODE_ANALYZER_H
+#define LLVM_BYTECODE_ANALYZER_H
+
+#include <string>
+#include <map>
+
+namespace llvm {
+
+/// This structure is used to contain the output of the Bytecode Analysis
+/// library. It simply contains fields to hold each item of the analysis
+/// results.
+/// @brief Bytecode Analysis results structure
+struct BytecodeAnalysis {
+ unsigned byteSize; ///< The size of the bytecode file in bytes
+ unsigned numTypes; ///< The number of types
+ unsigned numValues; ///< The number of values
+ unsigned numFunctions; ///< The number of functions defined
+ unsigned numConstants; ///< The number of constants
+ unsigned numGlobalVars; ///< The number of global variables
+ unsigned numInstructions; ///< The number of instructions in all functions
+ unsigned numBasicBlocks; ///< The number of BBs in all functions
+ unsigned numOperands; ///< The number of BBs in all functions
+ unsigned maxTypeSlot; ///< The maximum slot number for types
+ unsigned maxValueSlot; ///< The maximum slot number for values
+ double density; ///< Density of file (bytes/defs)
+
+ /// A structure that contains various pieces of information related to
+ /// an analysis of a single function.
+ struct BytecodeFunctionInfo {
+ unsigned byteSize; ///< The size of the function in bytecode bytes
+ unsigned numInstructions; ///< The number of instructions in the function
+ unsigned numBasicBlocks; ///< The number of basic blocks in the function
+ unsigned numOperands; ///< The number of operands in the function
+ double density; ///< Density of function
+ double vbrEffectiveness; ///< Effectiveness of variable bit rate encoding.
+ ///< This is the average number of bytes per unsigned value written in the
+ ///< vbr encoding. A "perfect" score of 1.0 means all vbr values were
+ ///< encoded in one byte. A score between 1.0 and 4.0 means that some
+ ///< savings were achieved. A score of 4.0 means vbr didn't help. A score
+ ///< greater than 4.0 means vbr negatively impacted size of the file.
+ };
+
+ /// A mapping of function names to the collected information about the
+ /// function.
+ std::map<std::string,BytecodeFunctionInfo> FunctionInfo;
+
+ /// Flags for what should be done
+ bool dumpBytecode;
+};
+
+/// This function is the main entry point into the bytecode analysis library. It
+/// allows you to simply provide a \P filename and storage for the \P Results
+/// that will be filled in with the analysis results.
+/// @brief Analyze contents of a bytecode File
+void AnalyzeBytecodeFile(
+ const std::string& Filename, ///< The name of the bytecode file to read
+ BytecodeAnalysis& Results, ///< The results of the analysis
+ std::string* ErrorStr = 0 ///< Errors, if any.
+ );
+
+/// This function is an alternate entry point into the bytecode analysis
+/// library. It allows you to provide an arbitrary memory buffer which is
+/// assumed to contain a complete bytecode file. The \P Buffer is analyzed and
+/// the \P Results are filled in.
+/// @brief Analyze contents of a bytecode buffer.
+void AnalyzeBytecodeBuffer(
+ const unsigned char* Buffer, ///< Pointer to start of bytecode buffer
+ unsigned BufferSize, ///< Size of the bytecode buffer
+ BytecodeAnalysis& Results, ///< The results of the analysis
+ std::string* ErrorStr = 0 ///< Errors, if any.
+ );
+
+/// This function prints the contents of rhe BytecodeAnalysis structure in
+/// a human legible form.
+/// @brief Print BytecodeAnalysis structure to an ostream
+void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out );
+
+} // End llvm namespace
+
+#endif
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index 17eec871f7..caba4afd8b 100644
--- a/include/llvm/Instruction.h
+++ b/include/llvm/Instruction.h
@@ -87,9 +87,14 @@ public:
}
static const char* getOpcodeName(unsigned OpCode);
+ static inline bool isTerminator(unsigned OpCode) {
+ return OpCode >= TermOpsBegin && OpCode < TermOpsEnd;
+ }
+
inline bool isTerminator() const { // Instance of TerminatorInst?
- return iType >= TermOpsBegin && iType < TermOpsEnd;
+ return isTerminator(iType);
}
+
inline bool isBinaryOp() const {
return iType >= BinaryOpsBegin && iType < BinaryOpsEnd;
}
diff --git a/lib/Bytecode/Analyzer/Analyzer.cpp b/lib/Bytecode/Analyzer/Analyzer.cpp
new file mode 100644
index 0000000000..99c3e41f9f
--- /dev/null
+++ b/lib/Bytecode/Analyzer/Analyzer.cpp
@@ -0,0 +1,242 @@
+//===-- BytecodeHandler.cpp - Parsing Handler -------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This header file defines the BytecodeHandler class that gets called by the
+// AbstractBytecodeParser when parsing events occur.
+//
+//===----------------------------------------------------------------------===//
+
+#include "AnalyzerInternals.h"
+
+using namespace llvm;
+
+
+namespace {
+
+class AnalyzerHandler : public BytecodeHandler {
+public:
+ bool handleError(const std::string& str )
+ {
+ return false;
+ }
+
+ void handleStart()
+ {
+ }
+
+ void handleFinish()
+ {
+ }
+
+ void handleModuleBegin(const std::string& id)
+ {
+ }
+
+ void handleModuleEnd(const std::string& id)
+ {
+ }
+
+ void handleVersionInfo(
+ unsigned char RevisionNum, ///< Byte code revision number
+ Module::Endianness Endianness, ///< Endianness indicator
+ Module::PointerSize PointerSize ///< PointerSize indicator
+ )
+ {
+ }
+
+ void handleModuleGlobalsBegin()
+ {
+ }
+
+ void handleGlobalVariable(
+ const Type* ElemType, ///< The type of the global variable
+ bool isConstant, ///< Whether the GV is constant or not
+ GlobalValue::LinkageTypes ///< The linkage type of the GV
+ )
+ {
+ }
+
+ void handleInitializedGV(
+ const Type* ElemType, ///< The type of the global variable
+ bool isConstant, ///< Whether the GV is constant or not
+ GlobalValue::LinkageTypes,///< The linkage type of the GV
+ unsigned initSlot ///< Slot number of GV's initializer
+ )
+ {
+ }
+
+ virtual void handleType( const Type* Ty )
+ {
+ }
+
+ void handleFunctionDeclaration(
+ const Type* FuncType ///< The type of the function
+ )
+ {
+ }
+
+ void handleModuleGlobalsEnd()
+ {
+ }
+
+ void handleCompactionTableBegin()
+ {
+ }
+
+ void handleCompactionTablePlane(
+ unsigned Ty,
+ unsigned NumEntries
+ )
+ {
+ }
+
+ void handleCompactionTableType(
+ unsigned i,
+ unsigned TypSlot,
+ const Type*
+ )
+ {
+ }
+
+ void handleCompactionTableValue(
+ unsigned i,
+ unsigned ValSlot,
+ const Type*
+ )
+ {
+ }
+
+ void handleCompactionTableEnd()
+ {
+ }
+
+ void handleSymbolTableBegin()
+ {
+ }
+
+ void handleSymbolTablePlane(
+ unsigned Ty,
+ unsigned NumEntries,
+ const Type* Typ
+ )
+ {
+ }
+
+ void handleSymbolTableType(
+ unsigned i,
+ unsigned slot,
+ const std::string& name
+ )
+ {
+ }
+
+ void handleSymbolTableValue(
+ unsigned i,
+ unsigned slot,
+ const std::string& name
+ )
+ {
+ }
+
+ void handleSymbolTableEnd()
+ {
+ }
+
+ void handleFunctionBegin(
+ const Type* FType,
+ GlobalValue::LinkageTypes linkage
+ )
+ {
+ }
+
+ void handleFunctionEnd(
+ const Type* FType
+ )
+ {
+ }
+
+ void handleBasicBlockBegin(
+ unsigned blocknum
+ )
+ {
+ }
+
+ bool handleInstruction(
+ unsigned Opcode,
+ const Type* iType,
+ std::vector<unsigned>& Operands
+ )
+ {
+ return false;
+ }
+
+ void handleBasicBlockEnd(unsigned blocknum)
+ {
+ }
+
+ void handleGlobalConstantsBegin()
+ {
+ }
+
+ void handleConstantExpression(
+ unsigned Opcode,
+ const Type* Typ,
+ std::vector<std::pair<const Type*,unsigned> > ArgVec
+ )
+ {
+ }
+
+ void handleConstantValue( Constant * c )
+ {
+ }
+
+ void handleConstantArray(
+ const ArrayType* AT,
+ std::vector<unsigned>& Elements )
+ {
+ }
+
+ void handleConstantStruct(
+ const StructType* ST,
+ std::vector<unsigned>& ElementSlots)
+ {
+ }
+
+ void handleConstantPointer(
+ const PointerType* PT, unsigned Slot)
+ {
+ }
+
+ void handleConstantString( const ConstantArray* CA )
+ {
+ }
+
+
+ void handleGlobalConstantsEnd()
+ {
+ }
+
+};
+
+}
+
+void llvm::BytecodeAnalyzer::AnalyzeBytecode(
+ const unsigned char *Buf,
+ unsigned Length,
+ BytecodeAnalysis& bca,
+ const std::string &ModuleID
+)
+{
+ AnalyzerHandler TheHandler;
+ AbstractBytecodeParser TheParser(&TheHandler);
+ TheParser.ParseBytecode( Buf, Length, ModuleID );
+ TheParser.ParseAllFunctionBodies();
+}
+
+// vim: sw=2
diff --git a/lib/Bytecode/Analyzer/AnalyzerInternals.h b/lib/Bytecode/Analyzer/AnalyzerInternals.h
new file mode 100644
index 0000000000..d9a2e843d8
--- /dev/null
+++ b/lib/Bytecode/Analyzer/AnalyzerInternals.h
@@ -0,0 +1,65 @@
+//===-- ReaderInternals.h - Definitions internal to the reader --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This header file defines various stuff that is used by the bytecode reader.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef ANALYZER_INTERNALS_H
+#define ANALYZER_INTERNALS_H
+
+#include "Parser.h"
+#include "llvm/Bytecode/Analyzer.h"
+
+// Enable to trace to figure out what the heck is going on when parsing fails
+//#define TRACE_LEVEL 10
+//#define DEBUG_OUTPUT
+
+#if TRACE_LEVEL // ByteCodeReading_TRACEr
+#define BCR_TRACE(n, X) \
+ if (n < TRACE_LEVEL) std::cerr << std::string(n*2, ' ') << X
+#else
+#define BCR_TRACE(n, X)
+#endif
+
+namespace llvm {
+
+class BytecodeAnalyzer {
+ BytecodeAnalyzer(const BytecodeAnalyzer &); // DO NOT IMPLEMENT
+ void operator=(const BytecodeAnalyzer &); // DO NOT IMPLEMENT
+public:
+ BytecodeAnalyzer() { }
+ ~BytecodeAnalyzer() { }
+
+ void AnalyzeBytecode(
+ const unsigned char *Buf,
+ unsigned Length,
+ BytecodeAnalysis& bca,
+ const std::string &ModuleID
+ );
+
+ void DumpBytecode(
+ const unsigned char *Buf,
+ unsigned Length,
+ BytecodeAnalysis& bca,
+ const std::string &ModuleID
+ );
+
+ void dump() const {
+ std::cerr << "BytecodeParser instance!\n";
+ }
+private:
+ BytecodeAnalysis TheAnalysis;
+};
+
+} // End llvm namespace
+
+#endif
+
+// vim: sw=2
diff --git a/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp b/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp
new file mode 100644
index 0000000000..a0e4845a1b
--- /dev/null
+++ b/lib/Bytecode/Analyzer/AnalyzerWrappers.cpp
@@ -0,0 +1,208 @@
+//===- AnalyzerWrappers.cpp - Analyze bytecode from file or buffer -------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements loading and analysis of a bytecode file and analyzing a
+// bytecode buffer.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Bytecode/Analyzer.h"
+#include "AnalyzerInternals.h"
+#include "Support/FileUtilities.h"
+#include "Support/StringExtras.h"
+#include "Config/unistd.h"
+#include <cerrno>
+
+using namespace llvm;
+
+//===----------------------------------------------------------------------===//
+// BytecodeFileAnalyzer - Analyze from an mmap'able file descriptor.
+//
+
+namespace {
+ /// BytecodeFileAnalyzer - parses a bytecode file from a file
+ class BytecodeFileAnalyzer : public BytecodeAnalyzer {
+ private:
+ unsigned char *Buffer;
+ unsigned Length;
+
+ BytecodeFileAnalyzer(const BytecodeFileAnalyzer&); // Do not implement
+ void operator=(const BytecodeFileAnalyzer &BFR); // Do not implement
+
+ public:
+ BytecodeFileAnalyzer(const std::string &Filename, BytecodeAnalysis& bca);
+ ~BytecodeFileAnalyzer();
+ };
+}
+
+static std::string ErrnoMessage (int savedErrNum, std::string descr) {
+ return ::strerror(savedErrNum) + std::string(", while trying to ") + descr;
+}
+
+BytecodeFileAnalyzer::BytecodeFileAnalyzer(const std::string &Filename,
+ BytecodeAnalysis& bca) {
+ Buffer = (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
+ if (Buffer == 0)
+ throw "Error reading file '" + Filename + "'.";
+
+ try {
+ // Parse the bytecode we mmapped in
+ if ( bca.dumpBytecode )
+ DumpBytecode(Buffer, Length, bca, Filename);
+ AnalyzeBytecode(Buffer, Length, bca, Filename);
+ } catch (...) {
+ UnmapFileFromAddressSpace(Buffer, Length);
+ throw;
+ }
+}
+
+BytecodeFileAnalyzer::~BytecodeFileAnalyzer() {
+ // Unmmap the bytecode...
+ UnmapFileFromAddressSpace(Buffer, Length);
+}
+
+//===----------------------------------------------------------------------===//
+// BytecodeBufferAnalyzer - Read from a memory buffer
+//
+
+namespace {
+ /// BytecodeBufferAnalyzer - parses a bytecode file from a buffer
+ ///
+ class BytecodeBufferAnalyzer : public BytecodeAnalyzer {
+ private:
+ const unsigned char *Buffer;
+ bool MustDelete;
+
+ BytecodeBufferAnalyzer(const BytecodeBufferAnalyzer&); // Do not implement
+ void operator=(const BytecodeBufferAnalyzer &BFR); // Do not implement
+
+ public:
+ BytecodeBufferAnalyzer(const unsigned char *Buf, unsigned Length,
+ BytecodeAnalysis& bca, const std::string &ModuleID);
+ ~BytecodeBufferAnalyzer();
+
+ };
+}
+
+BytecodeBufferAnalyzer::BytecodeBufferAnalyzer(const unsigned char *Buf,
+ unsigned Length,
+ BytecodeAnalysis& bca,
+ const std::string &ModuleID) {
+ // If not aligned, allocate a new buffer to hold the bytecode...
+ const unsigned char *ParseBegin = 0;
+ if ((intptr_t)Buf & 3) {
+ Buffer = new unsigned char[Length+4];
+ unsigned Offset = 4 - ((intptr_t)Buffer & 3); // Make sure it's aligned
+ ParseBegin = Buffer + Offset;
+ memcpy((unsigned char*)ParseBegin, Buf, Length); // Copy it over
+ MustDelete = true;
+ } else {
+ // If we don't need to copy it over, just use the caller's copy
+ ParseBegin = Buffer = Buf;
+ MustDelete = false;
+ }
+ try {
+ if ( bca.dumpBytecode )
+ DumpBytecode(ParseBegin, Length, bca, ModuleID);
+ AnalyzeBytecode(ParseBegin, Length, bca, ModuleID);
+ } catch (...) {
+ if (MustDelete) delete [] Buffer;
+ throw;
+ }
+}
+
+BytecodeBufferAnalyzer::~BytecodeBufferAnalyzer() {
+ if (MustDelete) delete [] Buffer;
+}
+
+//===----------------------------------------------------------------------===//
+// BytecodeStdinAnalyzer - Read bytecode from Standard Input
+//
+
+namespace {
+ /// BytecodeStdinAnalyzer - parses a bytecode file from stdin
+ ///
+ class BytecodeStdinAnalyzer : public BytecodeAnalyzer {
+ private:
+ std::vector<unsigned char> FileData;
+ unsigned char *FileBuf;
+
+ BytecodeStdinAnalyzer(const BytecodeStdinAnalyzer&); // Do not implement
+ void operator=(const BytecodeStdinAnalyzer &BFR); // Do not implement
+
+ public:
+ BytecodeStdinAnalyzer(BytecodeAnalysis& bca);
+ };
+}
+
+BytecodeStdinAnalyzer::BytecodeStdinAnalyzer(BytecodeAnalysis& bca ) {
+ int BlockSize;
+ unsigned char Buffer[4096*4];
+
+ // Read in all of the data from stdin, we cannot mmap stdin...
+ while ((BlockSize = ::read(0 /*stdin*/, Buffer, 4096*4))) {
+ if (BlockSize == -1)
+ throw ErrnoMessage(errno, "read from standard input");
+
+ FileData.insert(FileData.end(), Buffer, Buffer+BlockSize);
+ }
+
+ if (FileData.empty())
+ throw std::string("Standard Input empty!");
+
+ FileBuf = &FileData[0];
+ if (bca.dumpBytecode)
+ DumpBytecode(&FileData[0], FileData.size(), bca, "<stdin>");
+ AnalyzeBytecode(FileBuf, FileData.size(), bca, "<stdin>");
+}
+
+//===----------------------------------------------------------------------===//
+// Wrapper functions
+//===----------------------------------------------------------------------===//
+
+// AnalyzeBytecodeFile - analyze one file
+void llvm::AnalyzeBytecodeFile(const std::string &Filename,
+ BytecodeAnalysis& bca,
+ std::string *ErrorStr)
+{
+ try {
+ if ( Filename != "-" )
+ BytecodeFileAnalyzer bfa(Filename,bca);
+ else
+ BytecodeStdinAnalyzer bsa(bca);
+ } catch (std::string &err) {
+ if (ErrorStr) *ErrorStr = err;
+ }
+}
+
+// AnalyzeBytecodeBuffer - analyze a buffer
+void llvm::AnalyzeBytecodeBuffer(
+ const unsigned char* Buffer, ///< Pointer to start of bytecode buffer
+ unsigned BufferSize, ///< Size of the bytecode buffer
+ BytecodeAnalysis& Results, ///< The results of the analysis
+ std::string* ErrorStr ///< Errors, if any.
+ )
+{
+ try {
+ BytecodeBufferAnalyzer(Buffer, BufferSize, Results, "<buffer>" );
+ } catch (std::string& err ) {
+ if ( ErrorStr) *ErrorStr = err;
+ }
+}
+
+
+/// This function prints the contents of rhe BytecodeAnalysis structure in
+/// a human legible form.
+/// @brief Print BytecodeAnalysis structure to an ostream
+void llvm::PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out )
+{
+ Out << "Not Implemented Yet.\n";
+}
+
+// vim: sw=2
diff --git a/lib/Bytecode/Analyzer/BytecodeHandler.cpp b/lib/Bytecode/Analyzer/BytecodeHandler.cpp
new file mode 100644
index 0000000000..2415958867
--- /dev/null
+++ b/lib/Bytecode/Analyzer/BytecodeHandler.cpp
@@ -0,0 +1,220 @@
+//===-- BytecodeHandler.cpp - Parsing Handler -------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This header file defines the BytecodeHandler class that gets called by the
+// AbstractBytecodeParser when parsing events occur.
+//
+//===----------------------------------------------------------------------===//
+
+#include "BytecodeHandler.h"
+
+using namespace llvm;
+
+bool BytecodeHandler::handleError(const std::string& str )
+{
+ return false;
+}
+
+void BytecodeHandler::handleStart()
+{
+}
+
+void BytecodeHandler::handleFinish()
+{
+}
+
+void BytecodeHandler::handleModuleBegin(const std::string& id)
+{
+}
+
+void BytecodeHandler::handleModuleEnd(const std::string& id)
+{
+}
+
+void BytecodeHandler::handleVersionInfo(
+ unsigned char RevisionNum, ///< Byte code revision number
+ Module::Endianness Endianness, ///< Endianness indicator
+ Module::PointerSize PointerSize ///< PointerSize indicator
+)
+{
+}
+
+void BytecodeHandler::handleModuleGlobalsBegin()
+{
+}
+
+void BytecodeHandler::handleGlobalVariable(
+ const Type* ElemType, ///< The type of the global variable
+ bool isConstant, ///< Whether the GV is constant or not
+ GlobalValue::LinkageTypes ///< The linkage type of the GV
+)
+{
+}
+
+void BytecodeHandler::handleInitializedGV(
+ const Type* ElemType, ///< The type of the global variable
+ bool isConstant, ///< Whether the GV is constant or not
+ GlobalValue::LinkageTypes,///< The linkage type of the GV
+ unsigned initSlot ///< Slot number of GV's initializer
+)
+{
+}
+
+void BytecodeHandler::handleType( const Type* Ty )
+{
+}
+
+void BytecodeHandler::handleFunctionDeclaration(
+ const Type* FuncType ///< The type of the function
+)
+{
+}
+
+void BytecodeHandler::handleModuleGlobalsEnd()
+{
+}
+
+void BytecodeHandler::handleCompactionTableBegin()
+{
+}
+
+void BytecodeHandler::handleCompactionTablePlane(
+ unsigned Ty,
+ unsigned NumEntries
+)
+{
+}
+
+void BytecodeHandler::handleCompactionTableType(
+ unsigned i,
+ unsigned TypSlot,
+ const Type*
+)
+{
+}
+
+void BytecodeHandler::handleCompactionTableValue(
+ unsigned i,
+ unsigned ValSlot,
+ const Type*
+)
+{
+}
+
+void BytecodeHandler::handleCompactionTableEnd()
+{
+}
+
+void BytecodeHandler::handleSymbolTableBegin()
+{
+}
+
+void BytecodeHandler::handleSymbolTablePlane(
+ unsigned Ty,
+ unsigned NumEntries,
+ const Type* Typ
+)
+{
+}
+
+void BytecodeHandler::handleSymbolTableType(
+ unsigned i,
+ unsigned slot,
+ const std::string& name
+)
+{
+}
+
+void BytecodeHandler::handleSymbolTableValue(
+ unsigned i,
+ unsigned slot,
+ const std::string& name
+)
+{
+}
+
+void BytecodeHandler::handleSymbolTableEnd()
+{
+}
+
+void BytecodeHandler::handleFunctionBegin(
+ const Type* FType,
+ GlobalValue::LinkageTypes linkage
+)
+{
+}
+
+void BytecodeHandler::handleFunctionEnd(
+ const Type* FType
+)
+{
+}
+
+void BytecodeHandler::handleBasicBlockBegin(
+ unsigned blocknum
+)
+{
+}
+
+bool BytecodeHandler::handleInstruction(
+ unsigned Opcode,
+ const Type* iType,
+ std::vector<unsigned>& Operands
+)
+{
+ return false;
+}
+
+void BytecodeHandler::handleBasicBlockEnd(unsigned blocknum)
+{
+}
+
+void BytecodeHandler::handleGlobalConstantsBegin()
+{
+}
+
+void BytecodeHandler::handleConstantExpression(
+ unsigned Opcode,
+ const Type* Typ,
+ std::vector<std::pair<const Type*,unsigned> > ArgVec
+ )
+{
+}
+
+void BytecodeHandler::handleConstantValue( Constant * c )
+{
+}
+
+void BytecodeHandler::handleConstantArray(
+ const ArrayType* AT,
+ std::vector<unsigned>& Elements )
+{
+}
+
+void BytecodeHandler::handleConstantStruct(
+ const StructType* ST,
+ std::vector<unsigned>& ElementSlots)
+{
+}
+
+void BytecodeHandler::handleConstantPointer(
+ const PointerType* PT, unsigned Slot)
+{
+}
+
+void BytecodeHandler::handleConstantString( const ConstantArray* CA )
+{
+}
+
+
+void BytecodeHandler::handleGlobalConstantsEnd()
+{
+}
+
+// vim: sw=2
diff --git a/lib/Bytecode/Analyzer/BytecodeHandler.h b/lib/Bytecode/Analyzer/BytecodeHandler.h
new file mode 100644
index 0000000000..2b03e2d332
--- /dev/null
+++ b/lib/Bytecode/Analyzer/BytecodeHandler.h
@@ -0,0 +1,247 @@
+//===-- BytecodeHandler.h - Parsing Handler ---------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This header file defines the BytecodeHandler class that gets called by the
+// AbstractBytecodeParser when parsing events occur.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef BYTECODE_HANDLER_H
+#define BYTECODE_HANDLER_H
+
+#include "llvm/Module.h"
+#include "llvm/GlobalValue.h"
+#include <vector>
+
+namespace llvm {
+
+class ArrayType;
+class StructType;
+class PointerType;
+class ConstantArray;
+
+/// This class provides the interface for the handling bytecode events during
+/// parsing. The methods on this interface are invoked by the
+/// AbstractBytecodeParser as it discovers the content of a bytecode stream.
+/// This class provides a a clear separation of concerns between recognizing
+/// the semantic units of a bytecode file and deciding what to do with them.
+/// The AbstractBytecodeParser recognizes the content of the bytecode file and
+/// calls the BytecodeHandler methods to determine what should be done. This
+/// arrangement allows Bytecode files to be read and handled for a number of
+/// purposes simply by creating a subclass of BytecodeHandler. None of the
+/// parsing details need to be understood, only the meaning of the calls
+/// made on this interface.
+///
+/// Another paradigm that uses this design pattern is the XML SAX Parser. The
+/// ContentHandler for SAX plays the same role as the BytecodeHandler here.
+/// @brief Handle Bytecode Parsing Events
+class BytecodeHandler {
+
+/// @name Constructors And Operators
+/// @{
+public:
+ /// @brief Default constructor (empty)
+ BytecodeHandler() {}
+ /// @brief Virtual destructor (empty)
+ virtual ~BytecodeHandler() {}
+
+private:
+ BytecodeHandler(const BytecodeHandler &); // DO NOT IMPLEMENT
+ void operator=(const BytecodeHandler &); // DO NOT IMPLEMENT
+
+/// @}
+/// @name Handler Methods
+/// @{
+public:
+
+ /// This method is called whenever the parser detects an error in the
+ /// bytecode formatting. Returning true will cause the parser to keep
+ /// going, however this is inadvisable in most cases. Returning false will
+ /// cause the parser to throw the message as a std::string.
+ /// @brief Handle parsing errors.
+ virtual bool handleError(const std::string& str );
+
+ /// This method is called at the beginning of a parse before anything is
+ /// read in order to give the handler a chance to initialize.
+ /// @brief Handle the start of a bytecode parse
+ virtual void handleStart();
+
+ /// This method is called at the end of a parse after everything has been
+ /// read in order to give the handler a chance to terminate.
+ /// @brief Handle the end of a bytecode parse
+ virtual void handleFinish();
+
+ /// This method is called at the start of a module to indicate that a
+ /// module is being parsed.
+ /// @brief Handle the start of a module.
+ virtual void handleModuleBegin(const std::string& id);
+
+ /// This method is called at the end of a module to indicate that the module
+ /// previously being parsed has concluded.
+ /// @brief Handle the end of a module.
+ virtual void handleModuleEnd(const std::string& id);
+
+ /// This method is called once the version information has been parsed. It
+ /// provides the information about the version of the bytecode file being