前面对debug测试出现的问题解决之后,现在通过分析debug信息来确定rose里面是如何利用数据流分析框架实现常量传播的。
测试代码入口:
int
main( int argc, char * argv[] )
{
printf("========== S T A R T ==========\n");
// Build the AST used by ROSE
SgProject* project = frontend(argc,argv);
initAnalysis(project);
Dbg::init("Divisibility Analysis Test", ".", "index.html");
liveDeadAnalysisDebugLevel = 1;
analysisDebugLevel = 1;
if (liveDeadAnalysisDebugLevel)
{
printf("*********************************************************************\n");
printf("***************** Constant Propagation Analysis *****************\n");
printf("*********************************************************************\n");
}
// liveness analysis is used to generate FiniteVarsExprsProductLattice only for live variables at a CFG point
// &ldva can be set to NULL then all visible variables and expressions will be used to generate FiniteVarsExprsProductLattice
LiveDeadVarsAnalysis ldva(project);
UnstructuredPassInterDataflow ciipd_ldva(&ldva);
ciipd_ldva.runAnalysis();
// prepare call graph
CallGraphBuilder cgb(project);
cgb.buildCallGraph();
SgIncidenceDirectedGraph* graph = cgb.getGraph();
// use constant propagation within the context insensitive interprocedural dataflow driver
analysisDebugLevel = 1;
ConstantPropagationAnalysis cpA(&ldva);
//ConstantPropagationAnalysis cpA(NULL);
ContextInsensitiveInterProceduralDataflow cpInter(&cpA, graph);
cpInter.runAnalysis();
}
以上代码分为以下四个步骤:
1.根据源文件构建AST树
2.初始化流图
3.对程序中的变量进行LiveDeadVarsAnalysis分析
4.再次读入源程序构建有函数调用的流图
5.根据3)分析的结果,以及4构建的流图进行上下文无关的程序间分析来得到常量传播信息。
由于现在先做出来一个程序内的框架,所以测试的代码不包括函数调用。
rose对LiveDeadVarsAnalysis的分析是自底向上的分析,对常量传播的分析是自顶向下的分析。