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

The base datatype class for the decompiler. More...

#include <type.hh>

Inheritance diagram for ghidra::Datatype:
ghidra::TypeArray ghidra::TypeBase ghidra::TypeCode ghidra::TypePartialStruct ghidra::TypePartialUnion ghidra::TypePointer ghidra::TypeSpacebase ghidra::TypeStruct ghidra::TypeUnion ghidra::TypeVoid

Public Member Functions

 Datatype (const Datatype &op)
 Construct the base data-type copying low-level properties of another.
 
 Datatype (int4 s, type_metatype m)
 Construct the base data-type providing size and meta-type.
 
virtual ~Datatype (void)
 Destructor.
 
bool isCoreType (void) const
 Is this a core data-type.
 
bool isCharPrint (void) const
 Does this print as a 'char'.
 
bool isEnumType (void) const
 Is this an enumerated type.
 
bool isPowerOfTwo (void) const
 Is this a flag-based enumeration.
 
bool isASCII (void) const
 Does this print as an ASCII 'char'.
 
bool isUTF16 (void) const
 Does this print as UTF16 'wchar'.
 
bool isUTF32 (void) const
 Does this print as UTF32 'wchar'.
 
bool isVariableLength (void) const
 Is this a variable length structure.
 
bool hasSameVariableBase (const Datatype *ct) const
 Are these the same variable length data-type. More...
 
bool isOpaqueString (void) const
 Is this an opaquely encoded string.
 
bool isPointerRel (void) const
 Is this a TypePointerRel.
 
bool isFormalPointerRel (void) const
 Is this a non-ephemeral TypePointerRel.
 
bool hasStripped (void) const
 Return true if this has a stripped form.
 
bool isIncomplete (void) const
 Is this an incompletely defined data-type.
 
bool needsResolution (void) const
 Is this a union or a pointer to union.
 
uint4 getInheritable (void) const
 Get properties pointers inherit.
 
uint4 getDisplayFormat (void) const
 Get the display format for constants with this data-type. More...
 
type_metatype getMetatype (void) const
 Get the type meta-type.
 
sub_metatype getSubMeta (void) const
 Get the sub-metatype.
 
uint8 getId (void) const
 Get the type id.
 
int4 getSize (void) const
 Get the type size.
 
const string & getName (void) const
 Get the type name.
 
const string & getDisplayName (void) const
 Get string to use in display.
 
DatatypegetTypedef (void) const
 Get the data-type immediately typedefed by this (or null)
 
virtual void printRaw (ostream &s) const
 Print a description of the type to stream. More...
 
virtual const TypeFieldfindTruncation (int8 off, int4 sz, const PcodeOp *op, int4 slot, int8 &newoff) const
 Find an immediate subfield of this data-type. More...
 
virtual DatatypegetSubType (int8 off, int8 *newoff) const
 Recover component data-type one-level down. More...
 
virtual DatatypenearestArrayedComponentForward (int8 off, int8 *newoff, int8 *elSize) const
 
virtual DatatypenearestArrayedComponentBackward (int8 off, int8 *newoff, int8 *elSize) const
 
virtual int4 getHoleSize (int4 off) const
 Get number of bytes at the given offset that are padding.
 
virtual int4 numDepend (void) const
 Return number of component sub-types.
 
virtual DatatypegetDepend (int4 index) const
 Return the i-th component sub-type.
 
virtual void printNameBase (ostream &s) const
 Print name as short prefix.
 
virtual int4 compare (const Datatype &op, int4 level) const
 Order types for propagation. More...
 
virtual int4 compareDependency (const Datatype &op) const
 Compare for storage in tree structure. More...
 
virtual void encode (Encoder &encoder) const
 Encode the data-type to a stream. More...
 
virtual bool isPtrsubMatching (uintb off) const
 Is this data-type suitable as input to a CPUI_PTRSUB op. More...
 
virtual DatatypegetStripped (void) const
 Get a stripped version of this for formal use in formal declarations. More...
 
virtual DatatyperesolveInFlow (PcodeOp *op, int4 slot)
 Tailor data-type propagation based on Varnode use. More...
 
virtual DatatypefindResolve (const PcodeOp *op, int4 slot)
 Find a previously resolved sub-type. More...
 
