decompiler
1.0.0
|
A strategy for applying type casts. More...
#include <cast.hh>
Public Types | |
enum | IntPromotionCode { NO_PROMOTION = -1, UNKNOWN_PROMOTION = 0, UNSIGNED_EXTENSION = 1, SIGNED_EXTENSION = 2, EITHER_EXTENSION = 3 } |
Types of integer promotion. More... | |
Public Member Functions | |
CastStrategy (void) | |
Constructor. | |
void | setTypeFactory (TypeFactory *t) |
Establish the data-type factory. More... | |
virtual | ~CastStrategy (void) |
Destructor. | |
virtual int4 | localExtensionType (const Varnode *vn) const =0 |
Decide on integer promotion by examining just local properties of the given Varnode. More... | |
virtual int4 | intPromotionType (const Varnode *vn) const =0 |
Calculate the integer promotion code of a given Varnode. More... | |
virtual bool | checkIntPromotionForCompare (const PcodeOp *op, int4 slot) const =0 |
Check if integer promotion forces a cast for the given comparison op and slot. More... | |
virtual bool | checkIntPromotionForExtension (const PcodeOp *op) const =0 |
Check if integer promotion forces a cast for the input to the given extension. More... | |
virtual Datatype * | castStandard (Datatype *reqtype, Datatype *curtype, bool care_uint_int, bool care_ptr_uint) const =0 |
Does there need to be a visible cast between the given data-types. More... | |
virtual Datatype * | arithmeticOutputStandard (const PcodeOp *op)=0 |
What is the output data-type produced by the given integer arithmetic operation. More... | |
virtual bool | isSubpieceCast (Datatype *outtype, Datatype *intype, uint4 offset) const =0 |
Is truncating an input data-type, producing an output data-type, considered a cast. More... | |
virtual bool | isSubpieceCastEndian (Datatype *outtype, Datatype *intype, uint4 offset, bool isbigend) const =0 |
Is the given data-type truncation considered a cast, given endianess concerns. More... | |
virtual bool | isSextCast (Datatype *outtype, Datatype *intype) const =0 |
Is sign-extending an input data-type, producing an output data-type, considered a cast. More... | |
virtual bool | isZextCast (Datatype *outtype, Datatype *intype) const =0 |
Is zero-extending an input data-type, producing an output data-type, considered a cast. More... | |
Protected Attributes | |
TypeFactory * | tlst |
Type factory associated with the Architecture. | |
int4 | promoteSize |
Size of int data-type, (size that integers get promoted to) | |
A strategy for applying type casts.
A cast operation in C or other languages masks a variety of possible low-level conversions, such as extensions, truncations, integer to floating-point, etc. On top of this, languages allow many of these types of operations to be implied in the source code, with no explicit token representing the conversion. Conversions happen automatically for things like integer promotion, between different sizes (of integers), and between signed and unsigned data-type variants.
This class is the API for making four kinds of decisions:
Types of integer promotion.
For many languages, small integers are automatically promoted to a standard size. The decompiler describes how an expression is or will be affected by integer promotion, using these codes
What is the output data-type produced by the given integer arithmetic operation.
op | is the given operation |
Implemented in CastStrategyC.
Referenced by TypeOpIntAdd::getOutputToken(), TypeOpIntSub::getOutputToken(), TypeOpInt2Comp::getOutputToken(), TypeOpIntNegate::getOutputToken(), TypeOpIntXor::getOutputToken(), TypeOpIntAnd::getOutputToken(), TypeOpIntOr::getOutputToken(), and TypeOpIntMult::getOutputToken().
|
pure virtual |
Does there need to be a visible cast between the given data-types.
The cast is from a current data-type to an expected data-type. NULL is returned if no cast is required, otherwise the data-type to cast to (usually the expected data-type) is returned.
reqtype | is the expected data-type |
curtype | is the current data-type |
care_uint_int | is true if we care about a change in signedness |
care_ptr_uint | is true if we care about conversions between pointers and unsigned values |
Implemented in CastStrategyJava, and CastStrategyC.
Referenced by ActionSetCasts::castOutput(), TypeOp::getInputCast(), TypeOpCopy::getInputCast(), TypeOpLoad::getInputCast(), TypeOpStore::getInputCast(), TypeOpEqual::getInputCast(), TypeOpNotEqual::getInputCast(), TypeOpIntSless::getInputCast(), TypeOpIntSlessEqual::getInputCast(), TypeOpIntLess::getInputCast(), TypeOpIntLessEqual::getInputCast(), TypeOpIntZext::getInputCast(), TypeOpIntSext::getInputCast(), TypeOpIntRight::getInputCast(), TypeOpIntSright::getInputCast(), TypeOpIntDiv::getInputCast(), TypeOpIntSdiv::getInputCast(), TypeOpIntRem::getInputCast(), TypeOpIntSrem::getInputCast(), TypeOpPtradd::getInputCast(), and TypeOpPtrsub::getInputCast().
|
pure virtual |
Check if integer promotion forces a cast for the given comparison op and slot.
Compute to what level the given slot has seen integer promotion and if a cast is required before the comparison operator makes sense.
op | is the given comparison operator |
slot | is the input slot being tested |
Implemented in CastStrategyC.
Referenced by TypeOpEqual::getInputCast(), TypeOpNotEqual::getInputCast(), TypeOpIntSless::getInputCast(), TypeOpIntSlessEqual::getInputCast(), TypeOpIntLess::getInputCast(), and TypeOpIntLessEqual::getInputCast().
|
pure virtual |
Check if integer promotion forces a cast for the input to the given extension.
Compute to what level the given slot has seen integer promotion and if a cast is required before the extension operator makes sense.
op | is the given extension operator INT_ZEXT or INT_SEXT |
Implemented in CastStrategyC.
Referenced by TypeOpIntZext::getInputCast(), and TypeOpIntSext::getInputCast().
|
pure virtual |
Calculate the integer promotion code of a given Varnode.
Recursively examine the expression defining the Varnode as necessary
vn | is the given Varnode |
Implemented in CastStrategyC.
Is sign-extending an input data-type, producing an output data-type, considered a cast.
Data-types must be provided from the input and output of an INT_SEXT operation.
outtype | is the output data-type |
intype | is the input data-type |
Implemented in CastStrategyC.
Referenced by PrintC::opIntSext().
|
pure virtual |
Is truncating an input data-type, producing an output data-type, considered a cast.
Data-types must be provided from the input and output of a SUBPIECE operation.
outtype | is the output data-type |
intype | is the input data-type |
offset | is number of bytes truncated by the SUBPIECE |
Implemented in CastStrategyC.
Referenced by PrintC::opSubpiece().
|
pure virtual |
Is the given data-type truncation considered a cast, given endianess concerns.
This is equivalent to isSubpieceCast() but where the truncation is accomplished by pulling bytes directly out of memory. We assume the input data-type is layed down in memory, and we pull the output value starting at a given byte offset.
outtype | is the output data-type |
intype | is the input data-type |
offset | is the given byte offset (into the input memory) |
isbigend | is true if the address space holding the memory is big endian. |
Implemented in CastStrategyC.
Referenced by PrintC::pushPartialSymbol().
Is zero-extending an input data-type, producing an output data-type, considered a cast.
Data-types must be provided from the input and output of an INT_ZEXT operation.
outtype | is the output data-type |
intype | is the input data-type |
Implemented in CastStrategyJava, and CastStrategyC.
Referenced by PrintC::opIntZext().
|
pure virtual |
Decide on integer promotion by examining just local properties of the given Varnode.
vn | is the given Varnode |
Implemented in CastStrategyC.
void CastStrategy::setTypeFactory | ( | TypeFactory * | t | ) |
Establish the data-type factory.
Sets the TypeFactory used to produce data-types for the arithmeticOutputStandard() method
t | is the TypeFactory |
References TypeFactory::getSizeOfInt(), promoteSize, and tlst.
Referenced by Architecture::init(), and Architecture::setPrintLanguage().