decompiler  1.0.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
ghidra::FlowBlock Class Reference

Description of a control-flow block containing PcodeOps. More...

#include <block.hh>

Inheritance diagram for ghidra::FlowBlock:
ghidra::BlockBasic ghidra::BlockCopy ghidra::BlockGraph ghidra::BlockCondition ghidra::BlockDoWhile ghidra::BlockGoto ghidra::BlockIf ghidra::BlockInfLoop ghidra::BlockList ghidra::BlockMultiGoto ghidra::BlockSwitch ghidra::BlockWhileDo

Public Types

enum  block_type {
  t_plain, t_basic, t_graph, t_copy,
  t_goto, t_multigoto, t_ls, t_condition,
  t_if, t_whiledo, t_dowhile, t_switch,
  t_infloop
}
 The possible block types.
 
enum  block_flags {
  f_goto_goto = 1, f_break_goto = 2, f_continue_goto = 4, f_switch_out = 0x10,
  f_unstructured_targ = 0x20, f_mark = 0x80, f_mark2 = 0x100, f_entry_point = 0x200,
  f_interior_gotoout = 0x400, f_interior_gotoin = 0x800, f_label_bumpup = 0x1000, f_donothing_loop = 0x2000,
  f_dead = 0x4000, f_whiledo_overflow = 0x8000, f_flip_path = 0x10000, f_joined_block = 0x20000,
  f_duplicate_block = 0x40000
}
 Boolean properties of blocks. More...
 
enum  edge_flags {
  f_goto_edge = 1, f_loop_edge = 2, f_defaultswitch_edge = 4, f_irreducible = 8,
  f_tree_edge = 0x10, f_forward_edge = 0x20, f_cross_edge = 0x40, f_back_edge = 0x80,
  f_loop_exit_edge = 0x100
}
 Boolean properties on edges. More...
 

Public Member Functions

 FlowBlock (void)
 Construct a block with no edges.
 
virtual ~FlowBlock (void)
 Destructor.
 
int4 getIndex (void) const
 Get the index assigned to this block.
 
FlowBlockgetParent (void)
 Get the parent FlowBlock of this.
 
FlowBlockgetImmedDom (void) const
 Get the immediate dominator FlowBlock.
 
FlowBlockgetCopyMap (void) const
 Get the mapped FlowBlock.
 
const FlowBlockgetParent (void) const
 Get the parent FlowBlock of this.
 
uint4 getFlags (void) const
 Get the block_flags properties.
 
virtual Address getStart (void) const
 Get the starting address of code in this FlowBlock.
 
virtual Address getStop (void) const
 Get the ending address of code in this FlowBlock.
 
virtual block_type getType (void) const
 Get the FlowBlock type of this.
 
virtual FlowBlocksubBlock (int4 i) const
 Get the i-th component block.
 
virtual void markUnstructured (void)
 Mark target blocks of any unstructured edges.
 
virtual void markLabelBumpUp (bool bump)
 Let hierarchical blocks steal labels of their (first) components. More...
 
virtual void scopeBreak (int4 curexit, int4 curloopexit)
 Mark unstructured edges that should be breaks.
 
virtual void printHeader (ostream &s) const
 Print a simple description of this to stream. More...
 
virtual void printTree (ostream &s, int4 level) const
 Print tree structure of any blocks owned by this. More...
 
virtual void printRaw (ostream &s) const
 Print raw instructions contained in this FlowBlock.
 
virtual void emit (PrintLanguage *lng) const
 Emit the instructions in this FlowBlock as structured code. More...
 
virtual const FlowBlockgetExitLeaf (void) const
 Get the FlowBlock to which this block exits.
 
virtual PcodeOplastOp (void) const
 Get the last PcodeOp executed by this FlowBlock.
 
virtual bool negateCondition (bool toporbottom)
 Flip the condition computed by this. More...
 
virtual bool preferComplement (Funcdata &data)
 Rearrange this hierarchy to simplify boolean expressions. More...
 
virtual FlowBlockgetSplitPoint (void)
 Get the leaf splitting block. More...
 
virtual int4 flipInPlaceTest (vector< PcodeOp *> &fliplist) const
 Test normalizing the conditional branch in this. More...
 
virtual void flipInPlaceExecute (void)
 Perform the flip to normalize conditional branch executed by this block. More...
 
virtual bool isComplex (void) const
 Is this too complex to be a condition (BlockCondition)
 
virtual FlowBlocknextFlowAfter (const FlowBlock *bl) const
 Get the leaf FlowBlock that will execute after the given FlowBlock. More...
 
virtual void finalTransform (Funcdata &data)
 Do any structure driven final transforms.
 
virtual void finalizePrinting (Funcdata &data) const
 Make any final configurations necessary to print the block.
 
virtual void encodeHeader (Encoder &encoder) const
 Encode basic information as attributes. More...
 
virtual void decodeHeader (Decoder &decoder)
 Decode basic information from element attributes. More...
 
