Change LLI's internal representation of va_list to a pointer to the next

argument to be returned by va_arg. This allows va_lists to be passed
between different LLVM procedures (though it is unlikely that an LLI
va_list would make sense to an external function, except by chance.)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9965 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Brian Gaeke 2003-11-13 06:06:01 +00:00
parent 79390d48d0
commit 8da17489aa
3 changed files with 15 additions and 13 deletions

View File

@ -812,13 +812,14 @@ void Interpreter::visitCastInst(CastInst &I) {
void Interpreter::visitVANextInst(VANextInst &I) { void Interpreter::visitVANextInst(VANextInst &I) {
ExecutionContext &SF = ECStack.back(); ExecutionContext &SF = ECStack.back();
// Get the incoming valist element. LLI treats the valist as an integer. // Get the incoming valist parameter. LLI treats the valist as a pointer
// to the next argument.
GenericValue VAList = getOperandValue(I.getOperand(0), SF); GenericValue VAList = getOperandValue(I.getOperand(0), SF);
// Move to the next operand. // Move the pointer to the next vararg.
unsigned Argument = VAList.IntVal++; GenericValue *ArgPtr = (GenericValue *) GVTOP (VAList);
assert(Argument < SF.VarArgs.size() && ++ArgPtr;
"Accessing past the last vararg argument!"); VAList = PTOGV (ArgPtr);
SetValue(&I, VAList, SF); SetValue(&I, VAList, SF);
} }
@ -828,12 +829,11 @@ void Interpreter::visitVANextInst(VANextInst &I) {
void Interpreter::visitVAArgInst(VAArgInst &I) { void Interpreter::visitVAArgInst(VAArgInst &I) {
ExecutionContext &SF = ECStack.back(); ExecutionContext &SF = ECStack.back();
// Get the incoming valist element. LLI treats the valist as an integer. // Get the incoming valist parameter. LLI treats the valist as a pointer
// to the next argument.
GenericValue VAList = getOperandValue(I.getOperand(0), SF); GenericValue VAList = getOperandValue(I.getOperand(0), SF);
unsigned Argument = VAList.IntVal; assert (GVTOP (VAList) != 0 && "VAList was null in vaarg instruction");
assert(Argument < SF.VarArgs.size() && GenericValue Dest, Src = *(GenericValue *) GVTOP (VAList);
"Accessing past the last vararg argument!");
GenericValue Dest, Src = SF.VarArgs[Argument];
const Type *Ty = I.getType(); const Type *Ty = I.getType();
switch (Ty->getPrimitiveID()) { switch (Ty->getPrimitiveID()) {
IMPLEMENT_VAARG(UByte); IMPLEMENT_VAARG(UByte);

View File

@ -696,9 +696,7 @@ GenericValue lle_X_fprintf(FunctionType *M, const vector<GenericValue> &Args) {
// <va_list> llvm.va_start() - Implement the va_start operation... // <va_list> llvm.va_start() - Implement the va_start operation...
GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) { GenericValue llvm_va_start(FunctionType *F, const vector<GenericValue> &Args) {
assert(Args.size() == 0); assert(Args.size() == 0);
GenericValue Val; return TheInterpreter->getFirstVarArg();
Val.UIntVal = 0; // Start at the first '...' argument...
return Val;
} }
// void llvm.va_end(<va_list> *) - Implement the va_end operation... // void llvm.va_end(<va_list> *) - Implement the va_end operation...

View File

@ -146,6 +146,10 @@ public:
AtExitHandlers.push_back(F); AtExitHandlers.push_back(F);
} }
GenericValue *getFirstVarArg () {
return &(ECStack[ECStack.size () - 2].VarArgs[0]);
}
//FIXME: private: //FIXME: private:
public: public:
GenericValue executeGEPOperation(Value *Ptr, User::op_iterator I, GenericValue executeGEPOperation(Value *Ptr, User::op_iterator I,