LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

llvm::BytecodeReader Class Reference

Forward declare the handler interfaceBytecode Reader interface. More...

#include <Reader.h>

Inheritance diagram for llvm::BytecodeReader:

Inheritance graph
[legend]
Collaboration diagram for llvm::BytecodeReader:

Collaboration graph
[legend]
List of all members.

Public Types

Types
typedef const unsigned char * BufPtr
 A convenience type for the buffer pointer.
typedef std::vector< PATypeHolderTypeListTy
 The type used for a vector of potentially abstract types.
typedef std::vector< ValueList * > ValueTable
 A 2 dimensional table of values.
typedef std::map< std::pair<
const Type *, unsigned >,
Constant * > 
ConstantRefsType
 A mapping of a Type/slot pair to a Constant*.
typedef std::map< Function *,
LazyFunctionInfo
LazyFunctionMap
 A mapping of functions to their LazyFunctionInfo for lazy reading.
typedef std::vector< std::pair<
GlobalVariable *, unsigned > > 
GlobalInitsList
 A list of global variables and the slot number that initializes them.
typedef std::map< std::pair<
unsigned, unsigned >, Value * > 
ForwardReferenceMap
 A map for dealing with forward references of values.

Public Member Functions

Constructors
 BytecodeReader (BytecodeHandler *h=0)
 Default constructor. By default, no handler is used.
 ~BytecodeReader ()
Methods
void ParseBytecode (const unsigned char *Buf, unsigned Length, const std::string &ModuleID)
 Main interface to parsing a bytecode buffer.
void ParseAllFunctionBodies ()
 Parse all function bodies.
void ParseFunction (Function *Func)
 Parse the next function of specific type.
virtual void materializeFunction (Function *F)
 Make a specific function materialize.
virtual ModulematerializeModule ()
 Make the whole module materialize.
ModulereleaseModule ()
 Release our hold on the generated module.

Protected Member Functions

Parsing Units For Subclasses
void ParseModule ()
 Parse whole module scope.
void ParseVersionInfo ()
 Parse the version information block.
void ParseModuleGlobalInfo ()
 Parse the ModuleGlobalInfo block.
void ParseSymbolTable (Function *Func, SymbolTable *ST)
 Parse a symbol table.
void ParseFunctionLazily ()
 Parse functions lazily.
void ParseFunctionBody (Function *Func)
 Parse a function body.
void ParseCompactionTypes (unsigned NumEntries)
 Parse the type list portion of a compaction table.
void ParseCompactionTable ()
 Parse a compaction table.
void ParseGlobalTypes ()
 Parse global types.
BasicBlockParseBasicBlock (unsigned BlockNo)
 Parse a basic block (for LLVM 1.0 basic block blocks).
