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

A class for expanding macro directives within a p-code section. More...

#include <slgh_compile.hh>

Inheritance diagram for ghidra::MacroBuilder:
ghidra::PcodeBuilder

Public Member Functions

 MacroBuilder (SleighCompile *sl, vector< OpTpl * > &ovec, uint4 lbcnt)
 Constructor.
 
void setMacroOp (OpTpl *macroop)
 Establish the MACRO directive to expand. More...
 
bool hasError (void) const
 Return true if there were errors during expansion.
 
virtual void appendBuild (OpTpl *bld, int4 secnum)
 Execute or filter a build directive in sequence. More...
 
virtual void delaySlot (OpTpl *op)
 Execute or filter a delayslot directive in sequence. More...
 
virtual void setLabel (OpTpl *op)
 Process or filter a label in sequence. More...
 
virtual void appendCrossBuild (OpTpl *bld, int4 secnum)
 Process or filter a crossbuild directive in sequence. More...
 
- Public Member Functions inherited from ghidra::PcodeBuilder
 PcodeBuilder (uint4 lbcnt)
 Construct with a starting label index.
 
virtual ~PcodeBuilder (void)
 Destructor.
 
uint4 getLabelBase (void) const
 Get the starting label index for this builder.
 
ParserWalker * getCurrentWalker () const
 Get the current instruction context.
 
void build (ConstructTpl *construct, int4 secnum)
 Build the semantics for the given constructor. More...
 
virtual void appendBuild (OpTpl *bld, int4 secnum)=0
 Execute or filter a build directive in sequence. More...
 
virtual void delaySlot (OpTpl *op)=0
 Execute or filter a delayslot directive in sequence. More...
 
virtual void setLabel (OpTpl *op)=0
 Process or filter a label in sequence. More...
 
virtual void appendCrossBuild (OpTpl *bld, int4 secnum)=0
 Process or filter a crossbuild directive in sequence. More...
 

Private Member Functions

bool transferOp (OpTpl *op, vector< HandleTpl * > &params)
 Given a cloned OpTpl, substitute parameters and add to the output list. More...
 
virtual void dump (OpTpl *op)
 Output/build the given p-code operation. More...
 
void free (void)
 Free resources used by the builder.
 
void reportError (const Location *loc, const string &val)
 Report error encountered expanding the macro. More...
 

Private Attributes

SleighCompile * slgh
 The SLEIGH parsing object.
 
bool haserror
 Set to true by the build() method if there was an error.
 
vector< OpTpl * > & outvec
 The partial list of op templates to expand the macro into.
 
vector< HandleTpl * > params
 List of parameters to substitute into the macro.
 

Additional Inherited Members

virtual void dump (OpTpl *op)=0
 Output/build the given p-code operation. More...
 
- Protected Attributes inherited from ghidra::PcodeBuilder
ParserWalker * walker
 Current instruction context.
 

Detailed Description

A class for expanding macro directives within a p-code section.

It is handed a (partial) list of p-code op templates (OpTpl). The macro directive is established with the setMacroOp() method. Then calling build() expands the macro into the list of OpTpls, providing parameter substitution. The class is derived from PcodeBuilder, where the dump() method, instead of emitting raw p-code, clones the macro templates into the list of OpTpls.

Member Function Documentation

◆ appendBuild()

virtual void ghidra::MacroBuilder::appendBuild ( OpTpl *  bld,
int4  secnum 
)
inlinevirtual

Execute or filter a build directive in sequence.

Any recursion through build directives into ConstructTpl for sub-constructors happens here.

Parameters
bldis the build directive, which encodes the particular sub-construction
secnumis the current section number of the constructor

Implements ghidra::PcodeBuilder.

References dump().

◆ appendCrossBuild()

virtual void ghidra::MacroBuilder::appendCrossBuild ( OpTpl *  bld,
int4  secnum 
)
inlinevirtual

Process or filter a crossbuild directive in sequence.

Any recursion through crossbuild directives into new instructions and sections happens here.

Parameters
bldis the crossbuild directive
secnumis the current section number being processed

Implements ghidra::PcodeBuilder.

References dump().

◆ delaySlot()

virtual void ghidra::MacroBuilder::delaySlot ( OpTpl *  op)
inlinevirtual

