Skip to content

Commit 4150aaa

Browse files
Pull continuation_of_block function out
We pull this function out of the cover_basic_blockst constructor, as the constructor is rather long, and having a function for this part makes this part of the code clearer.
1 parent e47744d commit 4150aaa

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/goto-instrument/cover_basic_blocks.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ Author: Peter Schrammel
1919
/// location of basic block, compress to ranges if applicable
2020
static void update_covered_lines(cover_basic_blockst::block_infot &block_info);
2121

22+
/// If this block is a continuation of a previous block through unconditional
23+
/// forward gotos, return this blocks number.
24+
static optionalt<unsigned> continuation_of_block(
25+
const goto_programt::const_targett &instruction,
26+
std::map<goto_programt::const_targett, unsigned> &block_map)
27+
{
28+
if(instruction->incoming_edges.size() != 1)
29+
return {};
30+
31+
const goto_programt::targett in_t = *instruction->incoming_edges.cbegin();
32+
if(in_t->is_goto() && !in_t->is_backwards_goto() && in_t->guard.is_true())
33+
return block_map[in_t];
34+
35+
return {};
36+
}
37+
2238
cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
2339
{
2440
bool next_is_target = true;
@@ -29,25 +45,13 @@ cover_basic_blockst::cover_basic_blockst(const goto_programt &_goto_program)
2945
// Is it a potential beginning of a block?
3046
if(next_is_target || it->is_target())
3147
{
32-
// We keep the block number if this potential block
33-
// is a continuation of a previous block through
34-
// unconditional forward gotos; otherwise we increase the
35-
// block number.
36-
bool increase_block_nr = true;
37-
if(it->incoming_edges.size() == 1)
48+
if(auto block_number = continuation_of_block(it, block_map))
3849
{
39-
goto_programt::targett in_t = *it->incoming_edges.begin();
40-
if(
41-
in_t->is_goto() && !in_t->is_backwards_goto() &&
42-
in_t->guard.is_true())
43-
{
44-
current_block = block_map[in_t];
45-
increase_block_nr = false;
46-
}
50+
current_block = *block_number;
4751
}
48-
if(increase_block_nr)
52+
else
4953
{
50-
block_infos.push_back(block_infot());
54+
block_infos.emplace_back();
5155
block_infos.back().representative_inst = it;
5256
block_infos.back().source_location = source_locationt::nil();
5357
current_block = block_infos.size() - 1;

0 commit comments

Comments
 (0)