aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bytecode/Reader/ConstantReader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-28 17:50:18 +0000
committerChris Lattner <sabre@nondot.org>2001-07-28 17:50:18 +0000
commit3d3f289eac5e85f65e55ca2798d0f0f1b7218163 (patch)
tree5d4830712de96f2d15734853bc8a3ee1e767397f /lib/Bytecode/Reader/ConstantReader.cpp
parent81e29632f70bcd789af6d27b4622ea3cba162aba (diff)
downloadexternal_llvm-3d3f289eac5e85f65e55ca2798d0f0f1b7218163.zip
external_llvm-3d3f289eac5e85f65e55ca2798d0f0f1b7218163.tar.gz
external_llvm-3d3f289eac5e85f65e55ca2798d0f0f1b7218163.tar.bz2
* Add calls to failure template so that it is actually possible to debug
why bytecode parsing is failing. Just put a breakpoint in the failure templates. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader/ConstantReader.cpp')
-rw-r--r--lib/Bytecode/Reader/ConstantReader.cpp74
1 files changed, 37 insertions, 37 deletions
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp
index e367d02..ec841cf 100644
--- a/lib/Bytecode/Reader/ConstantReader.cpp
+++ b/lib/Bytecode/Reader/ConstantReader.cpp
@@ -19,7 +19,7 @@ bool BytecodeParser::parseTypeConstant(const uchar *&Buf, const uchar *EndBuf,
const Type *Val = 0;
unsigned PrimType;
- if (read_vbr(Buf, EndBuf, PrimType)) return true;
+ if (read_vbr(Buf, EndBuf, PrimType)) return failure(true);
if ((Val = Type::getPrimitiveType((Type::PrimitiveID)PrimType))) {
V = new ConstPoolType(Val); // It's just a primitive ID.
@@ -29,18 +29,18 @@ bool BytecodeParser::parseTypeConstant(const uchar *&Buf, const uchar *EndBuf,
switch (PrimType) {
case Type::MethodTyID: {
unsigned Typ;
- if (read_vbr(Buf, EndBuf, Typ)) return true;
+ if (read_vbr(Buf, EndBuf, Typ)) return failure(true);
const Type *RetType = getType(Typ);
- if (RetType == 0) return true;
+ if (RetType == 0) return failure(true);
unsigned NumParams;
- if (read_vbr(Buf, EndBuf, NumParams)) return true;
+ if (read_vbr(Buf, EndBuf, NumParams)) return failure(true);
MethodType::ParamTypes Params;
while (NumParams--) {
- if (read_vbr(Buf, EndBuf, Typ)) return true;
+ if (read_vbr(Buf, EndBuf, Typ)) return failure(true);
const Type *Ty = getType(Typ);
- if (Ty == 0) return true;
+ if (Ty == 0) return failure(true);
Params.push_back(Ty);
}
@@ -49,12 +49,12 @@ bool BytecodeParser::parseTypeConstant(const uchar *&Buf, const uchar *EndBuf,
}
case Type::ArrayTyID: {
unsigned ElTyp;
- if (read_vbr(Buf, EndBuf, ElTyp)) return true;
+ if (read_vbr(Buf, EndBuf, ElTyp)) return failure(true);
const Type *ElementType = getType(ElTyp);
- if (ElementType == 0) return true;
+ if (ElementType == 0) return failure(true);
int NumElements;
- if (read_vbr(Buf, EndBuf, NumElements)) return true;
+ if (read_vbr(Buf, EndBuf, NumElements)) return failure(true);
Val = ArrayType::getArrayType(ElementType, NumElements);
break;
}
@@ -62,13 +62,13 @@ bool BytecodeParser::parseTypeConstant(const uchar *&Buf, const uchar *EndBuf,
unsigned Typ;
StructType::ElementTypes Elements;
- if (read_vbr(Buf, EndBuf, Typ)) return true;
+ if (read_vbr(Buf, EndBuf, Typ)) return failure(true);
while (Typ) { // List is terminated by void/0 typeid
const Type *Ty = getType(Typ);
- if (Ty == 0) return true;
+ if (Ty == 0) return failure(true);
Elements.push_back(Ty);
- if (read_vbr(Buf, EndBuf, Typ)) return true;
+ if (read_vbr(Buf, EndBuf, Typ)) return failure(true);
}
Val = StructType::getStructType(Elements);
@@ -76,9 +76,9 @@ bool BytecodeParser::parseTypeConstant(const uchar *&Buf, const uchar *EndBuf,
}
case Type::PointerTyID: {
unsigned ElTyp;
- if (read_vbr(Buf, EndBuf, ElTyp)) return true;
+ if (read_vbr(Buf, EndBuf, ElTyp)) return failure(true);
const Type *ElementType = getType(ElTyp);
- if (ElementType == 0) return true;
+ if (ElementType == 0) return failure(true);
Val = PointerType::getPointerType(ElementType);
break;
}
@@ -86,7 +86,7 @@ bool BytecodeParser::parseTypeConstant(const uchar *&Buf, const uchar *EndBuf,
default:
cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to deserialize"
<< " primitive Type " << PrimType << "\n";
- return true;
+ return failure(true);
}
V = new ConstPoolType(Val);
@@ -99,8 +99,8 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
switch (Ty->getPrimitiveID()) {
case Type::BoolTyID: {
unsigned Val;
- if (read_vbr(Buf, EndBuf, Val)) return true;
- if (Val != 0 && Val != 1) return true;
+ if (read_vbr(Buf, EndBuf, Val)) return failure(true);
+ if (Val != 0 && Val != 1) return failure(true);
V = new ConstPoolBool(Val == 1);
break;
}
@@ -109,15 +109,15 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
case Type::UShortTyID:
case Type::UIntTyID: {
unsigned Val;
- if (read_vbr(Buf, EndBuf, Val)) return true;
- if (!ConstPoolUInt::isValueValidForType(Ty, Val)) return true;
+ if (read_vbr(Buf, EndBuf, Val)) return failure(true);
+ if (!ConstPoolUInt::isValueValidForType(Ty, Val)) return failure(true);
V = new ConstPoolUInt(Ty, Val);
break;
}
case Type::ULongTyID: {
uint64_t Val;
- if (read_vbr(Buf, EndBuf, Val)) return true;
+ if (read_vbr(Buf, EndBuf, Val)) return failure(true);
V = new ConstPoolUInt(Ty, Val);
break;
}
@@ -126,35 +126,35 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
case Type::ShortTyID:
case Type::IntTyID: {
int Val;
- if (read_vbr(Buf, EndBuf, Val)) return true;
- if (!ConstPoolSInt::isValueValidForType(Ty, Val)) return 0;
+ if (read_vbr(Buf, EndBuf, Val)) return failure(true);
+ if (!ConstPoolSInt::isValueValidForType(Ty, Val)) return failure(true);
V = new ConstPoolSInt(Ty, Val);
break;
}
case Type::LongTyID: {
int64_t Val;
- if (read_vbr(Buf, EndBuf, Val)) return true;
+ if (read_vbr(Buf, EndBuf, Val)) return failure(true);
V = new ConstPoolSInt(Ty, Val);
break;
}
case Type::FloatTyID: {
float F;
- if (input_data(Buf, EndBuf, &F, &F+1)) return true;
+ if (input_data(Buf, EndBuf, &F, &F+1)) return failure(true);
V = new ConstPoolFP(Ty, F);
break;
}
case Type::DoubleTyID: {
double Val;
- if (input_data(Buf, EndBuf, &Val, &Val+1)) return true;
+ if (input_data(Buf, EndBuf, &Val, &Val+1)) return failure(true);
V = new ConstPoolFP(Ty, Val);
break;
}
case Type::TypeTyID:
- if (parseTypeConstant(Buf, EndBuf, V)) return true;
+ if (parseTypeConstant(Buf, EndBuf, V)) return failure(true);
break;
case Type::ArrayTyID: {
@@ -163,15 +163,14 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
if (AT->isSized()) // Sized array, # elements stored in type!
NumElements = (unsigned)AT->getNumElements();
else // Unsized array, # elements stored in stream!
- if (read_vbr(Buf, EndBuf, NumElements)) return true;
+ if (read_vbr(Buf, EndBuf, NumElements)) return failure(true);
vector<ConstPoolVal *> Elements;
while (NumElements--) { // Read all of the elements of the constant.
unsigned Slot;
- if (read_vbr(Buf, EndBuf, Slot)) return true;
+ if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
Value *V = getValue(AT->getElementType(), Slot, false);
- if (!V || !V->isConstant())
- return true;
+ if (!V || !V->isConstant()) return failure(true);
Elements.push_back((ConstPoolVal*)V);
}
V = new ConstPoolArray(AT, Elements);
@@ -185,10 +184,10 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
vector<ConstPoolVal *> Elements;
for (unsigned i = 0; i < ET.size(); ++i) {
unsigned Slot;
- if (read_vbr(Buf, EndBuf, Slot)) return true;
+ if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
Value *V = getValue(ET[i], Slot, false);
if (!V || !V->isConstant())
- return true;
+ return failure(true);
Elements.push_back((ConstPoolVal*)V);
}
@@ -200,7 +199,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
cerr << __FILE__ << ":" << __LINE__
<< ": Don't know how to deserialize constant value of type '"
<< Ty->getName() << "'\n";
- return true;
+ return failure(true);
}
return false;
}
@@ -212,13 +211,13 @@ bool BytecodeParser::ParseConstantPool(const uchar *&Buf, const uchar *EndBuf,
unsigned NumEntries, Typ;
if (read_vbr(Buf, EndBuf, NumEntries) ||
- read_vbr(Buf, EndBuf, Typ)) return true;
+ read_vbr(Buf, EndBuf, Typ)) return failure(true);
const Type *Ty = getType(Typ);
- if (Ty == 0) return true;
+ if (Ty == 0) return failure(true);
for (unsigned i = 0; i < NumEntries; i++) {
ConstPoolVal *I;
- if (parseConstPoolValue(Buf, EndBuf, Ty, I)) return true;
+ if (parseConstPoolValue(Buf, EndBuf, Ty, I)) return failure(true);
#if 0
cerr << " Read const value: <" << I->getType()->getName()
<< ">: " << I->getStrValue() << endl;
@@ -228,5 +227,6 @@ bool BytecodeParser::ParseConstantPool(const uchar *&Buf, const uchar *EndBuf,
}
}
- return Buf > EndBuf;
+ if (Buf > EndBuf) return failure(true);
+ return false;
}