ROSE 0.11.145.237
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#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
11#include <boost/serialization/access.hpp>
12#include <boost/serialization/base_object.hpp>
13#include <boost/serialization/export.hpp>
14#endif
15
16namespace Rose {
17namespace BinaryAnalysis {
18namespace InstructionSemantics {
19namespace BaseSemantics {
20
22typedef boost::shared_ptr<class MemoryCellMap> MemoryCellMapPtr;
23
31public:
34
37
43 typedef uint64_t CellKey;
44
47
48private:
49 uint32_t lastPosition_ = 0; // used when inserting new cells
50
51protected:
52 CellMap cells;
53
54#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
55private:
56 friend class boost::serialization::access;
57
58 template<class S>
59 void serialize(S &s, const unsigned /*version*/) {
60 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
61 s & BOOST_SERIALIZATION_NVP(cells);
62 }
63#endif
64
65public:
67
68protected:
69 MemoryCellMap(); // for serialization
70
71 explicit MemoryCellMap(const MemoryCellPtr &protocell);
72
73 MemoryCellMap(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
74
76
77private:
78 MemoryCellMap& operator=(MemoryCellMap&) /*delete*/;
79
80public:
84
85public:
89 virtual CellKey generateCellKey(const SValuePtr &address) const = 0;
90
96 virtual MemoryCellPtr findCell(const SValuePtr &addr) const;
97
102 virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const;
103
104public:
105 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
106 virtual void clear() override;
107 virtual bool merge(const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
108 virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
109 RiscOperators *addrOps, RiscOperators *valOps) override;
110 virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
111 RiscOperators *addrOps, RiscOperators *valOps) override;
112 virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
113 RiscOperators *addrOps, RiscOperators *valOps) override;
114 virtual void print(std::ostream&, Formatter&) const override;
115 virtual std::vector<MemoryCellPtr> matchingCells(MemoryCell::Predicate&) const override;
116 virtual std::vector<MemoryCellPtr> leadingCells(MemoryCell::Predicate&) const override;
119 virtual void traverse(MemoryCell::Visitor&) override;
120 virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
121 RiscOperators *valOps) override;
122 virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
123 RiscOperators *valOps) override;
124
125private:
126 // Increment lastPosition_ and return its new value.
127 unsigned nextPosition();
128
129 // Last position returned by nextPosition
130 unsigned lastPosition() const;
131 void lastPosition(unsigned);
132};
133
134} // namespace
135} // namespace
136} // namespace
137} // namespace
138
139#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
141#endif
142
143#endif
144#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.