unsigned ParseInstructionList (Function *F)
 parse an instruction list (for post LLVM 1.0 instruction lists with blocks differentiated by terminating instructions.
void ParseInstruction (std::vector< unsigned > &Args, BasicBlock *BB)
 Parse a single instruction.
void ParseConstantPool (ValueTable &Values, TypeListTy &Types, bool isFunction)
 Parse the whole constant pool.
ConstantParseConstantValue (unsigned TypeID)
 Parse a single constant value.
void ParseTypes (TypeListTy &Tab, unsigned NumEntries)
 Parse a block of types constants.
const TypeParseType ()
 Parse a single type constant.
void ParseStringConstants (unsigned NumEntries, ValueTable &Tab)
 Parse a string constants block.

Classes

struct  LazyFunctionInfo
 Keeps pointers to function contents for later use. More...
struct  ValueList
 A list of values as a User of those Values. More...

Detailed Description

Forward declare the handler interfaceBytecode Reader interface.

This class defines the interface for parsing a buffer of bytecode. The parser itself takes no action except to call the various functions of the handler interface. The parser's sole responsibility is the correct interpretation of the bytecode buffer. The handler is responsible for instantiating and keeping track of all values. As a convenience, the parser is responsible for materializing types and will pass them through the handler interface as necessary.

See also:
BytecodeHandler

Definition at line 41 of file lib/Bytecode/Reader/Reader.h.


Member Typedef Documentation

typedef const unsigned char* llvm::BytecodeReader::BufPtr
 

A convenience type for the buffer pointer.

Definition at line 66 of file lib/Bytecode/Reader/Reader.h.

typedef std::map<std::pair<const Type*,unsigned>, Constant*> llvm::BytecodeReader::ConstantRefsType
 

A mapping of a Type/slot pair to a Constant*.

This map is needed so that forward references to constants can be looked up by Type and slot number when resolving those references.

Definition at line 105 of file lib/Bytecode/Reader/Reader.h.

typedef std::map<std::pair<unsigned,unsigned>,Value*> llvm::BytecodeReader::ForwardReferenceMap
 

A map for dealing with forward references of values.

This type maps a typeslot/valueslot pair to the corresponding Value*. It is used for dealing with forward references as values are read in.

Definition at line 128 of file lib/Bytecode/Reader/Reader.h.

typedef std::vector<std::pair<GlobalVariable*, unsigned> > llvm::BytecodeReader::GlobalInitsList
 

A list of global variables and the slot number that initializes them.

Definition at line 123 of file lib/Bytecode/Reader/Reader.h.

typedef std::map<Function*, LazyFunctionInfo> llvm::BytecodeReader::LazyFunctionMap
 

A mapping of functions to their LazyFunctionInfo for lazy reading.

Definition at line 119 of file lib/Bytecode/Reader/Reader.h.

typedef std::vector<PATypeHolder> llvm::BytecodeReader::TypeListTy
 

The type used for a vector of potentially abstract types.

Definition at line 69 of file lib/Bytecode/Reader/Reader.h.

typedef std::vector<ValueList*> llvm::BytecodeReader::ValueTable
 

A 2 dimensional table of values.

Definition at line 100 of file lib/Bytecode/Reader/Reader.h.


Constructor & Destructor Documentation

llvm::BytecodeReader::BytecodeReader BytecodeHandler h = 0  )  [inline]
 

Default constructor. By default, no handler is used.

Definition at line 47 of file lib/Bytecode/Reader/Reader.h.

llvm::BytecodeReader::~BytecodeReader  )  [inline]
 

Definition at line 52 of file lib/Bytecode/Reader/Reader.h.


Member Function Documentation

virtual void llvm::BytecodeReader::materializeFunction Function F  )  [inline, virtual]
 

Make a specific function materialize.

This method is abstract in the parent ModuleProvider class. Its implementation is identical to the ParseFunction method.

See also:
ParseFunction

Implements llvm::ModuleProvider.

Definition at line 151 of file lib/Bytecode/Reader/Reader.h.

References ParseFunction().

virtual Module* llvm::BytecodeReader::materializeModule  )  [inline, virtual]
 

Make the whole module materialize.

This method is abstract in the parent ModuleProvider class. Its implementation is identical to ParseAllFunctionBodies.

See also:
ParseAllFunctionBodies

Implements llvm::ModuleProvider.

Definition at line 161 of file lib/Bytecode/Reader/Reader.h.

References ParseAllFunctionBodies(), and llvm::ModuleProvider::TheModule.

void BytecodeReader::ParseAllFunctionBodies  ) 
 

Parse all function bodies.

The ParseAllFunctionBodies method parses through all the previously unparsed functions in the bytecode file. If you want to completely parse a bytecode file, this method should be called after Parsebytecode because Parsebytecode only records the locations in the bytecode file of where the function definitions are located. This function uses that information to materialize the functions.

See also:
ParseBytecode

Definition at line 1792 of file Reader.cpp.

References ParseFunctionBody().

Referenced by materializeModule().

BasicBlock * BytecodeReader::ParseBasicBlock unsigned  BlockNo  )  [protected]
 

Parse a basic block (for LLVM 1.0 basic block blocks).

In LLVM 1.0 bytecode files, we used to output one basicblock at a time. This method reads in one of the basicblock packets. This method is not used for bytecode files after LLVM 1.0

Returns:
The basic block constructed.

Definition at line 953 of file Reader.cpp.

References llvm::ISD::BasicBlock, and ParseInstruction().

Referenced by ParseFunctionBody().

void llvm::BytecodeReader::ParseBytecode const unsigned char *  Buf,
unsigned  Length,
const std::string &  ModuleID
 

Main interface to parsing a bytecode buffer.

