@@ -16,11 +16,14 @@ Date: November 2011
1616#include < util/arith_tools.h>
1717#include < util/bitvector_types.h>
1818
19+ #include < goto-programs/goto_convert_functions.h>
1920#include < goto-programs/goto_model.h>
2021
2122#include < linking/static_lifetime_init.h>
2223
23- symbol_exprt add_stack_depth_symbol (symbol_tablet &symbol_table)
24+ static symbol_exprt add_stack_depth_symbol (
25+ goto_modelt &goto_model,
26+ message_handlert &message_handler)
2427{
2528 const irep_idt identifier=" $stack_depth" ;
2629 unsignedbv_typet type (sizeof (std::size_t )*8 );
@@ -36,12 +39,26 @@ symbol_exprt add_stack_depth_symbol(symbol_tablet &symbol_table)
3639 new_symbol.is_thread_local =true ;
3740 new_symbol.is_lvalue =true ;
3841
39- symbol_table.insert (std::move (new_symbol));
42+ bool failed = goto_model.symbol_table .add (new_symbol);
43+ CHECK_RETURN (!failed);
4044
41- return symbol_exprt (identifier, type);
45+ if (goto_model.goto_functions .function_map .erase (INITIALIZE_FUNCTION) != 0 )
46+ {
47+ static_lifetime_init (
48+ goto_model.symbol_table ,
49+ goto_model.symbol_table .lookup_ref (INITIALIZE_FUNCTION).location );
50+ goto_convert (
51+ INITIALIZE_FUNCTION,
52+ goto_model.symbol_table ,
53+ goto_model.goto_functions ,
54+ message_handler);
55+ goto_model.goto_functions .update ();
56+ }
57+
58+ return new_symbol.symbol_expr ();
4259}
4360
44- void stack_depth (
61+ static void stack_depth (
4562 goto_programt &goto_program,
4663 const symbol_exprt &symbol,
4764 const std::size_t i_depth,
@@ -77,10 +94,10 @@ void stack_depth(
7794
7895void stack_depth (
7996 goto_modelt &goto_model,
80- const std::size_t depth)
97+ const std::size_t depth,
98+ message_handlert &message_handler)
8199{
82- const symbol_exprt sym=
83- add_stack_depth_symbol (goto_model.symbol_table );
100+ const symbol_exprt sym = add_stack_depth_symbol (goto_model, message_handler);
84101
85102 const exprt depth_expr (from_integer (depth, sym.type ()));
86103
@@ -95,21 +112,6 @@ void stack_depth(
95112 }
96113 }
97114
98- // initialize depth to 0
99- goto_functionst::function_mapt::iterator i_it =
100- goto_model.goto_functions .function_map .find (INITIALIZE_FUNCTION);
101- DATA_INVARIANT (
102- i_it!=goto_model.goto_functions .function_map .end (),
103- INITIALIZE_FUNCTION " must exist" );
104-
105- goto_programt &init=i_it->second .body ;
106- goto_programt::targett first=init.instructions .begin ();
107- init.insert_before (
108- first,
109- goto_programt::make_assignment (
110- code_assignt (sym, from_integer (0 , sym.type ()))));
111- // no suitable value for source location -- omitted
112-
113115 // update counters etc.
114116 goto_model.goto_functions .update ();
115117}
0 commit comments