decompiler
1.0.0
|
Class for caching a chunk of p-code, prior to emitting. More...
#include <sleigh.hh>
Public Member Functions | |
PcodeCacher (void) | |
Constructor. | |
~PcodeCacher (void) | |
Destructor. | |
VarnodeData * | allocateVarnodes (uint4 size) |
Allocate data objects for a new set of Varnodes. More... | |
PcodeData * | allocateInstruction (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 | |
VarnodeData * | expandPool (uint4 size) |
Expand the memory pool. More... | |
Private Attributes | |
VarnodeData * | poolstart |
Start of the pool of VarnodeData objects. | |
VarnodeData * | curpool |
First unused VarnodeData. | |
VarnodeData * | endpool |
End of the pool of VarnodeData objects. | |
vector< PcodeData > | issued |
P-code ops issued for the current instruction. | |
list< RelativeRecord > | label_refs |
References to labels. | |
vector< uintb > | labels |
Locations of labels. | |
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.
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.
id | is the given id of the label |
References issued, and labels.
Referenced by ghidra::SleighBuilder::SleighBuilder().
void ghidra::PcodeCacher::addLabelRef | ( | VarnodeData * | ptr | ) |
|
inline |
Allocate a data object for a new p-code operation.
References ghidra::PcodeData::invar, and ghidra::PcodeData::outvar.
|
inline |
Allocate data objects for a new set of Varnodes.
size | is the number of objects to allocate |
Pass the cached p-code data to the emitter.
Each p-code operation is presented to the emitter via its dump() method.
addr | is the Address associated with the p-code operation |
emt | is the emitter |
References ghidra::PcodeEmit::dump(), and issued.
Referenced by ghidra::Sleigh::oneInstruction().
|
private |
Expand the memory pool.
Expand the VarnodeData pool so that size more elements fit, and return a pointer to first available element.
size | is the number of elements to expand the pool by |
References curpool, endpool, issued, label_refs, and poolstart.
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().