@@ -16,11 +16,14 @@ Date: November 2011
16
16
#include < util/arith_tools.h>
17
17
#include < util/bitvector_types.h>
18
18
19
+ #include < goto-programs/goto_convert_functions.h>
19
20
#include < goto-programs/goto_model.h>
20
21
21
22
#include < linking/static_lifetime_init.h>
22
23
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)
24
27
{
25
28
const irep_idt identifier=" $stack_depth" ;
26
29
unsignedbv_typet type (sizeof (std::size_t )*8 );
@@ -36,12 +39,26 @@ symbol_exprt add_stack_depth_symbol(symbol_tablet &symbol_table)
36
39
new_symbol.is_thread_local =true ;
37
40
new_symbol.is_lvalue =true ;
38
41
39
- symbol_table.insert (std::move (new_symbol));
42
+ bool failed = goto_model.symbol_table .add (new_symbol);
43
+ CHECK_RETURN (!failed);
40
44
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 ();
42
59
}
43
60
44
- void stack_depth (
61
+ static void stack_depth (
45
62
goto_programt &goto_program,
46
63
const symbol_exprt &symbol,
47
64
const std::size_t i_depth,
@@ -77,10 +94,10 @@ void stack_depth(
77
94
78
95
void stack_depth (
79
96
goto_modelt &goto_model,
80
- const std::size_t depth)
97
+ const std::size_t depth,
98
+ message_handlert &message_handler)
81
99
{
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);
84
101
85
102
const exprt depth_expr (from_integer (depth, sym.type ()));
86
103
@@ -95,21 +112,6 @@ void stack_depth(
95
112
}
96
113
}
97
114
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
-
113
115
// update counters etc.
114
116
goto_model.goto_functions .update ();
115
117
}
0 commit comments