Skip to content

Commit 686c9e4

Browse files
martinmartin-cs
authored andcommitted
Port value_set_analysist and value_set_domain to the ai framework
This removes the last in-tree use of static_analysis.{h,cpp}. It also gives the option of using value_set_domain with the history options to perform per-path value-set analysis.
1 parent 3ebd7f0 commit 686c9e4

File tree

8 files changed

+150
-163
lines changed

8 files changed

+150
-163
lines changed

jbmc/unit/pointer-analysis/custom_value_set_analysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ SCENARIO("test_value_set_analysis",
198198
std::prev(test_function.instructions.end());
199199

200200
value_set_analysist normal_analysis(ns);
201-
normal_analysis(goto_model.goto_functions);
201+
normal_analysis(TEST_FUNCTION_NAME, test_function, ns);
202202
const auto &normal_function_end_vs=
203203
normal_analysis[test_function_end].value_set;
204204

205205
test_value_set_analysist test_analysis(ns);
206-
test_analysis(goto_model.goto_functions);
206+
test_analysis(TEST_FUNCTION_NAME, test_function, ns);
207207
const auto &test_function_end_vs=
208208
test_analysis[test_function_end].value_set;
209209

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int goto_instrument_parse_optionst::doit()
319319
log.status() << "Pointer Analysis" << messaget::eom;
320320
namespacet ns(goto_model.symbol_table);
321321
value_set_analysist value_set_analysis(ns);
322-
value_set_analysis(goto_model.goto_functions);
322+
value_set_analysis(goto_model);
323323
show_value_sets(
324324
ui_message_handler.get_ui(), goto_model, value_set_analysis);
325325
return CPROVER_EXIT_SUCCESS;
@@ -550,7 +550,7 @@ int goto_instrument_parse_optionst::doit()
550550

551551
log.status() << "Pointer Analysis" << messaget::eom;
552552
value_set_analysist value_set_analysis(ns);
553-
value_set_analysis(goto_model.goto_functions);
553+
value_set_analysis(goto_model);
554554

555555
const symbolt &symbol=ns.lookup(ID_main);
556556
symbol_exprt main(symbol.name, symbol.type);
@@ -1534,7 +1534,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
15341534
log.status() << "Pointer Analysis" << messaget::eom;
15351535
const namespacet ns(goto_model.symbol_table);
15361536
value_set_analysist value_set_analysis(ns);
1537-
value_set_analysis(goto_model.goto_functions);
1537+
value_set_analysis(goto_model);
15381538

15391539
if(cmdline.isset("remove-pointers"))
15401540
{

src/pointer-analysis/show_value_sets.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,39 @@ void show_value_sets(
2727
switch(ui)
2828
{
2929
case ui_message_handlert::uit::XML_UI:
30-
{
31-
xmlt xml;
32-
convert(goto_model.goto_functions, value_set_analysis, xml);
33-
std::cout << xml << '\n';
34-
}
30+
std::cout << value_set_analysis.output_xml(goto_model);
3531
break;
3632

3733
case ui_message_handlert::uit::PLAIN:
38-
value_set_analysis.output(goto_model.goto_functions, std::cout);
34+
value_set_analysis.output(goto_model, std::cout);
3935
break;
4036

4137
case ui_message_handlert::uit::JSON_UI:
42-
UNIMPLEMENTED;
38+
std::cout << value_set_analysis.output_json(goto_model);
39+
break;
4340
}
4441
}
4542

4643
void show_value_sets(
4744
ui_message_handlert::uit ui,
45+
const namespacet &ns,
46+
const irep_idt &function_name,
4847
const goto_programt &goto_program,
4948
const value_set_analysist &value_set_analysis)
5049
{
5150
switch(ui)
5251
{
5352
case ui_message_handlert::uit::XML_UI:
54-
{
55-
xmlt xml;
56-
convert(goto_program, value_set_analysis, xml);
57-
std::cout << xml << '\n';
58-
}
53+
std::cout << value_set_analysis.output_xml(ns, function_name, goto_program);
5954
break;
6055

6156
case ui_message_handlert::uit::PLAIN:
62-
value_set_analysis.output(goto_program, std::cout);
57+
value_set_analysis.output(ns, function_name, goto_program, std::cout);
6358
break;
6459

6560
case ui_message_handlert::uit::JSON_UI:
66-
UNIMPLEMENTED;
61+
std::cout << value_set_analysis.output_json(
62+
ns, function_name, goto_program);
63+
break;
6764
}
6865
}

src/pointer-analysis/value_set.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Author: Daniel Kroening, [email protected]
2626
#include <util/simplify_expr.h>
2727
#include <util/std_code.h>
2828
#include <util/symbol.h>
29+
#include <util/xml.h>
2930

3031
#include <ostream>
3132

@@ -217,6 +218,39 @@ void value_sett::output(std::ostream &out, const std::string &indent) const
217218
});
218219
}
219220

