-
Notifications
You must be signed in to change notification settings - Fork 273
Interpreter sparse memory #689
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
peterschrammel
merged 3 commits into
diffblue:test-gen-support
from
romainbrenguier:interpreter-sparse-memory
Mar 30, 2017
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected] | |
#include <stack> | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/sparse_vector.h> | ||
|
||
#include "goto_functions.h" | ||
#include "goto_trace.h" | ||
|
@@ -68,6 +69,9 @@ class interpretert:public messaget | |
// List of dynamically allocated symbols that are not in the symbol table | ||
typedef std::map<irep_idt, typet> dynamic_typest; | ||
|
||
typedef std::map<irep_idt, function_assignmentst> output_valuest; | ||
output_valuest output_values; | ||
|
||
// An assignment list annotated with the calling context. | ||
struct function_assignments_contextt | ||
{ | ||
|
@@ -103,27 +107,78 @@ class interpretert:public messaget | |
|
||
const goto_functionst &goto_functions; | ||
|
||
typedef std::unordered_map<irep_idt, unsigned, irep_id_hash> memory_mapt; | ||
typedef std::unordered_map<irep_idt, std::size_t, irep_id_hash> memory_mapt; | ||
typedef std::map<std::size_t, irep_idt> inverse_memory_mapt; | ||
memory_mapt memory_map; | ||
inverse_memory_mapt inverse_memory_map; | ||
|
||
const inverse_memory_mapt::value_type &address_to_object_record( | ||
std::size_t address) const | ||
{ | ||
auto lower_bound=inverse_memory_map.lower_bound(address); | ||
if(lower_bound->first!=address) | ||
{ | ||
assert(lower_bound!=inverse_memory_map.begin()); | ||
--lower_bound; | ||
} | ||
return *lower_bound; | ||
} | ||
|
||
irep_idt address_to_identifier(std::size_t address) const | ||
{ | ||
return address_to_object_record(address).second; | ||
} | ||
|
||
std::size_t address_to_offset(std::size_t address) const | ||
{ | ||
return address-(address_to_object_record(address).first); | ||
} | ||
|
||
std::size_t base_address_to_alloc_size(std::size_t address) const | ||
{ | ||
assert(address_to_offset(address)==0); | ||
auto upper_bound=inverse_memory_map.upper_bound(address); | ||
std::size_t next_alloc_address= | ||
upper_bound==inverse_memory_map.end() ? | ||
memory.size() : | ||
upper_bound->first; | ||
return next_alloc_address-address; | ||
} | ||
|
||
std::size_t base_address_to_actual_size(std::size_t address) const | ||
{ | ||
auto memory_iter=memory.find(address); | ||
if(memory_iter==memory.end()) | ||
return 0; | ||
std::size_t ret=0; | ||
std::size_t alloc_size=base_address_to_alloc_size(address); | ||
while(memory_iter!=memory.end() && ret<alloc_size) | ||
{ | ||
++ret; | ||
++memory_iter; | ||
} | ||
return ret; | ||
} | ||
|
||
class memory_cellt | ||
{ | ||
public: | ||
irep_idt identifier; | ||
unsigned offset; | ||
memory_cellt() : | ||
value(0), | ||
initialized(0) | ||
{} | ||
mp_integer value; | ||
// Initialized is annotated even during reads | ||
// Set to 1 when written-before-read, -1 when read-before-written | ||
mutable char initialized; | ||
}; | ||
|
||
typedef std::vector<memory_cellt> memoryt; | ||
typedef sparse_vectort<memory_cellt> memoryt; | ||
typedef std::map<std::string, const irep_idt &> parameter_sett; | ||
// mapping <structure, field> -> value | ||
typedef std::pair<const irep_idt, const irep_idt> struct_member_idt; | ||
typedef std::map<struct_member_idt, const exprt> struct_valuest; | ||
|
||
|
||
// The memory is being annotated/reshaped even during reads | ||
// (ie to find a read-before-write location) thus memory | ||
// properties need to be mutable to avoid making all calls nonconst | ||
|
@@ -135,6 +190,7 @@ class interpretert:public messaget | |
void build_memory_map(const symbolt &symbol); | ||
mp_integer build_memory_map(const irep_idt &id, const typet &type); | ||
typet concretize_type(const typet &type); | ||
bool unbounded_size(const typet &); | ||
size_t get_size(const typet &type); | ||
|
||
irep_idt get_component_id(const irep_idt &object, unsigned offset); | ||
|
@@ -169,6 +225,10 @@ class interpretert:public messaget | |
mp_integer address, | ||
mp_vectort &dest) const; | ||
|
||
void read_unbounded( | ||
mp_integer address, | ||
mp_vectort &dest) const; | ||
|
||
virtual void command(); | ||
|
||
class stack_framet | ||
|
Oops, something went wrong.
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.
Is this convention documented?
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.
I added comments about this in this commit 1a97a94