Parameters:
Buf  Beginning of the bytecode buffer
Length  Length of the bytecode buffer
ModuleID  An identifier for the module constructed.

void BytecodeReader::ParseCompactionTable  )  [protected]
 

Parse a compaction table.

Definition at line 1088 of file Reader.cpp.

References llvm::Constant::getNullValue(), and ParseCompactionTypes().

Referenced by ParseFunctionBody().

void BytecodeReader::ParseCompactionTypes unsigned  NumEntries  )  [protected]
 

Parse the type list portion of a compaction table.

Definition at line 1076 of file Reader.cpp.

Referenced by ParseCompactionTable().

void BytecodeReader::ParseConstantPool ValueTable Tab,
TypeListTy TypeTab,
bool  isFunction
[protected]
 

Parse the whole constant pool.

In LLVM 1.3 Type does not derive from Value so the types do not occupy a plane. Consequently, we read the types first in the constant pool.

In LLVM 1.2 and before, Types were written to the bytecode file in the "Type Type" plane (#12). In 1.3 plane 12 is now the label plane. Handle this here.

Use of Type::VoidTyID is a misnomer. It actually means that the following plane is constant strings

Definition at line 1527 of file Reader.cpp.

References llvm::Type::getDescription(), llvm::Value::getName(), ParseConstantValue(), ParseStringConstants(), ParseTypes(), llvm::utostr(), and llvm::Type::VoidTyID.

Referenced by ParseFunctionBody(), and ParseModule().

Constant * BytecodeReader::ParseConstantValue unsigned  TypeID  )  [protected]
 

Parse a single constant value.

Definition at line 1280 of file Reader.cpp.

References llvm::Type::ArrayTyID, llvm::Type::BoolTyID, llvm::Instruction::Cast, llvm::Type::DoubleTyID, E, llvm::Type::FloatTyID, llvm::gep_type_begin(), llvm::gep_type_end(), llvm::ConstantPacked::get(), llvm::ConstantStruct::get(), llvm::ConstantArray::get(), llvm::ConstantFP::get(), llvm::ConstantSInt::get(), llvm::ConstantUInt::get(), llvm::ConstantBool::get(), llvm::ConstantExpr::get(), llvm::UndefValue::get(), llvm::ConstantExpr::getCast(), llvm::Type::getDescription(), llvm::StructType::getElementType(), llvm::SequentialType::getElementType(), llvm::ConstantExpr::getGetElementPtr(), llvm::PackedType::getNumElements(), llvm::StructType::getNumElements(), llvm::ArrayType::getNumElements(), llvm::ConstantExpr::getSelect(), llvm::Value::getType(), llvm::Type::getTypeID(), llvm::Type::IntTyID, llvm::ConstantSInt::isValueValidForType(), llvm::ConstantUInt::isValueValidForType(), llvm::Type::LongTyID, llvm::Type::PackedTyID, llvm::Type::PointerTyID, llvm::Type::SByteTyID, llvm::Instruction::Select, llvm::Type::ShortTyID, llvm::Type::StructTyID, llvm::Type::UByteTy, llvm::Type::UByteTyID, llvm::Type::UIntTy, llvm::Type::UIntTyID, llvm::Type::ULongTyID, and llvm::Type::UShortTyID.

Referenced by ParseConstantPool().

void BytecodeReader::ParseFunction Function Func  ) 
 

Parse the next function of specific type.

The ParserFunction method lazily parses one function. Use this method to casue the parser to parse a specific function in the module. Note that this will remove the function from what is to be included by ParseAllFunctionBodies.

See also:
ParseAllFunctionBodies

ParseBytecode

Definition at line 1766 of file Reader.cpp.

References llvm::Type::getDescription(), llvm::GlobalValue::getType(), and ParseFunctionBody().

Referenced by materializeFunction().

void BytecodeReader::ParseFunctionBody Function F  )  [protected]
 

Parse a function body.

Parse the contents of a function. Note that this function can be called lazily by materializeFunction

See also:
materializeFunction

Definition at line 1592 of file Reader.cpp.

