ROSE  0.9.12.28
BaseSemanticsMemoryState.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_MemoryState_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_MemoryState_H
3 
4 #include <BaseSemanticsTypes.h>
5 
6 #include <boost/enable_shared_from_this.hpp>
7 #include <boost/serialization/access.hpp>
8 #include <boost/serialization/shared_ptr.hpp>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 namespace InstructionSemantics2 {
13 namespace BaseSemantics {
14 
16 // Memory State
18 
22 class MemoryState: public boost::enable_shared_from_this<MemoryState> {
23  SValuePtr addrProtoval_;
24  SValuePtr valProtoval_;
25  ByteOrder::Endianness byteOrder_;
26  MergerPtr merger_;
27  bool byteRestricted_; // are cell values all exactly one byte wide?
28 
30  // Serialization
31 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
32 private:
33  friend class boost::serialization::access;
34 
35  template<class S>
36  void serialize(S &s, const unsigned /*version*/) {
37  s & BOOST_SERIALIZATION_NVP(addrProtoval_);
38  s & BOOST_SERIALIZATION_NVP(valProtoval_);
39  s & BOOST_SERIALIZATION_NVP(byteOrder_);
40  //s & merger_ -- not saved
41  s & BOOST_SERIALIZATION_NVP(byteRestricted_);
42  }
43 #endif
44 
45 
47  // Real constructors
48 protected:
49  MemoryState(); // for serialization
50  MemoryState(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
51  MemoryState(const MemoryStatePtr &other);
52 
53 public:
56 
57 public:
58  virtual ~MemoryState();
59 
61  // Static allocating constructors. None needed since this class is abstract
62 
64  // Virtual constructors
65 public:
72  virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const = 0;
73 
75  virtual MemoryStatePtr clone() const = 0;
76 
78  // Dynamic pointer casts. No-op since this is the base class.
79 public:
80  static MemoryStatePtr promote(const MemoryStatePtr &x) {
81  ASSERT_not_null(x);
82  return x;
83  }
84 
86  // Methods first declared at this level of the class hierarchy
87 public:
96  MergerPtr merger() const;
97  void merger(const MergerPtr&);
102  SValuePtr get_addr_protoval() const { return addrProtoval_; }
103 
106  SValuePtr get_val_protoval() const { return valProtoval_; }
107 
109  virtual void clear() = 0;
110 
118  bool byteRestricted() const { return byteRestricted_; }
119  void byteRestricted(bool b) { byteRestricted_ = b; }
124  ByteOrder::Endianness get_byteOrder() const { return byteOrder_; }
125  void set_byteOrder(ByteOrder::Endianness bo) { byteOrder_ = bo; }
131  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) = 0;
132 
152  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
153  RiscOperators *addrOps, RiscOperators *valOps) = 0;
154 
159  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
160  RiscOperators *addrOps, RiscOperators *valOps) = 0;
161 
171  virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value,
172  RiscOperators *addrOps, RiscOperators *valOps) = 0;
173 
176  void print(std::ostream&, const std::string prefix = "") const;
177  virtual void print(std::ostream&, Formatter&) const = 0;
182  MemoryStatePtr obj;
183  Formatter &fmt;
184  public:
185  WithFormatter(const MemoryStatePtr &obj, Formatter &fmt): obj(obj), fmt(fmt) {}
186  void print(std::ostream &stream) const { obj->print(stream, fmt); }
187  };
188 
196  WithFormatter with_format(Formatter &fmt) { return WithFormatter(shared_from_this(), fmt); }
199 };
200 
201 std::ostream& operator<<(std::ostream&, const MemoryState&);
202 std::ostream& operator<<(std::ostream&, const MemoryState::WithFormatter&);
203 
204 } // namespace
205 } // namespace
206 } // namespace
207 } // namespace
208 
209 #endif
WithFormatter operator+(Formatter &fmt)
Used for printing memory states with formatting.
void print(std::ostream &, const std::string prefix="") const
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.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
MemoryStatePtr Ptr
Shared-ownership pointer for a MemoryState.
virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const =0
Virtual allocating constructor.
Main namespace for the ROSE library.
void byteRestricted(bool b)
Indicates whether memory cell values are required to be eight bits wide.
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
Read a value from memory.
virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps)=0
Merge memory states for data flow analysis.
Base class for most instruction semantics RISC operators.
WithFormatter with_format(Formatter &fmt)
Used for printing memory states with formatting.
virtual MemoryStatePtr clone() const =0
Virtual allocating copy constructor.
bool byteRestricted() const
Indicates whether memory cell values are required to be eight bits wide.
virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps)=0
Write a value to memory.