@@ -12,6 +12,8 @@ Author: Peter Schrammel
1212#include " shadow_memory.h"
1313
1414#include < util/bitvector_types.h>
15+ #include < util/expr_initializer.h>
16+ #include < util/format_expr.h>
1517#include < util/format_type.h>
1618#include < util/fresh_symbol.h>
1719
@@ -22,34 +24,64 @@ Author: Peter Schrammel
2224
2325void shadow_memoryt::initialize_shadow_memory (
2426 goto_symex_statet &state,
25- const exprt & expr,
27+ exprt expr,
2628 const shadow_memory_field_definitionst::field_definitiont &fields)
2729{
28- // To be implemented
30+ typet type = ns.follow (expr.type ());
31+ clean_pointer_expr (expr, type);
32+ for (const auto &field_pair : fields)
33+ {
34+ const symbol_exprt &shadow = add_field (state, expr, field_pair.first , type);
35+
36+ if (
37+ field_pair.second .id () == ID_typecast &&
38+ to_typecast_expr (field_pair.second ).op ().is_zero ())
39+ {
40+ const auto zero_value =
41+ zero_initializer (type, expr.source_location (), ns);
42+ CHECK_RETURN (zero_value.has_value ());
43+
44+ symex_assign (state, shadow, *zero_value);
45+ }
46+ else
47+ {
48+ exprt init_expr = field_pair.second ;
49+ if (init_expr.id () == ID_typecast)
50+ init_expr = to_typecast_expr (field_pair.second ).op ();
51+ const auto init_value =
52+ expr_initializer (type, expr.source_location (), ns, init_expr);
53+ CHECK_RETURN (init_value.has_value ());
54+
55+ symex_assign (state, shadow, *init_value);
56+ }
57+
58+ log.debug () << " Shadow memory: initialize field "
59+ << id2string (shadow.get_identifier ()) << " for " << format (expr)
60+ << " with initial value " << format (field_pair.second )
61+ << messaget::eom;
62+ }
2963}
3064
31- symbol_exprt shadow_memoryt::add_field (
65+ const symbol_exprt & shadow_memoryt::add_field (
3266 goto_symex_statet &state,
3367 const exprt &expr,
3468 const irep_idt &field_name,
3569 const typet &field_type)
3670{
37- // To be completed
38-
3971 const auto &function_symbol = ns.lookup (state.source .function_id );
40-
41- symbolt &new_symbol = get_fresh_aux_symbol (
72+ const symbolt &new_symbol = get_fresh_aux_symbol (
4273 field_type,
4374 id2string (state.source .function_id ),
4475 SHADOW_MEMORY_PREFIX + from_expr (expr) + " __" + id2string (field_name),
4576 state.source .pc ->source_location (),
4677 function_symbol.mode ,
4778 state.symbol_table );
4879
49- // Call some function on ns to silence the compiler in the meanwhile.
50- ns.get_symbol_table ();
80+ auto &addresses = state.shadow_memory .address_fields [field_name];
81+ addresses.push_back (
82+ shadow_memory_statet::shadowed_addresst{expr, new_symbol.symbol_expr ()});
5183
52- return new_symbol. symbol_expr () ;
84+ return addresses. back (). shadow ;
5385}
5486
5587void shadow_memoryt::symex_set_field (
0 commit comments