decompiler 1.0.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ghidra::PcodeCompile Class Referenceabstract

The base class for compiling p-code expressions from SLEIGH syntax. More...

#include <pcodecompile.hh>

Inheritance diagram for ghidra::PcodeCompile:
ghidra::SleighPcode

Public Member Functions

 PcodeCompile (void)
 Constructor.
 
virtual ~PcodeCompile (void)
 Destructor.
 
virtual const Location * getLocation (SleighSymbol *sym) const =0
 Get the parse location associated with the given symbol. More...
 
virtual void reportError (const Location *loc, const string &msg)=0
 Report a fatal error in parsing. More...
 
virtual void reportWarning (const Location *loc, const string &msg)=0
 Report a non-fatal issue encountered during parsing. More...
 
void resetLabelCount (void)
 Reset labels. The next label generated will have id 0.
 
void setDefaultSpace (AddrSpace *spc)
 Set the SLEIGH default address space.
 
void setConstantSpace (AddrSpace *spc)
 Set the SLEIGH constant address space.
 
void setUniqueSpace (AddrSpace *spc)
 Set the SLEIGH unique address space.
 
void setEnforceLocalKey (bool val)
 Toggle whether use of the 'local' key is enforced.
 
AddrSpace * getDefaultSpace (void) const
 Get the default address space.
 
AddrSpace * getConstantSpace (void) const
 Get the constant address space.
 
VarnodeTpl * buildTemporary (void)
 Create a temporary register (with 0 size) More...
 
LabelSymbol * defineLabel (string *name)
 Create a SLEIGH label symbol. More...
 
vector< OpTpl * > * placeLabel (LabelSymbol *sym)
 Create a raw expression containing the given label. More...
 
vector< OpTpl * > * newOutput (bool usesLocalKey, ExprTree *rhs, string *varname, uint4 size=0)
 Create a new output VarnodeTpl for an expression. More...
 
void newLocalDefinition (string *varname, uint4 size=0)
 Create a new temporary symbol (without generating any p-code) More...
 
ExprTree * createOp (OpCode opc, ExprTree *vn)
 Add a new unary operation to the given expression. More...
 
ExprTree * createOp (OpCode opc, ExprTree *vn1, ExprTree *vn2)
 Create a new binary operation combining the given expressions. More...
 
ExprTree * createOpOut (VarnodeTpl *outvn, OpCode opc, ExprTree *vn1, ExprTree *vn2)
 Create a new binary operation combining the given input expressions and an explicit output VarnodeTpl. More...
 
ExprTree * createOpOutUnary (VarnodeTpl *outvn, OpCode opc, ExprTree *vn)
 Create a new unary operation with the given expression as input and an explicit output VarnodeTpl. More...
 
vector< OpTpl * > * createOpNoOut (OpCode opc, ExprTree *vn)
 Create a new unary operation with the given expression as input and no output. More...
 
vector< OpTpl * > * createOpNoOut (OpCode opc, ExprTree *vn1, ExprTree *vn2)
 Create a new binary operation with the given expressions as input and no output. More...
 
vector< OpTpl * > * createOpConst (OpCode opc, uintb val)
 Create a new unary operation with the given constant as input and no output. More...
 
ExprTree * createLoad (StarQuality *qual, ExprTree *ptr)
 Create a new LOAD operation with the given pointer expression as input. More...
 
vector< OpTpl * > * createStore (StarQuality *qual, ExprTree *ptr, ExprTree *val)
 Create a new STORE operation with the given expressions as inputs. More...
 
ExprTree * createUserOp (UserOpSymbol *sym, vector< ExprTree * > *param)
 Create a CALLOTHER p-code op with temporary output, given a symbol and parameter expressions. More...
 
vector< OpTpl * > * createUserOpNoOut (UserOpSymbol *sym, vector< ExprTree * > *param)
 Create a CALLOTHER p-code op, given a symbol and parameter expressions. More...
 
ExprTree * createVariadic (OpCode opc, vector< ExprTree * > *param)
 Create a new operation with a variable number of inputs and a temporary output. More...
 
void appendOp (OpCode opc, ExprTree *res, uintb constval, int4 constsz)
 Append a binary operation to the given expression. More...
 
VarnodeTpl * buildTruncatedVarnode (VarnodeTpl *basevn, uint4 bitoffset, uint4 numbits)
 Build a truncated VarnodeTpl, if possible, from the given bit range. More...
 
