ROSE  0.11.83.2
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:
33 
34 private:
35  MergerPtr merger_;
36  SValuePtr protoval_;
38 protected:
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:
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;
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); }
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 
238 
239 #endif
240 #endif
virtual void hash(Combinatorics::Hasher &, RiscOperators *) const =0
Hash the register state.
virtual RegisterStatePtr clone() const =0
Make a copy of this register state.
virtual void clear()=0
Removes stored values from the register state.
virtual bool merge(const RegisterStatePtr &other, RiscOperators *ops)=0
Merge register states for data flow analysis.
virtual void writeRegister(RegisterDescriptor reg, const SValuePtr &value, RiscOperators *ops)=0
Write a value to a register.
Main namespace for the ROSE library.
void print(std::ostream &stream, const std::string prefix="") const
Print the register contents.
virtual SValuePtr readRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops)=0
Read a value from a register.
RegisterStatePtr Ptr
Shared-ownership pointer for a RegisterState object.
Definition: RegisterState.h:32
const RegisterDictionary * registerDictionary() const
Property: Register dictionary.
Base classes for instruction semantics.
Definition: Dispatcher.h:18
Describes (part of) a physical CPU register.
WithFormatter operator+(Formatter &fmt)
Used for printing register states with formatting.
WithFormatter with_format(Formatter &fmt)
Used for printing register states with formatting.
virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionary *regdict) const =0
Virtual constructor.
const RegisterDictionary * regdict
Registers that are able to be stored by this state.
Definition: RegisterState.h:39
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
Defines registers available for a particular architecture.
Definition: Registers.h:37
virtual SValuePtr peekRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops)=0
Read a register without side effects.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
void registerDictionary(const RegisterDictionary *rd)
Property: Register dictionary.