use isValidOperands instead of duplicating checks

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27527 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2006-04-08 04:09:19 +00:00
parent f4bd7d8151
commit 59fecec7d0

View File

@@ -719,19 +719,27 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
case Instruction::ExtractElement: { case Instruction::ExtractElement: {
if (Oprnds.size() != 2) if (Oprnds.size() != 2)
throw std::string("Invalid extractelement instruction!"); throw std::string("Invalid extractelement instruction!");
Result = new ExtractElementInst(getValue(iType, Oprnds[0]), Value *V1 = getValue(iType, Oprnds[0]);
getValue(Type::UIntTyID, Oprnds[1])); Value *V2 = getValue(Type::UIntTyID, Oprnds[1]);
if (!ExtractElementInst::isValidOperands(V1, V2))
throw std::string("Invalid extractelement instruction!");
Result = new ExtractElementInst(V1, V2);
break; break;
} }
case Instruction::InsertElement: { case Instruction::InsertElement: {
const PackedType *PackedTy = dyn_cast<PackedType>(InstTy); const PackedType *PackedTy = dyn_cast<PackedType>(InstTy);
if (!PackedTy || Oprnds.size() != 3) if (!PackedTy || Oprnds.size() != 3)
throw std::string("Invalid insertelement instruction!"); throw std::string("Invalid insertelement instruction!");
Result =
new InsertElementInst(getValue(iType, Oprnds[0]), Value *V1 = getValue(iType, Oprnds[0]);
getValue(getTypeSlot(PackedTy->getElementType()), Value *V2 = getValue(getTypeSlot(PackedTy->getElementType()), Oprnds[1]);
Oprnds[1]), Value *V3 = getValue(Type::UIntTyID, Oprnds[2]);
getValue(Type::UIntTyID, Oprnds[2]));
if (!InsertElementInst::isValidOperands(V1, V2, V3))
throw std::string("Invalid insertelement instruction!");
Result = new InsertElementInst(V1, V2, V3);
break; break;
} }
case Instruction::ShuffleVector: { case Instruction::ShuffleVector: {
@@ -1495,22 +1503,25 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result); if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
return Result; return Result;
} else if (Opcode == Instruction::ExtractElement) { } else if (Opcode == Instruction::ExtractElement) {
if (ArgVec.size() != 2) if (ArgVec.size() != 2 ||
error("ExtractElement instruction must have two arguments."); !ExtractElementInst::isValidOperands(ArgVec[0], ArgVec[1]))
error("Invalid extractelement constand expr arguments");
Constant* Result = ConstantExpr::getExtractElement(ArgVec[0], ArgVec[1]); Constant* Result = ConstantExpr::getExtractElement(ArgVec[0], ArgVec[1]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result); if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
return Result; return Result;
} else if (Opcode == Instruction::InsertElement) { } else if (Opcode == Instruction::InsertElement) {
if (ArgVec.size() != 3) if (ArgVec.size() != 3 ||
error("InsertElement instruction must have three arguments."); !InsertElementInst::isValidOperands(ArgVec[0], ArgVec[1], ArgVec[2]))
Constant* Result = error("Invalid insertelement constand expr arguments");
Constant *Result =
ConstantExpr::getInsertElement(ArgVec[0], ArgVec[1], ArgVec[2]); ConstantExpr::getInsertElement(ArgVec[0], ArgVec[1], ArgVec[2]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result); if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);
return Result; return Result;
} else if (Opcode == Instruction::ShuffleVector) { } else if (Opcode == Instruction::ShuffleVector) {
if (ArgVec.size() != 3 || if (ArgVec.size() != 3 ||
!ShuffleVectorInst::isValidOperands(ArgVec[0], ArgVec[1], ArgVec[2])) !ShuffleVectorInst::isValidOperands(ArgVec[0], ArgVec[1], ArgVec[2]))
error("shufflevector constant expr must have three arguments."); error("Invalid shufflevector constant expr arguments.");
Constant *Result = Constant *Result =
ConstantExpr::getShuffleVector(ArgVec[0], ArgVec[1], ArgVec[2]); ConstantExpr::getShuffleVector(ArgVec[0], ArgVec[1], ArgVec[2]);
if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result); if (Handler) Handler->handleConstantExpression(Opcode, ArgVec, Result);