|
decompiler 1.0.0
|
A class for expanding macro directives within a p-code section. More...
#include <slgh_compile.hh>
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 * > ¶ms) |
| 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. | |
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.
|
inlinevirtual |
Execute or filter a build directive in sequence.
Any recursion through build directives into ConstructTpl for sub-constructors happens here.
| bld | is the build directive, which encodes the particular sub-construction |
| secnum | is the current section number of the constructor |
Implements ghidra::PcodeBuilder.
References dump().
|
inlinevirtual |
Process or filter a crossbuild directive in sequence.
Any recursion through crossbuild directives into new instructions and sections happens here.
| bld | is the crossbuild directive |
| secnum | is the current section number being processed |
Implements ghidra::PcodeBuilder.
References dump().
|
inlinevirtual |
Execute or filter a delayslot directive in sequence.
Any recursion through delayslot directives into new instructions happens here.
| op | is the delayslot directive, which encodes the number of bytes in the particular delay slot. |
Implements ghidra::PcodeBuilder.
References dump().
|
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.
| op | is 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().
|
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.
| loc | is the parse location where the error occurred |
| val | is the error message |
References ghidra::SleighCompile::reportError().
|
virtual |
Process or filter a label in sequence.
The builder has the opportunity to record exactly where in sequence the given label occurs.
| op | is 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().
| void ghidra::MacroBuilder::setMacroOp | ( | OpTpl * | macroop | ) |
Establish the MACRO directive to expand.
Given the op corresponding to the invocation, set up the specific parameters.
| macroop | is the given MACRO directive op |
References ghidra::OpTpl::getIn(), and ghidra::OpTpl::numInput().
Referenced by ghidra::SleighCompile::expandMacros().
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.
| op | is the cloned op to emit |
| params | is the set of parameters specific to the macro invocation |
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().