-
Notifications
You must be signed in to change notification settings - Fork 277
Introduce a renamedt type for renamed expressions in symex #4305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tautschnig
merged 7 commits into
diffblue:develop
from
romainbrenguier:refactor/renamedt
Mar 3, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43eb277
Define a symex_level2t::operator()
romainbrenguier 012b2e0
Make symex_level::rename functions return a value
romainbrenguier c2eda2f
Move levelt to renaming_level.h
romainbrenguier de0f2a5
Introduce renamedt type for result of rename
romainbrenguier ba9e63d
Make symex_level0t::operator() return a renamedt
romainbrenguier 4bb3472
Make symex_level1t::operator() return a renamedt
romainbrenguier b5ae64b
Make symex_level2t::operator() return a renamedt
romainbrenguier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,45 +17,54 @@ Author: Romain Brenguier, [email protected] | |
|
||
#include "goto_symex_state.h" | ||
|
||
void symex_level0t:: | ||
operator()(ssa_exprt &ssa_expr, const namespacet &ns, unsigned thread_nr) const | ||
renamedt<ssa_exprt, L0> symex_level0t:: | ||
operator()(ssa_exprt ssa_expr, const namespacet &ns, unsigned thread_nr) const | ||
{ | ||
// already renamed? | ||
if(!ssa_expr.get_level_0().empty()) | ||
return; | ||
return renamedt<ssa_exprt, L0>{std::move(ssa_expr)}; | ||
|
||
const irep_idt &obj_identifier = ssa_expr.get_object_name(); | ||
|
||
// guards are not L0-renamed | ||
if(obj_identifier == goto_symex_statet::guard_identifier()) | ||
return; | ||
return renamedt<ssa_exprt, L0>{std::move(ssa_expr)}; | ||
|
||
const symbolt *s; | ||
const bool found_l0 = !ns.lookup(obj_identifier, s); | ||
INVARIANT(found_l0, "level0: failed to find " + id2string(obj_identifier)); | ||
|
||
// don't rename shared variables or functions | ||
if(s->type.id() == ID_code || s->is_shared()) | ||
return; | ||
return renamedt<ssa_exprt, L0>{std::move(ssa_expr)}; | ||
|
||
// rename! | ||
ssa_expr.set_level_0(thread_nr); | ||
return renamedt<ssa_exprt, L0>{ssa_expr}; | ||
} | ||
|
||
void symex_level1t::operator()(ssa_exprt &ssa_expr) const | ||
renamedt<ssa_exprt, L1> symex_level1t:: | ||
operator()(renamedt<ssa_exprt, L0> l0_expr) const | ||
{ | ||
// already renamed? | ||
if(!ssa_expr.get_level_1().empty()) | ||
return; | ||
if(!l0_expr.get().get_level_1().empty()) | ||
return renamedt<ssa_exprt, L1>{std::move(l0_expr.value)}; | ||
|
||
const irep_idt l0_name = ssa_expr.get_l1_object_identifier(); | ||
const irep_idt l0_name = l0_expr.get().get_l1_object_identifier(); | ||
|
||
const auto it = current_names.find(l0_name); | ||
if(it == current_names.end()) | ||
return; | ||
return renamedt<ssa_exprt, L1>{std::move(l0_expr.value)}; | ||
|
||
// rename! | ||
ssa_expr.set_level_1(it->second.second); | ||
l0_expr.value.set_level_1(it->second.second); | ||
return renamedt<ssa_exprt, L1>{std::move(l0_expr.value)}; | ||
} | ||
|
||
renamedt<ssa_exprt, L2> symex_level2t:: | ||
operator()(renamedt<ssa_exprt, L1> l1_expr) const | ||
{ | ||
l1_expr.value.set_level_2(current_count(l1_expr.get().get_identifier())); | ||
return renamedt<ssa_exprt, L2>{std::move(l1_expr.value)}; | ||
} | ||
|
||
void symex_level1t::restore_from( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,14 @@ Author: Romain Brenguier, [email protected] | |
#include <util/irep.h> | ||
#include <util/ssa_expr.h> | ||
|
||
/// Symex renaming level names. | ||
enum levelt | ||
{ | ||
L0 = 0, | ||
L1 = 1, | ||
L2 = 2 | ||
}; | ||
|
||
/// Wrapper for a \c current_names map, which maps each identifier to an SSA | ||
/// expression and a counter. | ||
/// This is extended by the different symex_level structures which are used | ||
|
@@ -51,13 +59,44 @@ struct symex_renaming_levelt | |
} | ||
}; | ||
|
||
/// Wrapper for expressions or types which have been renamed up to a given | ||
/// \p level | ||
template <typename underlyingt, levelt level> | ||
class renamedt | ||
{ | ||
public: | ||
static_assert( | ||
std::is_base_of<exprt, underlyingt>::value || | ||
std::is_base_of<typet, underlyingt>::value, | ||
"underlyingt should inherit from exprt or typet"); | ||
|
||
const underlyingt &get() const | ||
{ | ||
return value; | ||
} | ||
|
||
private: | ||
underlyingt value; | ||
|
||
friend struct symex_level0t; | ||
friend struct symex_level1t; | ||
friend struct symex_level2t; | ||
|
||
/// Only symex_levelXt classes can create renamedt objects | ||
explicit renamedt(underlyingt value) : value(std::move(value)) | ||
{ | ||
} | ||
}; | ||
|
||
/// Functor to set the level 0 renaming of SSA expressions. | ||
/// Level 0 corresponds to threads. | ||
/// The renaming is built for one particular interleaving. | ||
struct symex_level0t : public symex_renaming_levelt | ||
{ | ||
void operator()(ssa_exprt &ssa_expr, const namespacet &ns, unsigned thread_nr) | ||
const; | ||
renamedt<ssa_exprt, L0> operator()( | ||
ssa_exprt ssa_expr, | ||
const namespacet &ns, | ||
unsigned thread_nr) const; | ||
|
||
symex_level0t() = default; | ||
~symex_level0t() override = default; | ||
|
@@ -68,7 +107,7 @@ struct symex_level0t : public symex_renaming_levelt | |
/// This is to preserve locality in case of recursion | ||
struct symex_level1t : public symex_renaming_levelt | ||
{ | ||
void operator()(ssa_exprt &ssa_expr) const; | ||
renamedt<ssa_exprt, L1> operator()(renamedt<ssa_exprt, L0> l0_expr) const; | ||
|
||
/// Insert the content of \p other into this renaming | ||
void restore_from(const current_namest &other); | ||
|
@@ -82,6 +121,8 @@ struct symex_level1t : public symex_renaming_levelt | |
/// This is to ensure each variable is only assigned once. | ||
struct symex_level2t : public symex_renaming_levelt | ||
{ | ||
renamedt<ssa_exprt, L2> operator()(renamedt<ssa_exprt, L1> l1_expr) const; | ||
|
||
symex_level2t() = default; | ||
~symex_level2t() override = default; | ||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underlyingt
appears to bessa_exprt
everywhere -- simply hardwire that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now it is, but my plan is to next use it with
exprt
(draft PR here: #3986 though it needs to be rebased on this one), we could also think of using it with typet