decompiler  1.0.0
Public Member Functions | List of all members
CastStrategyC Class Reference

Casting strategies that are specific to the C language. More...

#include <cast.hh>

Inheritance diagram for CastStrategyC:
CastStrategy CastStrategyJava

Public Member Functions

virtual int4 localExtensionType (const Varnode *vn) const
 Decide on integer promotion by examining just local properties of the given Varnode. More...
 
virtual int4 intPromotionType (const Varnode *vn) const
 Calculate the integer promotion code of a given Varnode. More...
 
virtual bool checkIntPromotionForCompare (const PcodeOp *op, int4 slot) const
 Check if integer promotion forces a cast for the given comparison op and slot. More...
 
virtual bool checkIntPromotionForExtension (const PcodeOp *op) const
 Check if integer promotion forces a cast for the input to the given extension. More...
 
virtual DatatypecastStandard (Datatype *reqtype, Datatype *curtype, bool care_uint_int, bool care_ptr_uint) const
 Does there need to be a visible cast between the given data-types. More...
 
virtual DatatypearithmeticOutputStandard (const PcodeOp *op)
 What is the output data-type produced by the given integer arithmetic operation. More...
 
virtual bool isSubpieceCast (Datatype *outtype, Datatype *intype, uint4 offset) const
 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
 Is the given data-type truncation considered a cast, given endianess concerns. More...
 
virtual bool isSextCast (Datatype *outtype, Datatype *intype) const
 Is sign-extending an input data-type, producing an output data-type, considered a cast. More...
 
virtual bool isZextCast (Datatype *outtype, Datatype *intype) const
 Is zero-extending an input data-type, producing an output data-type, considered a cast. More...
 
- Public Member Functions inherited from CastStrategy
 CastStrategy (void)
 Constructor.
 
void setTypeFactory (TypeFactory *t)
 Establish the data-type factory. More...
 
virtual ~CastStrategy (void)
 Destructor.
 

Additional Inherited Members

- Public Types inherited from CastStrategy
enum  IntPromotionCode {
  NO_PROMOTION = -1, UNKNOWN_PROMOTION = 0, UNSIGNED_EXTENSION = 1, SIGNED_EXTENSION = 2,
  EITHER_EXTENSION = 3
}
 Types of integer promotion. More...
 
- Protected Attributes inherited from CastStrategy
TypeFactorytlst
 Type factory associated with the Architecture.
 
int4 promoteSize
 Size of int data-type, (size that integers get promoted to)
 

Detailed Description

Casting strategies that are specific to the C language.

Member Function Documentation

◆ arithmeticOutputStandard()

Datatype * CastStrategyC::arithmeticOutputStandard ( const PcodeOp op)
virtual

What is the output data-type produced by the given integer arithmetic operation.

Parameters
opis the given operation
Returns
the output data-type

Implements CastStrategy.

References TypeFactory::getBase(), Varnode::getHigh(), PcodeOp::getIn(), Datatype::getMetatype(), Datatype::getSize(), HighVariable::getType(), PcodeOp::numInput(), CastStrategy::tlst, TYPE_BOOL, TYPE_INT, and Datatype::typeOrder().

◆ castStandard()

Datatype * CastStrategyC::castStandard ( Datatype reqtype,
Datatype curtype,
bool  care_uint_int,
bool  care_ptr_uint 
) const
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.

Parameters
reqtypeis the expected data-type
curtypeis the current data-type
care_uint_intis true if we care about a change in signedness
care_ptr_uintis true if we care about conversions between pointers and unsigned values
Returns
NULL to indicate no cast, or the data-type to cast to

Implements CastStrategy.

Reimplemented in CastStrategyJava.

References Datatype::getMetatype(), Datatype::getSize(), TYPE_BOOL, TYPE_CODE, TYPE_INT, TYPE_PTR, TYPE_UINT, TYPE_UNKNOWN, and TYPE_VOID.

◆ checkIntPromotionForCompare()

bool CastStrategyC::checkIntPromotionForCompare ( const PcodeOp op,
int4  slot 
) const
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.

Parameters
opis the given comparison operator
slotis the input slot being tested
Returns
true if a cast is required before comparing

Implements CastStrategy.

References PcodeOp::getIn(), intPromotionType(), CastStrategy::NO_PROMOTION, and CastStrategy::UNKNOWN_PROMOTION.

◆ checkIntPromotionForExtension()

bool CastStrategyC::checkIntPromotionForExtension ( const PcodeOp op) const
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.

Parameters
opis the given extension operator INT_ZEXT or INT_SEXT
Returns
true if a cast is required before extending

Implements CastStrategy.

References PcodeOp::code(), CPUI_INT_SEXT, CPUI_INT_ZEXT, PcodeOp::getIn(), intPromotionType(), CastStrategy::NO_PROMOTION, CastStrategy::SIGNED_EXTENSION, CastStrategy::UNKNOWN_PROMOTION, and CastStrategy::UNSIGNED_EXTENSION.

◆ intPromotionType()

int4 CastStrategyC::intPromotionType ( const Varnode vn) const
virtual

◆ isSextCast()

bool CastStrategyC::isSextCast ( Datatype outtype,
Datatype intype 
) const
virtual

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.

Parameters
outtypeis the output data-type
intypeis the input data-type
Returns
true if the INT_SEXT should be represented as a cast

Implements CastStrategy.

References Datatype::getMetatype(), TYPE_BOOL, TYPE_INT, and TYPE_UINT.

◆ isSubpieceCast()

bool CastStrategyC::isSubpieceCast ( Datatype outtype,
Datatype intype,
uint4  offset 
) const
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.

Parameters
outtypeis the output data-type
intypeis the input data-type
offsetis number of bytes truncated by the SUBPIECE
Returns
true if the SUBPIECE should be represented as a cast

Implements CastStrategy.

References Datatype::getMetatype(), TYPE_FLOAT, TYPE_INT, TYPE_PTR, TYPE_UINT, and TYPE_UNKNOWN.

Referenced by isSubpieceCastEndian().

◆ isSubpieceCastEndian()

bool CastStrategyC::isSubpieceCastEndian ( Datatype outtype,
Datatype intype,
uint4  offset,
bool  isbigend 
) const
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.

Parameters
outtypeis the output data-type
intypeis the input data-type
offsetis the given byte offset (into the input memory)
isbigendis true if the address space holding the memory is big endian.
Returns
true if the truncation should be represented as a cast

Implements CastStrategy.

References Datatype::getSize(), and isSubpieceCast().

◆ isZextCast()

bool CastStrategyC::isZextCast ( Datatype outtype,
Datatype intype 
) const
virtual

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.

Parameters
outtypeis the output data-type
intypeis the input data-type
Returns
true if the INT_ZEXT should be represented as a cast

Implements CastStrategy.

Reimplemented in CastStrategyJava.

References Datatype::getMetatype(), TYPE_BOOL, TYPE_INT, and TYPE_UINT.

◆ localExtensionType()

int4 CastStrategyC::localExtensionType ( const Varnode vn) const
virtual

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