void Interpreter::visitVAArgInst(VAArgInst &I) { ExecutionContext &SF = ECStack.back(); // Get the incoming valist parameter. LLI treats the valist as a // (ec-stack-depth var-arg-index) pair. GenericValue VAList = getOperandValue(I.getOperand(0), SF); GenericValue Dest; GenericValue Src = ECStack[VAList.UIntPairVal.first] .VarArgs[VAList.UIntPairVal.second]; const Type *Ty = I.getType(); switch (Ty->getTypeID()) { IMPLEMENT_VAARG(UByte); IMPLEMENT_VAARG(SByte); IMPLEMENT_VAARG(UShort); IMPLEMENT_VAARG(Short); IMPLEMENT_VAARG(UInt); IMPLEMENT_VAARG(Int); IMPLEMENT_VAARG(ULong); IMPLEMENT_VAARG(Long); IMPLEMENT_VAARG(Pointer); IMPLEMENT_VAARG(Float); IMPLEMENT_VAARG(Double); IMPLEMENT_VAARG(Bool); default: std::cout << "Unhandled dest type for vaarg instruction: " << *Ty << "\n"; abort(); } // Set the Value of this Instruction. SetValue(&I, Dest, SF); }
void GraphBuilder::visitVAArgInst(VAArgInst &I) { Module *M = FB->getParent(); Triple TargetTriple(M->getTargetTriple()); Triple::ArchType Arch = TargetTriple.getArch(); switch(Arch) { case Triple::x86_64: { // On x86_64, we have va_list as a struct {i32, i32, i8*, i8* } // The first i8* is where arguments generally go, but the second i8* can // be used also to pass arguments by register. // We model this by having both the i8*'s point to an array of pointers // to the arguments. DSNodeHandle Ptr = G.getVANodeFor(*FB); DSNodeHandle Dest = getValueDest(&I); if (Ptr.isNull()) return; // Make that the node is read and written Ptr.getNode()->setReadMarker()->setModifiedMarker(); // Not updating type info, as it is already a collapsed node if (isa<PointerType>(I.getType())) Dest.mergeWith(Ptr); return; } default: { assert(0 && "What frontend generates this?"); DSNodeHandle Ptr = getValueDest(I.getOperand(0)); //FIXME: also updates the argument if (Ptr.isNull()) return; // Make that the node is read and written Ptr.getNode()->setReadMarker()->setModifiedMarker(); // Ensure a type record exists. DSNode *PtrN = Ptr.getNode(); PtrN->mergeTypeInfo(I.getType(), Ptr.getOffset()); if (isa<PointerType>(I.getType())) setDestTo(I, getLink(Ptr)); } } }