ROSE 0.11.145.147
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/BasicTypes.h>
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellState.h>
8
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
15namespace Rose {
16namespace BinaryAnalysis {
17namespace InstructionSemantics {
18namespace BaseSemantics {
19
21typedef boost::shared_ptr<class MemoryCellMap> MemoryCellMapPtr;
22
30public:
33
36
42 typedef uint64_t CellKey;
43
46
47private:
48 uint32_t lastPosition_ = 0; // used when inserting new cells
49
50protected:
51 CellMap cells;
52
53#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
54private:
55 friend class boost::serialization::access;
56
57 template<class S>
58 void serialize(S &s, const unsigned /*version*/) {
59 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
60 s & BOOST_SERIALIZATION_NVP(cells);
61 }
62#endif
63
64protected:
65 MemoryCellMap() {} // for serialization
66
67 explicit MemoryCellMap(const MemoryCellPtr &protocell)
68 : MemoryCellState(protocell) {}
69
70 MemoryCellMap(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
71 : MemoryCellState(addrProtoval, valProtoval) {}
72
73 MemoryCellMap(const MemoryCellMap&);
74
75private:
76 MemoryCellMap& operator=(MemoryCellMap&) /*delete*/;
77
78public:
82 MemoryCellMapPtr retval = boost::dynamic_pointer_cast<MemoryCellMap>(x);
83 ASSERT_not_null(retval);
84 return retval;
85 }
86
87public:
91 virtual CellKey generateCellKey(const SValuePtr &address) const = 0;
92
98 virtual MemoryCellPtr findCell(const SValuePtr &addr) const;
99
104 virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const;
105
106public:
107 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
108 virtual void clear() override;
109 virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
110 virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
111 RiscOperators *addrOps, RiscOperators *valOps) override;
112 virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
113 RiscOperators *addrOps, RiscOperators *valOps) override;
114 virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
115 RiscOperators *addrOps, RiscOperators *valOps) override;
116 virtual void print(std::ostream&, Formatter&) const override;
117 virtual std::vector<MemoryCellPtr> matchingCells(MemoryCell::Predicate&) const override;
118 virtual std::vector<MemoryCellPtr> leadingCells(MemoryCell::Predicate&) const override;
121 virtual void traverse(MemoryCell::Visitor&) override;
122 virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
123 RiscOperators *valOps) override;
124 virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
125 RiscOperators *valOps) override;
126
127private:
128 // Increment lastPosition_ and return its new value.
129 unsigned nextPosition();
130
131 // Last position returned by nextPosition
132 unsigned lastPosition() const;
133 void lastPosition(unsigned);
134};
135
136} // namespace
137} // namespace
138} // namespace
139} // namespace
140
141#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
143#endif
144
145#endif
146#endif
virtual void eraseLeadingCells(MemoryCell::Predicate &) override
Remove leading matching cells.
virtual void print(std::ostream &, Formatter &) const override
Print a memory state to more than one line of output.
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
Calculate a hash for this memory state.
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.
virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override
Merge memory states for data flow analysis.
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.
static MemoryCellMapPtr promote(const MemoryStatePtr &x)
Promote a base memory state pointer to a MemoryCellMap pointer.
Base class for most instruction semantics RISC operators.
Container associating values with keys.
Definition Sawyer/Map.h:72
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
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.
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
The ROSE library.