mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-10 02:36:06 +00:00
dac69c83c2
will (eventually) provide statistical analysis of bytecode files as well as the ability to dump them in a low level format (slot numbers not resolved). The purpose of this is to aid in the Type!=Value change of bug 122. With this initial release, llvm-abcd merely dumps out the bytecode. However, the infrastructure for separating bytecode parsing from handling the parsing events is in place. The style chosen is similar to SAX XML parsing where a handler object is called to handlign the parsing events. This probably isn't useful to anyone but me right now as there is no analysis yet, and the dumper doesn't work on every bytecode file. It will probably be useful by the end of this week. Note that there is some duplication of code from the bytecode reader. This was done to eliminate errors from being introduced in the reader and to minimize the impact to other LLVM developers. At some point, the Analyzer and the Reader will be integrated to use the same infrastructure. Also, sorry for the minor change to Instruction.h but I just couldn't bring myself to write code that depends on Instruction internals. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14048 91177308-0d34-0410-b5e6-96231b3b80d8
243 lines
4.1 KiB
C++
243 lines
4.1 KiB
C++
//===-- 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
|