decompiler  1.0.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ghidra::TypeOp Class Referenceabstract

Associate data-type and behavior information with a specific p-code op-code. More...

#include <typeop.hh>

Inheritance diagram for ghidra::TypeOp:
ghidra::TypeOpBinary ghidra::TypeOpBranch ghidra::TypeOpBranchind ghidra::TypeOpCall ghidra::TypeOpCallind ghidra::TypeOpCallother ghidra::TypeOpCast ghidra::TypeOpCbranch ghidra::TypeOpCopy ghidra::TypeOpCpoolref ghidra::TypeOpFunc ghidra::TypeOpIndirect ghidra::TypeOpLoad ghidra::TypeOpMulti ghidra::TypeOpNew ghidra::TypeOpPtradd ghidra::TypeOpPtrsub ghidra::TypeOpReturn ghidra::TypeOpSegment ghidra::TypeOpStore ghidra::TypeOpUnary

Public Types

enum  {
  inherits_sign = 1, inherits_sign_zero = 2, shift_op = 4, arithmetic_op = 8,
  logical_op = 0x10, floatingpoint_op = 0x20
}
 

Public Member Functions

 TypeOp (TypeFactory *t, OpCode opc, const string &n)
 Constructor. More...
 
virtual ~TypeOp (void)
 Destructor.
 
const string & getName (void) const
 Get the display name of the op-code.
 
OpCode getOpcode (void) const
 Get the op-code value.
 
uint4 getFlags (void) const
 Get the properties associated with the op-code.
 
OpBehaviorgetBehavior (void) const
 Get the behavior associated with the op-code.
 
uintb evaluateUnary (int4 sizeout, int4 sizein, uintb in1) const
 Emulate the unary op-code on an input value. More...
 
uintb evaluateBinary (int4 sizeout, int4 sizein, uintb in1, uintb in2) const
 Emulate the binary op-code on an input value. More...
 
uintb recoverInputBinary (int4 slot, int4 sizeout, uintb out, int4 sizein, uintb in) const
 Reverse the binary op-code operation, recovering a constant input value. More...
 
uintb recoverInputUnary (int4 sizeout, uintb out, int4 sizein) const
 Reverse the unary op-code operation, recovering a constant input value. More...
 
bool isCommutative (void) const
 Return true if this op-code is commutative. More...
 
bool inheritsSign (void) const
 Return true if the op-code inherits its signedness from its inputs.
 
bool inheritsSignFirstParamOnly (void) const
 Return true if the op-code inherits its signedness from only its first input.
 
bool isShiftOp (void) const
 Return true if the op-code is a shift (INT_LEFT, INT_RIGHT, or INT_SRIGHT)
 
bool isArithmeticOp (void) const
 Return true if the opcode is INT_ADD, INT_MULT, INT_DIV, INT_REM, or other arithmetic op.
 
bool isLogicalOp (void) const
 Return true if the opcode is INT_AND, INT_OR, INT_XOR, or other logical op.
 
bool isFloatingPointOp (void) const
 Return true if the opcode is FLOAT_ADD, FLOAT_MULT, or other floating-point operation.
 
virtual DatatypegetOutputLocal (const PcodeOp *op) const
 Find the minimal (or suggested) data-type of an output to this op-code. More...
 
virtual DatatypegetInputLocal (const PcodeOp *op, int4 slot) const
 Find the minimal (or suggested) data-type of an input to this op-code. More...
 
virtual DatatypegetOutputToken (const PcodeOp *op, CastStrategy *castStrategy) const
 Find the data-type of the output that would be assigned by a compiler. More...
 
virtual DatatypegetInputCast (const PcodeOp *op, int4 slot, const CastStrategy *castStrategy) const
 Find the data-type of the input to a specific PcodeOp. More...
 
virtual DatatypepropagateType (Datatype *alttype, PcodeOp *op, Varnode *invn, Varnode *outvn, int4 inslot, int4 outslot)
 Propagate an incoming data-type across a specific PcodeOp. More...
 
virtual void push (PrintLanguage *lng, const PcodeOp *op, const PcodeOp *readOp) const =0
 Push the specific PcodeOp to the emitter's RPN stack. More...
 
virtual void printRaw (ostream &s, const PcodeOp *op)=0
 Print (for debugging purposes) this specific PcodeOp to the stream. More...
 
virtual string getOperatorName (const PcodeOp *op) const
 Get the name of the op-code as it should be displayed in context. More...
 

Static Public Member Functions

