25 #include "print_instruction_seq.h"
26 #include "highlevel_formatter.h"
27 #include "lowlevel_formatter.h"
62 template<
typename Formatter,
typename BlockAnnotator = DefaultBlockAnnotator>
66 BlockAnnotator m_annotator;
67 std::shared_ptr<ControlFlowGraph> m_cfg;
76 BlockAnnotator annotator = BlockAnnotator());
98 template<
typename BlockAnnotator = DefaultBlockAnnotator>
116 template<
typename BlockAnnotator = DefaultBlockAnnotator>
126 template<
typename Formatter,
typename BlockAnnotator>
129 BlockAnnotator annotator)
130 : m_formatter(formatter)
131 , m_annotator(annotator)
135 template<
typename Formatter,
typename BlockAnnotator>
139 template<
typename Formatter,
typename BlockAnnotator>
141 for (
auto i = m_cfg->bb_begin(); i != m_cfg->bb_end(); i++) {
142 std::shared_ptr<InstructionSequence> bb = *i;
145 std::string begin_str;
146 begin_str +=
"BASIC BLOCK ";
147 begin_str += std::to_string(bb->get_block_id());
151 if (bb->has_block_label()) {
152 begin_str +=
" (label ";
153 begin_str += bb->get_block_label();
156 std::string begin_annotation = m_annotator.get_block_begin_annotation(bb);
157 if (!begin_annotation.empty()) {
158 if (begin_str.size() < 37)
159 begin_str += (
" " + begin_str.size());
161 begin_str += begin_annotation;
164 printf(
"%s\n", begin_str.c_str());
168 print_ins_seq.print(bb);
172 for (
auto j = outgoing_edges.cbegin(); j != outgoing_edges.cend(); j++) {
175 printf(
" %s EDGE to BASIC BLOCK %u\n", e->
get_kind() == EDGE_FALLTHROUGH ?
"fall-through" :
"branch", e->
get_target()->get_block_id());
179 std::string end_annotation = m_annotator.get_block_end_annotation(bb);
180 if (!end_annotation.empty())
181 printf(
" At end of block: /* %s */\n", end_annotation.c_str());
ControlFlowGraph and associated types.
ControlFlowGraphPrinter< HighLevelFormatter, BlockAnnotator > make_highlevel_cfg_printer(const std::shared_ptr< ControlFlowGraph > &hl_cfg, BlockAnnotator annotator=BlockAnnotator())
Create a ControlFlowGraphPrinter for printing a high-level ControlFlowGraph.
Definition: cfg_printer.h:100
ControlFlowGraphPrinter< LowLevelFormatter, BlockAnnotator > make_lowlevel_cfg_printer(const std::shared_ptr< ControlFlowGraph > &ll_cfg, BlockAnnotator annotator=BlockAnnotator())
Create a ControlFlowGraphPrinter for printing a low-level ControlFlowGraph.
Definition: cfg_printer.h:118
Print a textual representation of a ControlFlowGraph.
Definition: cfg_printer.h:63
ControlFlowGraphPrinter(const std::shared_ptr< ControlFlowGraph > &cfg, Formatter formatter=Formatter(), BlockAnnotator annotator=BlockAnnotator())
Constructor.
Definition: cfg_printer.h:127
void print()
Print the ControlFlowGraph to the standard output.
Definition: cfg_printer.h:140
std::vector< Edge * > EdgeList
Data type for a vector of edges.
Definition: cfg.h:92
Default annotator for printing a control flow graph.
Definition: cfg_printer.h:35
virtual std::string get_block_begin_annotation(std::shared_ptr< InstructionSequence > bb) const
Get a begin annotation for a basic block.
Definition: cfg_printer.h:42
virtual std::string get_block_end_annotation(std::shared_ptr< InstructionSequence > bb) const
Get an end annotation for a basic block.
Definition: cfg_printer.h:51
Definition: print_instruction_seq.h:28
Control-flow graph edge data type.
Definition: cfg.h:56
EdgeKind get_kind() const
Get the EdgeKind of this Edge.
Definition: cfg.h:71
std::shared_ptr< InstructionSequence > get_target() const
Get the target basic block.
Definition: cfg.h:79
Definition: print_instruction_seq.h:43
BasicBlockKind
Kinds of basic blocks.
Definition: instruction_seq.h:39
@ BASICBLOCK_INTERIOR
normal basic block in the "interior" of the CFG
Definition: instruction_seq.h:42
@ BASICBLOCK_ENTRY
special "entry" block
Definition: instruction_seq.h:40