ROSE  0.11.2.0
BaseSemanticsMemoryState.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_MemoryState_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_MemoryState_H
3 #include <rosePublicConfig.h>
4 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
5 
6 #include <BaseSemanticsTypes.h>
7 
8 #include <boost/enable_shared_from_this.hpp>
9 #include <boost/serialization/access.hpp>
10 #include <boost/serialization/shared_ptr.hpp>
11 
12 namespace Rose {
13 namespace BinaryAnalysis {
14 namespace InstructionSemantics2 {
15 namespace BaseSemantics {
16 
18 // Memory State
20 
24 class MemoryState: public boost::enable_shared_from_this<MemoryState> {
25  SValuePtr addrProtoval_;
26  SValuePtr valProtoval_;
27  ByteOrder::Endianness byteOrder_;
28  MergerPtr merger_;
29  bool byteRestricted_; // are cell values all exactly one byte wide?
30 
32  // Serialization
33 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
34 private:
35  friend class boost::serialization::access;
36 
37  template<class S>
38  void serialize(S &s, const unsigned /*version*/) {
39  s & BOOST_SERIALIZATION_NVP(addrProtoval_);
40  s & BOOST_SERIALIZATION_NVP(valProtoval_);
41  s & BOOST_SERIALIZATION_NVP(byteOrder_);
42  //s & merger_ -- not saved
43  s & BOOST_SERIALIZATION_NVP(byteRestricted_);
44  }
45 #endif
46 
47 
49  // Real constructors
50 protected:
51  MemoryState(); // for serialization
52  MemoryState(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
53  MemoryState(const MemoryStatePtr &other);
54 
55 public:
57  typedef MemoryStatePtr Ptr;
58 
59 public:
60  virtual ~MemoryState();
61 
63  // Static allocating constructors. None needed since this class is abstract
64 
66  // Virtual constructors
67 public:
74  virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const = 0;
75 
77  virtual MemoryStatePtr clone() const = 0;
78 
80  // Dynamic pointer casts. No-op since this is the base class.
81 public:
82  static MemoryStatePtr promote(const MemoryStatePtr &x) {
83  ASSERT_not_null(x);
84  return x;
85  }
86 
88  // Methods first declared at this level of the class hierarchy
89 public:
98  MergerPtr merger() const;
99  void merger(const MergerPtr&);
104  SValuePtr get_addr_protoval() const { return addrProtoval_; }
105 
108  SValuePtr get_val_protoval() const { return valProtoval_; }
109 
111  virtual void clear() = 0;
112 
120  bool byteRestricted() const { return byteRestricted_; }
121  void byteRestricted(bool b) { byteRestricted_ = b; }
126  ByteOrder::Endianness get_byteOrder() const { return byteOrder_; }
127  void set_byteOrder(ByteOrder::Endianness bo) { byteOrder_ = bo; }
133  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) = 0;
134 
154  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
155  RiscOperators *addrOps, RiscOperators *valOps) = 0;
156 
161  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
162  RiscOperators *addrOps, RiscOperators *valOps) = 0;
163 
173  virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value,
174  RiscOperators *addrOps, RiscOperators *valOps) = 0;
175 
178  void print(std::ostream&, const std::string prefix = "") const;
179  virtual void print(std::ostream&, Formatter&) const = 0;
183  class WithFormatter {
184  MemoryStatePtr obj;
185  Formatter &fmt;
186  public:
187  WithFormatter(const MemoryStatePtr &obj, Formatter &fmt): obj(obj), fmt(fmt) {}
188  void print(std::ostream &stream) const { obj->print(stream, fmt); }
189  };
190 
206  WithFormatter with_format(Formatter &fmt) { return WithFormatter(shared_from_this(), fmt); }
207  WithFormatter operator+(Formatter &fmt) { return with_format(fmt); }
208  WithFormatter operator+(const std::string &linePrefix);
210 };
211 
212 std::ostream& operator<<(std::ostream&, const MemoryState&);
213 std::ostream& operator<<(std::ostream&, const MemoryState::WithFormatter&);
214 
215 } // namespace
216 } // namespace
217 } // namespace
218 } // namespace
219 
220 #endif
221 #endif
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
void print(const StackVariables &, const Partitioner2::Partitioner &, std::ostream &out, const std::string &prefix="")
Print info about multiple local variables.
Main namespace for the ROSE library.
Sawyer::SharedPointer< Merger > MergerPtr
Shared-ownership pointer for Merger classes.
void clear(Word *words, const BitRange &where)
Clear some bits.
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
BaseSemantics::Formatter Formatter
Formatter for symbolic values.