CBMC
shadow_memory.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Symex Shadow Memory Instrumentation
4 
5 Author: Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_SYMEX_SHADOW_MEMORY_H
13 #define CPROVER_GOTO_SYMEX_SHADOW_MEMORY_H
14 
15 #include <util/expr.h>
16 #include <util/message.h>
17 
19 
20 #define SHADOW_MEMORY_PREFIX "SM__"
21 #define SHADOW_MEMORY_FIELD_DECL "field_decl"
22 #define SHADOW_MEMORY_GLOBAL_SCOPE "_global"
23 #define SHADOW_MEMORY_LOCAL_SCOPE "_local"
24 #define SHADOW_MEMORY_GET_FIELD "get_field"
25 #define SHADOW_MEMORY_SET_FIELD "set_field"
26 #define SHADOW_MEMORY_SYMBOL_PREFIX "__SM"
27 
30 class goto_symex_statet;
31 class side_effect_exprt;
32 class ssa_exprt;
33 class symbol_exprt;
34 
37 {
38 public:
40  const std::function<void(goto_symex_statet &, const exprt &, const exprt &)>
42  const namespacet &ns,
43  message_handlert &message_handler)
44  : symex_assign(symex_assign), ns(ns), log(message_handler)
45  {
46  }
47 
54  const abstract_goto_modelt &goto_model,
55  message_handlert &message_handler);
56 
60  void symex_field_static_init(goto_symex_statet &state, const ssa_exprt &lhs);
61 
67  goto_symex_statet &state,
68  const ssa_exprt &expr,
69  const exprt &rhs);
70 
74  void symex_field_local_init(goto_symex_statet &state, const ssa_exprt &expr);
75 
81  goto_symex_statet &state,
82  const exprt &expr,
83  const side_effect_exprt &code);
84 
89  void symex_get_field(
90  goto_symex_statet &state,
91  const exprt &lhs,
92  const exprt::operandst &arguments);
93 
97  void
98  symex_set_field(goto_symex_statet &state, const exprt::operandst &arguments);
99 
100 private:
106  static void convert_field_declaration(
107  const code_function_callt &code_function_call,
109  bool is_global,
110  message_handlert &message_handler);
111 
118  goto_symex_statet &state,
119  exprt expr,
121 
128  const symbol_exprt &add_field(
129  goto_symex_statet &state,
130  const exprt &expr,
131  const irep_idt &field_name,
132  const typet &field_type);
133 
134 private:
135  const std::function<void(goto_symex_statet &, const exprt &, const exprt)>
137  const namespacet &ns;
139 };
140 
141 #endif // CPROVER_GOTO_SYMEX_SHADOW_MEMORY_H
Abstract interface to eager or lazy GOTO models.
goto_instruction_codet representation of a function call statement.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
std::vector< exprt > operandst
Definition: expr.h:58
Central data structure: state.
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
The shadow memory field definitions.
std::map< irep_idt, exprt > field_definitiont
A field definition mapping a field name to its initial value.
The shadow memory instrumentation performed during symbolic execution.
Definition: shadow_memory.h:37
const symbol_exprt & add_field(goto_symex_statet &state, const exprt &expr, const irep_idt &field_name, const typet &field_type)
Registers a shadow memory field for the given original memory.
void symex_get_field(goto_symex_statet &state, const exprt &lhs, const exprt::operandst &arguments)
Symbolically executes a __CPROVER_get_field call.
static void convert_field_declaration(const code_function_callt &code_function_call, shadow_memory_field_definitionst::field_definitiont &fields, bool is_global, message_handlert &message_handler)
Converts a field declaration.
void symex_field_dynamic_init(goto_symex_statet &state, const exprt &expr, const side_effect_exprt &code)
Initialize global-scope shadow memory for dynamically allocated memory.
void symex_field_static_init(goto_symex_statet &state, const ssa_exprt &lhs)
Initialize global-scope shadow memory for global/static variables.
const std::function< void(goto_symex_statet &, const exprt &, const exprt)> symex_assign
void symex_field_static_init_string_constant(goto_symex_statet &state, const ssa_exprt &expr, const exprt &rhs)
Initialize global-scope shadow memory for string constants.
const namespacet & ns
static shadow_memory_field_definitionst gather_field_declarations(const abstract_goto_modelt &goto_model, message_handlert &message_handler)
Gathers the available shadow memory field definitions (__CPROVER_field_decl calls) from the goto mode...
void symex_field_local_init(goto_symex_statet &state, const ssa_exprt &expr)
Initialize local-scope shadow memory for local variables and parameters.
shadow_memoryt(const std::function< void(goto_symex_statet &, const exprt &, const exprt &)> symex_assign, const namespacet &ns, message_handlert &message_handler)
Definition: shadow_memory.h:39
void initialize_shadow_memory(goto_symex_statet &state, exprt expr, const shadow_memory_field_definitionst::field_definitiont &fields)
Allocates and initializes a shadow memory field for the given original memory.
void symex_set_field(goto_symex_statet &state, const exprt::operandst &arguments)
Symbolically executes a __CPROVER_set_field call.
An expression containing a side effect.
Definition: std_code.h:1450
Expression providing an SSA-renamed symbol of expressions.
Definition: ssa_expr.h:17
Expression to hold a symbol (variable)
Definition: std_expr.h:131
The type of an expression, extends irept.
Definition: type.h:29
Symex Shadow Memory Field Definitions.