def _build_cfg(self, all_states): graph = CFGraph() for state in all_states: b = state.pc_initial graph.add_node(b) for state in all_states: for edge in state.outgoing_edges: graph.add_edge(state.pc_initial, edge.pc, 0) graph.set_entry_point(0) graph.process() self.cfgraph = graph
def from_adj_list(self, d, entry_point=0): """ Build a CFGraph class from a dict of adjacency lists. """ g = CFGraph() # Need to add all nodes before adding edges for node in d: g.add_node(node) for node, dests in d.items(): for dest in dests: g.add_edge(node, dest) return g
def compute_cfg_from_blocks(blocks): cfg = CFGraph() for k in blocks: cfg.add_node(k) for k, b in blocks.items(): term = b.terminator for target in term.get_targets(): cfg.add_edge(k, target) cfg.set_entry_point(min(blocks)) cfg.process() return cfg