Skip to content

Commit 3743787

Browse files
Add extract_field_name in new shadow_memory_util.h/.cpp
One of the utility functions that we are going to need in the shadow memory instrumentation implementation. We put these utility functions into a separate in order not to bloat the shadow_memory.cpp file.
1 parent 339d17c commit 3743787

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/goto-symex/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SRC = auto_objects.cpp \
1515
precondition.cpp \
1616
renaming_level.cpp \
1717
shadow_memory.cpp \
18+
shadow_memory_util.cpp \
1819
show_program.cpp \
1920
show_vcc.cpp \
2021
slice.cpp \

src/goto-symex/shadow_memory_util.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************\
2+
3+
Module: Symex Shadow Memory Instrumentation
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Symex Shadow Memory Instrumentation Utilities
11+
12+
#include "shadow_memory_util.h"
13+
14+
#include <util/invariant.h>
15+
#include <util/pointer_expr.h>
16+
#include <util/std_expr.h>
17+
18+
irep_idt extract_field_name(const exprt &string_expr)
19+
{
20+
if(string_expr.id() == ID_typecast)
21+
return extract_field_name(to_typecast_expr(string_expr).op());
22+
else if(string_expr.id() == ID_address_of)
23+
return extract_field_name(to_address_of_expr(string_expr).object());
24+
else if(string_expr.id() == ID_index)
25+
return extract_field_name(to_index_expr(string_expr).array());
26+
else if(string_expr.id() == ID_string_constant)
27+
{
28+
return string_expr.get(ID_value);
29+
}
30+
else
31+
UNREACHABLE;
32+
}

src/goto-symex/shadow_memory_util.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************\
2+
3+
Module: Symex Shadow Memory Instrumentation
4+
5+
Author: Peter Schrammel
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Symex Shadow Memory Instrumentation Utilities
11+
12+
#ifndef CPROVER_GOTO_SYMEX_SHADOW_MEMORY_UTIL_H
13+
#define CPROVER_GOTO_SYMEX_SHADOW_MEMORY_UTIL_H
14+
15+
#include <util/irep.h>
16+
17+
class exprt;
18+
19+
/// Extracts the field name identifier from a string expression,
20+
/// e.g. as passed as argument to a __CPROVER_field_decl_local call.
21+
/// \param string_expr The string argument expression
22+
/// \return The identifier denoted by the string argument expression
23+
irep_idt extract_field_name(const exprt &string_expr);
24+
25+
#endif // CPROVER_GOTO_SYMEX_SHADOW_MEMORY_STATE_H

0 commit comments

Comments
 (0)