@@ -16,12 +16,15 @@ Date: December 2012
16
16
#include < iostream>
17
17
#include < unordered_set>
18
18
19
- #include < util/prefix.h>
20
19
#include < util/file_util.h>
20
+ #include < util/pointer_offset_size.h>
21
+ #include < util/prefix.h>
21
22
22
23
#include < goto-programs/cfg.h>
23
24
#include < goto-programs/goto_model.h>
24
25
26
+ #include < linking/static_lifetime_init.h>
27
+
25
28
typedef std::unordered_set<irep_idt> linest;
26
29
typedef std::unordered_map<irep_idt, linest> filest;
27
30
typedef std::unordered_map<irep_idt, filest> working_dirst;
@@ -142,3 +145,56 @@ void print_path_lengths(const goto_modelt &goto_model)
142
145
++n_reachable;
143
146
std::cout << " Reachable instructions: " << n_reachable << " \n " ;
144
147
}
148
+
149
+ void print_global_state_size (const goto_modelt &goto_model)
150
+ {
151
+ const namespacet ns (goto_model.symbol_table );
152
+
153
+ // if we have a linked object, only account for those that are used
154
+ // (slice-global-inits may have been used to avoid unnecessary initialization)
155
+ goto_functionst::function_mapt::const_iterator f_it =
156
+ goto_model.goto_functions .function_map .find (INITIALIZE_FUNCTION);
157
+ const bool has_initialize =
158
+ f_it != goto_model.goto_functions .function_map .end ();
159
+ std::unordered_set<irep_idt> initialized;
160
+
161
+ if (has_initialize)
162
+ {
163
+ for (const auto &ins : f_it->second .body .instructions )
164
+ {
165
+ if (ins.is_assign ())
166
+ {
167
+ const code_assignt &code_assign = to_code_assign (ins.code );
168
+ object_descriptor_exprt ode;
169
+ ode.build (code_assign.lhs (), ns);
170
+
171
+ if (ode.root_object ().id () == ID_symbol)
172
+ {
173
+ const symbol_exprt &symbol_expr = to_symbol_expr (ode.root_object ());
174
+ initialized.insert (symbol_expr.get_identifier ());
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ mp_integer total_size = 0 ;
181
+
182
+ for (const auto &symbol_entry : goto_model.symbol_table .symbols )
183
+ {
184
+ const symbolt &symbol = symbol_entry.second ;
185
+ if (
186
+ symbol.is_type || symbol.is_macro || symbol.type .id () == ID_code ||
187
+ symbol.type .get_bool (ID_C_constant) ||
188
+ has_prefix (id2string (symbol.name ), CPROVER_PREFIX) ||
189
+ (has_initialize && initialized.find (symbol.name ) == initialized.end ()))
190
+ {
191
+ continue ;
192
+ }
193
+
194
+ const mp_integer bits = pointer_offset_bits (symbol.type , ns);
195
+ if (bits > 0 )
196
+ total_size += bits;
197
+ }
198
+
199
+ std::cout << " Total size of global objects: " << total_size << " bits\n " ;
200
+ }
0 commit comments