ROSE 0.11.145.237
MemoryCell.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryCell_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryCell_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/AddressSet.h>
8#include <Combinatorics.h> // rose
9
10#include <Sawyer/Set.h>
11
12#include <boost/enable_shared_from_this.hpp>
13
14#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
15#include <boost/serialization/access.hpp>
16#include <boost/serialization/export.hpp>
17#include <boost/serialization/list.hpp>
18#endif
19
20#include <list>
21
22namespace Rose {
23namespace BinaryAnalysis {
24namespace InstructionSemantics {
25namespace BaseSemantics {
26
35class MemoryCell: public boost::enable_shared_from_this<MemoryCell> {
36public:
39
41 class Visitor {
42 public:
43 virtual ~Visitor() {}
44 virtual void operator()(MemoryCellPtr&) = 0;
45 };
46
48 class Predicate {
49 public:
50 virtual ~Predicate() {};
51
55 virtual bool operator()(const MemoryCellPtr&) = 0;
56 };
57
59 class AllCells: public Predicate {
60 public:
61 virtual bool operator()(const MemoryCellPtr&) override {
62 return true;
63 }
64 };
65
69 class NonWrittenCells: public Predicate {
70 public:
71 virtual bool operator()(const MemoryCellPtr&) override;
72 };
73
74private:
75 SValuePtr address_; // Address of memory cell.
76 SValuePtr value_; // Value stored at that address.
77 AddressSet writers_; // Instructions that wrote to this cell
78 InputOutputPropertySet ioProperties_;
79 unsigned position_ = 0; // position when printing a memory state
80
82 // Serialization
83#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
84private:
85 friend class boost::serialization::access;
86
87 template<class S>
88 void serialize(S &s, const unsigned version) {
89 s & BOOST_SERIALIZATION_NVP(address_);
90 s & BOOST_SERIALIZATION_NVP(value_);
91 s & BOOST_SERIALIZATION_NVP(writers_);
92 s & BOOST_SERIALIZATION_NVP(ioProperties_);
93 if (version >= 1)
94 s & BOOST_SERIALIZATION_NVP(position_);
95 }
96#endif
97
99 // Real constructors
100protected:
101 MemoryCell(); // for serialization
102
104
105 // deep-copy cell list so modifying this new one doesn't alter the existing one
106 MemoryCell(const MemoryCell &other);
107
108public:
109 virtual ~MemoryCell();
110
112 // Static allocating constructors
113public:
117 }
118
120 static MemoryCellPtr instance(const MemoryCellPtr &other) {
121 return MemoryCellPtr(new MemoryCell(*other));
122 }
123
125 // Virtual constructors
126public:
129 return instance(address, value);
130 }
131
133 virtual MemoryCellPtr clone() const {
134 return MemoryCellPtr(new MemoryCell(*this));
135 }
136
138 // Dynamic pointer casts. No-op since this is the base class.
139public:
140 static MemoryCellPtr promote(const MemoryCellPtr &x) {
141 ASSERT_not_null(x);
142 return x;
143 }
144
146 // Methods first declared at this level of the class hierarchy
147public:
153 virtual SValuePtr address() const;
154 virtual void address(const SValuePtr &addr);
162 virtual SValuePtr value() const;
163 virtual void value(const SValuePtr &v);
169 virtual const AddressSet& getWriters() const {
170 return writers_;
171 }
172
179 bool insertWriter(Address writerVa) /*final*/ { return writers_.insert(writerVa); }
180 virtual bool insertWriters(const AddressSet &writerVas) { return writers_.insert(writerVas); }
189 bool eraseWriter(Address writerVa) /*final*/ { return writers_.erase(writerVa); }
190 virtual bool eraseWriters(const AddressSet &writerVas) { return writers_.erase(writerVas); }
198 void setWriter(Address writerVa) /*final*/;
199 virtual void setWriters(const AddressSet &writerVas) { writers_.insert(writerVas); }
205 virtual void eraseWriters() { writers_.clear(); }
206
213 const InputOutputPropertySet& ioProperties() const { return ioProperties_; }
214 InputOutputPropertySet& ioProperties() { return ioProperties_; }
226 unsigned position() const { return position_; }
227 void position(unsigned p) { position_ = p; }
235 bool mayAlias(const MemoryCellPtr &other, RiscOperators *addrOps) const;
236
242 bool mustAlias(const MemoryCellPtr &other, RiscOperators *addrOps) const;
243
249 virtual void hash(Combinatorics::Hasher&) const;
250
253 void print(std::ostream &stream) const;
254 virtual void print(std::ostream&, Formatter&) const;
259 MemoryCellPtr obj;
260 Formatter &fmt;
261 public:
262 WithFormatter(const MemoryCellPtr &obj, Formatter &fmt): obj(obj), fmt(fmt) {}
263 void print(std::ostream &stream) const { obj->print(stream, fmt); }
264 };
265
275 WithFormatter operator+(const std::string &linePrefix);
277};
278
280using CellList = std::list<MemoryCellPtr>;
281
282std::ostream& operator<<(std::ostream&, const MemoryCell&);
283std::ostream& operator<<(std::ostream&, const MemoryCell::WithFormatter&);
284
285} // namespace
286} // namespace
287} // namespace
288} // namespace
289
290#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
293#endif
294
295#endif
296#endif
virtual bool operator()(const MemoryCellPtr &) override
Invoked for some cell.
Definition MemoryCell.h:61
virtual bool operator()(const MemoryCellPtr &) override
Invoked for some cell.
virtual bool operator()(const MemoryCellPtr &)=0
Invoked for some cell.
virtual MemoryCellPtr clone() const
Creates a new deep-copy of this memory cell.
Definition MemoryCell.h:133
WithFormatter operator+(Formatter &)
Used for printing states with formatting.
virtual SValuePtr address() const
Property: Memory cell address.
virtual bool eraseWriters(const AddressSet &writerVas)
Erase specified writers.
Definition MemoryCell.h:190
unsigned position() const
Property: Position in listings.
Definition MemoryCell.h:226
bool mustAlias(const MemoryCellPtr &other, RiscOperators *addrOps) const
Test whether two memory cells must alias one another.
void position(unsigned p)
Property: Position in listings.
Definition MemoryCell.h:227
virtual void address(const SValuePtr &addr)
Property: Memory cell address.
InputOutputPropertySet & ioProperties()
Properties: Boolean property set.
Definition MemoryCell.h:214
virtual void value(const SValuePtr &v)
Property: Memory cell value.
bool eraseWriter(Address writerVa)
Erase specified writers.
Definition MemoryCell.h:189
static MemoryCellPtr instance(const MemoryCellPtr &other)
Instantiates a new copy of an existing cell.
Definition MemoryCell.h:120
bool insertWriter(Address writerVa)
Insert writer information.
Definition MemoryCell.h:179
virtual bool insertWriters(const AddressSet &writerVas)
Insert writer information.
Definition MemoryCell.h:180
void setWriter(Address writerVa)
Sets writer information.
virtual void print(std::ostream &, Formatter &) const
Print the memory cell on a single line.
virtual const AddressSet & getWriters() const
Get writer information.
Definition MemoryCell.h:169
WithFormatter with_format(Formatter &)
Used for printing states with formatting.
virtual MemoryCellPtr create(const SValuePtr &address, const SValuePtr &value)
Creates a new memory cell object with the specified address and value.
Definition MemoryCell.h:128
bool mayAlias(const MemoryCellPtr &other, RiscOperators *addrOps) const
Test whether two memory cells can alias one another.
const InputOutputPropertySet & ioProperties() const
Properties: Boolean property set.
Definition MemoryCell.h:213
void print(std::ostream &stream) const
Print the memory cell on a single line.
static MemoryCellPtr instance(const SValuePtr &address, const SValuePtr &value)
Instantiates a new memory cell object with the specified address and value.
Definition MemoryCell.h:115
virtual SValuePtr value() const
Property: Memory cell value.
WithFormatter operator+(const std::string &linePrefix)
Used for printing states with formatting.
virtual void setWriters(const AddressSet &writerVas)
Sets writer information.
Definition MemoryCell.h:199
virtual void hash(Combinatorics::Hasher &) const
Hash the address and value.
Base class for most instruction semantics RISC operators.
bool insert(const Value &value)
Insert a value.
Definition Set.h:258
bool erase(const Value &value)
Erase a value.
Definition Set.h:278
void clear()
Erase all values.
Definition Set.h:298
Base classes for instruction semantics.
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
std::list< MemoryCellPtr > CellList
List of memory cells.
Definition MemoryCell.h:280
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.