Ghidra Decompiler Analysis Engine
Public Member Functions | List of all members
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...
 

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 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

◆ addLabelRef()

void 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

◆ allocateInstruction()

PcodeData* PcodeCacher::allocateInstruction ( void  )
inline

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

Returns
the new PcodeData object

◆ allocateVarnodes()

VarnodeData* 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 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

◆ resolveRelatives()

void 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


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