ROSE  0.11.145.0
Partitioner2/DataFlow.h
1 #ifndef ROSE_BinaryAnalysis_Partitioner2_DataFlow_H
2 #define ROSE_BinaryAnalysis_Partitioner2_DataFlow_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
6 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
7 
8 #include <Rose/BinaryAnalysis/DataFlow.h>
9 #include <Rose/BinaryAnalysis/Variables.h>
10 #include <Sawyer/Graph.h>
11 
12 #include <ostream>
13 #include <string>
14 
15 namespace Rose {
16 namespace BinaryAnalysis {
17 namespace Partitioner2 {
18 
20 namespace DataFlow {
21 
23 // Control Flow Graph
25 
29 class DfCfgVertex {
30 public:
32  enum Type {
37  };
38 
39 private:
40  Type type_;
41  BasicBlockPtr bblock_; // attached to BBLOCK vertices
42  FunctionPtr callee_; // function represented by FAKED_CALL
43  FunctionPtr parentFunction_; // function "owning" this vertex
44  size_t inliningId_; // invocation ID for inlining functions during inter-procedural
45 
46 public:
47  ~DfCfgVertex();
48 
51 
53  DfCfgVertex(const FunctionPtr &function, const FunctionPtr &parentFunction, size_t inliningId);
54 
57 
61  Type type() const;
62 
67  const BasicBlockPtr& bblock() const;
68 
70  const FunctionPtr& callee() const;
71 
78 
84  size_t inliningId() const;
85 
90 
94  void print(std::ostream&) const;
95 
99  std::string toString() const;
100 };
101 
124 
131 public:
132  virtual ~InterproceduralPredicate() {}
133  virtual bool operator()(const ControlFlowGraph&, const ControlFlowGraph::ConstEdgeIterator&, size_t depth) = 0;
134 };
135 
138 public:
139  bool operator()(const ControlFlowGraph&, const ControlFlowGraph::ConstEdgeIterator&, size_t /*depth*/) override {
140  return false;
141  }
142 };
143 extern NotInterprocedural NOT_INTERPROCEDURAL;
144 
146 std::vector<SgAsmInstruction*> vertexUnpacker(const DfCfgVertex&);
147 
154 DfCfg buildDfCfg(const PartitionerConstPtr&, const ControlFlowGraph&, const ControlFlowGraph::ConstVertexIterator &startVertex,
155  InterproceduralPredicate &predicate = NOT_INTERPROCEDURAL);
156 
158 void dumpDfCfg(std::ostream&, const DfCfg&);
159 
166 
172 template<class DfCfg>
175  using namespace Sawyer::Container;
176  typename GraphTraits<DfCfg>::VertexIterator retval = dfCfg.vertices().end();
177  for (typename GraphTraits<DfCfg>::VertexIterator vi = dfCfg.vertices().begin(); vi != dfCfg.vertices().end(); ++vi) {
178  if (vi->value().type() == DfCfgVertex::FUNCRET) {
179  ASSERT_require(retval == dfCfg.vertices().end());
180  retval = vi;
181  }
182  }
183  return retval;
184 }
185 
187 // Transfer function
188 //
189 // The transfer function is reponsible for taking a CFG vertex and an initial state and producing the next state, the final
190 // state for that vertex. Users can use whatever transfer function they want; this one is based on the DfCfg and an
191 // instruction semantics state.
193 
198  const RegisterDescriptor STACK_POINTER_REG;
199  const RegisterDescriptor INSN_POINTER_REG;
200  CallingConvention::DefinitionPtr defaultCallingConvention_;
201  bool ignoringSemanticFailures_;
202 
203 public:
204  ~TransferFunction();
205 
210 
213 
218 
238  bool ignoringSemanticFailures() const;
239  void ignoringSemanticFailures(bool);
242  // Required by data-flow engine
243  std::string toString(const InstructionSemantics::BaseSemantics::StatePtr &state);
244 
245  // Required by data-flow engine: compute new output state given a vertex and input state.
247  operator()(const DfCfg&, size_t vertexId, const InstructionSemantics::BaseSemantics::StatePtr &incomingState) const;
248 };
249 
255 
260  MergeFunction>;
261 
275  const InstructionSemantics::BaseSemantics::SValuePtr &initialStackPointer);
276 
283  const InstructionSemantics::BaseSemantics::SValuePtr &initialStackPointer);
284 
292  const InstructionSemantics::BaseSemantics::SValuePtr &initialStackPointer);
293 
298 std::vector<AbstractLocation> findGlobalVariables(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops,
299  size_t wordNBytes);
300 
301 } // namespace
302 } // namespace
303 } // namespace
304 } // namespace
305 
306 #endif
307 #endif
Rose::BinaryAnalysis::DataFlow::SemanticsMerge MergeFunction
Data-flow merge function.
DfCfg buildDfCfg(const PartitionerConstPtr &, const ControlFlowGraph &, const ControlFlowGraph::ConstVertexIterator &startVertex, InterproceduralPredicate &predicate=NOT_INTERPROCEDURAL)
build a cfg useful for data-flow analysis.
Predicate that always returns false, preventing interprocedural analysis.
FunctionPtr bestSummaryFunction(const FunctionSet &functions)
Choose best function for data-flow summary vertex.
Graph containing user-defined vertices and edges.
Definition: Graph.h:625
Sawyer::Container::GraphTraits< DfCfg >::VertexIterator findReturnVertex(DfCfg &dfCfg)
Find the return vertex.
Basic merge operation for instruction semantics.
Definition: DataFlow.h:215
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
Sawyer::Optional< rose_addr_t > address() const
Virtual address of vertex.
boost::iterator_range< VertexIterator > vertices()
Iterators for all vertices.
Definition: Graph.h:1469
Main namespace for the ROSE library.
boost::shared_ptr< State > StatePtr
Shared-ownership pointer to a semantic state.
const FunctionPtr & callee() const
Function represented by faked call.
boost::shared_ptr< Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
Variables::StackVariables findLocalVariables(const FunctionPtr &function, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops, const InstructionSemantics::BaseSemantics::SValuePtr &initialStackPointer)
Returns the list of all known local variables.
InstructionSemantics::BaseSemantics::StatePtr initialState() const
Construct an initial state.
Container classes that store user-defined values.
Definition: AddressMap.h:34
TransferFunction(const InstructionSemantics::BaseSemantics::DispatcherPtr &)
Construct from a CPU.
Describes (part of) a physical CPU register.
Sawyer::Container::Graph< DfCfgVertex > DfCfg
Control flow graph used by data-flow analysis.
Predicate that decides when to use inter-procedural data-flow.
size_t inliningId() const
Inlining invocation number.
InstructionSemantics::BaseSemantics::DispatcherPtr cpu() const
Property: Virtual CPU.
std::vector< SgAsmInstruction * > vertexUnpacker(const DfCfgVertex &)
Unpacks a vertex into a list of instructions.
std::vector< AbstractLocation > findGlobalVariables(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops, size_t wordNBytes)
Returns a list of global variables.
void print(std::ostream &) const
Print a short description of this vertex.
Variables::StackVariables findFunctionArguments(const FunctionPtr &function, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops, const InstructionSemantics::BaseSemantics::SValuePtr &initialStackPointer)
Returns the list of all known function arguments.
DfCfgVertex(const BasicBlockPtr &, const FunctionPtr &parentFunction, size_t inliningId)
Construct a basic block vertex.
G::VertexIterator VertexIterator
Const or non-const vertex iterator.
Definition: Graph.h:295
FunctionPtr parentFunction() const
Function owning this vertex.
void dumpDfCfg(std::ostream &, const DfCfg &)
Emit a data-flow CFG as a GraphViz file.
Indeterminate basic block where no information is available.
Variables::StackVariables findStackVariables(const FunctionPtr &function, const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops, const InstructionSemantics::BaseSemantics::SValuePtr &initialStackPointer)
Returns the list of all known stack variables.
const BasicBlockPtr & bblock() const
Basic block.
bool ignoringSemanticFailures() const
Property: Whether to ignore instructions with unknown semantics.
std::string toString() const
Single-line description of this vertex.
CallingConvention::DefinitionPtr defaultCallingConvention() const
Property: Default calling convention.