ROSE 0.11.145.147
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#include <boost/serialization/access.hpp>
14#include <boost/serialization/export.hpp>
15#include <boost/serialization/list.hpp>
16#include <list>
17
18namespace Rose {
19namespace BinaryAnalysis {
20namespace InstructionSemantics {
21namespace BaseSemantics {
22
31class MemoryCell: public boost::enable_shared_from_this<MemoryCell> {
32public:
35
37 class Visitor {
38 public:
39 virtual ~Visitor() {}
40 virtual void operator()(MemoryCellPtr&) = 0;
41 };
42
44 class Predicate {
45 public:
46 virtual ~Predicate() {};
47
51 virtual bool operator()(const MemoryCellPtr&) = 0;
52 };
53
55 class AllCells: public Predicate {
56 public:
57 virtual bool operator()(const MemoryCellPtr&) override {
58 return true;
59 }
60 };
61
65 class NonWrittenCells: public Predicate {
66 public:
67 virtual bool operator()(const MemoryCellPtr&) override;
68 };
69
70private:
71 SValuePtr address_; // Address of memory cell.
72 SValuePtr value_; // Value stored at that address.
73 AddressSet writers_; // Instructions that wrote to this cell
74 InputOutputPropertySet ioProperties_;
75 unsigned position_ = 0; // position when printing a memory state
76
78 // Serialization
79#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
80private:
81 friend class boost::serialization::access;
82
83 template<class S>
84 void serialize(S &s, const unsigned version) {
85 s & BOOST_SERIALIZATION_NVP(address_);
86 s & BOOST_SERIALIZATION_NVP(value_);
87 s & BOOST_SERIALIZATION_NVP(writers_);
88 s & BOOST_SERIALIZATION_NVP(ioProperties_);
89 if (version >= 1)
90 s & BOOST_SERIALIZATION_NVP(position_);
91 }
92#endif
93
95 // Real constructors
96protected:
97 MemoryCell(); // for serialization
98
100
101 // deep-copy cell list so modifying this new one doesn't alter the existing one
102 MemoryCell(const MemoryCell &other);
103
104public:
105 virtual ~MemoryCell();
106
108 // Static allocating constructors
109public:
113 }
114
116 static MemoryCellPtr instance(const MemoryCellPtr &other) {
117 return MemoryCellPtr(new MemoryCell(*other));
118 }
119
121 // Virtual constructors
122public:
125 return instance(address, value);
126 }
127
129 virtual MemoryCellPtr clone() const {
130 return MemoryCellPtr(new MemoryCell(*this));
131 }
132
134 // Dynamic pointer casts. No-op since this is the base class.
135public:
136 static MemoryCellPtr promote(const MemoryCellPtr &x) {
137 ASSERT_not_null(x);
138 return x;
139 }
140
142 // Methods first declared at this level of the class hierarchy
143public:
149 virtual SValuePtr address() const;
150 virtual void address(const SValuePtr &addr);
158 virtual SValuePtr value() const;
159 virtual void value(const SValuePtr &v);
165 virtual const AddressSet& getWriters() const {
166 return writers_;
167 }
168
175 bool insertWriter(rose_addr_t writerVa) /*final*/ { return writers_.insert(writerVa); }
176 virtual bool insertWriters(const AddressSet &writerVas) { return writers_.insert(writerVas); }
185 bool eraseWriter(rose_addr_t writerVa) /*final*/ { return writers_.erase(writerVa); }
186 virtual bool eraseWriters(const AddressSet &writerVas) { return writers_.erase(writerVas); }
194 void setWriter(rose_addr_t writerVa) /*final*/;
195 virtual void setWriters(const AddressSet &writerVas) { writers_.insert(writerVas); }
201 virtual void eraseWriters() { writers_.clear(); }
202
209 const InputOutputPropertySet& ioProperties() const { return ioProperties_; }
210 InputOutputPropertySet& ioProperties() { return ioProperties_; }
222 unsigned position() const { return position_; }
223 void position(unsigned p) { position_ = p; }
231 bool mayAlias(const MemoryCellPtr &other, RiscOperators *addrOps) const;
232
238 bool mustAlias(const MemoryCellPtr &other, RiscOperators *addrOps) const;
239
245 virtual void hash(Combinatorics::Hasher&) const;
246
249 void print(std::ostream &stream) const;
250 virtual void print(std::ostream&, Formatter&) const;
255 MemoryCellPtr obj;
256 Formatter &fmt;
257 public:
258 WithFormatter(const MemoryCellPtr &obj, Formatter &fmt): obj(obj), fmt(fmt) {}
259 void print(std::ostream &stream) const { obj->print(stream, fmt); }
260 };
261
271 WithFormatter operator+(const std::string &linePrefix);
273};
274
276using CellList = std::list<MemoryCellPtr>;
277
278std::ostream& operator<<(std::ostream&, const MemoryCell&);
279std::ostream& operator<<(std::ostream&, const MemoryCell::WithFormatter&);
280
281} // namespace
282} // namespace
283} // namespace
284} // namespace
285
288
289#endif
290#endif
virtual bool operator()(const MemoryCellPtr &) override
Invoked for some cell.
Definition MemoryCell.h:57
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:129
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:186
unsigned position() const
Property: Position in listings.
Definition MemoryCell.h:222
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:223
virtual void address(const SValuePtr &addr)
Property: Memory cell address.
InputOutputPropertySet & ioProperties()
Properties: Boolean property set.
Definition MemoryCell.h:210
bool eraseWriter(rose_addr_t writerVa)
Erase specified writers.
Definition MemoryCell.h:185
virtual void value(const SValuePtr &v)
Property: Memory cell value.
static MemoryCellPtr instance(const MemoryCellPtr &other)
Instantiates a new copy of an existing cell.
Definition MemoryCell.h:116
virtual bool insertWriters(const AddressSet &writerVas)
Insert writer information.
Definition MemoryCell.h:176
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:165
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:124
bool insertWriter(rose_addr_t writerVa)
Insert writer information.
Definition MemoryCell.h:175
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:209
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:111
virtual SValuePtr value() const
Property: Memory cell value.
void setWriter(rose_addr_t writerVa)
Sets writer information.
WithFormatter operator+(const std::string &linePrefix)
Used for printing states with formatting.
virtual void setWriters(const AddressSet &writerVas)
Sets writer information.
Definition MemoryCell.h:195
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
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
std::list< MemoryCellPtr > CellList
List of memory cells.
Definition MemoryCell.h:276
The ROSE library.