virtual void encodeBody (Encoder &encoder) const
 Encode detail about components to a stream.
 
virtual void decodeBody (Decoder &decoder)
 Restore details about this FlowBlock from an element stream. More...
 
void encodeEdges (Encoder &encoder) const
 Encode edge information to a stream. More...
 
void decodeEdges (Decoder &decoder, BlockMap &resolver)
 Restore edges from an encoded stream. More...
 
void encode (Encoder &encoder) const
 Encode this to a stream. More...
 
void decode (Decoder &decoder, BlockMap &resolver)
 Decode this from a stream. More...
 
const FlowBlocknextInFlow (void) const
 Return next block to be executed in flow. More...
 
void setVisitCount (int4 i)
 Set the number of times this block has been visited.
 
int4 getVisitCount (void) const
 Get the count of visits.
 
void setGotoBranch (int4 i)
 Mark a goto branch. More...
 
void setDefaultSwitch (int4 pos)
 Mark an edge as the switch default. More...
 
bool isMark (void) const
 Return true if this block has been marked.
 
void setMark (void)
 Mark this block.
 
void clearMark (void)
 Clear any mark on this block.
 
void setDonothingLoop (void)
 Label this as a do nothing loop.
 
void setDead (void)
 Label this as dead.
 
bool hasSpecialLabel (void) const
 Return true if this uses a different label.
 
bool isJoined (void) const
 Return true if this is a joined basic block.
 
bool isDuplicated (void) const
 Return true if this is a duplicated block.
 
void setLoopExit (int4 i)
 Label the edge exiting this as a loop.
 
void clearLoopExit (int4 i)
 Clear the loop exit edge.
 
void setBackEdge (int4 i)
 Label the back edge of a loop.
 
bool getFlipPath (void) const
 Have out edges been flipped.
 
bool isJumpTarget (void) const
 Return true if non-fallthru jump flows into this. More...
 
FlowBlockgetFalseOut (void) const
 Get the false output FlowBlock.
 
FlowBlockgetTrueOut (void) const
 Get the true output FlowBlock.
 
FlowBlockgetOut (int4 i)
 Get the i-th output FlowBlock.
 
const FlowBlockgetOut (int4 i) const
 Get i-th output FlowBlock.
 
int4 getOutRevIndex (int4 i) const
 Get the input index of the i-th output FlowBlock.
 
FlowBlockgetIn (int4 i)
 Get the i-th input FlowBlock.
 
const FlowBlockgetIn (int4 i) const
 Get the i-th input FlowBlock.
 
int4 getInRevIndex (int4 i) const
 Get the output index of the i-th input FlowBlock.
 
const FlowBlockgetFrontLeaf (void) const
 Get the first leaf FlowBlock. More...
 
FlowBlockgetFrontLeaf (void)
 Get the first leaf FlowBlock. More...
 
int4 calcDepth (const FlowBlock *leaf) const
 Get the depth of the given component FlowBlock. More...
 
bool dominates (const FlowBlock *subBlock) const
 Does this block dominate the given block. More...
 
bool restrictedByConditional (const FlowBlock *cond) const
 Check if the condition from the given block holds for this block. More...
 
int4 sizeOut (void) const
 Get the number of out edges.
 
int4 sizeIn (void) const
 Get the number of in edges.
 
bool hasLoopIn (void) const
 Is there a looping edge coming into this block. More...
 
bool hasLoopOut (void) const
 Is there a looping edge going out of this block. More...
 
bool isLoopIn (int4 i) const
 Is the i-th incoming edge a loop edge.
 
bool isLoopOut (int4 i) const
 Is the i-th outgoing edge a loop edge.
 
int4 getInIndex (const FlowBlock *bl) const
 Get the incoming edge index for the given FlowBlock. More...
 
int4 getOutIndex (const FlowBlock *bl) const
 Get the outgoing edge index for the given FlowBlock. More...
 
bool isDefaultBranch (int4 i) const
 Is the i-th out edge the switch default edge.
 
bool isLabelBumpUp (void) const
 Are labels for this printed by the parent.
 
bool isUnstructuredTarget (void) const
 Is this the target of an unstructured goto.
 
bool isInteriorGotoTarget (void) const
 Is there an unstructured goto to this block's interior.
 
bool hasInteriorGoto (void) const
 Is there an unstructured goto out of this block's interior.
 
bool isEntryPoint (void) const
 Is the entry point of the function.
 
bool isSwitchOut (void) const
 Is this a switch block.
 
bool isDonothingLoop (void) const
 Is this a do nothing block.
 
bool isDead (void) const
 Is this block dead.
 
bool isTreeEdgeIn (int4 i) const
 Is the i-th incoming edge part of the spanning tree.
 
bool isBackEdgeIn (int4 i) const
 Is the i-th incoming edge a back edge.
 
bool isBackEdgeOut (int4 i) const
 Is the i-th outgoing edge a back edge.
 
