int main(int argc, char *argv[]) { SgProject* sageProject = frontend(argc,argv); AstTests::runAllTests(sageProject); Rose_STL_Container <SgNode*> functions = NodeQuery::querySubTree(sageProject, V_SgFunctionDefinition); for (Rose_STL_Container <SgNode*>::const_iterator i = functions.begin(); i != functions.end(); ++i) { SgFunctionDefinition* proc = isSgFunctionDefinition(*i); ROSE_ASSERT (proc); string file_name = StringUtility::stripPathFromFileName(proc->get_file_info()->get_filename()); string file_func_name= file_name+ "_"+proc->get_mangled_name().getString(); string full_output = file_func_name +"_scfg.dot"; // Full CFG graph StaticCFG::CFG cfg(proc); cfg.buildFullCFG(); cfg.cfgToDot(proc, full_output); #if 0 // not ready string simple_output = file_func_name +"_simple_vcfg.dot"; std::ofstream simplegraph(simple_output.c_str()); // Simplified CFG suitable for most analyses // This will cause assertion failure //StaticCFG::cfgToDot(simplegraph, proc->get_declaration()->get_name(), StaticCFG::makeInterestingCfg(proc)); // This will generate identical graph as cfgToDotForDebugging () StaticCFG::cfgToDot(simplegraph, proc->get_declaration()->get_name(), proc->cfgForBeginning()); #endif } return 0; }
void CFG::buildFullCFG() { // Before building a new CFG, make sure to clear all nodes built before. all_nodes_.clear(); clearNodesAndEdges(); std::set<VirtualCFG::CFGNode> explored; graph_ = new SgIncidenceDirectedGraph; if (SgProject* project = isSgProject(start_)) { Rose_STL_Container<SgNode*> functions = NodeQuery::querySubTree(project, V_SgFunctionDefinition); for (Rose_STL_Container<SgNode*>::const_iterator i = functions.begin(); i != functions.end(); ++i) { SgFunctionDefinition* proc = isSgFunctionDefinition(*i); if (proc) { buildCFG<VirtualCFG::CFGNode, VirtualCFG::CFGEdge> (proc->cfgForBeginning(), all_nodes_, explored); } } } else buildCFG<VirtualCFG::CFGNode, VirtualCFG::CFGEdge> (start_->cfgForBeginning(), all_nodes_, explored); }
int main(int argc, char * argv[]) { // Build the AST used by ROSE project = frontend(argc,argv); /*convertToOMPNormalForm(project, project); // Run internal consistancy tests on AST AstTests::runAllTests(project); Rose_STL_Container<SgNode*> functions = NodeQuery::querySubTree(project, V_SgFunctionDefinition); for (Rose_STL_Container<SgNode*>::const_iterator i = functions.begin(); i != functions.end(); ++i) { SgFunctionDefinition* func = isSgFunctionDefinition(*i); ROSE_ASSERT(func); printf("func = %s\n", func->unparseToString().c_str()); // output the CFG to a file ofstream fileCFG; fileCFG.open((func->get_declaration()->get_name().getString()+"_cfg.dot").c_str()); cout << " writing to file "<<(func->get_declaration()->get_name().getString()+"_cfg.dot")<<"\n"; cfgToDot(fileCFG, func->get_declaration()->get_name(), func->cfgForBeginning()); fileCFG.close(); } backend(project);*/ //generatePDF ( *project ); // find a declaration for foo() Rose_STL_Container<SgNode*> funcDecls = NodeQuery::querySubTree(project, V_SgFunctionDeclaration); for(Rose_STL_Container<SgNode*>::iterator it = funcDecls.begin(); it!=funcDecls.end(); it++) { SgFunctionDeclaration* decl = isSgFunctionDeclaration(*it); ROSE_ASSERT(decl); if(decl->get_name().getString() == "foo") { fooDecl = decl; break; } } if(!fooDecl) { printf("ERROR: could not find declaration of function foo()!\n"); numFails++; } testParsing(); convertToOMPNormalForm(project, project); testOMPForSensitiveInsertion(); AstTests::runAllTests(project); insertTopBottomOmpDirectives(project, ompUtils::omp_critical, true, &fooCallStmtCreate); insertTopBottomOmpDirectives(project, ompUtils::omp_single, false, &fooCallStmtCreate); // Run internal consistancy tests on AST // // Generate the CFGs of all the functions to ensure that all CFG data is good Rose_STL_Container<SgNode*> functions = NodeQuery::querySubTree(project, V_SgFunctionDefinition); for (Rose_STL_Container<SgNode*>::const_iterator i = functions.begin(); i != functions.end(); ++i) { SgFunctionDefinition* func = isSgFunctionDefinition(*i); ROSE_ASSERT(func); printf("func = %s\n", func->unparseToString().c_str()); // output the CFG to a file ofstream fileCFG; fileCFG.open((func->get_declaration()->get_name().getString()+"_cfg.dot").c_str()); cout << " writing to file "<<(func->get_declaration()->get_name().getString()+"_cfg.dot")<<"\n"; cfgToDot(fileCFG, func->get_declaration()->get_name(), func->cfgForBeginning()); fileCFG.close(); } backend(project); system("diff rose_test_example.c test_example.valid_rose_output.c > selfTest.out"); struct stat file; stat("selfTest.out",&file); if(file.st_size!=0) { printf("Error: found differences between rose_test_example.c and the canonical test_example.valid_rose_output.c! Details in selfTest.out.\n"); numFails++; } if(numFails==0) cout << "PASSED\n"; else cout << "FAILED!\n"; }