decompiler
1.0.0
|
Associate data-type and behavior information with a specific p-code op-code. More...
#include <typeop.hh>
Public Types | |
enum | { inherits_sign = 1, inherits_sign_zero = 2 } |
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. | |
OpBehavior * | getBehavior (void) const |
Get the behavior associated with the op-code. | |
bool | markExplicitUnsigned (PcodeOp *op, int4 slot) const |
Check if a constant input should be explicitly labeled as unsigned. More... | |
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 it signedness from its inputs. | |
virtual Datatype * | getOutputLocal (const PcodeOp *op) const |
Find the minimal (or suggested) data-type of an output to this op-code. More... | |
virtual Datatype * | getInputLocal (const PcodeOp *op, int4 slot) const |
Find the minimal (or suggested) data-type of an input to this op-code. More... | |
virtual Datatype * | getOutputToken (const PcodeOp *op, CastStrategy *castStrategy) const |
Find the data-type of the output that would be assigned by a compiler. More... | |
virtual Datatype * | getInputCast (const PcodeOp *op, int4 slot, const CastStrategy *castStrategy) const |
Find the data-type of the input to a specific PcodeOp. More... | |
virtual void | push (PrintLanguage *lng, const PcodeOp *op) 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 | |
TypeFactory * | tlst |
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. | |
OpBehavior * | behave |
Object for emulating the behavior of the op-code. | |
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.
anonymous enum |
TypeOp::TypeOp | ( | TypeFactory * | t, |
OpCode | opc, | ||
const string & | n | ||
) |
|
inline |
Emulate the binary op-code on an input value.
sizeout | is the size of the output in bytes |
sizein | is the size of the inputs in bytes |
in1 | is the first input value |
in2 | is the second input value |
References behave, and OpBehavior::evaluateBinary().
Referenced by RuleAddMultCollapse::applyOp(), and PcodeOp::collapse().
|
inline |
Emulate the unary op-code on an input value.
sizeout | is the size of the output in bytes |
sizein | is the size of the input in bytes |
in1 | is the input value |
References behave, and OpBehavior::evaluateUnary().
Referenced by PcodeOp::collapse().
|
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
op | is the specific PcodeOp |
slot | is the input to consider |
castStrategy | is the current casting strategy |
Reimplemented in TypeOpNew, TypeOpCpoolref, TypeOpSegment, TypeOpPtrsub, TypeOpPtradd, TypeOpIntSrem, TypeOpIntRem, TypeOpIntSdiv, TypeOpIntDiv, TypeOpIntSright, TypeOpIntRight, TypeOpIntSext, TypeOpIntZext, TypeOpIntLessEqual, TypeOpIntLess, TypeOpIntSlessEqual, TypeOpIntSless, TypeOpNotEqual, TypeOpEqual, TypeOpStore, TypeOpLoad, and TypeOpCopy.
References CastStrategy::castStandard(), Varnode::getHigh(), PcodeOp::getIn(), HighVariable::getType(), PcodeOp::inputTypeLocal(), and Varnode::isAnnotation().
Referenced by ActionSetCasts::castInput(), TypeOpIntRight::getInputCast(), TypeOpIntSright::getInputCast(), TypeOpIntRem::getInputCast(), TypeOpIntSrem::getInputCast(), TypeOpPtradd::getInputCast(), and TypeOpPtrsub::getInputCast().
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)
op | is the PcodeOp being considered |
slot | is the input being considered |
Reimplemented in TypeOpCpoolref, TypeOpPtrsub, TypeOpPtradd, TypeOpIndirect, TypeOpIntSright, TypeOpIntRight, TypeOpIntLeft, TypeOpReturn, TypeOpCallother, TypeOpCallind, TypeOpCall, TypeOpCbranch, TypeOpFunc, TypeOpUnary, and TypeOpBinary.
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().
|
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.
op | is the PcodeOp context |
Reimplemented in TypeOpSubpiece, TypeOpPiece, TypeOpIntSborrow, TypeOpIntScarry, TypeOpIntCarry, TypeOpIntSext, TypeOpIntZext, and TypeOpCallother.
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().
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)
op | is the PcodeOp being considered |
Reimplemented in TypeOpCpoolref, TypeOpPtrsub, TypeOpPtradd, TypeOpCallother, TypeOpCallind, TypeOpCall, TypeOpFunc, TypeOpUnary, and TypeOpBinary.
References TypeFactory::getBase(), PcodeOp::getOut(), Varnode::getSize(), tlst, and TYPE_UNKNOWN.
Referenced by TypeOpCall::getOutputLocal(), TypeOpCallind::getOutputLocal(), TypeOpCallother::getOutputLocal(), TypeOpCpoolref::getOutputLocal(), and PcodeOp::outputTypeLocal().
|
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.
op | is the specific PcodeOp |
castStrategy | is the current casting strategy |
Reimplemented in TypeOpSegment, TypeOpPtrsub, TypeOpPtradd, TypeOpSubpiece, TypeOpPiece, TypeOpIntMult, TypeOpIntSright, TypeOpIntRight, TypeOpIntLeft, TypeOpIntOr, TypeOpIntAnd, TypeOpIntXor, TypeOpIntNegate, TypeOpInt2Comp, TypeOpIntSub, TypeOpIntAdd, TypeOpLoad, and TypeOpCopy.
References PcodeOp::outputTypeLocal().
Referenced by ActionSetCasts::castOutput(), and TypeOpPtrsub::getOutputToken().
bool TypeOp::isCommutative | ( | void | ) | const |
Return true if this op-code is commutative.
References PcodeOp::commutative, and opflags.
bool TypeOp::markExplicitUnsigned | ( | PcodeOp * | op, |
int4 | slot | ||
) | const |
Check if a constant input should be explicitly labeled as unsigned.
Many languages can mark an integer constant as explicitly unsigned. When the decompiler is deciding on cast operations, this is one of the checks it performs. This method checks if the indicated input is an integer constant that needs to be coerced (as a source token) into being unsigned. If this is true, the input Varnode is marked for printing as explicitly unsigned.
op | is the PcodeOp taking the value as input |
slot | is the input slot of the value |
References addlflags, Varnode::getHigh(), PcodeOp::getIn(), Datatype::getMetatype(), PcodeOp::getOut(), HighVariable::getType(), inherits_sign, inherits_sign_zero, PcodeOp::inheritsSign(), Datatype::isCharPrint(), Varnode::isConstant(), Datatype::isEnumType(), Varnode::isExplicit(), Varnode::loneDescend(), PcodeOp::numInput(), Varnode::setUnsignedPrint(), TYPE_UINT, and TYPE_UNKNOWN.
Referenced by PcodeOp::markExplicitUnsigned().
|
pure virtual |
Print (for debugging purposes) this specific PcodeOp to the stream.
s | is the output stream |
op | is the specific PcodeOp to print |
Implemented in TypeOpNew, TypeOpCpoolref, TypeOpSegment, TypeOpPtrsub, TypeOpPtradd, TypeOpCast, TypeOpIndirect, TypeOpMulti, TypeOpIntSright, TypeOpReturn, TypeOpCallother, TypeOpCallind, TypeOpCall, TypeOpBranchind, TypeOpCbranch, TypeOpBranch, TypeOpStore, TypeOpLoad, TypeOpCopy, TypeOpFunc, TypeOpUnary, and TypeOpBinary.
Referenced by PcodeOp::printRaw().
|
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.
lng | is the PrintLanguage to emit |
op | is the specific PcodeOp |
Implemented in TypeOpNew, TypeOpCpoolref, TypeOpSegment, TypeOpPtrsub, TypeOpPtradd, TypeOpCast, TypeOpSubpiece, TypeOpPiece, TypeOpIndirect, TypeOpMulti, TypeOpFloatRound, TypeOpFloatFloor, TypeOpFloatCeil, TypeOpFloatTrunc, TypeOpFloatFloat2Float, TypeOpFloatInt2Float, TypeOpFloatSqrt, TypeOpFloatAbs, TypeOpFloatNeg, TypeOpFloatSub, TypeOpFloatMult, TypeOpFloatDiv, TypeOpFloatAdd, TypeOpFloatNan, TypeOpFloatLessEqual, TypeOpFloatLess, TypeOpFloatNotEqual, TypeOpFloatEqual, TypeOpBoolOr, TypeOpBoolAnd, TypeOpBoolXor, TypeOpBoolNegate, TypeOpIntSrem, TypeOpIntRem, TypeOpIntSdiv, TypeOpIntDiv, TypeOpIntMult, TypeOpIntSright, TypeOpIntRight, TypeOpIntLeft, TypeOpIntOr, TypeOpIntAnd, TypeOpIntXor, TypeOpIntNegate, TypeOpInt2Comp, TypeOpIntSborrow, TypeOpIntScarry, TypeOpIntCarry, TypeOpIntSub, TypeOpIntAdd, TypeOpIntSext, TypeOpIntZext, TypeOpIntLessEqual, TypeOpIntLess, TypeOpIntSlessEqual, TypeOpIntSless, TypeOpNotEqual, TypeOpEqual, TypeOpReturn, TypeOpCallother, TypeOpCallind, TypeOpCall, TypeOpBranchind, TypeOpCbranch, TypeOpBranch, TypeOpStore, TypeOpLoad, and TypeOpCopy.
Referenced by PcodeOp::push().
|
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.
slot | is the input slot to recover |
sizeout | is the size of the output in bytes |
out | is the output value |
sizein | is the size of the inputs in bytes |
in | is the known input value |
References behave, and OpBehavior::recoverInputBinary().
|
inline |
Reverse the unary op-code operation, recovering a constant input value.
If the output value is known, recover the input value.
sizeout | is the size of the output in bytes |
out | is the output value |
sizein | is the size of the input in bytes |
References behave, and OpBehavior::recoverInputUnary().
|
static |
Build a map from op-code value to the TypeOp information objects.
inst | will hold the array of TypeOp objects, indexed on op-code |
tlst | is the corresponding TypeFactory for the Architecture |
trans | is the Translate object for floating-point formats |
References CPUI_BOOL_AND, CPUI_BOOL_NEGATE, CPUI_BOOL_OR, CPUI_BOOL_XOR, CPUI_BRANCH, CPUI_BRANCHIND, CPUI_CALL, CPUI_CALLIND, CPUI_CALLOTHER, CPUI_CAST, CPUI_CBRANCH, CPUI_COPY, CPUI_CPOOLREF, CPUI_FLOAT_ABS, CPUI_FLOAT_ADD, CPUI_FLOAT_CEIL, CPUI_FLOAT_DIV, CPUI_FLOAT_EQUAL, CPUI_FLOAT_FLOAT2FLOAT, CPUI_FLOAT_FLOOR, CPUI_FLOAT_INT2FLOAT, CPUI_FLOAT_LESS, CPUI_FLOAT_LESSEQUAL, CPUI_FLOAT_MULT, CPUI_FLOAT_NAN, CPUI_FLOAT_NEG, CPUI_FLOAT_NOTEQUAL, CPUI_FLOAT_ROUND, CPUI_FLOAT_SQRT, CPUI_FLOAT_SUB, CPUI_FLOAT_TRUNC, CPUI_INDIRECT, CPUI_INT_2COMP, CPUI_INT_ADD, CPUI_INT_AND, CPUI_INT_CARRY, CPUI_INT_DIV, CPUI_INT_EQUAL, CPUI_INT_LEFT, CPUI_INT_LESS, CPUI_INT_LESSEQUAL, CPUI_INT_MULT, CPUI_INT_NEGATE, CPUI_INT_NOTEQUAL, CPUI_INT_OR, CPUI_INT_REM, CPUI_INT_RIGHT, CPUI_INT_SBORROW, CPUI_INT_SCARRY, CPUI_INT_SDIV, CPUI_INT_SEXT, CPUI_INT_SLESS, CPUI_INT_SLESSEQUAL, CPUI_INT_SREM, CPUI_INT_SRIGHT, CPUI_INT_SUB, CPUI_INT_XOR, CPUI_INT_ZEXT, CPUI_LOAD, CPUI_MAX, CPUI_MULTIEQUAL, CPUI_NEW, CPUI_PIECE, CPUI_PTRADD, CPUI_PTRSUB, CPUI_RETURN, CPUI_SEGMENTOP, CPUI_STORE, CPUI_SUBPIECE, and tlst.
Referenced by Architecture::buildInstructions().
|
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.
inst | is the array of TypeOp information objects |
val | is 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 PrintJava::adjustTypeOperators(), and PrintC::adjustTypeOperators().