Skip to content

Commit 7938cd1

Browse files
Make goto_symex_statet inherit from goto_statet
All fields of goto_statet are also found in goto_symex_statet. We can use inheritence two avoid repeating the parts that are common. Documentation is moved from goto_symex_statet to goto_statet for these fields. The debugging function output_propagation_map is also moved to goto_statet since it can be useful to both. It makes comparing the two easier; makes goto_symex_statet shorter and more structured; and make converting one to the other a bit clearer.
1 parent 2f0b7ff commit 7938cd1

File tree

2 files changed

+30
-50
lines changed

2 files changed

+30
-50
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ Author: Daniel Kroening, [email protected]
2828
static void get_l1_name(exprt &expr);
2929

3030
goto_symex_statet::goto_symex_statet()
31-
: depth(0),
32-
symex_target(nullptr),
33-
atomic_section_id(0),
34-
total_vccs(0),
35-
remaining_vccs(0),
36-
record_events(true),
37-
dirty()
31+
: symex_target(nullptr), record_events(true), dirty()
3832
{
3933
threads.resize(1);
4034
new_frame();
@@ -741,7 +735,7 @@ void goto_symex_statet::print_backtrace(std::ostream &out) const
741735
/// Print the constant propagation map in a human-friendly format.
742736
/// This is primarily for use from the debugger; please don't delete me just
743737
/// because there aren't any current callers.
744-
void goto_symex_statet::output_propagation_map(std::ostream &out)
738+
void goto_statet::output_propagation_map(std::ostream &out)
745739
{
746740
for(const auto &name_value : propagation)
747741
{

src/goto-symex/goto_symex_state.h

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,43 @@ Author: Daniel Kroening, [email protected]
3737
class goto_statet
3838
{
3939
public:
40+
/// Distance from entry
4041
unsigned depth = 0;
42+
4143
symex_level2t level2;
44+
45+
/// Uses level 1 names, and is used to do dereferencing
4246
value_sett value_set;
47+
48+
// A guard is a particular condition that has to pass for an instruction
49+
// to be executed. The easiest example is an if/else: each instruction along
50+
// the if branch will be guarded by the condition of the if (and if there
51+
// is an else branch then instructions on it will be guarded by the negation
52+
// of the condition of the if).
4353
guardt guard{true_exprt{}};
54+
4455
symex_targett::sourcet source;
56+
57+
// Map L1 names to (L2) constants. Values will be evicted from this map
58+
// when they become non-constant. This is used to propagate values that have
59+
// been worked out to only have one possible value.
60+
//
61+
// "constants" can include symbols, but only in the context of an address-of
62+
// op (i.e. &x can be propagated), and an address-taken thing should only be
63+
// L1.
4564
std::map<irep_idt, exprt> propagation;
65+
66+
void output_propagation_map(std::ostream &);
67+
68+
/// Threads
4669
unsigned atomic_section_id = 0;
70+
4771
std::unordered_map<irep_idt, local_safe_pointerst> safe_pointers;
4872
unsigned total_vccs = 0;
4973
unsigned remaining_vccs = 0;
5074

51-
goto_statet(const class goto_symex_statet &s);
75+
explicit goto_statet(const class goto_symex_statet &s);
76+
goto_statet() = default;
5277
};
5378

5479
// stack frames -- these are used for function calls and
@@ -96,7 +121,7 @@ struct framet
96121
/// state will be copied into a \ref goto_statet, stored in a map for later
97122
/// reference and then merged again (via merge_goto) once it reaches a
98123
/// control-flow graph convergence.
99-
class goto_symex_statet final
124+
class goto_symex_statet final : public goto_statet
100125
{
101126
public:
102127
goto_symex_statet();
@@ -116,15 +141,6 @@ class goto_symex_statet final
116141
/// for error traces even after symbolic execution has finished.
117142
symbol_tablet symbol_table;
118143

119-
/// distance from entry
120-
unsigned depth;
121-
122-
// A guard is a particular condition that has to pass for an instruction
123-
// to be executed. The easiest example is an if/else: each instruction along
124-
// the if branch will be guarded by the condition of the if (and if there
125-
// is an else branch then instructions on it will be guarded by the negation
126-
// of the condition of the if).
127-
guardt guard{true_exprt{}};
128144
symex_targett::sourcet source;
129145
symex_target_equationt *symex_target;
130146

@@ -133,17 +149,6 @@ class goto_symex_statet final
133149

134150
symex_level0t level0;
135151
symex_level1t level1;
136-
symex_level2t level2;
137-
138-
// Map L1 names to (L2) constants. Values will be evicted from this map
139-
// when they become non-constant. This is used to propagate values that have
140-
// been worked out to only have one possible value.
141-
//
142-
// "constants" can include symbols, but only in the context of an address-of
143-
// op (i.e. &x can be propagated), and an address-taken thing should only be
144-
// L1.
145-
std::map<irep_idt, exprt> propagation;
146-
void output_propagation_map(std::ostream &);
147152

148153
// Symex renaming levels.
149154
enum levelt { L0=0, L1=1, L2=2 };
@@ -204,24 +209,8 @@ class goto_symex_statet final
204209
l1_typest l1_types;
205210

206211
public:
207-
std::unordered_map<irep_idt, local_safe_pointerst> safe_pointers;
208-
209-
// uses level 1 names, and is used to
210-
// do dereferencing
211-
value_sett value_set;
212-
213-
explicit goto_symex_statet(const goto_statet &s)
214-
: depth(s.depth),
215-
guard(s.guard),
216-
source(s.source),
217-
propagation(s.propagation),
218-
safe_pointers(s.safe_pointers),
219-
value_set(s.value_set),
220-
atomic_section_id(s.atomic_section_id),
221-
total_vccs(s.total_vccs),
222-
remaining_vccs(s.remaining_vccs)
212+
explicit goto_symex_statet(const goto_statet &s) : goto_statet(s)
223213
{
224-
level2.current_names = s.level2.current_names;
225214
}
226215

227216
// gotos
@@ -273,15 +262,12 @@ class goto_symex_statet final
273262
void print_backtrace(std::ostream &) const;
274263

275264
// threads
276-
unsigned atomic_section_id;
277265
typedef std::pair<unsigned, std::list<guardt> > a_s_r_entryt;
278266
typedef std::list<guardt> a_s_w_entryt;
279267
std::unordered_map<ssa_exprt, a_s_r_entryt, irep_hash> read_in_atomic_section;
280268
std::unordered_map<ssa_exprt, a_s_w_entryt, irep_hash>
281269
written_in_atomic_section;
282270

283-
unsigned total_vccs, remaining_vccs;
284-
285271
struct threadt
286272
{
287273
goto_programt::const_targett pc;

0 commit comments

Comments
 (0)