//_________________________________________________________________________________________________ void SwitchInst::setTarget(U_32 i, Node* bb) { assert(bb->isBlockNode()); ConstantAreaItem * cai = getConstantAreaItem(); assert(i<cai->getSize()/sizeof(Node*)); ((Node**)cai->getValue())[i]=bb; }
//_________________________________________________________________________________________________ void SwitchInst::replaceTarget(Node * bbFrom, Node * bbTo) { assert(bbTo->isBlockNode()); ConstantAreaItem * cai = getConstantAreaItem(); Node** bbs=(Node**)cai->getValue(); #ifdef _DEBUG bool found = false; #endif for (U_32 i=0, n=cai->getSize()/sizeof(Node*); i<n; i++) { if (bbs[i]==bbFrom) { #ifdef _DEBUG found = true; #endif bbs[i]=bbTo; } } assert(found); }
const void* OpndUtils::extractAddrOfConst(const Opnd* op) { if (op->getMemOpndKind() != MemOpndKind_ConstantArea) { return NULL; } // Actually, it's currently only works for IA-32 - I expect // the address of constant completely in the displacement. // On Intel64, the address already get loaded into a register, // so more complicated analysis needed to find the proper constant Opnd* disp = op->getMemOpndSubOpnd(MemOpndSubOpndKind_Displacement); if (disp == NULL) { // Perhaps, it's IA-32? return NULL; } Opnd::RuntimeInfo* rtInfo = disp->getRuntimeInfo(); assert(rtInfo != NULL); assert(rtInfo->getKind() == Opnd::RuntimeInfo::Kind_ConstantAreaItem); ConstantAreaItem* item = (ConstantAreaItem*)rtInfo->getValue(0); // At this point we must have the address... assert(item->getValue()!= NULL); return item->getValue(); }
Node* SwitchInst::getTarget(U_32 i)const { ConstantAreaItem * cai = getConstantAreaItem(); assert(i<cai->getSize()/sizeof(Node*)); return ((Node**)cai->getValue())[i]; }