当我们获取到一个method的UnitGraph时,可以通过下面方法遍历CFG:
UnitGraph: g
List<Unit> ulist = g.getHeads();
Unit u = ulist.get(0);
while (!unitBelongList(u, g.getTails()))
{
EntityNode eNode = new EntityNode();
u = g.getSuccsOf(u).get(0);
Stmt stmt = (Stmt) u;
}
boolean unitBelongList(Unit u, List<Unit> g)
{
for(Unit i:g)
{
if(i.equals(u))
return true;
}
return false;
}