decompiler  1.0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ghidra::PcodeCacher Class Reference

Class for caching a chunk of p-code, prior to emitting. More...

#include <sleigh.hh>

Public Member Functions

 PcodeCacher (void)
 Constructor.
 
 ~PcodeCacher (void)
 Destructor.
 
VarnodeDataallocateVarnodes (uint4 size)
 Allocate data objects for a new set of Varnodes. More...
 
PcodeDataallocateInstruction (void)
 Allocate a data object for a new p-code operation. More...
 
void addLabelRef (VarnodeData *ptr)
 Denote a Varnode holding a relative branch offset. More...
 
void addLabel (uint4 id)
 Attach a label to the next p-code instruction. More...
 
void clear (void)
 Reset the cache so that all objects are unallocated.
 
void resolveRelatives (void)
 Rewrite branch target Varnodes as relative offsets. More...
 
void emit (const Address &addr, PcodeEmit *emt) const
 Pass the cached p-code data to the emitter. More...
 

Private Member Functions

VarnodeDataexpandPool (uint4 size)
 Expand the memory pool. More...
 

Private Attributes

VarnodeDatapoolstart
 Start of the pool of VarnodeData objects.
 
VarnodeDatacurpool
 First unused VarnodeData.
 
VarnodeDataendpool
 End of the pool of VarnodeData objects.
 
vector< PcodeDataissued
 P-code ops issued for the current instruction.
 
list< RelativeRecordlabel_refs
 References to labels.
 
vector< uintb > labels
 Locations of labels.
 

Detailed Description

Class for caching a chunk of p-code, prior to emitting.

The engine accumulates PcodeData and VarnodeData objects for a single instruction. Once the full instruction is constructed, the objects are passed to the emitter (PcodeEmit) via the emit() method. The class acts as a pool of memory for PcodeData and VarnodeData objects that can be reused repeatedly to emit multiple instructions.

Member Function Documentation

◆ addLabel()

void ghidra::PcodeCacher::addLabel ( uint4  id)

Attach a label to the next p-code instruction.

The label has an id that is referred to by Varnodes holding intra-instruction branch targets, prior to converting them to a relative branch offset. The label is associated with the absolute index of the next PcodeData object to be issued, facilitating this conversion.

Parameters
idis the given id of the label

References issued, and labels.

Referenced by ghidra::SleighBuilder::SleighBuilder().

◆ addLabelRef()

void ghidra::PcodeCacher::addLabelRef ( VarnodeData ptr)

Denote a Varnode holding a relative branch offset.

Store off a reference to the Varnode and the absolute index of the next instruction. The Varnode must be an operand of the current instruction.

Parameters
ptris the Varnode reference

References issued, and label_refs.

◆ allocateInstruction()

PcodeData* ghidra::PcodeCacher::allocateInstruction ( void  )
inline

Allocate a data object for a new p-code operation.

Returns
the new PcodeData object

References ghidra::PcodeData::invar, and ghidra::PcodeData::outvar.

◆ allocateVarnodes()

VarnodeData* ghidra::PcodeCacher::allocateVarnodes ( uint4  size)
inline

Allocate data objects for a new set of Varnodes.

Parameters
sizeis the number of objects to allocate
Returns
a pointer to the array of available VarnodeData objects

◆ emit()

void ghidra::PcodeCacher::emit ( const Address addr,
PcodeEmit emt 
) const

Pass the cached p-code data to the emitter.

Each p-code operation is presented to the emitter via its dump() method.

Parameters
addris the Address associated with the p-code operation
emtis the emitter

References ghidra::PcodeEmit::dump(), and issued.

Referenced by ghidra::Sleigh::oneInstruction().

◆ expandPool()

VarnodeData * ghidra::PcodeCacher::expandPool ( uint4  size)
private

Expand the memory pool.

Expand the VarnodeData pool so that size more elements fit, and return a pointer to first available element.

Parameters
sizeis the number of elements to expand the pool by
Returns
the first available VarnodeData

References curpool, endpool, issued, label_refs, and poolstart.

◆ resolveRelatives()

void ghidra::PcodeCacher::resolveRelatives ( void  )

Rewrite branch target Varnodes as relative offsets.

Assuming all the PcodeData has been generated for an instruction, go resolve any relative offsets and back patch their value(s) into the PcodeData

References ghidra::calc_mask(), label_refs, labels, ghidra::VarnodeData::offset, and ghidra::VarnodeData::size.

Referenced by ghidra::Sleigh::oneInstruction().


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