virtual int4 findCompatibleResolve (Datatype *ct) const
 Find a resolution compatible with the given data-type. More...
 
virtual const TypeFieldresolveTruncation (int8 offset, PcodeOp *op, int4 slot, int8 &newoff)
 Resolve which union field is being used for a given PcodeOp when a truncation is involved. More...
 
int4 typeOrder (const Datatype &op) const
 Order this with -op- datatype.
 
int4 typeOrderBool (const Datatype &op) const
 Order this with -op-, treating bool data-type as special. More...
 
void encodeRef (Encoder &encoder) const
 Encode a reference of this to a stream. More...
 
bool isPieceStructured (void) const
 Does this data-type consist of separate pieces? More...
 

Static Public Member Functions

static uint4 encodeIntegerFormat (const string &val)
 Encode the format attribute from an XML element. More...
 
static string decodeIntegerFormat (uint4 val)
 Decode the given format value into an XML attribute string. More...
 

Protected Types

enum  {
  coretype = 1, chartype = 2, enumtype = 4, poweroftwo = 8,
  utf16 = 16, utf32 = 32, opaque_string = 64, variable_length = 128,
  has_stripped = 0x100, is_ptrrel = 0x200, type_incomplete = 0x400, needs_resolution = 0x800,
  force_format = 0x7000, truncate_bigendian = 0x8000
}
 Boolean properties of datatypes. More...
 

Protected Member Functions

void decodeBasic (Decoder &decoder)
 Recover basic data-type properties. More...
 
void encodeBasic (type_metatype meta, Encoder &encoder) const
 Encode basic data-type properties. More...
 
void encodeTypedef (Encoder &encoder) const
 Encode this as a typedef element to a stream. More...
 
void markComplete (void)
 Mark this data-type as completely defined.
 
void setDisplayFormat (uint4 format)
 Set a specific display format. More...
 
virtual Datatypeclone (void) const =0
 Clone the data-type.
 

Static Protected Member Functions

static uint8 hashName (const string &nm)
 Produce a data-type id by hashing the type name. More...
 
static uint8 hashSize (uint8 id, int4 size)
 Reversibly hash size into id. More...
 

Protected Attributes

uint8 id
 A unique id for the type (or 0 if an id is not assigned)
 
int4 size
 Size (of variable holding a value of this type)
 
uint4 flags
 Boolean properties of the type.
 
string name
 Name of type.
 
string displayName
 Name to display in output.
 
type_metatype metatype
 Meta-type - type disregarding size.
 
sub_metatype submeta
 Sub-type of of the meta-type, for comparisons.
 
DatatypetypedefImm
 The immediate data-type being typedefed by this.
 

Static Protected Attributes

static sub_metatype base2sub [15]
 

Friends

class TypeFactory
 
struct DatatypeCompare
 

Detailed Description

The base datatype class for the decompiler.

Used for symbols, function prototypes, type propagation etc.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

Boolean properties of datatypes.

Enumerator
coretype 

This is a basic type which will never be redefined.

chartype 

ASCII character data.

enumtype 

An enumeration type (as well as an integer)

poweroftwo 

An enumeration type where all values are of 2^^n form.

utf16 

16-bit wide chars in unicode UTF16

utf32 

32-bit wide chars in unicode UTF32

opaque_string 

Structure that should be treated as a string.

variable_length 

May be other structures with same name different lengths.

has_stripped 

Datatype has a stripped form for formal declarations.

is_ptrrel 

Datatype is a TypePointerRel.

type_incomplete 

Set if this (recursive) data-type has not been fully defined yet.

needs_resolution 

Datatype (union, pointer to union) needs resolution before propagation.

force_format 

3-bits encoding display format, 0=none, 1=hex, 2=dec, 3=oct, 4=bin, 5=char

truncate_bigendian 

Pointer can be truncated and is big endian.

Member Function Documentation

◆ compare()

int4 ghidra::Datatype::compare ( const Datatype op,
int4  level 
) const
virtual

◆ compareDependency()

int4 ghidra::Datatype::compareDependency ( const Datatype op) const
virtual

Compare for storage in tree structure.