vector< OpTpl * > * assignBitRange (VarnodeTpl *vn, uint4 bitoffset, uint4 numbits, ExprTree *rhs)
 Assign an expression to a bit range within a given VarnodeTpl. More...
 
ExprTree * createBitRange (SpecificSymbol *sym, uint4 bitoffset, uint4 numbits)
 Create an expression computing the indicated bit range of a symbol. More...
 
VarnodeTpl * addressOf (VarnodeTpl *var, uint4 size)
 Produce a constant VarnodeTpl that is the offset of the storage address of the given VarnodeTpl. More...
 

Static Public Member Functions

static void force_size (VarnodeTpl *vt, const ConstTpl &size, const vector< OpTpl * > &ops)
 Force a size on a specific VarnodeTpl if possible. More...
 
static void matchSize (int4 j, OpTpl *op, bool inputonly, const vector< OpTpl * > &ops)
 Try to propagate a known size across a p-code operation to zero size inputs and outputs. More...
 
static void fillinZero (OpTpl *op, const vector< OpTpl * > &ops)
 Try to deduce the size of all input and output VarnodeTpl for the given OpTpl. More...
 
static bool propagateSize (ConstructTpl *ct)
 Propagate a size to all VarnodeTpl whose size is unknown. More...
 

Private Member Functions

virtual uint4 allocateTemp (void)=0
 Get the offset for the next available temporary register. More...
 
virtual void addSymbol (SleighSymbol *sym)=0
 Add a new symbol to the current scope. More...
 

Private Attributes

AddrSpace * defaultspace
 SLEIGH's default address space.
 
AddrSpace * constantspace
 SLEIGH's constant address space.
 
AddrSpace * uniqspace
 SLEIGH's unique address space.
 
uint4 local_labelcount
 Number of labels in current constructor.
 
bool enforceLocalKey
 If true, force specification to use 'local' keyword when defining temporary varnodes.
 

Detailed Description

The base class for compiling p-code expressions from SLEIGH syntax.

This is essentially a utility class for building OpTpl, VarnodeTpl, and their associated expressions. Address spaces must be provided via the setXXXSpace() methods, so that the class can model the corresponding SLEIGH concepts.

Member Function Documentation

◆ addressOf()

VarnodeTpl * ghidra::PcodeCompile::addressOf ( VarnodeTpl *  var,
uint4  size 
)

Produce a constant VarnodeTpl that is the offset of the storage address of the given VarnodeTpl.

Parameters
varis the given VarnodeTpl to take the address of
sizeis the size of the resulting pointer constant (may be 0)
Returns
the new constant VarnodeTpl

References ghidra::AddrSpace::byteToAddress(), constantspace, ghidra::AddrSpace::getAddrSize(), ghidra::VarnodeTpl::getOffset(), ghidra::ConstTpl::getReal(), ghidra::ConstTpl::getSpace(), ghidra::VarnodeTpl::getSpace(), ghidra::ConstTpl::getType(), ghidra::AddrSpace::getWordSize(), ghidra::ConstTpl::real, and ghidra::ConstTpl::spaceid.

◆ addSymbol()

virtual void ghidra::PcodeCompile::addSymbol ( SleighSymbol *  sym)
privatepure virtual

Add a new symbol to the current scope.

Parameters
symis the symbol being added

Implemented in ghidra::SleighPcode.

Referenced by defineLabel(), newLocalDefinition(), and newOutput().

◆ allocateTemp()

virtual uint4 ghidra::PcodeCompile::allocateTemp ( void  )
privatepure virtual

Get the offset for the next available temporary register.

A fixed number of bytes in the unique space is consumed.

Returns
the reserved offset

Implemented in ghidra::SleighPcode.

Referenced by buildTemporary(), and newLocalDefinition().

◆ appendOp()

void ghidra::PcodeCompile::appendOp ( OpCode  opc,
ExprTree *  res,
uintb  constval,
int4  constsz 
)

Append a binary operation to the given expression.

A new operation is appended to the end of the expression. The root VarnodeTpl of the expression becomes the first input to the operation. The given constant value and size becomes the second input.

Parameters
opcis the binary operation code
resis the expression being modified and the first input
constvalis the second input value
constszis the second input size