bool isIrreducibleOut (int4 i) const
 Is the i-th outgoing edge an irreducible edge.
 
bool isIrreducibleIn (int4 i) const
 Is the i-th incoming edge an irreducible edge.
 
bool isDecisionOut (int4 i) const
 Can this and the i-th output be merged into a BlockIf or BlockList.
 
bool isDecisionIn (int4 i) const
 Can this and the i-th input be merged into a BlockIf or BlockList.
 
bool isLoopDAGOut (int4 i) const
 Is the i-th outgoing edge part of the DAG sub-graph.
 
bool isLoopDAGIn (int4 i) const
 Is the i-th incoming edge part of the DAG sub-graph.
 
bool isGotoIn (int4 i) const
 Is the i-th incoming edge unstructured.
 
bool isGotoOut (int4 i) const
 Is the i-th outgoing edge unstructured.
 
JumpTablegetJumptable (void) const
 Get the JumpTable associated this block. More...
 

Static Public Member Functions

static block_type nameToType (const string &name)
 Get the block_type associated with a name string. More...
 
static string typeToName (block_type bt)
 Get the name string associated with a block_type. More...
 
static bool compareBlockIndex (const FlowBlock *bl1, const FlowBlock *bl2)
 Compare FlowBlock by index. More...
 
static bool compareFinalOrder (const FlowBlock *bl1, const FlowBlock *bl2)
 Final FlowBlock comparison. More...
 
static FlowBlockfindCommonBlock (FlowBlock *bl1, FlowBlock *bl2)
 Find the common dominator of two FlowBlocks. More...
 
static FlowBlockfindCommonBlock (const vector< FlowBlock *> &blockSet)
 Find common dominator of multiple FlowBlocks. More...
 

Protected Member Functions

void setFlag (uint4 fl)
 Set a boolean property.
 
void clearFlag (uint4 fl)
 Clear a boolean property.
 

Private Member Functions

void addInEdge (FlowBlock *b, uint4 lab)
 Add an edge coming into this. More...
 
void decodeNextInEdge (Decoder &decoder, BlockMap &resolver)
 Restore the next input edge from XML. More...
 
void halfDeleteInEdge (int4 slot)
 Delete the in half of an edge, correcting indices. More...
 
void halfDeleteOutEdge (int4 slot)
 Delete the out half of an edge, correcting indices. More...
 
void removeInEdge (int4 slot)
 Remove an incoming edge. More...
 
void removeOutEdge (int4 slot)
 Remove an outgoing edge. More...
 
void replaceInEdge (int4 num, FlowBlock *b)
 Make an incoming edge flow from a given block. More...
 
void replaceOutEdge (int4 num, FlowBlock *b)
 Make an outgoing edge flow to a given block. More...
 
void replaceEdgesThru (int4 in, int4 out)
 Remove this from flow between two blocks. More...
 
void swapEdges (void)
 Swap the first and second out edges.
 
void setOutEdgeFlag (int4 i, uint4 lab)
 Apply an out edge label. More...
 
void clearOutEdgeFlag (int4 i, uint4 lab)
 Remove an out edge label. More...
 
void eliminateInDups (FlowBlock *bl)
 Eliminate duplicate in edges from given block. More...
 
void eliminateOutDups (FlowBlock *bl)
 Eliminate duplicate out edges to given block. More...
 
void dedup (void)
 Eliminate duplicate edges.
 
void replaceUsingMap (void)
 Update references to other blocks using getCopyMap() More...
 

Static Private Member Functions

static void replaceEdgeMap (vector< BlockEdge > &vec)
 Update block references in edges with copy map. More...
 
static void findDups (const vector< BlockEdge > &ref, vector< FlowBlock *> &duplist)
 Find blocks that are at the end of multiple edges. More...
 

Private Attributes

uint4 flags
 Collection of block_flags.
 
FlowBlockparent
 The parent block to which this belongs.
 
FlowBlockimmed_dom
 Immediate dominating block.
 
FlowBlockcopymap
 Back reference to a BlockCopy of this.
 
int4 index
 Reference index for this block (reverse post order)
 
int4 visitcount
 A count of visits of this node for various algorithms.
 
int4 numdesc
 Number of descendants of this block in spanning tree (+1)
 
vector< BlockEdgeintothis
 Blocks which (can) fall into this block.
 
vector< BlockEdgeoutofthis
 Blocks into which this block (can) fall.
 

Friends

class BlockGraph
 

Detailed Description

Description of a control-flow block containing PcodeOps.

This is the base class for basic blocks (BlockBasic) and the hierarchical description of structured code. At all levels, these can be viewed as a block of code (PcodeOp objects) with other blocks flowing into and out of it.

Member Enumeration Documentation

◆ block_flags

Boolean properties of blocks.

The first four flags describe attributes of the blocks primary exiting edges The f_interior_* flags do not necessarily apply to these edges. They are used with the block structure and hierarchy algorithms where unstructured jumps are removed from the list of primary edges. These flags keep track only of the existence of unstructured edges, even though they aren't listed

