ROSE 0.11.145.250
MemoryCellList.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryCellList_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryCellList_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellState.h>
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/RiscOperators.h>
8
9#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
10#include <boost/serialization/access.hpp>
11#include <boost/serialization/base_object.hpp>
12#include <boost/serialization/export.hpp>
13#endif
14
15namespace Rose {
16namespace BinaryAnalysis {
17namespace InstructionSemantics {
18namespace BaseSemantics {
19
21typedef boost::shared_ptr<class MemoryCellList> MemoryCellListPtr;
22
42public:
45
48
49protected:
50 CellList cells; // list of cells in reverse chronological order
51 bool occlusionsErased_; // prune away old cells that are occluded by newer ones.
52
54 // Serialization
55#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
56private:
57 friend class boost::serialization::access;
58
59 template<class S>
60 void serialize(S &s, const unsigned /*version*/) {
61 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
62 s & BOOST_SERIALIZATION_NVP(cells);
63 s & BOOST_SERIALIZATION_NVP(occlusionsErased_);
64 }
65#endif
66
68 // Real constructors
69public:
71
72protected:
73 MemoryCellList(); // only used for deserialization
74
75 explicit MemoryCellList(const MemoryCellPtr &protocell);
76
77 MemoryCellList(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
78
79 // deep-copy cell list so that modifying this new state does not modify the existing state
80 MemoryCellList(const MemoryCellList &other);
81
83 // Static allocating constructors
84public:
88 static MemoryCellListPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
89
91 static MemoryCellListPtr instance(const MemoryCellPtr &protocell);
92
95
97 // Virtual constructors
98public:
99 virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override;
100
102 virtual MemoryStatePtr create(const MemoryCellPtr &protocell) const;
103
104 virtual AddressSpacePtr clone() const override;
105
107 // Dynamic pointer casts
108public:
112
114 // Methods we inherited
115public:
116 virtual void clear() override;
117 virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
118 virtual std::vector<MemoryCellPtr> matchingCells(MemoryCell::Predicate&) const override;
119 virtual std::vector<MemoryCellPtr> leadingCells(MemoryCell::Predicate&) const override;
122 virtual void traverse(MemoryCell::Visitor&) override;
123 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
124
135 virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
136 RiscOperators *addrOps, RiscOperators *valOps) override;
137
138 virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
139 RiscOperators *addrOps, RiscOperators *valOps) override;
140
147 virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value,
148 RiscOperators *addrOps, RiscOperators *valOps) override;
149
150 virtual void print(std::ostream&, Formatter&) const override;
151
153 // Methods first declared at this level of the class hierarchy
154public:
159 bool mergeNoAliasing(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps);
160
165 bool mergeWithAliasing(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps);
166
171 virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps, RiscOperators *valOps) const;
172
179 bool occlusionsErased() const { return occlusionsErased_; }
180 void occlusionsErased(bool b) { occlusionsErased_ = b; }
198 template<class Iterator>
199 CellList scan(Iterator &cursor /*in,out*/, const SValuePtr &addr, size_t nBits,
200 RiscOperators *addrOps, RiscOperators *valOps) const {
201 ASSERT_not_null(addr);
202 CellList retval;
203 MemoryCellPtr tempCell = protocell->create(addr, valOps->undefined_(nBits));
204 for (/*void*/; cursor!=cells.end(); ++cursor) {
205 if (tempCell->mayAlias(*cursor, addrOps)) {
206 retval.push_back(*cursor);
207 if (tempCell->mustAlias(*cursor, addrOps))
208 break;
209 }
210 }
211 return retval;
212 }
213
216 virtual const CellList& get_cells() const { return cells; }
217 virtual CellList& get_cells() { return cells; }
220 virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
221 RiscOperators *valOps) override;
222
223 virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
224 RiscOperators *valOps) override;
225
226protected:
227 // Compute a new value by merging the specified cells. If the cell list is empty return the specified default.
228 virtual SValuePtr mergeCellValues(const CellList &cells, const SValuePtr &dflt, RiscOperators *addrOps,
229 RiscOperators *valOps);
230
231 // Returns the union of all writers from the specified cells.
232 virtual AddressSet mergeCellWriters(const CellList &cells);
233
234 // Returns the union of all properties from the specified cells.
235 virtual InputOutputPropertySet mergeCellProperties(const CellList &cells);
236
237 // Insert a new cell at the head of the list. It's writers set is empty and its I/O properties will be READ,
238 // READ_BEFORE_WRITE, and READ_UNINITIALIZED.
239 virtual MemoryCellPtr insertReadCell(const SValuePtr &addr, const SValuePtr &value);
240
241 // Insert a new cell at the head of the list. The specified writers and I/O properties are used.
242 virtual MemoryCellPtr insertReadCell(const SValuePtr &addr, const SValuePtr &value,
243 const AddressSet &writers, const InputOutputPropertySet &props);
244};
245
246} // namespace
247} // namespace
248} // namespace
249} // namespace
250
251#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
253#endif
254
255#endif
256#endif
virtual const CellList & get_cells() const
Returns the list of all memory cells.
virtual void traverse(MemoryCell::Visitor &) override
Traverse and modify cells.
virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory without side effects.
virtual std::vector< MemoryCellPtr > matchingCells(MemoryCell::Predicate &) const override
Find all matching cells.
static MemoryCellListPtr instance(const MemoryCellListPtr &other)
Instantiate a new copy of an existing memory state.
bool mergeWithAliasing(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps)
Merge two states with aliasing.
virtual CellList & get_cells()
Returns the list of all memory cells.
virtual AddressSpacePtr clone() const override
Deep-copy of this address space.
virtual MemoryStatePtr create(const MemoryCellPtr &protocell) const
Virtual allocating constructor.
virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) override
Writers for an address.
virtual std::vector< MemoryCellPtr > leadingCells(MemoryCell::Predicate &) const override
Find leading matching cells.
CellList scan(Iterator &cursor, const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) const
Scan cell list to find matching cells.
virtual void eraseLeadingCells(MemoryCell::Predicate &) override
Remove leading matching cells.
virtual void hash(Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const override
Hash this address space.
virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps, RiscOperators *valOps) const
Predicate to determine whether all bytes are present.
static MemoryCellListPtr promote(const BaseSemantics::AddressSpacePtr &m)
Promote a base address space pointer to a BaseSemantics::MemoryCellList pointer.
virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) override
Write a value to memory.
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory.
virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override
Virtual allocating constructor.
virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) override
Writers for an address.
static MemoryCellListPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
Instantiate a new prototypical memory state.
static MemoryCellListPtr instance(const MemoryCellPtr &protocell)
Instantiate a new memory state with prototypical memory cell.
virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override
Merge address spaces for data flow analysis.
virtual void print(std::ostream &, Formatter &) const override
Print an address space.
virtual void eraseMatchingCells(MemoryCell::Predicate &) override
Remove all matching cells.
bool mergeNoAliasing(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps)
Merge two states without aliasing.
Base class for most instruction semantics RISC operators.
virtual SValuePtr undefined_(size_t nbits)
Returns a new undefined value.
Base classes for instruction semantics.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
std::list< MemoryCellPtr > CellList
List of memory cells.
Definition MemoryCell.h:280
boost::shared_ptr< class MemoryCellList > MemoryCellListPtr
Shared-ownership pointer to a list-based memory state.
boost::shared_ptr< AddressSpace > AddressSpacePtr
Shared-ownership pointer for AddressSpace objects.
The ROSE library.