<< ArgValSlot << "\n");
// Get the arg value from its slot if it exists, otherwise a placeholder
- Value *Val = getValue(ArgTy, ArgValSlot, false);
- Constant *C;
- if (Val) {
- if (!(C = dyn_cast<Constant>(Val))) return true;
- BCR_TRACE(5, "Constant Found in ValueTable!\n");
- } else { // Nope... find or create a forward ref. for it
- GlobalRefsType::iterator I =
- GlobalRefs.find(make_pair(ArgTy, ArgValSlot));
-
- if (I != GlobalRefs.end()) {
- BCR_TRACE(5, "Previous forward ref found!\n");
- C = cast<Constant>(I->second);
- } else {
- // Create a placeholder for the constant reference and
- // keep track of the fact that we have a forward ref to recycle it
- BCR_TRACE(5, "Creating new forward ref to a constant!\n");
- C = new ConstPHolder(ArgTy, ArgValSlot);
-
- // Keep track of the fact that we have a forward ref to recycle it
- GlobalRefs.insert(make_pair(make_pair(ArgTy, ArgValSlot), C));
- }
- }
+ Constant *C = getConstantValue(ArgTy, ArgValSlot);
+ if (C == 0) return true;
ArgVec.push_back(C);
}
while (NumElements--) { // Read all of the elements of the constant.
unsigned Slot;
if (read_vbr(Buf, EndBuf, Slot)) return true;
- Value *V = getValue(AT->getElementType(), Slot, false);
- if (!V || !isa<Constant>(V)) return true;
- Elements.push_back(cast<Constant>(V));
+ Constant *C = getConstantValue(AT->getElementType(), Slot);
+ if (!C) return true;
+ Elements.push_back(C);
}
V = ConstantArray::get(AT, Elements);
break;
for (unsigned i = 0; i < ET.size(); ++i) {
unsigned Slot;
if (read_vbr(Buf, EndBuf, Slot)) return true;
- Value *V = getValue(ET[i], Slot, false);
- if (!V || !isa<Constant>(V))
- return true;
- Elements.push_back(cast<Constant>(V));
+ Constant *C = getConstantValue(ET[i], Slot);
+ if (!C) return true;
+ Elements.push_back(C);
}
V = ConstantStruct::get(ST, Elements);
return d;
}
+/// getConstantValue - 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. Later,
+/// after the real value is parsed, the placeholder is eliminated.
+///
+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...
+
+ GlobalRefsType::iterator I = GlobalRefs.find(make_pair(Ty, Slot));
+ if (I != GlobalRefs.end()) {
+ BCR_TRACE(5, "Previous forward ref found!\n");
+ return cast<Constant>(I->second);
+ } else {
+ // Create a placeholder for the constant reference and
+ // keep track of the fact that we have a forward ref to recycle it
+ BCR_TRACE(5, "Creating new forward ref to a constant!\n");
+ Constant *C = new ConstPHolder(Ty, Slot);
+
+ // Keep track of the fact that we have a forward ref to recycle it
+ GlobalRefs.insert(make_pair(make_pair(Ty, Slot), C));
+ return C;
+ }
+}
+
+
+
bool BytecodeParser::postResolveValues(ValueTable &ValTab) {
bool Error = false;
for (unsigned ty = 0; ty < ValTab.size(); ++ty) {