ROSE  0.11.145.0
RegisterState.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_RegisterState_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_RegisterState_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/BasicTypes.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/Merger.h>
8 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/SValue.h>
9 #include <Rose/BinaryAnalysis/RegisterDictionary.h>
10 
11 #include <boost/enable_shared_from_this.hpp>
12 #include <boost/serialization/access.hpp>
13 #include <boost/serialization/export.hpp>
14 #include <boost/serialization/nvp.hpp>
15 #include <boost/serialization/shared_ptr.hpp>
16 #include <boost/serialization/version.hpp>
17 
18 namespace Rose {
19 namespace BinaryAnalysis {
20 namespace InstructionSemantics {
21 namespace BaseSemantics {
22 
24 // Register States
26 
30 class RegisterState: public boost::enable_shared_from_this<RegisterState> {
31 public:
34 
35 private:
36  MergerPtr merger_;
37  SValuePtr protoval_;
39 protected:
42  // Serialization
44 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
45 private:
46  friend class boost::serialization::access;
47 
48  template<class S>
49  void serialize(S &s, const unsigned version) {
50  //s & merger_; -- not saved
51  s & BOOST_SERIALIZATION_NVP(protoval_);
52  if (version >= 1)
53  s & BOOST_SERIALIZATION_NVP(regdict);
54  }
55 #endif
56 
57 
59  // Real constructors
60 protected:
61  RegisterState(); // for serialization
62 
63  RegisterState(const SValuePtr &protoval, const RegisterDictionaryPtr &regdict);
64 
65 public:
66  virtual ~RegisterState();
67 
69  // Static allocating constructors. None are needed--this class is abstract.
70 
71 
73  // Virtual constructors.
74 public:
79  virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionaryPtr &regdict) const = 0;
80 
82  virtual RegisterStatePtr clone() const = 0;
83 
85  // Dynamic pointer casts. No-op since this is the base class.
86 public:
87  static RegisterStatePtr promote(const RegisterStatePtr&);
88 
89 public:
91  // The rest of the API...
92 
101  MergerPtr merger() const { return merger_; }
102  void merger(const MergerPtr &m) { merger_ = m; }
106  SValuePtr protoval() const { return protoval_; }
107 
114  RegisterDictionaryPtr registerDictionary() const /*final*/;
115  void registerDictionary(const RegisterDictionaryPtr&) /*final*/;
128  virtual void clear() = 0;
129 
131  virtual void zero() = 0;
132 
136  virtual bool merge(const RegisterStatePtr &other, RiscOperators *ops) = 0;
137 
151  virtual SValuePtr readRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops) = 0;
152 
156  virtual SValuePtr peekRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops) = 0;
157 
163  virtual void updateReadProperties(RegisterDescriptor) = 0;
164 
171  virtual void writeRegister(RegisterDescriptor reg, const SValuePtr &value, RiscOperators *ops) = 0;
172 
177  virtual void updateWriteProperties(RegisterDescriptor, InputOutputProperty) = 0;
178 
182  virtual void hash(Combinatorics::Hasher&, RiscOperators*) const = 0;
183 
186  void print(std::ostream &stream, const std::string prefix = "") const;
187  virtual void print(std::ostream&, Formatter&) const = 0;
192  RegisterStatePtr obj;
193  Formatter &fmt;
194  public:
195  WithFormatter(const RegisterStatePtr &obj, Formatter &fmt): obj(obj), fmt(fmt) {}
196  void print(std::ostream &stream) const { obj->print(stream, fmt); }
197  };
198 
214  WithFormatter with_format(Formatter &fmt) { return WithFormatter(shared_from_this(), fmt); }
216  WithFormatter operator+(const std::string &linePrefix);
219 };
220 
221 std::ostream& operator<<(std::ostream&, const RegisterState&);
222 std::ostream& operator<<(std::ostream&, const RegisterState::WithFormatter&);
223 
224 } // namespace
225 } // namespace
226 } // namespace
227 } // namespace
228 
231 
232 #endif
233 #endif
virtual void updateWriteProperties(RegisterDescriptor, InputOutputProperty)=0
Update register properties after writing to a register.
virtual void clear()=0
Removes stored values from the register state.
RegisterDictionaryPtr regdict
Registers that are able to be stored by this state.
Definition: RegisterState.h:40
WithFormatter with_format(Formatter &fmt)
Used for printing register states with formatting.
STL namespace.
boost::shared_ptr< RegisterState > RegisterStatePtr
Shared-ownership pointer to a register state.
Main namespace for the ROSE library.
virtual RegisterStatePtr clone() const =0
Make a copy of this register state.
virtual void zero()=0
Set all registers to the zero.
virtual SValuePtr peekRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops)=0
Read a register without side effects.
virtual void writeRegister(RegisterDescriptor reg, const SValuePtr &value, RiscOperators *ops)=0
Write a value to a register.
Describes (part of) a physical CPU register.
virtual RegisterStatePtr create(const SValuePtr &protoval, const RegisterDictionaryPtr &regdict) const =0
Virtual constructor.
virtual SValuePtr readRegister(RegisterDescriptor reg, const SValuePtr &dflt, RiscOperators *ops)=0
Read a value from a register.
WithFormatter operator+(Formatter &fmt)
Used for printing register states with formatting.
void print(std::ostream &stream, const std::string prefix="") const
Print the register contents.
virtual void hash(Combinatorics::Hasher &, RiscOperators *) const =0
Hash the register state.
virtual bool merge(const RegisterStatePtr &other, RiscOperators *ops)=0
Merge register states for data flow analysis.
RegisterDictionaryPtr registerDictionary() const
Property: Register dictionary.
Base class for most instruction semantics RISC operators.
Definition: RiscOperators.h:49
virtual void updateReadProperties(RegisterDescriptor)=0
Update register properties after reading a register.