221+
xmlt value_sett::output_xml(void) const
222+
{
223+
xmlt output;
224+
225+
value_sett::valuest::viewt view;
226+
this->values.get_view(view);
227+
228+
for(const auto &values_entry : view)
229+
{
230+
xmlt &var = output.new_element("variable");
231+
var.new_element("identifier").data = id2string(values_entry.first);
232+
233+
#if 0
234+
const value_sett::expr_sett &expr_set=
235+
value_entries.expr_set();
236+
237+
for(value_sett::expr_sett::const_iterator
238+
e_it=expr_set.begin();
239+
e_it!=expr_set.end();
240+
e_it++)
241+
{
242+
std::string value_str=
243+
from_expr(ns, identifier, *e_it);
244+
245+
var.new_element("value").data=
246+
xmlt::escape(value_str);
247+
}
248+
#endif
249+
}
250+
251+
return output;
252+
}
253+
220254
exprt value_sett::to_expr(const object_map_dt::value_type &it) const
221255
{
222256
const exprt &object=object_numbering[it.first];

src/pointer-analysis/value_set.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected]
2222
#include "value_sets.h"
2323

2424
class namespacet;
25+
class xmlt;
2526

2627
/// State type in value_set_domaint, used in value-set analysis and goto-symex.
2728
/// Represents a mapping from expressions to the addresses that may be stored
@@ -287,6 +288,9 @@ class value_sett
287288
/// \param indent: string to use for indentation of the output
288289
void output(std::ostream &out, const std::string &indent = "") const;
289290

291+
/// Output the value set formatted as XML
292+
xmlt output_xml(void) const;
293+
290294
/// Stores the LHS ID -> RHS expression set map. See `valuest` documentation
291295
/// for more detail.
292296
valuest values;

src/pointer-analysis/value_set_analysis.cpp

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -11,86 +11,3 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "value_set_analysis.h"
1313

14-
#include <util/xml_irep.h>
15-
16-
void value_sets_to_xml(
17-
const std::function<const value_sett &(goto_programt::const_targett)>
18-
&get_value_set,
19-
const goto_programt &goto_program,
20-
xmlt &dest)
21-
{
22-
source_locationt previous_location;
23-
24-
forall_goto_program_instructions(i_it, goto_program)
25-
{
26-
const source_locationt &location = i_it->source_location();
27-
28-
if(location==previous_location)
29-
continue;
30-
31-
if(location.is_nil() || location.get_file().empty())
32-
continue;
33-
34-
// find value set
35-
const value_sett &value_set=get_value_set(i_it);
36-
37-
xmlt &i=dest.new_element("instruction");
38-
i.new_element()=::xml(location);
39-
40-
value_sett::valuest::viewt view;
41-
value_set.values.get_view(view);
42-
43-
for(const auto &values_entry : view)
44-
{
45-
xmlt &var=i.new_element("variable");
46-
var.new_element("identifier").data = id2string(values_entry.first);
47-
48-
#if 0
49-
const value_sett::expr_sett &expr_set=
50-
v_it->second.expr_set();
51-
52-
for(value_sett::expr_sett::const_iterator
53-
e_it=expr_set.begin();
54-
e_it!=expr_set.end();
55-
e_it++)
56-
{
57-
std::string value_str=
58-
from_expr(ns, identifier, *e_it);
59-
60-
var.new_element("value").data=
61-
xmlt::escape(value_str);
62-
}
63-
#endif
64-
}
65-
}
66-
}
67-
68-
void convert(
69-
const goto_functionst &goto_functions,
70-
const value_set_analysist &value_set_analysis,
71-
xmlt &dest)
72-
{
73-
dest=xmlt("value_set_analysis");
74-
75-
for(goto_functionst::function_mapt::const_iterator
76-
f_it=goto_functions.function_map.begin();
77-
f_it!=goto_functions.function_map.end();
78-
f_it++)
79-
{
80-
xmlt &f=dest.new_element("function");
81-
f.new_element("identifier").data=id2string(f_it->first);
82-
value_set_analysis.convert(f_it->second.body, f);
83-
}
84-
}
85-
86-
void convert(
87-
const goto_programt &goto_program,
88-
const value_set_analysist &value_set_analysis,
89-
xmlt &dest)
90-
{
91-
dest=xmlt("value_set_analysis");
92-
93-
value_set_analysis.convert(
94-
goto_program,
95-
dest.new_element("program"));
96-
}

