CBMC
Loading...
Searching...
No Matches
cover_basic_blocks.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Coverage Instrumentation
4
5Author: Daniel Kroening
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_GOTO_INSTRUMENT_COVER_BASIC_BLOCKS_H
13#define CPROVER_GOTO_INSTRUMENT_COVER_BASIC_BLOCKS_H
14
16
17#include "source_lines.h"
18
20
22{
23public:
24 virtual ~cover_blocks_baset() = default;
27 // part of
28 virtual std::size_t block_of(goto_programt::const_targett t) const = 0;
29
33 virtual std::optional<goto_programt::const_targett>
34 instruction_of(std::size_t block_nr) const = 0;
35
39 virtual const source_locationt &
40 source_location_of(std::size_t block_nr) const = 0;
41
44 virtual const source_linest &source_lines_of(std::size_t block_nr) const = 0;
45
47 virtual void output(std::ostream &out) const = 0;
48
54 const irep_idt &function_id,
55 const goto_programt &goto_program,
56 message_handlert &message_handler)
57 {
58 // unused parameters
59 (void)function_id;
60 (void)goto_program;
61 (void)message_handler;
62 }
63};
64
66{
67public:
68 explicit cover_basic_blockst(const goto_programt &goto_program);
69
73 std::size_t block_of(goto_programt::const_targett t) const override;
74
78 std::optional<goto_programt::const_targett>
79 instruction_of(std::size_t block_nr) const override;
80
84 const source_locationt &
85 source_location_of(std::size_t block_nr) const override;
86
89 const source_linest &source_lines_of(std::size_t block_nr) const override;
90
96 const irep_idt &function_id,
97 const goto_programt &goto_program,
98 message_handlert &message_handler) override;
99
101 void output(std::ostream &out) const override;
102
103private:
104 typedef std::map<
106 std::size_t,
109
111 {
113 std::optional<goto_programt::const_targett> representative_inst;
114
119
122 };
123
127 std::vector<block_infot> block_infos;
128
130 static void add_block_lines(
132 const goto_programt::instructiont &instruction);
133
136 static std::optional<std::size_t> continuation_of_block(
137 const goto_programt::const_targett &instruction,
139};
140
142{
143private:
144 // map block number to first instruction of the block
145 std::vector<goto_programt::const_targett> block_infos;
146 // map block number to its location
147 std::vector<source_locationt> block_locations;
148 // map java indexes to block indexes
149 std::unordered_map<irep_idt, std::size_t> index_to_block;
150 // map block number to its source lines
151 std::vector<source_linest> block_source_lines;
152
153public:
155
158 std::size_t block_of(goto_programt::const_targett t) const override;
159
162 std::optional<goto_programt::const_targett>
163 instruction_of(std::size_t block_number) const override;
164
167 const source_locationt &
168 source_location_of(std::size_t block_number) const override;
169
172 const source_linest &source_lines_of(std::size_t block_number) const override;
173
175 void output(std::ostream &out) const override;
176};
177
178#endif // CPROVER_GOTO_INSTRUMENT_COVER_BASIC_BLOCKS_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
std::vector< goto_programt::const_targett > block_infos
const source_locationt & source_location_of(std::size_t block_number) const override
std::vector< source_locationt > block_locations
void output(std::ostream &out) const override
Outputs the list of blocks.
std::size_t block_of(goto_programt::const_targett t) const override
const source_linest & source_lines_of(std::size_t block_number) const override
std::vector< source_linest > block_source_lines
std::optional< goto_programt::const_targett > instruction_of(std::size_t block_number) const override
std::unordered_map< irep_idt, std::size_t > index_to_block
void output(std::ostream &out) const override
Outputs the list of blocks.
std::optional< goto_programt::const_targett > instruction_of(std::size_t block_nr) const override
static std::optional< std::size_t > continuation_of_block(const goto_programt::const_targett &instruction, block_mapt &block_map)
If this block is a continuation of a previous block through unconditional forward gotos,...
std::map< goto_programt::const_targett, std::size_t, goto_programt::target_less_than > block_mapt
std::vector< block_infot > block_infos
map block numbers to block information
void report_block_anomalies(const irep_idt &function_id, const goto_programt &goto_program, message_handlert &message_handler) override
Output warnings about ignored blocks.
const source_linest & source_lines_of(std::size_t block_nr) const override
std::size_t block_of(goto_programt::const_targett t) const override
static void add_block_lines(cover_basic_blockst::block_infot &block, const goto_programt::instructiont &instruction)
Adds the lines which instruction spans to block.
const source_locationt & source_location_of(std::size_t block_nr) const override
block_mapt block_map
map program locations to block numbers
virtual void report_block_anomalies(const irep_idt &function_id, const goto_programt &goto_program, message_handlert &message_handler)
Output warnings about ignored blocks.
virtual void output(std::ostream &out) const =0
Outputs the list of blocks.
virtual ~cover_blocks_baset()=default
virtual const source_linest & source_lines_of(std::size_t block_nr) const =0
virtual std::optional< goto_programt::const_targett > instruction_of(std::size_t block_nr) const =0
virtual const source_locationt & source_location_of(std::size_t block_nr) const =0
virtual std::size_t block_of(goto_programt::const_targett t) const =0
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
This class represents an instruction in the GOTO intermediate representation.
A generic container class for the GOTO intermediate representation of one function.
instructionst::const_iterator const_targett
Concrete Goto Program.
Set of source code lines contributing to a basic block.
std::optional< goto_programt::const_targett > representative_inst
the program location to instrument for this block
source_locationt source_location
the source location representative for this block (we need a separate copy of source locations becaus...
source_linest source_lines
the set of source code lines belonging to this block
A total order over targett and const_targett.