aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/Interpreter/Execution.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-04-20 16:43:21 +0000
committerChris Lattner <sabre@nondot.org>2004-04-20 16:43:21 +0000
commit759d34ffb718cf35e97682b5bd541beb82d9a192 (patch)
treecfe73e5d385983108949f19606e846b1aad98339 /lib/ExecutionEngine/Interpreter/Execution.cpp
parent0eb61037f7f554f705a511b47a6cf43f0b39bb9a (diff)
Add support for the select instruction
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13076 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/Interpreter/Execution.cpp')
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index 456e2a8f3c..2ecd72eb3b 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -66,7 +66,9 @@ static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2,
const Type *Ty);
-
+static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2,
+ GenericValue Src3);
+
GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
ExecutionContext &SF) {
switch (CE->getOpcode()) {
@@ -139,7 +141,10 @@ GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
return executeShrInst(getOperandValue(CE->getOperand(0), SF),
getOperandValue(CE->getOperand(1), SF),
CE->getOperand(0)->getType());
-
+ case Instruction::Select:
+ return executeSelectInst(getOperandValue(CE->getOperand(0), SF),
+ getOperandValue(CE->getOperand(1), SF),
+ getOperandValue(CE->getOperand(2), SF));
default:
std::cerr << "Unhandled ConstantExpr: " << CE << "\n";
abort();
@@ -518,6 +523,21 @@ void Interpreter::visitBinaryOperator(BinaryOperator &I) {
SetValue(&I, R, SF);
}
+static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2,
+ GenericValue Src3) {
+ return Src1.BoolVal ? Src2 : Src3;
+}
+
+void Interpreter::visitSelectInst(SelectInst &I) {
+ ExecutionContext &SF = ECStack.back();
+ GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
+ GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
+ GenericValue Src3 = getOperandValue(I.getOperand(2), SF);
+ GenericValue R = executeSelectInst(Src1, Src2, Src3);
+ SetValue(&I, R, SF);
+}
+
+
//===----------------------------------------------------------------------===//
// Terminator Instruction Implementations
//===----------------------------------------------------------------------===//