src/pointer-analysis/value_set_analysis.h

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,29 @@ Author: Daniel Kroening, [email protected]
1212
#ifndef CPROVER_POINTER_ANALYSIS_VALUE_SET_ANALYSIS_H
1313
#define CPROVER_POINTER_ANALYSIS_VALUE_SET_ANALYSIS_H
1414

15-
#define USE_DEPRECATED_STATIC_ANALYSIS_H
16-
#include <analyses/static_analysis.h>
15+
#include <analyses/ai.h>
1716

1817
#include "value_set_domain.h"
1918
#include "value_sets.h"
2019

21-
class xmlt;
22-
23-
void value_sets_to_xml(
24-
const std::function<const value_sett &(goto_programt::const_targett)>
25-
&get_value_set,
26-
const goto_programt &goto_program,
27-
xmlt &dest);
28-
2920
/// This template class implements a data-flow analysis which keeps track of
3021
/// what values different variables might have at different points in the
3122
/// program. It is used through the alias `value_set_analysist`, so `VSDT` is
3223
/// `value_set_domain_templatet<value_sett>`.
33-
///
34-
/// Note: it is currently based on `static_analysist`, which is obsolete. It
35-
/// should be moved onto `ait`.
36-
template<class VSDT>
37-
class value_set_analysis_templatet:
38-
public value_setst,
39-
public static_analysist<VSDT>
24+
template <class VSDT>
25+
class value_set_analysis_templatet : public value_setst, public ait<VSDT>
4026
{
27+
private:
28+
const namespacet &ns;
29+
4130
public:
4231
typedef VSDT domaint;
43-
typedef static_analysist<domaint> baset;
32+
typedef ait<domaint> baset;
4433
typedef typename baset::locationt locationt;
4534

46-
explicit value_set_analysis_templatet(const namespacet &ns):baset(ns)
35+
explicit value_set_analysis_templatet(const namespacet &_ns)
36+
: baset(util_make_unique<ai_domain_factory_location_constructort<VSDT>>()),
37+
ns(_ns)
4738
{
4839
}
4940

@@ -52,38 +43,17 @@ class value_set_analysis_templatet:
5243
return (*this)[t].value_set;
5344
}
5445

55-
void convert(
56-
const goto_programt &goto_program,
57-
xmlt &dest) const
58-
{
59-
using std::placeholders::_1;
60-
value_sets_to_xml(
61-
std::bind(&value_set_analysis_templatet::get_value_set, *this, _1),
62-
goto_program,
63-
dest);
64-
}
65-
6646
public:
6747
// interface value_sets
6848
std::vector<exprt>
6949
get_values(const irep_idt &, locationt l, const exprt &expr) override
7050
{
71-
return (*this)[l].value_set.get_value_set(expr, baset::ns);
51+
return (*this)[l].value_set.get_value_set(expr, ns);
7252
}
7353
};
7454

7555
typedef
7656
value_set_analysis_templatet<value_set_domain_templatet<value_sett>>
7757
value_set_analysist;
7858

79-
void convert(
80-
const goto_functionst &goto_functions,
81-
const value_set_analysist &value_set_analysis,
82-
xmlt &dest);
83-
84-
void convert(
85-
const goto_programt &goto_program,
86-
const value_set_analysist &value_set_analysis,
87-
xmlt &dest);
88-
8959
#endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_ANALYSIS_H

0 commit comments

Comments
 (0)