Sort data-types for the main TypeFactory container. The sort needs to be based on the data-type structure so that an example data-type, constructed outside the factory, can be used to find the equivalent object inside the factory. This means the comparison should not examine the data-type id. In practice, the comparison only needs to go down one level in the component structure before just comparing component pointers.

Parameters
opis the data-type to compare with this
Returns
negative, 0, positive depending on ordering of types

Reimplemented in ghidra::TypeSpacebase, ghidra::TypeCode, ghidra::TypePointerRel, ghidra::TypePartialUnion, ghidra::TypePartialStruct, ghidra::TypeUnion, ghidra::TypeStruct, ghidra::TypeEnum, ghidra::TypeArray, and ghidra::TypePointer.

References metatype, size, submeta, ghidra::TYPE_ARRAY, ghidra::TYPE_BOOL, ghidra::TYPE_CODE, ghidra::TYPE_FLOAT, ghidra::TYPE_INT, ghidra::TYPE_PARTIALSTRUCT, ghidra::TYPE_PARTIALUNION, ghidra::TYPE_PTR, ghidra::TYPE_PTRREL, ghidra::TYPE_SPACEBASE, ghidra::TYPE_STRUCT, ghidra::TYPE_UINT, ghidra::TYPE_UNION, ghidra::TYPE_UNKNOWN, and ghidra::TYPE_VOID.

Referenced by ghidra::TypeEnum::compareDependency(), ghidra::TypeStruct::compareDependency(), ghidra::TypeUnion::compareDependency(), ghidra::TypeCode::compareDependency(), ghidra::TypeSpacebase::compareDependency(), ghidra::TypeFactory::decodeCode(), ghidra::TypeFactory::decodeStruct(), ghidra::TypeFactory::decodeUnion(), ghidra::TypeEnum::endEnum(), ghidra::TypeFactory::findAdd(), ghidra::TypeStruct::getDepend(), ghidra::TypeUnion::getDepend(), ghidra::TypePartialStruct::getParent(), ghidra::TypePartialUnion::getParentUnion(), ghidra::TypePointerRel::getPointerOffset(), ghidra::TypeCode::getPrototype(), ghidra::DatatypeCompare::operator()(), printNameBase(), ghidra::TypePointer::printNameBase(), ghidra::TypeArray::printNameBase(), and ghidra::TypeSpacebase::TypeSpacebase().

◆ decodeBasic()

void ghidra::Datatype::decodeBasic ( Decoder decoder)
protected

◆ decodeIntegerFormat()

string ghidra::Datatype::decodeIntegerFormat ( uint4  val)
static

Decode the given format value into an XML attribute string.

Possible encoded values are 1-5 corresponding to "hex", "dec", "oct", "bin", "char"

Parameters
valis the value to decode
Returns
the decoded string

Referenced by encodeBasic(), ghidra::Symbol::encodeHeader(), encodeTypedef(), and typeOrder().

◆ encode()

void ghidra::Datatype::encode ( Encoder encoder) const
virtual

◆ encodeBasic()

void ghidra::Datatype::encodeBasic ( type_metatype  meta,
Encoder encoder 
) const
protected

◆ encodeIntegerFormat()

uint4 ghidra::Datatype::encodeIntegerFormat ( const string &  val)
static

Encode the format attribute from an XML element.

Possible values are:

  • 1 - hex
  • 2 - dec
  • 3 - oct
  • 4 - bin
  • 5 - char
Parameters
valis the string to encode
Returns
the encoded value

Referenced by decodeBasic(), ghidra::Symbol::decodeHeader(), ghidra::TypeFactory::decodeTypedef(), ghidra::IfcForceFormat::execute(), ghidra::IfcForceDatatypeFormat::execute(), and typeOrder().

◆ encodeRef()

void ghidra::Datatype::encodeRef ( Encoder encoder) const

Encode a reference of this to a stream.

Encode a simple reference to this data-type as a <typeref> element, including only the name and id.

Parameters
encoderis the stream encoder

References ghidra::Encoder::closeElement(), encode(), hashSize(), isVariableLength(), name, ghidra::Encoder::openElement(), ghidra::TYPE_VOID, ghidra::Encoder::writeSignedInteger(), ghidra::Encoder::writeString(), and ghidra::Encoder::writeUnsignedInteger().

