1 #ifndef ROSE_BinaryAnalysis_ControlFlow_H
2 #define ROSE_BinaryAnalysis_ControlFlow_H
4 #include <featureTests.h>
5 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
9 #include "SageBuilderAsm.h"
11 #include <boost/foreach.hpp>
12 #include <boost/graph/adjacency_list.hpp>
13 #include <boost/graph/reverse_graph.hpp>
14 #include <boost/graph/depth_first_search.hpp>
15 #include <Sawyer/GraphBoost.h>
143 : vertex_filter(NULL), edge_filter(NULL)
165 typedef boost::adjacency_list<boost::setS,
167 boost::bidirectionalS,
168 boost::property<boost::vertex_name_t, SgAsmBlock*> >
BlockGraph;
188 typedef boost::adjacency_list<boost::setS,
190 boost::bidirectionalS,
191 boost::property<boost::vertex_name_t, SgAsmInstruction*> >
InsnGraph;
259 return filter && !(*filter)(
this, src, dst);
267 VertexFilter *vertex_filter;
268 EdgeFilter *edge_filter;
297 template<
class ControlFlowGraph>
313 template<
class ControlFlowGraph>
346 template<
class ControlFlowGraph>
349 template<
class ControlFlowGraph>
352 template<
class ControlFlowGraph>
355 template<
class ControlFlowGraph>
361 template<
class BlockCFG,
class InsnCFG>
368 template<
class InsnCFG>
380 template<
class ControlFlowGraph>
383 template<
class ControlFlowGraph>
397 template<
class ControlFlowGraph>
398 ControlFlowGraph
copy(
const ControlFlowGraph &src);
400 template<
class ControlFlowGraph>
401 void copy(
const ControlFlowGraph &src, ControlFlowGraph &dst);
411 std::vector<typename boost::graph_traits<CFG>::vertex_descriptor> vertices;
412 std::vector<typename boost::graph_traits<CFG>::edge_descriptor> edges;
418 void operator()(std::ostream &o,
typename boost::graph_traits<CFG>::vertex_descriptor vertex)
const {}
424 void operator()(std::ostream &o,
typename boost::graph_traits<CFG>::edge_descriptor vertex)
const {}
429 template<
typename CFG,
class VertexPropertyWriter,
class EdgePropertyWriter>
430 void write_graphviz(std::ostream&,
const CFG&,
const VertexPropertyWriter&,
const EdgePropertyWriter&);
432 template<
typename CFG>
437 template<
typename CFG,
class VertexPropertyWriter>
438 void write_graphviz(std::ostream &out,
const CFG &cfg,
const VertexPropertyWriter &vpw) {
449 template<
class ControlFlowGraph>
450 struct FlowOrder:
public boost::default_dfs_visitor {
451 typedef typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor
Vertex;
452 typedef std::vector<Vertex> VertexList;
453 typedef std::vector<size_t> ReverseVertexList;
454 VertexList *forward_order;
455 FlowOrder(VertexList *forward_order): forward_order(forward_order) {}
456 void compute(
const ControlFlowGraph &g, Vertex v0, ReverseVertexList *reverse_order);
457 void finish_vertex(Vertex v, ControlFlowGraph g);
462 template<
class ControlFlowGraph>
465 ControlFlow *analyzer;
466 ControlFlowGraph &cfg;
467 typedef typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor
Vertex;
469 BlockVertexMap &bv_map;
470 VertexInserter(ControlFlow *analyzer, ControlFlowGraph &cfg, BlockVertexMap &bv_map)
471 : analyzer(analyzer), cfg(cfg), bv_map(bv_map)
474 void conditionally_add_vertex(
SgAsmBlock *block);
476 void visit(
SgNode *node) {
477 if (isSgAsmFunction(node)) {
481 conditionally_add_vertex(isSgAsmFunction(node)->get_entry_block());
483 conditionally_add_vertex(isSgAsmBlock(node));
521 template<
class ControlFlowGraph>
522 std::vector<typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor>
524 typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor start,
525 std::vector<size_t> *reverse_order=NULL);
529 template<
class ControlFlowGraph>
530 struct ReturnBlocks:
public boost::default_dfs_visitor {
531 typedef typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor Vertex;
532 typedef std::vector<Vertex> Vector;
534 ReturnBlocks(Vector &blocks): blocks(blocks) {}
535 void finish_vertex(Vertex v, ControlFlowGraph g);
546 template<
class ControlFlowGraph>
547 std::vector<typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor>
549 typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor start);
559 template<
class V,
class E>
563 typename CFG::ConstVertexValueIterator iter = cfg.
findVertex(vertexId);
570 template<
class V,
class E,
class AstNode>
574 typename CFG::VertexValueIterator iter = cfg.
findVertex(vertexId);
580 template<
class A,
class B,
class C,
class D,
class E,
class F,
class G>
581 typename boost::property_traits<typename boost::property_map<boost::adjacency_list<A, B, C, D, E, F, G>,
582 boost::vertex_name_t>::type>::value_type
583 get_ast_node(
const boost::adjacency_list<A, B, C, D, E, F, G> &cfg,
584 typename boost::graph_traits<boost::adjacency_list<A, B, C, D, E, F, G> >::vertex_descriptor vertex) {
585 return boost::get(boost::vertex_name, cfg, vertex);
589 template<
class A,
class B,
class C,
class D,
class E,
class F,
class G>
591 put_ast_node(boost::adjacency_list<A, B, C, D, E, F, G> &cfg,
592 typename boost::graph_traits<boost::adjacency_list<A, B, C, D, E, F, G> >::vertex_descriptor vertex,
593 typename boost::property_traits<
594 typename boost::property_map<boost::adjacency_list<A, B, C, D, E, F, G>, boost::vertex_name_t>::type
595 >::value_type ast_node) {
596 boost::put(boost::vertex_name, cfg, vertex, ast_node);
603 template<
class ControlFlowGraph>
607 typename boost::graph_traits<ControlFlowGraph>::vertex_iterator vi, vi_end;
608 for (boost::tie(vi, vi_end)=boost::vertices(cfg); vi!=vi_end; ++vi) {
614 const SgAsmIntegerValuePtrList &targets = block->
get_successors();
615 for (SgAsmIntegerValuePtrList::const_iterator ti=targets.begin(); ti!=targets.end(); ++ti)
621 typename boost::graph_traits<ControlFlowGraph>::out_edge_iterator ei, ei_end;
622 for (boost::tie(ei, ei_end)=boost::out_edges(*vi, cfg); ei!=ei_end; ++ei) {
634 template<
class ControlFlowGraph>
638 typename boost::graph_traits<ControlFlowGraph>::vertex_iterator vi, vi_end;
639 for (boost::tie(vi, vi_end)=boost::vertices(cfg); vi!=vi_end; ++vi) {
646 template<
class ControlFlowGraph>
648 ControlFlow::VertexInserter<ControlFlowGraph>::conditionally_add_vertex(
SgAsmBlock *block)
650 if (block && block->
has_instructions() && !analyzer->is_vertex_filtered(block) && !bv_map.exists(block)) {
651 Vertex vertex = boost::add_vertex(cfg);
652 bv_map[block] = vertex;
657 template<
class ControlFlowGraph>
661 typedef typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor Vertex;
662 Vertex NO_VERTEX = boost::graph_traits<ControlFlowGraph>::null_vertex();
664 BlockVertexMap bv_map;
668 VertexInserter<ControlFlowGraph>(
this, cfg, bv_map).traverse(root, preorder);
672 for (
typename BlockVertexMap::iterator bvi=bv_map.begin(); bvi!=bv_map.end(); ++bvi)
673 addrToVertex[bvi->first->get_address()] = bvi->second;
676 BOOST_FOREACH (Vertex sourceVertex, boost::vertices(cfg)) {
680 if (targetVertex!=NO_VERTEX) {
682 assert(targetBlock!=NULL);
684 boost::add_edge(sourceVertex, targetVertex, cfg);
690 template<
class ControlFlowGraph>
697 bool preserve_call_fallthrough_edges =
false;
701 template<
class ControlFlowGraph>
709 SgAsmFunction *src_func = SageInterface::getEnclosingNode<SgAsmFunction>(src,
true);
710 SgAsmBlock *dst_block = SageInterface::getEnclosingNode<SgAsmBlock>(dst,
true);
711 SgAsmFunction *dst_func = SageInterface::getEnclosingNode<SgAsmFunction>(dst_block);
712 if (!src_func || !dst_func || dst_block!=dst_func->
get_entry_block()) {
714 }
else if (src_func!=dst_func) {
719 return parent ? (*parent)(analyzer, src, dst) :
true;
724 T1 edge_filter(parent);
735 template<
class ControlFlowGraph>
739 typedef typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor Vertex;
740 Vertex NO_VERTEX = boost::graph_traits<ControlFlowGraph>::null_vertex();
743 std::vector<Vertex> src_to_dst(boost::num_vertices(src), NO_VERTEX);
745 typename boost::graph_traits<const ControlFlowGraph>::vertex_iterator vi, vi_end;
746 for (boost::tie(vi, vi_end)=boost::vertices(src); vi!=vi_end; ++vi) {
749 src_to_dst[*vi] = boost::add_vertex(dst);
754 typename boost::graph_traits<const ControlFlowGraph>::edge_iterator ei, ei_end;
755 for (boost::tie(ei, ei_end)=boost::edges(src); ei!=ei_end; ++ei) {
756 if (NO_VERTEX!=src_to_dst[boost::source(*ei, src)] && NO_VERTEX!=src_to_dst[boost::target(*ei, src)]) {
760 boost::add_edge(src_to_dst[boost::source(*ei, src)], src_to_dst[boost::target(*ei, src)], dst);
765 template<
class ControlFlowGraph>
769 ControlFlowGraph dst;
774 template<
class BlockCFG,
class InsnCFG>
779 typedef typename boost::graph_traits<const BlockCFG>::vertex_descriptor BlockCFG_Vertex;
780 typedef typename boost::graph_traits<const BlockCFG>::vertex_iterator BlockCFG_VertexIterator;
781 typedef typename boost::graph_traits<const BlockCFG>::edge_iterator BlockCFG_EdgeIterator;
785 typedef typename boost::graph_traits<InsnCFG>::vertex_descriptor InsnCFG_Vertex;
786 typedef std::pair<InsnCFG_Vertex, InsnCFG_Vertex> InsnCFG_VertexPair;
792 BlockCFG_VertexIterator vi, vi_end;
793 for (boost::tie(vi, vi_end)=boost::vertices(cfgb); vi!=vi_end; ++vi) {
796 assert(!insns.empty());
797 InsnCFG_Vertex enter_vertex = boost::graph_traits<InsnCFG>::null_vertex();
798 InsnCFG_Vertex prev_vertex = boost::graph_traits<InsnCFG>::null_vertex();
799 for (SgAsmStatementPtrList::const_iterator ii=insns.begin(); ii!=insns.end(); ++ii) {
802 InsnCFG_Vertex vertex = boost::add_vertex(cfgi);
804 if (ii==insns.begin()) {
805 enter_vertex = vertex;
807 boost::add_edge(prev_vertex, vertex, cfgi);
809 prev_vertex = vertex;
811 assert(prev_vertex!=boost::graph_traits<InsnCFG>::null_vertex());
812 vertex_translation[*vi] = InsnCFG_VertexPair(enter_vertex, prev_vertex);
819 BlockCFG_EdgeIterator ei, ei_end;
820 for (boost::tie(ei, ei_end)=boost::edges(cfgb); ei!=ei_end; ++ei) {
821 InsnCFG_Vertex src_leave_vertex = vertex_translation.
get_one(boost::source(*ei, cfgb)).second;
822 InsnCFG_Vertex dst_enter_vertex = vertex_translation.
get_one(boost::target(*ei, cfgb)).first;
823 assert(src_leave_vertex!=boost::graph_traits<InsnCFG>::null_vertex());
824 assert(dst_enter_vertex!=boost::graph_traits<InsnCFG>::null_vertex());
825 boost::add_edge(src_leave_vertex, dst_enter_vertex, cfgi);
830 template<
class InsnCFG>
834 typedef typename boost::graph_traits<InsnCFG>::vertex_descriptor CFG_Vertex;
835 typedef typename boost::graph_traits<InsnCFG>::vertex_iterator CFG_VertexIterator;
836 typedef typename boost::graph_traits<InsnCFG>::in_edge_iterator CFG_InEdgeIterator;
837 typedef std::pair<CFG_Vertex, CFG_Vertex> CFG_VertexPair;
839 CFG_Vertex NO_VERTEX = boost::graph_traits<InsnCFG>::null_vertex();
844 InstructionMap insns;
845 InsnToVertex insn_to_vertex;
846 std::vector<bool> isret(boost::num_vertices(cfg),
false);
848 CFG_VertexIterator vi, vi_end;
849 for (boost::tie(vi, vi_end)=boost::vertices(cfg); vi!=vi_end; ++vi) {
852 insn_to_vertex[insn] = *vi;
854 if (0==boost::out_degree(*vi, cfg)) {
857 isret[*vi] = x86_ret==insn_x86->get_kind();
864 struct FunctionEntryVertex {
865 const InsnToVertex &insn_to_vertex;
866 const InstructionMap &imap;
867 FunctionEntryVertex(
const InsnToVertex &insn_to_vertex,
const InstructionMap &imap)
868 : insn_to_vertex(insn_to_vertex), imap(imap) {}
870 SgAsmFunction *func = SageInterface::getEnclosingNode<SgAsmFunction>(insn,
true);
872 CFG_Vertex entry_vertex = insn_to_vertex.get_one(entry_insn);
875 } function_entry_vertex(insn_to_vertex, insns);
878 std::vector<CFG_VertexPair> edges_to_insert, edges_to_erase;
880 CFG_VertexIterator vi, vi_end;
881 for (boost::tie(vi, vi_end)=boost::vertices(cfg); vi!=vi_end; ++vi) {
882 CFG_Vertex returner_vertex = *vi;
883 if (!isret[returner_vertex])
891 std::vector<bool> seen(boost::num_vertices(cfg),
false);
893 worklist.
push(function_entry_vertex(returner_insn));
894 while (!worklist.
empty()) {
895 CFG_Vertex callee_vertex = worklist.
shift();
896 CFG_InEdgeIterator ei, ei_end;
897 for (boost::tie(ei, ei_end)=boost::in_edges(callee_vertex, cfg); ei!=ei_end; ++ei) {
898 CFG_Vertex caller_vertex = boost::source(*ei, cfg);
899 if (!seen[caller_vertex]) {
900 seen[caller_vertex] =
true;
902 SgAsmBlock *caller_block = SageInterface::getEnclosingNode<SgAsmBlock>(caller_insn);
903 assert(caller_block!=NULL);
904 rose_addr_t target_va, returnee_va;
909 CFG_Vertex returnee_vertex = insn_to_vertex.get_value_or(returnee_insn, NO_VERTEX);
910 if (returnee_vertex!=NO_VERTEX) {
911 edges_to_insert.push_back(CFG_VertexPair(returner_vertex, returnee_vertex));
912 edges_to_erase.push_back(CFG_VertexPair(caller_vertex, returnee_vertex));
918 worklist.
push(function_entry_vertex(caller_insn));
927 if (!preserve_call_fallthrough_edges) {
928 for (
size_t i=0; i<edges_to_erase.size(); ++i)
929 boost::remove_edge(edges_to_erase[i].first, edges_to_erase[i].second, cfg);
931 for (
size_t i=0; i<edges_to_insert.size(); ++i)
932 boost::add_edge(edges_to_insert[i].first, edges_to_insert[i].second, cfg);
935 template<
class ControlFlowGraph>
937 ControlFlow::FlowOrder<ControlFlowGraph>::compute(
const ControlFlowGraph &g, Vertex v0,
938 ReverseVertexList *reverse_order) {
939 forward_order->clear();
940 std::vector<boost::default_color_type> colors(boost::num_vertices(g), boost::white_color);
941 boost::depth_first_visit(g, v0, *
this, &(colors[0]));
942 assert(!forward_order->empty());
943 std::reverse(forward_order->begin(), forward_order->end());
945 reverse_order->clear();
946 reverse_order->resize(boost::num_vertices(g),
INVALID_INDEX);
947 for (
size_t i=0; i<forward_order->size(); i++)
948 (*reverse_order)[(*forward_order)[i]] = i;
952 template<
class ControlFlowGraph>
954 ControlFlow::FlowOrder<ControlFlowGraph>::finish_vertex(Vertex v, ControlFlowGraph g) {
955 forward_order->push_back(v);
958 template<
class ControlFlowGraph>
959 std::vector<typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor>
961 typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor start,
962 std::vector<size_t> *reverse_order)
964 std::vector<typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor> forward_order;
965 FlowOrder<ControlFlowGraph>(&forward_order).compute(cfg, start, reverse_order);
966 return forward_order;
969 template<
class ControlFlowGraph>
971 ControlFlow::ReturnBlocks<ControlFlowGraph>::finish_vertex(Vertex v, ControlFlowGraph g)
973 typename boost::graph_traits<ControlFlowGraph>::out_edge_iterator ei, ei_end;
974 boost::tie(ei, ei_end) = boost::out_edges(v, g);
979 template<
class ControlFlowGraph>
980 std::vector<typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor>
982 typename boost::graph_traits<ControlFlowGraph>::vertex_descriptor start)
984 typename ReturnBlocks<ControlFlowGraph>::Vector result;
985 ReturnBlocks<ControlFlowGraph> visitor(result);
986 std::vector<boost::default_color_type> colors(boost::num_vertices(cfg), boost::white_color);
987 boost::depth_first_visit(cfg, start, visitor, &(colors[0]));
991 template<
class ControlFlowGraph>
995 ControlFlowGraph cfg;
1000 template<
class ControlFlowGraph>
1004 ControlFlowGraph cfg;
1009 template<
class ControlFlowGraph>
1013 ControlFlowGraph cfg;
1019 template<
typename CFG,
class VertexPropertyWriter,
class EdgePropertyWriter>
1022 const VertexPropertyWriter &vpw,
const EdgePropertyWriter &epw)
1025 typedef typename boost::graph_traits<CFG>::edge_descriptor CFG_Edge;
1026 typedef typename boost::graph_traits<CFG>::vertex_iterator CFG_VertexIterator;
1027 typedef typename boost::graph_traits<CFG>::out_edge_iterator CFG_OutEdgeIterator;
1032 std::vector<CFG_Edge> interfunc_edges;
1033 CFG_VertexIterator vi, vi_end;
1034 for (boost::tie(vi, vi_end)=boost::vertices(cfg); vi!=vi_end; ++vi) {
1037 f.vertices.push_back(*vi);
1038 CFG_OutEdgeIterator ei, ei_end;
1039 for (boost::tie(ei, ei_end)=boost::out_edges(*vi, cfg); ei!=ei_end; ++ei) {
1041 SgAsmFunction *tgt_func = SageInterface::getEnclosingNode<SgAsmFunction>(tgt_node,
true);
1042 if (tgt_func==func) {
1043 f.edges.push_back(*ei);
1045 interfunc_edges.push_back(*ei);
1051 out <<
"digraph G {\n";
1052 for (
typename Functions::iterator fi=funcs.begin(); fi!=funcs.end(); ++fi) {
1054 if (!f.vertices.empty() || !f.edges.empty()) {
1056 SgAsmFunction *func = SageInterface::getEnclosingNode<SgAsmFunction>(node,
true);
1057 char cluster_name[64];
1058 sprintf(cluster_name,
"cluster_F%" PRIx64, func->get_entry_va());
1059 out <<
" subgraph " <<cluster_name <<
" {\n"
1060 <<
" style=filled;\n"
1061 <<
" color=lightgrey;\n"
1063 <<(func->get_name().empty()?std::string(
""):(
" <"+func->get_name()+
">")) <<
"\";\n";
1064 for (
size_t i=0; i<f.vertices.size(); ++i) {
1065 out <<
" " <<f.vertices[i];
1066 vpw(out, f.vertices[i]);
1069 for (
size_t i=0; i<f.edges.size(); ++i) {
1070 out <<
" " <<boost::source(f.edges[i], cfg) <<
"->" <<boost::target(f.edges[i], cfg);
1071 epw(out, f.edges[i]);
1079 for (
size_t i=0; i<interfunc_edges.size(); ++i) {
1080 out <<
" " <<boost::source(interfunc_edges[i], cfg) <<
"->" <<boost::target(interfunc_edges[i], cfg);
1081 epw(out, interfunc_edges[i]);
BlockGraph Graph
Default control flow graph.
Default vertex property writer is a no-op.
void put_ast_node(Sawyer::Container::Graph< V, E > &cfg, size_t vertexId, AstNode *astNode)
Set the AST node associated with a vertex.
void write_graphviz(std::ostream &out, const CFG &cfg)
Write a CFG to a graphviz file, creating a cluster subgraph for each function.
Graph containing user-defined vertices and edges.
ROSE_UTIL_API std::string numberToString(long long)
Convert an integer to a string.
bool is_function_call(rose_addr_t &target_va, rose_addr_t &return_va)
Returns true if basic block appears to be a function call.
Base class for all binary analysis IR nodes.
Class for traversing the AST.
void apply_to_ast(const ControlFlowGraph &)
Applies graph to AST.
void set_cached_vertex(size_t)
Property: Cached vertex for control flow graphs.
Base class for machine instructions.
bool is_vertex_filtered(SgAsmNode *bb_or_insn, VertexFilter *filter)
Determines if a vertex is filtered out.
SgAsmBlock * get_entry_block() const
Function entry basic block.
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, boost::property< boost::vertex_name_t, SgAsmInstruction * > > InsnGraph
Default instruction-based control flow graph.
void set_successors_complete(bool)
Property: Whether the successors list is complete.
void explode_blocks(const BlockCFG &cfgb, InsnCFG &cfgi)
Create an instruction control flow graph from a basic block control flow graph.
const T & get_value_or(const Key &key, const T &dflt) const
Convenience for getting a value from an Option.
void set_parent(SgNode *parent)
All nodes in the AST contain a reference to a parent node.
List of things to work on.
ControlFlowGraph build_insn_cfg_from_ast(SgNode *root)
Builds a control flow graph for part of an AST.
Represents a synthesized function.
Sawyer::Container::Graph< V, E >::VertexValue get_ast_node(const Sawyer::Container::Graph< V, E > &cfg, size_t vertexId)
Return the AST node associated with a vertex.
ControlFlowGraph build_block_cfg_from_ast(SgNode *root)
Builds a control flow graph for part of an AST.
std::vector< typename boost::graph_traits< ControlFlowGraph >::vertex_descriptor > flow_order(const ControlFlowGraph &, typename boost::graph_traits< ControlFlowGraph >::vertex_descriptor start, std::vector< size_t > *reverse_order=NULL)
Orders nodes by depth first search reverse post order.
void write_graphviz(std::ostream &out, const CFG &cfg, const VertexPropertyWriter &vpw)
Write a CFG to a graphviz file, creating a cluster subgraph for each function.
ControlFlowGraph copy(const ControlFlowGraph &src)
Copies a graph while filtering.
boost::iterator_range< VertexIterator > vertices()
Iterators for all vertices.
Main namespace for the ROSE library.
void fixup_fcall_fret(InsnCFG &cfg, bool preserve_call_fallthrough_edges)
Fix up a CFG by changing function call and return edges.
void clear_ast(SgNode *ast)
Clears successor information from the AST.
T shift()
Remove and return the item from the front of the work list.
void set_edge_filter(EdgeFilter *filter)
Manipulate the edge filter.
bool push(const T &, boost::tribool check_uniqueness=boost::logic::indeterminate)
Add an item to the back of the work list.
Base class for integer values.
This class represents the base class for all IR nodes within Sage III.
ROSE_UTIL_API std::string addrToString(uint64_t value, size_t nbits=0)
Convert a virtual address to a string.
bool is_edge_filtered(SgAsmNode *src, SgAsmNode *dst)
Determines if an edge is filtered out.
ControlFlowGraph build_cg_from_ast(SgNode *root)
Builds a control flow graph with only function call edges.
const SgAsmIntegerValuePtrList & get_successors() const
Property: Control flow successors.
void makeRelativeTo(SgNode *baseNode)
Makes the value of this integer relative to some other addressable node.
bool has_instructions() const
Determins if a block contains instructions.
boost::adjacency_list< boost::setS, boost::vecS, boost::bidirectionalS, boost::property< boost::vertex_name_t, SgAsmBlock * > > BlockGraph
Default basic block control flow graph type.
VertexIterator findVertex(size_t id)
Finds the vertex with specified ID number.
VertexFilter * get_vertex_filter() const
Manipulate the vertex filter.
Represents one Intel x86 machine instruction.
Extends std::map with methods that return optional values.
rose_addr_t get_entry_va() const
Property: Primary entry address.
bool empty() const
Returns true if this work list is empty.
const SgAsmStatementPtrList & get_statementList() const
Property: Statements of which this block is composed.
std::vector< typename boost::graph_traits< ControlFlowGraph >::vertex_descriptor > return_blocks(const ControlFlowGraph &cfg, typename boost::graph_traits< ControlFlowGraph >::vertex_descriptor start)
Returns list of function return blocks.
bool is_edge_filtered(SgAsmNode *src, SgAsmNode *dst, EdgeFilter *filter)
Determines if an edge is filtered out.
Binary control flow analysis.
void write_graphviz(std::ostream &, const CFG &, const VertexPropertyWriter &, const EdgePropertyWriter &)
Write a CFG to a graphviz file, creating a cluster subgraph for each function.
Default edge property writer is a no-op.
V VertexValue
User-level data associated with vertices.
const T & get_one(const Key &key) const
Look up one value or throw an exception.
rose_addr_t get_address() const
Property: Starting virtual address.
uint64_t get_absoluteValue(size_t nbits=0) const
Returns the current absolute value zero filled to 64 bits.
bool is_vertex_filtered(SgAsmNode *bb_or_insn)
Determines if a vertex is filtered out.
const size_t INVALID_INDEX(-1)
Invalid array index.
void cache_vertex_descriptors(const ControlFlowGraph &)
Cache basic block vertex descriptors in AST.
List of vertices and intra-function edges for one function.
EdgeFilter * get_edge_filter() const
Manipulate the edge filter.
void set_vertex_filter(VertexFilter *filter)
Manipulate the vertex filter.