ROSE  0.11.31.0
SymbolicMemory2.h
1 // Symbolic memory -- a memory state where memory is represented by an SMT function whose domain is the address space and whose
2 // range are the bytes stored at those addresses.
3 #ifndef Rose_SymbolicMemory_H
4 #define Rose_SymbolicMemory_H
5 #include <featureTests.h>
6 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
7 
8 #include <BaseSemantics2.h>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 namespace InstructionSemantics2 {
13 namespace BaseSemantics {
14 
16 typedef boost::shared_ptr<class SymbolicMemory> SymbolicMemoryPtr;
17 
23 class SymbolicMemory: public MemoryState {
24  SymbolicExpr::Ptr mem_;
25 protected:
26  // All memory states should be heap allocated; use instance(), create(), or clone() instead.
27  explicit SymbolicMemory(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
28  : MemoryState(addrProtoval, valProtoval) {
29  // Initially assume that addresses are 32 bits wide and values are 8 bits wide. We can change this on the first access.
31  }
32 
33 public:
35  static SymbolicMemoryPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) {
36  return SymbolicMemoryPtr(new SymbolicMemory(addrProtoval, valProtoval));
37  }
38 
39 public:
40  // documented in base class
41  virtual MemoryStatePtr create(const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const ROSE_OVERRIDE {
42  return instance(addrProtoval, valProtoval);
43  }
44 
45  // documented in base class
46  virtual MemoryStatePtr clone() const ROSE_OVERRIDE {
47  return SymbolicMemoryPtr(new SymbolicMemory(*this));
48  }
49 
53  static SymbolicMemoryPtr promote(const MemoryStatePtr &x) {
54  SymbolicMemoryPtr retval = boost::dynamic_pointer_cast<SymbolicMemory>(x);
55  ASSERT_not_null(retval);
56  return retval;
57  }
58 
59 public:
63  SymbolicExpr::Ptr expression() const { return mem_; }
64  void expression(const SymbolicExpr::Ptr &mem);
67 public:
68  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
69 
70  virtual void clear() ROSE_OVERRIDE;
71 
72  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
73  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
74 
75  virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
76  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
77 
78  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
79  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
80 
81 public:
82  virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
83 
84  virtual void print(std::ostream&, Formatter&) const ROSE_OVERRIDE;
85 };
86 
87 } // namespace
88 } // namespace
89 } // namespace
90 } // namespace
91 
92 #endif
93 #endif
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
static SymbolicMemoryPtr instance(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
Instantiate a new empty memory state on the heap.
STL namespace.
Main namespace for the ROSE library.
static SymbolicMemoryPtr promote(const MemoryStatePtr &x)
Convert pointer to a SymbolicMemory pointer.
SymbolicExpr::Ptr expression() const
Property: the symbolic expression for the memory.
boost::shared_ptr< class SymbolicMemory > SymbolicMemoryPtr
Shared-ownership pointer for symbolic memory state.
Base class for most instruction semantics RISC operators.
LeafPtr makeMemoryVariable(size_t addressWidth, size_t valueWidth, const std::string &comment="", unsigned flags=0)
Leaf constructor.