Ghidra Decompiler Analysis Engine
Classes | Public Member Functions | List of all members
BlockSwitch Class Reference

A structured switch construction. More...

#include <block.hh>

Inheritance diagram for BlockSwitch:
Inheritance graph
[legend]
Collaboration diagram for BlockSwitch:
Collaboration graph
[legend]

Public Member Functions

 BlockSwitch (FlowBlock *ind)
 Construct given the multi-exit root block.
 
void grabCaseBasic (FlowBlock *switchbl, const vector< FlowBlock * > &cs)
 Build annotated CaseOrder objects. More...
 
int4 getNumLabels (int4 i) const
 Get the number of labels associated with one case block. More...
 
uintb getLabel (int4 i, int4 j) const
 Get a specific label associated with a case block. More...
 
const DatatypegetSwitchType (void) const
 Get the data-type of the switch variable. More...
 
virtual block_type getType (void) const
 
virtual void markUnstructured (void)
 
virtual void scopeBreak (int4 curexit, int4 curloopexit)
 
virtual void printHeader (ostream &s) const
 Print a simple description of this to stream. More...
 
virtual void emit (PrintLanguage *lng) const
 Emit the instructions in this FlowBlock as structured code. More...
 
virtual FlowBlocknextFlowAfter (const FlowBlock *bl) const
 Get the leaf FlowBlock that will execute after the given FlowBlock. More...
 
virtual void finalizePrinting (Funcdata &data) const
 
- Public Member Functions inherited from BlockGraph
void clear (void)
 Clear all component FlowBlock objects.
 
virtual FlowBlocksubBlock (int4 i) const
 
virtual void markLabelBumpUp (bool bump)
 Let hierarchical blocks steal labels of their (first) components. 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
 
virtual void finalTransform (Funcdata &data)
 
virtual void saveXmlBody (ostream &s) const
 
virtual void restoreXmlBody (List::const_iterator &iter, List::const_iterator enditer, BlockMap &resolver)
 Restore details about this FlowBlock from an XML stream. More...
 
void restoreXml (const Element *el, const AddrSpaceManager *m)
 Restore this BlockGraph from an XML stream. More...
 
void addEdge (FlowBlock *begin, FlowBlock *end)
 Add a directed edge between component FlowBlocks. More...
 
void addLoopEdge (FlowBlock *begin, int4 outindex)
 Mark a given edge as a loop edge. More...
 
void removeEdge (FlowBlock *begin, FlowBlock *end)
 Remove an edge between component FlowBlocks. More...
 
void switchEdge (FlowBlock *in, FlowBlock *outbefore, FlowBlock *outafter)
 Move an edge from one out FlowBlock to another. More...
 
void moveOutEdge (FlowBlock *blold, int4 slot, FlowBlock *blnew)
 Move indicated out edge to a new FlowBlock. More...
 
void removeBlock (FlowBlock *bl)
 Remove a FlowBlock from this BlockGraph. More...
 
void removeFromFlow (FlowBlock *bl)
 Remove given FlowBlock preserving flow in this. More...
 
void removeFromFlowSplit (FlowBlock *bl, bool flipflow)
 Remove FlowBlock splitting flow between input and output edges. More...
 
void spliceBlock (FlowBlock *bl)
 Splice given FlowBlock together with its output. More...
 
void setStartBlock (FlowBlock *bl)
 Set the entry point FlowBlock for this graph. More...
 
FlowBlockgetStartBlock (void) const
 Get the entry point FlowBlock. More...
 
FlowBlocknewBlock (void)
 Build a new plain FlowBlock. More...
 
BlockBasicnewBlockBasic (Funcdata *fd)
 Build a new BlockBasic. More...
 
BlockCopynewBlockCopy (FlowBlock *bl)
 Build a new BlockCopy. More...
 
BlockGotonewBlockGoto (FlowBlock *bl)
 Build a new BlockGoto. More...
 
BlockMultiGotonewBlockMultiGoto (FlowBlock *bl, int4 outedge)
 Build a new BlockMultiGoto. More...
 
BlockListnewBlockList (const vector< FlowBlock * > &nodes)
 Build a new BlockList. More...
 
BlockConditionnewBlockCondition (FlowBlock *b1, FlowBlock *b2)
 Build a new BlockCondition. More...
 
BlockIfnewBlockIfGoto (FlowBlock *cond)
 Build a new BlockIfGoto. More...
 
BlockIfnewBlockIf (FlowBlock *cond, FlowBlock *tc)
 Build a new BlockIf. More...
 
BlockIfnewBlockIfElse (FlowBlock *cond, FlowBlock *tc, FlowBlock *fc)
 Build a new BlockIfElse. More...
 
BlockWhileDonewBlockWhileDo (FlowBlock *cond, FlowBlock *cl)
 Build a new BlockWhileDo. More...
 
BlockDoWhilenewBlockDoWhile (FlowBlock *condcl)
 Build a new BlockDoWhile. More...
 
BlockInfLoopnewBlockInfLoop (FlowBlock *body)
 Build a new BlockInfLoop. More...
 
