decompiler  1.0.0
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
ghidra::TermOrder Class Reference

A class for ordering Varnode terms in an additive expression. More...

#include <coreaction.hh>

Public Member Functions

 TermOrder (PcodeOp *rt)
 Construct given root PcodeOp.
 
int4 getSize (void) const
 Get the number of terms in the expression.
 
void collect (void)
 Collect all the terms in the expression. More...
 
void sortTerms (void)
 Sort the terms using additiveCompare()
 
const vector< AdditiveEdge * > & getSort (void)
 Get the sorted list of references.
 

Static Private Member Functions

static bool additiveCompare (const AdditiveEdge *op1, const AdditiveEdge *op2)
 A comparison operator for ordering terms in a sum. More...
 

Private Attributes

PcodeOproot
 The final PcodeOp in the expression.
 
vector< AdditiveEdgeterms
 Collected terms.
 
vector< AdditiveEdge * > sorter
 An array of references to terms for quick sorting.
 

Detailed Description

A class for ordering Varnode terms in an additive expression.

Given the final PcodeOp in a data-flow expression that sums 2 or more Varnode terms, this class collects all the terms then allows sorting of the terms to facilitate constant collapse and factoring simplifications.

Member Function Documentation

◆ additiveCompare()

bool ghidra::TermOrder::additiveCompare ( const AdditiveEdge op1,
const AdditiveEdge op2 
)
inlinestaticprivate

A comparison operator for ordering terms in a sum.

This is based on Varnode::termOrder which groups constants terms and ignores multiplicative coefficients.

Parameters
op1is the first term to compare
op2is the second term
Returns
true if the first term is less than the second

References ghidra::AdditiveEdge::getVarnode(), and ghidra::Varnode::termOrder().

◆ collect()

void ghidra::TermOrder::collect ( void  )

Collect all the terms in the expression.

Assuming root->getOut() is the root of an expression formed with the CPUI_INT_ADD op, collect all the Varnode terms of the expression.

References ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_MULT, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), ghidra::Varnode::isConstant(), ghidra::Varnode::isWritten(), ghidra::Varnode::loneDescend(), and ghidra::PcodeOp::numInput().

Referenced by ghidra::RuleCollectTerms::applyOp().


The documentation for this class was generated from the following files: