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

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

#include <typeop.hh>

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

Public Types

enum  { inherits_sign = 1 , inherits_sign_zero = 2 , shift_op = 4 }
 

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)
 
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. More...
 
virtual void setMetatypeOut (type_metatype val)
 Set the data-type associated with outputs of this opcode. More...
 
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.

Constructor & Destructor Documentation

◆ TypeOp()

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.

Member Function Documentation

◆ evaluateBinary()

uintb 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 behave, and OpBehavior::evaluateBinary().

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

◆ evaluateUnary()

uintb 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 behave, and OpBehavior::evaluateUnary().

Referenced by PcodeOp::collapse().

◆ getInputCast()

Datatype * 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 TypeOpCopy, TypeOpLoad, TypeOpStore, TypeOpEqual, TypeOpNotEqual, TypeOpIntSless, TypeOpIntSlessEqual, TypeOpIntLess, TypeOpIntLessEqual, TypeOpIntZext, TypeOpIntSext, TypeOpIntRight, TypeOpIntSright, TypeOpIntDiv, TypeOpIntSdiv, TypeOpIntRem, TypeOpIntSrem, TypeOpPtradd, TypeOpPtrsub, TypeOpSegment, TypeOpCpoolref, and TypeOpNew.

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

Referenced by ActionSetCasts::castInput(), TypeOpIntRight::getInputCast(), TypeOpIntSright::getInputCast(), TypeOpPtradd::getInputCast(), and TypeOpPtrsub::getInputCast().

◆ getInputLocal()

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

Find the minimal (or suggested) data-type of an input to this op-code.

The result should depend only on the op-code itself (and the size of the input)

Parameters
opis the PcodeOp being considered
slotis the input being considered
Returns
the data-type

Reimplemented in TypeOpBinary, TypeOpUnary, TypeOpFunc, TypeOpCbranch, TypeOpCall, TypeOpCallind, TypeOpCallother, TypeOpReturn, TypeOpIntLeft, TypeOpIntRight, TypeOpIntSright, TypeOpIndirect, TypeOpPtradd, TypeOpPtrsub, TypeOpCpoolref, TypeOpInsert, and TypeOpExtract.

References TypeFactory::getBase(), PcodeOp::getIn(), Varnode::getSize(), tlst, and TYPE_UNKNOWN.

Referenced by TypeOpCall::getInputLocal(), TypeOpCallind::getInputLocal(), TypeOpCallother::getInputLocal(), TypeOpReturn::getInputLocal(), TypeOpIndirect::getInputLocal(), and PcodeOp::inputTypeLocal().

◆ getOperatorName()

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

Get the name of the op-code as it should be displayed in context.

Depending on the context, the same op-code may get displayed in different ways.

Parameters
opis the PcodeOp context
Returns
the display token

Reimplemented in TypeOpCallother, TypeOpIntZext, TypeOpIntSext, TypeOpIntCarry, TypeOpIntScarry, TypeOpIntSborrow, TypeOpPiece, and TypeOpSubpiece.

References name.

Referenced by TypeOpCallother::getOperatorName(), PrintC::opCallother(), PrintC::opFunc(), TypeOpBinary::printRaw(), TypeOpUnary::printRaw(), TypeOpFunc::printRaw(), TypeOpMulti::printRaw(), TypeOpIndirect::printRaw(), TypeOpSegment::printRaw(), TypeOpCpoolref::printRaw(), and TypeOpNew::printRaw().

◆ getOutputLocal()

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

Find the minimal (or suggested) data-type of an output to this op-code.

The result should depend only on the op-code itself (and the size of the output)

Parameters
opis the PcodeOp being considered
Returns
the data-type

Reimplemented in TypeOpBinary, TypeOpUnary, TypeOpFunc, TypeOpCall, TypeOpCallind, TypeOpCallother, TypeOpPtradd, TypeOpPtrsub, and TypeOpCpoolref.

