ROSE  0.11.2.0
BaseSemanticsRegisterState.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_RegisterState_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics2_BaseSemantics_RegisterState_H
3 #include <rosePublicConfig.h>
4 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
5 
6 #include <BaseSemanticsMerger.h>
7 #include <BaseSemanticsSValue.h>
8 #include <Registers.h>
9 
10 #include <boost/enable_shared_from_this.hpp>
11 #include <boost/serialization/access.hpp>
12 #include <boost/serialization/nvp.hpp>
13 #include <boost/serialization/shared_ptr.hpp>
14 #include <boost/serialization/version.hpp>
15 
16 namespace Rose {
17 namespace BinaryAnalysis {
18 namespace InstructionSemantics2 {
19 namespace BaseSemantics {
20 
22 // Register States
24 
28 class RegisterState: public boost::enable_shared_from_this<RegisterState> {
29  MergerPtr merger_;
30  SValuePtr protoval_;
32 protected:
33  const RegisterDictionary *regdict;
35  // Serialization
37 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
38 private:
39  friend class boost::serialization::access;
40 
41  template<class S>
42  void serialize(S &s, const unsigned version) {
43  //s & merger_; -- not saved
44  s & BOOST_SERIALIZATION_NVP(protoval_);
45  if (version >= 1)
46  s & BOOST_SERIALIZATION_NVP(regdict);
47  }
48 #endif
49 
50 
52  // Real constructors
53 protected:
55  : regdict(NULL) {} // for serialization
56 
57  RegisterState(const SValuePtr &protoval, const RegisterDictionary *regdict)
58  : protoval_(protoval), regdict(regdict) {
59  ASSERT_not_null(protoval_);
60  }
61 
62 public:
64  typedef RegisterStatePtr Ptr;
65 
66 public:
67  virtual ~RegisterState() {}
68 
70  // Static allocating constructors. None are needed--this class is abstract.
71 
72 
74  // Virtual constructors.
75 public:
80  virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionary *regdict) const = 0;
81 
83  virtual RegisterStatePtr clone() const = 0;
84 
86  // Dynamic pointer casts. No-op since this is the base class.
87 public:
88  static RegisterStatePtr promote(const RegisterStatePtr &x) {
89  ASSERT_not_null(x);
90  return x;
91  }
92 
93 public:
95  // The rest of the API...
96 
105  MergerPtr merger() const { return merger_; }
106  void merger(const MergerPtr &m) { merger_ = m; }
110  SValuePtr protoval() const { return protoval_; }
111 
115  const RegisterDictionary *get_register_dictionary() const { return regdict; }
116  void set_register_dictionary(const RegisterDictionary *rd) { regdict = rd; }
129  virtual void clear() = 0;
130 
132  virtual void zero() = 0;
133 
137  virtual bool merge(const RegisterStatePtr &other, RiscOperators *ops) = 0;
138 
152  virtual SValuePtr readRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops) = 0;
153 
157  virtual SValuePtr peekRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops) = 0;
158 
165  virtual void writeRegister(RegisterDescriptor reg, const SValuePtr &value, RiscOperators *ops) = 0;
166 
169  void print(std::ostream &stream, const std::string prefix = "") const;
170  virtual void print(std::ostream&, Formatter&) const = 0;
174  class WithFormatter {
175  RegisterStatePtr obj;
176  Formatter &fmt;
177  public:
178  WithFormatter(const RegisterStatePtr &obj, Formatter &fmt): obj(obj), fmt(fmt) {}
179  void print(std::ostream &stream) const { obj->print(stream, fmt); }
180  };
181 
197  WithFormatter with_format(Formatter &fmt) { return WithFormatter(shared_from_this(), fmt); }
198  WithFormatter operator+(Formatter &fmt) { return with_format(fmt); }
199  WithFormatter operator+(const std::string &linePrefix);
202 };
203 
204 std::ostream& operator<<(std::ostream&, const RegisterState&);
205 std::ostream& operator<<(std::ostream&, const RegisterState::WithFormatter&);
206 
207 } // namespace
208 } // namespace
209 } // namespace
210 } // namespace
211 
212 // Class versions must be at global scope
213 BOOST_CLASS_VERSION(Rose::BinaryAnalysis::InstructionSemantics2::BaseSemantics::RegisterState, 1);
214 
215 #endif
216 #endif
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
InstructionSemantics2::BaseSemantics::RegisterStateGeneric RegisterState
Register state for the partitioner.
Definition: Semantics.h:34
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.