Reorder comparison with constant

This commit is contained in:
RootCubed 2023-04-25 14:02:54 +02:00
parent cc48928827
commit 6fcbce8d30
3 changed files with 18 additions and 2 deletions

View File

@ -132,6 +132,14 @@ PrintC::PrintC(Architecture *g,const string &nm) : PrintLanguage(g,nm)
greater_equal.negate = &less_than;
equal.negate = &not_equal;
not_equal.negate = &equal;
// Set the swap tokens
less_than.lrswap = &greater_than;
less_equal.lrswap = &greater_equal;
greater_than.lrswap = &less_than;
greater_equal.lrswap = &less_equal;
equal.lrswap = &equal;
not_equal.lrswap = &not_equal;
castStrategy = new CastStrategyC();
resetDefaultsPrintC();

View File

@ -549,11 +549,18 @@ void PrintLanguage::opBinary(const OpToken *tok,const PcodeOp *op)
if (tok == (const OpToken *)0)
throw LowlevelError("Could not find fliptoken");
}
const Varnode *lhs = op->getIn(0);
const Varnode *rhs = op->getIn(1);
if (op->getIn(0)->isConstant() && tok->lrswap != (const OpToken *)0) {
tok = tok->lrswap;
lhs = op->getIn(1);
rhs = op->getIn(0);
}
pushOp(tok,op); // Push on reverse polish notation
// implied vn's pushed on in reverse order for efficiency
// see PrintLanguage::pushVnImplied
pushVn(op->getIn(1),op,mods);
pushVn(op->getIn(0),op,mods);
pushVn(rhs,op,mods);
pushVn(lhs,op,mods);
}
/// Push an operator onto the stack that has a normal unary format.

View File

@ -101,6 +101,7 @@ public:
int4 spacing; ///< Spaces to print around operator
int4 bump; ///< Spaces to indent if we break here
OpToken *negate; ///< The token representing the negation of this token
OpToken *lrswap; ///< The token representing the token used if the left-hand and right-hand sides are swapped
};
/// \brief The base class API for emitting a high-level language