InterFlow CFAnalysis::interFlow(Flow& flow) { // 1) for each call use AST information to find its corresponding called function // 2) create a set of <call,entry,exit,callreturn> edges cout<<"STATUS: establishing inter-flow ..."<<endl; InterFlow interFlow; LabelSet callLabs=functionCallLabels(flow); int callLabsNum=callLabs.size(); cout << "INFO: number of function call labels: "<<callLabsNum<<endl; int callLabNr=0; for(LabelSet::iterator i=callLabs.begin();i!=callLabs.end();++i) { //cout<<"INFO: resolving function call "<<callLabNr<<" of "<<callLabsNum<<endl; SgNode* callNode=getNode(*i); //cout<<"INFO: creating inter-flow for "<<callNode->unparseToString(); //info: callNode->get_args() SgFunctionCallExp *funCall=SgNodeHelper::Pattern::matchFunctionCall(callNode); if(!funCall) throw SPRAY::Exception("interFlow: unknown call exp (not a SgFunctionCallExp)"); SgFunctionDefinition* funDef=SgNodeHelper::determineFunctionDefinition(funCall); Label callLabel,entryLabel,exitLabel,callReturnLabel; if(funDef==0) { //cout<<" [no definition found]"<<endl; // we were not able to find the funDef in the AST //cout << "STATUS: External function "; //if(SgFunctionDeclaration* funDecl=funCall->getAssociatedFunctionDeclaration()) // cout << SgNodeHelper::getFunctionName(funDecl)<<"."<<endl; //else // cout << "cannot be determined."<<endl; callLabel=*i; entryLabel=Labeler::NO_LABEL; exitLabel=Labeler::NO_LABEL; callReturnLabel=labeler->functionCallReturnLabel(callNode); //cout <<"No function definition found for call: "<<funCall->unparseToString()<<endl; } else { //cout<<" [definition found]"<<endl; callLabel=*i; entryLabel=labeler->functionEntryLabel(funDef); exitLabel=labeler->functionExitLabel(funDef); callReturnLabel=labeler->functionCallReturnLabel(callNode); } interFlow.insert(InterEdge(callLabel,entryLabel,exitLabel,callReturnLabel)); callLabNr++; } cout<<"STATUS: inter-flow established."<<endl; return interFlow; }
InterFlow CFAnalyzer::interFlow(Flow& flow) { // 1) for each call use AST information to find its corresponding called function // 2) create a set of <call,entry,exit,callreturn> edges InterFlow interFlow; LabelSet callLabs=functionCallLabels(flow); //cout << "calllabs: "<<callLabs.size()<<endl; for(LabelSet::iterator i=callLabs.begin();i!=callLabs.end();++i) { SgNode* callNode=getNode(*i); //info: callNode->get_args() SgFunctionCallExp *funCall=SgNodeHelper::Pattern::matchFunctionCall(callNode); if(!funCall) throw "Error: interFlow: unkown call exp (not a SgFunctionCallExp)."; SgFunctionDefinition* funDef=SgNodeHelper::determineFunctionDefinition(funCall); Label callLabel,entryLabel,exitLabel,callReturnLabel; if(funDef==0) { // we were not able to find the funDef in the AST cout << "STATUS: External function "; if(SgFunctionDeclaration* funDecl=funCall->getAssociatedFunctionDeclaration()) cout << SgNodeHelper::getFunctionName(funDecl)<<"."<<endl; else cout << "cannot be determined."<<endl; callLabel=*i; entryLabel=Labeler::NO_LABEL; exitLabel=Labeler::NO_LABEL; callReturnLabel=labeler->functionCallReturnLabel(callNode); } else { callLabel=*i; entryLabel=labeler->functionEntryLabel(funDef); exitLabel=labeler->functionExitLabel(funDef); callReturnLabel=labeler->functionCallReturnLabel(callNode); } interFlow.insert(InterEdge(callLabel,entryLabel,exitLabel,callReturnLabel)); } return interFlow; }