ROSE 0.11.145.192
MemoryCellMap.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryCellMap_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryCellMap_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5
6#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellState.h>
7
8#include <Sawyer/Map.h>
9
10#include <boost/serialization/access.hpp>
11#include <boost/serialization/base_object.hpp>
12#include <boost/serialization/export.hpp>
13
14namespace Rose {
15namespace BinaryAnalysis {
16namespace InstructionSemantics {
17namespace BaseSemantics {
18
20typedef boost::shared_ptr<class MemoryCellMap> MemoryCellMapPtr;
21
29public:
32
35
41 typedef uint64_t CellKey;
42
45
46private:
47 uint32_t lastPosition_ = 0; // used when inserting new cells
48
49protected:
50 CellMap cells;
51
52#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
53private:
54 friend class boost::serialization::access;
55
56 template<class S>
57 void serialize(S &s, const unsigned /*version*/) {
58 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
59 s & BOOST_SERIALIZATION_NVP(cells);
60 }
61#endif
62
63public:
65
66protected:
67 MemoryCellMap(); // for serialization
68
69 explicit MemoryCellMap(const MemoryCellPtr &protocell);
70
71 MemoryCellMap(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
72
74
75private:
76 MemoryCellMap& operator=(MemoryCellMap&) /*delete*/;
77
78public:
82
83public:
87 virtual CellKey generateCellKey(const SValuePtr &address) const = 0;
88
94 virtual MemoryCellPtr findCell(const SValuePtr &addr) const;
95
100 virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const;
101
102public:
103 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
104 virtual void clear() override;
105 virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
106 virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
107 RiscOperators *addrOps, RiscOperators *valOps) override;
108 virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
109 RiscOperators *addrOps, RiscOperators *valOps) override;
110 virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
111 RiscOperators *addrOps, RiscOperators *valOps) override;
112 virtual void print(std::ostream&, Formatter&) const override;
113 virtual std::vector<MemoryCellPtr> matchingCells(MemoryCell::Predicate&) const override;
114 virtual std::vector<MemoryCellPtr> leadingCells(MemoryCell::Predicate&) const override;
117 virtual void traverse(MemoryCell::Visitor&) override;
118 virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
119 RiscOperators *valOps) override;
120 virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
121 RiscOperators *valOps) override;
122
123private:
124 // Increment lastPosition_ and return its new value.
125 unsigned nextPosition();
126
127 // Last position returned by nextPosition
128 unsigned lastPosition() const;
129 void lastPosition(unsigned);
130};
131
132} // namespace
133} // namespace
134} // namespace
135} // namespace
136
137#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
139#endif
140
141#endif
142#endif
virtual void eraseLeadingCells(MemoryCell::Predicate &) override
Remove leading matching cells.
virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override
Merge address spaces for data flow analysis.
virtual void print(std::ostream &, Formatter &) const override
Print an address space.
static MemoryCellMapPtr promote(const AddressSpacePtr &)
Promote a base address space pointer to a MemoryCellMap pointer.
virtual void writeMemory(const SValuePtr &address, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) override
Write a value to memory.
virtual std::vector< MemoryCellPtr > leadingCells(MemoryCell::Predicate &) const override
Find leading matching cells.
virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const
Predicate to determine whether all bytes are present.
virtual CellKey generateCellKey(const SValuePtr &address) const =0
Generate a cell lookup key.
virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) override
Writers for an address.
virtual void traverse(MemoryCell::Visitor &) override
Traverse and modify cells.
virtual void hash(Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const override
Hash this address space.
virtual void eraseMatchingCells(MemoryCell::Predicate &) override
Remove all matching cells.
virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) override
Writers for an address.
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory.
Sawyer::Container::Map< CellKey, MemoryCellPtr > CellMap
Map of memory cells indexed by cell keys.
virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory without side effects.
virtual MemoryCellPtr findCell(const SValuePtr &addr) const
Look up memory cell for address.
virtual std::vector< MemoryCellPtr > matchingCells(MemoryCell::Predicate &) const override
Find all matching cells.
Base class for most instruction semantics RISC operators.
Container associating values with keys.
Definition Sawyer/Map.h:72
Base classes for instruction semantics.
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
boost::shared_ptr< class MemoryCellMap > MemoryCellMapPtr
Shared-ownership pointer to a map-based memory state.
boost::shared_ptr< AddressSpace > AddressSpacePtr
Shared-ownership pointer for AddressSpace objects.
The ROSE library.