Referenced by ghidra::TypePartialUnion::encode(), encodeTypedef(), and typeOrder().

◆ encodeTypedef()

void ghidra::Datatype::encodeTypedef ( Encoder encoder) const
protected

Encode this as a typedef element to a stream.

Called only if the typedefImm field is non-null. Encode the data-type to the stream as a simple <typedef> element including only the names and ids of this and the data-type it typedefs.

Parameters
encoderis the stream encoder

References ghidra::Encoder::closeElement(), decodeIntegerFormat(), encodeRef(), getDisplayFormat(), name, ghidra::Encoder::openElement(), typedefImm, ghidra::Encoder::writeString(), and ghidra::Encoder::writeUnsignedInteger().

Referenced by ghidra::TypeChar::encode(), ghidra::TypeUnicode::encode(), ghidra::TypeVoid::encode(), ghidra::TypePointer::encode(), ghidra::TypeArray::encode(), ghidra::TypeEnum::encode(), ghidra::TypeStruct::encode(), ghidra::TypeUnion::encode(), ghidra::TypeCode::encode(), and ghidra::TypeSpacebase::encode().

◆ findCompatibleResolve()

int4 ghidra::Datatype::findCompatibleResolve ( Datatype ct) const
virtual

Find a resolution compatible with the given data-type.

If this data-type has an alternate data-type form that matches the given data-type, return an index indicating this form, otherwise return -1.

Parameters
ctis the given data-type
Returns
the index of the matching form or -1

Reimplemented in ghidra::TypePartialUnion, ghidra::TypeUnion, ghidra::TypeStruct, and ghidra::TypeArray.

Referenced by ghidra::TypeArray::clone(), ghidra::TypeStruct::clone(), ghidra::TypeUnion::clone(), ghidra::TypeArray::findCompatibleResolve(), ghidra::TypeStruct::findCompatibleResolve(), ghidra::TypeUnion::findCompatibleResolve(), ghidra::TypePartialUnion::getStripped(), printNameBase(), and ghidra::ActionSetCasts::tryResolutionAdjustment().

◆ findResolve()

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

Find a previously resolved sub-type.

This is the constant version of resolveInFlow. If a resulting subtype has already been calculated, for the particular read (slot >= 0) or write (slot == -1), then return it. Otherwise return the original data-type.

Parameters
opis the PcodeOp using the Varnode assigned with this data-type
slotis the slot reading or writing the Varnode
Returns
the resolved subtype or the original data-type

Reimplemented in ghidra::TypePartialUnion, ghidra::TypeUnion, ghidra::TypeStruct, ghidra::TypeArray, and ghidra::TypePointer.

Referenced by ghidra::ActionSetCasts::castOutput(), ghidra::TypePointer::clone(), ghidra::TypeArray::clone(), ghidra::TypeStruct::clone(), ghidra::TypeUnion::clone(), ghidra::TypePartialUnion::findResolve(), ghidra::Varnode::getHighTypeDefFacing(), ghidra::Varnode::getHighTypeReadFacing(), ghidra::TypePartialUnion::getStripped(), ghidra::Varnode::getTypeDefFacing(), ghidra::Varnode::getTypeReadFacing(), printNameBase(), and ghidra::PrintC::pushPartialSymbol().

◆ findTruncation()

const TypeField * ghidra::Datatype::findTruncation ( int8  off,
int4  sz,
const PcodeOp op,
int4  slot,
int8 &  newoff 
) const
virtual

Find an immediate subfield of this data-type.

Given a byte range within this data-type, determine the field it is contained in and pass back the renormalized offset. This method applies to TYPE_STRUCT, TYPE_UNION, and TYPE_PARTIALUNION, data-types that have field components. For TYPE_UNION and TYPE_PARTIALUNION, the field may depend on the p-code op extracting or writing the value.

Parameters
offis the byte offset into this
szis the size of the byte range
opis the PcodeOp reading/writing the data-type
slotis the index of the Varnode being accessed, -1 for the output, >=0 for an input
newoffpoints to the renormalized offset to pass back
Returns
the containing field or NULL if the range is not contained

Reimplemented in ghidra::TypePartialUnion, ghidra::TypeUnion, and ghidra::TypeStruct.

