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:

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)
 
virtual void delaySlot (OpTpl *op)
 
virtual void setLabel (OpTpl *op)
 
virtual void appendCrossBuild (OpTpl *bld, int4 secnum)
 

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

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

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

◆ 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

◆ 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

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::CPUI_SUBPIECE.


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