BlockSwitchnewBlockSwitch (const vector< FlowBlock * > &cs, bool hasExit)
 Build a new BlockSwitch. More...
 
void orderBlocks (void)
 
void buildCopy (const BlockGraph &graph)
 Build a copy of a BlockGraph. More...
 
void clearVisitCount (void)
 Clear the visit count in all node FlowBlocks.
 
void calcForwardDominator (const vector< FlowBlock * > &rootlist)
 Calculate forward dominators. More...
 
void buildDomTree (vector< vector< FlowBlock * > > &child) const
 Build the dominator tree. More...
 
int4 buildDomDepth (vector< int4 > &depth) const
 Calculate dominator depths. More...
 
void buildDomSubTree (vector< FlowBlock * > &res, FlowBlock *root) const
 Collect nodes from a dominator sub-tree. More...
 
void calcLoop (void)
 Calculate loop edges. More...
 
void collectReachable (vector< FlowBlock * > &res, FlowBlock *bl, bool un) const
 Collect reachable/unreachable FlowBlocks from a given start FlowBlock. More...
 
void structureLoops (vector< FlowBlock * > &rootlist)
 Label loop edges. More...
 
- Public Member Functions inherited from FlowBlock
 FlowBlock (void)
 Construct a block with no edges.
 
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 void saveXmlHeader (ostream &s) const
 Save basic information as XML attributes. More...
 
virtual void restoreXmlHeader (const Element *el)
 Restore basic information for XML attributes. More...
 
void saveXmlEdges (ostream &s) const
 Save edge information to an XML stream. More...
 
void restoreXmlEdges (List::const_iterator &iter, List::const_iterator enditer, BlockMap &resolver)
 Restore edges from an XML stream. More...
 
void saveXml (ostream &s) const
 Write out this to an XML stream. More...
 
void restoreXml (const Element *el, BlockMap &resolver)
 Restore this from an XML stream. More...
 
const FlowBlocknextInFlow (void) const
 Return next block to be executed in flow. More...
 
void setGotoBranch (int4 i)
 Mark a goto branch. More...
 
bool isJumpTarget (void) const
 Return true if non-fallthru jump flows into this. More...
 
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...
 
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...
 
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 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.
 
JumpTablegetJumptable (void) const
 Get the JumpTable associated this block. More...
 

Additional Inherited Members

- Public Types inherited from FlowBlock
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...
 
- Static Public Member Functions inherited from FlowBlock
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 inherited from BlockGraph
void swapBlocks (int4 i, int4 j)
 Swap the positions two component FlowBlocks. More...
 
- Static Protected Member Functions inherited from BlockGraph
static void markCopyBlock (FlowBlock *bl, uint4 fl)
 Set properties on the first leaf FlowBlock. More...
 

Detailed Description

A structured switch construction.

This always has at least one component, the first, that executes the switch statement itself and has multiple outgoing edges. Each edge flows either to a formal exit block, or to another case component. All additional components are case components, which have either zero or one outgoing edge. If there is an edge, it flows either to another case component or to the formal exit block. The BlockSwitch instance has zero or one outgoing edges.

Member Function Documentation

◆ emit()

virtual void BlockSwitch::emit ( PrintLanguage lng) const
inlinevirtual

Emit the instructions in this FlowBlock as structured code.

This is the main entry point, at the control-flow level, for printing structured code.

Parameters
lngis the PrintLanguage that provides details of the high-level language being printed

Reimplemented from BlockGraph.

◆ getLabel()

uintb BlockSwitch::getLabel ( int4  i,
int4  j 
) const
inline

Get a specific label associated with a case block.

Parameters
iis the index of the case block
jis the index of the specific label
Returns
the label as an untyped constant

◆ getNumLabels()

int4 BlockSwitch::getNumLabels ( int4  i) const
inline

Get the number of labels associated with one case block.

Parameters
iis the index of the case block
Returns
the number of labels put on the associated block

◆ getSwitchType()

const Datatype * BlockSwitch::getSwitchType ( void  ) const

Get the data-type of the switch variable.

Drill down to the variable associated with the BRANCHIND itself, and return its data-type

Returns
the Datatype associated with the switch variable

◆ grabCaseBasic()

void BlockSwitch::grabCaseBasic ( FlowBlock switchbl,
const vector< FlowBlock * > &  cs 
)

Build annotated CaseOrder objects.

Given the list of components for the switch structure, build the annotated descriptions of the cases. Work out flow between cases and if there are any unstructured cases. The first FlowBlock in the component list is the switch component itself. All other FlowBlocks in the list are the case components.

Parameters
switchblis the underlying basic block, with multiple outgoing edges, for the switch
csis the list of switch and case components

◆ nextFlowAfter()

FlowBlock * BlockSwitch::nextFlowAfter ( const FlowBlock bl) const
virtual

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 from BlockGraph.

◆ printHeader()

void BlockSwitch::printHeader ( ostream &  s) const
virtual

Print a simple description of this to stream.

Only print a header for this single block

Parameters
sis the output stream

Reimplemented from FlowBlock.


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