[llvm-commits] CVS: llvm/lib/Bytecode/Reader/ConstantReader.cpp Reader.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Oct 9 15:42:01 PDT 2003
Changes in directory llvm/lib/Bytecode/Reader:
ConstantReader.cpp updated: 1.56 -> 1.57
Reader.cpp updated: 1.75 -> 1.76
---
Log message:
Change getConstantValue to throw an exception on error, not return null
---
Diffs of the changes: (+7 -10)
Index: llvm/lib/Bytecode/Reader/ConstantReader.cpp
diff -u llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.56 llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.57
--- llvm/lib/Bytecode/Reader/ConstantReader.cpp:1.56 Thu Oct 9 15:22:47 2003
+++ llvm/lib/Bytecode/Reader/ConstantReader.cpp Thu Oct 9 15:41:16 2003
@@ -165,9 +165,7 @@
<< ArgValSlot << "\n");
// Get the arg value from its slot if it exists, otherwise a placeholder
- Constant *C = getConstantValue(ArgTy, ArgValSlot);
- if (C == 0) throw std::string("No arg value or placeholder found.");
- ArgVec.push_back(C);
+ ArgVec.push_back(getConstantValue(ArgTy, ArgValSlot));
}
// Construct a ConstantExpr of the appropriate kind
@@ -241,9 +239,7 @@
while (NumElements--) { // Read all of the elements of the constant.
unsigned Slot;
if (read_vbr(Buf, EndBuf, Slot)) throw Error_readvbr;
- Constant *C = getConstantValue(AT->getElementType(), Slot);
- if (!C) throw std::string("Unable to get const value of array slot.");
- Elements.push_back(C);
+ Elements.push_back(getConstantValue(AT->getElementType(), Slot));
}
return ConstantArray::get(AT, Elements);
}
@@ -256,9 +252,7 @@
for (unsigned i = 0; i < ET.size(); ++i) {
unsigned Slot;
if (read_vbr(Buf, EndBuf, Slot)) throw Error_readvbr;
- Constant *C = getConstantValue(ET[i], Slot);
- if (!C) throw std::string("Could not read const value in struct slot.");
- Elements.push_back(C);
+ Elements.push_back(getConstantValue(ET[i], Slot));
}
return ConstantStruct::get(ST, Elements);
Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.75 llvm/lib/Bytecode/Reader/Reader.cpp:1.76
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.75 Thu Oct 9 15:30:04 2003
+++ llvm/lib/Bytecode/Reader/Reader.cpp Thu Oct 9 15:41:16 2003
@@ -164,7 +164,10 @@
///
Constant *BytecodeParser::getConstantValue(const Type *Ty, unsigned Slot) {
if (Value *V = getValue(Ty, Slot, false))
- return dyn_cast<Constant>(V); // If we already have the value parsed...
+ if (Constant *C = dyn_cast<Constant>(V))
+ return C; // If we already have the value parsed, just return it
+ else
+ throw std::string("Reference of a value is expected to be a constant!");
std::pair<const Type*, unsigned> Key(Ty, Slot);
GlobalRefsType::iterator I = GlobalRefs.lower_bound(Key);
More information about the llvm-commits
mailing list