Skip to content

Commit 17e53d6

Browse files
authored
Merge pull request #4294 from romainbrenguier/refactor/goto_state
Move goto_statet and framet to their own files [blocks: #4302]
2 parents 22d87d5 + 3bce5c2 commit 17e53d6

File tree

6 files changed

+149
-98
lines changed

6 files changed

+149
-98
lines changed

src/goto-symex/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SRC = auto_objects.cpp \
22
build_goto_trace.cpp \
3+
goto_state.cpp \
34
goto_symex.cpp \
45
goto_symex_state.cpp \
56
memory_model.cpp \

src/goto-symex/frame.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************\
2+
3+
Module: Symbolic Execution
4+
5+
Author: Romain Brenguier, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Class for stack frames
11+
12+
#ifndef CPROVER_GOTO_SYMEX_FRAME_H
13+
#define CPROVER_GOTO_SYMEX_FRAME_H
14+
15+
#include "goto_state.h"
16+
17+
/// Stack frames -- these are used for function calls and for exceptions
18+
struct framet
19+
{
20+
// gotos
21+
using goto_state_listt = std::list<goto_statet>;
22+
23+
// function calls
24+
irep_idt function_identifier;
25+
std::map<goto_programt::const_targett, goto_state_listt> goto_state_map;
26+
symex_targett::sourcet calling_location;
27+
28+
goto_programt::const_targett end_of_function;
29+
exprt return_value = nil_exprt();
30+
bool hidden_function = false;
31+
32+
symex_renaming_levelt::current_namest old_level1;
33+
34+
std::set<irep_idt> local_objects;
35+
36+
// exceptions
37+
std::map<irep_idt, goto_programt::targett> catch_map;
38+
39+
// loop and recursion unwinding
40+
struct loop_infot
41+
{
42+
unsigned count = 0;
43+
bool is_recursion = false;
44+
};
45+
46+
std::unordered_map<irep_idt, loop_infot> loop_iterations;
47+
48+
explicit framet(symex_targett::sourcet _calling_location)
49+
: calling_location(std::move(_calling_location))
50+
{
51+
}
52+
};
53+
54+
#endif // CPROVER_GOTO_SYMEX_FRAME_H

src/goto-symex/goto_state.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*******************************************************************\
2+
3+
Module: Symbolic Execution
4+
5+
Author: Romain Brenguier, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "goto_state.h"
10+
11+
#include <util/format_expr.h>
12+
13+
/// Print the constant propagation map in a human-friendly format.
14+
/// This is primarily for use from the debugger; please don't delete me just
15+
/// because there aren't any current callers.
16+
void goto_statet::output_propagation_map(std::ostream &out)
17+
{
18+
for(const auto &name_value : propagation)
19+
{
20+
out << name_value.first << " <- " << format(name_value.second) << "\n";
21+
}
22+
}

src/goto-symex/goto_state.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*******************************************************************\
2+
3+
Module: Symbolic Execution
4+
5+
Author: Romain Brenguier, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// goto_statet class definition
11+
12+
#ifndef CPROVER_GOTO_SYMEX_GOTO_STATE_H
13+
#define CPROVER_GOTO_SYMEX_GOTO_STATE_H
14+
15+
#include <analyses/local_safe_pointers.h>
16+
#include <pointer-analysis/value_set.h>
17+
#include <util/guard.h>
18+
19+
#include "renaming_level.h"
20+
#include "symex_target_equation.h"
21+
22+
/// Container for data that varies per program point, e.g. the constant
23+
/// propagator state, when state needs to branch. This is copied out of
24+
/// goto_symex_statet at a control-flow fork and then back into it at a
25+
/// control-flow merge.
26+
class goto_statet
27+
{
28+
public:
29+
/// Distance from entry
30+
unsigned depth = 0;
31+
32+
symex_level2t level2;
33+
34+
/// Uses level 1 names, and is used to do dereferencing
35+
value_sett value_set;
36+
37+
// A guard is a particular condition that has to pass for an instruction
38+
// to be executed. The easiest example is an if/else: each instruction along
39+
// the if branch will be guarded by the condition of the if (and if there
40+
// is an else branch then instructions on it will be guarded by the negation
41+
// of the condition of the if).
42+
guardt guard{true_exprt{}};
43+
44+
symex_targett::sourcet source;
45+
46+
// Map L1 names to (L2) constants. Values will be evicted from this map
47+
// when they become non-constant. This is used to propagate values that have
48+
// been worked out to only have one possible value.
49+
//
50+
// "constants" can include symbols, but only in the context of an address-of
51+
// op (i.e. &x can be propagated), and an address-taken thing should only be
52+
// L1.
53+
std::map<irep_idt, exprt> propagation;
54+
55+
void output_propagation_map(std::ostream &);
56+
57+
/// Threads
58+
unsigned atomic_section_id = 0;
59+
60+
unsigned total_vccs = 0;
61+
unsigned remaining_vccs = 0;
62+
63+
/// Constructors
64+
explicit goto_statet(const class goto_symex_statet &s);
65+
explicit goto_statet(const symex_targett::sourcet &_source) : source(_source)
66+
{
67+
}
68+
};
69+
70+
#endif // CPROVER_GOTO_SYMEX_GOTO_STATE_H

src/goto-symex/goto_symex_state.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -785,14 +785,3 @@ void goto_symex_statet::print_backtrace(std::ostream &out) const
785785
<< frame.calling_location.pc->location_number << "\n";
786786
}
787787
}
788-
789-
/// Print the constant propagation map in a human-friendly format.
790-
/// This is primarily for use from the debugger; please don't delete me just
791-
/// because there aren't any current callers.
792-
void goto_statet::output_propagation_map(std::ostream &out)
793-
{
794-
for(const auto &name_value : propagation)
795-
{
796-
out << name_value.first << " <- " << format(name_value.second) << "\n";
797-
}
798-
}