Execute or filter a delayslot directive in sequence.

Any recursion through delayslot directives into new instructions happens here.

Parameters
opis the delayslot directive, which encodes the number of bytes in the particular delay slot.

Implements ghidra::PcodeBuilder.

References dump().

◆ dump()

void ghidra::MacroBuilder::dump ( OpTpl *  op)
privatevirtual

Output/build the given p-code operation.

This is the main hook point for different p-code generation strategies. It is called once, in sequence, for each p-code operation generated for a specific instruction. Directives and labels have had the opportunity to be expanded or filtered by other methods.

Parameters
opis the p-code operation to process

Implements ghidra::PcodeBuilder.

References ghidra::OpTpl::addInput(), ghidra::OpTpl::getIn(), ghidra::VarnodeTpl::getOffset(), ghidra::OpTpl::getOpcode(), ghidra::OpTpl::getOut(), ghidra::ConstTpl::getReal(), ghidra::VarnodeTpl::isRelative(), ghidra::OpTpl::numInput(), ghidra::OpTpl::setOutput(), and ghidra::VarnodeTpl::setRelative().

Referenced by appendBuild(), appendCrossBuild(), and delaySlot().

◆ reportError()

void ghidra::MacroBuilder::reportError ( const Location *  loc,
const string &  val 
)
private

Report error encountered expanding the macro.

The error is passed up to the main parse object and a note is made locally that an error occurred so parsing can be terminated immediately.

Parameters
locis the parse location where the error occurred
valis the error message

References ghidra::SleighCompile::reportError().

◆ setLabel()

void ghidra::MacroBuilder::setLabel ( OpTpl *  op)
virtual

Process or filter a label in sequence.

The builder has the opportunity to record exactly where in sequence the given label occurs.

Parameters
opis the OpTpl encoding the label index

Implements ghidra::PcodeBuilder.

References ghidra::OpTpl::addInput(), ghidra::OpTpl::getIn(), ghidra::VarnodeTpl::getOffset(), ghidra::OpTpl::getOpcode(), ghidra::ConstTpl::getReal(), and ghidra::VarnodeTpl::setOffset().

◆ setMacroOp()

void ghidra::MacroBuilder::setMacroOp ( OpTpl *  macroop)

Establish the MACRO directive to expand.

Given the op corresponding to the invocation, set up the specific parameters.

Parameters
macroopis the given MACRO directive op

References ghidra::OpTpl::getIn(), and ghidra::OpTpl::numInput().

Referenced by ghidra::SleighCompile::expandMacros().

◆ transferOp()

bool ghidra::MacroBuilder::transferOp ( OpTpl *  op,
vector< HandleTpl * > &  params 
)
private

Given a cloned OpTpl, substitute parameters and add to the output list.

VarnodesTpls used by the op are examined to see if they are derived from parameters of the macro. If so, details of the parameters actively passed as part of the specific macro invocation are substituted into the VarnodeTpl. Truncation operations on a macro parameter may cause additional CPUI_SUBPIECE operators to be inserted as part of the expansion and certain forms are not permitted.

Parameters
opis the cloned op to emit
paramsis the set of parameters specific to the macro invocation
Returns
true if there are no illegal truncations

References ghidra::OpTpl::addInput(), ghidra::CPUI_SUBPIECE, ghidra::AddrSpaceManager::getConstantSpace(), ghidra::ConstTpl::getHandleIndex(), ghidra::OpTpl::getIn(), ghidra::VarnodeTpl::getOffset(), ghidra::OpTpl::getOut(), ghidra::HandleTpl::getPtrOffset(), ghidra::ConstTpl::getReal(), ghidra::VarnodeTpl::getSize(), ghidra::HandleTpl::getSize(), ghidra::HandleTpl::getSpace(), ghidra::ConstTpl::getType(), ghidra::SleighCompile::getUniqueAddr(), ghidra::AddrSpaceManager::getUniqueSpace(), ghidra::ConstTpl::handle, ghidra::OpTpl::numInput(), ghidra::ConstTpl::real, ghidra::OpTpl::setInput(), ghidra::OpTpl::setOutput(), and ghidra::VarnodeTpl::transfer().


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