Ejemplo n.º 1
0
RangeAnalysis::RangeAnalysis(Function &F){
	//TO DO: Figure this out.
//	top = RangeFlowSet(Flow::TOP);//Should be changed by subclasses of Flow to an instance of the subclass
//	bottom = RangeFlowSet(Flow::BOTTOM);//Should be changed by subclasses of Flow to an instance of the subclass
	this->top = new RangeFlowSet;
	this->bottom = new RangeFlowSet;
	this->functionName = F.getName();
	buildCFG(F);
}
Ejemplo n.º 2
0
//Build CFG for each procedure
void DesignExtractor::computeCFG(){
/*
	int numOfProc = procTable->getNoOfProc();
	//CFG cfg = CFG(ast, follows, parent);
	for(int i=0; i<numOfProc; i++){
		//buildCFG(procTable->getFirstStmt(procTable->getProcName(i)), procTable->getLastStmt(procTable->getProcName(i)));
		CFG * cfg = new CFG(Graph,Block);
		procTable->insertCFG(procTable->getProcName(i), cfg);
	}
*/
	//starting with the program node, we look at each child of program node
	INDEX root = ast->getRoot();
	int numOfProc = ast->getNoOfChild(ast->getNode(root));
	CFG * cfg = new CFG(storeRootWhile, storeRootIf);
	vector<std::pair<int,int>> * graph = new vector<std::pair<int,int>>();
	PROCLIST procList = procTable->getAllProcNames();
	
	//init graph
	std::pair<int,int> a_pair (0,0);
	for(int i = 0; i <= procTable->getLastStmt(*(procList.end()-1)); ++i){
		graph->push_back(a_pair);
	}
	for(int i = 0; i < numOfProc; ++i){
		TNode currProc = ast->getChild(ast->getNode(root), i);
		buildCFG(currProc, graph);
		
		
	}
	//TODO create cfg and insert into proc table
	int numOfProcs = procTable->getNoOfProc();
	for(int i=0; i<numOfProcs; i++){		
		CFG * cfg = new CFG(graph, procTable->getFirstStmt(procTable->getProcName(i)), procTable->getLastStmt(procTable->getProcName(i)), storeRootWhile, storeRootIf);
		procTable->insertCFG(procTable->getProcName(i), cfg);
	}
	
	//print out graph
	for(int i = 0; i < graph->size(); ++i){
		cout << i << "->" << graph->at(i).first << ", " << graph->at(i).second << endl;
	}
	
	//system("PAUSE");
}
Ejemplo n.º 3
0
void DesignExtractor::buildCFG(TNode currNode, vector<std::pair<int,int>> * graph){
	int nodeType = currNode.getNodeType();
	vector<int> children = currNode.getChildren();	
	vector<std::pair<int,int>>::iterator it = graph->begin();
	int currStmtNum = currNode.getStmtNumber();
	switch(nodeType){
		case PROCEDURE:
		{
			//go into statement list
			buildCFG(ast->getChild(currNode, 0), graph);
			//set end nodes
			setEndNode(graph);
			break;
		}
		case STMT_LST:
		{
			//for each node of stmtLst visit it
			for(int i = 0; i < children.size(); ++i){
				buildCFG(ast->getChild(currNode, i), graph);
			}
			break;
		}
		case CALL:
		case ASSIGN:
		{
			//first we check if we can find follows, otherwise find a parent's follows.
			STMT followStmtNum = follows->getFollows(1,currStmtNum);
			if(followStmtNum == -1) {
				graph->at(currStmtNum).first = findLoopback(currStmtNum);
				if(graph->at(currStmtNum).first == 0)
					graph->at(currStmtNum).first = findFollows(currStmtNum);
			}
			else{
				graph->at(currStmtNum).first = followStmtNum;
			}
			return;
			break;
		}
		case WHILE:
		{
			//connect to first stmt of my stmtLst
			STMT firstStmtNum = ast->getChild(ast->getChild(currNode, 1), 0).getStmtNumber();
			graph->at(currStmtNum).first = firstStmtNum;
			//first we check if we can find follows, otherwise find a parent's follows.
			STMT followStmtNum = follows->getFollows(1,currStmtNum);
			if(followStmtNum == -1) {
				graph->at(currStmtNum).second = findLoopback(currStmtNum);
				if(graph->at(currStmtNum).second == 0)
					graph->at(currStmtNum).second = findFollows(currStmtNum);
			}
			else{
				graph->at(currStmtNum).second = followStmtNum;
			}
			// call buildCFG again on the stmtLst
			buildCFG(ast->getChild(currNode, 1), graph);
			break;
		}
		case IF:
		{
			//connect to first stmt of then stmtLst
			TNode thenNode = ast->getChild(currNode, 1);
			STMT thenStmtNum = ast->getChild(thenNode, 0).getStmtNumber();
			graph->at(currStmtNum).first = thenStmtNum;
			//connect to first stmt of else stmtLst
			TNode elseNode = ast->getChild(currNode, 2);
			STMT elseStmtNum = ast->getChild(elseNode, 0).getStmtNumber();
			graph->at(currStmtNum).second = elseStmtNum;
			//call buildCFG of then
			buildCFG(thenNode, graph);
			//call buildCFG of else
			buildCFG(elseNode, graph);
			break;
		}
		default:
			break;
	}
}
Ejemplo n.º 4
0
 foreach (const VirtualCFG::CFGEdge& edge, inEdges)
 {
     ROSE_ASSERT(edge.target() == n);
     buildCFG(edge.source());
 }