ROSE  0.11.31.0
BinaryReturnValueUsed.h
1 #ifndef ROSE_BinaryAnalysis_ReturnValueUsed_H
2 #define ROSE_BinaryAnalysis_ReturnValueUsed_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Partitioner2/BasicTypes.h>
7 #include <Partitioner2/ControlFlowGraph.h>
8 
9 namespace Rose {
10 namespace BinaryAnalysis {
11 
15 namespace ReturnValueUsed {
16 
20 void initDiagnostics();
21 
26 
28 // Miscellaneous small types
30 
32  bool didConverge_; // Are the following data members valid (else only approximations)?
33  std::vector<Partitioner2::Function::Ptr> callees_;
34  RegisterParts returnRegistersUsed_;
35  RegisterParts returnRegistersUnused_;
36 
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 & BOOST_SERIALIZATION_NVP(didConverge_);
44  s & BOOST_SERIALIZATION_NVP(callees_);
45  s & BOOST_SERIALIZATION_NVP(returnRegistersUsed_);
46  s & BOOST_SERIALIZATION_NVP(returnRegistersUnused_);
47  }
48 #endif
49 
50 public:
52  : didConverge_(false) {}
53 
61  bool didConverge() const { return didConverge_; }
62  void didConverge(bool b) { didConverge_ = b; }
66  const std::vector<Partitioner2::Function::Ptr> callees() const { return callees_; }
67 
73  const RegisterParts& returnRegistersUsed() const { return returnRegistersUsed_; }
74  RegisterParts& returnRegistersUsed() { return returnRegistersUsed_; }
75  void returnRegistersUsed(const RegisterParts &regs) { returnRegistersUsed_ = regs; }
83  const RegisterParts& returnRegistersUnused() const { return returnRegistersUnused_; }
84  RegisterParts& returnRegistersUnused() { return returnRegistersUnused_; }
85  void returnRegistersUnused(const RegisterParts &regs) { returnRegistersUnused_ = regs; }
88 private:
89  friend class Analysis;
90  void callees(const std::vector<Partitioner2::Function::Ptr> &functions) { callees_ = functions; }
91 };
92 
94 // Main analysis class
96 
97 class Analysis {
98 private:
99  typedef Sawyer::Container::Map<rose_addr_t /*call_site*/, CallSiteResults> CallSiteMap;
100 
101 private:
102  CallingConvention::Definition::Ptr defaultCallingConvention_;
103  CallSiteMap callSites_;
104  bool assumeCallerReturnsValue_;
105 
106 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
107 private:
108  friend class boost::serialization::access;
109 
110  template<class S>
111  void serialize(S &s, const unsigned /*version*/) {
112  s & BOOST_SERIALIZATION_NVP(defaultCallingConvention_);
113  s & BOOST_SERIALIZATION_NVP(callSites_);
114  s & BOOST_SERIALIZATION_NVP(assumeCallerReturnsValue_);
115  }
116 #endif
117 
118 public:
125  : assumeCallerReturnsValue_(true) {}
126 
137  CallingConvention::Definition::Ptr defaultCallingConvention() const { return defaultCallingConvention_; }
138  void defaultCallingConvention(const CallingConvention::Definition::Ptr &defn) { defaultCallingConvention_ = defn; }
172  bool assumeCallerReturnsValue() const { return assumeCallerReturnsValue_; }
173  void assumeCallerReturnsValue(bool b) { assumeCallerReturnsValue_ = b; }
180  void clearResults();
181 
183  CallSiteResults analyzeCallSite(const Partitioner2::Partitioner&, const Partitioner2::ControlFlowGraph::ConstVertexIterator&);
184 
185 private:
186  // Given a control flow graph vertex, if that vertex is a function call basic block then return a list of the known, called
187  // functions.
188  std::vector<Partitioner2::Function::Ptr>
189  findCallees(const Partitioner2::Partitioner&, const Partitioner2::ControlFlowGraph::ConstVertexIterator &callSite);
190 
191  // Given a control flow graph vertex, if that vertex is a function call basic block then return a list of all vertices that
192  // are known call-return points for that call.
193  std::vector<Partitioner2::ControlFlowGraph::ConstVertexIterator>
194  findReturnTargets(const Partitioner2::Partitioner&, const Partitioner2::ControlFlowGraph::ConstVertexIterator &callSite);
195 };
196 
197 } // namespace
198 } // namespace
199 } // namespace
200 
201 #endif
202 #endif
RegisterParts & returnRegistersUnused()
Property: Return registers that are unused in the caller.
Collection of streams.
Definition: Message.h:1606
const RegisterParts & returnRegistersUnused() const
Property: Return registers that are unused in the caller.
CallingConvention::Definition::Ptr defaultCallingConvention() const
Property: Default calling convention.
CallSiteResults analyzeCallSite(const Partitioner2::Partitioner &, const Partitioner2::ControlFlowGraph::ConstVertexIterator &)
Analyze a call site to see if a function's return value is used.
void initDiagnostics()
Initialize diagnostics.
Main namespace for the ROSE library.
Holds a set of registers without regard for register boundaries.
Definition: RegisterParts.h:28
const std::vector< Partitioner2::Function::Ptr > callees() const
Property: Functions called at this site.
Sawyer::Message::Facility mlog
Facility for diagnostic output.
void clearResults()
Clear analysis results.
RegisterParts & returnRegistersUsed()
Property: Return registers that are used in the caller.
bool assumeCallerReturnsValue() const
Property: Assume caller returns value(s).
bool didConverge() const
Property: Did the analysis converge to a solution.
void defaultCallingConvention(const CallingConvention::Definition::Ptr &defn)
Property: Default calling convention.
const RegisterParts & returnRegistersUsed() const
Property: Return registers that are used in the caller.
void returnRegistersUnused(const RegisterParts &regs)
Property: Return registers that are unused in the caller.
void returnRegistersUsed(const RegisterParts &regs)
Property: Return registers that are used in the caller.
void assumeCallerReturnsValue(bool b)
Property: Assume caller returns value(s).
void didConverge(bool b)
Property: Did the analysis converge to a solution.
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:323
Container associating values with keys.
Definition: Sawyer/Map.h:66