References ghidra::OpTpl::addInput(), buildTemporary(), constantspace, ghidra::ExprTree::ops, ghidra::ExprTree::outvn, ghidra::ConstTpl::real, and ghidra::OpTpl::setOutput().

Referenced by assignBitRange(), and createBitRange().

◆ assignBitRange()

vector< OpTpl * > * ghidra::PcodeCompile::assignBitRange ( VarnodeTpl *  vn,
uint4  bitoffset,
uint4  numbits,
ExprTree *  rhs 
)

Assign an expression to a bit range within a given VarnodeTpl.

Other bits of the VarnodeTpl are preserved. The value assigned is taken from the root VarnodeTpl of the expression, which is assumed to have zero bits in any position greater than or equal to numbits. If the bit range falls on byte boundaries, the assignment is accomplished with byte based truncation operations. Otherwise mask and shift operations (INT_AND, INT_OR, and INT_LEFT) are used.

Parameters
vnis the given VarnodeTpl being assigned to
bitoffsetis the starting bit of the range (0 indicates the least significant bit)
numbitsis the number of bits in the range
rhsis the expression being assigned
Returns
a new combined expression as a raw array

References appendOp(), buildTruncatedVarnode(), ghidra::CPUI_COPY, ghidra::CPUI_INT_AND, ghidra::CPUI_INT_LEFT, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_ZEXT, createOp(), createOpOut(), createOpOutUnary(), force_size(), ghidra::ConstTpl::getReal(), ghidra::VarnodeTpl::getSize(), ghidra::ConstTpl::getType(), ghidra::ExprTree::ops, ghidra::ExprTree::outvn, ghidra::ConstTpl::real, and reportError().

◆ buildTemporary()

VarnodeTpl * ghidra::PcodeCompile::buildTemporary ( void  )

Create a temporary register (with 0 size)

Space for the register is allocated in the unique address space.

Returns
the new temporary register

References allocateTemp(), ghidra::ConstTpl::real, ghidra::VarnodeTpl::setUnnamed(), and uniqspace.

Referenced by appendOp(), createLoad(), createOp(), createUserOp(), createVariadic(), and newOutput().

◆ buildTruncatedVarnode()

VarnodeTpl * ghidra::PcodeCompile::buildTruncatedVarnode ( VarnodeTpl *  basevn,
uint4  bitoffset,
uint4  numbits 
)

Build a truncated VarnodeTpl, if possible, from the given bit range.

The bit range must be on byte boundaries or NULL is returned. The VarnodeTpl being must already have fixed dimensions or be a handle. For a handle, the truncation is built using ConstTpl::v_offset_plus mechanics, allowing the truncation for exported values to be computed in the context of a specific instruction.

Parameters
basevnis the VarnodeTpl to be truncated
bitoffsetis the starting bit of the range (0 indicates the least significant bit)
numbitsis the number of bits in the range
Returns
the truncated VarnodeTpl (or NULL)

References defaultspace, ghidra::ConstTpl::getHandleIndex(), ghidra::VarnodeTpl::getOffset(), ghidra::ConstTpl::getReal(), ghidra::VarnodeTpl::getSize(), ghidra::VarnodeTpl::getSpace(), ghidra::ConstTpl::getType(), ghidra::ConstTpl::handle, ghidra::AddrSpace::isBigEndian(), ghidra::ConstTpl::real, and ghidra::ConstTpl::v_offset_plus.

Referenced by assignBitRange(), and createBitRange().

◆ createBitRange()

ExprTree * ghidra::PcodeCompile::createBitRange ( SpecificSymbol *  sym,
uint4  bitoffset,
uint4  numbits 
)

Create an expression computing the indicated bit range of a symbol.

The result is truncated to the smallest byte size that can contain the indicated number of bits, with the desired bits shifted into the least significant positions. If the bit range is on byte boundaries, the truncation is accomplished with byte based truncation operations. Otherwise masks and shifts (INT_AND and INT_RIGHT) are used.

Parameters
symis the symbol representing the VarnodeTpl to truncate
bitoffsetis the starting bit of the range (0 indicates the least significant bit)
numbitsis the number of bits in the range
Returns
a new expression whose root VarnodeTpl holds the result