Referenced by ghidra::TypeStruct::endField(), ghidra::TypeUnion::getField(), ghidra::TypeOpSubpiece::getOutputToken(), ghidra::TypePartialUnion::getParentUnion(), getTypedef(), ghidra::PrintC::opPtrsub(), ghidra::PrintC::opSubpiece(), and ghidra::PrintC::pushPartialSymbol().

◆ getDisplayFormat()

uint4 ghidra::Datatype::getDisplayFormat ( void  ) const
inline

Get the display format for constants with this data-type.

A non-zero result indicates the type of formatting that is forced on the constant. One of the following values is returned.

  • 1 for hexadecimal
  • 2 for decimal
  • 3 for octal
  • 4 for binary
  • 5 for char
Returns
the forced encoding type or zero

References flags, and force_format.

Referenced by encodeBasic(), encodeTypedef(), getInheritable(), ghidra::PrintC::push_integer(), and ghidra::PrintC::pushCharConstant().

◆ getStripped()

Datatype * ghidra::Datatype::getStripped ( void  ) const
virtual

Get a stripped version of this for formal use in formal declarations.

Some data-types are ephemeral, and, in the final decompiler output, get replaced with a formal version that is a stripped down version of the original. This method returns this stripped down version, if it exists, or null otherwise. A non-null return should correspond with hasStripped returning true.

Returns
the stripped version or null

Reimplemented in ghidra::TypePointerRel, ghidra::TypePartialUnion, and ghidra::TypePartialStruct.

Referenced by ghidra::Scope::addSymbol(), ghidra::TypeFactory::getTypeArray(), ghidra::TypeFactory::getTypePointer(), ghidra::TypeFactory::getTypePointerStripArray(), printNameBase(), ghidra::TypeFactory::resizePointer(), and ghidra::ScopeInternal::retypeSymbol().

◆ getSubType()

Datatype * ghidra::Datatype::getSubType ( int8  off,
int8 *  newoff 
) const
virtual

Recover component data-type one-level down.

Given an offset into this data-type, return the component data-type at that offset. Also, pass back a "renormalized" offset suitable for recursize getSubType() calls: i.e. if the original offset hits the exact start of the sub-type, 0 is passed back. If there is no valid component data-type at the offset, return NULL and pass back the original offset

Parameters
offis the offset into this data-type
newoffis a pointer to the passed-back offset
Returns
a pointer to the component data-type or NULL

Reimplemented in ghidra::TypeSpacebase, ghidra::TypeCode, ghidra::TypePartialStruct, ghidra::TypeStruct, ghidra::TypeArray, and ghidra::TypePointer.

Referenced by ghidra::RuleStructOffset0::applyOp(), ghidra::SplitDatatype::buildPointers(), ghidra::RulePieceStructure::convertZextToPiece(), ghidra::ScoreUnionFields::derefPointer(), ghidra::RulePieceStructure::determineDatatype(), ghidra::TypePointer::downChain(), ghidra::TypeStruct::endField(), ghidra::TypePartialUnion::findResolve(), ghidra::SplitDatatype::getComponent(), ghidra::TypeFactory::getExactPiece(), ghidra::TypePartialStruct::getParent(), ghidra::TypeCode::getPrototype(), ghidra::TypePointerRel::getPtrToFromParent(), ghidra::TypePointer::getSpace(), ghidra::TypeStruct::getSubType(), ghidra::TypePartialStruct::getSubType(), getTypedef(), ghidra::AddTreeState::hasMatchingSubType(), ghidra::TypeArray::numElements(), ghidra::TypeOpPiece::propagateType(), ghidra::TypeOpSubpiece::propagateType(), ghidra::RangeHint::reconcile(), ghidra::TypePartialUnion::resolveInFlow(), ghidra::ScoreUnionFields::scoreTruncation(), ghidra::RulePieceStructure::spanningRange(), and ghidra::TypeSpacebase::TypeSpacebase().

◆ hashName()

uint8 ghidra::Datatype::hashName ( const string &  nm)
staticprotected

◆ hashSize()

uint8 ghidra::Datatype::hashSize ( uint8  id,
int4  size 
)
staticprotected

