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

A container for disassembly context used by the SLEIGH engine. More...

#include <sleigh.hh>

Public Member Functions

 DisassemblyCache (Translate *trans, ContextCache *ccache, AddrSpace *cspace, int4 cachesize, int4 windowsize)
 Constructor. More...
 
 ~DisassemblyCache (void)
 Destructor.
 
ParserContext * getParserContext (const Address &addr)
 Get the parser for a particular Address. More...
 

Private Member Functions

void initialize (int4 min, int4 hashsize)
 Initialize the hash-table of ParserContexts. More...
 
void free (void)
 Free the hash-table of ParserContexts.
 

Private Attributes

Translatetranslate
 The Translate object that owns this cache.
 
ContextCachecontextcache
 Cached values from the ContextDatabase.
 
AddrSpaceconstspace
 The constant address space.
 
int4 minimumreuse
 Can call getParserContext this many times, before a ParserContext is reused.
 
uint4 mask
 Size of the hashtable in form 2^n-1.
 
ParserContext ** list
 (circular) array of currently cached ParserContext objects
 
int4 nextfree
 Current end/beginning of circular list.
 
ParserContext ** hashtable
 Hashtable for looking up ParserContext via Address.
 

Detailed Description

A container for disassembly context used by the SLEIGH engine.

This acts as a factor for the ParserContext objects which are used to disassemble a single instruction. These all share a ContextCache which is a front end for accessing the ContextDatabase and resolving context variables from the SLEIGH spec. ParserContext objects are stored in a hash-table keyed by the address of the instruction.

Constructor & Destructor Documentation

◆ DisassemblyCache()

ghidra::DisassemblyCache::DisassemblyCache ( Translate trans,
ContextCache ccache,
AddrSpace cspace,
int4  cachesize,
int4  windowsize 
)

Constructor.

Parameters
transis the Translate object instantiating this cache (for inst_next2 callbacks)
ccacheis the ContextCache front-end shared across all the parser contexts
cspaceis the constant address space used for minting constant Varnodes
cachesizeis the number of distinct ParserContext objects in this cache
windowsizeis the size of the ParserContext hash-table

Member Function Documentation

◆ getParserContext()

ParserContext * ghidra::DisassemblyCache::getParserContext ( const Address addr)

Get the parser for a particular Address.

Return a (possibly cached) ParserContext that is associated with addr If n different calls to this interface are made with n different Addresses, if

  • n <= minimumreuse AND
  • all the addresses are within the windowsize (=mask+1)

then the cacher guarantees that you get all different ParserContext objects

Parameters
addris the Address to disassemble at
Returns
the ParserContext associated with the address

References ghidra::Address::getOffset().

Referenced by ghidra::Sleigh::obtainContext(), and ghidra::SleighBuilder::SleighBuilder().

◆ initialize()

void ghidra::DisassemblyCache::initialize ( int4  min,
int4  hashsize 
)
private

Initialize the hash-table of ParserContexts.

Parameters
minis the minimum number of allocations before a reuse is expected
hashsizeis the number of elements in the hash-table

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