ROSE  0.9.9.139
MemoryCellList.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_MemoryCellList_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_MemoryCellList_H
3 
4 #include <BaseSemantics2.h>
5 #include <MemoryCellState.h>
6 
7 #include <boost/serialization/access.hpp>
8 #include <boost/serialization/base_object.hpp>
9 #include <boost/serialization/export.hpp>
10 
11 namespace Rose {
12 namespace BinaryAnalysis {
13 namespace InstructionSemantics2 {
14 namespace BaseSemantics {
15 
17 typedef boost::shared_ptr<class MemoryCellList> MemoryCellListPtr;
18 
38 public:
39  typedef std::list<MemoryCellPtr> CellList;
41 protected:
42  CellList cells; // list of cells in reverse chronological order
43  bool occlusionsErased_; // prune away old cells that are occluded by newer ones.
44 
46  // Serialization
47 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
48 private:
49  friend class boost::serialization::access;
50 
51  template<class S>
52  void serialize(S &s, const unsigned version) {
53  s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
54  s & BOOST_SERIALIZATION_NVP(cells);
55  s & BOOST_SERIALIZATION_NVP(occlusionsErased_);
56  }
57 #endif
58 
60  // Real constructors
61 protected:
62  MemoryCellList() // for serialization
63  : occlusionsErased_(false) {}
64 
65  explicit MemoryCellList(const MemoryCellPtr &protocell)
66  : MemoryCellState(protocell), occlusionsErased_(false) {}
67 
68  MemoryCellList(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
69  : MemoryCellState(addrProtoval, valProtoval), occlusionsErased_(false) {}
70 
71  // deep-copy cell list so that modifying this new state does not modify the existing state
72  MemoryCellList(const MemoryCellList &other)
73  : MemoryCellState(other), occlusionsErased_(other.occlusionsErased_) {
74  for (CellList::const_iterator ci=other.cells.begin(); ci!=other.cells.end(); ++ci)
75  cells.push_back((*ci)->clone());
76  }
77 
79  // Static allocating constructors
80 public:
84  static MemoryCellListPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) {
85  return MemoryCellListPtr(new MemoryCellList(addrProtoval, valProtoval));
86  }
87 
89  static MemoryCellListPtr instance(const MemoryCellPtr &protocell) {
90  return MemoryCellListPtr(new MemoryCellList(protocell));
91  }
92 
94  static MemoryCellListPtr instance(const MemoryCellListPtr &other) {
95  return MemoryCellListPtr(new MemoryCellList(*other));
96  }
97 
98 
100  // Virtual constructors
101 public:
102  virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const ROSE_OVERRIDE {
103  return instance(addrProtoval, valProtoval);
104  }
105 
107  virtual MemoryStatePtr create(const MemoryCellPtr &protocell) const {
108  return instance(protocell);
109  }
110 
111  virtual MemoryStatePtr clone() const ROSE_OVERRIDE {
112  return MemoryStatePtr(new MemoryCellList(*this));
113  }
114 
116  // Dynamic pointer casts
117 public:
120  static MemoryCellListPtr promote(const BaseSemantics::MemoryStatePtr &m) {
121  MemoryCellListPtr retval = boost::dynamic_pointer_cast<MemoryCellList>(m);
122  ASSERT_not_null(retval);
123  return retval;
124  }
125 
127  // Methods we inherited
128 public:
129  virtual void clear() ROSE_OVERRIDE;
130  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
131  virtual std::vector<MemoryCellPtr> matchingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
132  virtual std::vector<MemoryCellPtr> leadingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
133  virtual void eraseMatchingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
134  virtual void eraseLeadingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
135  virtual void traverse(MemoryCell::Visitor&) ROSE_OVERRIDE;
136 
147  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
148  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
149 
156  virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value,
157  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
158 
159  virtual void print(std::ostream&, Formatter&) const ROSE_OVERRIDE;
160 
162  // Methods first declared at this level of the class hierarchy
163 public:
170  bool occlusionsErased() const { return occlusionsErased_; }
171  void occlusionsErased(bool b) { occlusionsErased_ = b; }
189  template<class Iterator>
190  CellList scan(Iterator &cursor /*in,out*/, const SValuePtr &addr, size_t nBits,
191  RiscOperators *addrOps, RiscOperators *valOps) const {
192  ASSERT_not_null(addr);
193  CellList retval;
194  MemoryCellPtr tempCell = protocell->create(addr, valOps->undefined_(nBits));
195  for (/*void*/; cursor!=cells.end(); ++cursor) {
196  if (tempCell->may_alias(*cursor, addrOps)) {
197  retval.push_back(*cursor);
198  if (tempCell->must_alias(*cursor, addrOps))
199  break;
200  }
201  }
202  return retval;
203  }
204 
205  // [Robb P. Matzke 2015-08-18]: deprecated
206  virtual CellList scan(const SValuePtr &address, size_t nbits, RiscOperators *addrOps, RiscOperators *valOps,
207  bool &short_circuited/*out*/) const ROSE_DEPRECATED("use the cursor-based scan instead");
208 
211  virtual const CellList& get_cells() const { return cells; }
212  virtual CellList& get_cells() { return cells; }
215  // [Robb Matzke 2015-12-26]: deprecated
216  virtual MemoryCellPtr get_latest_written_cell() const ROSE_DEPRECATED("use latestWrittenCell instead") {
217  return latestWrittenCell();
218  }
219 
220  virtual MemoryCell::AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
221  RiscOperators *valOps) ROSE_OVERRIDE;
222 
223  virtual MemoryCell::AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
224  RiscOperators *valOps) ROSE_OVERRIDE;
225 
226  // [Robb P. Matzke 2015-08-17]: deprecated
227  virtual std::set<rose_addr_t> get_latest_writers(const SValuePtr &addr, size_t nbits,
228  RiscOperators *addrOps, RiscOperators *valOps)
229  ROSE_DEPRECATED("use getWritersUnion instead");
230 
231 
232 protected:
233  // Compute a new value by merging the specified cells. If the cell list is empty return the specified default.
234  virtual SValuePtr mergeCellValues(const CellList &cells, const SValuePtr &dflt, RiscOperators *addrOps,
235  RiscOperators *valOps);
236 
237  // Returns the union of all writers from the specified cells.
238  virtual AddressSet mergeCellWriters(const CellList &cells);
239 
240  // Returns the union of all properties from the specified cells.
241  virtual InputOutputPropertySet mergeCellProperties(const CellList &cells);
242 
243  // Adjust I/O properties in the specified cells to make it look like they were just read. This adds the READ property and
244  // may also add READ_AFTER_WRITE, READ_BEFORE_WRITE, and/or READ_UNINITIALIZED.
245  virtual void updateReadProperties(CellList &cells);
246 
247  // Insert a new cell at the head of the list. It's writers set is empty and its I/O properties will be READ,
248  // READ_BEFORE_WRITE, and READ_UNINITIALIZED.
249  virtual MemoryCellPtr insertReadCell(const SValuePtr &addr, const SValuePtr &value);
250 
251  // Insert a new cell at the head of the list. The specified writers and I/O properties are used.
252  virtual MemoryCellPtr insertReadCell(const SValuePtr &addr, const SValuePtr &value,
253  const AddressSet &writers, const InputOutputPropertySet &props);
254 };
255 
256 } // namespace
257 } // namespace
258 } // namespace
259 } // namespace
260 
261 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
263 #endif
264 
265 #endif
boost::shared_ptr< class MemoryCell > MemoryCellPtr
Shared-ownership pointer to a semantic memory cell.
Definition: MemoryCell.h:15
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Read a value from memory.
virtual SValuePtr undefined_(size_t nbits)
Returns a new undefined value.
virtual const CellList & get_cells() const
Returns the list of all memory cells.
virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Write a value to memory.
STL namespace.
Main namespace for the ROSE library.
static MemoryCellListPtr instance(const MemoryCellPtr &protocell)
Instantiate a new memory state with prototypical memory cell.
Sawyer::Container::Set< rose_addr_t > AddressSet
A set of concrete virtual addresses.
Definition: MemoryCell.h:26
virtual MemoryCell::AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Writers for an address.
virtual MemoryStatePtr create(const MemoryCellPtr &protocell) const
Virtual allocating constructor.
boost::shared_ptr< class MemoryCellList > MemoryCellListPtr
Shared-ownership pointer to a list-based memory state.
virtual MemoryStatePtr clone() const ROSE_OVERRIDE
Virtual allocating copy constructor.
Base classes for instruction semantics.
Sawyer::Container::Set< rose_addr_t > AddressSet
Set of concrete virtual addresses.
static MemoryCellListPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
Instantiate a new prototypical memory state.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
Base class for most instruction semantics RISC operators.
virtual void traverse(MemoryCell::Visitor &) ROSE_OVERRIDE
Traverse and modify cells.
virtual void print(std::ostream &, Formatter &) const ROSE_OVERRIDE
Print a memory state to more than one line of output.
CellList scan(Iterator &cursor, const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) const
Scan cell list to find matching cells.
virtual MemoryCell::AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Writers for an address.
std::list< MemoryCellPtr > CellList
List of memory cells.
virtual CellList & get_cells()
Returns the list of all memory cells.
boost::shared_ptr< class MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
virtual std::vector< MemoryCellPtr > leadingCells(const MemoryCell::Predicate &) const ROSE_OVERRIDE
Find leading matching cells.
virtual void eraseMatchingCells(const MemoryCell::Predicate &) ROSE_OVERRIDE
Remove all matching cells.
virtual void eraseLeadingCells(const MemoryCell::Predicate &) ROSE_OVERRIDE
Remove leading matching cells.
static MemoryCellListPtr promote(const BaseSemantics::MemoryStatePtr &m)
Promote a base memory state pointer to a BaseSemantics::MemoryCellList pointer.
static MemoryCellListPtr instance(const MemoryCellListPtr &other)
Instantiate a new copy of an existing memory state.
Sawyer::Container::Set< InputOutputProperty > InputOutputPropertySet
Set of Boolean properties.
virtual std::vector< MemoryCellPtr > matchingCells(const MemoryCell::Predicate &) const ROSE_OVERRIDE
Find all matching cells.
virtual MemoryCellPtr latestWrittenCell() const
Property: Cell most recently written.
virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const ROSE_OVERRIDE
Virtual allocating constructor.
virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Merge memory states for data flow analysis.