Пример #1
0
void visitorTraversal::analyzePath(vector<VertexID>& pth) {
    std::vector<VertexID> pathR = pth;
    std::vector<SgGraphNode*> path;
    for (unsigned int j = 0; j < pathR.size(); j++) {
        SgGraphNode* R = (*orig)[pathR[j]].sg;
        path.push_back(R);
    }
    for (unsigned int k = 0; k < path.size(); k++) {
        if (isSgFunctionRefExp(path[k]->get_SgNode())) {
            SgFunctionRefExp* sfrd = isSgFunctionRefExp(path[k]->get_SgNode());
            SgFunctionDeclaration* fd = sfrd->getAssociatedFunctionDeclaration();
            fd = isSgFunctionDeclaration(fd->get_definingDeclaration());
            assert(fd!=NULL);
            SgFunctionDefinition* fdd = fd->get_definition();
            SgName sname = fdd->get_mangled_name();
            string sn = sname.getString();
            if (find(defstr.begin(), defstr.end(), sn) == defstr.end()) {
                defstr.push_back(sn);
                defs.push_back(fdd);
                std::cout << "found new sn: " << sn << std::endl;
            }
            else {
                std::cout << "found old sn: " << sn << std::endl;
            }
        }
    }
#pragma omp atomic
    paths++;
}
Пример #2
0
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;
}
Пример #3
0
 void IntraAnalysisResultsToDotFiles::runAnalysis()
 {
   set<FunctionState*> allFuncs = FunctionState::getAllDefinedFuncs();
   // Go through functions one by one, call an intra-procedural analysis on each of them
   // iterate over all functions with bodies
   for(set<FunctionState*>::iterator it=allFuncs.begin(); it!=allFuncs.end(); it++)
   {
 
     FunctionState* fState = *it;
     // compose the output file name as filename_mangled_function_name.dot
     Function *func = & (fState->getFunc());
     assert (func != NULL);
     SgFunctionDefinition* proc = func->get_definition();
     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 +"_cfg.dot";
     std::ofstream ostr(full_output.c_str());
 
     ostr << "digraph " << "mygraph" << " {\n";
     analysisStatesToDOT* dot_analysis = dynamic_cast <analysisStatesToDOT*> ( intraAnalysis);
     assert (dot_analysis != NULL);
     dot_analysis->ostr = &ostr;
     dot_analysis->runAnalysis(fState->func, &(fState->state));
     ostr << "}\n";
   }
 
 }