ROSE  0.11.50.0
BaseSemantics/MemoryCellMap.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_MemoryCellMap_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_MemoryCellMap_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/InstructionSemantics2/BaseSemantics/Types.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics2/BaseSemantics/MemoryCellState.h>
8 
9 #include <Sawyer/Map.h>
10 
11 #include <boost/foreach.hpp>
12 #include <boost/serialization/access.hpp>
13 #include <boost/serialization/base_object.hpp>
14 #include <boost/serialization/export.hpp>
15 
16 namespace Rose {
17 namespace BinaryAnalysis {
18 namespace InstructionSemantics2 {
19 namespace BaseSemantics {
20 
22 typedef boost::shared_ptr<class MemoryCellMap> MemoryCellMapPtr;
23 
31 public:
34 
37 
43  typedef uint64_t CellKey;
44 
47 
48 protected:
49  CellMap cells;
50 
51 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
52 private:
53  friend class boost::serialization::access;
54 
55  template<class S>
56  void serialize(S &s, const unsigned /*version*/) {
57  s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
58  s & BOOST_SERIALIZATION_NVP(cells);
59  }
60 #endif
61 
62 protected:
63  MemoryCellMap() {} // for serialization
64 
65  explicit MemoryCellMap(const MemoryCellPtr &protocell)
66  : MemoryCellState(protocell) {}
67 
68  MemoryCellMap(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
69  : MemoryCellState(addrProtoval, valProtoval) {}
70 
71  MemoryCellMap(const MemoryCellMap &other)
72  : MemoryCellState(other) {
73  BOOST_FOREACH (const MemoryCellPtr &cell, other.cells.values())
74  cells.insert(other.generateCellKey(cell->address()), cell->clone());
75  }
76 
77 private:
78  MemoryCellMap& operator=(MemoryCellMap&) /*delete*/;
79 
80 public:
83  static MemoryCellMapPtr promote(const MemoryStatePtr &x) {
84  MemoryCellMapPtr retval = boost::dynamic_pointer_cast<MemoryCellMap>(x);
85  ASSERT_not_null(retval);
86  return retval;
87  }
88 
89 public:
93  virtual CellKey generateCellKey(const SValuePtr &address) const = 0;
94 
100  virtual MemoryCellPtr findCell(const SValuePtr &addr) const;
101 
106  virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const;
107 
108 public:
109  virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
110  virtual void clear() ROSE_OVERRIDE;
111  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
112  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
113  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
114  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
115  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
116  virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
117  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
118  virtual void print(std::ostream&, Formatter&) const ROSE_OVERRIDE;
119  virtual std::vector<MemoryCellPtr> matchingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
120  virtual std::vector<MemoryCellPtr> leadingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
121  virtual void eraseMatchingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
122  virtual void eraseLeadingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
123  virtual void traverse(MemoryCell::Visitor&) ROSE_OVERRIDE;
124  virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
125  RiscOperators *valOps) ROSE_OVERRIDE;
126  virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
127  RiscOperators *valOps) ROSE_OVERRIDE;
128 };
129 
130 } // namespace
131 } // namespace
132 } // namespace
133 } // namespace
134 
135 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
137 #endif
138 
139 #endif
140 #endif
virtual std::vector< MemoryCellPtr > leadingCells(const MemoryCell::Predicate &) const ROSE_OVERRIDE
Find leading matching cells.
virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Writers for an address.
virtual void traverse(MemoryCell::Visitor &) ROSE_OVERRIDE
Traverse and modify cells.
virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const
Predicate to determine whether all bytes are present.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
virtual CellKey generateCellKey(const SValuePtr &address) const =0
Generate a cell lookup key.
STL namespace.
Main namespace for the ROSE library.
virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Writers for an address.
static MemoryCellMapPtr promote(const MemoryStatePtr &x)
Promote a base memory state pointer to a MemoryCellMap pointer.
virtual void eraseLeadingCells(const MemoryCell::Predicate &) ROSE_OVERRIDE
Remove leading matching cells.
virtual std::vector< MemoryCellPtr > matchingCells(const MemoryCell::Predicate &) const ROSE_OVERRIDE
Find all matching cells.
Sawyer::Container::Map< CellKey, MemoryCellPtr > CellMap
Map of memory cells indexed by cell keys.
Base class for most instruction semantics RISC operators.
Definition: RiscOperators.h:48
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
Map & insert(const Key &key, const Value &value)
Insert or update a key/value pair.
Definition: Sawyer/Map.h:594
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
virtual void eraseMatchingCells(const MemoryCell::Predicate &) ROSE_OVERRIDE
Remove all matching cells.
virtual MemoryCellPtr findCell(const SValuePtr &addr) const
Look up memory cell for address.
boost::shared_ptr< class MemoryCellMap > MemoryCellMapPtr
Shared-ownership pointer to a map-based memory state.