@@ -12,6 +12,8 @@ Author: Peter Schrammel
12
12
#include " shadow_memory.h"
13
13
14
14
#include < util/bitvector_types.h>
15
+ #include < util/expr_initializer.h>
16
+ #include < util/format_expr.h>
15
17
#include < util/format_type.h>
16
18
#include < util/fresh_symbol.h>
17
19
@@ -22,34 +24,64 @@ Author: Peter Schrammel
22
24
23
25
void shadow_memoryt::initialize_shadow_memory (
24
26
goto_symex_statet &state,
25
- const exprt & expr,
27
+ exprt expr,
26
28
const shadow_memory_field_definitionst::field_definitiont &fields)
27
29
{
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
+ }
29
63
}
30
64
31
- symbol_exprt shadow_memoryt::add_field (
65
+ const symbol_exprt & shadow_memoryt::add_field (
32
66
goto_symex_statet &state,
33
67
const exprt &expr,
34
68
const irep_idt &field_name,
35
69
const typet &field_type)
36
70
{
37
- // To be completed
38
-
39
71
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 (
42
73
field_type,
43
74
id2string (state.source .function_id ),
44
75
SHADOW_MEMORY_PREFIX + from_expr (expr) + " __" + id2string (field_name),
45
76
state.source .pc ->source_location (),
46
77
function_symbol.mode ,
47
78
state.symbol_table );
48
79
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 ()});
51
83
52
- return new_symbol. symbol_expr () ;
84
+ return addresses. back (). shadow ;
53
85
}
54
86
55
87
void shadow_memoryt::symex_set_field (
0 commit comments