ROSE  0.9.10.91
MemoryCellMap.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_MemoryCellMap_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_MemoryCellMap_H
3 
4 #include <BaseSemantics2.h>
5 #include <boost/foreach.hpp>
6 #include <MemoryCellState.h>
7 #include <Sawyer/Map.h>
8 
9 #include <boost/serialization/access.hpp>
10 #include <boost/serialization/base_object.hpp>
11 #include <boost/serialization/export.hpp>
12 
13 namespace Rose {
14 namespace BinaryAnalysis {
15 namespace InstructionSemantics2 {
16 namespace BaseSemantics {
17 
19 typedef boost::shared_ptr<class MemoryCellMap> MemoryCellMapPtr;
20 
28 public:
34  typedef uint64_t CellKey;
35 
38 
39 protected:
40  CellMap cells;
41 
42 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
43 private:
44  friend class boost::serialization::access;
45 
46  template<class S>
47  void serialize(S &s, const unsigned /*version*/) {
48  s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
49  s & BOOST_SERIALIZATION_NVP(cells);
50  }
51 #endif
52 
53 protected:
54  MemoryCellMap() {} // for serialization
55 
56  explicit MemoryCellMap(const MemoryCellPtr &protocell)
57  : MemoryCellState(protocell) {}
58 
59  MemoryCellMap(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
60  : MemoryCellState(addrProtoval, valProtoval) {}
61 
62  MemoryCellMap(const MemoryCellMap &other)
63  : MemoryCellState(other) {
64  BOOST_FOREACH (const MemoryCellPtr &cell, other.cells.values())
65  cells.insert(other.generateCellKey(cell->get_address()), cell->clone());
66  }
67 
68 private:
69  MemoryCellMap& operator=(MemoryCellMap&) /*delete*/;
70 
71 public:
73  typedef MemoryCellMap Ptr;
74 
75 public:
78  static MemoryCellMapPtr promote(const MemoryStatePtr &x) {
79  MemoryCellMapPtr retval = boost::dynamic_pointer_cast<MemoryCellMap>(x);
80  ASSERT_not_null(retval);
81  return retval;
82  }
83 
84 public:
88  virtual CellKey generateCellKey(const SValuePtr &address) const = 0;
89 
95  virtual MemoryCellPtr findCell(const SValuePtr &addr) const;
96 
101  virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const;
102 
103 public:
104  virtual void clear() ROSE_OVERRIDE;
105  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
106  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
107  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
108  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
109  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
110  virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
111  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
112  virtual void print(std::ostream&, Formatter&) const ROSE_OVERRIDE;
113  virtual std::vector<MemoryCellPtr> matchingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
114  virtual std::vector<MemoryCellPtr> leadingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
115  virtual void eraseMatchingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
116  virtual void eraseLeadingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
117  virtual void traverse(MemoryCell::Visitor&) ROSE_OVERRIDE;
118  virtual MemoryCell::AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
119  RiscOperators *valOps) ROSE_OVERRIDE;
120  virtual MemoryCell::AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
121  RiscOperators *valOps) ROSE_OVERRIDE;
122 };
123 
124 } // namespace
125 } // namespace
126 } // namespace
127 } // namespace
128 
129 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
131 #endif
132 
133 #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:15
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.
virtual void writeMemory(const SValuePtr &address, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Write a value to memory.
virtual void print(std::ostream &, Formatter &) const ROSE_OVERRIDE
Print a memory state to more than one line of output.
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:78
virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Merge memory states for data flow analysis.
virtual void eraseLeadingCells(const MemoryCell::Predicate &) ROSE_OVERRIDE
Remove leading matching cells.
Base classes for instruction semantics.
virtual std::vector< MemoryCellPtr > matchingCells(const MemoryCell::Predicate &) const ROSE_OVERRIDE
Find all matching cells.
Sawyer::SharedPointer< class SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
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:37
Base class for most instruction semantics RISC operators.
MemoryCellMap Ptr
Shared-ownership pointer for a memory cell map object.
Definition: MemoryCellMap.h:73
boost::shared_ptr< class MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
Map & insert(const Key &key, const Value &value)
Insert or update a key/value pair.
Definition: Sawyer/Map.h:532
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.
virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Read a value from memory without side effects.
boost::shared_ptr< class MemoryCellMap > MemoryCellMapPtr
Shared-ownership pointer to a map-based memory state.
Definition: MemoryCellMap.h:19
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Read a value from memory.
virtual MemoryCell::AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE
Writers for an address.