2004-06-25 04:32:27 +02:00
|
|
|
//===-- BytecodeHandler.h - Handle Bytecode Parsing Events ------*- C++ -*-===//
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2004-06-25 01:05:07 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-04-21 22:39:54 +02:00
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
2004-06-25 01:05:07 +02:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 22:39:54 +02:00
|
|
|
//
|
2004-06-25 01:05:07 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This header file defines the interface to the Bytecode Handler. The handler
|
2004-06-25 04:32:27 +02:00
|
|
|
// is called by the Bytecode Reader to obtain out-of-band parsing events for
|
2004-06-25 01:05:07 +02:00
|
|
|
// tasks other then LLVM IR construction.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-06-30 01:18:52 +02:00
|
|
|
#ifndef LLVM_BYTECODE_BYTECODEHANDLER_H
|
|
|
|
#define LLVM_BYTECODE_BYTECODEHANDLER_H
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2004-06-25 04:32:27 +02:00
|
|
|
#include "llvm/Module.h"
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class ArrayType;
|
|
|
|
class StructType;
|
|
|
|
class PointerType;
|
2007-02-15 03:26:10 +01:00
|
|
|
class VectorType;
|
2004-06-25 01:05:07 +02:00
|
|
|
class ConstantArray;
|
2004-06-30 01:18:52 +02:00
|
|
|
class Module;
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// This class provides the interface for handling bytecode events during
|
2005-04-21 22:39:54 +02:00
|
|
|
/// reading of bytecode. The methods on this interface are invoked by the
|
|
|
|
/// BytecodeReader 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 (the Reader) and deciding what to do
|
|
|
|
/// with them (the Handler).
|
2004-06-25 04:32:27 +02:00
|
|
|
///
|
2004-06-25 01:05:07 +02:00
|
|
|
/// The BytecodeReader recognizes the content of the bytecode file and
|
|
|
|
/// calls the BytecodeHandler methods to let it perform additional tasks. 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.
|
2005-04-21 22:39:54 +02:00
|
|
|
///
|
2004-06-25 01:05:07 +02:00
|
|
|
/// @see BytecodeHandler
|
|
|
|
/// @brief Handle Bytecode Parsing Events
|
|
|
|
class BytecodeHandler {
|
|
|
|
|
|
|
|
/// @name Constructors And Operators
|
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// @brief Default constructor (empty)
|
|
|
|
BytecodeHandler() {}
|
|
|
|
/// @brief Virtual destructor (empty)
|
2004-06-25 04:32:27 +02:00
|
|
|
virtual ~BytecodeHandler();
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
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
|
2004-06-25 04:32:27 +02:00
|
|
|
/// bytecode formatting. It gives the handler a chance to do something
|
2005-04-21 22:39:54 +02:00
|
|
|
/// with the error message before the parser throws an exception to
|
|
|
|
/// terminate the parsing.
|
2004-06-25 01:05:07 +02:00
|
|
|
/// @brief Handle parsing errors.
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleError(const std::string& str ) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// 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
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleStart( Module* Mod, unsigned byteSize ) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// 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
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleFinish() {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// 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.
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleModuleBegin(const std::string& moduleId) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// 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& moduleId ///< An identifier for the module
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
/// This method is called once the version information has been parsed. It
|
|
|
|
/// provides the information about the version of the bytecode file being
|
2004-06-25 01:05:07 +02:00
|
|
|
/// read.
|
|
|
|
/// @brief Handle the bytecode prolog
|
|
|
|
virtual void handleVersionInfo(
|
2007-01-26 09:09:01 +01:00
|
|
|
unsigned char RevisionNum ///< Byte code revision number
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// This method is called at the start of a module globals block which
|
|
|
|
/// contains the global variables and the function placeholders
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleModuleGlobalsBegin() {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
/// This method is called when a non-initialized global variable is
|
2004-06-25 01:05:07 +02:00
|
|
|
/// recognized. Its type, constness, and linkage type are provided.
|
|
|
|
/// @brief Handle a non-initialized global variable
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleGlobalVariable(
|
2004-06-25 01:05:07 +02:00
|
|
|
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
|
2007-01-12 20:20:47 +01:00
|
|
|
GlobalValue::VisibilityTypes,///< The visibility style of the GV
|
2004-06-25 01:05:07 +02:00
|
|
|
unsigned SlotNum, ///< Slot number of GV
|
|
|
|
unsigned initSlot ///< Slot number of GV's initializer (0 if none)
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2004-08-21 22:41:12 +02:00
|
|
|
/// This method is called when a type list is recognized. It simply
|
|
|
|
/// provides the number of types that the list contains. The handler
|
|
|
|
/// should expect that number of calls to handleType.
|
|
|
|
/// @brief Handle a type
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleTypeList(
|
2004-08-21 22:41:12 +02:00
|
|
|
unsigned numEntries ///< The number of entries in the type list
|
|
|
|
) {}
|
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
/// This method is called when a new type is recognized. The type is
|
2004-06-25 01:05:07 +02:00
|
|
|
/// converted from the bytecode and passed to this method.
|
|
|
|
/// @brief Handle a type
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleType(
|
2004-06-25 01:05:07 +02:00
|
|
|
const Type* Ty ///< The type that was just recognized
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// This method is called when the function prototype for a function is
|
|
|
|
/// encountered in the module globals block.
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleFunctionDeclaration(
|
2004-06-25 04:32:27 +02:00
|
|
|
Function* Func ///< The function being declared
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2004-06-30 01:18:52 +02:00
|
|
|
/// This method is called when a global variable is initialized with
|
|
|
|
/// its constant value. Because of forward referencing, etc. this is
|
|
|
|
/// done towards the end of the module globals block
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleGlobalInitializer(GlobalVariable*, Constant* ) {}
|
2004-06-30 01:18:52 +02:00
|
|
|
|
2004-08-21 22:41:12 +02:00
|
|
|
/// This method is called for each dependent library name found
|
|
|
|
/// in the module globals block.
|
|
|
|
virtual void handleDependentLibrary(const std::string& libName) {}
|
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
/// This method is called if the module globals has a non-empty target
|
2004-08-21 22:41:12 +02:00
|
|
|
/// triple
|
|
|
|
virtual void handleTargetTriple(const std::string& triple) {}
|
|
|
|
|
2004-06-25 01:05:07 +02:00
|
|
|
/// This method is called at the end of the module globals block.
|
|
|
|
/// @brief Handle end of module globals block.
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleModuleGlobalsEnd() {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle start of a symbol table
|
2007-02-05 21:47:22 +01:00
|
|
|
virtual void handleTypeSymbolTableBegin(
|
|
|
|
TypeSymbolTable* ST ///< The symbol table being filled
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2007-02-05 21:47:22 +01:00
|
|
|
/// @brief Handle start of a symbol table
|
|
|
|
virtual void handleValueSymbolTableBegin(
|
|
|
|
Function* Func, ///< The function to which the ST belongs or 0 for Mod
|
|
|
|
ValueSymbolTable* ST ///< The symbol table being filled
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle a named type in the symbol table
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleSymbolTableType(
|
2004-06-25 01:05:07 +02:00
|
|
|
unsigned i, ///< The index of the type in this plane
|
|
|
|
unsigned slot, ///< Slot number of the named type
|
|
|
|
const std::string& name ///< Name of the type
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle a named value in the symbol table
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleSymbolTableValue(
|
2004-06-25 01:05:07 +02:00
|
|
|
unsigned i, ///< The index of the value in this plane
|
|
|
|
unsigned slot, ///< Slot number of the named value
|
2007-02-12 19:53:43 +01:00
|
|
|
const char *name, unsigned NameLen ///< Name of the value.
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2007-02-05 21:47:22 +01:00
|
|
|
/// @brief Handle the end of a value symbol table
|
|
|
|
virtual void handleTypeSymbolTableEnd() {}
|
|
|
|
|
|
|
|
/// @brief Handle the end of a type symbol table
|
|
|
|
virtual void handleValueSymbolTableEnd() {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle the beginning of a function body
|
|
|
|
virtual void handleFunctionBegin(
|
|
|
|
Function* Func, ///< The function being defined
|
|
|
|
unsigned Size ///< The size (in bytes) of the function's bytecode
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle the end of a function body
|
|
|
|
virtual void handleFunctionEnd(
|
|
|
|
Function* Func ///< The function whose definition has just finished.
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle the beginning of a basic block
|
|
|
|
virtual void handleBasicBlockBegin(
|
|
|
|
unsigned blocknum ///< The block number of the block
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
/// This method is called for each instruction that is parsed.
|
2004-06-25 01:05:07 +02:00
|
|
|
/// @returns true if the instruction is a block terminating instruction
|
|
|
|
/// @brief Handle an instruction
|
|
|
|
virtual bool handleInstruction(
|
|
|
|
unsigned Opcode, ///< Opcode of the instruction
|
|
|
|
const Type* iType, ///< Instruction type
|
2007-02-07 06:09:50 +01:00
|
|
|
unsigned *Operands, unsigned NumOps, ///< Vector of slot # operands
|
2007-02-05 21:47:22 +01:00
|
|
|
Instruction *Inst, ///< The resulting instruction
|
2004-06-25 01:05:07 +02:00
|
|
|
unsigned Length ///< Length of instruction in bc bytes
|
2004-07-04 13:29:56 +02:00
|
|
|
) { return false; }
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle the end of a basic block
|
|
|
|
virtual void handleBasicBlockEnd(
|
|
|
|
unsigned blocknum ///< The block number of the block just finished
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle start of global constants block.
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleGlobalConstantsBegin() {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle a constant expression
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleConstantExpression(
|
2004-06-25 01:05:07 +02:00
|
|
|
unsigned Opcode, ///< Opcode of primary expression operator
|
2007-02-07 06:09:50 +01:00
|
|
|
Constant**Args, unsigned NumArgs, ///< expression args
|
2004-06-30 01:18:52 +02:00
|
|
|
Constant* C ///< The constant value
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle a constant array
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleConstantArray(
|
2004-06-25 01:05:07 +02:00
|
|
|
const ArrayType* AT, ///< Type of the array
|
2007-02-07 06:09:50 +01:00
|
|
|
Constant**ElementSlots, unsigned NumElts,///< Slot nums for array values
|
2004-06-30 01:18:52 +02:00
|
|
|
unsigned TypeSlot, ///< Slot # of type
|
|
|
|
Constant* Val ///< The constant value
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2005-04-21 22:39:54 +02:00
|
|
|
/// @brief Handle a constant structure
|
|
|
|
virtual void handleConstantStruct(
|
2004-06-25 01:05:07 +02:00
|
|
|
const StructType* ST, ///< Type of the struct
|
2007-02-07 06:09:50 +01:00
|
|
|
Constant**ElementSlots, unsigned NumElts,///< Slot nums for struct values
|
2004-06-30 01:18:52 +02:00
|
|
|
Constant* Val ///< The constant value
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
2004-08-20 08:00:58 +02:00
|
|
|
/// @brief Handle a constant packed
|
2007-02-15 03:26:10 +01:00
|
|
|
virtual void handleConstantVector(
|
|
|
|
const VectorType* PT, ///< Type of the array
|
2007-02-07 06:09:50 +01:00
|
|
|
Constant**ElementSlots, unsigned NumElts,///< Slot nums for packed values
|
2004-08-20 08:00:58 +02:00
|
|
|
unsigned TypeSlot, ///< Slot # of type
|
|
|
|
Constant* Val ///< The constant value
|
|
|
|
) {}
|
|
|
|
|
2004-06-25 01:05:07 +02:00
|
|
|
/// @brief Handle a constant pointer
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleConstantPointer(
|
2004-06-25 01:05:07 +02:00
|
|
|
const PointerType* PT, ///< Type of the pointer
|
2004-06-30 01:18:52 +02:00
|
|
|
unsigned Slot, ///< Slot num of initializer value
|
2004-07-18 01:23:30 +02:00
|
|
|
GlobalValue* GV ///< Referenced global value
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle a constant strings (array special case)
|
|
|
|
virtual void handleConstantString(
|
|
|
|
const ConstantArray* CA ///< Type of the string array
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle a primitive constant value
|
2005-04-21 22:39:54 +02:00
|
|
|
virtual void handleConstantValue(
|
2004-06-25 01:05:07 +02:00
|
|
|
Constant * c ///< The constant just defined
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle the end of the global constants
|
2004-07-04 13:29:56 +02:00
|
|
|
virtual void handleGlobalConstantsEnd() {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle an alignment event
|
|
|
|
virtual void handleAlignment(
|
|
|
|
unsigned numBytes ///< The number of bytes added for alignment
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @brief Handle a bytecode block
|
|
|
|
virtual void handleBlock(
|
|
|
|
unsigned BType, ///< The type of block
|
|
|
|
const unsigned char* StartPtr, ///< The start of the block
|
|
|
|
unsigned Size ///< The size of the block
|
2004-07-04 13:29:56 +02:00
|
|
|
) {}
|
2004-06-25 01:05:07 +02:00
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|