References TypeFactory::getBase(), PcodeOp::getOut(), Varnode::getSize(), tlst, and TYPE_UNKNOWN.

Referenced by TypeOpCall::getOutputLocal(), TypeOpCallind::getOutputLocal(), TypeOpCallother::getOutputLocal(), TypeOpCpoolref::getOutputLocal(), and PcodeOp::outputTypeLocal().

◆ getOutputToken()

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

Find the data-type of the output that would be assigned by a compiler.

Calculate the actual data-type of the output for a specific PcodeOp as would be assigned by a C compiler parsing a grammar containing this op.

Parameters
opis the specific PcodeOp
castStrategyis the current casting strategy
Returns
the data-type

Reimplemented in TypeOpCopy, TypeOpLoad, TypeOpIntAdd, TypeOpIntSub, TypeOpInt2Comp, TypeOpIntNegate, TypeOpIntXor, TypeOpIntAnd, TypeOpIntOr, TypeOpIntLeft, TypeOpIntRight, TypeOpIntSright, TypeOpIntMult, TypeOpPiece, TypeOpSubpiece, TypeOpPtradd, TypeOpPtrsub, and TypeOpSegment.

References PcodeOp::outputTypeLocal().

Referenced by ActionSetCasts::castOutput(), and TypeOpPtrsub::getOutputToken().

◆ isCommutative()

bool 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 PcodeOp::commutative, and opflags.

◆ printRaw()

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

Print (for debugging purposes) this specific PcodeOp to the stream.

Parameters
sis the output stream
opis the specific PcodeOp to print

Implemented in TypeOpBinary, TypeOpUnary, TypeOpFunc, TypeOpCopy, TypeOpLoad, TypeOpStore, TypeOpBranch, TypeOpCbranch, TypeOpBranchind, TypeOpCall, TypeOpCallind, TypeOpCallother, TypeOpReturn, TypeOpIntSright, TypeOpMulti, TypeOpIndirect, TypeOpCast, TypeOpPtradd, TypeOpPtrsub, TypeOpSegment, TypeOpCpoolref, and TypeOpNew.

Referenced by PcodeOp::printRaw().

◆ propagateType()

Datatype * 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 TypeOpCopy, TypeOpLoad, TypeOpStore, TypeOpEqual, TypeOpNotEqual, TypeOpIntSless, TypeOpIntSlessEqual, TypeOpIntLess, TypeOpIntLessEqual, TypeOpIntAdd, TypeOpIntXor, TypeOpIntAnd, TypeOpIntOr, TypeOpMulti, TypeOpIndirect, TypeOpSubpiece, TypeOpPtradd, TypeOpPtrsub, TypeOpSegment, and TypeOpNew.

Referenced by ActionInferTypes::propagateTypeEdge().

◆ push()

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

◆ recoverInputBinary()

uintb 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 behave, and OpBehavior::recoverInputBinary().

Referenced by JumpBasic::backup2Switch().

◆ recoverInputUnary()

uintb 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 behave, and OpBehavior::recoverInputUnary().

Referenced by JumpBasic::backup2Switch().

◆ registerInstructions()

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

◆ selectJavaOperators()

void 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 CPUI_INT_AND, CPUI_INT_NEGATE, CPUI_INT_OR, CPUI_INT_RIGHT, CPUI_INT_XOR, CPUI_INT_ZEXT, TYPE_INT, TYPE_UINT, and TYPE_UNKNOWN.

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

◆ setMetatypeIn()

virtual void TypeOp::setMetatypeIn ( type_metatype  val)
inlineprotectedvirtual

Set the data-type associated with inputs to this opcode.

Reimplemented in TypeOpBinary, TypeOpUnary, and TypeOpFunc.

◆ setMetatypeOut()

virtual void TypeOp::setMetatypeOut ( type_metatype  val)
inlineprotectedvirtual

Set the data-type associated with outputs of this opcode.

Reimplemented in TypeOpBinary, TypeOpUnary, and TypeOpFunc.


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