References appendOp(), buildTruncatedVarnode(), ghidra::CPUI_INT_AND, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_SUBPIECE, force_size(), getLocation(), ghidra::ConstTpl::getReal(), ghidra::VarnodeTpl::getSize(), ghidra::VarnodeTpl::getSpace(), ghidra::ConstTpl::getType(), ghidra::ConstTpl::handle, ghidra::VarnodeTpl::isZeroSize(), ghidra::ExprTree::ops, ghidra::ExprTree::outvn, ghidra::ConstTpl::real, reportError(), and ghidra::VarnodeTpl::setSize().

◆ createLoad()

ExprTree * ghidra::PcodeCompile::createLoad ( StarQuality *  qual,
ExprTree *  ptr 
)

Create a new LOAD operation with the given pointer expression as input.

A new expression is created ending in a LOAD operation. The input pointer is the root VarnodeTpl of the given expression. The output is a new temporary register.

Parameters
qualprovides the address space and any knowledge of the size being LOADed
ptris the given pointer expression
Returns
the new expression

References ghidra::OpTpl::addInput(), buildTemporary(), constantspace, ghidra::CPUI_LOAD, force_size(), ghidra::StarQuality::id, ghidra::ExprTree::ops, ghidra::ExprTree::outvn, ghidra::ConstTpl::real, ghidra::OpTpl::setOutput(), and ghidra::StarQuality::size.

◆ createOp() [1/2]

ExprTree * ghidra::PcodeCompile::createOp ( OpCode  opc,
ExprTree *  vn 
)

Add a new unary operation to the given expression.

A new expression is created ending in a unary operation. The input to the operation is the root VarnodeTpl of the given expression, and the output is a new temporary register.

Parameters
opcis the unary operation code
vnis the given input expression
Returns
the new expression

References ghidra::OpTpl::addInput(), buildTemporary(), ghidra::ExprTree::ops, ghidra::ExprTree::outvn, and ghidra::OpTpl::setOutput().

Referenced by assignBitRange().

◆ createOp() [2/2]

ExprTree * ghidra::PcodeCompile::createOp ( OpCode  opc,
ExprTree *  vn1,
ExprTree *  vn2 
)

Create a new binary operation combining the given expressions.

A new expression is created ending in a binary operation. Inputs to the operation are the root VarnodeTpl from the two given expressions, and the output is a new temporary register.

Parameters
opcis the binary operation code
vn1is the first input expression
vn2is the second input expression
Returns
the new combined expression

References ghidra::OpTpl::addInput(), buildTemporary(), ghidra::ExprTree::ops, ghidra::ExprTree::outvn, and ghidra::OpTpl::setOutput().

◆ createOpConst()

vector< OpTpl * > * ghidra::PcodeCompile::createOpConst ( OpCode  opc,
uintb  val 
)

Create a new unary operation with the given constant as input and no output.

A new expression is created ending in a unary operation. A new constant VarnodeTpl is created as input.

Parameters
opcis the unary operation code
valis the constant value of the input
Returns
the new expression as a raw array

References ghidra::OpTpl::addInput(), constantspace, and ghidra::ConstTpl::real.

◆ createOpNoOut() [1/2]

vector< OpTpl * > * ghidra::PcodeCompile::createOpNoOut ( OpCode  opc,
ExprTree *  vn 
)

Create a new unary operation with the given expression as input and no output.

A new expression is created ending in a unary operation. The input to the operation is the root VarnodeTpl of the given expression.

Parameters
opcis the unary operation code
vnis the input expression
Returns
the new combined expression as raw array

References ghidra::OpTpl::addInput(), ghidra::ExprTree::ops, and ghidra::ExprTree::outvn.

◆ createOpNoOut() [2/2]

vector< OpTpl * > * ghidra::PcodeCompile::createOpNoOut ( OpCode  opc,
ExprTree *  vn1,
ExprTree *  vn2 
)

Create a new binary operation with the given expressions as input and no output.

A new expression is created ending in a binary operation. Inputs are the root VarnodeTpl of the given expressions.

Parameters
opcis the binary operation code
vn1is the first input expression
vn2is the second input expression
Returns
the new combined expression as a raw array

References ghidra::OpTpl::addInput(), ghidra::ExprTree::ops, and ghidra::ExprTree::outvn.

◆ createOpOut()

ExprTree * ghidra::PcodeCompile::createOpOut ( VarnodeTpl *  outvn,
OpCode  opc,
ExprTree *  vn1,
ExprTree *  vn2 
)

