1#ifndef ROSE_BinaryAnalysis_Partitioner2_ControlFlowGraph_H
2#define ROSE_BinaryAnalysis_Partitioner2_ControlFlowGraph_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
7#include <Rose/BinaryAnalysis/Partitioner2/Utility.h>
9#include <Sawyer/BiMap.h>
10#include <Sawyer/Graph.h>
11#include <Sawyer/GraphIteratorSet.h>
12#include <Sawyer/GraphIteratorBiMap.h>
13#include <Sawyer/HashMap.h>
14#include <Sawyer/Map.h>
15#include <Sawyer/Optional.h>
17#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
18#include <boost/serialization/access.hpp>
25namespace BinaryAnalysis {
26namespace Partitioner2 {
35#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
37 friend class boost::serialization::access;
38 template<
class S>
void serialize(S&,
unsigned version);
148#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
150 friend class boost::serialization::access;
151 template<
class S>
void serialize(S&,
unsigned version);
177bool sortEdgesBySrc(
const ControlFlowGraph::ConstEdgeIterator&,
const ControlFlowGraph::ConstEdgeIterator&);
180bool sortEdgesByDst(
const ControlFlowGraph::ConstEdgeIterator&,
const ControlFlowGraph::ConstEdgeIterator&);
183bool sortEdgesById(
const ControlFlowGraph::ConstEdgeIterator&,
const ControlFlowGraph::ConstEdgeIterator&);
186bool sortVerticesByAddress(
const ControlFlowGraph::ConstVertexIterator&,
const ControlFlowGraph::ConstVertexIterator&);
189bool sortVerticesById(
const ControlFlowGraph::ConstVertexIterator&,
const ControlFlowGraph::ConstVertexIterator&);
192std::ostream& operator<<(std::ostream&,
const ControlFlowGraph::Vertex&);
195std::ostream& operator<<(std::ostream&,
const ControlFlowGraph::Edge&);
392 ControlFlowGraph::VertexIterator &entry);
409 const ControlFlowGraph::ConstVertexIterator &gcfgEntry);
Base class for CFG-adjustment callbacks.
Sawyer::SharedPointer< CfgAdjustmentCallback > Ptr
Shared ownership pointer.
virtual bool operator()(bool chain, const DetachedBasicBlock &)=0
Called when basic block is detached or placeholder erased.
virtual bool operator()(bool chain, const AttachedBasicBlock &)=0
Called when basic block is attached or placeholder inserted.
CfgEdge(EdgeType type, Confidence confidence=ASSUMED)
Construct an edge with a specified type and confidence.
CfgEdge()
Construct a new normal edge.
Confidence confidence() const
Property: Confidence.
void confidence(Confidence)
Property: Confidence.
EdgeType type() const
Return edge type.
Control flow graph vertex.
const FunctionSet & owningFunctions() const
Property: Owning functions.
FunctionSet & owningFunctions()
Property: Owning functions.
const BasicBlockPtr & bblock() const
Property: basic block.
bool insertOwningFunction(const FunctionPtr &)
Add a function to the list of functions that own this vertex.
rose_addr_t address() const
Property: starting address.
FunctionPtr isEntryBlock() const
Is block a function entry block?
CfgVertex(const BasicBlockPtr &bb)
Construct a basic block vertex.
Sawyer::Optional< rose_addr_t > optionalAddress() const
Safe version of starting address.
AddressIntervalSet addresses() const
Compute entire address set.
Sawyer::Optional< rose_addr_t > optionalLastAddress() const
Address of last item in the vertex.
void eraseOwningFunction(const FunctionPtr &)
Remove a function from the list of functions that own this vertex.
void bblock(const BasicBlockPtr &)
Property: basic block.
CfgVertex(VertexType type)
Construct a special vertex.
bool isOwningFunction(const FunctionPtr &) const
Determines if a function owns this vertex.
void address(rose_addr_t)
Property: starting address.
CfgVertex(rose_addr_t startVa)
Construct a basic block placeholder vertex.
VertexType type() const
Returns the vertex type.
size_t nOwningFunctions() const
Number of functions that own this vertex.
void nullify()
Turns a basic block vertex into a placeholder.
Bidirectional map of graph edge or vertex pointers.
Set of graph edge or vertex pointers (iterators).
Container associating values with keys.
Container associating values with keys.
Holds a value or nothing.
Base class for reference counted objects.
CfgConstVertexSet forwardMapped(const CfgConstVertexSet &, const CfgVertexMap &)
Return corresponding iterators.
void insertCfg(ControlFlowGraph &dst, const ControlFlowGraph &src, CfgVertexMap &vmap)
Insert one control flow graph into another.
std::list< ControlFlowGraph::ConstVertexIterator > CfgConstVertexList
List of CFG vertex pointers.
CfgConstVertexSet findIncidentVertices(const CfgConstEdgeSet &)
Vertices that are incident to specified edges.
std::list< ControlFlowGraph::EdgeIterator > CfgEdgeList
List of CFG edge pointers.
CfgConstVertexSet findFunctionReturns(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &beginVertex)
Find all function return vertices.
Sawyer::Container::Map< FunctionPtr, CfgConstEdgeSet > findFunctionReturnEdges(const PartitionerConstPtr &)
Find function return edges organized by function.
CfgConstEdgeSet findCallReturnEdges(const PartitionerConstPtr &, const ControlFlowGraph &)
Return outgoing call-return edges.
ControlFlowGraph functionCfgByReachability(const ControlFlowGraph &gcfg, const FunctionPtr &function, const ControlFlowGraph::ConstVertexIterator &gcfgEntry)
Generate a function control flow graph.
void expandFunctionReturnEdges(const PartitionerConstPtr &, ControlFlowGraph &cfg)
Rewrite function return edges.
bool sortEdgesByDst(const ControlFlowGraph::ConstEdgeIterator &, const ControlFlowGraph::ConstEdgeIterator &)
Sort edges by target vertex address.
bool sortEdgesBySrc(const ControlFlowGraph::ConstEdgeIterator &, const ControlFlowGraph::ConstEdgeIterator &)
Sort edges by source vertex address.
bool sortVerticesByAddress(const ControlFlowGraph::ConstVertexIterator &, const ControlFlowGraph::ConstVertexIterator &)
Sort vertices by address.
CfgConstEdgeSet findCallEdges(const ControlFlowGraph::ConstVertexIterator &callSite)
Find function call edges.
Sawyer::Container::GraphIteratorBiMap< ControlFlowGraph::ConstVertexIterator, ControlFlowGraph::ConstVertexIterator > CfgVertexMap
Map vertices from one CFG to another CFG and vice versa.
bool sortVerticesById(const ControlFlowGraph::ConstVertexIterator &, const ControlFlowGraph::ConstVertexIterator &)
Sort vertices by vertex ID number.
EdgeType
Partitioner control flow edge types.
Confidence
How sure are we of something.
@ ASSUMED
The value is an assumption without any proof.
Sawyer::Container::GraphIteratorSet< ControlFlowGraph::ConstEdgeIterator > CfgConstEdgeSet
Set of CFG edge pointers.
Sawyer::Container::HashMap< rose_addr_t, ControlFlowGraph::VertexIterator > CfgVertexIndex
Mapping from basic block starting address to CFG vertex.
std::list< ControlFlowGraph::VertexIterator > CfgVertexList
List of CFG vertex pointers.
std::list< ControlFlowGraph::ConstEdgeIterator > CfgConstEdgeList
List of CFG edge pointers.
CfgConstVertexSet reverseMapped(const CfgConstVertexSet &, const CfgVertexMap &)
Return corresponding iterators.
Sawyer::Container::GraphIteratorSet< ControlFlowGraph::ConstVertexIterator > CfgConstVertexSet
Set of CFG vertex pointers.
Sawyer::Container::GraphIteratorSet< ControlFlowGraph::EdgeIterator > CfgEdgeSet
Set of CFG edge pointers.
CfgConstVertexSet findDetachedVertices(const ControlFlowGraph &)
Find vertices that have zero degree.
Sawyer::Container::GraphIteratorSet< ControlFlowGraph::VertexIterator > CfgVertexSet
Set of CFG vertex pointers.
void eraseEdges(ControlFlowGraph &, const CfgConstEdgeSet &toErase)
Erase multiple edges.
bool sortEdgesById(const ControlFlowGraph::ConstEdgeIterator &, const ControlFlowGraph::ConstEdgeIterator &)
Sort edges by edge ID number.
CfgConstEdgeSet findBackEdges(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &begin)
Find back edges.
ControlFlowGraph functionCfgByErasure(const ControlFlowGraph &gcfg, const FunctionPtr &function, ControlFlowGraph::VertexIterator &entry)
Generate a function control flow graph.
CfgConstVertexSet findCalledFunctions(const ControlFlowGraph &cfg, const ControlFlowGraph::ConstVertexIterator &callSite)
Find called functions.
VertexType
Partitioner control flow vertex types.
Arguments for attaching a basic block.
const PartitionerPtr partitioner
Partitioner in which change occurred.
rose_addr_t startVa
Starting address for basic block or placeholder.
BasicBlockPtr bblock
Optional basic block; otherwise a placeholder operation.
Arguments for detaching a basic block.
PartitionerConstPtr partitioner
Partitioner in which change occurred.
BasicBlockPtr bblock
Optional basic block; otherwise a placeholder operation.
rose_addr_t startVa
Starting address for basic block or placeholder.