Reversibly hash size into id.

This allows IDs for variable length structures to be uniquefied based on size. A base ID is given and a size of the specific instance. A unique ID is returned. The hashing is reversible by feeding the output ID back into this function with the same size.

Parameters
idis the given ID to (de)uniquify
sizeis the instance size of the structure
Returns
the (de)uniquified id

References id, and size.

Referenced by decodeBasic(), ghidra::TypeFactory::decodeTypedef(), encodeBasic(), encodeRef(), ghidra::TypeFactory::findById(), hasSameVariableBase(), and markComplete().

◆ hasSameVariableBase()

bool ghidra::Datatype::hasSameVariableBase ( const Datatype ct) const

Are these the same variable length data-type.

If this and the other given data-type are both variable length and come from the the same base data-type, return true.

Parameters
ctis the other given data-type to compare with this
Returns
true if they are the same variable length data-type.

References hashSize(), id, isVariableLength(), and size.

Referenced by ghidra::CastStrategyC::castStandard(), and isVariableLength().

◆ isPieceStructured()

bool ghidra::Datatype::isPieceStructured ( void  ) const
inline

Does this data-type consist of separate pieces?

If a value with this data-type is put together from multiple pieces, is it better to display this construction as a sequence of separate assignments or as a single concatenation. Generally a TYPE_STRUCT or TYPE_ARRAY should be represented with separate assignments.

Returns
true if the data-type is put together with multiple assignments

References metatype, and ghidra::TYPE_ARRAY.

Referenced by ghidra::RuleSubRight::applyOp(), ghidra::RulePieceStructure::determineDatatype(), ghidra::Varnode::getStructuredType(), ghidra::PrintC::opSubpiece(), ghidra::RulePieceStructure::separateSymbol(), ghidra::RulePieceStructure::spanningRange(), and typeOrder().

◆ isPtrsubMatching()

bool ghidra::Datatype::isPtrsubMatching ( uintb  off) const
virtual

Is this data-type suitable as input to a CPUI_PTRSUB op.

A CPUI_PTRSUB must act on a pointer data-type where the given offset addresses a component. Perform this check.

Parameters
offis the given offset
Returns
true if this is a suitable PTRSUB data-type

Reimplemented in ghidra::TypePointerRel, and ghidra::TypePointer.

Referenced by ghidra::ActionSetCasts::apply(), ghidra::RulePtrsubUndo::applyOp(), ghidra::TypePointer::clone(), ghidra::TypePointerRel::clone(), and printNameBase().

◆ nearestArrayedComponentBackward()

Datatype * ghidra::Datatype::nearestArrayedComponentBackward ( int8  off,
int8 *  newoff,
int8 *  elSize 
) const
virtual

Find the first component data-type before the given offset that is (or contains) an array, and pass back the difference between the component's start and the given offset. Return the component data-type or null if no array is found.

Parameters
offis the given offset into this data-type
newoffis used to pass back the offset difference
elSizeis used to pass back the array element size
Returns
the component data-type or null

Reimplemented in ghidra::TypeSpacebase, and ghidra::TypeStruct.

Referenced by ghidra::TypeStruct::endField(), getTypedef(), ghidra::AddTreeState::hasMatchingSubType(), ghidra::TypeStruct::nearestArrayedComponentBackward(), ghidra::TypeSpacebase::nearestArrayedComponentBackward(), and ghidra::TypeSpacebase::TypeSpacebase().

◆ nearestArrayedComponentForward()

Datatype * ghidra::Datatype::nearestArrayedComponentForward ( int8  off,
int8 *  newoff,
int8 *  elSize 
) const
virtual

Find the first component data-type after the given offset that is (or contains) an array, and pass back the difference between the component's start and the given offset. Return the component data-type or null if no array is found.

Parameters
offis the given offset into this data-type
newoffis used to pass back the offset difference
elSizeis used to pass back the array element size
Returns
the component data-type or null

Reimplemented in ghidra::TypeSpacebase, and ghidra::TypeStruct.

Referenced by ghidra::TypeStruct::endField(), getTypedef(), ghidra::AddTreeState::hasMatchingSubType(), ghidra::TypeStruct::nearestArrayedComponentForward(), ghidra::TypeSpacebase::nearestArrayedComponentForward(), and ghidra::TypeSpacebase::TypeSpacebase().