Create a new binary operation combining the given input expressions and an explicit output VarnodeTpl.

A new expression is created ending in a binary operation. Inputs are the root VarnodeTpl from the two given expressions.

Parameters
outvnis the explicit output of the new operation
opcis the binary operation code
vn1is the first input expression
vn2is the second input expression
Returns
the new combined expression

References ghidra::OpTpl::addInput(), ghidra::ExprTree::ops, ghidra::ExprTree::outvn, and ghidra::OpTpl::setOutput().

Referenced by assignBitRange().

◆ createOpOutUnary()

ExprTree * ghidra::PcodeCompile::createOpOutUnary ( VarnodeTpl *  outvn,
OpCode  opc,
ExprTree *  vn 
)

Create a new unary operation with the given expression as input and an explicit output VarnodeTpl.

A new expression is created ending in a unary operation. The input to the operation is the root VarnodeTpl of the given expression.

Parameters
outvnis the explicit output of the new operation
opcis the unary operation code
vnis the input expression
Returns
the new combined expression

References ghidra::OpTpl::addInput(), ghidra::ExprTree::ops, ghidra::ExprTree::outvn, and ghidra::OpTpl::setOutput().

Referenced by assignBitRange().

◆ createStore()

vector< OpTpl * > * ghidra::PcodeCompile::createStore ( StarQuality *  qual,
ExprTree *  ptr,
ExprTree *  val 
)

Create a new STORE operation with the given expressions as inputs.

A new expression is created ending in a STORE operation. The inputs are the root VarnodeTpl of the given expressions.

Parameters
qualprovides the address space and any knowledge of the size being STOREed
ptris the pointer expression
valis the value being STOREd
Returns
the new expression as a raw array

References ghidra::OpTpl::addInput(), constantspace, ghidra::CPUI_STORE, force_size(), ghidra::StarQuality::id, ghidra::ExprTree::ops, ghidra::ExprTree::outvn, ghidra::ConstTpl::real, and ghidra::StarQuality::size.

◆ createUserOp()

ExprTree * ghidra::PcodeCompile::createUserOp ( UserOpSymbol *  sym,
vector< ExprTree * > *  param 
)

Create a CALLOTHER p-code op with temporary output, given a symbol and parameter expressions.

A new expression is created ending in a CALLOTHER operation. Inputs are the root VarnodeTpl from the given array of expressions. The output is a new temporary register.

Parameters
symis the symbol to associate with CALLOTHER
paramis the array of input expressions
Returns
the new combined expression

References buildTemporary(), createUserOpNoOut(), ghidra::ExprTree::ops, and ghidra::ExprTree::outvn.

◆ createUserOpNoOut()

vector< OpTpl * > * ghidra::PcodeCompile::createUserOpNoOut ( UserOpSymbol *  sym,
vector< ExprTree * > *  param 
)

Create a CALLOTHER p-code op, given a symbol and parameter expressions.

A new expression is created ending in a CALLOTHER operation, with no output. Inputs are the root VarnodeTpl from the given array of expressions.

Parameters
symis the symbol to associate with the CALLOTHER
paramis the array of input expressions
Returns
the new combined expression as a raw array

References ghidra::OpTpl::addInput(), ghidra::ExprTree::appendParams(), constantspace, ghidra::CPUI_CALLOTHER, and ghidra::ConstTpl::real.

Referenced by createUserOp().

◆ createVariadic()

ExprTree * ghidra::PcodeCompile::createVariadic ( OpCode  opc,
vector< ExprTree * > *  param 
)

Create a new operation with a variable number of inputs and a temporary output.

A new expression is created ending in the new operation. Inputs are the root VarnodeTpl from the given array of expressions. The output is a new temporary register.

Parameters
opcis the variadic operation code
paramis the array of input expressions
Returns
the new combined expression

References ghidra::ExprTree::appendParams(), buildTemporary(), ghidra::ExprTree::ops, and ghidra::ExprTree::outvn.

◆ defineLabel()

LabelSymbol * ghidra::PcodeCompile::defineLabel ( string *  name)

Create a SLEIGH label symbol.

The parsed name and the next available id are assigned to the label. The symbol is assigned to the current scope.

Parameters
nameis the parsed name of the label
Returns
the new symbol

