mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
removing implied casts in array index expressions
This commit is contained in:
parent
f57af0b730
commit
706960a139
2 changed files with 39 additions and 5 deletions
|
@ -577,8 +577,12 @@ void PrintC::opReturn(const PcodeOp *op)
|
|||
void PrintC::opIntZext(const PcodeOp *op)
|
||||
|
||||
{
|
||||
if (castStrategy->isZextCast(op->getOut()->getHigh()->getType(),op->getIn(0)->getHigh()->getType()))
|
||||
opTypeCast(op);
|
||||
if (castStrategy->isZextCast(op->getOut()->getHigh()->getType(),op->getIn(0)->getHigh()->getType())) {
|
||||
if (isExtensionCastImplied(op))
|
||||
pushVnImplied(op->getIn(0),op,mods);
|
||||
else
|
||||
opTypeCast(op);
|
||||
}
|
||||
else
|
||||
opFunc(op);
|
||||
}
|
||||
|
@ -586,8 +590,12 @@ void PrintC::opIntZext(const PcodeOp *op)
|
|||
void PrintC::opIntSext(const PcodeOp *op)
|
||||
|
||||
{
|
||||
if (castStrategy->isSextCast(op->getOut()->getHigh()->getType(),op->getIn(0)->getHigh()->getType()))
|
||||
opTypeCast(op);
|
||||
if (castStrategy->isSextCast(op->getOut()->getHigh()->getType(),op->getIn(0)->getHigh()->getType())) {
|
||||
if (isExtensionCastImplied(op))
|
||||
pushVnImplied(op->getIn(0),op,mods);
|
||||
else
|
||||
opTypeCast(op);
|
||||
}
|
||||
else
|
||||
opFunc(op);
|
||||
}
|
||||
|
@ -1247,6 +1255,31 @@ bool PrintC::printCharacterConstant(ostream &s,const Address &addr,int4 charsize
|
|||
return res;
|
||||
}
|
||||
|
||||
/// \brief Is the given ZEXT/SEXT cast implied by the expression its in
|
||||
///
|
||||
/// We know that the given ZEXT or SEXT op can be viewed as a natural \e cast operation.
|
||||
/// Sometimes such a cast is implied by the expression its in, and the cast itself
|
||||
/// doesn't need to be printed.
|
||||
/// \param op is the given ZEXT or SEXT PcodeOp
|
||||
/// \return \b true if the op as a cast does not need to be printed
|
||||
bool PrintC::isExtensionCastImplied(const PcodeOp *op) const
|
||||
|
||||
{
|
||||
const Varnode *outVn = op->getOut();
|
||||
if (outVn->isExplicit()) {
|
||||
|
||||
}
|
||||
else {
|
||||
PcodeOp *expOp = outVn->loneDescend();
|
||||
if (expOp != (PcodeOp *)0) {
|
||||
OpCode opc = expOp->code();
|
||||
if (opc == CPUI_PTRADD)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// \brief Push a single character constant to the RPN stack
|
||||
///
|
||||
/// For C, a character constant is usually emitted as the character in single quotes.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue