Ghidra Decompiler Analysis Engine
|
Go to the documentation of this file.
19 #ifndef __CPUI_BLOCK__
20 #define __CPUI_BLOCK__
65 t_plain, t_basic, t_graph, t_copy, t_goto, t_multigoto, t_ls,
66 t_condition, t_if, t_whiledo, t_dowhile, t_switch, t_infloop
114 vector<BlockEdge> intothis;
115 vector<BlockEdge> outofthis;
120 static void replaceEdgeMap(vector<BlockEdge> &vec);
123 void halfDeleteInEdge(int4 slot);
124 void halfDeleteOutEdge(int4 slot);
125 void removeInEdge(int4 slot);
126 void removeOutEdge(int4 slot);
127 void replaceInEdge(int4 num,
FlowBlock *b);
128 void replaceOutEdge(int4 num,
FlowBlock *b);
129 void replaceEdgesThru(int4 in,int4 out);
130 void swapEdges(
void);
131 void setOutEdgeFlag(int4 i,uint4 lab);
132 void clearOutEdgeFlag(int4 i,uint4 lab);
135 static void findDups(
const vector<BlockEdge> &ref,vector<FlowBlock *> &duplist);
137 void replaceUsingMap(
void);
138 #ifdef BLOCKCONSISTENT_DEBUG
139 void checkEdges(
void);
142 void setFlag(uint4 fl) { flags |= fl; }
143 void clearFlag(uint4 fl) { flags &= ~fl; }
147 int4 getIndex(
void)
const {
return index; }
148 FlowBlock *getParent(
void) {
return parent; }
149 FlowBlock *getImmedDom(
void)
const {
return immed_dom; }
150 FlowBlock *getCopyMap(
void)
const {
return copymap; }
152 uint4 getFlags(
void)
const {
return flags; }
155 virtual block_type getType(
void)
const {
return t_plain; }
157 virtual void markUnstructured(
void) {}
159 virtual void scopeBreak(int4 curexit,int4 curloopexit) {}
161 virtual void printTree(ostream &s,int4 level)
const;
162 virtual void printRaw(ostream &s)
const {}
171 virtual bool isComplex(
void)
const {
return true; }
173 virtual void finalTransform(
Funcdata &data) {}
174 virtual void finalizePrinting(
Funcdata &data)
const {}
177 virtual void saveXmlBody(ostream &s)
const {}
187 void saveXml(ostream &s)
const;
190 void setVisitCount(int4 i) { visitcount = i; }
191 int4 getVisitCount(
void)
const {
return visitcount; }
194 bool isMark(
void)
const {
return ((flags&
f_mark)!=0); }
195 void setMark(
void) { flags |=
f_mark; }
196 void clearMark(
void) { flags &= ~
f_mark; }
198 void setDead(
void) { flags |=
f_dead; }
204 void setBackEdge(int4 i) { setOutEdgeFlag(i,
f_back_edge); }
205 bool getFlipPath(
void)
const {
return ((flags &
f_flip_path)!=0); }
207 FlowBlock *getFalseOut(
void)
const {
return outofthis[0].point; }
208 FlowBlock *getTrueOut(
void)
const {
return outofthis[1].point; }
209 FlowBlock *getOut(int4 i) {
return outofthis[i].point; }
210 const FlowBlock *getOut(int4 i)
const {
return (
const FlowBlock *) outofthis[i].point; }
211 int4 getOutRevIndex(int4 i)
const {
return outofthis[i].reverse_index; }
212 FlowBlock *getIn(int4 i) {
return intothis[i].point; }
213 const FlowBlock *getIn(int4 i)
const {
return (
const FlowBlock *) intothis[i].point; }
214 int4 getInRevIndex(int4 i)
const {
return intothis[i].reverse_index; }
220 int4 sizeOut(
void)
const {
return outofthis.size(); }
221 int4 sizeIn(
void)
const {
return intothis.size(); }
224 bool isLoopIn(int4 i)
const {
return ((intothis[i].label &
f_loop_edge)!=0); }
225 bool isLoopOut(int4 i)
const {
return ((outofthis[i].label &
f_loop_edge)!=0); }
229 bool isLabelBumpUp(
void)
const {
return ((flags &
f_label_bumpup)!=0); }
231 bool isInteriorGotoTarget(
void)
const {
return ((flags &
f_interior_gotoin)!=0); }
233 bool isEntryPoint(
void)
const {
return ((flags&
f_entry_point)!=0); }
234 bool isSwitchOut(
void)
const {
return ((flags&
f_switch_out)!=0); }
236 bool isDead(
void)
const {
return ((flags &
f_dead)!=0); }
237 bool isTreeEdgeIn(int4 i)
const {
return ((intothis[i].label &
f_tree_edge)!=0); }
238 bool isBackEdgeIn(int4 i)
const {
return ((intothis[i].label &
f_back_edge)!=0); }
239 bool isBackEdgeOut(int4 i)
const {
return ((outofthis[i].label &
f_back_edge)!=0); }
240 bool isIrreducibleOut(int4 i)
const {
return ((outofthis[i].label &
f_irreducible)!=0); }
241 bool isIrreducibleIn(int4 i)
const {
return ((intothis[i].label &
f_irreducible)!=0); }
272 vector<FlowBlock *> list;
274 void forceOutputNum(int4 i);
275 void selfIdentify(
void);
276 void identifyInternal(
BlockGraph *ident,
const vector<FlowBlock *> &nodes);
277 void clearEdgeFlags(uint4 flags);
278 static FlowBlock *createVirtualRoot(
const vector<FlowBlock *> &rootlist);
279 void findSpanningTree(vector<FlowBlock *> &preorder,vector<FlowBlock *> &rootlist);
280 bool findIrreducible(
const vector<FlowBlock *> &preorder,int4 &irreduciblecount);
281 void forceFalseEdge(
const FlowBlock *out0);
288 const vector<FlowBlock *> &getList(
void)
const {
return list; }
289 int4 getSize(
void)
const {
return list.size(); }
290 FlowBlock *getBlock(int4 i)
const {
return list[i]; }
291 virtual block_type getType(
void)
const {
return t_graph; }
292 virtual FlowBlock *subBlock(int4 i)
const {
return list[i]; }
293 virtual void markUnstructured(
void);
295 virtual void scopeBreak(int4 curexit,int4 curloopexit);
296 virtual void printTree(ostream &s,int4 level)
const;
297 virtual void printRaw(ostream &s)
const;
300 virtual void finalTransform(
Funcdata &data);
301 virtual void finalizePrinting(
Funcdata &data)
const;
302 virtual void saveXmlBody(ostream &s)
const;
339 void buildDomTree(vector<vector<FlowBlock *> > &child)
const;
345 #ifdef BLOCKCONSISTENT_DEBUG
346 bool isConsistent(
void)
const;
370 void insert(list<PcodeOp *>::iterator iter,
PcodeOp *inst);
372 void copyRange(
const BlockBasic *bb) { cover = bb->cover; }
378 Funcdata *getFuncdata(
void) {
return data; }
380 bool contains(
const Address &addr)
const {
return cover.
inRange(addr, 1); }
382 virtual Address getStart(
void)
const;
383 virtual Address getStop(
void)
const;
384 virtual block_type getType(
void)
const {
return t_basic; }
386 virtual void saveXmlBody(ostream &s)
const;
389 virtual void printRaw(ostream &s)
const;
391 virtual const FlowBlock *getExitLeaf(
void)
const {
return this; }
392 virtual PcodeOp *lastOp(
void)
const;
397 virtual bool isComplex(
void)
const;
401 list<PcodeOp *>::iterator
beginOp(
void) {
return op.begin(); }
402 list<PcodeOp *>::iterator
endOp(
void) {
return op.end(); }
403 list<PcodeOp *>::const_iterator
beginOp(
void)
const {
return op.begin(); }
404 list<PcodeOp *>::const_iterator
endOp(
void)
const {
return op.end(); }
405 bool emptyOp(
void)
const {
return op.empty(); }
423 virtual FlowBlock *subBlock(int4 i)
const {
return copy; }
424 virtual block_type getType(
void)
const {
return t_copy; }
426 virtual void printTree(ostream &s,int4 level)
const;
427 virtual void printRaw(ostream &s)
const { copy->printRaw(s); }
429 virtual const FlowBlock *getExitLeaf(
void)
const {
return this; }
430 virtual PcodeOp *lastOp(
void)
const {
return copy->lastOp(); }
433 virtual bool isComplex(
void)
const {
return copy->isComplex(); }
449 FlowBlock *getGotoTarget(
void)
const {
return gototarget; }
450 uint4 getGotoType(
void)
const {
return gototype; }
452 virtual block_type getType(
void)
const {
return t_goto; }
453 virtual void markUnstructured(
void);
454 virtual void scopeBreak(int4 curexit,int4 curloopexit);
456 virtual void printRaw(ostream &s)
const { getBlock(0)->printRaw(s); }
458 virtual const FlowBlock *getExitLeaf(
void)
const {
return getBlock(0)->getExitLeaf(); }
459 virtual PcodeOp *lastOp(
void)
const {
return getBlock(0)->lastOp(); }
461 virtual void saveXmlBody(ostream &s)
const;
471 vector<FlowBlock *> gotoedges;
475 void setDefaultGoto(
void) { defaultswitch =
true; }
476 bool hasDefaultGoto(
void)
const {
return defaultswitch; }
478 int4 numGotos(
void)
const {
return gotoedges.size(); }
479 FlowBlock *getGoto(int4 i)
const {
return gotoedges[i]; }
481 virtual block_type getType(
void)
const {
return t_multigoto; }
482 virtual void scopeBreak(int4 curexit,int4 curloopexit);
484 virtual void printRaw(ostream &s)
const { getBlock(0)->printRaw(s); }
486 virtual const FlowBlock *getExitLeaf(
void)
const {
return getBlock(0)->getExitLeaf(); }
487 virtual PcodeOp *lastOp(
void)
const {
return getBlock(0)->lastOp(); }
489 virtual void saveXmlBody(ostream &s)
const;
499 virtual block_type getType(
void)
const {
return t_ls; }
502 virtual const FlowBlock *getExitLeaf(
void)
const;
503 virtual PcodeOp *lastOp(
void)
const;
522 OpCode getOpcode(
void)
const {
return opc; }
523 virtual block_type getType(
void)
const {
return t_condition; }
524 virtual void scopeBreak(int4 curexit,int4 curloopexit);
531 virtual PcodeOp *lastOp(
void)
const;
532 virtual bool isComplex(
void)
const {
return getBlock(0)->isComplex(); }
560 void setGotoTarget(
FlowBlock *bl) { gototarget = bl; }
561 FlowBlock *getGotoTarget(
void)
const {
return gototarget; }
562 uint4 getGotoType(
void)
const {
return gototype; }
563 virtual block_type getType(
void)
const {
return t_if; }
564 virtual void markUnstructured(
void);
565 virtual void scopeBreak(int4 curexit,int4 curloopexit);
569 virtual const FlowBlock *getExitLeaf(
void)
const;
570 virtual PcodeOp *lastOp(
void)
const;
572 virtual void saveXmlBody(ostream &s)
const;
597 bool testIterateForm(
void)
const;
600 PcodeOp *getInitializeOp(
void)
const {
return initializeOp; }
601 PcodeOp *getIterateOp(
void)
const {
return iterateOp; }
604 virtual block_type getType(
void)
const {
return t_whiledo; }
606 virtual void scopeBreak(int4 curexit,int4 curloopexit);
620 virtual block_type getType(
void)
const {
return t_dowhile; }
622 virtual void scopeBreak(int4 curexit,int4 curloopexit);
634 virtual block_type getType(
void)
const {
return t_infloop; }
636 virtual void scopeBreak(int4 curexit,int4 curloopexit);
662 static bool compare(
const CaseOrder &a,
const CaseOrder &b);
664 mutable vector<CaseOrder> caseblocks;
669 FlowBlock *getSwitchBlock(
void)
const {
return getBlock(0); }
670 int4 getNumCaseBlocks(
void)
const {
return caseblocks.size(); }
671 FlowBlock *getCaseBlock(int4 i)
const {
return caseblocks[i].block; }
686 bool isDefaultCase(int4 i)
const {
return caseblocks[i].isdefault; }
687 uint4 getGotoType(int4 i)
const {
return caseblocks[i].gototype; }
688 bool isExit(int4 i)
const {
return caseblocks[i].isexit; }
690 virtual block_type getType(
void)
const {
return t_switch; }
691 virtual void markUnstructured(
void);
692 virtual void scopeBreak(int4 curexit,int4 curloopexit);
696 virtual void finalizePrinting(
Funcdata &data)
const;
707 vector<FlowBlock *> sortlist;
709 static FlowBlock *findBlock(
const vector<FlowBlock *> &list,int4 ind);
797 return (bl1->getIndex() < bl2->getIndex());
804 inline bool BlockSwitch::CaseOrder::compare(
const CaseOrder &a,
const CaseOrder &b)
807 if (a.label != b.label)
808 return (a.label < b.label);
809 return (a.depth < b.depth);
void spliceBlock(FlowBlock *bl)
Splice given FlowBlock together with its output.
Definition: block.cc:1510
void orderBlocks(void)
Definition: block.hh:334
FlowBlock(void)
Construct a block with no edges.
Definition: block.cc:50
FlowBlock * newBlock(void)
Build a new plain FlowBlock.
Definition: block.cc:1572
The base class API for emitting a high-level language.
Definition: printlanguage.hh:134
const Datatype * getSwitchType(void) const
Get the data-type of the switch variable.
Definition: block.cc:3375
void buildDomSubTree(vector< FlowBlock * > &res, FlowBlock *root) const
Collect nodes from a dominator sub-tree.
Definition: block.cc:1986
A control-flow block built out of sub-components.
Definition: block.hh:271
virtual int4 flipInPlaceTest(vector< PcodeOp * > &fliplist) const
Test normalizing the conditional branch in this.
Definition: block.cc:2267
@ f_whiledo_overflow
Set if the conditional block of a whiledo is too big to print as while(cond) { ...
Definition: block.hh:89
Description of a control-flow block containing PcodeOps.
Definition: block.hh:60
virtual void finalTransform(Funcdata &data)
Definition: block.cc:3135
@ f_goto_goto
(Block ends in) non-structured branch
Definition: block.hh:76
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:624
virtual void emitBlockCopy(const BlockCopy *bl)=0
Emit a basic block (with any labels)
BlockMultiGoto * newBlockMultiGoto(FlowBlock *bl, int4 outedge)
Build a new BlockMultiGoto.
Definition: block.cc:1633
bool restrictedByConditional(const FlowBlock *cond) const
Check if the condition from the given block holds for this block.
Definition: block.cc:381
bool isLoopDAGIn(int4 i) const
Is the i-th incoming edge part of the DAG sub-graph.
Definition: block.hh:253
int4 getInIndex(const FlowBlock *bl) const
Get the incoming edge index for the given FlowBlock.
Definition: block.cc:549
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:2614
int4 calcDepth(const FlowBlock *leaf) const
Get the depth of the given component FlowBlock.
Definition: block.cc:344
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:726
virtual void markLabelBumpUp(bool bump)
Let hierarchical blocks steal labels of their (first) components.
Definition: block.cc:3205
void clearVisitCount(void)
Clear the visit count in all node FlowBlocks.
Definition: block.cc:1846
virtual void emitBlockLs(const BlockList *bl)=0
Emit a sequence of blocks.
void calcLoop(void)
Calculate loop edges.
Definition: block.cc:2010
virtual void restoreXmlBody(List::const_iterator &iter, List::const_iterator enditer, BlockMap &resolver)
Restore details about this FlowBlock from an XML stream.
Definition: block.hh:184
@ f_mark2
A secondary mark.
Definition: block.hh:82
static bool compareFinalOrder(const FlowBlock *bl1, const FlowBlock *bl2)
Final FlowBlock comparison.
Definition: block.cc:668
virtual void markLabelBumpUp(bool bump)
Let hierarchical blocks steal labels of their (first) components.
Definition: block.cc:3095
@ f_entry_point
Official entry point of the function.
Definition: block.hh:83
static FlowBlock * findCommonBlock(FlowBlock *bl1, FlowBlock *bl2)
Find the common dominator of two FlowBlocks.
Definition: block.cc:695
A loop structure where the condition is checked at the bottom.
Definition: block.hh:618
A control-flow edge between blocks (FlowBlock)
Definition: block.hh:44
virtual void emitBlockGoto(const BlockGoto *bl)=0
Emit a block ending with a goto statement.
static block_type nameToType(const string &name)
Get the block_type associated with a name string.
Definition: block.cc:616
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:298
A map from values to control-flow targets within a function.
Definition: jumptable.hh:499
@ f_label_bumpup
Any label printed higher up in hierarchy.
Definition: block.hh:86
void restoreXmlEdges(List::const_iterator &iter, List::const_iterator enditer, BlockMap &resolver)
Restore edges from an XML stream.
Definition: block.cc:2376
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:1240
bool hasLoopOut(void) const
Is there a looping edge going out of this block.
Definition: block.cc:407
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:3411
void structureLoops(vector< FlowBlock * > &rootlist)
Label loop edges.
Definition: block.cc:2100
void removeFromFlowSplit(FlowBlock *bl, bool flipflow)
Remove FlowBlock splitting flow between input and output edges.
Definition: block.cc:1488
bool inRange(const Address &addr, int4 size) const
Check containment an address range.
Definition: address.cc:402
@ f_unstructured_targ
Block is destination of unstructured goto.
Definition: block.hh:80
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:3255
void swapBlocks(int4 i, int4 j)
Swap the positions two component FlowBlocks.
Definition: block.cc:1150
virtual void flipInPlaceExecute(void)
Perform the flip to normalize conditional branch executed by this block.
Definition: block.cc:2787
virtual void finalizePrinting(Funcdata &data) const
Definition: block.cc:3182
const FlowBlock * nextInFlow(void) const
Return next block to be executed in flow.
Definition: block.cc:2420
virtual FlowBlock * getSplitPoint(void)
Get the leaf splitting block.
Definition: block.hh:745
@ f_forward_edge
An edge that jumps forward in the spanning tree.
Definition: block.hh:101
@ f_break_goto
Block ends with a break;.
Definition: block.hh:77
virtual void emitBlockIf(const BlockIf *bl)=0
Emit an if/else style construct.
virtual void emitBlockWhileDo(const BlockWhileDo *bl)=0
Emit a loop structure, check at top.
BlockList * newBlockList(const vector< FlowBlock * > &nodes)
Build a new BlockList.
Definition: block.cc:1664
static string typeToName(block_type bt)
Get the name string associated with a block_type.
Definition: block.cc:630
Classes to support jump-tables and their recovery.
virtual void emitBlockDoWhile(const BlockDoWhile *bl)=0
Emit a loop structure, check at bottom.
BlockInfLoop * newBlockInfLoop(FlowBlock *body)
Build a new BlockInfLoop.
Definition: block.cc:1795
virtual void printTree(ostream &s, int4 level) const
Print tree structure of any blocks owned by this.
Definition: block.cc:586
@ f_flip_path
If true, out edges have been flipped since last time path was traced.
Definition: block.hh:90
list< PcodeOp * >::const_iterator endOp(OpCode opc) const
End of PcodeOp objects with the given op-code.
Definition: funcdata.hh:458
BlockCondition * newBlockCondition(FlowBlock *b1, FlowBlock *b2)
Build a new BlockCondition.
Definition: block.cc:1686
@ f_mark
Generic way to mark a block.
Definition: block.hh:81
BlockWhileDo * newBlockWhileDo(FlowBlock *cond, FlowBlock *cl)
Build a new BlockWhileDo.
Definition: block.cc:1764
int4 getOutIndex(const FlowBlock *bl) const
Get the outgoing edge index for the given FlowBlock.
Definition: block.cc:562
virtual void markLabelBumpUp(bool bump)
Let hierarchical blocks steal labels of their (first) components.
Definition: block.cc:3233
void grabCaseBasic(FlowBlock *switchbl, const vector< FlowBlock * > &cs)
Build annotated CaseOrder objects.
Definition: block.cc:3303
bool isDoNothing(void) const
Should this block should be removed.
Definition: block.cc:2502
BlockDoWhile * newBlockDoWhile(FlowBlock *condcl)
Build a new BlockDoWhile.
Definition: block.cc:1780
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:2703
@ f_loop_edge
Edge completes a loop, removing these edges gives you a DAG.
Definition: block.hh:97
virtual int4 flipInPlaceTest(vector< PcodeOp * > &fliplist) const
Test normalizing the conditional branch in this.
Definition: block.cc:2769
FlowBlock * getStartBlock(void) const
Get the entry point FlowBlock.
Definition: block.cc:1562
uintb getLabel(int4 i, int4 j) const
Get a specific label associated with a case block.
Definition: block.hh:684
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:2832
@ f_interior_gotoout
The block has an unstructured jump out of interior.
Definition: block.hh:84
An XML element. A node in the DOM tree.
Definition: xml.hh:150
A basic block for p-code operations.
Definition: block.hh:365
bool unblockedMulti(int4 outslot) const
Check if this block can be removed without introducing inconsistencies.
Definition: block.cc:2440
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:2906
static bool noInterveningStatement(PcodeOp *first, int4 path, PcodeOp *last)
Check if there is meaningful activity between two branch instructions.
Definition: block.cc:2598
Lowest level operation of the p-code language.
Definition: op.hh:58
void buildCopy(const BlockGraph &graph)
Build a copy of a BlockGraph.
Definition: block.cc:1831
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:526
BlockGoto * newBlockGoto(FlowBlock *bl)
Build a new BlockGoto.
Definition: block.cc:1615
void saveXml(ostream &s) const
Save the edge to an XML stream.
Definition: block.cc:22
virtual FlowBlock * getSplitPoint(void)
Get the leaf splitting block.
Definition: block.hh:432
void removeFromFlow(FlowBlock *bl)
Remove given FlowBlock preserving flow in this.
Definition: block.cc:1458
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:3111
A block with multiple edges out, at least one of which is an unstructured (goto) branch.
Definition: block.hh:470
void setStartBlock(FlowBlock *bl)
Set the entry point FlowBlock for this graph.
Definition: block.cc:1538
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:3120
uint4 label
Label of the edge.
Definition: block.hh:45
block_type
The possible block types.
Definition: block.hh:64
@ f_defaultswitch_edge
This is default edge from switchblock.
Definition: block.hh:98
virtual bool negateCondition(bool toporbottom)
Flip the condition computed by this.
Definition: block.cc:2250
void restoreXml(const Element *el, BlockMap &resolver)
Restore this from an XML stream.
Definition: block.cc:2406
static void markCopyBlock(FlowBlock *bl, uint4 fl)
Set properties on the first leaf FlowBlock.
Definition: block.cc:1162
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:3227
bool hasLoopIn(void) const
Is there a looping edge coming into this block.
Definition: block.cc:398
An infinite loop structure.
Definition: block.hh:632
A disjoint set of Ranges, possibly across multiple address spaces.
Definition: address.hh:203
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:501
virtual void printTree(ostream &s, int4 level) const
Print tree structure of any blocks owned by this.
Definition: block.cc:2621
virtual void saveXmlHeader(ostream &s) const
Save basic information as XML attributes.
Definition: block.cc:2838
virtual bool preferComplement(Funcdata &data)
Rearrange this hierarchy to simplify boolean expressions.
Definition: block.cc:2872
void removeBlock(FlowBlock *bl)
Remove a FlowBlock from this BlockGraph.
Definition: block.cc:1430
void printRaw(ostream &s) const
Print raw p-code op descriptions to a stream.
Definition: funcdata.cc:193
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:2762
int4 getNumLabels(int4 i) const
Get the number of labels associated with one case block.
Definition: block.hh:677
A block that terminates with an unstructured (goto) branch to another block.
Definition: block.hh:444
edge_flags
Boolean properties on edges.
Definition: block.hh:95
@ f_interior_gotoin
Block is target of unstructured jump to its interior.
Definition: block.hh:85
int4 numIndicesByBlock(const FlowBlock *bl) const
Return the number of address table entries that target the given basic-block.
Definition: jumptable.cc:2268
virtual void saveXmlHeader(ostream &s) const
Save basic information as XML attributes.
Definition: block.cc:2346
virtual void emitBlockCondition(const BlockCondition *bl)=0
Emit a conditional statement.
BlockMap(const BlockMap &op2)
Copy constructor.
Definition: block.cc:3437
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:3418
virtual bool preferComplement(Funcdata &data)
Rearrange this hierarchy to simplify boolean expressions.
Definition: block.hh:735
@ f_dead
Block is in process of being deleted.
Definition: block.hh:88
void collectReachable(vector< FlowBlock * > &res, FlowBlock *bl, bool un) const
Collect reachable/unreachable FlowBlocks from a given start FlowBlock.
Definition: block.cc:2060
void restoreXml(const Element *el, const AddrSpaceManager *m)
Restore this BlockGraph from an XML stream.
Definition: block.cc:1342
virtual void emitBlockGraph(const BlockGraph *bl)=0
Emit (an unspecified) list of blocks.
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:2820
@ f_joined_block
Block is a merged form of original basic blocks.
Definition: block.hh:91
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:2710
virtual bool negateCondition(bool toporbottom)
Flip the condition computed by this.
Definition: block.cc:282
void merge(const RangeList &op2)
Merge another RangeList into this.
Definition: address.cc:385
BlockCopy * newBlockCopy(FlowBlock *bl)
Build a new BlockCopy.
Definition: block.cc:1594
@ f_goto_edge
Edge is unstructured.
Definition: block.hh:96
@ f_donothing_loop
Block does nothing in infinite loop (halt)
Definition: block.hh:87
virtual void saveXmlHeader(ostream &s) const
Save basic information as XML attributes.
Definition: block.cc:2627
void setGotoBranch(int4 i)
Mark a goto branch.
Definition: block.cc:293
A low-level machine address for labelling bytes and data.
Definition: address.hh:46
BlockSwitch * newBlockSwitch(const vector< FlowBlock * > &cs, bool hasExit)
Build a new BlockSwitch.
Definition: block.cc:1810
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:3248
Address getEntryAddr(void) const
Get the address of the (original) first operation to execute.
Definition: block.cc:2208
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:694
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:2865
Container for data structures associated with a single function.
Definition: funcdata.hh:45
The base datatype class for the decompiler.
Definition: type.hh:62
A series of blocks that execute in sequence.
Definition: block.hh:497
virtual FlowBlock * getSplitPoint(void)
Get the leaf splitting block.
Definition: block.cc:2260
@ f_switch_out
Output is decided by switch.
Definition: block.hh:79
void clear(void)
Clear all component FlowBlock objects.
Definition: block.cc:1168
bool isDecisionIn(int4 i) const
Can this and the i-th input be merged into a BlockIf or BlockList.
Definition: block.hh:247
int4 buildDomDepth(vector< int4 > &depth) const
Calculate dominator depths.
Definition: block.cc:1962
void moveOutEdge(FlowBlock *blold, int4 slot, FlowBlock *blnew)
Move indicated out edge to a new FlowBlock.
Definition: block.cc:1415
void addLoopEdge(FlowBlock *begin, int4 outindex)
Mark a given edge as a loop edge.
Definition: block.cc:1364
virtual void restoreXmlHeader(const Element *el)
Restore basic information for XML attributes.
Definition: block.cc:2353
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:2565
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:457
virtual void printTree(ostream &s, int4 level) const
Print tree structure of any blocks owned by this.
Definition: block.cc:1219
bool isDecisionOut(int4 i) const
Can this and the i-th output be merged into a BlockIf or BlockList.
Definition: block.hh:244
FlowBlock * findLevelBlock(int4 index) const
Find the FlowBlock matching the given index.
Definition: block.hh:720
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:608
BlockIf * newBlockIfGoto(FlowBlock *cond)
Build a new BlockIfGoto.
Definition: block.cc:1705
list< PcodeOp * >::const_iterator beginOp(OpCode opc) const
Start of PcodeOp objects with the given op-code.
Definition: funcdata.hh:455
virtual void flipInPlaceExecute(void)
Perform the flip to normalize conditional branch executed by this block.
Definition: block.hh:772
FlowBlock * createBlock(const string &name)
Create a FlowBlock of the named type.
Definition: block.cc:3494
A loop structure where the condition is checked at the top.
Definition: block.hh:590
BlockSwitch(FlowBlock *ind)
Construct given the multi-exit root block.
Definition: block.cc:3264
void calcForwardDominator(const vector< FlowBlock * > &rootlist)
Calculate forward dominators.
Definition: block.cc:1860
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:574
OpCode
The op-code defining a specific p-code operation (PcodeOp)
Definition: opcodes.hh:35
int4 getIndexByBlock(const FlowBlock *bl, int4 i) const
Get the index of the i-th address table entry that corresponds to the given basic-block.
Definition: jumptable.cc:2315
A basic "if" block.
Definition: block.hh:555
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:485
virtual void emitBlockSwitch(const BlockSwitch *bl)=0
Emit a switch structure.
virtual bool negateCondition(bool toporbottom)
Flip the condition computed by this.
Definition: block.cc:2802
Helper class for resolving cross-references while deserializing BlockGraph objects.
Definition: block.hh:705
void removeEdge(FlowBlock *begin, FlowBlock *end)
Remove an edge between component FlowBlocks.
Definition: block.cc:1382
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:428
BlockIf * newBlockIf(FlowBlock *cond, FlowBlock *tc)
Build a new BlockIf.
Definition: block.cc:1728
const FlowBlock * getFrontLeaf(void) const
Get the first leaf FlowBlock.
Definition: block.cc:316
void restoreXml(const Element *el, BlockMap &resolver)
Restore this edge from an XML stream.
Definition: block.cc:34
void addEdge(FlowBlock *begin, FlowBlock *end)
Add a directed edge between component FlowBlocks.
Definition: block.cc:1352
@ f_cross_edge
An edge that crosses subtrees in the spanning tree.
Definition: block.hh:102
bool dominates(const FlowBlock *subBlock) const
Does this block dominate the given block.
Definition: block.cc:362
@ f_continue_goto
Block ends with a continue;.
Definition: block.hh:78
@ f_tree_edge
An edge in the spanning tree.
Definition: block.hh:100
int4 reverse_index
Index for edge coming other way.
Definition: block.hh:47
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:567
bool hasOnlyMarkers(void) const
Does this block contain only MULTIEQUAL and INDIRECT ops.
Definition: block.cc:2484
virtual void emitBlockBasic(const BlockBasic *bb)=0
Emit statements in a basic block.
virtual void restoreXmlBody(List::const_iterator &iter, List::const_iterator enditer, BlockMap &resolver)
Restore details about this FlowBlock from an XML stream.
Definition: block.cc:2558
virtual void emitBlockInfLoop(const BlockInfLoop *bl)=0
Emit an infinite loop structure.
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:390
block_flags
Boolean properties of blocks.
Definition: block.hh:75
JumpTable * getJumptable(void) const
Get the JumpTable associated this block.
Definition: block.cc:600
virtual bool negateCondition(bool toporbottom)
Flip the condition computed by this.
Definition: block.hh:431
@ f_irreducible
Edge which must be removed to make graph reducible.
Definition: block.hh:99
BlockBasic * newBlockBasic(Funcdata *fd)
Build a new BlockBasic.
Definition: block.cc:1583
virtual void markLabelBumpUp(bool bump)
Let hierarchical blocks steal labels of their (first) components.
Definition: block.cc:1187
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.hh:785
bool isLoopDAGOut(int4 i) const
Is the i-th outgoing edge part of the DAG sub-graph.
Definition: block.hh:250
@ f_duplicate_block
Block is a duplicated version of an original basic block.
Definition: block.hh:92
bool gotoPrints(void) const
Should a formal goto statement be emitted.
Definition: block.cc:2660
virtual bool negateCondition(bool toporbottom)
Flip the condition computed by this.
Definition: block.cc:2746
bool isJumpTarget(void) const
Return true if non-fallthru jump flows into this.
Definition: block.cc:305
A manager for different address spaces.
Definition: translate.hh:218
virtual int4 flipInPlaceTest(vector< PcodeOp * > &fliplist) const
Test normalizing the conditional branch in this.
Definition: block.hh:762
virtual void markLabelBumpUp(bool bump)
Let hierarchical blocks steal labels of their (first) components.
Definition: block.cc:247
virtual void restoreXmlBody(List::const_iterator &iter, List::const_iterator enditer, BlockMap &resolver)
Restore details about this FlowBlock from an XML stream.
Definition: block.cc:1306
Two conditional blocks combined into one conditional using BOOL_AND or BOOL_OR.
Definition: block.hh:518
virtual void flipInPlaceExecute(void)
Perform the flip to normalize conditional branch executed by this block.
Definition: block.cc:2277
BlockIf * newBlockIfElse(FlowBlock *cond, FlowBlock *tc, FlowBlock *fc)
Build a new BlockIfElse.
Definition: block.cc:1746
@ f_loop_exit_edge
Edge exits the body of a loop.
Definition: block.hh:104
@ f_back_edge
Within (reducible) graph, a back edge defining a loop.
Definition: block.hh:103
void sortList(void)
Sort the list of FlowBlock objects.
Definition: block.cc:3484
virtual void emit(PrintLanguage *lng) const
Emit the instructions in this FlowBlock as structured code.
Definition: block.hh:638
virtual FlowBlock * getSplitPoint(void)
Get the leaf splitting block.
Definition: block.hh:528
void saveXml(ostream &s) const
Write out this to an XML stream.
Definition: block.cc:2390
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:3220
virtual void printHeader(ostream &s) const
Print a simple description of this to stream.
Definition: block.cc:2671
void saveXmlEdges(ostream &s) const
Save edge information to an XML stream.
Definition: block.cc:2363
A structured switch construction.
Definition: block.hh:649
virtual FlowBlock * nextFlowAfter(const FlowBlock *bl) const
Get the leaf FlowBlock that will execute after the given FlowBlock.
Definition: block.cc:2678
void buildDomTree(vector< vector< FlowBlock * > > &child) const
Build the dominator tree.
Definition: block.cc:1942
FlowBlock * point
Other end of the edge.
Definition: block.hh:46
This class is used to mirror the BlockBasic objects in the fixed control-flow graph for a function.
Definition: block.hh:419
virtual FlowBlock * getSplitPoint(void)
Get the leaf splitting block.
Definition: block.cc:2755
void switchEdge(FlowBlock *in, FlowBlock *outbefore, FlowBlock *outafter)
Move an edge from one out FlowBlock to another.
Definition: block.cc:1402
static bool compareBlockIndex(const FlowBlock *bl1, const FlowBlock *bl2)
Compare FlowBlock by index.
Definition: block.hh:794