Suggestions made by Chris:

* Instead of a #define, use inline function
* Fix the name on the #define, errr... now inline function to be more logical:
  it doesn't CHECK the alignment, it PERFORMS the alignment
* To get string name of a Type*, use getDescription(), not getName()


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8683 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Misha Brukman
2003-09-23 16:15:29 +00:00
parent d57308a33c
commit e0dd0d47cb

View File

@@ -25,10 +25,11 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#define CHECK_ALIGN32(begin,end) \ static inline void ALIGN32(const unsigned char *&begin,
if (align32(begin,end)) \ const unsigned char *end) {
throw std::string("Alignment error: Reader.cpp:" + \ if (align32(begin, end))
utostr((unsigned)__LINE__)); throw std::string("Alignment error in buffer: read past end of block.");
}
void void
BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) { BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) {
@@ -202,7 +203,8 @@ void BytecodeParser::postResolveValues(ValueTable &ValTab) {
Value *NewDef = getValue(D->getType(), IDNumber, false); Value *NewDef = getValue(D->getType(), IDNumber, false);
if (NewDef == 0) { if (NewDef == 0) {
throw std::string("Unresolvable reference found: <" + throw std::string("Unresolvable reference found: <" +
D->getType()->getName() + ">:" +utostr(IDNumber)+"."); D->getType()->getDescription() + ">:" +
utostr(IDNumber) + ".");
} else { } else {
// Fixup all of the uses of this placeholder def... // Fixup all of the uses of this placeholder def...
D->replaceAllUsesWith(NewDef); D->replaceAllUsesWith(NewDef);
@@ -389,7 +391,7 @@ void BytecodeParser::materializeFunction(Function* F) {
BCR_TRACE(2, "} end block\n"); BCR_TRACE(2, "} end block\n");
// Malformed bc file if read past end of block. // Malformed bc file if read past end of block.
CHECK_ALIGN32(Buf, EndBuf); ALIGN32(Buf, EndBuf);
} }
// Check for unresolvable references // Check for unresolvable references
@@ -486,7 +488,7 @@ void BytecodeParser::ParseModuleGlobalInfo(const unsigned char *&Buf,
BCR_TRACE(2, "Function of type: " << Ty << "\n"); BCR_TRACE(2, "Function of type: " << Ty << "\n");
} }
CHECK_ALIGN32(Buf, End); ALIGN32(Buf, End);
// 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. // remove elements efficiently from the back of the vector.
@@ -570,7 +572,7 @@ void BytecodeParser::ParseModule(const unsigned char *Buf,
// Read into instance variables... // Read into instance variables...
ParseVersionInfo(Buf, EndBuf); ParseVersionInfo(Buf, EndBuf);
CHECK_ALIGN32(Buf, EndBuf); ALIGN32(Buf, EndBuf);
while (Buf < EndBuf) { while (Buf < EndBuf) {
const unsigned char *OldBuf = Buf; const unsigned char *OldBuf = Buf;
@@ -608,7 +610,7 @@ void BytecodeParser::ParseModule(const unsigned char *Buf,
break; break;
} }
BCR_TRACE(1, "} end block\n"); BCR_TRACE(1, "} end block\n");
CHECK_ALIGN32(Buf, EndBuf); ALIGN32(Buf, EndBuf);
} }
// After the module constant pool has been read, we can safely initialize // After the module constant pool has been read, we can safely initialize
@@ -636,9 +638,11 @@ void BytecodeParser::ParseModule(const unsigned char *Buf,
void void
BytecodeParser::ParseBytecode(const unsigned char *Buf, unsigned Length, BytecodeParser::ParseBytecode(const unsigned char *Buf, unsigned Length,
const std::string &ModuleID) { const std::string &ModuleID) {
unsigned Sig;
unsigned char *EndBuf = (unsigned char*)(Buf + Length); unsigned char *EndBuf = (unsigned char*)(Buf + Length);
// Read and check signature... // Read and check signature...
unsigned Sig;
if (read(Buf, EndBuf, Sig) || if (read(Buf, EndBuf, Sig) ||
Sig != ('l' | ('l' << 8) | ('v' << 16) | ('m' << 24))) Sig != ('l' | ('l' << 8) | ('v' << 16) | ('m' << 24)))
throw std::string("Invalid bytecode signature!"); throw std::string("Invalid bytecode signature!");