◆ printRaw()

void ghidra::Datatype::printRaw ( ostream &  s) const
virtual

◆ resolveInFlow()

Datatype * ghidra::Datatype::resolveInFlow ( PcodeOp op,
int4  slot 
)
virtual

Tailor data-type propagation based on Varnode use.

For certain data-types, particularly union, variables of that data-type are transformed into a subtype depending on the particular use. Each read or write of the variable may use a different subtype. This method returns the particular subtype required based on a specific PcodeOp. A slot index >=0 indicates which operand reads the variable, or if the index is -1, the variable is written.

Parameters
opis the specific PcodeOp
slotindicates the input operand, or the output
Returns
the resolved sub-type

Reimplemented in ghidra::TypePartialUnion, ghidra::TypeUnion, ghidra::TypeStruct, ghidra::TypeArray, and ghidra::TypePointer.

Referenced by ghidra::RulePieceStructure::applyOp(), ghidra::ActionSetCasts::castOutput(), ghidra::TypePointer::clone(), ghidra::TypeArray::clone(), ghidra::TypeStruct::clone(), ghidra::TypeUnion::clone(), ghidra::TypePartialUnion::getStripped(), printNameBase(), ghidra::ActionInferTypes::propagateTypeEdge(), and ghidra::ActionSetCasts::resolveUnion().

◆ resolveTruncation()

const TypeField * ghidra::Datatype::resolveTruncation ( int8  offset,
PcodeOp op,
int4  slot,
int8 &  newoff 
)
virtual

Resolve which union field is being used for a given PcodeOp when a truncation is involved.

This method applies to the TYPE_UNION and TYPE_PARTIALUNION data-types, when a Varnode is backed by a larger Symbol with a union data-type, or if the Varnode is produced by a CPUI_SUBPIECE where the input Varnode has a union data-type. Scoring is done to compute the best field and the result is cached with the function. The record of the best field is returned or null if there is no appropriate field

Parameters
offsetis the byte offset into the union we are truncating to
opis either the PcodeOp reading the truncated Varnode or the CPUI_SUBPIECE doing the truncation
slotis either the input slot of the reading PcodeOp or the artificial SUBPIECE slot: 1
newoffis used to pass back how much offset is left to resolve
Returns
the field of the union best associated with the truncation or null

Reimplemented in ghidra::TypePartialUnion, and ghidra::TypeUnion.

Referenced by ghidra::TypeUnion::clone(), ghidra::TypePartialUnion::getStripped(), printNameBase(), ghidra::TypeOpSubpiece::propagateType(), and ghidra::TypePartialUnion::resolveInFlow().

◆ setDisplayFormat()

void ghidra::Datatype::setDisplayFormat ( uint4  format)
inlineprotected

Set a specific display format.

The display format for the data-type is changed based on the given format. A value of zero clears any preexisting format. Otherwise the value can be one of: 1=hex, 2=dec, 3=oct, 4=bin, 5=char

Parameters
formatis the given format

References flags, and force_format.

Referenced by decodeBasic(), ghidra::TypeFactory::getArch(), ghidra::TypeFactory::getTypedef(), markComplete(), and ghidra::TypeFactory::setDisplayFormat().

◆ typeOrderBool()

int4 ghidra::Datatype::typeOrderBool ( const Datatype op) const
inline

Order this with -op-, treating bool data-type as special.

Order data-types, with special handling of the bool data-type. Data-types are compared using the normal ordering, but bool is ordered after all other data-types. A return value of 0 indicates the data-types are the same, -1 indicates that this is prefered (ordered earlier), and 1 indicates this is ordered later.

Parameters
opis the other data-type to compare with this
Returns
-1, 0, or 1

References compare(), metatype, and ghidra::TYPE_BOOL.

Referenced by ghidra::HighVariable::getTypeRepresentative(), and typeOrder().

Member Data Documentation

◆ base2sub

sub_metatype ghidra::Datatype::base2sub
staticprotected
Initial value:

The base propagation ordering associated with each meta-type. The array elements correspond to the ordering of #type_metatype.

Referenced by decodeBasic().


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