@@ -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,50 @@ 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
+ const symbol_exprt &symbol_expr = to_symbol_expr (code_assign.lhs ());
169
+
170
+ initialized.insert (symbol_expr.get_identifier ());
171
+ }
172
+ }
173
+ }
174
+
175
+ mp_integer total_size = 0 ;
176
+
177
+ for (const auto &symbol_entry : goto_model.symbol_table .symbols )
178
+ {
179
+ const symbolt &symbol = symbol_entry.second ;
180
+ if (
181
+ symbol.is_type || symbol.is_macro || symbol.type .id () == ID_code ||
182
+ symbol.type .get_bool (ID_C_constant) ||
183
+ (has_initialize && initialized.find (symbol.name ) == initialized.end ()))
184
+ {
185
+ continue ;
186
+ }
187
+
188
+ const mp_integer bits = pointer_offset_bits (symbol.type , ns);
189
+ if (bits > 0 )
190
+ total_size += bits;
191
+ }
192
+
193
+ std::cout << " Total size of global objects: " << total_size << " bits\n " ;
194
+ }
0 commit comments