ROSE  0.11.2.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 <rosePublicConfig.h>
6 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
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
70  BaseSemantics::RiscOperators *valOps) ROSE_OVERRIDE;
71 
72  virtual void clear() ROSE_OVERRIDE;
73 
74  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
75  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
76 
77  virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
78  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
79 
80  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
81  RiscOperators *addrOps, RiscOperators *valOps) ROSE_OVERRIDE;
82 
83 public:
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.