rose编译器实现了龙书上的经典数据流分析框架,基于该框架实现以下功能:
1)常量传播
2)活性变量分析
3)常量的符号量分析
目前测试的是常量传播基础设施功能,测试代码位置:
\rose\tests\roseTests\programAnalysisTests\generalDataFlowAnalysisTests\
测试代码入口:
int
main( int argc, char * argv[] )
{
printf("========== S T A R T ==========\n");
// Build the AST used by ROSE 根据文件创建AST树
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();
// verify the results
evaluateAnalysisStates eas(&cpA, " ");
UnstructuredPassInterAnalysis upia_eas(eas);
upia_eas.runAnalysis();
算法步骤:
1.首先进行流图的LiveDeadVarsAnalysis分析
2,根据1的分析结果使用上下文无关的过程间分析来得到流图的常量传播
目前需要实现的目标是实现数组的local分析,所以格的位置应该是数组的范围。对于上下文无关过程间分析太过复杂,所以先做过程内的分析,需要分析的主要是对实现LiveDeadVarsAnalysis功能的分析。
在下一篇对UnstructuredPassInterDataflow这个类进行分析。