ROSE  0.9.9.109
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 
97 public:
98  virtual void clear() ROSE_OVERRIDE;
99  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
100  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
101  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
102  virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
103  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
104  virtual void print(std::ostream&, Formatter&) const ROSE_OVERRIDE;
105  virtual std::vector<MemoryCellPtr> matchingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
106  virtual std::vector<MemoryCellPtr> leadingCells(const MemoryCell::Predicate&) const ROSE_OVERRIDE;
107  virtual void eraseMatchingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
108  virtual void eraseLeadingCells(const MemoryCell::Predicate&) ROSE_OVERRIDE;
109  virtual void traverse(MemoryCell::Visitor&) ROSE_OVERRIDE;
110  virtual MemoryCell::AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
111  RiscOperators *valOps) ROSE_OVERRIDE;
112  virtual MemoryCell::AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
113  RiscOperators *valOps) ROSE_OVERRIDE;
114 };
115 
116 } // namespace
117 } // namespace
118 } // namespace
119 } // namespace
120 
121 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
123 #endif
124 
125 #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 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:530
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: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.