src/goto-symex/goto_symex_state.h

Lines changed: 2 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -22,98 +22,13 @@ Author: Daniel Kroening, [email protected]
2222
#include <util/std_expr.h>
2323
#include <util/ssa_expr.h>
2424
#include <util/make_unique.h>
25-
26-
#include <pointer-analysis/value_set.h>
2725
#include <goto-programs/goto_function.h>
2826

27+
#include "frame.h"
28+
#include "goto_state.h"
2929
#include "renaming_level.h"
3030
#include "symex_target_equation.h"
3131

32-
/// Container for data that varies per program point, e.g. the constant
33-
/// propagator state, when state needs to branch. This is copied out of
34-
/// goto_symex_statet at a control-flow fork and then back into it at a
35-
/// control-flow merge.
36-
class goto_statet
37-
{
38-
public:
39-
/// Distance from entry
40-
unsigned depth = 0;
41-
42-
symex_level2t level2;
43-
44-
/// Uses level 1 names, and is used to do dereferencing
45-
value_sett value_set;
46-
47-
// A guard is a particular condition that has to pass for an instruction
48-
// to be executed. The easiest example is an if/else: each instruction along
49-
// the if branch will be guarded by the condition of the if (and if there
50-
// is an else branch then instructions on it will be guarded by the negation
51-
// of the condition of the if).
52-
guardt guard{true_exprt{}};
53-
54-
symex_targett::sourcet source;
55-
56-
// Map L1 names to (L2) constants. Values will be evicted from this map
57-
// when they become non-constant. This is used to propagate values that have
58-
// been worked out to only have one possible value.
59-
//
60-
// "constants" can include symbols, but only in the context of an address-of
61-
// op (i.e. &x can be propagated), and an address-taken thing should only be
62-
// L1.
63-
std::map<irep_idt, exprt> propagation;
64-
65-
void output_propagation_map(std::ostream &);
66-
67-
/// Threads
68-
unsigned atomic_section_id = 0;
69-
70-
unsigned total_vccs = 0;
71-
unsigned remaining_vccs = 0;
72-
73-
/// Constructors
74-
explicit goto_statet(const class goto_symex_statet &s);
75-
explicit goto_statet(const symex_targett::sourcet &_source) : source(_source)
76-
{
77-
}
78-
};
79-
80-
// stack frames -- these are used for function calls and
81-
// for exceptions
82-
struct framet
83-
{
84-
// gotos
85-
using goto_state_listt = std::list<goto_statet>;
86-
87-
// function calls
88-
irep_idt function_identifier;
89-
std::map<goto_programt::const_targett, goto_state_listt> goto_state_map;
90-
symex_targett::sourcet calling_location;
91-
92-
goto_programt::const_targett end_of_function;
93-
exprt return_value = nil_exprt();
94-
bool hidden_function = false;
95-
96-
symex_renaming_levelt::current_namest old_level1;
97-
98-
std::set<irep_idt> local_objects;
99-
100-
// exceptions
101-
std::map<irep_idt, goto_programt::targett> catch_map;
102-
103-
// loop and recursion unwinding
104-
struct loop_infot
105-
{
106-
unsigned count = 0;
107-
bool is_recursion = false;
108-
};
109-
std::unordered_map<irep_idt, loop_infot> loop_iterations;
110-
111-
explicit framet(symex_targett::sourcet _calling_location)
112-
: calling_location(std::move(_calling_location))
113-
{
114-
}
115-
};
116-
11732
/// \brief Central data structure: state.
11833
///
11934
/// The state is a persistent data structure that symex maintains as it

0 commit comments

Comments
 (0)