mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-18 12:27:55 +00:00
Change getConstantValue to throw an exception on error, not return null
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8988 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -165,9 +165,7 @@ Constant *BytecodeParser::parseConstantValue(const unsigned char *&Buf,
|
|||||||
<< ArgValSlot << "\n");
|
<< ArgValSlot << "\n");
|
||||||
|
|
||||||
// Get the arg value from its slot if it exists, otherwise a placeholder
|
// Get the arg value from its slot if it exists, otherwise a placeholder
|
||||||
Constant *C = getConstantValue(ArgTy, ArgValSlot);
|
ArgVec.push_back(getConstantValue(ArgTy, ArgValSlot));
|
||||||
if (C == 0) throw std::string("No arg value or placeholder found.");
|
|
||||||
ArgVec.push_back(C);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a ConstantExpr of the appropriate kind
|
// Construct a ConstantExpr of the appropriate kind
|
||||||
@@ -241,9 +239,7 @@ Constant *BytecodeParser::parseConstantValue(const unsigned char *&Buf,
|
|||||||
while (NumElements--) { // Read all of the elements of the constant.
|
while (NumElements--) { // Read all of the elements of the constant.
|
||||||
unsigned Slot;
|
unsigned Slot;
|
||||||
if (read_vbr(Buf, EndBuf, Slot)) throw Error_readvbr;
|
if (read_vbr(Buf, EndBuf, Slot)) throw Error_readvbr;
|
||||||
Constant *C = getConstantValue(AT->getElementType(), Slot);
|
Elements.push_back(getConstantValue(AT->getElementType(), Slot));
|
||||||
if (!C) throw std::string("Unable to get const value of array slot.");
|
|
||||||
Elements.push_back(C);
|
|
||||||
}
|
}
|
||||||
return ConstantArray::get(AT, Elements);
|
return ConstantArray::get(AT, Elements);
|
||||||
}
|
}
|
||||||
@@ -256,9 +252,7 @@ Constant *BytecodeParser::parseConstantValue(const unsigned char *&Buf,
|
|||||||
for (unsigned i = 0; i < ET.size(); ++i) {
|
for (unsigned i = 0; i < ET.size(); ++i) {
|
||||||
unsigned Slot;
|
unsigned Slot;
|
||||||
if (read_vbr(Buf, EndBuf, Slot)) throw Error_readvbr;
|
if (read_vbr(Buf, EndBuf, Slot)) throw Error_readvbr;
|
||||||
Constant *C = getConstantValue(ET[i], Slot);
|
Elements.push_back(getConstantValue(ET[i], Slot));
|
||||||
if (!C) throw std::string("Could not read const value in struct slot.");
|
|
||||||
Elements.push_back(C);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConstantStruct::get(ST, Elements);
|
return ConstantStruct::get(ST, Elements);
|
||||||
|
@@ -164,7 +164,10 @@ BasicBlock *BytecodeParser::getBasicBlock(unsigned ID) {
|
|||||||
///
|
///
|
||||||
Constant *BytecodeParser::getConstantValue(const Type *Ty, unsigned Slot) {
|
Constant *BytecodeParser::getConstantValue(const Type *Ty, unsigned Slot) {
|
||||||
if (Value *V = getValue(Ty, Slot, false))
|
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);
|
std::pair<const Type*, unsigned> Key(Ty, Slot);
|
||||||
GlobalRefsType::iterator I = GlobalRefs.lower_bound(Key);
|
GlobalRefsType::iterator I = GlobalRefs.lower_bound(Key);
|
||||||
|
Reference in New Issue
Block a user