demo.cpp
/* Print source code of a loop.
 */
Print source code of a loop.
Print source code of a loop .
void Support::printLoopSrcCode(Loop *pLoop)
{
	int minlinenumber  = 0xfffffff;
	int maxlinenumber  = 0;
	string sFileName = "";
	for (Loop::block_iterator BI = pLoop->block_begin(); BI != pLoop->block_end(); BI++) {
		BasicBlock *BB = *BI;
		for (BasicBlock::iterator II = BB->begin(); II != BB->end(); II++) {
			Instruction *I = &*II;
			const DILocation * DIL = I->getDebugLoc();
			if(!DIL){
				continue;
			}else{
				char pPath[200];
				if(sFileName == ""){
					if(DIL->getFilename().str().substr(0,5) == "/home"){
						sFileName = DIL->getFilename().str();
					}else{
						sFileName = DIL->getDirectory().str() + "/" + DIL->getFilename().str();
					}
					realpath(sFileName.c_str(), pPath);
					sFileName = string(sFileName);
				}
				unsigned int numLine = DIL->getLine();
				if(numLine < minlinenumber){
					minlinenumber = numLine;
				}
				if(numLine > maxlinenumber){
					maxlinenumber = numLine;
				}
			}
		}
	}
    errs()<< "--------------------------Source code:-----------------------------" << "\n";
	string lines = ReadLine( sFileName.c_str(), minlinenumber, maxlinenumber);
    errs()<< lines << "\n";
	errs()<< "-------------------------SRC Code end:-----------------------------" << "\n";
	return;
}
void Support :: printLoopSrcCode ( Loop * pLoop ) { int minlinenumber = 0xfffffff ; int maxlinenumber = 0 ; string sFileName = " " ; for ( Loop :: block_iterator BI = pLoop -> block_begin ( ) ; BI != pLoop -> block_end ( ) ; BI ++ ) { BasicBlock * BB = * BI ; for ( BasicBlock :: iterator II = BB -> begin ( ) ; II != BB -> end ( ) ; II ++ ) { Instruction * I = & * II ; const DILocation * DIL = I -> getDebugLoc ( ) ; if ( ! DIL ) { continue ; } else { char pPath [ 200 ] ; if ( sFileName == " " ) { if ( DIL -> getFilename ( ) . str ( ) . substr ( 0 , 5 ) == " " ) { sFileName = DIL -> getFilename ( ) . str ( ) ; } else { sFileName = DIL -> getDirectory ( ) . str ( ) + " " + DIL -> getFilename ( ) . str ( ) ; } realpath ( sFileName . c_str ( ) , pPath ) ; sFileName = string ( sFileName ) ; } unsigned int numLine = DIL -> getLine ( ) ; if ( numLine < minlinenumber ) { minlinenumber = numLine ; } if ( numLine > maxlinenumber ) { maxlinenumber = numLine ; } } } } errs ( ) << " " << " \n " ; string lines = ReadLine ( sFileName . c_str ( ) , minlinenumber , maxlinenumber ) ; errs ( ) << lines << " \n " ; errs ( ) << " " << " \n " ; return ; }
Print source code of a loop.
Print source code of a loop .
//errs() << "//---" << sFileName << ": " << numLine << "\n";