cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
interval_analysis.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Interval Analysis
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
13
14
#include "
interval_analysis.h
"
15
16
#include <
util/find_symbols.h
>
17
18
#include "
ai.h
"
19
#include "
interval_domain.h
"
20
30
void
instrument_intervals
(
31
const
ait<interval_domaint>
&
interval_analysis
,
32
goto_functionst::goto_functiont
&goto_function)
33
{
34
std::set<symbol_exprt> symbols;
35
36
for
(
const
auto
&i : goto_function.body.instructions)
37
i.apply([&symbols](
const
exprt
&e) {
find_symbols
(e, symbols); });
38
39
Forall_goto_program_instructions
(i_it, goto_function.body)
40
{
41
if
(i_it==goto_function.body.instructions.begin())
42
{
43
// first instruction, we instrument
44
}
45
else
46
{
47
goto_programt::const_targett
previous = std::prev(i_it);
48
49
if
(previous->is_goto() && previous->condition() !=
true
)
50
{
51
// we follow a branch, instrument
52
}
53
else
if
(previous->is_function_call())
54
{
55
// we follow a function call, instrument
56
}
57
else
if
(i_it->is_target() || i_it->is_function_call())
58
{
59
// we are a target or a function call, instrument
60
}
61
else
62
continue
;
// don't instrument
63
}
64
65
const
interval_domaint
&d=
interval_analysis
[i_it];
66
67
exprt::operandst
assertion;
68
69
for
(
const
auto
&symbol_expr : symbols)
70
{
71
exprt
tmp=d.
make_expression
(symbol_expr);
72
if
(tmp !=
true
)
73
assertion.push_back(tmp);
74
}
75
76
if
(!assertion.empty())
77
{
78
goto_programt::targett
t=i_it;
79
goto_function.body.insert_before_swap(i_it);
80
i_it++;
// goes to original instruction
81
*t =
goto_programt::make_assumption
(
82
conjunction
(assertion), i_it->
source_location
());
83
}
84
}
85
}
86
90
void
interval_analysis
(
goto_modelt
&goto_model)
91
{
92
ait<interval_domaint>
interval_analysis
;
93
94
const
namespacet
ns(goto_model.
symbol_table
);
95
interval_analysis
(goto_model.
goto_functions
, ns);
96
97
for
(
auto
&gf_entry : goto_model.
goto_functions
.
function_map
)
98
instrument_intervals
(
interval_analysis
, gf_entry.second);
99
}
ai.h
Abstract Interpretation.
ait
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition
ai.h:566
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::operandst
std::vector< exprt > operandst
Definition
expr.h:59
exprt::source_location
const source_locationt & source_location() const
Definition
expr.h:236
goto_functionst::function_map
function_mapt function_map
Definition
goto_functions.h:29
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition
goto_functions.h:27
goto_modelt
Definition
goto_model.h:27
goto_modelt::symbol_table
symbol_tablet symbol_table
Symbol table.
Definition
goto_model.h:31
goto_modelt::goto_functions
goto_functionst goto_functions
GOTO functions.
Definition
goto_model.h:34
goto_programt::make_assumption
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
Definition
goto_program.h:944
goto_programt::targett
instructionst::iterator targett
Definition
goto_program.h:613
goto_programt::const_targett
instructionst::const_iterator const_targett
Definition
goto_program.h:614
interval_domaint
Definition
interval_domain.h:24
interval_domaint::make_expression
exprt make_expression(const symbol_exprt &) const
Definition
interval_domain.cpp:408
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition
namespace.h:91
find_symbols
static bool find_symbols(symbol_kindt, const typet &, std::function< bool(const symbol_exprt &)>, std::unordered_set< irep_idt > &bindings, const std::vector< irep_idt > &subs_to_find)
Find identifiers with id ID_symbol of the sub expressions and the subs with ID in subs_to_find consid...
Definition
find_symbols.cpp:152
find_symbols.h
Forall_goto_program_instructions
#define Forall_goto_program_instructions(it, program)
Definition
goto_program.h:1233
interval_analysis
void interval_analysis(goto_modelt &goto_model)
Initialises the abstract interpretation over interval domain and instruments instructions using inter...
Definition
interval_analysis.cpp:90
instrument_intervals
void instrument_intervals(const ait< interval_domaint > &interval_analysis, goto_functionst::goto_functiont &goto_function)
Instruments all "post-branch" instructions with assumptions about variable intervals.
Definition
interval_analysis.cpp:30
interval_analysis.h
Interval Analysis.
interval_domain.h
Interval Domain.
conjunction
exprt conjunction(exprt a, exprt b)
Conjunction of two expressions.
Definition
std_expr.cpp:252
analyses
interval_analysis.cpp
Generated by
1.17.0