CBMC
|
#include <allocate_objects.h>
Public Member Functions | |
allocate_objectst (const irep_idt &symbol_mode, const source_locationt &source_location, const irep_idt &name_prefix, symbol_table_baset &symbol_table) | |
exprt | allocate_object (code_blockt &assignments, const exprt &target_expr, const typet &allocate_type, const lifetimet lifetime, const irep_idt &basename_prefix="tmp") |
Allocates a new object, either by creating a local variable with automatic lifetime, a global variable with static lifetime, or by dynamically allocating memory via ALLOCATE(). | |
exprt | allocate_automatic_local_object (code_blockt &assignments, const exprt &target_expr, const typet &allocate_type, const irep_idt &basename_prefix="tmp") |
Creates a local variable with automatic lifetime. | |
exprt | allocate_static_global_object (code_blockt &assignments, const exprt &target_expr, const typet &allocate_type, const irep_idt &basename_prefix="tmp") |
Creates a global variable with static lifetime. | |
exprt | allocate_dynamic_object_symbol (code_blockt &output_code, const exprt &target_expr, const typet &allocate_type) |
Generates code for allocating a dynamic object. | |
exprt | allocate_dynamic_object (code_blockt &output_code, const exprt &target_expr, const typet &allocate_type) |
Generate the same code as allocate_dynamic_object_symbol, but return a dereference_exprt that dereferences the newly created pointer to the allocated memory. | |
symbol_exprt | allocate_automatic_local_object (const typet &allocate_type, const irep_idt &basename_prefix="tmp") |
Creates a local variable with automatic lifetime and returns it as a symbol expression. | |
void | add_created_symbol (const symbolt &symbol) |
Add a pointer to a symbol to the list of pointers to symbols created so far. | |
void | declare_created_symbols (code_blockt &init_code) |
Adds declarations for all non-static symbols created. | |
void | mark_created_symbols_as_input (code_blockt &init_code) |
Adds code to mark the created symbols as input. | |
Private Member Functions | |
exprt | allocate_non_dynamic_object (code_blockt &assignments, const exprt &target_expr, const typet &allocate_type, const bool static_lifetime, const irep_idt &basename_prefix) |
Private Attributes | |
const irep_idt | symbol_mode |
const source_locationt | source_location |
const irep_idt | name_prefix |
symbol_table_baset & | symbol_table |
const namespacet | ns |
std::vector< irep_idt > | symbols_created |
Definition at line 26 of file allocate_objects.h.
|
inline |
Definition at line 29 of file allocate_objects.h.
Add a pointer to a symbol to the list of pointers to symbols created so far.
symbol | symbol in the symbol table |
Definition at line 221 of file allocate_objects.cpp.
exprt allocate_objectst::allocate_automatic_local_object | ( | code_blockt & | assignments, |
const exprt & | target_expr, | ||
const typet & | allocate_type, | ||
const irep_idt & | basename_prefix = "tmp" |
||
) |
Creates a local variable with automatic lifetime.
Code is added to assignments
which assigns a pointer to the variable to target_expr
. The allocate_type
may differ from target_expr.type()
, e.g. for target_expr
having type int*
and allocate_type
being an int[10]
..
assignments | The code block to add code to. |
target_expr | A pointer to the variable will be assigned to this lvalue expression |
allocate_type | Type of the new variable |
basename_prefix | prefix of the basename of the new variable |
Definition at line 72 of file allocate_objects.cpp.
symbol_exprt allocate_objectst::allocate_automatic_local_object | ( | const typet & | allocate_type, |
const irep_idt & | basename_prefix = "tmp" |
||
) |
Creates a local variable with automatic lifetime and returns it as a symbol expression.
allocate_type | Type of the new variable |
basename_prefix | prefix of the basename of the new variable |
Definition at line 109 of file allocate_objects.cpp.
exprt allocate_objectst::allocate_dynamic_object | ( | code_blockt & | output_code, |
const exprt & | target_expr, | ||
const typet & | allocate_type | ||
) |
Generate the same code as allocate_dynamic_object_symbol, but return a dereference_exprt that dereferences the newly created pointer to the allocated memory.
Definition at line 174 of file allocate_objects.cpp.
exprt allocate_objectst::allocate_dynamic_object_symbol | ( | code_blockt & | output_code, |
const exprt & | target_expr, | ||
const typet & | allocate_type | ||
) |
Generates code for allocating a dynamic object.
A new variable with basename prefix alloc_site
is introduced to which the allocated memory is assigned. Then, the variable is assigned to target_expr
. For example, with target_expr
being *p
the following code is generated:
alloc_site$1 = ALLOCATE(object_size, FALSE);
*p = alloc_site$1;
output_code | Code block to which the necessary code is added |
target_expr | A pointer to the allocated memory will be assigned to this (lvalue) expression |
allocate_type | Type of the object allocated |
allocate_type
is void Definition at line 126 of file allocate_objects.cpp.
|
private |
Definition at line 183 of file allocate_objects.cpp.
exprt allocate_objectst::allocate_object | ( | code_blockt & | assignments, |
const exprt & | target_expr, | ||
const typet & | allocate_type, | ||
const lifetimet | lifetime, | ||
const irep_idt & | basename_prefix = "tmp" |
||
) |
Allocates a new object, either by creating a local variable with automatic lifetime, a global variable with static lifetime, or by dynamically allocating memory via ALLOCATE().
Code is added to assignments
which assigns a pointer to the allocated memory to target_expr
. The allocate_type
may differ from target_expr.type()
, e.g. for target_expr having type int*
and allocate_type
being an int[10]
.
assignments | The code block to add code to. |
target_expr | A pointer to the allocated memory will be assigned to this lvalue expression |
allocate_type | Type of the object allocated |
lifetime | Lifetime of the allocated object (AUTOMATIC_LOCAL, STATIC_GLOBAL, or DYNAMIC) |
basename_prefix | prefix of the basename of the new variable |
Definition at line 34 of file allocate_objects.cpp.
exprt allocate_objectst::allocate_static_global_object | ( | code_blockt & | assignments, |
const exprt & | target_expr, | ||
const typet & | allocate_type, | ||
const irep_idt & | basename_prefix = "tmp" |
||
) |
Creates a global variable with static lifetime.
Code is added to assignments
which assigns a pointer to the variable to target_expr
. The allocate_type
may differ from target_expr.type()
, e.g. for target_expr
having type int*
and allocate_type
being an int[10]
.
assignments | The code block to add code to. |
target_expr | A pointer to the variable will be assigned to this lvalue expression |
allocate_type | Type of the new variable |
basename_prefix | prefix of the basename of the new variable |
Definition at line 93 of file allocate_objects.cpp.
void allocate_objectst::declare_created_symbols | ( | code_blockt & | init_code | ) |
Adds declarations for all non-static symbols created.
init_code | code block to which to add the declarations |
Definition at line 229 of file allocate_objects.cpp.
void allocate_objectst::mark_created_symbols_as_input | ( | code_blockt & | init_code | ) |
Adds code to mark the created symbols as input.
init_code | code block to which to add the generated code |
Definition at line 248 of file allocate_objects.cpp.
Definition at line 102 of file allocate_objects.h.
|
private |
Definition at line 105 of file allocate_objects.h.
|
private |
Definition at line 101 of file allocate_objects.h.
Definition at line 100 of file allocate_objects.h.
|
private |
Definition at line 104 of file allocate_objects.h.
|
private |
Definition at line 107 of file allocate_objects.h.