ConstExpr::getelementptr now takes a vector of Constants not Values

llvm-svn: 2948
This commit is contained in:
Chris Lattner 2002-07-18 00:14:27 +00:00
parent 7af3ee9840
commit 980ddf5854
2 changed files with 13 additions and 3 deletions

View File

@ -969,13 +969,23 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
}; };
// FIXME: ConstExpr::get never return null!
ConstExpr: Types CAST ConstVal { ConstExpr: Types CAST ConstVal {
ConstantExpr* CPE = ConstantExpr::get($2, $3, $1->get()); ConstantExpr* CPE = ConstantExpr::get($2, $3, $1->get());
if (CPE == 0) ThrowException("constant expression builder returned null!"); if (CPE == 0) ThrowException("constant expression builder returned null!");
$$ = CPE; $$ = CPE;
} }
| Types GETELEMENTPTR '(' ConstVal IndexList ')' { | Types GETELEMENTPTR '(' ConstVal IndexList ')' {
ConstantExpr* CPE = ConstantExpr::get($2, $4, *$5, $1->get()); vector<Constant*> IdxVec;
for (unsigned i = 0, e = $5->size(); i != e; ++i)
if (Constant *C = dyn_cast<Constant>((*$5)[i]))
IdxVec.push_back(C);
else
ThrowException("Arguments to getelementptr must be constants!");
delete $5;
ConstantExpr* CPE = ConstantExpr::get($2, $4, IdxVec, $1->get());
if (CPE == 0) ThrowException("constant expression builder returned null!"); if (CPE == 0) ThrowException("constant expression builder returned null!");
$$ = CPE; $$ = CPE;
} }

View File

@ -204,7 +204,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
// 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
Value *Val = getValue(argTy, argValSlot, false); Value *Val = getValue(argTy, argValSlot, false);
Constant* C; Constant *C;
if (Val) { if (Val) {
if (!(C = dyn_cast<Constant>(Val))) return failure(true); if (!(C = dyn_cast<Constant>(Val))) return failure(true);
BCR_TRACE(5, "Constant Found in ValueTable!\n"); BCR_TRACE(5, "Constant Found in ValueTable!\n");
@ -218,7 +218,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
if (isExprNumArgs == 1) { // All one-operand expressions if (isExprNumArgs == 1) { // All one-operand expressions
V = ConstantExpr::get(opCode, argVec[0], Ty); V = ConstantExpr::get(opCode, argVec[0], Ty);
} else if (opCode == Instruction::GetElementPtr) { // GetElementPtr } else if (opCode == Instruction::GetElementPtr) { // GetElementPtr
std::vector<Value*> IdxList(argVec.begin()+1, argVec.end()); std::vector<Constant*> IdxList(argVec.begin()+1, argVec.end());
V = ConstantExpr::get(opCode, argVec[0], IdxList, Ty); V = ConstantExpr::get(opCode, argVec[0], IdxList, Ty);
} else { // All other 2-operand expressions } else { // All other 2-operand expressions
V = ConstantExpr::get(opCode, argVec[0], argVec[1], Ty); V = ConstantExpr::get(opCode, argVec[0], argVec[1], Ty);