ROSE  0.11.2.0
AbstractLocation.h
1 #ifndef Rose_BinaryAnalysis_AbstractLocation_H
2 #define Rose_BinaryAnalysis_AbstractLocation_H
3 #include <rosePublicConfig.h>
4 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
5 
6 #include "BaseSemantics2.h"
7 
8 namespace Rose {
9 namespace BinaryAnalysis {
10 
26 public:
29 private:
30  RegisterDescriptor reg_;
31  Address addr_;
32  size_t nBytes_; // size of memory location, or zero if unknown
33  const RegisterDictionary *regdict_;
34 
35 public:
40  AbstractLocation(): nBytes_(0), regdict_(NULL) {}
41 
44  : reg_(other.reg_), addr_(other.addr_), nBytes_(other.nBytes_), regdict_(other.regdict_) {}
45 
49  explicit AbstractLocation(RegisterDescriptor reg, const RegisterDictionary *regdict=NULL)
50  : reg_(reg), nBytes_(0), regdict_(regdict) {}
51 
55  explicit AbstractLocation(const Address &addr, size_t nBytes=0): addr_(addr), nBytes_(nBytes), regdict_(NULL) {}
56 
59  reg_ = other.reg_;
60  addr_ = other.addr_;
61  nBytes_ = other.nBytes_;
62  regdict_ = other.regdict_;
63  return *this;
64  }
65 
70  bool isValid() const { return isRegister() || isAddress(); }
71 
76  bool isRegister() const { return !reg_.isEmpty(); }
77 
82  bool isAddress() const { return addr_!=NULL; }
83 
89  RegisterDescriptor getRegister() const { return reg_; }
90 
95  const Address getAddress() const { return addr_; }
96 
101  size_t nBytes() const { ASSERT_require(isAddress()); return nBytes_; }
102 
112  bool mayAlias(const AbstractLocation &other, const SmtSolverPtr &solver = SmtSolverPtr()) const;
113 
123  bool mustAlias(const AbstractLocation &other, const SmtSolverPtr &solver = SmtSolverPtr()) const;
124 
131  void print(std::ostream &out, const RegisterDictionary *regdict=NULL) const {
133  print(out, regdict, fmt);
134  }
135  void print(std::ostream &out, InstructionSemantics2::BaseSemantics::Formatter &fmt) const {
136  print(out, NULL, fmt);
137  }
138  void print(std::ostream &out, const RegisterDictionary *regdict, InstructionSemantics2::BaseSemantics::Formatter &fmt) const;
140 };
141 
142 std::ostream& operator<<(std::ostream&, const AbstractLocation&);
143 
144 } // namespace
145 } // namespace
146 
147 #endif
148 #endif
AbstractLocation(const AbstractLocation &other)
Copy constructor.
bool isValid() const
Validity checker.
size_t nBytes() const
Returns size of memory location in bytes.
void print(std::ostream &out, InstructionSemantics2::BaseSemantics::Formatter &fmt) const
Print an abstract location.
Main namespace for the ROSE library.
Sawyer::SharedPointer< class SmtSolver > SmtSolverPtr
Reference-counting pointer for SMT solvers.
RegisterDescriptor getRegister() const
Returns register.
const Address getAddress() const
Returns memory address.
void print(std::ostream &out, const RegisterDictionary *regdict=NULL) const
Print an abstract location.
AbstractLocation & operator=(const AbstractLocation &other)
Assignment operator.
Describes (part of) a physical CPU register.
bool isAddress() const
Checks memory reference.
AbstractLocation(RegisterDescriptor reg, const RegisterDictionary *regdict=NULL)
Register referent.
bool mayAlias(const AbstractLocation &other, const SmtSolverPtr &solver=SmtSolverPtr()) const
True if two abstract locations could be aliases.
bool mustAlias(const AbstractLocation &other, const SmtSolverPtr &solver=SmtSolverPtr()) const
True if two abstract locations are certainly aliases.
InstructionSemantics2::BaseSemantics::SValuePtr Address
Type of memory address.
Defines registers available for a particular architecture.
Definition: Registers.h:38
bool isEmpty() const
Predicate returns true if the width is zero.
bool isRegister() const
Checks register reference.
AbstractLocation(const Address &addr, size_t nBytes=0)
Memory referent.