ROSE  0.10.7.0
MemoryCellMap.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_MemoryCellMap_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_MemoryCellMap_H
3 #include <rosePublicConfig.h>
4 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
5 
6 #include <BaseSemantics2.h>
7 #include <boost/foreach.hpp>
8 #include <MemoryCellState.h>
9 #include <Sawyer/Map.h>
10 
11 #include <boost/serialization/access.hpp>
12 #include <boost/serialization/base_object.hpp>
13 #include <boost/serialization/export.hpp>
14 
15 namespace Rose {
16 namespace BinaryAnalysis {
17 namespace InstructionSemantics2 {
18 namespace BaseSemantics {
19 
21 typedef boost::shared_ptr<class MemoryCellMap> MemoryCellMapPtr;
22 
30 public:
36  typedef uint64_t CellKey;
37 
40 
41 protected:
42  CellMap cells;
43 
44 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
45 private:
46  friend class boost::serialization::access;
47 
48  template<class S>
49  void serialize(S &s, const unsigned /*version*/) {
50  s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
51  s & BOOST_SERIALIZATION_NVP(cells);
52  }
53 #endif
54 
55 protected:
56  MemoryCellMap() {} // for serialization
57 
58  explicit MemoryCellMap(const MemoryCellPtr &protocell)
59  : MemoryCellState(protocell) {}
60 
61  MemoryCellMap(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
62  : MemoryCellState(addrProtoval, valProtoval) {}
63 
64  MemoryCellMap(const MemoryCellMap &other)
65  : MemoryCellState(other) {
66  BOOST_FOREACH (const MemoryCellPtr &cell, other.cells.values())
67  cells.insert(other.generateCellKey(cell->get_address()), cell->clone());
68  }
69 
70 private:
71  MemoryCellMap& operator=(MemoryCellMap&) /*delete*/;
72 
73 public:
75  typedef MemoryCellMap Ptr;
76 
77 public:
80  static MemoryCellMapPtr promote(const MemoryStatePtr &x) {
81  MemoryCellMapPtr retval = boost::dynamic_pointer_cast<MemoryCellMap>(x);
82  ASSERT_not_null(retval);
83  return retval;
84  }
85 
86 public:
90  virtual CellKey generateCellKey(const SValuePtr &address) const = 0;
91 
97  virtual MemoryCellPtr findCell(const SValuePtr &addr) const;
98 
103  virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const;
104 
105 public:
106  virtual void clear() ROSE_OVERRIDE;
107  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
108  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
109  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
110  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
111  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
112  virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
113  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
114  virtual void print(std::ostream&, Formatter&) const ROSE_OVERRIDE;
115  virtual std::vector<MemoryCellPtr> matchingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
116  virtual std::vector<MemoryCellPtr> leadingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
117  virtual void eraseMatchingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
118  virtual void eraseLeadingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
119  virtual void traverse(MemoryCell::Visitor&) ROSE_OVERRIDE;
120  virtual MemoryCell::AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
121  RiscOperators *valOps) ROSE_OVERRIDE;
122  virtual MemoryCell::AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
123  RiscOperators *valOps) ROSE_OVERRIDE;
124 };
125 
126 } // namespace
127 } // namespace
128 } // namespace
129 } // namespace
130 
131 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
133 #endif
134 
135 #endif
136 #endif
virtual std::vector< MemoryCellPtr > leadingCells(const MemoryCell::Predicate &) const ROSE_OVERRIDE
Find leading matching cells.
boost::shared_ptr< class MemoryCell > MemoryCellPtr
Shared-ownership pointer to a semantic memory cell.
Definition: MemoryCell.h:17
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.
static MemoryCellMapPtr promote(const MemoryStatePtr &x)
Promote a base memory state pointer to a MemoryCellMap pointer.
Definition: MemoryCellMap.h:80
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.
virtual MemoryCell::AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Writers for an address.
Sawyer::Container::Map< CellKey, MemoryCellPtr > CellMap
Map of memory cells indexed by cell keys.
Definition: MemoryCellMap.h:39
Base class for most instruction semantics RISC operators.
MemoryCellMap Ptr
Shared-ownership pointer for a memory cell map object.
Definition: MemoryCellMap.h:75
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.
Definition: MemoryCellMap.h:21
virtual MemoryCell::AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Writers for an address.