References llvm::GlobalValue::AppendingLinkage, llvm::BytecodeFormat::BasicBlock, llvm::BytecodeFormat::CompactionTableBlockID, llvm::BytecodeFormat::ConstantPoolBlockID, E, llvm::GlobalValue::ExternalLinkage, llvm::BytecodeFormat::InstructionListBlockID, llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::LinkOnceLinkage, ParseBasicBlock(), ParseCompactionTable(), ParseConstantPool(), ParseInstructionList(), ParseSymbolTable(), llvm::GlobalValue::setLinkage(), llvm::BytecodeFormat::SymbolTableBlockID, and llvm::GlobalValue::WeakLinkage.

Referenced by ParseAllFunctionBodies(), and ParseFunction().

void BytecodeReader::ParseFunctionLazily  )  [protected]
 

Parse functions lazily.

This function parses LLVM functions lazily. It obtains the type of the function and records where the body of the function is in the bytecode buffer. The caller can then use the ParseNextFunction and ParseAllFunctionBodies to get handler events for the functions.

Definition at line 1742 of file Reader.cpp.

References llvm::GlobalValue::GhostLinkage, and llvm::GlobalValue::setLinkage().

Referenced by ParseModule().

void BytecodeReader::ParseGlobalTypes  )  [protected]
 

Parse global types.

Definition at line 1806 of file Reader.cpp.

References ParseTypes().

Referenced by ParseModule().

void BytecodeReader::ParseInstruction std::vector< unsigned > &  Oprnds,
BasicBlock BB
[protected]
 

Parse a single instruction.

This method parses a single instruction. The instruction is inserted at the end of the BB provided. The arguments of the instruction are provided in the Oprnds vector.

Parameters:
Oprnds  The arguments to be filled in
BB  The BB the instruction goes in

Definition at line 554 of file Reader.cpp.

References llvm::SwitchInst::addCase(), llvm::PHINode::addIncoming(), llvm::Instruction::Alloca, llvm::Type::BoolTyID, llvm::ISD::Br, llvm::Instruction::Call, llvm::Instruction::Cast, llvm::BinaryOperator::create(), llvm::ConstantExpr::getCast(), llvm::SequentialType::getElementType(), llvm::GetElementPtrInst::getIndexedType(), llvm::BasicBlock::getInstList(), llvm::FunctionType::getNumParams(), llvm::FunctionType::getParamType(), llvm::Value::getType(), llvm::Type::IntTyID, llvm::FunctionType::isVarArg(), llvm::Instruction::Load, llvm::Type::LongTyID, llvm::Instruction::Malloc, llvm::User::op_reserve(), llvm::FunctionType::param_begin(), llvm::FunctionType::param_end(), llvm::Instruction::PHI, llvm::ISD::Ret, llvm::Instruction::Select, llvm::Instruction::Shl, llvm::ISD::Store, llvm::ISD::Switch, llvm::Type::UByteTyID, llvm::Type::UIntTy, llvm::Type::UIntTyID, llvm::Type::ULongTyID, llvm::Instruction::VAArg, and llvm::Instruction::VANext.

Referenced by ParseBasicBlock(), and ParseInstructionList().

unsigned BytecodeReader::ParseInstructionList Function F  )  [protected]
 

parse an instruction list (for post LLVM 1.0 instruction lists with blocks differentiated by terminating instructions.

Parse all of the BasicBlock's & Instruction's in the body of a function. In post 1.0 bytecode files, we no longer emit basic block individually, in order to avoid per-basic-block overhead.

Returns:
Rhe number of basic blocks encountered.
Parameters:
F  The function into which BBs will be inserted

Definition at line 977 of file Reader.cpp.

References llvm::ISD::BasicBlock, llvm::Function::getBasicBlockList(), llvm::BasicBlock::getTerminator(), and ParseInstruction().

Referenced by ParseFunctionBody().

void BytecodeReader::ParseModule  )  [protected]
 

Parse whole module scope.

Make sure we pulled them all out. If we didn't then there's a declaration but a missing body. That's not allowed.

Definition at line 2093 of file Reader.cpp.

References llvm::BytecodeFormat::ConstantPoolBlockID, llvm::BytecodeFormat::FunctionBlockID, llvm::SequentialType::getElementType(), llvm::Module::getSymbolTable(), llvm::GlobalValue::getType(), llvm::BytecodeFormat::GlobalTypePlaneBlockID, llvm::GlobalVariable::hasInitializer(), llvm::BytecodeFormat::ModuleGlobalInfoBlockID, ParseConstantPool(), ParseFunctionLazily(), ParseGlobalTypes(), ParseModuleGlobalInfo(), ParseSymbolTable(), ParseVersionInfo(), llvm::BytecodeFormat::SymbolTableBlockID, llvm::ModuleProvider::TheModule, and llvm::utostr().

