llvm.org GIT mirror llvm / 9d20b71
Represent va_list in interpreter as a (ec-stack-depth . var-arg-index) pair, and look up varargs in the execution stack every time, instead of just pushing iterators (which can be invalidated during callFunction()) around. (union GenericValue now has a "pair of uints" member, to support this mechanism.) Fixes Bug 234. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11845 91177308-0d34-0410-b5e6-96231b3b80d8 Brian Gaeke 16 years ago
2 changed file(s) with 15 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
3232 int64_t LongVal;
3333 double DoubleVal;
3434 float FloatVal;
35 struct { unsigned int first; unsigned int second; } UIntPairVal;
3536 PointerTy PointerVal;
3637 unsigned char Untyped[8];
3738
773773 switch (F->getIntrinsicID()) {
774774 case Intrinsic::not_intrinsic:
775775 break;
776 case Intrinsic::va_start: // va_start: implemented by getFirstVarArg()
777 SetValue(CS.getInstruction(), getFirstVarArg(), SF);
776 case Intrinsic::va_start: { // va_start
777 GenericValue ArgIndex;
778 ArgIndex.UIntPairVal.first = ECStack.size() - 1;
779 ArgIndex.UIntPairVal.second = 0;
780 SetValue(CS.getInstruction(), ArgIndex, SF);
778781 return;
782 }
779783 case Intrinsic::va_end: // va_end is a noop for the interpreter
780784 return;
781785 case Intrinsic::va_copy: // va_copy: dest = src
959963 void Interpreter::visitVANextInst(VANextInst &I) {
960964 ExecutionContext &SF = ECStack.back();
961965
962 // Get the incoming valist parameter. LLI treats the valist as a pointer
963 // to the next argument.
966 // Get the incoming valist parameter. LLI treats the valist as a
967 // (ec-stack-depth var-arg-index) pair.
964968 GenericValue VAList = getOperandValue(I.getOperand(0), SF);
965969
966970 // Move the pointer to the next vararg.
967 GenericValue *ArgPtr = (GenericValue *) GVTOP (VAList);
968 ++ArgPtr;
969 VAList = PTOGV (ArgPtr);
971 ++VAList.UIntPairVal.second;
970972 SetValue(&I, VAList, SF);
971973 }
972974
976978 void Interpreter::visitVAArgInst(VAArgInst &I) {
977979 ExecutionContext &SF = ECStack.back();
978980
979 // Get the incoming valist parameter. LLI treats the valist as a pointer
980 // to the next argument.
981 // Get the incoming valist parameter. LLI treats the valist as a
982 // (ec-stack-depth var-arg-index) pair.
981983 GenericValue VAList = getOperandValue(I.getOperand(0), SF);
982 assert (GVTOP (VAList) != 0 && "VAList was null in vaarg instruction");
983 GenericValue Dest, Src = *(GenericValue *) GVTOP (VAList);
984 GenericValue Dest;
985 GenericValue Src = ECStack[VAList.UIntPairVal.first]
986 .VarArgs[VAList.UIntPairVal.second];
984987 const Type *Ty = I.getType();
985988 switch (Ty->getPrimitiveID()) {
986989 IMPLEMENT_VAARG(UByte);