Skip to content

Commit 1a52fae

Browse files
committed
Remove dubious module dependencies in goto-programs
- Move call_graph and does_remove_const from analyses to goto-programs - Move symex_target_equation graphml functions to goto-symex - Update module_dependencies.txt and build files accordingly - Refactor code to eliminate cross-module dependencies Fixes: #571
1 parent 4fe3ade commit 1a52fae

25 files changed

+501
-274
lines changed

src/goto-checker/bmc_util.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Daniel Kroening, Peter Schrammel
2222
#include <goto-symex/memory_model_pso.h>
2323
#include <goto-symex/slice.h>
2424
#include <goto-symex/symex_target_equation.h>
25+
#include <goto-symex/symex_target_equation_graphml_witness.h>
2526
#include <solvers/decision_procedure.h>
2627

2728
#include "goto_symex_property_decider.h"
@@ -133,7 +134,7 @@ void output_graphml(
133134
if(graphml.empty())
134135
return;
135136

136-
graphml_witnesst graphml_witness(ns);
137+
symex_target_equation_graphml_witnesst graphml_witness(ns);
137138
graphml_witness(symex_target_equation);
138139

139140
if(graphml == "-")

src/goto-instrument/aggressive_slicer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ Author: Elizabeth Polgreen, [email protected]
1313

1414
#include <util/message.h>
1515

16+
#include <goto-programs/call_graph_helpers.h>
1617
#include <goto-programs/goto_model.h>
1718
#include <goto-programs/show_properties.h>
1819

1920
#include <linking/static_lifetime_init.h>
2021

21-
#include <analyses/call_graph_helpers.h>
22-
2322
#include "remove_function.h"
2423

2524
void aggressive_slicert::note_functions_to_keep(

src/goto-instrument/aggressive_slicer.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ Author: Elizabeth Polgreen, [email protected]
1414
#ifndef CPROVER_GOTO_INSTRUMENT_AGGRESSIVE_SLICER_H
1515
#define CPROVER_GOTO_INSTRUMENT_AGGRESSIVE_SLICER_H
1616

17-
#include <list>
18-
#include <string>
19-
2017
#include <util/irep.h>
2118

22-
#include <analyses/call_graph.h>
23-
19+
#include <goto-programs/call_graph.h>
2420
#include <goto-programs/goto_model.h>
2521

22+
#include <list>
23+
#include <string>
24+
2625
class message_handlert;
2726

2827
/// \brief The aggressive slicer removes the body of all the functions except

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]
2121
#include <util/unicode.h>
2222
#include <util/version.h>
2323

24+
#include <goto-programs/call_graph.h>
2425
#include <goto-programs/class_hierarchy.h>
2526
#include <goto-programs/ensure_one_backedge_per_target.h>
2627
#include <goto-programs/goto_check.h>
@@ -47,7 +48,6 @@ Author: Daniel Kroening, [email protected]
4748
#include <goto-programs/string_abstraction.h>
4849
#include <goto-programs/write_goto_binary.h>
4950

50-
#include <analyses/call_graph.h>
5151
#include <analyses/constant_propagator.h>
5252
#include <analyses/custom_bitvector_analysis.h>
5353
#include <analyses/dependence_graph.h>

src/goto-programs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ add_library(goto-programs ${sources})
33

44
generic_includes(goto-programs)
55

6-
target_link_libraries(goto-programs util assembler langapi analyses linking ansi-c)
6+
target_link_libraries(goto-programs util assembler langapi linking ansi-c)

src/goto-programs/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
SRC = adjust_float_expressions.cpp \
2+
call_graph.cpp \
3+
call_graph_helpers.cpp \
24
class_hierarchy.cpp \
35
class_identifier.cpp \
46
compute_called_functions.cpp \
7+
does_remove_const.cpp \
58
elf_reader.cpp \
69
ensure_one_backedge_per_target.cpp \
710
goto_check.cpp \

src/analyses/call_graph.cpp renamed to src/goto-programs/call_graph.cpp

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/xml.h>
1515

16-
#include <goto-programs/goto_model.h>
16+
#include "goto_model.h"
1717

1818
/// Create empty call graph
1919
/// \param collect_callsites: if true, then each added graph edge will have
2020
/// the calling instruction recorded in `callsites` map.
21-
call_grapht::call_grapht(bool collect_callsites):
22-
collect_callsites(collect_callsites)
21+
call_grapht::call_grapht(bool collect_callsites)
22+
: collect_callsites(collect_callsites)
2323
{
2424
}
2525

2626
/// Create complete call graph
2727
/// \param goto_model: model to search for callsites
2828
/// \param collect_callsites: if true, then each added graph edge will have
2929
/// the calling instruction recorded in `callsites` map.
30-
call_grapht::call_grapht(const goto_modelt &goto_model, bool collect_callsites):
31-
call_grapht(goto_model.goto_functions, collect_callsites)
30+
call_grapht::call_grapht(const goto_modelt &goto_model, bool collect_callsites)
31+
: call_grapht(goto_model.goto_functions, collect_callsites)
3232
{
3333
}
3434

@@ -37,8 +37,9 @@ call_grapht::call_grapht(const goto_modelt &goto_model, bool collect_callsites):
3737
/// \param collect_callsites: if true, then each added graph edge will have
3838
/// the calling instruction recorded in `callsites` map.
3939
call_grapht::call_grapht(
40-
const goto_functionst &goto_functions, bool collect_callsites):
41-
collect_callsites(collect_callsites)
40+
const goto_functionst &goto_functions,
41+
bool collect_callsites)
42+
: collect_callsites(collect_callsites)
4243
{
4344
for(const auto &gf_entry : goto_functions.function_map)
4445
{
@@ -75,15 +76,15 @@ static void forall_callsites(
7576
call_grapht::call_grapht(
7677
const goto_functionst &goto_functions,
7778
const irep_idt &root,
78-
bool collect_callsites):
79-
collect_callsites(collect_callsites)
79+
bool collect_callsites)
80+
: collect_callsites(collect_callsites)
8081
{
8182
std::stack<irep_idt, std::vector<irep_idt>> pending_stack;
8283
pending_stack.push(root);
8384

8485
while(!pending_stack.empty())
8586
{
86-
irep_idt function=pending_stack.top();
87+
irep_idt function = pending_stack.top();
8788
pending_stack.pop();
8889

8990
nodes.insert(function);
@@ -97,13 +98,11 @@ call_grapht::call_grapht(
9798

9899
forall_callsites(
99100
goto_program,
100-
[&](goto_programt::const_targett i_it, const irep_idt &callee)
101-
{
101+
[&](goto_programt::const_targett i_it, const irep_idt &callee) {
102102
add(function, callee, i_it);
103-
if(edges.find(callee)==edges.end())
103+
if(edges.find(callee) == edges.end())
104104
pending_stack.push(callee);
105-
}
106-
); // NOLINT
105+
}); // NOLINT
107106
}
108107
}
109108

@@ -115,30 +114,23 @@ call_grapht::call_grapht(
115114
call_grapht::call_grapht(
116115
const goto_modelt &goto_model,
117116
const irep_idt &root,
118-
bool collect_callsites):
119-
call_grapht(goto_model.goto_functions, root, collect_callsites)
117+
bool collect_callsites)
118+
: call_grapht(goto_model.goto_functions, root, collect_callsites)
120119
{
121120
}
122121

123-
void call_grapht::add(
124-
const irep_idt &function,
125-
const goto_programt &body)
122+
void call_grapht::add(const irep_idt &function, const goto_programt &body)
126123
{
127124
forall_callsites(
128-
body,
129-
[&](goto_programt::const_targett i_it, const irep_idt &callee)
130-
{
125+
body, [&](goto_programt::const_targett i_it, const irep_idt &callee) {
131126
add(function, callee, i_it);
132-
}
133-
); // NOLINT
127+
}); // NOLINT
134128
}
135129

136130
/// Add edge
137131
/// \param caller: caller function
138132
/// \param callee: callee function
139-
void call_grapht::add(
140-
const irep_idt &caller,
141-
const irep_idt &callee)
133+
void call_grapht::add(const irep_idt &caller, const irep_idt &callee)
142134
{
143135
edges.insert({caller, callee});
144136
nodes.insert(caller);
@@ -181,19 +173,18 @@ class function_indicest
181173
public:
182174
std::unordered_map<irep_idt, node_indext> function_indices;
183175

184-
explicit function_indicest(call_grapht::directed_grapht &graph):
185-
graph(graph)
176+
explicit function_indicest(call_grapht::directed_grapht &graph) : graph(graph)
186177
{
187178
}
188179

189180
node_indext operator[](const irep_idt &function)
190181
{
191-
auto findit=function_indices.insert({function, 0});
182+
auto findit = function_indices.insert({function, 0});
192183
if(findit.second)
193184
{
194-
node_indext new_index=graph.add_node();
195-
findit.first->second=new_index;
196-
graph[new_index].function=function;
185+
node_indext new_index = graph.add_node();
186+
findit.first->second = new_index;
187+
graph[new_index].function = function;
197188
}
198189
return findit.first->second;
199190
}
@@ -218,19 +209,19 @@ call_grapht::directed_grapht call_grapht::get_directed_graph() const
218209

219210
for(const auto &edge : edges)
220211
{
221-
auto a_index=function_indices[edge.first];
222-
auto b_index=function_indices[edge.second];
212+
auto a_index = function_indices[edge.first];
213+
auto b_index = function_indices[edge.second];
223214
// Check then create the edge like this to avoid copying the callsites
224215
// set once per parallel edge, which could be costly if there are many.
225216
if(!ret.has_edge(a_index, b_index))
226217
{
227218
ret.add_edge(a_index, b_index);
228219
if(collect_callsites)
229-
ret[a_index].out[b_index].callsites=callsites.at(edge);
220+
ret[a_index].out[b_index].callsites = callsites.at(edge);
230221
}
231222
}
232223

233-
ret.nodes_by_name=std::move(function_indices.function_indices);
224+
ret.nodes_by_name = std::move(function_indices.function_indices);
234225
return ret;
235226
}
236227

@@ -241,14 +232,14 @@ call_grapht::directed_grapht call_grapht::get_directed_graph() const
241232
std::string call_grapht::format_callsites(const edget &edge) const
242233
{
243234
PRECONDITION(collect_callsites);
244-
std::string ret="{";
235+
std::string ret = "{";
245236
for(const locationt &loc : callsites.at(edge))
246237
{
247-
if(ret.size()>1)
248-
ret+=", ";
249-
ret+=std::to_string(loc->location_number);
238+
if(ret.size() > 1)
239+
ret += ", ";
240+
ret += std::to_string(loc->location_number);
250241
}
251-
ret+='}';
242+
ret += '}';
252243
return ret;
253244
}
254245

@@ -285,7 +276,7 @@ void call_grapht::output_xml(std::ostream &out) const
285276
// to the first interested XML user.
286277
if(collect_callsites)
287278
out << "<!-- XML call-graph representation does not document callsites yet."
288-
" If you need this, edit call_grapht::output_xml -->\n";
279+
" If you need this, edit call_grapht::output_xml -->\n";
289280
for(const auto &edge : edges)
290281
{
291282
out << "<call_graph_edge caller=\"";
@@ -299,8 +290,8 @@ void call_grapht::output_xml(std::ostream &out) const
299290
std::optional<std::size_t>
300291
call_grapht::directed_grapht::get_node_index(const irep_idt &function) const
301292
{
302-
auto findit=nodes_by_name.find(function);
303-
if(findit==nodes_by_name.end())
293+
auto findit = nodes_by_name.find(function);
294+
if(findit == nodes_by_name.end())
304295
return std::optional<node_indext>();
305296
else
306297
return findit->second;

src/analyses/call_graph.h renamed to src/goto-programs/call_graph.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ Author: Daniel Kroening, [email protected]
99
/// \file
1010
/// Function Call Graphs
1111

12-
#ifndef CPROVER_ANALYSES_CALL_GRAPH_H
13-
#define CPROVER_ANALYSES_CALL_GRAPH_H
12+
#ifndef CPROVER_GOTO_PROGRAMS_CALL_GRAPH_H
13+
#define CPROVER_GOTO_PROGRAMS_CALL_GRAPH_H
14+
15+
#include <util/graph.h>
16+
17+
#include "goto_program.h"
1418

1519
#include <iosfwd>
1620
#include <map>
1721
#include <unordered_set>
1822

19-
#include <util/graph.h>
20-
21-
#include <goto-programs/goto_program.h>
22-
2323
class goto_functionst;
2424
class goto_modelt;
2525

@@ -43,9 +43,9 @@ class goto_modelt;
4343
class call_grapht
4444
{
4545
public:
46-
explicit call_grapht(bool collect_callsites=false);
47-
explicit call_grapht(const goto_modelt &, bool collect_callsites=false);
48-
explicit call_grapht(const goto_functionst &, bool collect_callsites=false);
46+
explicit call_grapht(bool collect_callsites = false);
47+
explicit call_grapht(const goto_modelt &, bool collect_callsites = false);
48+
explicit call_grapht(const goto_functionst &, bool collect_callsites = false);
4949

5050
// These two functions build a call graph restricted to functions
5151
// reachable from the given root.
@@ -79,7 +79,6 @@ class call_grapht
7979
bool collect_callsites);
8080

8181
public:
82-
8382
void output_dot(std::ostream &out) const;
8483
void output(std::ostream &out) const;
8584
void output_xml(std::ostream &out) const;
@@ -163,11 +162,11 @@ class call_grapht
163162
directed_grapht get_directed_graph() const;
164163

165164
protected:
166-
void add(const irep_idt &function,
167-
const goto_programt &body);
165+
void add(const irep_idt &function, const goto_programt &body);
166+
168167
private:
169168
bool collect_callsites;
170169
std::string format_callsites(const edget &edge) const;
171170
};
172171

173-
#endif // CPROVER_ANALYSES_CALL_GRAPH_H
172+
#endif // CPROVER_GOTO_PROGRAMS_CALL_GRAPH_H

src/analyses/call_graph_helpers.cpp renamed to src/goto-programs/call_graph_helpers.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ static std::set<irep_idt> get_neighbours(
2828
return result;
2929
}
3030

31-
std::set<irep_idt> get_callees(
32-
const call_grapht::directed_grapht &graph, const irep_idt &function)
31+
std::set<irep_idt>
32+
get_callees(const call_grapht::directed_grapht &graph, const irep_idt &function)
3333
{
3434
return get_neighbours(graph, function, true);
3535
}
3636

37-
std::set<irep_idt> get_callers(
38-
const call_grapht::directed_grapht &graph, const irep_idt &function)
37+
std::set<irep_idt>
38+
get_callers(const call_grapht::directed_grapht &graph, const irep_idt &function)
3939
{
4040
return get_neighbours(graph, function, false);
4141
}
@@ -60,13 +60,15 @@ static std::set<irep_idt> get_connected_functions(
6060
}
6161

6262
std::set<irep_idt> get_reachable_functions(
63-
const call_grapht::directed_grapht &graph, const irep_idt &function)
63+
const call_grapht::directed_grapht &graph,
64+
const irep_idt &function)
6465
{
6566
return get_connected_functions(graph, function, true);
6667
}
6768

6869
std::set<irep_idt> get_reaching_functions(
69-
const call_grapht::directed_grapht &graph, const irep_idt &function)
70+
const call_grapht::directed_grapht &graph,
71+
const irep_idt &function)
7072
{
7173
return get_connected_functions(graph, function, false);
7274
}

0 commit comments

Comments
 (0)