References addSymbol(), and local_labelcount.

◆ fillinZero()

void ghidra::PcodeCompile::fillinZero ( OpTpl *  op,
const vector< OpTpl * > &  ops 
)
static

Try to deduce the size of all input and output VarnodeTpl for the given OpTpl.

For any VarnodeTpl whose size is not known (isZeroSize() returns true), an attempt is made to fill in the size from another input or output of the OpTpl.

Parameters
opis the given OpTpl
opsis the complete set of OpTpl in the expression/constructor

References ghidra::CPUI_BOOL_AND, ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_BOOL_OR, ghidra::CPUI_BOOL_XOR, ghidra::CPUI_COPY, ghidra::CPUI_CPOOLREF, ghidra::CPUI_FLOAT_ABS, ghidra::CPUI_FLOAT_ADD, ghidra::CPUI_FLOAT_CEIL, ghidra::CPUI_FLOAT_DIV, ghidra::CPUI_FLOAT_EQUAL, ghidra::CPUI_FLOAT_FLOOR, ghidra::CPUI_FLOAT_LESS, ghidra::CPUI_FLOAT_LESSEQUAL, ghidra::CPUI_FLOAT_MULT, ghidra::CPUI_FLOAT_NAN, ghidra::CPUI_FLOAT_NEG, ghidra::CPUI_FLOAT_NOTEQUAL, ghidra::CPUI_FLOAT_ROUND, ghidra::CPUI_FLOAT_SQRT, ghidra::CPUI_FLOAT_SUB, ghidra::CPUI_INT_2COMP, ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_AND, ghidra::CPUI_INT_CARRY, ghidra::CPUI_INT_DIV, ghidra::CPUI_INT_EQUAL, ghidra::CPUI_INT_LEFT, ghidra::CPUI_INT_LESS, ghidra::CPUI_INT_LESSEQUAL, ghidra::CPUI_INT_MULT, ghidra::CPUI_INT_NEGATE, ghidra::CPUI_INT_NOTEQUAL, ghidra::CPUI_INT_OR, ghidra::CPUI_INT_REM, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_SBORROW, ghidra::CPUI_INT_SCARRY, ghidra::CPUI_INT_SDIV, ghidra::CPUI_INT_SLESS, ghidra::CPUI_INT_SLESSEQUAL, ghidra::CPUI_INT_SREM, ghidra::CPUI_INT_SRIGHT, ghidra::CPUI_INT_SUB, ghidra::CPUI_INT_XOR, ghidra::CPUI_SUBPIECE, force_size(), ghidra::OpTpl::getIn(), ghidra::OpTpl::getOpcode(), ghidra::OpTpl::getOut(), ghidra::VarnodeTpl::getSize(), ghidra::VarnodeTpl::isZeroSize(), matchSize(), ghidra::OpTpl::numInput(), and ghidra::ConstTpl::real.

Referenced by propagateSize().

◆ force_size()

void ghidra::PcodeCompile::force_size ( VarnodeTpl *  vt,
const ConstTpl &  size,
const vector< OpTpl * > &  ops 
)
static

Force a size on a specific VarnodeTpl if possible.

If the VarnodeTpl already has a fixed size, this method does nothing. If the VarnodeTpl is a temporary register then all other temporaries with the same offset in the same expression are also adjusted.

Parameters
vtis the specific VarnodeTpl to adjust
sizeis the size constant to assign
opsis the array of OpTpl in the expression

References ghidra::OpTpl::getIn(), ghidra::VarnodeTpl::getOffset(), ghidra::OpTpl::getOut(), ghidra::ConstTpl::getReal(), ghidra::VarnodeTpl::getSize(), ghidra::ConstTpl::getType(), ghidra::VarnodeTpl::isLocalTemp(), ghidra::OpTpl::numInput(), ghidra::ConstTpl::real, and ghidra::VarnodeTpl::setSize().

Referenced by assignBitRange(), createBitRange(), createLoad(), createStore(), fillinZero(), and matchSize().

◆ getLocation()

virtual const Location * ghidra::PcodeCompile::getLocation ( SleighSymbol *  sym) const
pure virtual

Get the parse location associated with the given symbol.

This is generally where the symbol is first defined.

Parameters
symis the given symbol
Returns
the location if known, or NULL otherwise

Implemented in ghidra::SleighPcode.