static void registerInstructions (vector< TypeOp *> &inst, TypeFactory *tlst, const Translate *trans)
 Build a map from op-code value to the TypeOp information objects. More...
 
static void selectJavaOperators (vector< TypeOp *> &inst, bool val)
 Toggle Java specific aspects of the op-code information. More...
 

Protected Member Functions

virtual void setMetatypeIn (type_metatype val)
 Set the data-type associated with inputs to this opcode.
 
virtual void setMetatypeOut (type_metatype val)
 Set the data-type associated with outputs of this opcode.
 
virtual void setSymbol (const string &nm)
 Set the display symbol associated with the op-code.
 

Protected Attributes

TypeFactorytlst
 Pointer to data-type factory.
 
OpCode opcode
 The op-code value.
 
uint4 opflags
 Cached pcode-op properties for this op-code.
 
uint4 addlflags
 Additional properties.
 
string name
 Symbol denoting this operation.
 
OpBehaviorbehave
 Object for emulating the behavior of the op-code.
 

Detailed Description

Associate data-type and behavior information with a specific p-code op-code.

This holds all information about a p-code op-code. The main PcodeOp object holds this as a representative of the op-code. The evaluate* methods can be used to let the op-code act on constant input values. The getOutput* and getInput* methods are used to obtain data-type information that is specific to the op-code. This also holds other PcodeOp boolean properties that are set in common for the op-code.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
inherits_sign 

Operator token inherits signedness from its inputs.

inherits_sign_zero 

Only inherits sign from first operand, not the second.

shift_op 

Shift operation.

arithmetic_op 

Operation involving addition, multiplication, or division.

logical_op 

Logical operation.

floatingpoint_op 

Floating-point operation.

Constructor & Destructor Documentation

◆ TypeOp()

ghidra::TypeOp::TypeOp ( TypeFactory t,
OpCode  opc,
const string &  n 
)

Constructor.

Parameters
tis the TypeFactory used to construct data-types
opcis the op-code value the new object will represent
nis the display name that will represent the op-code

References addlflags, behave, name, opcode, opflags, and tlst.

Referenced by setSymbol().

Member Function Documentation

◆ evaluateBinary()

uintb ghidra::TypeOp::evaluateBinary ( int4  sizeout,
int4  sizein,
uintb  in1,
uintb  in2 
) const
inline

Emulate the binary op-code on an input value.

Parameters
sizeoutis the size of the output in bytes
sizeinis the size of the inputs in bytes
in1is the first input value
in2is the second input value
Returns
the output value

References ghidra::OpBehavior::evaluateBinary().

Referenced by ghidra::RuleAddMultCollapse::applyOp(), and ghidra::PcodeOp::collapse().

◆ evaluateUnary()

uintb ghidra::TypeOp::evaluateUnary ( int4  sizeout,
int4  sizein,
uintb  in1 
) const
inline

Emulate the unary op-code on an input value.

Parameters
sizeoutis the size of the output in bytes
sizeinis the size of the input in bytes
in1is the input value
Returns
the output value

References ghidra::OpBehavior::evaluateUnary().

Referenced by ghidra::PcodeOp::collapse().

◆ getInputCast()

Datatype * ghidra::TypeOp::getInputCast ( const PcodeOp op,
int4  slot,
const CastStrategy castStrategy 
) const
virtual

Find the data-type of the input to a specific PcodeOp.

Calculate the actual data-type of the input to the specific PcodeOp. A null result indicates the input data-type is the same as or otherwise doesn't need a cast from the data-type of the actual input Varnode

Parameters
opis the specific PcodeOp
slotis the input to consider
castStrategyis the current casting strategy
Returns
the data-type

Reimplemented in ghidra::TypeOpNew, ghidra::TypeOpCpoolref, ghidra::TypeOpSegment, ghidra::TypeOpPtrsub, ghidra::TypeOpPtradd, ghidra::TypeOpSubpiece, ghidra::TypeOpPiece, ghidra::TypeOpIntSrem, ghidra::TypeOpIntRem, ghidra::TypeOpIntSdiv, ghidra::TypeOpIntDiv, ghidra::TypeOpIntSright, ghidra::TypeOpIntRight, ghidra::TypeOpIntSext, ghidra::TypeOpIntZext, ghidra::TypeOpIntLessEqual, ghidra::TypeOpIntLess, ghidra::TypeOpIntSlessEqual, ghidra::TypeOpIntSless, ghidra::TypeOpNotEqual, ghidra::TypeOpEqual, ghidra::TypeOpStore, ghidra::TypeOpLoad, and ghidra::TypeOpCopy.