Enumerator
f_goto_goto 

(Block ends in) non-structured branch

f_break_goto 

Block ends with a break;.

f_continue_goto 

Block ends with a continue;.

f_switch_out 

Output is decided by switch.

f_unstructured_targ 

Block is destination of unstructured goto.

f_mark 

Generic way to mark a block.

f_mark2 

A secondary mark.

f_entry_point 

Official entry point of the function.

f_interior_gotoout 

The block has an unstructured jump out of interior.

f_interior_gotoin 

Block is target of unstructured jump to its interior.

f_label_bumpup 

Any label printed higher up in hierarchy.

f_donothing_loop 

Block does nothing in infinite loop (halt)

f_dead 

Block is in process of being deleted.

f_whiledo_overflow 

Set if the conditional block of a whiledo is too big to print as while(cond) { ...

f_flip_path 

If true, out edges have been flipped since last time path was traced.

f_joined_block 

Block is a merged form of original basic blocks.

f_duplicate_block 

Block is a duplicated version of an original basic block.

◆ edge_flags

Boolean properties on edges.

Enumerator
f_goto_edge 

Edge is unstructured.

f_loop_edge 

Edge completes a loop, removing these edges gives you a DAG.

f_defaultswitch_edge 

This is default edge from switchblock.

f_irreducible 

Edge which must be removed to make graph reducible.

f_tree_edge 

An edge in the spanning tree.

f_forward_edge 

An edge that jumps forward in the spanning tree.

f_cross_edge 

An edge that crosses subtrees in the spanning tree.

f_back_edge 

Within (reducible) graph, a back edge defining a loop.

f_loop_exit_edge 

Edge exits the body of a loop.

Member Function Documentation

◆ addInEdge()

void ghidra::FlowBlock::addInEdge ( FlowBlock b,
uint4  lab 
)
private

Add an edge coming into this.

Parameters
bis the FlowBlock coming in
labis a label for the edge

References ghidra::BlockEdge::BlockEdge(), and outofthis.

Referenced by ghidra::BlockGraph::addEdge().

◆ calcDepth()

int4 ghidra::FlowBlock::calcDepth ( const FlowBlock leaf) const

Get the depth of the given component FlowBlock.

How many getParent() calls from the leaf to this

Parameters
leafis the component FlowBlock
Returns
the depth count

References getParent().

Referenced by ghidra::BlockGoto::encodeBody(), ghidra::BlockMultiGoto::encodeBody(), and ghidra::BlockIf::encodeBody().

◆ clearOutEdgeFlag()

void ghidra::FlowBlock::clearOutEdgeFlag ( int4  i,
uint4  lab 
)
private

Remove an out edge label.

Parameters
iis the index of the outgoing edge
labis the edge label to remove

References intothis.

Referenced by ghidra::BlockGraph::findIrreducible().

◆ compareBlockIndex()

bool ghidra::FlowBlock::compareBlockIndex ( const FlowBlock bl1,
const FlowBlock bl2 
)
inlinestatic

Compare FlowBlock by index.

Parameters
bl1is the first FlowBlock to compare
bl2is the second FlowBlock to compare
Returns
true if the first comes before the second

References getIndex().

Referenced by ghidra::BlockMap::sortList().

◆ compareFinalOrder()

bool ghidra::FlowBlock::compareFinalOrder ( const FlowBlock bl1,
const FlowBlock bl2 
)
static

Final FlowBlock comparison.

Comparator for ordering the final 0-exit blocks

Parameters
bl1is the first FlowBlock to compare
bl2is the second FlowBlock
Returns
true if the first comes before the second

References ghidra::PcodeOp::code(), ghidra::CPUI_RETURN, getIndex(), and lastOp().

◆ decode()

void ghidra::FlowBlock::decode ( Decoder decoder,
BlockMap resolver 
)

Decode this from a stream.

Recover this and all it sub-components from a <block> element.

This will construct all the sub-components using resolver as a factory.

Parameters
decoderis the stream decoder
resolveracts as a factory and resolves cross-references

References ghidra::Decoder::closeElement(), and ghidra::Decoder::openElement().

Referenced by ghidra::BlockGraph::decode(), and ghidra::BlockGraph::decodeBody().

◆ decodeBody()

virtual void ghidra::FlowBlock::decodeBody ( Decoder decoder)
inlinevirtual

Restore details about this FlowBlock from an element stream.

Parameters
decoderis the stream decoder

Reimplemented in ghidra::BlockBasic, and ghidra::BlockGraph.

References ghidra::BlockEdge::decode(), and ghidra::BlockEdge::encode().

◆ decodeEdges()

void ghidra::FlowBlock::decodeEdges ( Decoder decoder,
BlockMap resolver 
)

Restore edges from an encoded stream.

Parameters
decoderis the stream decoder
resolveris used to recover FlowBlock cross-references

References ghidra::Decoder::peekElement().

◆ decodeHeader()

void ghidra::FlowBlock::decodeHeader ( Decoder decoder)
virtual

Decode basic information from element attributes.

Parameters
decoderis the stream decoder to pull attributes from

References ghidra::Decoder::readSignedInteger().

◆ decodeNextInEdge()

void ghidra::FlowBlock::decodeNextInEdge ( Decoder decoder,
BlockMap resolver 
)
private

Restore the next input edge from XML.

Parse the next <edge> element in the stream

Parameters
decoderis the stream decoder
resolveris used to resolve block references

References ghidra::BlockEdge::decode(), ghidra::BlockEdge::label, ghidra::BlockEdge::point, and ghidra::BlockEdge::reverse_index.

◆ dominates()

bool ghidra::FlowBlock::dominates ( const FlowBlock subBlock) const

Does this block dominate the given block.

Return true if this block dominates the given block (or is equal to it). This assumes that block indices have been set with a reverse post order so that having a smaller index is a necessary condition for dominance.

Parameters
subBlockis the given block to test against this for dominance
Returns
true if this dominates

References getImmedDom().

Referenced by ghidra::Merge::checkCopyPair(), and ghidra::ActionConditionalConst::propagateConstant().

◆ eliminateInDups()

void ghidra::FlowBlock::eliminateInDups ( FlowBlock bl)
private

Eliminate duplicate in edges from given block.

Parameters
blis the given block

References halfDeleteOutEdge(), and ghidra::BlockEdge::point.

◆ eliminateOutDups()

void ghidra::FlowBlock::eliminateOutDups ( FlowBlock bl)
private

Eliminate duplicate out edges to given block.

Parameters
blis the given block

References halfDeleteInEdge(), and ghidra::BlockEdge::point.

◆ emit()

void ghidra::FlowBlock::emit ( PrintLanguage lng) const
inlinevirtual

◆ encode()

void ghidra::FlowBlock::encode ( Encoder encoder) const

Encode this to a stream.

Encode this and all its sub-components as a <block> element.

Parameters
encoderis the stream encoder

References ghidra::Encoder::closeElement(), and ghidra::Encoder::openElement().

Referenced by ghidra::IfcStructureBlocks::execute(), and ghidra::StructureGraph::rawAction().

◆ encodeEdges()

void ghidra::FlowBlock::encodeEdges ( Encoder encoder) const

Encode edge information to a stream.

Write <edge> element to a stream

Parameters
encoderis the stream encoder

Referenced by ghidra::Funcdata::encodeTree().

◆ encodeHeader()

void ghidra::FlowBlock::encodeHeader ( Encoder encoder) const
virtual

Encode basic information as attributes.

Parameters
encoderis the stream encoder

Reimplemented in ghidra::BlockCondition, and ghidra::BlockCopy.

References ghidra::Encoder::writeSignedInteger().

Referenced by ghidra::BlockCopy::encodeHeader(), and ghidra::BlockCondition::encodeHeader().

◆ findCommonBlock() [1/2]

FlowBlock * ghidra::FlowBlock::findCommonBlock ( FlowBlock bl1,
FlowBlock bl2 
)
static

Find the common dominator of two FlowBlocks.

Within the dominator tree, find the earliest common ancestor of two FlowBlocks

Parameters
bl1is the first FlowBlock
bl2is the second
Returns
the common ancestor which dominates both

References clearMark(), getImmedDom(), isMark(), and setMark().

Referenced by ghidra::Merge::buildDominantCopy(), ghidra::PcodeOp::compareOrder(), ghidra::cseElimination(), and ghidra::ActionConditionalConst::placeMultipleConstants().

◆ findCommonBlock() [2/2]

FlowBlock * ghidra::FlowBlock::findCommonBlock ( const vector< FlowBlock *> &  blockSet)
static

Find common dominator of multiple FlowBlocks.

Find the most immediate dominating FlowBlock of all blocks in the given set. The container must not be empty.

Parameters
blockSetis the given set of blocks
Returns
the most immediate dominating FlowBlock

References getImmedDom(), getIndex(), isMark(), and setMark().

◆ findDups()

void ghidra::FlowBlock::findDups ( const vector< BlockEdge > &  ref,
vector< FlowBlock *> &  duplist 
)
staticprivate

Find blocks that are at the end of multiple edges.

Parameters
refis the list of BlockEdges to search
duplistwill contain the list of blocks with duplicate edges

◆ flipInPlaceExecute()

void ghidra::FlowBlock::flipInPlaceExecute ( void  )
inlinevirtual

Perform the flip to normalize conditional branch executed by this block.

This reverses the outgoing edge order in the right basic blocks, but does not modify the instructions directly.

Reimplemented in ghidra::BlockCondition, and ghidra::BlockBasic.

Referenced by ghidra::BlockIf::preferComplement().

◆ flipInPlaceTest()

int4 ghidra::FlowBlock::flipInPlaceTest ( vector< PcodeOp *> &  fliplist) const
inlinevirtual

Test normalizing the conditional branch in this.

Find the set of PcodeOp objects that need to be adjusted to flip the condition this FlowBlock calculates.

Return:

  • 0 if the flip would normalize the condition
  • 1 if the flip doesn't affect normalization of the condition
  • 2 if the flip produces an unnormalized condition
    Parameters
    fliplistwill contain the PcodeOps that need to be adjusted
    Returns
    0 if the condition will be normalized, 1 or 2 otherwise

Reimplemented in ghidra::BlockCondition, and ghidra::BlockBasic.

Referenced by ghidra::BlockCondition::flipInPlaceTest(), and ghidra::BlockIf::preferComplement().

◆ getFrontLeaf() [1/2]

const FlowBlock * ghidra::FlowBlock::getFrontLeaf ( void  ) const

◆ getFrontLeaf() [2/2]

FlowBlock * ghidra::FlowBlock::getFrontLeaf ( void  )

Get the first leaf FlowBlock.

Keep descending tree hierarchy, taking the front block, until we get to the bottom copy block

Returns
the first leaf FlowBlock to execute

References getType(), and subBlock().

◆ getInIndex()

int4 ghidra::FlowBlock::getInIndex ( const FlowBlock bl) const

Get the incoming edge index for the given FlowBlock.

Search through incoming blocks in edge order for the given block.

Parameters
blis the given FlowBlock
Returns
the matching edge index or -1 if bl doesn't flow into this

References ghidra::BlockEdge::point.

Referenced by ghidra::BlockSwitch::addCase(), ghidra::Funcdata::blockRemoveInternal(), ghidra::Funcdata::branchRemoveInternal(), ghidra::BlockSwitch::grabCaseBasic(), and ghidra::BlockBasic::unblockedMulti().

◆ getJumptable()

JumpTable * ghidra::FlowBlock::getJumptable ( void  ) const

Get the JumpTable associated this block.

If this FlowBlock was ends with a computed jump, retrieve the associated JumpTable object

Returns
the JumpTable object or NULL

References ghidra::Funcdata::findJumpTable(), ghidra::BlockBasic::getFuncdata(), and ghidra::PcodeOp::getParent().

Referenced by ghidra::BlockSwitch::BlockSwitch().

◆ getOutIndex()

int4 ghidra::FlowBlock::getOutIndex ( const FlowBlock bl) const

Get the outgoing edge index for the given FlowBlock.

Search through outgoing blocks in edge order for the given block.

Parameters
blis the given FlowBlock
Returns
the matching edge index or -1 if bl doesn't flow out of this

References ghidra::BlockEdge::point.

Referenced by ghidra::FloatingEdge::getCurrentEdge(), and ghidra::Funcdata::nodeJoinCreateBlock().

◆ getSplitPoint()

FlowBlock * ghidra::FlowBlock::getSplitPoint ( void  )
inlinevirtual

Get the leaf splitting block.

If this block ends with a conditional branch, return the deepest component block that performs the split. This component needs to be able to perform flipInPlaceTest() and flipInPlaceExecute()

Returns
the component FlowBlock or NULL if this doesn't end in a conditional branch

Reimplemented in ghidra::BlockCondition, ghidra::BlockList, ghidra::BlockCopy, and ghidra::BlockBasic.

Referenced by ghidra::BlockCondition::flipInPlaceTest(), ghidra::BlockCopy::getSplitPoint(), ghidra::BlockList::getSplitPoint(), and ghidra::BlockIf::preferComplement().

◆ halfDeleteInEdge()

void ghidra::FlowBlock::halfDeleteInEdge ( int4  slot)
private

Delete the in half of an edge, correcting indices.

Parameters
slotis the index of the incoming edge being altered

References outofthis, ghidra::BlockEdge::point, and ghidra::BlockEdge::reverse_index.

Referenced by eliminateOutDups(), removeOutEdge(), and replaceOutEdge().

◆ halfDeleteOutEdge()

void ghidra::FlowBlock::halfDeleteOutEdge ( int4  slot)
private

Delete the out half of an edge, correcting indices.

Parameters
slotis the index of the outgoing edge being altered

References intothis, ghidra::BlockEdge::point, and ghidra::BlockEdge::reverse_index.

Referenced by eliminateInDups(), removeInEdge(), and replaceInEdge().

◆ hasLoopIn()

bool ghidra::FlowBlock::hasLoopIn ( void  ) const

Is there a looping edge coming into this block.

Returns
true if this is the top of a loop

References ghidra::BlockEdge::label.

Referenced by ghidra::RulePullsubMulti::applyOp().

◆ hasLoopOut()

bool ghidra::FlowBlock::hasLoopOut ( void  ) const

Is there a looping edge going out of this block.

Returns
true if this is the bottom of a loop

References ghidra::BlockEdge::label.

◆ isJumpTarget()

bool ghidra::FlowBlock::isJumpTarget ( void  ) const

Return true if non-fallthru jump flows into this.

return true if block is the target of a jump

References index, and ghidra::BlockEdge::point.

Referenced by ghidra::PrintC::emitLabelStatement().

◆ markLabelBumpUp()

void ghidra::FlowBlock::markLabelBumpUp ( bool  bump)
virtual

Let hierarchical blocks steal labels of their (first) components.

Parameters
bumpif true, mark that labels for this block are printed by somebody higher in hierarchy

Reimplemented in ghidra::BlockInfLoop, ghidra::BlockDoWhile, ghidra::BlockWhileDo, and ghidra::BlockGraph.

Referenced by ghidra::BlockGraph::markLabelBumpUp().

◆ nameToType()

FlowBlock::block_type ghidra::FlowBlock::nameToType ( const string &  nm)
static

Get the block_type associated with a name string.

Given a string describing a FlowBlock type, return the block_type. This is currently only used by the decode() process. TODO: Fill in the remaining names and types

Parameters
nmis the name string
Returns
the corresponding block_type

Referenced by ghidra::BlockMap::createBlock().

◆ negateCondition()

bool ghidra::FlowBlock::negateCondition ( bool  toporbottom)
virtual

Flip the condition computed by this.

Flip the order of outgoing edges (at least). This should also affect the original op causing the condition. Note: we don't have to flip at all levels of the hierarchy only at the top and at the bottom

Parameters
toporbottomis true if this is the top outermost block of the hierarchy getting negated
Returns
true if a change was made to data-flow

Reimplemented in ghidra::BlockCondition, ghidra::BlockList, ghidra::BlockCopy, and ghidra::BlockBasic.

Referenced by ghidra::BlockBasic::flipInPlaceExecute(), ghidra::BlockBasic::negateCondition(), ghidra::BlockCopy::negateCondition(), ghidra::BlockList::negateCondition(), ghidra::BlockCondition::negateCondition(), ghidra::CollapseStructure::ruleBlockDoWhile(), ghidra::CollapseStructure::ruleBlockGoto(), ghidra::CollapseStructure::ruleBlockIfNoExit(), ghidra::CollapseStructure::ruleBlockOr(), ghidra::CollapseStructure::ruleBlockProperIf(), and ghidra::CollapseStructure::ruleBlockWhileDo().

◆ nextFlowAfter()

FlowBlock * ghidra::FlowBlock::nextFlowAfter ( const FlowBlock bl) const
inlinevirtual

Get the leaf FlowBlock that will execute after the given FlowBlock.

Within the hierarchy of this FlowBlock, assume the given FlowBlock will fall-thru in its execution at some point. Return the first leaf block (BlockBasic or BlockCopy) that will execute after the given FlowBlock completes, assuming this is a unique block.

Parameters
blis the given FlowBlock
Returns
the next FlowBlock to execute or NULL

Reimplemented in ghidra::BlockSwitch, ghidra::BlockInfLoop, ghidra::BlockDoWhile, ghidra::BlockWhileDo, ghidra::BlockIf, ghidra::BlockCondition, ghidra::BlockMultiGoto, ghidra::BlockGoto, and ghidra::BlockGraph.

Referenced by ghidra::BlockGoto::gotoPrints(), ghidra::BlockIf::nextFlowAfter(), and ghidra::BlockSwitch::nextFlowAfter().

◆ nextInFlow()

const FlowBlock * ghidra::FlowBlock::nextInFlow ( void  ) const

Return next block to be executed in flow.

If there are two branches, pick the fall-thru branch

Returns
the next block in flow, or NULL otherwise

References ghidra::PcodeOp::code(), ghidra::CPUI_CBRANCH, and ghidra::PcodeOp::isFallthruTrue().

Referenced by ghidra::PrintC::emitBlockLs().

◆ preferComplement()

bool ghidra::FlowBlock::preferComplement ( Funcdata data)
inlinevirtual

Rearrange this hierarchy to simplify boolean expressions.

For the instructions in this block, decide if the control-flow structure can be rearranged so that boolean expressions come out more naturally.

Parameters
datais the function to analyze
Returns
true if a change was made

Reimplemented in ghidra::BlockIf.

Referenced by ghidra::ActionPreferComplement::apply().

◆ printHeader()

void ghidra::FlowBlock::printHeader ( ostream &  s) const
virtual

◆ printTree()

void ghidra::FlowBlock::printTree ( ostream &  s,
int4  level 
) const
virtual

Print tree structure of any blocks owned by this.

Recursively print out the hierarchical structure of this FlowBlock.

Parameters
sis the output stream
levelis the current level of indentation

Reimplemented in ghidra::BlockCopy, and ghidra::BlockGraph.

Referenced by ghidra::BlockGraph::printTree().

◆ removeInEdge()

void ghidra::FlowBlock::removeInEdge ( int4  slot)
private

Remove an incoming edge.

Parameters
slotis the index of the incoming edge to remove

References halfDeleteOutEdge().

Referenced by ghidra::BlockGraph::removeEdge().

◆ removeOutEdge()

void ghidra::FlowBlock::removeOutEdge ( int4  slot)
private

Remove an outgoing edge.

Parameters
slotis the index of the outgoing edge to remove

References halfDeleteInEdge().

Referenced by ghidra::BlockGraph::calcForwardDominator(), ghidra::BlockGraph::removeFromFlow(), and ghidra::BlockGraph::spliceBlock().

◆ replaceEdgeMap()

void ghidra::FlowBlock::replaceEdgeMap ( vector< BlockEdge > &  vec)
staticprivate

Update block references in edges with copy map.

Block references are updated using the getCopyMap() reference on the original block

Parameters
vecis the list of edges whose block references should be updated

◆ replaceEdgesThru()

void ghidra::FlowBlock::replaceEdgesThru ( int4  in,
int4  out 
)
private

Remove this from flow between two blocks.

Remove edge in and out from this block, but create a new edge between the in-block and the out-block, preserving position in the in/out edge lists.

Parameters
inis the index of the incoming block
outis the index of the outgoing block

References intothis, and outofthis.

Referenced by ghidra::BlockGraph::removeFromFlowSplit().

◆ replaceInEdge()

void ghidra::FlowBlock::replaceInEdge ( int4  num,
FlowBlock b 
)
private

Make an incoming edge flow from a given block.

The original edge, which must exist, is replaced.

Parameters
numis the index of the incoming edge
bis the new incoming block

References ghidra::BlockEdge::BlockEdge(), halfDeleteOutEdge(), ghidra::BlockEdge::label, outofthis, and ghidra::BlockEdge::reverse_index.

Referenced by ghidra::BlockGraph::moveOutEdge(), and ghidra::BlockGraph::selfIdentify().

◆ replaceOutEdge()

void ghidra::FlowBlock::replaceOutEdge ( int4  num,
FlowBlock b 
)
private

Make an outgoing edge flow to a given block.

The original edge, which must exist is replaced.

Parameters
numis the index of the outgoing edge
bis the new outgoing block

References ghidra::BlockEdge::BlockEdge(), halfDeleteInEdge(), intothis, ghidra::BlockEdge::label, and ghidra::BlockEdge::reverse_index.

Referenced by ghidra::BlockGraph::removeFromFlow(), ghidra::BlockGraph::selfIdentify(), and ghidra::BlockGraph::switchEdge().

◆ replaceUsingMap()

void ghidra::FlowBlock::replaceUsingMap ( void  )
private

Update references to other blocks using getCopyMap()

Run through incoming and outgoing edges and replace FlowBlock references with the FlowBlock accessed via the getCopyMap() method.

◆ restrictedByConditional()

bool ghidra::FlowBlock::restrictedByConditional ( const FlowBlock cond) const

Check if the condition from the given block holds for this block.

We assume the given block has 2 out-edges and that this block is immediately reached by one of these two edges. Some condition holds when traversing the out-edge to this, and the complement of the condition holds for traversing the other out-edge. We verify that the condition holds for this entire block. More specifically, we check that that there is no path to this through the sibling edge, where the complement of the condition holds (unless we loop back through the conditional block).

Parameters
condis the conditional block with 2 out-edges
Returns
true if the condition holds for this block

References getImmedDom().

Referenced by ghidra::ActionConditionalConst::apply(), and ghidra::ValueSetSolver::applyConstraints().

◆ setDefaultSwitch()

void ghidra::FlowBlock::setDefaultSwitch ( int4  pos)

Mark an edge as the switch default.

The switch can have exactly 1 default edge, so we make sure other edges are not marked.

Parameters
posis the index of the out edge that should be the default

Referenced by ghidra::Funcdata::installSwitchDefaults().

◆ setGotoBranch()

void ghidra::FlowBlock::setGotoBranch ( int4  i)

Mark a goto branch.

This is the main entry point for marking a branch from one block to another as unstructured.

Parameters
iis the index of the outgoing edge to mark

Referenced by ghidra::CollapseStructure::checkSwitchSkips(), ghidra::Funcdata::forceGoto(), ghidra::CollapseStructure::markExitsAsGotos(), ghidra::CollapseStructure::ruleCaseFallthru(), and ghidra::CollapseStructure::selectGoto().

◆ setOutEdgeFlag()

void ghidra::FlowBlock::setOutEdgeFlag ( int4  i,
uint4  lab 
)
private

Apply an out edge label.

Parameters
iis the index of the outgoing edge
labis the new edge label

References intothis.

Referenced by ghidra::BlockGraph::addLoopEdge(), ghidra::BlockGraph::findIrreducible(), and ghidra::BlockGraph::findSpanningTree().

◆ typeToName()

string ghidra::FlowBlock::typeToName ( FlowBlock::block_type  bt)
static

Get the name string associated with a block_type.

For use in serializng FlowBlocks to XML.

Parameters
btis the block_type
Returns
the corresponding name string

Referenced by ghidra::BlockGraph::encodeBody().


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