From fefd3bebc403859150546957bcdb7fb72254e714 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 18 Oct 2003 05:55:25 +0000 Subject: [PATCH] Interpret the new varargs intrinsics correctly llvm-svn: 9222 --- .../ExecutionEngine/Interpreter/Execution.cpp | 22 +++++-------------- .../Interpreter/ExternalFunctions.cpp | 17 +++++--------- .../ExecutionEngine/Interpreter/Interpreter.h | 2 +- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp index 7d9d727e7667..69e746d1591b 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -845,27 +845,17 @@ void Interpreter::visitCastInst(CastInst &I) { SetValue(&I, executeCastOperation(I.getOperand(0), I.getType(), SF), SF); } -void Interpreter::visitVarArgInst(VarArgInst &I) { +void Interpreter::visitVANextInst(VANextInst &I) { ExecutionContext &SF = ECStack.back(); - // Get the pointer to the valist element. LLI treats the valist in memory as - // an integer. - GenericValue VAListPtr = getOperandValue(I.getOperand(0), SF); - - // Load the pointer - GenericValue VAList = - TheEE->LoadValueFromMemory((GenericValue *)GVTOP(VAListPtr), Type::UIntTy); - + // Get the incoming valist element. LLI treats the valist as an integer. + GenericValue VAList = getOperandValue(I.getOperand(0), SF); + + // Move to the next operand. unsigned Argument = VAList.IntVal++; - - // Update the valist to point to the next argument... - TheEE->StoreValueToMemory(VAList, (GenericValue *)GVTOP(VAListPtr), - Type::UIntTy); - - // Set the value... assert(Argument < SF.VarArgs.size() && "Accessing past the last vararg argument!"); - SetValue(&I, SF.VarArgs[Argument], SF); + SetValue(&I, VAList, SF); } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index b92e3c6a0236..44ba87f3b31e 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -687,14 +687,12 @@ GenericValue lle_X_fprintf(FunctionType *M, const vector &Args) { // LLVM Intrinsic Functions... //===----------------------------------------------------------------------===// -// void llvm.va_start( *) - Implement the va_start operation... +// llvm.va_start() - Implement the va_start operation... GenericValue llvm_va_start(FunctionType *F, const vector &Args) { - assert(Args.size() == 1); - GenericValue *VAListP = (GenericValue *)GVTOP(Args[0]); + assert(Args.size() == 0); GenericValue Val; Val.UIntVal = 0; // Start at the first '...' argument... - TheInterpreter->StoreValueToMemory(Val, VAListP, Type::UIntTy); - return GenericValue(); + return Val; } // void llvm.va_end( *) - Implement the va_end operation... @@ -703,13 +701,10 @@ GenericValue llvm_va_end(FunctionType *F, const vector &Args) { return GenericValue(); // Noop! } -// void llvm.va_copy( *, ) - Implement the va_copy -// operation... +// llvm.va_copy() - Implement the va_copy operation... GenericValue llvm_va_copy(FunctionType *F, const vector &Args) { - assert(Args.size() == 2); - GenericValue *DestVAList = (GenericValue*)GVTOP(Args[0]); - TheInterpreter->StoreValueToMemory(Args[1], DestVAList, Type::UIntTy); - return GenericValue(); + assert(Args.size() == 1); + return Args[0]; } } // End extern "C" diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h index 61d391a360a7..62ac1f0d3fd5 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -131,7 +131,7 @@ public: void visitCallInst(CallInst &I); void visitShl(ShiftInst &I); void visitShr(ShiftInst &I); - void visitVarArgInst(VarArgInst &I); + void visitVANextInst(VANextInst &I); void visitInstruction(Instruction &I) { std::cerr << I; assert(0 && "Instruction not interpretable yet!");