ROSE 0.11.145.192
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#include <boost/serialization/access.hpp>
10#include <boost/serialization/base_object.hpp>
11#include <boost/serialization/export.hpp>
12
13namespace Rose {
14namespace BinaryAnalysis {
15namespace InstructionSemantics {
16namespace BaseSemantics {
17
19typedef boost::shared_ptr<class MemoryCellList> MemoryCellListPtr;
20
40public:
43
46
47protected:
48 CellList cells; // list of cells in reverse chronological order
49 bool occlusionsErased_; // prune away old cells that are occluded by newer ones.
50
52 // Serialization
53#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
54private:
55 friend class boost::serialization::access;
56
57 template<class S>
58 void serialize(S &s, const unsigned /*version*/) {
59 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
60 s & BOOST_SERIALIZATION_NVP(cells);
61 s & BOOST_SERIALIZATION_NVP(occlusionsErased_);
62 }
63#endif
64
66 // Real constructors
67public:
69
70protected:
71 MemoryCellList(); // only used for deserialization
72
73 explicit MemoryCellList(const MemoryCellPtr &protocell);
74
75 MemoryCellList(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
76
77 // deep-copy cell list so that modifying this new state does not modify the existing state
78 MemoryCellList(const MemoryCellList &other);
79
81 // Static allocating constructors
82public:
86 static MemoryCellListPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
87
89 static MemoryCellListPtr instance(const MemoryCellPtr &protocell);
90
93
95 // Virtual constructors
96public:
97 virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override;
98
100 virtual MemoryStatePtr create(const MemoryCellPtr &protocell) const;
101
102 virtual AddressSpacePtr clone() const override;
103
105 // Dynamic pointer casts
106public:
110
112 // Methods we inherited
113public:
114 virtual void clear() override;
115 virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
116 virtual std::vector<MemoryCellPtr> matchingCells(MemoryCell::Predicate&) const override;
117 virtual std::vector<MemoryCellPtr> leadingCells(MemoryCell::Predicate&) const override;
120 virtual void traverse(MemoryCell::Visitor&) override;
121 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
122
133 virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
134 RiscOperators *addrOps, RiscOperators *valOps) override;
135
136 virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
137 RiscOperators *addrOps, RiscOperators *valOps) override;
138
145 virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value,
146 RiscOperators *addrOps, RiscOperators *valOps) override;
147
148 virtual void print(std::ostream&, Formatter&) const override;
149
151 // Methods first declared at this level of the class hierarchy
152public:
157 bool mergeNoAliasing(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps);
158
163 bool mergeWithAliasing(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps);
164
169 virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps, RiscOperators *valOps) const;
170
177 bool occlusionsErased() const { return occlusionsErased_; }
178 void occlusionsErased(bool b) { occlusionsErased_ = b; }
196 template<class Iterator>
197 CellList scan(Iterator &cursor /*in,out*/, const SValuePtr &addr, size_t nBits,
198 RiscOperators *addrOps, RiscOperators *valOps) const {
199 ASSERT_not_null(addr);
200 CellList retval;
201 MemoryCellPtr tempCell = protocell->create(addr, valOps->undefined_(nBits));
202 for (/*void*/; cursor!=cells.end(); ++cursor) {
203 if (tempCell->mayAlias(*cursor, addrOps)) {
204 retval.push_back(*cursor);
205 if (tempCell->mustAlias(*cursor, addrOps))
206 break;
207 }
208 }
209 return retval;
210 }
211
214 virtual const CellList& get_cells() const { return cells; }
215 virtual CellList& get_cells() { return cells; }
218 virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
219 RiscOperators *valOps) override;
220
221 virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
222 RiscOperators *valOps) override;
223
224protected:
225 // Compute a new value by merging the specified cells. If the cell list is empty return the specified default.
226 virtual SValuePtr mergeCellValues(const CellList &cells, const SValuePtr &dflt, RiscOperators *addrOps,
227 RiscOperators *valOps);
228
229 // Returns the union of all writers from the specified cells.
230 virtual AddressSet mergeCellWriters(const CellList &cells);
231
232 // Returns the union of all properties from the specified cells.
233 virtual InputOutputPropertySet mergeCellProperties(const CellList &cells);
234
235 // Insert a new cell at the head of the list. It's writers set is empty and its I/O properties will be READ,
236 // READ_BEFORE_WRITE, and READ_UNINITIALIZED.
237 virtual MemoryCellPtr insertReadCell(const SValuePtr &addr, const SValuePtr &value);
238
239 // Insert a new cell at the head of the list. The specified writers and I/O properties are used.
240 virtual MemoryCellPtr insertReadCell(const SValuePtr &addr, const SValuePtr &value,
241 const AddressSet &writers, const InputOutputPropertySet &props);
242};
243
244} // namespace
245} // namespace
246} // namespace
247} // namespace
248
249#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
251#endif
252
253#endif
254#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:276
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.