diff options
-rw-r--r-- | lib/Bytecode/Reader/Analyzer.cpp | 168 | ||||
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 228 | ||||
-rw-r--r-- | lib/Bytecode/Reader/Reader.h | 56 | ||||
-rw-r--r-- | lib/Bytecode/Reader/ReaderWrappers.cpp | 30 |
4 files changed, 241 insertions, 241 deletions
diff --git a/lib/Bytecode/Reader/Analyzer.cpp b/lib/Bytecode/Reader/Analyzer.cpp index 5738f1a..63fdfb9 100644 --- a/lib/Bytecode/Reader/Analyzer.cpp +++ b/lib/Bytecode/Reader/Analyzer.cpp @@ -1,10 +1,10 @@ //===-- Analyzer.cpp - Analysis and Dumping of Bytecode 000000---*- C++ -*-===// -// +// // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and is distributed under the +// 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 the AnalyzerHandler class and PrintBytecodeAnalysis @@ -35,7 +35,7 @@ class AnalyzerHandler : public BytecodeHandler { BytecodeAnalysis& bca; ///< The structure in which data is recorded std::ostream* os; ///< A convenience for osing data. /// @brief Keeps track of current function - BytecodeAnalysis::BytecodeFunctionInfo* currFunc; + BytecodeAnalysis::BytecodeFunctionInfo* currFunc; Module* M; ///< Keeps track of current module /// @name Constructor @@ -44,8 +44,8 @@ public: /// The only way to construct an AnalyzerHandler. All that is needed is a /// reference to the BytecodeAnalysis structure where the output will be /// placed. - AnalyzerHandler(BytecodeAnalysis& TheBca, std::ostream* output) - : bca(TheBca) + AnalyzerHandler(BytecodeAnalysis& TheBca, std::ostream* output) + : bca(TheBca) , os(output) , currFunc(0) { } @@ -54,7 +54,7 @@ public: /// @name BytecodeHandler Implementations /// @{ public: - virtual void handleError(const std::string& str ) { + virtual void handleError(const std::string& str ) { if (os) *os << "ERROR: " << str << "\n"; } @@ -104,16 +104,16 @@ public: virtual void handleFinish() { if (os) - *os << "} End Bytecode\n"; + *os << "} End Bytecode\n"; bca.fileDensity = double(bca.byteSize) / double( bca.numTypes + bca.numValues ); double globalSize = 0.0; globalSize += double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]); globalSize += double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]); globalSize += double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]); - bca.globalsDensity = globalSize / double( bca.numTypes + bca.numConstants + + bca.globalsDensity = globalSize / double( bca.numTypes + bca.numConstants + bca.numGlobalVars ); - bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]) / + bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]) / double(bca.numFunctions); if ( bca.progressiveVerify ) { @@ -131,7 +131,7 @@ public: bca.ModuleId = id; } - virtual void handleModuleEnd(const std::string& id) { + virtual void handleModuleEnd(const std::string& id) { if (os) *os << " } End Module " << id << "\n"; if ( bca.progressiveVerify ) { @@ -147,22 +147,22 @@ public: unsigned char RevisionNum, ///< Byte code revision number Module::Endianness Endianness, ///< Endianness indicator Module::PointerSize PointerSize ///< PointerSize indicator - ) { + ) { if (os) - *os << " RevisionNum: " << int(RevisionNum) + *os << " RevisionNum: " << int(RevisionNum) << " Endianness: " << Endianness << " PointerSize: " << PointerSize << "\n"; bca.version = RevisionNum; } - virtual void handleModuleGlobalsBegin() { + virtual void handleModuleGlobalsBegin() { if (os) *os << " BLOCK: ModuleGlobalInfo {\n"; } - virtual void handleGlobalVariable( - const Type* ElemType, - bool isConstant, + virtual void handleGlobalVariable( + const Type* ElemType, + bool isConstant, GlobalValue::LinkageTypes Linkage, unsigned SlotNum, unsigned initSlot @@ -173,7 +173,7 @@ public: << ( isConstant? "Constant, " : "Variable, ") << " Linkage=" << Linkage << " Type="; WriteTypeSymbolic(*os, ElemType, M); - *os << " Slot=" << SlotNum << " InitSlot=" << initSlot + *os << " Slot=" << SlotNum << " InitSlot=" << initSlot << "\n"; } @@ -190,8 +190,8 @@ public: bca.maxTypeSlot = numEntries - 1; } - virtual void handleType( const Type* Ty ) { - bca.numTypes++; + virtual void handleType( const Type* Ty ) { + bca.numTypes++; if (os) { *os << " Type: "; WriteTypeSymbolic(*os,Ty,M); @@ -199,7 +199,7 @@ public: } } - virtual void handleFunctionDeclaration( + virtual void handleFunctionDeclaration( Function* Func ///< The function ) { bca.numFunctions++; @@ -228,7 +228,7 @@ public: *os << " Library: '" << libName << "'\n"; } - virtual void handleModuleGlobalsEnd() { + virtual void handleModuleGlobalsEnd() { if (os) *os << " } END BLOCK: ModuleGlobalInfo\n"; if ( bca.progressiveVerify ) { @@ -240,7 +240,7 @@ public: } } - virtual void handleCompactionTableBegin() { + virtual void handleCompactionTableBegin() { if (os) *os << " BLOCK: CompactionTable {\n"; bca.numCmpctnTables++; @@ -251,53 +251,53 @@ public: *os << " Plane: Ty=" << Ty << " Size=" << NumEntries << "\n"; } - virtual void handleCompactionTableType( unsigned i, unsigned TypSlot, + virtual void handleCompactionTableType( unsigned i, unsigned TypSlot, const Type* Ty ) { if (os) { *os << " Type: " << i << " Slot:" << TypSlot << " is "; WriteTypeSymbolic(*os,Ty,M); - *os << "\n"; + *os << "\n"; } } virtual void handleCompactionTableValue(unsigned i, unsigned TypSlot, - unsigned ValSlot) { + unsigned ValSlot) { if (os) - *os << " Value: " << i << " TypSlot: " << TypSlot + *os << " Value: " << i << " TypSlot: " << TypSlot << " ValSlot:" << ValSlot << "\n"; if (ValSlot > bca.maxValueSlot) bca.maxValueSlot = ValSlot; } - virtual void handleCompactionTableEnd() { + virtual void handleCompactionTableEnd() { if (os) *os << " } END BLOCK: CompactionTable\n"; } - virtual void handleSymbolTableBegin(Function* CF, SymbolTable* ST) { - bca.numSymTab++; + virtual void handleSymbolTableBegin(Function* CF, SymbolTable* ST) { + bca.numSymTab++; if (os) *os << " BLOCK: SymbolTable {\n"; } - virtual void handleSymbolTablePlane(unsigned Ty, unsigned NumEntries, - const Type* Typ) { + virtual void handleSymbolTablePlane(unsigned Ty, unsigned NumEntries, + const Type* Typ) { if (os) { *os << " Plane: Ty=" << Ty << " Size=" << NumEntries << " Type: "; WriteTypeSymbolic(*os,Typ,M); - *os << "\n"; + *os << "\n"; } } - virtual void handleSymbolTableType(unsigned i, unsigned TypSlot, - const std::string& name ) { + virtual void handleSymbolTableType(unsigned i, unsigned TypSlot, + const std::string& name ) { if (os) *os << " Type " << i << " Slot=" << TypSlot - << " Name: " << name << "\n"; + << " Name: " << name << "\n"; } - virtual void handleSymbolTableValue(unsigned i, unsigned ValSlot, - const std::string& name ) { + virtual void handleSymbolTableValue(unsigned i, unsigned ValSlot, + const std::string& name ) { if (os) *os << " Value " << i << " Slot=" << ValSlot << " Name: " << name << "\n"; @@ -305,7 +305,7 @@ public: bca.maxValueSlot = ValSlot; } - virtual void handleSymbolTableEnd() { + virtual void handleSymbolTableEnd() { if (os) *os << " } END BLOCK: SymbolTable\n"; } @@ -314,7 +314,7 @@ public: if (os) { *os << " BLOCK: Function {\n" << " Linkage: " << Func->getLinkage() << "\n" - << " Type: "; + << " Type: "; WriteTypeSymbolic(*os,Func->getType(),M); *os << "\n"; } @@ -362,14 +362,14 @@ public: if ( currFunc ) currFunc->numBasicBlocks++; } - virtual bool handleInstruction( unsigned Opcode, const Type* iType, + virtual bool handleInstruction( unsigned Opcode, const Type* iType, std::vector<unsigned>& Operands, unsigned Size){ if (os) { - *os << " INST: OpCode=" + *os << " INST: OpCode=" << Instruction::getOpcodeName(Opcode) << " Type=\""; WriteTypeSymbolic(*os,iType,M); *os << "\""; - for ( unsigned i = 0; i < Operands.size(); ++i ) + for ( unsigned i = 0; i < Operands.size(); ++i ) *os << " Op(" << i << ")=Slot(" << Operands[i] << ")"; *os << "\n"; } @@ -388,25 +388,25 @@ public: if (Size > 4 ) currFunc->longInstructions++; if ( Opcode == Instruction::PHI ) currFunc->numPhis++; } - return Instruction::isTerminator(Opcode); + return Instruction::isTerminator(Opcode); } - virtual void handleBasicBlockEnd(unsigned blocknum) { + virtual void handleBasicBlockEnd(unsigned blocknum) { if (os) *os << " } END BLOCK: BasicBlock #" << blocknum << "{\n"; } - virtual void handleGlobalConstantsBegin() { + virtual void handleGlobalConstantsBegin() { if (os) *os << " BLOCK: GlobalConstants {\n"; } - virtual void handleConstantExpression( unsigned Opcode, + virtual void handleConstantExpression( unsigned Opcode, std::vector<Constant*> ArgVec, Constant* C ) { if (os) { *os << " EXPR: " << Instruction::getOpcodeName(Opcode) << "\n"; for ( unsigned i = 0; i < ArgVec.size(); ++i ) { - *os << " Arg#" << i << " "; ArgVec[i]->print(*os); + *os << " Arg#" << i << " "; ArgVec[i]->print(*os); *os << "\n"; } *os << " Value="; @@ -427,13 +427,13 @@ public: bca.numValues++; } - virtual void handleConstantArray( const ArrayType* AT, + virtual void handleConstantArray( const ArrayType* AT, std::vector<Constant*>& Elements, unsigned TypeSlot, Constant* ArrayVal ) { if (os) { *os << " ARRAY: "; - WriteTypeSymbolic(*os,AT,M); + WriteTypeSymbolic(*os,AT,M); *os << " TypeSlot=" << TypeSlot << "\n"; for ( unsigned i = 0; i < Elements.size(); ++i ) { *os << " #" << i; @@ -459,7 +459,7 @@ public: WriteTypeSymbolic(*os,ST,M); *os << "\n"; for ( unsigned i = 0; i < Elements.size(); ++i ) { - *os << " #" << i << " "; Elements[i]->print(*os); + *os << " #" << i << " "; Elements[i]->print(*os); *os << "\n"; } *os << " Value="; @@ -470,11 +470,11 @@ public: bca.numValues++; } - virtual void handleConstantPacked( - const PackedType* PT, + virtual void handleConstantPacked( + const PackedType* PT, std::vector<Constant*>& Elements, - unsigned TypeSlot, - Constant* PackedVal) + unsigned TypeSlot, + Constant* PackedVal) { if (os) { *os << " PACKD: "; @@ -494,7 +494,7 @@ public: bca.numValues++; } - virtual void handleConstantPointer( const PointerType* PT, + virtual void handleConstantPointer( const PointerType* PT, unsigned Slot, GlobalValue* GV ) { if (os) { *os << " PNTR: "; @@ -510,14 +510,14 @@ public: virtual void handleConstantString( const ConstantArray* CA ) { if (os) { *os << " STRNG: "; - CA->print(*os); + CA->print(*os); *os << "\n"; } bca.numConstants++; bca.numValues++; } - virtual void handleGlobalConstantsEnd() { + virtual void handleGlobalConstantsEnd() { if (os) *os << " } END BLOCK: GlobalConstants\n"; @@ -574,38 +574,38 @@ public: /// @brief Utility for printing a titled unsigned value with /// an aligned colon. -inline static void print(std::ostream& Out, const char*title, +inline static void print(std::ostream& Out, const char*title, unsigned val, bool nl = true ) { - Out << std::setw(30) << std::right << title + Out << std::setw(30) << std::right << title << std::setw(0) << ": " << std::setw(9) << val << "\n"; } /// @brief Utility for printing a titled double value with an /// aligned colon -inline static void print(std::ostream&Out, const char*title, +inline static void print(std::ostream&Out, const char*title, double val ) { - Out << std::setw(30) << std::right << title + Out << std::setw(30) << std::right << title << std::setw(0) << ": " << std::setw(9) << std::setprecision(6) << val << "\n" ; } /// @brief Utility for printing a titled double value with a /// percentage and aligned colon. -inline static void print(std::ostream&Out, const char*title, +inline static void print(std::ostream&Out, const char*title, double top, double bot ) { - Out << std::setw(30) << std::right << title + Out << std::setw(30) << std::right << title << std::setw(0) << ": " - << std::setw(9) << std::setprecision(6) << top - << " (" << std::left << std::setw(0) << std::setprecision(4) + << std::setw(9) << std::setprecision(6) << top + << " (" << std::left << std::setw(0) << std::setprecision(4) << (top/bot)*100.0 << "%)\n"; } /// @brief Utility for printing a titled string value with /// an aligned colon. -inline static void print(std::ostream&Out, const char*title, +inline static void print(std::ostream&Out, const char*title, std::string val, bool nl = true) { - Out << std::setw(30) << std::right << title + Out << std::setw(30) << std::right << title << std::setw(0) << ": " << std::left << val << (nl ? "\n" : ""); } @@ -626,33 +626,33 @@ void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out ) print(Out, "Module Bytes", double(bca.BlockSizes[BytecodeFormat::ModuleBlockID]), double(bca.byteSize)); - print(Out, "Function Bytes", + print(Out, "Function Bytes", double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]), double(bca.byteSize)); - print(Out, "Global Types Bytes", + print(Out, "Global Types Bytes", double(bca.BlockSizes[BytecodeFormat::GlobalTypePlaneBlockID]), double(bca.byteSize)); - print(Out, "Constant Pool Bytes", + print(Out, "Constant Pool Bytes", double(bca.BlockSizes[BytecodeFormat::ConstantPoolBlockID]), double(bca.byteSize)); - print(Out, "Module Globals Bytes", + print(Out, "Module Globals Bytes", double(bca.BlockSizes[BytecodeFormat::ModuleGlobalInfoBlockID]), double(bca.byteSize)); - print(Out, "Instruction List Bytes", + print(Out, "Instruction List Bytes", double(bca.BlockSizes[BytecodeFormat::InstructionListBlockID]), double(bca.byteSize)); - print(Out, "Compaction Table Bytes", + print(Out, "Compaction Table Bytes", double(bca.BlockSizes[BytecodeFormat::CompactionTableBlockID]), double(bca.byteSize)); - print(Out, "Symbol Table Bytes", + print(Out, "Symbol Table Bytes", double(bca.BlockSizes[BytecodeFormat::SymbolTableBlockID]), double(bca.byteSize)); - print(Out, "Alignment Bytes", + print(Out, "Alignment Bytes", double(bca.numAlignment), double(bca.byteSize)); - print(Out, "Block Header Bytes", + print(Out, "Block Header Bytes", double(bca.BlockSizes[BytecodeFormat::Reserved_DoNotUse]), double(bca.byteSize)); - print(Out, "Dependent Libraries Bytes", double(bca.libSize), + print(Out, "Dependent Libraries Bytes", double(bca.libSize), double(bca.byteSize)); print(Out, "Number Of Bytecode Blocks", bca.numBlocks); print(Out, "Number Of Functions", bca.numFunctions); @@ -668,7 +668,7 @@ void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out ) print(Out, "Number Of Symbol Tables", bca.numSymTab); print(Out, "Number Of Dependent Libs", bca.numLibraries); print(Out, "Total Instruction Size", bca.instructionSize); - print(Out, "Average Instruction Size", + print(Out, "Average Instruction Size", double(bca.instructionSize)/double(bca.numInstructions)); print(Out, "Maximum Type Slot Number", bca.maxTypeSlot); @@ -680,16 +680,16 @@ void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out ) print(Out, "# of VBR 64-bit Integers", bca.vbrCount64); print(Out, "# of VBR Compressed Bytes", bca.vbrCompBytes); print(Out, "# of VBR Expanded Bytes", bca.vbrExpdBytes); - print(Out, "Bytes Saved With VBR", + print(Out, "Bytes Saved With VBR", double(bca.vbrExpdBytes)-double(bca.vbrCompBytes), double(bca.vbrExpdBytes)); if (bca.detailedResults) { Out << "\nDetailed Analysis Of " << bca.ModuleId << " Functions:\n"; - std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I = + std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator I = bca.FunctionInfo.begin(); - std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E = + std::map<const Function*,BytecodeAnalysis::BytecodeFunctionInfo>::iterator E = bca.FunctionInfo.end(); while ( I != E ) { @@ -704,14 +704,14 @@ void PrintBytecodeAnalysis(BytecodeAnalysis& bca, std::ostream& Out ) print(Out, "Long Instructions", I->second.longInstructions); print(Out, "Operands", I->second.numOperands); print(Out, "Instruction Size", I->second.instructionSize); - print(Out, "Average Instruction Size", + print(Out, "Average Instruction Size", double(I->second.instructionSize) / I->second.numInstructions); print(Out, "Bytes Per Instruction", I->second.density); print(Out, "# of VBR 32-bit Integers", I->second.vbrCount32); print(Out, "# of VBR 64-bit Integers", I->second.vbrCount64); print(Out, "# of VBR Compressed Bytes", I->second.vbrCompBytes); print(Out, "# of VBR Expanded Bytes", I->second.vbrExpdBytes); - print(Out, "Bytes Saved With VBR", + print(Out, "Bytes Saved With VBR", double(I->second.vbrExpdBytes) - I->second.vbrCompBytes), double(I->second.vbrExpdBytes); } diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 974a326..398ecfc 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -1,15 +1,15 @@ //===- Reader.cpp - Code to read bytecode files ---------------------------===// -// +// // 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 library implements the functionality defined in llvm/Bytecode/Reader.h // -// Note that this library should be as fast as possible, reentrant, and +// Note that this library should be as fast as possible, reentrant, and // threadsafe!! // // TODO: Allow passing in an option to ignore the symbol table @@ -39,7 +39,7 @@ namespace { void operator=(const ConstantPlaceHolder &); // DO NOT IMPLEMENT public: Use Op; - ConstantPlaceHolder(const Type *Ty) + ConstantPlaceHolder(const Type *Ty) : ConstantExpr(Ty, Instruction::UserOp1, &Op, 1), Op(UndefValue::get(Type::IntTy), this) { } @@ -77,16 +77,16 @@ inline void BytecodeReader::align32() { if (hasAlignment) { BufPtr Save = At; At = (const unsigned char *)((unsigned long)(At+3) & (~3UL)); - if (At > Save) + if (At > Save) if (Handler) Handler->handleAlignment(At - Save); - if (At > BlockEnd) + if (At > BlockEnd) error("Ran out of data while aligning!"); } } /// Read a whole unsigned integer inline unsigned BytecodeReader::read_uint() { - if (At+4 > BlockEnd) + if (At+4 > BlockEnd) error("Ran out of data reading uint!"); At += 4; return At[-4] | (At[-3] << 8) | (At[-2] << 16) | (At[-1] << 24); @@ -97,9 +97,9 @@ inline unsigned BytecodeReader::read_vbr_uint() { unsigned Shift = 0; unsigned Result = 0; BufPtr Save = At; - + do { - if (At == BlockEnd) + if (At == BlockEnd) error("Ran out of data reading vbr_uint!"); Result |= (unsigned)((*At++) & 0x7F) << Shift; Shift += 7; @@ -113,9 +113,9 @@ inline uint64_t BytecodeReader::read_vbr_uint64() { unsigned Shift = 0; uint64_t Result = 0; BufPtr Save = At; - + do { - if (At == BlockEnd) + if (At == BlockEnd) error("Ran out of data reading vbr_uint64!"); Result |= (uint64_t)((*At++) & 0x7F) << Shift; Shift += 7; @@ -151,7 +151,7 @@ inline std::string BytecodeReader::read_str() { inline void BytecodeReader::read_data(void *Ptr, void *End) { unsigned char *Start = (unsigned char *)Ptr; unsigned Amount = (unsigned char *)End - Start; - if (At+Amount > BlockEnd) + if (At+Amount > BlockEnd) error("Ran out of data!"); std::copy(At, At+Amount, Start); At += Amount; @@ -178,9 +178,9 @@ inline void BytecodeReader::read_double(double& DoubleVal) { double d; uint64_t i; } DoubleUnion; - DoubleUnion.i = (uint64_t(At[0]) << 0) | (uint64_t(At[1]) << 8) | + DoubleUnion.i = (uint64_t(At[0]) << 0) | (uint64_t(At[1]) << 8) | (uint64_t(At[2]) << 16) | (uint64_t(At[3]) << 24) | - (uint64_t(At[4]) << 32) | (uint64_t(At[5]) << 40) | + (uint64_t(At[4]) << 32) | (uint64_t(At[5]) << 40) | (uint64_t(At[6]) << 48) | (uint64_t(At[7]) << 56); At+=sizeof(uint64_t); DoubleVal = DoubleUnion.d; @@ -192,10 +192,10 @@ inline void BytecodeReader::read_block(unsigned &Type, unsigned &Size) { Type = read_uint(); Size = read_uint(); switch (Type) { - case BytecodeFormat::Reserved_DoNotUse : + case BytecodeFormat::Reserved_DoNotUse : error("Reserved_DoNotUse used as Module Type?"); Type = BytecodeFormat::ModuleBlockID; break; - case BytecodeFormat::Module: + case BytecodeFormat::Module: Type = BytecodeFormat::ModuleBlockID; break; case BytecodeFormat::Function: Type = BytecodeFormat::FunctionBlockID; break; @@ -238,8 +238,8 @@ inline void BytecodeReader::read_block(unsigned &Type, unsigned &Size) { /// 1.3 this changed so that Type does not derive from Value. Consequently, /// the BytecodeReader's containers for Values can't contain Types because /// there's no inheritance relationship. This means that the "Type Type" -/// plane is defunct along with the Type::TypeTyID TypeID. In LLVM 1.3 -/// whenever a bytecode construct must have both types and values together, +/// plane is defunct along with the Type::TypeTyID TypeID. In LLVM 1.3 +/// whenever a bytecode construct must have both types and values together, /// the types are always read/written first and then the Values. Furthermore /// since Type::TypeTyID no longer exists, its value (12) now corresponds to /// Type::LabelTyID. In order to overcome this we must "sanitize" all the @@ -249,7 +249,7 @@ inline void BytecodeReader::read_block(unsigned &Type, unsigned &Size) { /// larger than 12 (Type::LabelTyID). If the value is exactly 12, then this /// function returns true, otherwise false. This helps detect situations /// where the pre 1.3 bytecode is indicating that what follows is a type. -/// @returns true iff type id corresponds to pre 1.3 "type type" +/// @returns true iff type id corresponds to pre 1.3 "type type" inline bool BytecodeReader::sanitizeTypeId(unsigned &TypeId) { if (hasTypeDerivedFromValue) { /// do nothing if 1.3 or later if (TypeId == Type::LabelTyID) { @@ -342,7 +342,7 @@ unsigned BytecodeReader::getTypeSlot(const Type *Ty) { if (!CompactionTypes.empty()) { for (unsigned i = 0, e = CompactionTypes.size(); i != e; ++i) if (CompactionTypes[i].first == Ty) - return Type::FirstDerivedTyID + i; + return Type::FirstDerivedTyID + i; error("Couldn't find type specified in compaction table!"); } @@ -352,7 +352,7 @@ unsigned BytecodeReader::getTypeSlot(const Type *Ty) { FunctionTypes.end(), Ty); if (I != FunctionTypes.end()) - return Type::FirstDerivedTyID + ModuleTypes.size() + + return Type::FirstDerivedTyID + ModuleTypes.size() + (&*I - &FunctionTypes[0]); // Check the module level types now... @@ -390,8 +390,8 @@ unsigned BytecodeReader::getGlobalTableTypeSlot(const Type *Ty) { return Type::FirstDerivedTyID + (&*I - &ModuleTypes[0]); } -/// Retrieve a value of a given type and slot number, possibly creating -/// it if it doesn't already exist. +/// Retrieve a value of a given type and slot number, possibly creating +/// it if it doesn't already exist. Value * BytecodeReader::getValue(unsigned type, unsigned oNum, bool Create) { assert(type != Type::LabelTyID && "getValue() cannot get blocks!"); unsigned Num = oNum; @@ -424,8 +424,8 @@ Value * BytecodeReader::getValue(unsigned type, unsigned oNum, bool Create) { } } - if (FunctionValues.size() > type && - FunctionValues[type] && + if (FunctionValues.size() > type && + FunctionValues[type] && Num < FunctionValues[type]->size()) return FunctionValues[type]->getOperand(Num); @@ -447,8 +447,8 @@ Value * BytecodeReader::getValue(unsigned type, unsigned oNum, bool Create) { throw "Can't create placeholder for value of type slot #" + utostr(type); } -/// This is just like getValue, but when a compaction table is in use, it -/// is ignored. Also, no forward references or other fancy features are +/// This is just like getValue, but when a compaction table is in use, it +/// is ignored. Also, no forward references or other fancy features are /// supported. Value* BytecodeReader::getGlobalTableValue(unsigned TyID, unsigned SlotNo) { if (SlotNo == 0) @@ -467,11 +467,11 @@ Value* BytecodeReader::getGlobalTableValue(unsigned TyID, unsigned SlotNo) { SlotNo >= ModuleValues[TyID]->size()) { if (TyID >= ModuleValues.size() || ModuleValues[TyID] == 0) error("Corrupt compaction table entry!" - + utostr(TyID) + ", " + utostr(SlotNo) + ": " + + utostr(TyID) + ", " + utostr(SlotNo) + ": " + utostr(ModuleValues.size())); - else + else error("Corrupt compaction table entry!" - + utostr(TyID) + ", " + utostr(SlotNo) + ": " + + utostr(TyID) + ", " + utostr(SlotNo) + ": " + utostr(ModuleValues.size()) + ", " + utohexstr(reinterpret_cast<uint64_t>(((void*)ModuleValues[TyID]))) + ", " @@ -483,14 +483,14 @@ Value* BytecodeReader::getGlobalTableValue(unsigned TyID, unsigned SlotNo) { /// Just like getValue, except that it returns a null pointer /// only on error. It always returns a constant (meaning that if the value is /// defined, but is not a constant, that is an error). If the specified -/// constant hasn't been parsed yet, a placeholder is defined and used. +/// constant hasn't been parsed yet, a placeholder is defined and used. /// Later, after the real value is parsed, the placeholder is eliminated. Constant* BytecodeReader::getConstantValue(unsigned TypeSlot, unsigned Slot) { if (Value *V = getValue(TypeSlot, Slot, false)) if (Constant *C = dyn_cast<Constant>(V)) return C; // If we already have the value parsed, just return it else - error("Value for slot " + utostr(Slot) + + error("Value for slot " + utostr(Slot) + " is expected to be a constant!"); std::pair<unsigned, unsigned> Key(TypeSlot, Slot); @@ -502,7 +502,7 @@ Constant* BytecodeReader::getConstantValue(unsigned TypeSlot, unsigned Slot) { // Create a placeholder for the constant reference and // keep track of the fact that we have a forward ref to recycle it Constant *C = new ConstantPlaceHolder(getType(TypeSlot)); - + // Keep track of the fact that we have a forward ref to recycle it ConstantFwdRefs.insert(I, std::make_pair(Key, C)); return C; @@ -516,7 +516,7 @@ Constant* BytecodeReader::getConstantValue(unsigned TypeSlot, unsigned Slot) { /// As values are created, they are inserted into the appropriate place /// with this method. The ValueTable argument must be one of ModuleValues /// or FunctionValues data members of this class. -unsigned BytecodeReader::insertValue(Value *Val, unsigned type, +unsigned BytecodeReader::insertValue(Value *Val, unsigned type, ValueTable &ValueTab) { assert((!isa<Constant>(Val) || !cast<Constant>(Val)->isNullValue()) || !hasImplicitNull(type) && @@ -584,7 +584,7 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, // -------------------------- // 15-08: Resulting type plane // 23-16: Operand #1 - // 31-24: Operand #2 + // 31-24: Operand #2 // iType = (Op >> 8) & 255; Oprnds[0] = (Op >> 16) & 255; @@ -646,20 +646,20 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, getValue(iType, Oprnds[1])); switch (Opcode) { - default: - if (Result == 0) + default: + if (Result == 0) error("Illegal instruction read!"); break; case Instruction::VAArg: - Result = new VAArgInst(getValue(iType, Oprnds[0]), + Result = new VAArgInst(getValue(iType, Oprnds[0]), getSanitizedType(Oprnds[1])); break; case Instruction::VANext: - Result = new VANextInst(getValue(iType, Oprnds[0]), + Result = new VANextInst(getValue(iType, Oprnds[0]), getSanitizedType(Oprnds[1])); break; case Instruction::Cast: - Result = new CastInst(getValue(iType, Oprnds[0]), + Result = new CastInst(getValue(iType, Oprnds[0]), getSanitizedType(Oprnds[1])); break; case Instruction::Select: @@ -698,7 +698,7 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, if (Oprnds.size() == 1) Result = new BranchInst(getBasicBlock(Oprnds[0])); else if (Oprnds.size() == 3) - Result = new BranchInst(getBasicBlock(Oprnds[0]), + Result = new BranchInst(getBasicBlock(Oprnds[0]), getBasicBlock(Oprnds[1]), getValue(Type::BoolTyID , Oprnds[2])); else error("Invalid number of operands for a 'br' instruction!"); @@ -750,13 +750,13 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, // Read all of the fixed arguments for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) Params.push_back(getValue(getTypeSlot(FTy->getParamType(i)),Oprnds[i])); - + FirstVariableOperand = FTy->getNumParams(); - if ((Oprnds.size()-FirstVariableOperand) & 1) + if ((Oprnds.size()-FirstVariableOperand) & 1) error("Invalid call instruction!"); // Must be pairs of type/value - - for (unsigned i = FirstVariableOperand, e = Oprnds.size(); + + for (unsigned i = FirstVariableOperand, e = Oprnds.size(); i != e; i += 2) Params.push_back(getValue(Oprnds[i], Oprnds[i+1])); } @@ -765,16 +765,16 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, break; } case Instruction::Invoke: { - if (Oprnds.size() < 3) + if (Oprnds.size() < 3) error("Invalid invoke instruction!"); Value *F = getValue(iType, Oprnds[0]); // Check to make sure we have a pointer to function type const PointerType *PTy = dyn_cast<PointerType>(F->getType()); - if (PTy == 0) + if (PTy == 0) error("Invoke to non function pointer value!"); const FunctionType *FTy = dyn_cast<FunctionType>(PTy->getElementType()); - if (FTy == 0) + if (FTy == 0) error("Invoke to non function pointer value!"); std::vector<Value *> Params; @@ -797,12 +797,12 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, Normal = getBasicBlock(Oprnds[0]); Except = getBasicBlock(Oprnds[1]); - + unsigned FirstVariableArgument = FTy->getNumParams()+2; for (unsigned i = 2; i != FirstVariableArgument; ++i) Params.push_back(getValue(getTypeSlot(FTy->getParamType(i-2)), Oprnds[i])); - + if (Oprnds.size()-FirstVariableArgument & 1) // Must be type/value pairs error("Invalid invoke instruction!"); @@ -814,7 +814,7 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, break; } case Instruction::Malloc: - if (Oprnds.size() > 2) + if (Oprnds.size() > 2) error("Invalid malloc instruction!"); if (!isa<PointerType>(InstTy)) error("Invalid malloc instruction!"); @@ -825,13 +825,13 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, break; case Instruction::Alloca: - if (Oprnds.size() > 2) + if (Oprnds.size() > 2) error("Invalid alloca instruction!"); if (!isa<PointerType>(InstTy)) error("Invalid alloca instruction!"); Result = new AllocaInst(cast<PointerType>(InstTy)->getElementType(), - Oprnds.size() ? getValue(Type::UIntTyID, + Oprnds.size() ? getValue(Type::UIntTyID, Oprnds[0]) :0); break; case Instruction::Free: @@ -848,8 +848,8 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, const Type *NextTy = InstTy; for (unsigned i = 1, e = Oprnds.size(); i != e; ++i) { const CompositeType *TopTy = dyn_cast_or_null<CompositeType>(NextTy); - if (!TopTy) - error("Invalid getelementptr instruction!"); + if (!TopTy) + error("Invalid getelementptr instruction!"); unsigned ValIdx = Oprnds[i]; unsigned IdxTy = 0; @@ -894,7 +894,7 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, Result = new LoadInst(getValue(iType, Oprnds[0]), "", Opcode == 62); break; - case 63: // volatile store + case 63: // volatile store case Instruction::Store: { if (!isa<PointerType>(InstTy) || Oprnds.size() != 2) error("Invalid store instruction!"); @@ -913,7 +913,7 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds, if (Oprnds.size() != 0) error("Invalid unreachable instruction!"); Result = new UnreachableInst(); break; - } // end switch(Opcode) + } // end switch(Opcode) unsigned TypeSlot; if (Result->getType() == InstTy) @@ -945,7 +945,7 @@ BasicBlock *BytecodeReader::getBasicBlock(unsigned ID) { return ParsedBasicBlocks[ID] = new BasicBlock(); } -/// In LLVM 1.0 bytecode files, we used to output one basicblock at a time. +/// 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. @@ -970,7 +970,7 @@ BasicBlock *BytecodeReader::ParseBasicBlock(unsigned BlockNo) { } /// 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 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. unsigned BytecodeReader::ParseInstructionList(Function* F) { @@ -1071,7 +1071,7 @@ void BytecodeReader::ParseSymbolTable(Function *CurrentFunction, if (Handler) Handler->handleSymbolTableEnd(); } -/// Read in the types portion of a compaction table. +/// Read in the types portion of a compaction table. void BytecodeReader::ParseCompactionTypes(unsigned NumEntries) { for (unsigned i = 0; i != NumEntries; ++i) { unsigned TypeSlot = 0; @@ -1089,7 +1089,7 @@ void BytecodeReader::ParseCompactionTable() { // Notify handler that we're beginning a compaction table. if (Handler) Handler->handleCompactionTableBegin(); - // In LLVM 1.3 Type no longer derives from Value. So, + // In LLVM 1.3 Type no longer derives from Value. So, // we always write them first in the compaction table // because they can't occupy a "type plane" where the // Values reside. @@ -1155,10 +1155,10 @@ void BytecodeReader::ParseCompactionTable() { // Notify handler that the compaction table is done. if (Handler) Handler->handleCompactionTableEnd(); } - + // Parse a single type. The typeid is read in first. If its a primitive type // then nothing else needs to be read, we know how to instantiate it. If its -// a derived type, then additional data is read to fill out the type +// a derived type, then additional data is read to fill out the type // definition. const Type *BytecodeReader::ParseType() { unsigned PrimType = 0; @@ -1168,7 +1168,7 @@ const Type *BytecodeReader::ParseType() { const Type *Result = 0; if ((Result = Type::getPrimitiveType((Type::TypeID)PrimType))) return Result; - + switch (PrimType) { case Type::FunctionTyID: { const Type *RetType = readSanitizedType(); @@ -1176,7 +1176,7 @@ const Type *BytecodeReader::ParseType() { unsigned NumParams = read_vbr_uint(); std::vector<const Type*> Params; - while (NumParams--) + while (NumParams--) Params.push_back(readSanitizedType()); bool isVarArg = Params.size() && Params.back() == Type::VoidTy; @@ -1248,7 +1248,7 @@ void BytecodeReader::ParseTypes(TypeListTy &Tab, unsigned NumEntries){ for (unsigned i = 0; i != NumEntries; ++i) Tab.push_back(OpaqueType::get()); - if (Handler) + if (Handler) Handler->handleTypeList(NumEntries); // Loop through reading all of the types. Forward types will make use of the @@ -1257,10 +1257,10 @@ void BytecodeReader::ParseTypes(TypeListTy &Tab, unsigned NumEntries){ for (unsigned i = 0; i != NumEntries; ++i) { const Type* NewTy = ParseType(); const Type* OldTy = Tab[i].get(); - if (NewTy == 0) + if (NewTy == 0) error("Couldn't parse type!"); - // Don't directly push the new type on the Tab. Instead we want to replace + // Don't directly push the new type on the Tab. Instead we want to replace // the opaque type we previously inserted with the new concrete value. This // approach helps with forward references to types. The refinement from the // abstract (opaque) type to the new type causes all uses of the abstract @@ -1279,7 +1279,7 @@ void BytecodeReader::ParseTypes(TypeListTy &Tab, unsigned NumEntries){ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { // We must check for a ConstantExpr before switching by type because // a ConstantExpr can be of any type, and has no explicit value. - // + // // 0 if not expr; numArgs if is expr unsigned isExprNumArgs = read_vbr_uint(); @@ -1288,7 +1288,7 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { if (!hasNoUndefValue) if (--isExprNumArgs == 0) return UndefValue::get(getType(TypeID)); - + // FIXME: Encoding of constant exprs could be much more compact! std::vector<Constant*> ArgVec; ArgVec.reserve(isExprNumArgs); @@ -1296,18 +1296,18 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { // Bytecode files before LLVM 1.4 need have a missing terminator inst. if (hasNoUnreachableInst) Opcode++; - + // Read the slot number and types of each of the arguments for (unsigned i = 0; i != isExprNumArgs; ++i) { unsigned ArgValSlot = read_vbr_uint(); unsigned ArgTypeSlot = 0; if (read_typeid(ArgTypeSlot)) error("Invalid argument type (type type) for constant value"); - + // Get the arg value from its slot if it exists, otherwise a placeholder ArgVec.push_back(getConstantValue(ArgTypeSlot, ArgValSlot)); } - + // Construct a ConstantExpr of the appropriate kind if (isExprNumArgs == 1) { // All one-operand expressions if (Opcode != Instruction::Cast) @@ -1338,7 +1338,7 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { } else if (Opcode == Instruction::Select) { if (ArgVec.size() != 3) error("Select instruction must have three arguments."); - Constant* Result = ConstantExpr::getSelect(ArgVec[0], ArgVec[1], + Constant* Result = ConstantExpr::getSelect(ArgVec[0], ArgVec[1], ArgVec[2]); if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result); return Result; @@ -1348,13 +1348,13 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { return Result; } } - + // Ok, not an ConstantExpr. We now know how to read the given type... const Type *Ty = getType(TypeID); switch (Ty->getTypeID()) { case Type::BoolTyID: { unsigned Val = read_vbr_uint(); - if (Val != 0 && Val != 1) + if (Val != 0 && Val != 1) error("Invalid boolean value read."); Constant* Result = ConstantBool::get(Val == 1); if (Handler) Handler->handleConstantValue(Result); @@ -1365,7 +1365,7 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { case Type::UShortTyID: case Type::UIntTyID: { unsigned Val = read_vbr_uint(); - if (!ConstantUInt::isValueValidForType(Ty, Val)) + if (!ConstantUInt::isValueValidForType(Ty, Val)) error("Invalid unsigned byte/short/int read."); Constant* Result = ConstantUInt::get(Ty, Val); if (Handler) Handler->handleConstantValue(Result); @@ -1383,7 +1383,7 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { case Type::IntTyID: { case Type::LongTyID: int64_t Val = read_vbr_int64(); - if (!ConstantSInt::isValueValidForType(Ty, Val)) + if (!ConstantSInt::isValueValidForType(Ty, Val)) error("Invalid signed byte/short/int/long read."); Constant* Result = ConstantSInt::get(Ty, Val); if (Handler) Handler->handleConstantValue(Result); @@ -1432,7 +1432,7 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { Constant* Result = ConstantStruct::get(ST, Elements); if (Handler) Handler->handleConstantStruct(ST, Elements, Result); return Result; - } + } case Type::PackedTyID: { const PackedType *PT = cast<PackedType>(Ty); @@ -1451,7 +1451,7 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { case Type::PointerTyID: { // ConstantPointerRef value (backwards compat). const PointerType *PT = cast<PointerType>(Ty); unsigned Slot = read_vbr_uint(); - + // Check to see if we have already read this global variable... Value *Val = getValue(TypeID, Slot, false); if (Val) { @@ -1472,8 +1472,8 @@ Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) { return 0; } -/// Resolve references for constants. This function resolves the forward -/// referenced constants in the ConstantFwdRefs map. It uses the +/// Resolve references for constants. This function resolves the forward +/// referenced constants in the ConstantFwdRefs map. It uses the /// replaceAllUsesWith method of Value class to substitute the placeholder /// instance with the actual instance. void BytecodeReader::ResolveReferencesToConstant(Constant *NewV, unsigned Typ, @@ -1497,14 +1497,14 @@ void BytecodeReader::ParseStringConstants(unsigned NumEntries, ValueTable &Tab){ const Type *Ty = getType(Typ); if (!isa<ArrayType>(Ty)) error("String constant data invalid!"); - + const ArrayType *ATy = cast<ArrayType>(Ty); if (ATy->getElementType() != Type::SByteTy && ATy->getElementType() != Type::UByteTy) error("String constant data invalid!"); - + // Read character data. The type tells us how long the string is. - char *Data = reinterpret_cast<char *>(alloca(ATy->getNumElements())); + char *Data = reinterpret_cast<char *>(alloca(ATy->getNumElements())); read_data(Data, Data+ATy->getNumElements()); std::vector<Constant*> Elements(ATy->getNumElements()); @@ -1524,7 +1524,7 @@ void BytecodeReader::ParseStringConstants(unsigned NumEntries, ValueTable &Tab){ } /// Parse the constant pool. -void BytecodeReader::ParseConstantPool(ValueTable &Tab, +void BytecodeReader::ParseConstantPool(ValueTable &Tab, TypeListTy &TypeTab, bool isFunction) { if (Handler) Handler->handleGlobalConstantsBegin(); @@ -1574,9 +1574,9 @@ void BytecodeReader::ParseConstantPool(ValueTable &Tab, if (!ConstantFwdRefs.empty()) { ConstantRefsType::const_iterator I = ConstantFwdRefs.begin(); Constant* missingConst = I->second; - error(utostr(ConstantFwdRefs.size()) + - " unresolved constant reference exist. First one is '" + - missingConst->getName() + "' of type '" + + error(utostr(ConstantFwdRefs.size()) + + " unresolved constant reference exist. First one is '" + + missingConst->getName() + "' of type '" + missingConst->getType()->getDescription() + "'."); } @@ -1658,7 +1658,7 @@ void BytecodeReader::ParseFunctionBody(Function* F) { InsertedArguments = true; } - if (BlockNum) + if (BlockNum) error("Already parsed basic blocks!"); BlockNum = ParseInstructionList(F); break; @@ -1670,7 +1670,7 @@ void BytecodeReader::ParseFunctionBody(Function* F) { default: At += Size; - if (OldAt > At) + if (OldAt > At) error("Wrapped around reading bytecode."); break; } @@ -1709,7 +1709,7 @@ void BytecodeReader::ParseFunctionBody(Function* F) { /// 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 +/// buffer. The caller can then use the ParseNextFunction and /// ParseAllFunctionBodies to get handler events for the functions. void BytecodeReader::ParseFunctionLazily() { if (FunctionSignatureList.empty()) @@ -1729,9 +1729,9 @@ void BytecodeReader::ParseFunctionLazily() { At = BlockEnd; } -/// 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 +/// 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 ParseAllFunctionBodies /// @see ParseBytecode @@ -1811,7 +1811,7 @@ void BytecodeReader::ParseModuleGlobalInfo() { case 2: Linkage = GlobalValue::AppendingLinkage; break; case 3: Linkage = GlobalValue::InternalLinkage; break; case 4: Linkage = GlobalValue::LinkOnceLinkage; break; - default: + default: error("Unknown linkage type: " + utostr(LinkageID)); Linkage = GlobalValue::InternalLinkage; break; @@ -1834,7 +1834,7 @@ void BytecodeReader::ParseModuleGlobalInfo() { insertValue(GV, SlotNo, ModuleValues); unsigned initSlot = 0; - if (hasInitializer) { + if (hasInitializer) { initSlot = read_vbr_uint(); GlobalInits.push_back(std::make_pair(GV, initSlot)); } @@ -1858,17 +1858,17 @@ void BytecodeReader::ParseModuleGlobalInfo() { const Type *Ty = getType(FnSignature >> 5); if (!isa<PointerType>(Ty) || !isa<FunctionType>(cast<PointerType>(Ty)->getElementType())) { - error("Function not a pointer to function type! Ty = " + + error("Function not a pointer to function type! Ty = " + Ty->getDescription()); } // We create functions by passing the underlying FunctionType to create... - const FunctionType* FTy = + const FunctionType* FTy = cast<FunctionType>(cast<PointerType>(Ty)->getElementType()); // Insert the place holder. - Function* Func = new Function(FTy, GlobalValue::ExternalLinkage, + Function* Func = new Function(FTy, GlobalValue::ExternalLinkage, "", TheModule); insertValue(Func, FnSignature >> 5, ModuleValues); @@ -1889,7 +1889,7 @@ void BytecodeReader::ParseModuleGlobalInfo() { FnSignature = (FnSignature << 5) + 1; } - // Now that the function signature list is set up, reverse it so that we can + // Now that the function signature list is set up, reverse it so that we can // remove elements efficiently from the back of the vector. std::reverse(FunctionSignatureList.begin(), FunctionSignatureList.end()); @@ -1937,7 +1937,7 @@ void BytecodeReader::ParseVersionInfo() { bool hasNoEndianness = Version & 4; bool hasNoPointerSize = Version & 8; - + RevisionNum = Version >> 4; // Default values for the current bytecode version @@ -1977,12 +1977,12 @@ void BytecodeReader::ParseVersionInfo() { // LLVM 1.2 and before had the Type class derive from Value class. This // changed in release 1.3 and consequently LLVM 1.3 bytecode files are - // written differently because Types can no longer be part of the + // written differently because Types can no longer be part of the // type planes for Values. hasTypeDerivedFromValue = true; // FALL THROUGH - + case 2: // 1.2.5 (Not Released) // LLVM 1.2 and earlier had two-word block headers. This is a bit wasteful, @@ -1999,7 +1999,7 @@ void BytecodeReader::ParseVersionInfo() { // in various places and to ensure consistency. has32BitTypes = true; - // LLVM 1.2 and earlier did not provide a target triple nor a list of + // LLVM 1.2 and earlier did not provide a target triple nor a list of // libraries on which the bytecode is dependent. LLVM 1.3 provides these // features, for use in future versions of LLVM. hasNoDependentLibraries = true; @@ -2008,13 +2008,13 @@ void BytecodeReader::ParseVersionInfo() { case 3: // LLVM 1.3 (Released) // LLVM 1.3 and earlier caused alignment bytes to be written on some block - // boundaries and at the end of some strings. In extreme cases (e.g. lots + // boundaries and at the end of some strings. In extreme cases (e.g. lots // of GEP references to a constant array), this can increase the file size // by 30% or more. In version 1.4 alignment is done away with completely. hasAlignment = true; // FALL THROUGH - + case 4: // 1.3.1 (Not Released) // In version 4, we did not support the 'undef' constant. hasNoUndefValue = true; @@ -2034,8 +2034,8 @@ void BytecodeReader::ParseVersionInfo() { break; // FIXME: NONE of this is implemented yet! - // In version 5, basic blocks have a minimum index of 0 whereas all the - // other primitives have a minimum index of 1 (because 0 is the "null" + // In version 5, basic blocks have a minimum index of 0 whereas all the + // other primitives have a minimum index of 1 (because 0 is the "null" // value. In version 5, we made this consistent. hasInconsistentBBSlotNums = true; @@ -2090,7 +2090,7 @@ void BytecodeReader::ParseModule() { SeenGlobalTypePlane = true; break; - case BytecodeFormat::ModuleGlobalInfoBlockID: + case BytecodeFormat::ModuleGlobalInfoBlockID: if (SeenModuleGlobalInfo) error("Two ModuleGlobalInfo Blocks Encountered!"); ParseModuleGlobalInfo(); @@ -2133,7 +2133,7 @@ void BytecodeReader::ParseModule() { const llvm::PointerType* GVType = GV->getType(); unsigned TypeSlot = getTypeSlot(GVType->getElementType()); if (Constant *CV = getConstantValue(TypeSlot, Slot)) { - if (GV->hasInitializer()) + if (GV->hasInitializer()) error("Global *already* has an initializer?!"); if (Handler) Handler->handleGlobalInitializer(GV,CV); GV->setInitializer(CV); @@ -2149,7 +2149,7 @@ void BytecodeReader::ParseModule() { /// This function completely parses a bytecode buffer given by the \p Buf /// and \p Length parameters. -void BytecodeReader::ParseBytecode(BufPtr Buf, unsigned Length, +void BytecodeReader::ParseBytecode(BufPtr Buf, unsigned Length, const std::string &ModuleID) { try { @@ -2198,7 +2198,7 @@ void BytecodeReader::ParseBytecode(BufPtr Buf, unsigned Length, Type = read_uint(); Size = read_uint(); if (Type != BytecodeFormat::ModuleBlockID) { - error("Expected Module Block! Type:" + utostr(Type) + ", Size:" + error("Expected Module Block! Type:" + utostr(Type) + ", Size:" + utostr(Size)); } @@ -2220,7 +2220,7 @@ void BytecodeReader::ParseBytecode(BufPtr Buf, unsigned Length, error("Function expected, but bytecode stream ended!"); // Tell the handler we're done with the module - if (Handler) + if (Handler) Handler->handleModuleEnd(ModuleID); // Tell the handler we're finished the parse diff --git a/lib/Bytecode/Reader/Reader.h b/lib/Bytecode/Reader/Reader.h index c63fcc7..425222b 100644 --- a/lib/Bytecode/Reader/Reader.h +++ b/lib/Bytecode/Reader/Reader.h @@ -1,13 +1,13 @@ //===-- Reader.h - Interface To Bytecode Reading ----------------*- C++ -*-===// -// +// // The LLVM Compiler Infrastructure // -// This file was developed by Reid Spencer and is distributed under the +// 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 interface to the Bytecode Reader which is +// This header file defines the interface to the Bytecode Reader which is // responsible for correctly interpreting bytecode files (backwards compatible) // and materializing a module from the bytecode read. // @@ -32,8 +32,8 @@ class BytecodeHandler; ///< Forward declare the handler 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 +/// 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 BytecodeHandler @@ -44,13 +44,13 @@ class BytecodeReader : public ModuleProvider { /// @{ public: /// @brief Default constructor. By default, no handler is used. - BytecodeReader(BytecodeHandler* h = 0) { + BytecodeReader(BytecodeHandler* h = 0) { decompressedBlock = 0; Handler = h; } - ~BytecodeReader() { - freeState(); + ~BytecodeReader() { + freeState(); if (decompressedBlock) { ::free(decompressedBlock); decompressedBlock = 0; @@ -104,7 +104,7 @@ public: /// @brief A 2 dimensional table of values typedef std::vector<ValueList*> ValueTable; - /// This map is needed so that forward references to constants can be looked + /// This map is needed so that forward references to constants can be looked /// up by Type and slot number when resolving those references. /// @brief A mapping of a Type/slot pair to a Constant*. typedef std::map<std::pair<unsigned,unsigned>, Constant*> ConstantRefsType; @@ -112,7 +112,7 @@ public: /// For lazy read-in of functions, we need to save the location in the /// data stream where the function is located. This structure provides that /// information. Lazy read-in is used mostly by the JIT which only wants to - /// resolve functions as it needs them. + /// resolve functions as it needs them. /// @brief Keeps pointers to function contents for later use. struct LazyFunctionInfo { const unsigned char *Buf, *EndBuf; @@ -160,7 +160,7 @@ public: } /// This method is abstract in the parent ModuleProvider class. Its - /// implementation is identical to ParseAllFunctionBodies. + /// implementation is identical to ParseAllFunctionBodies. /// @see ParseAllFunctionBodies /// @brief Make the whole module materialize virtual Module* materializeModule() { @@ -218,7 +218,7 @@ protected: unsigned ParseInstructionList( Function* F ///< The function into which BBs will be inserted ); - + /// @brief Parse a single instruction. void ParseInstruction( std::vector<unsigned>& Args, ///< The arguments to be filled in @@ -226,7 +226,7 @@ protected: ); /// @brief Parse the whole constant pool - void ParseConstantPool(ValueTable& Values, TypeListTy& Types, + void ParseConstantPool(ValueTable& Values, TypeListTy& Types, bool isFunction); /// @brief Parse a single constant value @@ -245,7 +245,7 @@ protected: /// @name Data /// @{ private: - char* decompressedBlock; ///< Result of decompression + char* decompressedBlock; ///< Result of decompression BufPtr MemStart; ///< Start of the memory buffer BufPtr MemEnd; ///< End of the memory buffer BufPtr BlockStart; ///< Start of current block being parsed @@ -291,14 +291,14 @@ private: bool hasLongBlockHeaders; /// LLVM 1.2 and earlier wrote type slot numbers as vbr_uint32. In LLVM 1.3 - /// this has been reduced to vbr_uint24. It shouldn't make much difference + /// this has been reduced to vbr_uint24. It shouldn't make much difference /// since we haven't run into a module with > 24 million types, but for safety /// the 24-bit restriction has been enforced in 1.3 to free some bits in /// various places and to ensure consistency. In particular, global vars are /// restricted to 24-bits. bool has32BitTypes; - /// LLVM 1.2 and earlier did not provide a target triple nor a list of + /// LLVM 1.2 and earlier did not provide a target triple nor a list of /// libraries on which the bytecode is dependent. LLVM 1.3 provides these /// features, for use in future versions of LLVM. bool hasNoDependentLibraries; @@ -321,8 +321,8 @@ private: // unreachable instruction. bool hasNoUnreachableInst; - // In version 5, basic blocks have a minimum index of 0 whereas all the - // other primitives have a minimum index of 1 (because 0 is the "null" + // In version 5, basic blocks have a minimum index of 0 whereas all the + // other primitives have a minimum index of 1 (because 0 is the "null" // value. In version 5, we made this consistent. bool hasInconsistentBBSlotNums; @@ -388,11 +388,11 @@ private: // and its FunctionSlot. LazyFunctionMap LazyFunctionLoadMap; - /// This stores the parser's handler which is used for handling tasks other - /// just than reading bytecode into the IR. If this is non-null, calls on - /// the (polymorphic) BytecodeHandler interface (see llvm/Bytecode/Handler.h) - /// will be made to report the logical structure of the bytecode file. What - /// the handler does with the events it receives is completely orthogonal to + /// This stores the parser's handler which is used for handling tasks other + /// just than reading bytecode into the IR. If this is non-null, calls on + /// the (polymorphic) BytecodeHandler interface (see llvm/Bytecode/Handler.h) + /// will be made to report the logical structure of the bytecode file. What + /// the handler does with the events it receives is completely orthogonal to /// the business of parsing the bytecode and building the IR. This is used, /// for example, by the llvm-abcd tool for analysis of byte code. /// @brief Handler for parsing events. @@ -428,9 +428,9 @@ private: const Type *getGlobalTableType(unsigned TypeId); /// This is just like getTypeSlot, but when a compaction table is in use, - /// it is ignored. + /// it is ignored. unsigned getGlobalTableTypeSlot(const Type *Ty); - + /// @brief Get a value from its typeid and slot number Value* getValue(unsigned TypeID, unsigned num, bool Create = true); @@ -456,7 +456,7 @@ private: /// @brief Insert the arguments of a function. void insertArguments(Function* F ); - /// @brief Resolve all references to the placeholder (if any) for the + /// @brief Resolve all references to the placeholder (if any) for the /// given constant. void ResolveReferencesToConstant(Constant *C, unsigned Typ, unsigned Slot); @@ -534,7 +534,7 @@ private: /// @brief A function for creating a BytecodeAnalzer as a handler /// for the Bytecode reader. -BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca, +BytecodeHandler* createBytecodeAnalyzerHandler(BytecodeAnalysis& bca, std::ostream* output ); diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp index 086409e..81e3416 100644 --- a/lib/Bytecode/Reader/ReaderWrappers.cpp +++ b/lib/Bytecode/Reader/ReaderWrappers.cpp @@ -1,10 +1,10 @@ //===- ReaderWrappers.cpp - Parse bytecode from file or buffer -----------===// -// +// // 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 file implements loading and parsing a bytecode file and parsing a @@ -43,7 +43,7 @@ namespace { } BytecodeFileReader::BytecodeFileReader(const std::string &Filename, - llvm::BytecodeHandler* H ) + llvm::BytecodeHandler* H ) : BytecodeReader(H) , mapFile( sys::Path(Filename)) { @@ -113,7 +113,7 @@ BytecodeBufferReader::~BytecodeBufferReader() { namespace { /// BytecodeStdinReader - parses a bytecode file from stdin - /// + /// class BytecodeStdinReader : public BytecodeReader { private: std::vector<unsigned char> FileData; @@ -127,7 +127,7 @@ namespace { }; } -BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H ) +BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H ) : BytecodeReader(H) { char Buffer[4096*4]; @@ -156,7 +156,7 @@ BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H ) // new style varargs for backwards compatibility. static ModuleProvider *CheckVarargs(ModuleProvider *MP) { Module *M = MP->getModule(); - + // Check to see if va_start takes arguments... Function *F = M->getNamedFunction("llvm.va_start"); if (F == 0) return MP; // No varargs use, just return. @@ -172,11 +172,11 @@ static ModuleProvider *CheckVarargs(ModuleProvider *MP) { // the user. if (Function *F = M->getNamedFunction("llvm.va_start")) { assert(F->arg_size() == 1 && "Obsolete va_start takes 1 argument!"); - + const Type *RetTy = F->getFunctionType()->getParamType(0); RetTy = cast<PointerType>(RetTy)->getElementType(); Function *NF = M->getOrInsertFunction("llvm.va_start", RetTy, 0); - + for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; ) if (CallInst *CI = dyn_cast<CallInst>(*I++)) { Value *V = new CallInst(NF, "", CI); @@ -192,7 +192,7 @@ static ModuleProvider *CheckVarargs(ModuleProvider *MP) { ArgTy = cast<PointerType>(ArgTy)->getElementType(); Function *NF = M->getOrInsertFunction("llvm.va_end", Type::VoidTy, ArgTy, 0); - + for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; ) if (CallInst *CI = dyn_cast<CallInst>(*I++)) { Value *V = new LoadInst(CI->getOperand(1), "", CI); @@ -201,14 +201,14 @@ static ModuleProvider *CheckVarargs(ModuleProvider *MP) { } F->setName(""); } - + if (Function *F = M->getNamedFunction("llvm.va_copy")) { assert(F->arg_size() == 2 && "Obsolete va_copy takes 2 argument!"); const Type *ArgTy = F->getFunctionType()->getParamType(0); ArgTy = cast<PointerType>(ArgTy)->getElementType(); Function *NF = M->getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, 0); - + for (Value::use_iterator I = F->use_begin(), E = F->use_end(); I != E; ) if (CallInst *CI = dyn_cast<CallInst>(*I++)) { Value *V = new CallInst(NF, CI->getOperand(2), "", CI); @@ -226,7 +226,7 @@ static ModuleProvider *CheckVarargs(ModuleProvider *MP) { /// getBytecodeBufferModuleProvider - lazy function-at-a-time loading from a /// buffer -ModuleProvider* +ModuleProvider* llvm::getBytecodeBufferModuleProvider(const unsigned char *Buffer, unsigned Length, const std::string &ModuleID, @@ -313,7 +313,7 @@ Module* llvm::AnalyzeBytecodeBuffer( } } -bool llvm::GetBytecodeDependentLibraries(const std::string &fname, +bool llvm::GetBytecodeDependentLibraries(const std::string &fname, Module::LibraryListType& deplibs) { try { std::auto_ptr<ModuleProvider> AMP( getBytecodeModuleProvider(fname)); @@ -346,7 +346,7 @@ static void getSymbols(Module*M, std::vector<std::string>& symbols) { bool llvm::GetBytecodeSymbols(const sys::Path& fName, std::vector<std::string>& symbols) { try { - std::auto_ptr<ModuleProvider> AMP( + std::auto_ptr<ModuleProvider> AMP( getBytecodeModuleProvider(fName.toString())); // Get the module from the provider @@ -363,7 +363,7 @@ bool llvm::GetBytecodeSymbols(const sys::Path& fName, } } -ModuleProvider* +ModuleProvider* llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length, const std::string& ModuleID, std::vector<std::string>& symbols) { |