ROSE  0.11.50.0
RegisterState.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_RegisterState_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_RegisterState_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/InstructionSemantics2/BaseSemantics/Merger.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics2/BaseSemantics/SValue.h>
8 #include <Rose/BinaryAnalysis/Registers.h>
9 
10 #include <boost/enable_shared_from_this.hpp>
11 #include <boost/serialization/access.hpp>
12 #include <boost/serialization/export.hpp>
13 #include <boost/serialization/nvp.hpp>
14 #include <boost/serialization/shared_ptr.hpp>
15 #include <boost/serialization/version.hpp>
16 
17 namespace Rose {
18 namespace BinaryAnalysis {
19 namespace InstructionSemantics2 {
20 namespace BaseSemantics {
21 
23 // Register States
25 
29 class RegisterState: public boost::enable_shared_from_this<RegisterState> {
30 public:
32  using Ptr = RegisterStatePtr;
33 
34 private:
35  MergerPtr merger_;
36  SValuePtr protoval_;
38 protected:
39  const RegisterDictionary *regdict;
41  // Serialization
43 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
44 private:
45  friend class boost::serialization::access;
46 
47  template<class S>
48  void serialize(S &s, const unsigned version) {
49  //s & merger_; -- not saved
50  s & BOOST_SERIALIZATION_NVP(protoval_);
51  if (version >= 1)
52  s & BOOST_SERIALIZATION_NVP(regdict);
53  }
54 #endif
55 
56 
58  // Real constructors
59 protected:
60  RegisterState()
61  : regdict(NULL) {} // for serialization
62 
63  RegisterState(const SValuePtr &protoval, const RegisterDictionary *regdict)
64  : protoval_(protoval), regdict(regdict) {
65  ASSERT_not_null(protoval_);
66  }
67 
68 public:
69  virtual ~RegisterState() {}
70 
72  // Static allocating constructors. None are needed--this class is abstract.
73 
74 
76  // Virtual constructors.
77 public:
82  virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionary *regdict) const = 0;
83 
85  virtual RegisterStatePtr clone() const = 0;
86 
88  // Dynamic pointer casts. No-op since this is the base class.
89 public:
90  static RegisterStatePtr promote(const RegisterStatePtr &x) {
91  ASSERT_not_null(x);
92  return x;
93  }
94 
95 public:
97  // The rest of the API...
98 
107  MergerPtr merger() const { return merger_; }
108  void merger(const MergerPtr &m) { merger_ = m; }
112  SValuePtr protoval() const { return protoval_; }
113 
120  const RegisterDictionary *registerDictionary() const /*final*/ {
121  return regdict;
122  }
123  void registerDictionary(const RegisterDictionary *rd) /*final*/ {
124  regdict = rd;
125  }
128  // [Robb Matzke 2021-03-18]: deprecated
129  const RegisterDictionary *get_register_dictionary() const ROSE_DEPRECATED("use registerDictionary property") {
130  return registerDictionary();
131  }
132 
133  // [Robb Matzke 2021-03-18]: deprecated
134  void set_register_dictionary(const RegisterDictionary *rd) ROSE_DEPRECATED("use registerDictionary property") {
135  registerDictionary(rd);
136  }
137 
148  virtual void clear() = 0;
149 
151  virtual void zero() = 0;
152 
156  virtual bool merge(const RegisterStatePtr &other, RiscOperators *ops) = 0;
157 
171  virtual SValuePtr readRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops) = 0;
172 
176  virtual SValuePtr peekRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops) = 0;
177 
184  virtual void writeRegister(RegisterDescriptor reg, const SValuePtr &value, RiscOperators *ops) = 0;
185 
189  virtual void hash(Combinatorics::Hasher&, RiscOperators*) const = 0;
190 
193  void print(std::ostream &stream, const std::string prefix = "") const;
194  virtual void print(std::ostream&, Formatter&) const = 0;
198  class WithFormatter {
199  RegisterStatePtr obj;
200  Formatter &fmt;
201  public:
202  WithFormatter(const RegisterStatePtr &obj, Formatter &fmt): obj(obj), fmt(fmt) {}
203  void print(std::ostream &stream) const { obj->print(stream, fmt); }
204  };
205 
221  WithFormatter with_format(Formatter &fmt) { return WithFormatter(shared_from_this(), fmt); }
222  WithFormatter operator+(Formatter &fmt) { return with_format(fmt); }
223  WithFormatter operator+(const std::string &linePrefix);
226 };
227 
228 std::ostream& operator<<(std::ostream&, const RegisterState&);
229 std::ostream& operator<<(std::ostream&, const RegisterState::WithFormatter&);
230 
231 } // namespace
232 } // namespace
233 } // namespace
234 } // namespace
235 
236 BOOST_CLASS_VERSION(Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::RegisterState, 1);
237 BOOST_CLASS_EXPORT_KEY(Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::RegisterState);
238 
239 #endif
240 #endif
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
Definition: SymbolicExpr.h:156
void serialize(std::ostream &output, Graph &graph)
Serialize a graph into a stream of bytes.
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.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
Hash hash(const std::vector< Ptr > &)
Hash zero or more expressions.