X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FGCOV.cpp;h=1667401f88d0c1bed672d21e530a65d5541ad83b;hb=c636a42d4a72e8f6017298787b07a6ef0019bed8;hp=05fe1e07dfda69be595df2e6a1ff1abd8246ae82;hpb=56d05e468cdfd4ad195f264974f1b841bc4ca785;p=oota-llvm.git diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp index 05fe1e07dfd..1667401f88d 100644 --- a/lib/IR/GCOV.cpp +++ b/lib/IR/GCOV.cpp @@ -19,8 +19,8 @@ #include "llvm/Support/Format.h" #include "llvm/Support/MemoryObject.h" #include "llvm/Support/Path.h" -#include "llvm/Support/system_error.h" #include +#include using namespace llvm; //===----------------------------------------------------------------------===// @@ -432,6 +432,34 @@ static raw_ostream &operator<<(raw_ostream &OS, const formatBranchInfo &FBI) { return OS; } +namespace { +class LineConsumer { + std::unique_ptr Buffer; + StringRef Remaining; +public: + LineConsumer(StringRef Filename) { + ErrorOr> BufferOrErr = + MemoryBuffer::getFileOrSTDIN(Filename); + if (std::error_code EC = BufferOrErr.getError()) { + errs() << Filename << ": " << EC.message() << "\n"; + Remaining = ""; + } else { + Buffer = std::move(BufferOrErr.get()); + Remaining = Buffer->getBuffer(); + } + } + bool empty() { return Remaining.empty(); } + void printNext(raw_ostream &OS, uint32_t LineNum) { + StringRef Line; + if (empty()) + Line = "/*EOF*/"; + else + std::tie(Line, Remaining) = Remaining.split("\n"); + OS << format("%5u:", LineNum) << Line << "\n"; + } +}; +} + /// Convert a path to a gcov filename. If PreservePaths is true, this /// translates "/" to "#", ".." to "^", and drops ".", to match gcov. static std::string mangleCoveragePath(StringRef Filename, bool PreservePaths) { @@ -487,14 +515,14 @@ std::string FileInfo::getCoveragePath(StringRef Filename, std::unique_ptr FileInfo::openCoveragePath(StringRef CoveragePath) { if (Options.NoOutput) - return make_unique(); + return llvm::make_unique(); std::string ErrorInfo; - auto OS = make_unique(CoveragePath.str().c_str(), ErrorInfo, - sys::fs::F_Text); + auto OS = llvm::make_unique(CoveragePath.str().c_str(), + ErrorInfo, sys::fs::F_Text); if (!ErrorInfo.empty()) { errs() << ErrorInfo << "\n"; - return make_unique(); + return llvm::make_unique(); } return std::move(OS); } @@ -505,12 +533,7 @@ void FileInfo::print(StringRef MainFilename, StringRef GCNOFile, for (StringMap::const_iterator I = LineInfo.begin(), E = LineInfo.end(); I != E; ++I) { StringRef Filename = I->first(); - std::unique_ptr Buff; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { - errs() << Filename << ": " << ec.message() << "\n"; - return; - } - StringRef AllLines = Buff->getBuffer(); + auto AllLines = LineConsumer(Filename); std::string CoveragePath = getCoveragePath(Filename, MainFilename); std::unique_ptr S = openCoveragePath(CoveragePath); @@ -524,7 +547,8 @@ void FileInfo::print(StringRef MainFilename, StringRef GCNOFile, const LineData &Line = I->second; GCOVCoverage FileCoverage(Filename); - for (uint32_t LineIndex = 0; !AllLines.empty(); ++LineIndex) { + for (uint32_t LineIndex = 0; + LineIndex < Line.LastLine || !AllLines.empty(); ++LineIndex) { if (Options.BranchInfo) { FunctionLines::const_iterator FuncsIt = Line.Functions.find(LineIndex); if (FuncsIt != Line.Functions.end()) @@ -535,9 +559,7 @@ void FileInfo::print(StringRef MainFilename, StringRef GCNOFile, if (BlocksIt == Line.Blocks.end()) { // No basic blocks are on this line. Not an executable line of code. OS << " -:"; - std::pair P = AllLines.split('\n'); - OS << format("%5u:", LineIndex+1) << P.first << "\n"; - AllLines = P.second; + AllLines.printNext(OS, LineIndex + 1); } else { const BlockVector &Blocks = BlocksIt->second; @@ -599,9 +621,7 @@ void FileInfo::print(StringRef MainFilename, StringRef GCNOFile, } ++FileCoverage.LogicalLines; - std::pair P = AllLines.split('\n'); - OS << format("%5u:", LineIndex+1) << P.first << "\n"; - AllLines = P.second; + AllLines.printNext(OS, LineIndex + 1); uint32_t BlockNo = 0; uint32_t EdgeNo = 0;