void BytecodeReader::ParseModuleGlobalInfo  )  [protected]
 

Parse the ModuleGlobalInfo block.

Definition at line 1818 of file Reader.cpp.

References llvm::Module::addLibrary(), llvm::GlobalValue::AppendingLinkage, llvm::GlobalValue::ExternalLinkage, llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::LinkOnceLinkage, llvm::Module::setTargetTriple(), llvm::ModuleProvider::TheModule, llvm::utostr(), llvm::Type::VoidTyID, and llvm::GlobalValue::WeakLinkage.

Referenced by ParseModule().

void BytecodeReader::ParseStringConstants unsigned  NumEntries,
ValueTable Tab
[protected]
 

Parse a string constants block.

Definition at line 1492 of file Reader.cpp.

References llvm::ConstantArray::get(), llvm::ConstantUInt::get(), llvm::ConstantSInt::get(), llvm::SequentialType::getElementType(), llvm::ArrayType::getNumElements(), llvm::Type::SByteTy, and llvm::Type::UByteTy.

Referenced by ParseConstantPool().

void BytecodeReader::ParseSymbolTable Function CurrentFunction,
SymbolTable ST
[protected]
 

Parse a symbol table.

Parse a symbol table. This works for both module level and function level symbol tables. For function level symbol tables, the CurrentFunction parameter must be non-zero and the ST parameter must correspond to CurrentFunction's symbol table. For Module level symbol tables, the CurrentFunction argument must be zero.

In LLVM 1.3 we write types separately from values so The types are always first in the symbol table. This is because Type no longer derives from Value.

Definition at line 1011 of file Reader.cpp.

References E, llvm::SymbolTable::insert(), llvm::Type::LabelTyID, and llvm::Value::setName().

Referenced by ParseFunctionBody(), and ParseModule().

const Type * BytecodeReader::ParseType  )  [protected]
 

Parse a single type constant.

Definition at line 1164 of file Reader.cpp.

References llvm::Type::ArrayTyID, llvm::Type::FunctionTyID, llvm::OpaqueType::get(), llvm::PointerType::get(), llvm::StructType::get(), llvm::PackedType::get(), llvm::ArrayType::get(), llvm::FunctionType::get(), llvm::Type::getPrimitiveType(), llvm::Type::OpaqueTyID, llvm::Type::PackedTyID, llvm::Type::PointerTyID, llvm::Type::StructTyID, llvm::utostr(), and llvm::Type::VoidTy.

Referenced by ParseTypes().

void BytecodeReader::ParseTypes TypeListTy Tab,
unsigned  NumEntries
[protected]
 

Parse a block of types constants.

Definition at line 1244 of file Reader.cpp.

References llvm::OpaqueType::get(), and ParseType().

Referenced by ParseConstantPool(), and ParseGlobalTypes().

void BytecodeReader::ParseVersionInfo  )  [protected]
 

Parse the version information block.

Parse the version information and decode it by setting flags on the Reader that enable backward compatibility of the reader.

Definition at line 1956 of file Reader.cpp.

References llvm::Module::AnyEndianness, llvm::Module::AnyPointerSize, llvm::Module::BigEndian, llvm::itostr(), llvm::Module::LittleEndian, llvm::Module::Pointer32, llvm::Module::Pointer64, llvm::DS::PointerSize, llvm::Module::setEndianness(), llvm::Module::setPointerSize(), and llvm::ModuleProvider::TheModule.

Referenced by ParseModule().

Module* llvm::BytecodeReader::releaseModule  )  [inline, virtual]
 

Release our hold on the generated module.

This method is provided by the parent ModuleProvde class and overriden here. It simply releases the module from its provided and frees up our state.

Reimplemented from llvm::ModuleProvider.

Definition at line 170 of file lib/Bytecode/Reader/Reader.h.

References M, and llvm::ModuleProvider::releaseModule().


The documentation for this class was generated from the following files: