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

A class for sorting comments into and within basic blocks. More...

#include <comment.hh>

Public Types

enum  { header_basic = 0, header_unplaced = 1 }
 

Public Member Functions

void setupFunctionList (uint4 tp, const Funcdata *fd, const CommentDatabase &db, bool displayUnplaced)
 Collect and sort comments specific to the given function. More...
 
void setupBlockList (const FlowBlock *bl)
 Prepare to walk comments from a single basic block. More...
 
void setupOpList (const PcodeOp *op)
 Establish a p-code landmark within the current set of comments. More...
 
void setupHeader (uint4 headerType)
 Prepare to walk comments in the header. More...
 

Detailed Description

A class for sorting comments into and within basic blocks.

The decompiler endeavors to display comments within the flow of the source code statements it generates. Comments should be placed at or near the statement that encompasses the address of the original instruction to which the comment is attached. This is complicated by the fact that instructions may get removed and transformed during decompilation and even whole basic blocks may get removed.

This class sorts comments into the basic block that contains it. As statements are emitted, comments can get picked up, in the correct order, even if there is no longer a specific p-code operation at the comment's address. The decompiler maintains information about basic blocks that have been entirely removed, in which case, the user can elect to not display the corresponding comments.

This class also acts as state for walking comments within a specific basic block or within the header.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
header_basic 

Basic header comments.

header_unplaced 

Comment that can't be placed in code flow.

Member Function Documentation

◆ setupBlockList()

void CommentSorter::setupBlockList ( const FlowBlock bl)

Prepare to walk comments from a single basic block.

Find iterators that bound everything in the basic block

Parameters
blis the basic block

◆ setupFunctionList()

void CommentSorter::setupFunctionList ( uint4  tp,
const Funcdata fd,
const CommentDatabase db,
bool  displayUnplaced 
)

Collect and sort comments specific to the given function.

Only keep comments matching one of a specific set of properties

Parameters
tpis the set of properties (may be zero)
fdis the given function
dbis the container of comments to collect from
displayUnplacedis true if unplaced comments should be displayed in the header

◆ setupHeader()

void CommentSorter::setupHeader ( uint4  headerType)

Prepare to walk comments in the header.

Header comments are grouped together. Set up iterators.

Parameters
headerTypeselects either header_basic or header_unplaced comments

◆ setupOpList()

void CommentSorter::setupOpList ( const PcodeOp op)

Establish a p-code landmark within the current set of comments.

This will generally get called with the root p-code op of a statement being emitted by the decompiler. This establishes a key value within the basic block, so it is known where to stop emitting comments within the block for emitting the statement.

Parameters
opis the p-code representing the root of a statement

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