ROSE  0.9.9.139
BinaryReturnValueUsed.h
1 #ifndef ROSE_BinaryAnalysis_ReturnValueUsed_H
2 #define ROSE_BinaryAnalysis_ReturnValueUsed_H
3 
4 #include <Partitioner2/BasicTypes.h>
5 #include <Partitioner2/ControlFlowGraph.h>
6 
7 namespace Rose {
8 namespace BinaryAnalysis {
9 
13 namespace ReturnValueUsed {
14 
18 void initDiagnostics();
19 
24 
26 // Miscellaneous small types
28 
30  bool didConverge_; // Are the following data members valid (else only approximations)?
31  std::vector<Partitioner2::Function::Ptr> callees_;
32  RegisterParts returnRegistersUsed_;
33  RegisterParts returnRegistersUnused_;
34 
35 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
36 private:
37  friend class boost::serialization::access;
38 
39  template<class S>
40  void serialize(S & s, const unsigned version) {
41  s & BOOST_SERIALIZATION_NVP(didConverge_);
42  s & BOOST_SERIALIZATION_NVP(callees_);
43  s & BOOST_SERIALIZATION_NVP(returnRegistersUsed_);
44  s & BOOST_SERIALIZATION_NVP(returnRegistersUnused_);
45  }
46 #endif
47 
48 public:
50  : didConverge_(false) {}
51 
59  bool didConverge() const { return didConverge_; }
60  void didConverge(bool b) { didConverge_ = b; }
64  const std::vector<Partitioner2::Function::Ptr> callees() const { return callees_; }
65 
71  const RegisterParts& returnRegistersUsed() const { return returnRegistersUsed_; }
72  RegisterParts& returnRegistersUsed() { return returnRegistersUsed_; }
73  void returnRegistersUsed(const RegisterParts &regs) { returnRegistersUsed_ = regs; }
81  const RegisterParts& returnRegistersUnused() const { return returnRegistersUnused_; }
82  RegisterParts& returnRegistersUnused() { return returnRegistersUnused_; }
83  void returnRegistersUnused(const RegisterParts &regs) { returnRegistersUnused_ = regs; }
86 private:
87  friend class Analysis;
88  void callees(const std::vector<Partitioner2::Function::Ptr> &functions) { callees_ = functions; }
89 };
90 
92 // Main analysis class
94 
95 class Analysis {
96 private:
97  typedef Sawyer::Container::Map<rose_addr_t /*call_site*/, CallSiteResults> CallSiteMap;
98 
99 private:
100  CallingConvention::Definition::Ptr defaultCallingConvention_;
101  CallSiteMap callSites_;
102  bool assumeCallerReturnsValue_;
103 
104 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
105 private:
106  friend class boost::serialization::access;
107 
108  template<class S>
109  void serialize(S &s, const unsigned version) {
110  s & BOOST_SERIALIZATION_NVP(defaultCallingConvention_);
111  s & BOOST_SERIALIZATION_NVP(callSites_);
112  s & BOOST_SERIALIZATION_NVP(assumeCallerReturnsValue_);
113  }
114 #endif
115 
116 public:
123  : assumeCallerReturnsValue_(true) {}
124 
135  CallingConvention::Definition::Ptr defaultCallingConvention() const { return defaultCallingConvention_; }
136  void defaultCallingConvention(const CallingConvention::Definition::Ptr &defn) { defaultCallingConvention_ = defn; }
170  bool assumeCallerReturnsValue() const { return assumeCallerReturnsValue_; }
171  void assumeCallerReturnsValue(bool b) { assumeCallerReturnsValue_ = b; }
178  void clearResults();
179 
181  CallSiteResults analyzeCallSite(const Partitioner2::Partitioner&, const Partitioner2::ControlFlowGraph::ConstVertexIterator&);
182 
183 private:
184  // Given a control flow graph vertex, if that vertex is a function call basic block then return a list of the known, called
185  // functions.
186  std::vector<Partitioner2::Function::Ptr>
187  findCallees(const Partitioner2::Partitioner&, const Partitioner2::ControlFlowGraph::ConstVertexIterator &callSite);
188 
189  // Given a control flow graph vertex, if that vertex is a function call basic block then return a list of all vertices that
190  // are known call-return points for that call.
191  std::vector<Partitioner2::ControlFlowGraph::ConstVertexIterator>
192  findReturnTargets(const Partitioner2::Partitioner&, const Partitioner2::ControlFlowGraph::ConstVertexIterator &callSite);
193 };
194 
195 } // namespace
196 } // namespace
197 } // namespace
198 
199 #endif
RegisterParts & returnRegistersUnused()
Property: Return registers that are unused in the caller.
Collection of streams.
Definition: Message.h:1579
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:25
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:290
Container associating values with keys.
Definition: Sawyer/Map.h:64