Referenced by createBitRange(), newOutput(), and placeLabel().

◆ matchSize()

void ghidra::PcodeCompile::matchSize ( int4  j,
OpTpl *  op,
bool  inputonly,
const vector< OpTpl * > &  ops 
)
static

Try to propagate a known size across a p-code operation to zero size inputs and outputs.

If the OpTpl has an input (or output) VarnodeTpl with a know non-zero size, try to force this size onto the VarnodeTpl in the indicated slot.

Parameters
jis the slot we are trying to fill (-1=output)
opis the p-code operation to propagate the size across
inputonlyindicates, if true, whether the size propagates only between inputs of the operation.
opsis an array of all operations in the sequence

References force_size(), ghidra::OpTpl::getIn(), ghidra::OpTpl::getOut(), ghidra::VarnodeTpl::getSize(), ghidra::VarnodeTpl::isZeroSize(), and ghidra::OpTpl::numInput().

Referenced by fillinZero().

◆ newLocalDefinition()

void ghidra::PcodeCompile::newLocalDefinition ( string *  varname,
uint4  size = 0 
)

Create a new temporary symbol (without generating any p-code)

A temporary register is allocated, and the symbol is added to the current scope.

Parameters
varnameis the parsed symbol name
sizeis the size of the new register (0 indicates the size is initially unknown)

References addSymbol(), allocateTemp(), and uniqspace.

◆ newOutput()

vector< OpTpl * > * ghidra::PcodeCompile::newOutput ( bool  usesLocalKey,
ExprTree *  rhs,
string *  varname,
uint4  size = 0 
)

Create a new output VarnodeTpl for an expression.

A new named temporary register is created and assigned as the root of the given expression. A symbol representing the register is added to the current scope.

Parameters
usesLocalKeyis true if the name was defined with the 'local' keyword
rhsis the given expression
varnameis the parsed symbol name to associate with the new register
sizeis non-zero if an explicit size was provided in the parsed definition
Returns
the new expression as a raw array of OpTpl

References addSymbol(), buildTemporary(), enforceLocalKey, getLocation(), ghidra::VarnodeTpl::getOffset(), ghidra::ConstTpl::getReal(), ghidra::ExprTree::getSize(), ghidra::VarnodeTpl::getSize(), ghidra::ConstTpl::getSpace(), ghidra::VarnodeTpl::getSpace(), ghidra::ConstTpl::getType(), ghidra::ConstTpl::real, reportError(), ghidra::ExprTree::setOutput(), ghidra::VarnodeTpl::setSize(), and ghidra::ExprTree::toVector().

◆ placeLabel()

vector< OpTpl * > * ghidra::PcodeCompile::placeLabel ( LabelSymbol *  labsym)

Create a raw expression containing the given label.

A placeholder OpTpl for the label is created and returned, as an array.

Parameters
labsymis the given label
Returns
an array containing the new OpTpl

References ghidra::OpTpl::addInput(), constantspace, getLocation(), LABELBUILD, ghidra::ConstTpl::real, and reportError().

◆ propagateSize()

bool ghidra::PcodeCompile::propagateSize ( ConstructTpl *  ct)
static

Propagate a size to all VarnodeTpl whose size is unknown.

Size information is propagated across operations and expressions as far as possible. If there are any remaining VarnodeTpl whose size is unknown, return false.

Parameters
ctis the set of p-code operations to propagate across
Returns
true if all VarnodeTpl have a known size

References fillinZero(), and ghidra::ConstructTpl::getOpvec().

Referenced by ghidra::SleighCompile::buildMacro(), and ghidra::SleighCompile::finalizeSections().

◆ reportError()

virtual void ghidra::PcodeCompile::reportError ( const Location *  loc,
const string &  msg 
)
pure virtual

Report a fatal error in parsing.

Parsing may continue, but a final output is not produced.

Parameters
locis the location of the error
msgis a description of the error

Implemented in ghidra::SleighPcode.

Referenced by assignBitRange(), createBitRange(), newOutput(), and placeLabel().

◆ reportWarning()

virtual void ghidra::PcodeCompile::reportWarning ( const Location *  loc,
const string &  msg 
)
pure virtual

Report a non-fatal issue encountered during parsing.

Parameters
locis the location of the issue
msgis a description of the issue

Implemented in ghidra::SleighPcode.


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