1 /* ControlFlowGraph.java */
2 package org.quilt.cl;
3
4 import java.util.HashMap;
5 import java.util.Map;
6 import org.apache.bcel.generic.InstructionList;
7 import org.quilt.graph.*;
8
9 /***
10 * Directed graph extended for use in analyzing method instruction
11 * lists.
12 *
13 * @author <a href="jddixon@users.sourceforge.net">Jim Dixon</a>
14 */
15 public class ControlFlowGraph extends Directed {
16
17 /*** Key code vertex, value handle on first instruction. */
18 protected Map startHandles = null;
19 /*** Key code vertex, value handle on last instruction. */
20 protected Map endHandles = null;
21 /*** Key source vertex, value target vertex where connecting
22 * instruction is GotoInstruction. */
23 protected Map gotoFixMeUps = null;
24 /*** Instruction list built in walking the graph. */
25 protected InstructionList ilist = null;
26
27 /*** Get a reference to the map of handles on first instructions. */
28 public Map getStartHandles() {
29 return startHandles;
30 }
31 /*** Get a reference to the map of handles on last instructions. */
32 public Map getEndHandles() {
33 return endHandles;
34 }
35 /*** Get a reference to the source/target vertex map where the
36 * connecting instruction is a GotoInstruction. */
37 public Map getGotoFixMeUps() {
38 return gotoFixMeUps;
39 }
40 /*** Get a reference to the instruction list built while walking the
41 * graph. */
42 public InstructionList getInstructionList() {
43 return ilist;
44 }
45
46 /*** Create a new top level control flow graph. */
47 public ControlFlowGraph () {
48 super();
49 startHandles = new HashMap();
50 endHandles = new HashMap();
51 gotoFixMeUps = new HashMap();
52 ilist = new InstructionList();
53 }
54 /***
55 * Create a control flow graph without connecting it to this
56 * parent graph but sharing protected data structures.
57 * @param parent The cfg one level up.
58 */
59 protected ControlFlowGraph( ControlFlowGraph parent) {
60 super(parent);
61 startHandles = parent.startHandles;
62 endHandles = parent.endHandles;
63 gotoFixMeUps = parent.gotoFixMeUps;
64 ilist = parent.ilist;
65 }
66 /***
67 * Create a control flow graph, connecting it to this graph as
68 * its parent by inserting it along the directed edge e (the
69 * Entry first, followed by the subgraph Exit.
70 *
71 * @param e Edge along which the subgraph is to be inserted.
72 * @param n Number of extra edges on the ComplexConnector in
73 * the subgraph's Entry vertex (must be at least 1).
74 */
75 public Directed subgraph (final Edge e, final int n) {
76 return super.connectSubgraph( new ControlFlowGraph(this), e, n);
77 }
78
79 /***
80 * Insert a code vertex along an edge, retargeting the edge to
81 * the vertex inserted. The vertex is created by this method.
82 *
83 * @param e Edge along which the vertex is inserted.
84 * @return The CodeVertex created.
85 */
86 public CodeVertex insertCodeVertex (Edge e) {
87 return (CodeVertex) super.insertVertex ( new CodeVertex(this), e);
88 }
89
90 /***
91 * Insert a pre-existing CodeVertex along an edge. The edge
92 * and the vertex must be in the same graph.
93 *
94 * @param v CodeVertex being inserted.
95 * @param e Edge in which it is to be inserted.
96 */
97 public CodeVertex insertCodeVertex (CodeVertex v, Edge e) {
98 return (CodeVertex) super.insertVertex (v, e);
99 }
100 }
This page was automatically generated by Maven