GP-2627 TypePartialStruct

This commit is contained in:
caheckman 2023-03-14 13:25:39 -04:00
parent cc35d57933
commit 2591c17f22
15 changed files with 636 additions and 433 deletions

View file

@ -1685,6 +1685,44 @@ int4 RuleAndPiece::applyOp(PcodeOp *op,Funcdata &data)
return 1;
}
/// \class RuleAndZext
/// \brief Convert INT_AND to INT_ZEXT where appropriate: `sext(X) & 0xffff => zext(X)`
///
/// Similarly `concat(Y,X) & 0xffff => zext(X)`
void RuleAndZext::getOpList(vector<uint4> &oplist) const
{
oplist.push_back(CPUI_INT_AND);
}
int4 RuleAndZext::applyOp(PcodeOp *op,Funcdata &data)
{
Varnode *cvn1 = op->getIn(1);
if (!cvn1->isConstant()) return 0;
if (!op->getIn(0)->isWritten()) return 0;
PcodeOp *otherop = op->getIn(0)->getDef();
OpCode opc = otherop->code();
Varnode *rootvn;
if (opc == CPUI_INT_SEXT)
rootvn = otherop->getIn(0);
else if (opc == CPUI_PIECE)
rootvn = otherop->getIn(1);
else
return 0;
uintb mask = calc_mask(rootvn->getSize());
if (mask != cvn1->getOffset())
return 0;
if (rootvn->isFree())
return 0;
if (rootvn->getSize() > sizeof(uintb)) // FIXME: Should be arbitrary precision
return 0;
data.opSetOpcode(op, CPUI_INT_ZEXT);
data.opRemoveInput(op, 1);
data.opSetInput(op, rootvn, 0);
return 1;
}
/// \class RuleAndCompare
/// \brief Simplify INT_ZEXT and SUBPIECE in masked comparison: `zext(V) & c == 0 => V & (c & mask) == 0`
///