5 #include <AD/visualize/vcg.h>
11 class VisualizeCFG
: public VCG
16 VisualizeCFG
& Start(const char * bb
)
17 { begin_node(bb
); label("START"); color(lightblue
);
18 shape(ellipse
); end_node(bb
); return *this;
21 VisualizeCFG
& Stop(const char * bb
)
22 { begin_node(bb
); label("STOP"); color(lightblue
);
23 shape(ellipse
); end_node(bb
); return *this;
26 VisualizeCFG
& Compute(const char * bb
,const char * code
)
27 { begin_node(bb
); label(code
); color(lightgreen
); end_node(bb
);
31 VisualizeCFG
& Test(const char * bb
, const char * test
)
32 { begin_node(bb
); label(test
); color(lightyellow
);
33 shape(rhomb
); end_node(bb
); return *this;
36 VisualizeCFG
& TrueBranch(const char * a
, const char * b
)
37 { begin_edge(a
,b
); label("true"); end_edge(a
,b
); return *this; }
39 VisualizeCFG
& BackTrueBranch(const char * a
, const char * b
)
40 { begin_backedge(a
,b
); label("true"); end_edge(a
,b
); return *this; }
42 VisualizeCFG
& FalseBranch(const char * a
, const char * b
)
43 { begin_edge(a
,b
); label("false"); end_edge(a
,b
); return *this; }
45 VisualizeCFG
& BackFalseBranch(const char * a
, const char * b
)
46 { begin_backedge(a
,b
); label("false"); end_edge(a
,b
); return *this; }
48 VisualizeCFG
& Jump(const char * a
, const char * b
)
49 { begin_edge(a
,b
); end_edge(a
,b
); return *this; }
51 VisualizeCFG
& BackJump(const char * a
, const char * b
)
52 { begin_backedge(a
,b
); end_edge(a
,b
); return *this; }
54 VisualizeCFG
& BeginRegion(const char * r
, const char * l
)
55 { begin_graph(r
); label(l
); color(lightgreen
);
58 VisualizeCFG
& EndRegion(const char * r
)
68 const char * G
= "A Sample Graph";
72 const char * d1
= "d1";
73 const char * d2
= "d2";
74 const char * d3
= "d3";
75 const char * d4
= "d4";
83 V
. begin_graph(G
) . label(G
) . display_edge_labels(true)
84 . layoutalgorithm(VCG::minbackward
)
85 . xspace(40) . yspace(40);
87 // Create a sample CFG
90 . Compute(b
,"x := y + z;\nq := r * s;")
94 . BeginRegion(r
,"sub region")
98 . Compute(d2
,"x := x + 1;\ny := y / z;\nq := q[0];")
99 . Compute(d3
,"x := x - 1;\ny := y / z;\nq := q[1];")
102 . Compute(d4
,"y := y + x;\nx := z + 1;")
105 . Compute(e
,"x := x - 2;\nz := x * x;\nq : = q/z;")
110 . BackFalseBranch(f
,b
)
115 // translate it into GDL
118 ofstream
TMP("./cfg.vcg");
121 system("xvcg ./cfg.vcg");