References ghidra::CastStrategy::castStandard(), ghidra::Varnode::getHighTypeReadFacing(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::inputTypeLocal(), and ghidra::Varnode::isAnnotation().

Referenced by ghidra::ActionSetCasts::castInput(), ghidra::TypeOpIntRight::getInputCast(), ghidra::TypeOpIntSright::getInputCast(), ghidra::TypeOpPtradd::getInputCast(), ghidra::TypeOpPtrsub::getInputCast(), isFloatingPointOp(), ghidra::TypeOpEqual::push(), ghidra::TypeOpNotEqual::push(), ghidra::TypeOpIntLess::push(), ghidra::TypeOpIntLessEqual::push(), ghidra::TypeOpIntZext::push(), ghidra::TypeOpIntSext::push(), ghidra::TypeOpIntRight::push(), ghidra::TypeOpIntSright::push(), ghidra::TypeOpIntDiv::push(), ghidra::TypeOpIntSdiv::push(), ghidra::TypeOpIntRem::push(), and ghidra::TypeOpIntSrem::push().

◆ getInputLocal()

Datatype * ghidra::TypeOp::getInputLocal ( const PcodeOp op,
int4  slot 
) const
virtual

◆ getOperatorName()

virtual string ghidra::TypeOp::getOperatorName ( const PcodeOp op) const
inlinevirtual

◆ getOutputLocal()

Datatype * ghidra::TypeOp::getOutputLocal ( const PcodeOp op) const
virtual

◆ getOutputToken()

Datatype * ghidra::TypeOp::getOutputToken ( const PcodeOp op,
CastStrategy castStrategy 
) const
virtual

◆ isCommutative()

bool ghidra::TypeOp::isCommutative ( void  ) const

Return true if this op-code is commutative.

Returns
true if the ordering of the inputs does not affect the output

References ghidra::PcodeOp::commutative, and opflags.

Referenced by recoverInputUnary().

◆ printRaw()

virtual void ghidra::TypeOp::printRaw ( ostream &  s,
const PcodeOp op 
)
pure virtual

◆ propagateType()

Datatype * ghidra::TypeOp::propagateType ( Datatype alttype,
PcodeOp op,
Varnode invn,
Varnode outvn,
int4  inslot,
int4  outslot 
)
virtual

Propagate an incoming data-type across a specific PcodeOp.

The data-type can propagate between any two Varnodes attached to the PcodeOp, either in or out. The pair invn and inslot indicate the Varnode holding the incoming data-type. The pair outvn and outslot indicate the Varnode that will hold the outgoing data-type. The data-type for the outgoing Varnode is returned, which may be different then the incoming data-type as the PcodeOp can transform the data-type as it propagates.

Parameters
alttypeis the incoming data-type
opis the PcodeOp to propagate across
invnis the Varnode holding the incoming data-type
outvnis the Varnode that will hold the outgoing data-type
inslotindicates how the incoming Varnode is attached to the PcodeOp (-1 indicates output >= indicates input)
outslotindicates how the outgoing Varnode is attached to the PcodeOp
Returns
the outgoing data-type or null (to indicate no propagation)

Reimplemented in ghidra::TypeOpNew, ghidra::TypeOpSegment, ghidra::TypeOpPtrsub, ghidra::TypeOpPtradd, ghidra::TypeOpSubpiece, ghidra::TypeOpPiece, ghidra::TypeOpIndirect, ghidra::TypeOpMulti, ghidra::TypeOpIntOr, ghidra::TypeOpIntAnd, ghidra::TypeOpIntXor, ghidra::TypeOpIntAdd, ghidra::TypeOpIntLessEqual, ghidra::TypeOpIntLess, ghidra::TypeOpIntSlessEqual, ghidra::TypeOpIntSless, ghidra::TypeOpNotEqual, ghidra::TypeOpEqual, ghidra::TypeOpStore, ghidra::TypeOpLoad, and ghidra::TypeOpCopy.

Referenced by ghidra::TypeOpNew::getInputCast(), isFloatingPointOp(), ghidra::ActionInferTypes::propagateTypeEdge(), ghidra::TypeOpEqual::push(), ghidra::TypeOpNotEqual::push(), ghidra::TypeOpIntLess::push(), ghidra::TypeOpIntLessEqual::push(), and ghidra::TypeOpIntAdd::push().

◆ push()

virtual void ghidra::TypeOp::push ( PrintLanguage lng,
const PcodeOp op,
const PcodeOp readOp 
) const
pure virtual

Push the specific PcodeOp to the emitter's RPN stack.

Given a specific language and PcodeOp, emit the expression rooted at the operation.

Parameters
lngis the PrintLanguage to emit
opis the specific PcodeOp
readOpis the PcodeOp consuming the output (or null)

Implemented in ghidra::TypeOpLzcount, ghidra::TypeOpPopcount, ghidra::TypeOpExtract, ghidra::TypeOpInsert, ghidra::TypeOpNew, ghidra::TypeOpCpoolref, ghidra::TypeOpSegment, ghidra::TypeOpPtrsub, ghidra::TypeOpPtradd, ghidra::TypeOpCast, ghidra::TypeOpSubpiece, ghidra::TypeOpPiece, ghidra::TypeOpIndirect, ghidra::TypeOpMulti, ghidra::TypeOpFloatRound, ghidra::TypeOpFloatFloor, ghidra::TypeOpFloatCeil, ghidra::TypeOpFloatTrunc, ghidra::TypeOpFloatFloat2Float, ghidra::TypeOpFloatInt2Float, ghidra::TypeOpFloatSqrt, ghidra::TypeOpFloatAbs, ghidra::TypeOpFloatNeg, ghidra::TypeOpFloatSub, ghidra::TypeOpFloatMult, ghidra::TypeOpFloatDiv, ghidra::TypeOpFloatAdd, ghidra::TypeOpFloatNan, ghidra::TypeOpFloatLessEqual, ghidra::TypeOpFloatLess, ghidra::TypeOpFloatNotEqual, ghidra::TypeOpFloatEqual, ghidra::TypeOpBoolOr, ghidra::TypeOpBoolAnd, ghidra::TypeOpBoolXor, ghidra::TypeOpBoolNegate, ghidra::TypeOpIntSrem, ghidra::TypeOpIntRem, ghidra::TypeOpIntSdiv, ghidra::TypeOpIntDiv, ghidra::TypeOpIntMult, ghidra::TypeOpIntSright, ghidra::TypeOpIntRight, ghidra::TypeOpIntLeft, ghidra::TypeOpIntOr, ghidra::TypeOpIntAnd, ghidra::TypeOpIntXor, ghidra::TypeOpIntNegate, ghidra::TypeOpInt2Comp, ghidra::TypeOpIntSborrow, ghidra::TypeOpIntScarry, ghidra::TypeOpIntCarry, ghidra::TypeOpIntSub, ghidra::TypeOpIntAdd, ghidra::TypeOpIntSext, ghidra::TypeOpIntZext, ghidra::TypeOpIntLessEqual, ghidra::TypeOpIntLess, ghidra::TypeOpIntSlessEqual, ghidra::TypeOpIntSless, ghidra::TypeOpNotEqual, ghidra::TypeOpEqual, ghidra::TypeOpReturn, ghidra::TypeOpCallother, ghidra::TypeOpCallind, ghidra::TypeOpCall, ghidra::TypeOpBranchind, ghidra::TypeOpCbranch, ghidra::TypeOpBranch, ghidra::TypeOpStore, ghidra::TypeOpLoad, and ghidra::TypeOpCopy.

Referenced by ghidra::PrintC::emitExpression(), isFloatingPointOp(), ghidra::PrintC::pushImpliedField(), and ghidra::PrintLanguage::recurse().

◆ recoverInputBinary()

uintb ghidra::TypeOp::recoverInputBinary ( int4  slot,
int4  sizeout,
uintb  out,
int4  sizein,
uintb  in 
) const
inline

Reverse the binary op-code operation, recovering a constant input value.

If the output value and one of the input values is known, recover the value of the other input.

Parameters
slotis the input slot to recover
sizeoutis the size of the output in bytes
outis the output value
sizeinis the size of the inputs in bytes
inis the known input value
Returns
the input value corresponding to the slot

References ghidra::OpBehavior::recoverInputBinary().

Referenced by ghidra::JumpBasic::backup2Switch().

◆ recoverInputUnary()

uintb ghidra::TypeOp::recoverInputUnary ( int4  sizeout,
uintb  out,
int4  sizein 
) const
inline

Reverse the unary op-code operation, recovering a constant input value.

If the output value is known, recover the input value.

Parameters
sizeoutis the size of the output in bytes
outis the output value
sizeinis the size of the input in bytes
Returns
the input value

References isCommutative(), and ghidra::OpBehavior::recoverInputUnary().

Referenced by ghidra::JumpBasic::backup2Switch().

◆ registerInstructions()

void ghidra::TypeOp::registerInstructions ( vector< TypeOp *> &  inst,
TypeFactory tlst,
const Translate trans 
)
static

Build a map from op-code value to the TypeOp information objects.

Parameters
instwill hold the array of TypeOp objects, indexed on op-code
tlstis the corresponding TypeFactory for the Architecture
transis the Translate object for floating-point formats

References ghidra::CPUI_BOOL_AND, ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_BOOL_OR, ghidra::CPUI_BOOL_XOR, ghidra::CPUI_BRANCH, ghidra::CPUI_BRANCHIND, ghidra::CPUI_CALL, ghidra::CPUI_CALLIND, ghidra::CPUI_CALLOTHER, ghidra::CPUI_CAST, ghidra::CPUI_CBRANCH, ghidra::CPUI_COPY, ghidra::CPUI_CPOOLREF, ghidra::CPUI_EXTRACT, ghidra::CPUI_FLOAT_ABS, ghidra::CPUI_FLOAT_ADD, ghidra::CPUI_FLOAT_CEIL, ghidra::CPUI_FLOAT_DIV, ghidra::CPUI_FLOAT_EQUAL, ghidra::CPUI_FLOAT_FLOAT2FLOAT, ghidra::CPUI_FLOAT_FLOOR, ghidra::CPUI_FLOAT_INT2FLOAT, ghidra::CPUI_FLOAT_LESS, ghidra::CPUI_FLOAT_LESSEQUAL, ghidra::CPUI_FLOAT_MULT, ghidra::CPUI_FLOAT_NAN, ghidra::CPUI_FLOAT_NEG, ghidra::CPUI_FLOAT_NOTEQUAL, ghidra::CPUI_FLOAT_ROUND, ghidra::CPUI_FLOAT_SQRT, ghidra::CPUI_FLOAT_SUB, ghidra::CPUI_FLOAT_TRUNC, ghidra::CPUI_INDIRECT, ghidra::CPUI_INSERT, ghidra::CPUI_INT_2COMP, ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_AND, ghidra::CPUI_INT_CARRY, ghidra::CPUI_INT_DIV, ghidra::CPUI_INT_EQUAL, ghidra::CPUI_INT_LEFT, ghidra::CPUI_INT_LESS, ghidra::CPUI_INT_LESSEQUAL, ghidra::CPUI_INT_MULT, ghidra::CPUI_INT_NEGATE, ghidra::CPUI_INT_NOTEQUAL, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_REM, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_SBORROW, ghidra::CPUI_INT_SCARRY, ghidra::CPUI_INT_SDIV, ghidra::CPUI_INT_SEXT, ghidra::CPUI_INT_SLESS, ghidra::CPUI_INT_SLESSEQUAL, ghidra::CPUI_INT_SREM, ghidra::CPUI_INT_SRIGHT, ghidra::CPUI_INT_SUB, ghidra::CPUI_INT_XOR, ghidra::CPUI_INT_ZEXT, ghidra::CPUI_LOAD, ghidra::CPUI_LZCOUNT, ghidra::CPUI_MAX, ghidra::CPUI_MULTIEQUAL, ghidra::CPUI_NEW, ghidra::CPUI_PIECE, ghidra::CPUI_POPCOUNT, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::CPUI_RETURN, ghidra::CPUI_SEGMENTOP, ghidra::CPUI_STORE, and ghidra::CPUI_SUBPIECE.

Referenced by ghidra::Architecture::buildInstructions(), and getOperatorName().

◆ selectJavaOperators()

void ghidra::TypeOp::selectJavaOperators ( vector< TypeOp *> &  inst,
bool  val 
)
static

Toggle Java specific aspects of the op-code information.

Change basic data-type info (signed vs unsigned) and operator names ( '>>' vs '>>>' ) depending on the specific language.

Parameters
instis the array of TypeOp information objects
valis set to true for Java operators, false for C operators

References ghidra::CPUI_INT_AND, ghidra::CPUI_INT_NEGATE, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_XOR, ghidra::CPUI_INT_ZEXT, ghidra::TYPE_INT, ghidra::TYPE_UINT, and ghidra::TYPE_UNKNOWN.

Referenced by ghidra::PrintJava::adjustTypeOperators(), ghidra::PrintC::adjustTypeOperators(), and getOperatorName().


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