ROSE  0.11.145.0
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 
6 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
7 
8 #include <boost/enable_shared_from_this.hpp>
9 #include <boost/serialization/access.hpp>
10 #include <boost/serialization/export.hpp>
11 #include <boost/serialization/shared_ptr.hpp>
12 
13 namespace Rose {
14 namespace BinaryAnalysis {
15 namespace InstructionSemantics {
16 namespace BaseSemantics {
17 
19 // Memory State
21 
25 class MemoryState: public boost::enable_shared_from_this<MemoryState> {
26 public:
29 
30 private:
31  SValuePtr addrProtoval_;
32  SValuePtr valProtoval_;
33  ByteOrder::Endianness byteOrder_;
34  MergerPtr merger_;
35  bool byteRestricted_; // are cell values all exactly one byte wide?
36 
38  // Serialization
39 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
40 private:
41  friend class boost::serialization::access;
42 
43  template<class S>
44  void serialize(S &s, const unsigned /*version*/) {
45  s & BOOST_SERIALIZATION_NVP(addrProtoval_);
46  s & BOOST_SERIALIZATION_NVP(valProtoval_);
47  s & BOOST_SERIALIZATION_NVP(byteOrder_);
48  //s & merger_ -- not saved
49  s & BOOST_SERIALIZATION_NVP(byteRestricted_);
50  }
51 #endif
52 
53 
55  // Real constructors
56 protected:
57  MemoryState(); // for serialization
58  MemoryState(const SValuePtr &addrProtoval, const SValuePtr &valProtoval);
59  MemoryState(const MemoryStatePtr &other);
60 
61 public:
62  virtual ~MemoryState();
63 
65  // Static allocating constructors. None needed since this class is abstract
66 
68  // Virtual constructors
69 public:
76  virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const = 0;
77 
79  virtual MemoryStatePtr clone() const = 0;
80 
82  // Dynamic pointer casts. No-op since this is the base class.
83 public:
84  static MemoryStatePtr promote(const MemoryStatePtr&);
85 
87  // Methods first declared at this level of the class hierarchy
88 public:
97  MergerPtr merger() const;
98  void merger(const MergerPtr&);
104 
107  SValuePtr get_val_protoval() const;
108 
110  virtual void clear() = 0;
111 
119  bool byteRestricted() const;
120  void byteRestricted(bool);
125  ByteOrder::Endianness get_byteOrder() const;
126  void set_byteOrder(ByteOrder::Endianness);
132  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) = 0;
133 
153  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
154  RiscOperators *addrOps, RiscOperators *valOps) = 0;
155 
160  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
161  RiscOperators *addrOps, RiscOperators *valOps) = 0;
162 
172  virtual void writeMemory(const SValuePtr &addr, const SValuePtr &value,
173  RiscOperators *addrOps, RiscOperators *valOps) = 0;
174 
175 
180  virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const = 0;
181 
184  void print(std::ostream&, const std::string prefix = "") const;
185  virtual void print(std::ostream&, Formatter&) const = 0;
190  MemoryStatePtr obj;
191  Formatter &fmt;
192  public:
193  ~WithFormatter();
194  WithFormatter() = delete;
196  void print(std::ostream&) const;
197  };
198 
216  WithFormatter operator+(const std::string &linePrefix);
218 };
219 
220 std::ostream& operator<<(std::ostream&, const MemoryState&);
221 std::ostream& operator<<(std::ostream&, const MemoryState::WithFormatter&);
222 
223 } // namespace
224 } // namespace
225 } // namespace
226 } // namespace
227 
229 
230 #endif
231 #endif
virtual MemoryStatePtr clone() const =0
Virtual allocating copy constructor.
virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const =0
Virtual allocating constructor.
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
Read a value from memory.
bool byteRestricted() const
Indicates whether memory cell values are required to be eight bits wide.
SValuePtr get_val_protoval() const
Return the value protoval.
virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps)=0
Merge memory states for data flow analysis.
Main namespace for the ROSE library.
ByteOrder::Endianness get_byteOrder() const
Memory byte order.
WithFormatter with_format(Formatter &)
Used for printing memory states with formatting.
void set_byteOrder(ByteOrder::Endianness)
Memory byte order.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
Read a value from memory without side effects.
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 void writeMemory(const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps)=0
Write a value to memory.
SValuePtr get_addr_protoval() const
Return the address protoval.
Base class for most instruction semantics RISC operators.
Definition: RiscOperators.h:49
void print(std::ostream &, const std::string prefix="") const
Print a memory state to more than one line of output.