forked from OSchip/llvm-project
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
This commit is contained in:
parent
03ac82edf5
commit
48342ee908
|
|
@ -15,6 +15,7 @@
|
||||||
#ifndef LLVM_SUPPORT_GCOV_H
|
#ifndef LLVM_SUPPORT_GCOV_H
|
||||||
#define LLVM_SUPPORT_GCOV_H
|
#define LLVM_SUPPORT_GCOV_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
|
|
@ -212,10 +213,12 @@ private:
|
||||||
SmallVector<uint32_t, 4> Lines;
|
SmallVector<uint32_t, 4> Lines;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SmallVector<uint64_t, 16> LineCounts;
|
typedef DenseMap<uint32_t, uint64_t> LineCounts;
|
||||||
class FileInfo {
|
class FileInfo {
|
||||||
public:
|
public:
|
||||||
void addLineCount(StringRef Filename, uint32_t Line, uint64_t Count);
|
void addLineCount(StringRef Filename, uint32_t Line, uint64_t Count) {
|
||||||
|
LineInfo[Filename][Line-1] = Count;
|
||||||
|
}
|
||||||
void print(StringRef gcnoFile, StringRef gcdaFile);
|
void print(StringRef gcnoFile, StringRef gcdaFile);
|
||||||
private:
|
private:
|
||||||
StringMap<LineCounts> LineInfo;
|
StringMap<LineCounts> LineInfo;
|
||||||
|
|
|
||||||
|
|
@ -235,24 +235,6 @@ void GCOVLines::dump() {
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// FileInfo implementation.
|
// 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.
|
/// print - Print source files with collected line count information.
|
||||||
void FileInfo::print(StringRef gcnoFile, StringRef gcdaFile) {
|
void FileInfo::print(StringRef gcnoFile, StringRef gcdaFile) {
|
||||||
for (StringMap<LineCounts>::iterator I = LineInfo.begin(), E = LineInfo.end();
|
for (StringMap<LineCounts>::iterator I = LineInfo.begin(), E = LineInfo.end();
|
||||||
|
|
@ -268,16 +250,22 @@ void FileInfo::print(StringRef gcnoFile, StringRef gcdaFile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
StringRef AllLines = Buff.take()->getBuffer();
|
StringRef AllLines = Buff.take()->getBuffer();
|
||||||
for (unsigned i = 0, e = L.size(); i != e; ++i) {
|
uint32_t i = 0;
|
||||||
if (L[i])
|
while (!AllLines.empty()) {
|
||||||
outs() << format("%9lu:", L[i]);
|
if (L.find(i) != L.end()) {
|
||||||
else
|
if (L[i] == 0)
|
||||||
|
outs() << " #####:";
|
||||||
|
else
|
||||||
|
outs() << format("%9lu:", L[i]);
|
||||||
|
} else {
|
||||||
outs() << " -:";
|
outs() << " -:";
|
||||||
|
}
|
||||||
std::pair<StringRef, StringRef> P = AllLines.split('\n');
|
std::pair<StringRef, StringRef> P = AllLines.split('\n');
|
||||||
if (AllLines != P.first)
|
if (AllLines != P.first)
|
||||||
outs() << format("%5u:", i+1) << P.first;
|
outs() << format("%5u:", i+1) << P.first;
|
||||||
outs() << "\n";
|
outs() << "\n";
|
||||||
AllLines = P.second;
|
AllLines = P.second;
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue