@@ -16,12 +16,15 @@ Date: December 2012
1616#include < iostream>
1717#include < unordered_set>
1818
19- #include < util/prefix.h>
2019#include < util/file_util.h>
20+ #include < util/pointer_offset_size.h>
21+ #include < util/prefix.h>
2122
2223#include < goto-programs/cfg.h>
2324#include < goto-programs/goto_model.h>
2425
26+ #include < linking/static_lifetime_init.h>
27+
2528typedef std::unordered_set<irep_idt> linest;
2629typedef std::unordered_map<irep_idt, linest> filest;
2730typedef std::unordered_map<irep_idt, filest> working_dirst;
@@ -142,3 +145,50 @@ void print_path_lengths(const goto_modelt &goto_model)
142145 ++n_reachable;
143146 std::cout << " Reachable instructions: " << n_reachable << " \n " ;
144147}
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