ROSE 0.11.145.147
MemoryState.h
1#ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryState_H
2#define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryState_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/ByteOrder.h>
8#include <Combinatorics.h> // rose
9
10#include <boost/enable_shared_from_this.hpp>
11#include <boost/serialization/access.hpp>
12#include <boost/serialization/export.hpp>
13#include <boost/serialization/shared_ptr.hpp>
14
15namespace Rose {
16namespace BinaryAnalysis {
17namespace InstructionSemantics {
18namespace BaseSemantics {
19
21// Memory State
23
27class MemoryState: public boost::enable_shared_from_this<MemoryState> {
28public:
31
32private:
33 SValuePtr addrProtoval_;
34 SValuePtr valProtoval_;
35 ByteOrder::Endianness byteOrder_;
36 MergerPtr merger_;
37 bool byteRestricted_; // are cell values all exactly one byte wide?
38
40 // Serialization
41#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
42private:
43 friend class boost::serialization::access;
44
45 template<class S>
46 void serialize(S &s, const unsigned /*version*/) {
47 s & BOOST_SERIALIZATION_NVP(addrProtoval_);
48 s & BOOST_SERIALIZATION_NVP(valProtoval_);
49 s & BOOST_SERIALIZATION_NVP(byteOrder_);
50 //s & merger_ -- not saved
51 s & BOOST_SERIALIZATION_NVP(byteRestricted_);
52 }
53#endif
54
55
57 // Real constructors
58protected:
59 MemoryState(); // for serialization
60 MemoryState(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
61 MemoryState(const MemoryStatePtr &other);
62
63public:
64 virtual ~MemoryState();
65
67 // Static allocating constructors. None needed since this class is abstract
68
70 // Virtual constructors
71public:
78 virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const = 0;
79
81 virtual MemoryStatePtr clone() const = 0;
82
84 // Dynamic pointer casts. No-op since this is the base class.
85public:
86 static MemoryStatePtr promote(const MemoryStatePtr&);
87
89 // Methods first declared at this level of the class hierarchy
90public:
100 void merger(const MergerPtr&);
106
110
112 virtual void clear() = 0;
113
121 bool byteRestricted() const;
122 void byteRestricted(bool);
134 virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) = 0;
135
155 virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
156 RiscOperators *addrOps, RiscOperators *valOps) = 0;
157
162 virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
163 RiscOperators *addrOps, RiscOperators *valOps) = 0;
164
174 virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value,
175 RiscOperators *addrOps, RiscOperators *valOps) = 0;
176
177
182 virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const = 0;
183
186 void print(std::ostream&, const std::string prefix = "") const;
187 virtual void print(std::ostream&, Formatter&) const = 0;
192 MemoryStatePtr obj;
193 Formatter &fmt;
194 public:
196 WithFormatter() = delete;
198 void print(std::ostream&) const;
199 };
200
218 WithFormatter operator+(const std::string &linePrefix);
220};
221
222std::ostream& operator<<(std::ostream&, const MemoryState&);
223std::ostream& operator<<(std::ostream&, const MemoryState::WithFormatter&);
224
225} // namespace
226} // namespace
227} // namespace
228} // namespace
229
231
232#endif
233#endif
void set_byteOrder(ByteOrder::Endianness)
Memory byte order.
WithFormatter with_format(Formatter &)
Used for printing memory states with formatting.
WithFormatter operator+(const std::string &linePrefix)
Used for printing memory states with formatting.
virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps)=0
Merge memory states for data flow analysis.
virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const =0
Virtual allocating constructor.
virtual void print(std::ostream &, Formatter &) const =0
Print a memory state to more than one line of output.
virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
Read a value from memory without side effects.
void print(std::ostream &, const std::string prefix="") const
Print a memory state to more than one line of output.
SValuePtr get_val_protoval() const
Return the value protoval.
virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps)=0
Write a value to memory.
ByteOrder::Endianness get_byteOrder() const
Memory byte order.
virtual MemoryStatePtr clone() const =0
Virtual allocating copy constructor.
SValuePtr get_addr_protoval() const
Return the address protoval.
bool byteRestricted() const
Indicates whether memory cell values are required to be eight bits wide.
virtual void hash(Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const =0
Calculate a hash for this memory state.
WithFormatter operator+(Formatter &)
Used for printing memory states with formatting.
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
Read a value from memory.
void byteRestricted(bool)
Indicates whether memory cell values are required to be eight bits wide.
Base class for most instruction semantics RISC operators.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
The ROSE library.