14
14
15
15
#include < map>
16
16
#include < unordered_set>
17
- #include < memory>
18
17
19
18
#include < util/irep.h>
20
19
#include < util/ssa_expr.h>
@@ -87,29 +86,12 @@ struct symex_level2t : public symex_renaming_levelt
87
86
symex_level2t () = default ;
88
87
~symex_level2t () override = default ;
89
88
90
- // / In the case of a state split, we want to keep track of the overall
91
- // / name generation across all states for identifier creation.
92
- optionalt<current_namest> local_generations;
89
+ optionalt<current_namest> global_names;
93
90
94
91
void erase (const irep_idt &identifier)
95
92
{
93
+ // We don't want to erase anything from the global scope if it exists.
96
94
current_names->erase (identifier);
97
- if (local_generations)
98
- local_generations->erase (identifier);
99
- }
100
-
101
- // / If we have a local counter, use that instead of our global.
102
- unsigned current_count (const irep_idt &identifier) const override
103
- {
104
- if (local_generations)
105
- {
106
- const auto it = local_generations->find (identifier);
107
- return it == local_generations->end () ? 0 : it->second .second ;
108
- }
109
- else
110
- {
111
- return symex_renaming_levelt::current_count (identifier);
112
- }
113
95
}
114
96
115
97
// / Ages the generation of an ssa expression by one.
@@ -118,8 +100,8 @@ struct symex_level2t : public symex_renaming_levelt
118
100
const ssa_exprt &lhs)
119
101
{
120
102
current_names->emplace (l1_identifier, std::make_pair (lhs, 0 ));
121
- if (local_generations )
122
- local_generations ->emplace (l1_identifier, std::make_pair (lhs, 0 ));
103
+ if (global_names )
104
+ global_names ->emplace (l1_identifier, std::make_pair (lhs, 0 ));
123
105
124
106
increase_generation (l1_identifier);
125
107
}
@@ -129,35 +111,47 @@ struct symex_level2t : public symex_renaming_levelt
129
111
void increase_generation (
130
112
const irep_idt identifier)
131
113
{
114
+ // If we can't find the name in the local scope, don't increase the global
115
+ // even if it exists there.
132
116
auto current_names_iter = current_names->find (identifier);
133
117
if (current_names_iter == current_names->end ())
134
118
return ;
135
119
136
- current_names_iter->second .second ++;
137
- if (local_generations)
120
+ // If we have a global store, increment its generation count, then assign
121
+ // that new value to our local scope.
122
+ if (global_names)
138
123
{
139
- auto local_iter = local_generations->find (identifier);
140
- if (local_iter != local_generations->end ())
141
- local_iter->second .second = current_names_iter->second .second ;
124
+ auto global_names_iter = global_names->find (identifier);
125
+ if (global_names_iter == global_names->end ())
126
+ global_names_iter->second .second ++,
127
+ current_names_iter->second .second = global_names_iter->second .second ;
128
+ }
129
+ else
130
+ {
131
+ // Otherwise simply increase our local scope.
132
+ current_names_iter->second .second ++;
142
133
}
143
134
}
144
135
145
- current_namest get_current_names ()
146
- {
147
- return local_generations ? *local_generations : *current_names;
148
- }
149
-
136
+ // / Prints the differences between the global and local naming maps (if they
137
+ // / exist)
150
138
void print_differences (const std::string &differences)
151
139
{
152
- if (!local_generations )
140
+ if (!global_names )
153
141
return ;
154
142
155
- for (const auto &local_gen : *local_generations)
143
+ std::cout << " Printing differences between local and global generations." << ' \n ' ;
144
+
145
+ for (const auto &local : *current_names)
156
146
{
157
- auto local = local_gen.second .second ;
158
- auto global = current_names->find (local_gen.first )->second .second ;
159
- if (local != global)
160
- std::cout << differences << " ID: " << id2string (local_gen.first ) << " , local: " << local << " global: " << global << ' \n ' ;
147
+ auto global_iter = global_names->find (local.first );
148
+ if (global_iter == global_names->end ())
149
+ continue ;
150
+
151
+ auto global_count = global_iter->second .second ;
152
+ auto local_count = local.second .second ;
153
+ if (global_count != local_count)
154
+ std::cout << differences << " ID: " << id2string (local.first ) << " , local: " << local_count << " global: " << global_count << ' \n ' ;
161
155
}
162
156
}
163
157
};
0 commit comments