diff options
author | Yuchen Wu <yuchenericwu@hotmail.com> | 2013-10-23 19:45:03 +0000 |
---|---|---|
committer | Yuchen Wu <yuchenericwu@hotmail.com> | 2013-10-23 19:45:03 +0000 |
commit | 48342ee908aababa7ffda5a9e82b73fa96d965ee (patch) | |
tree | 7c473cbb1dd67c82d0c342acf4d8ccb2f43c95d0 /llvm/lib/IR/GCOV.cpp | |
parent | 03ac82edf5128f9e53b12ada34bfd41c63a24f94 (diff) | |
download | bcm5719-llvm-48342ee908aababa7ffda5a9e82b73fa96d965ee.tar.gz bcm5719-llvm-48342ee908aababa7ffda5a9e82b73fa96d965ee.zip |
Use a map instead of vector to store line counts.
There are a few motivations for this:
- Using a map allows for checking if line is in map. This differentiates
unexecutable lines (such as comments) from unexecuted logical lines of
code. "#####" is now outputted in this case, in line with gcov.
- Source files are no longer read in twice: once when storing the line
counts, and once when outputting the data.
- Greatly simplifies the function FileInfo::addLineCount().
llvm-svn: 193264
Diffstat (limited to 'llvm/lib/IR/GCOV.cpp')
-rw-r--r-- | llvm/lib/IR/GCOV.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/llvm/lib/IR/GCOV.cpp b/llvm/lib/IR/GCOV.cpp index f810d377755..68b91e6dc9a 100644 --- a/llvm/lib/IR/GCOV.cpp +++ b/llvm/lib/IR/GCOV.cpp @@ -235,24 +235,6 @@ void GCOVLines::dump() { //===----------------------------------------------------------------------===// // FileInfo implementation. -/// addLineCount - Add line count for the given line number in a file. -void FileInfo::addLineCount(StringRef Filename, uint32_t Line, uint64_t Count) { - if (LineInfo.find(Filename) == LineInfo.end()) { - OwningPtr<MemoryBuffer> Buff; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { - errs() << Filename << ": " << ec.message() << "\n"; - return; - } - StringRef AllLines = Buff.take()->getBuffer(); - LineCounts L(AllLines.count('\n')); - L[Line-1] = Count; - LineInfo[Filename] = L; - return; - } - LineCounts &L = LineInfo[Filename]; - L[Line-1] = Count; -} - /// print - Print source files with collected line count information. void FileInfo::print(StringRef gcnoFile, StringRef gcdaFile) { for (StringMap<LineCounts>::iterator I = LineInfo.begin(), E = LineInfo.end(); @@ -268,16 +250,22 @@ void FileInfo::print(StringRef gcnoFile, StringRef gcdaFile) { return; } StringRef AllLines = Buff.take()->getBuffer(); - for (unsigned i = 0, e = L.size(); i != e; ++i) { - if (L[i]) - outs() << format("%9lu:", L[i]); - else + uint32_t i = 0; + while (!AllLines.empty()) { + if (L.find(i) != L.end()) { + if (L[i] == 0) + outs() << " #####:"; + else + outs() << format("%9lu:", L[i]); + } else { outs() << " -:"; + } std::pair<StringRef, StringRef> P = AllLines.split('\n'); if (AllLines != P.first) outs() << format("%5u:", i+1) << P.first; outs() << "\n"; AllLines = P.second; + ++i; } } } |