2013-12-05 22:02:29 +00:00
|
|
|
//===- GCOV.h - LLVM coverage tool ----------------------------------------===//
|
2011-09-28 18:50:00 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2013-12-05 22:02:29 +00:00
|
|
|
// This header provides the interface to read and write coverage files that
|
2011-10-04 17:24:48 +00:00
|
|
|
// use 'gcov' format.
|
2011-09-28 18:50:00 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_SUPPORT_GCOV_H
|
|
|
|
#define LLVM_SUPPORT_GCOV_H
|
2011-09-28 18:50:00 +00:00
|
|
|
|
2013-10-23 19:45:03 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2013-12-19 00:29:25 +00:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2011-09-28 18:50:00 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
2015-01-23 22:57:02 +00:00
|
|
|
#include "llvm/ADT/iterator.h"
|
2011-09-28 18:50:00 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class GCOVFunction;
|
|
|
|
class GCOVBlock;
|
|
|
|
class FileInfo;
|
|
|
|
|
2012-08-31 17:31:28 +00:00
|
|
|
namespace GCOV {
|
2015-01-23 22:38:01 +00:00
|
|
|
enum GCOVVersion { V402, V404 };
|
2012-08-31 17:31:28 +00:00
|
|
|
} // end GCOV namespace
|
2011-09-28 18:50:00 +00:00
|
|
|
|
2013-12-10 01:02:07 +00:00
|
|
|
/// GCOVOptions - A struct for passing gcov options between functions.
|
|
|
|
struct GCOVOptions {
|
2014-05-07 02:11:18 +00:00
|
|
|
GCOVOptions(bool A, bool B, bool C, bool F, bool P, bool U, bool L, bool N)
|
2014-02-04 10:45:02 +00:00
|
|
|
: AllBlocks(A), BranchInfo(B), BranchCount(C), FuncCoverage(F),
|
2014-05-07 02:11:18 +00:00
|
|
|
PreservePaths(P), UncondBranch(U), LongFileNames(L), NoOutput(N) {}
|
2013-12-16 22:14:02 +00:00
|
|
|
|
2013-12-10 01:02:07 +00:00
|
|
|
bool AllBlocks;
|
2013-12-18 18:40:15 +00:00
|
|
|
bool BranchInfo;
|
|
|
|
bool BranchCount;
|
2013-12-19 00:29:25 +00:00
|
|
|
bool FuncCoverage;
|
2014-02-04 10:45:02 +00:00
|
|
|
bool PreservePaths;
|
2013-12-16 22:14:02 +00:00
|
|
|
bool UncondBranch;
|
2014-04-23 21:44:55 +00:00
|
|
|
bool LongFileNames;
|
2014-05-07 02:11:18 +00:00
|
|
|
bool NoOutput;
|
2013-12-10 01:02:07 +00:00
|
|
|
};
|
|
|
|
|
2011-09-29 16:52:53 +00:00
|
|
|
/// GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific
|
2011-09-28 18:50:00 +00:00
|
|
|
/// read operations.
|
|
|
|
class GCOVBuffer {
|
|
|
|
public:
|
|
|
|
GCOVBuffer(MemoryBuffer *B) : Buffer(B), Cursor(0) {}
|
2015-01-23 22:38:01 +00:00
|
|
|
|
2013-12-04 04:49:23 +00:00
|
|
|
/// readGCNOFormat - Check GCNO signature is valid at the beginning of buffer.
|
|
|
|
bool readGCNOFormat() {
|
|
|
|
StringRef File = Buffer->getBuffer().slice(0, 4);
|
|
|
|
if (File != "oncg") {
|
|
|
|
errs() << "Unexpected file type: " << File << ".\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor = 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// readGCDAFormat - Check GCDA signature is valid at the beginning of buffer.
|
|
|
|
bool readGCDAFormat() {
|
|
|
|
StringRef File = Buffer->getBuffer().slice(0, 4);
|
|
|
|
if (File != "adcg") {
|
|
|
|
errs() << "Unexpected file type: " << File << ".\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor = 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// readGCOVVersion - Read GCOV version.
|
|
|
|
bool readGCOVVersion(GCOV::GCOVVersion &Version) {
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef VersionStr = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
2013-12-04 04:49:23 +00:00
|
|
|
if (VersionStr == "*204") {
|
|
|
|
Cursor += 4;
|
|
|
|
Version = GCOV::V402;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (VersionStr == "*404") {
|
|
|
|
Cursor += 4;
|
|
|
|
Version = GCOV::V404;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
errs() << "Unexpected version: " << VersionStr << ".\n";
|
|
|
|
return false;
|
2011-09-28 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// readFunctionTag - If cursor points to a function tag then increment the
|
|
|
|
/// cursor and return true otherwise return false.
|
|
|
|
bool readFunctionTag() {
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef Tag = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
|
|
|
if (Tag.empty() || Tag[0] != '\0' || Tag[1] != '\0' || Tag[2] != '\0' ||
|
|
|
|
Tag[3] != '\1') {
|
2011-09-28 18:50:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor += 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// readBlockTag - If cursor points to a block tag then increment the
|
|
|
|
/// cursor and return true otherwise return false.
|
|
|
|
bool readBlockTag() {
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef Tag = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
|
|
|
if (Tag.empty() || Tag[0] != '\0' || Tag[1] != '\0' || Tag[2] != '\x41' ||
|
|
|
|
Tag[3] != '\x01') {
|
2011-09-28 18:50:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor += 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// readEdgeTag - If cursor points to an edge tag then increment the
|
|
|
|
/// cursor and return true otherwise return false.
|
|
|
|
bool readEdgeTag() {
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef Tag = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
|
|
|
if (Tag.empty() || Tag[0] != '\0' || Tag[1] != '\0' || Tag[2] != '\x43' ||
|
|
|
|
Tag[3] != '\x01') {
|
2011-09-28 18:50:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor += 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// readLineTag - If cursor points to a line tag then increment the
|
|
|
|
/// cursor and return true otherwise return false.
|
|
|
|
bool readLineTag() {
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef Tag = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
|
|
|
if (Tag.empty() || Tag[0] != '\0' || Tag[1] != '\0' || Tag[2] != '\x45' ||
|
|
|
|
Tag[3] != '\x01') {
|
2011-09-28 18:50:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor += 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// readArcTag - If cursor points to an gcda arc tag then increment the
|
|
|
|
/// cursor and return true otherwise return false.
|
|
|
|
bool readArcTag() {
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef Tag = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
|
|
|
if (Tag.empty() || Tag[0] != '\0' || Tag[1] != '\0' || Tag[2] != '\xa1' ||
|
|
|
|
Tag[3] != '\1') {
|
2011-09-28 18:50:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor += 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-05 01:11:58 +00:00
|
|
|
/// readObjectTag - If cursor points to an object summary tag then increment
|
|
|
|
/// the cursor and return true otherwise return false.
|
|
|
|
bool readObjectTag() {
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef Tag = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
|
|
|
if (Tag.empty() || Tag[0] != '\0' || Tag[1] != '\0' || Tag[2] != '\0' ||
|
|
|
|
Tag[3] != '\xa1') {
|
2013-11-05 01:11:58 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor += 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-25 02:22:21 +00:00
|
|
|
/// readProgramTag - If cursor points to a program summary tag then increment
|
|
|
|
/// the cursor and return true otherwise return false.
|
|
|
|
bool readProgramTag() {
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef Tag = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
|
|
|
if (Tag.empty() || Tag[0] != '\0' || Tag[1] != '\0' || Tag[2] != '\0' ||
|
|
|
|
Tag[3] != '\xa3') {
|
2013-10-25 02:22:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Cursor += 4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-14 00:07:15 +00:00
|
|
|
bool readInt(uint32_t &Val) {
|
2015-01-23 22:38:01 +00:00
|
|
|
if (Buffer->getBuffer().size() < Cursor + 4) {
|
|
|
|
errs() << "Unexpected end of memory buffer: " << Cursor + 4 << ".\n";
|
2013-11-14 00:07:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-23 22:38:01 +00:00
|
|
|
StringRef Str = Buffer->getBuffer().slice(Cursor, Cursor + 4);
|
2011-09-28 18:50:00 +00:00
|
|
|
Cursor += 4;
|
2013-11-14 00:07:15 +00:00
|
|
|
Val = *(const uint32_t *)(Str.data());
|
|
|
|
return true;
|
2011-09-28 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 00:07:15 +00:00
|
|
|
bool readInt64(uint64_t &Val) {
|
|
|
|
uint32_t Lo, Hi;
|
2015-01-23 22:38:01 +00:00
|
|
|
if (!readInt(Lo) || !readInt(Hi))
|
|
|
|
return false;
|
2013-11-14 00:07:15 +00:00
|
|
|
Val = ((uint64_t)Hi << 32) | Lo;
|
|
|
|
return true;
|
2011-09-28 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 00:07:15 +00:00
|
|
|
bool readString(StringRef &Str) {
|
2014-03-27 00:06:36 +00:00
|
|
|
uint32_t Len = 0;
|
|
|
|
// Keep reading until we find a non-zero length. This emulates gcov's
|
|
|
|
// behaviour, which appears to do the same.
|
|
|
|
while (Len == 0)
|
2015-01-23 22:38:01 +00:00
|
|
|
if (!readInt(Len))
|
|
|
|
return false;
|
2013-11-14 00:07:15 +00:00
|
|
|
Len *= 4;
|
2015-01-23 22:38:01 +00:00
|
|
|
if (Buffer->getBuffer().size() < Cursor + Len) {
|
|
|
|
errs() << "Unexpected end of memory buffer: " << Cursor + Len << ".\n";
|
2013-11-14 00:07:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-23 22:38:01 +00:00
|
|
|
Str = Buffer->getBuffer().slice(Cursor, Cursor + Len).split('\0').first;
|
2011-09-28 18:50:00 +00:00
|
|
|
Cursor += Len;
|
2013-11-14 00:07:15 +00:00
|
|
|
return true;
|
2011-09-28 18:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getCursor() const { return Cursor; }
|
2015-01-23 22:38:01 +00:00
|
|
|
void advanceCursor(uint32_t n) { Cursor += n * 4; }
|
|
|
|
|
2011-09-28 18:50:00 +00:00
|
|
|
private:
|
|
|
|
MemoryBuffer *Buffer;
|
|
|
|
uint64_t Cursor;
|
|
|
|
};
|
|
|
|
|
2011-09-29 16:52:53 +00:00
|
|
|
/// GCOVFile - Collects coverage information for one pair of coverage file
|
|
|
|
/// (.gcno and .gcda).
|
2011-09-28 18:50:00 +00:00
|
|
|
class GCOVFile {
|
|
|
|
public:
|
2015-01-23 22:38:01 +00:00
|
|
|
GCOVFile()
|
|
|
|
: GCNOInitialized(false), Checksum(0), Functions(), RunCount(0),
|
|
|
|
ProgramCount(0) {}
|
2013-12-04 04:49:23 +00:00
|
|
|
bool readGCNO(GCOVBuffer &Buffer);
|
|
|
|
bool readGCDA(GCOVBuffer &Buffer);
|
2013-12-04 05:42:28 +00:00
|
|
|
uint32_t getChecksum() const { return Checksum; }
|
2013-11-19 20:33:32 +00:00
|
|
|
void dump() const;
|
2011-09-28 18:50:00 +00:00
|
|
|
void collectLineCounts(FileInfo &FI);
|
2015-01-23 22:38:01 +00:00
|
|
|
|
2011-09-28 18:50:00 +00:00
|
|
|
private:
|
2013-12-04 05:07:36 +00:00
|
|
|
bool GCNOInitialized;
|
2013-12-04 04:49:23 +00:00
|
|
|
GCOV::GCOVVersion Version;
|
2013-11-20 04:15:05 +00:00
|
|
|
uint32_t Checksum;
|
2014-04-21 21:40:16 +00:00
|
|
|
SmallVector<std::unique_ptr<GCOVFunction>, 16> Functions;
|
2013-11-05 01:11:58 +00:00
|
|
|
uint32_t RunCount;
|
2013-10-25 02:22:21 +00:00
|
|
|
uint32_t ProgramCount;
|
2011-09-28 18:50:00 +00:00
|
|
|
};
|
|
|
|
|
2013-12-13 01:15:07 +00:00
|
|
|
/// GCOVEdge - Collects edge information.
|
2013-12-03 00:24:44 +00:00
|
|
|
struct GCOVEdge {
|
2014-04-21 21:40:16 +00:00
|
|
|
GCOVEdge(GCOVBlock &S, GCOVBlock &D) : Src(S), Dst(D), Count(0) {}
|
2013-12-03 00:24:44 +00:00
|
|
|
|
2014-04-21 21:40:16 +00:00
|
|
|
GCOVBlock &Src;
|
|
|
|
GCOVBlock &Dst;
|
2013-12-03 00:24:44 +00:00
|
|
|
uint64_t Count;
|
|
|
|
};
|
|
|
|
|
2011-09-28 18:50:00 +00:00
|
|
|
/// GCOVFunction - Collects function information.
|
|
|
|
class GCOVFunction {
|
|
|
|
public:
|
2015-01-23 22:57:02 +00:00
|
|
|
typedef pointee_iterator<SmallVectorImpl<
|
|
|
|
std::unique_ptr<GCOVBlock>>::const_iterator> BlockIterator;
|
2013-12-13 01:15:07 +00:00
|
|
|
|
2013-12-04 05:42:28 +00:00
|
|
|
GCOVFunction(GCOVFile &P) : Parent(P), Ident(0), LineNumber(0) {}
|
2013-12-04 04:49:23 +00:00
|
|
|
bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
|
|
|
|
bool readGCDA(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
|
2013-12-13 01:15:07 +00:00
|
|
|
StringRef getName() const { return Name; }
|
2013-11-14 00:32:00 +00:00
|
|
|
StringRef getFilename() const { return Filename; }
|
2013-12-10 01:02:07 +00:00
|
|
|
size_t getNumBlocks() const { return Blocks.size(); }
|
2013-12-13 01:15:07 +00:00
|
|
|
uint64_t getEntryCount() const;
|
|
|
|
uint64_t getExitCount() const;
|
|
|
|
|
|
|
|
BlockIterator block_begin() const { return Blocks.begin(); }
|
|
|
|
BlockIterator block_end() const { return Blocks.end(); }
|
2015-01-23 22:57:02 +00:00
|
|
|
iterator_range<BlockIterator> blocks() const {
|
|
|
|
return make_range(block_begin(), block_end());
|
|
|
|
}
|
2013-12-13 01:15:07 +00:00
|
|
|
|
2013-11-19 20:33:32 +00:00
|
|
|
void dump() const;
|
2011-09-28 18:50:00 +00:00
|
|
|
void collectLineCounts(FileInfo &FI);
|
2015-01-23 22:38:01 +00:00
|
|
|
|
2011-09-28 18:50:00 +00:00
|
|
|
private:
|
2013-12-04 05:42:28 +00:00
|
|
|
GCOVFile &Parent;
|
2011-09-28 18:50:00 +00:00
|
|
|
uint32_t Ident;
|
2013-12-04 08:57:17 +00:00
|
|
|
uint32_t Checksum;
|
2011-09-28 18:50:00 +00:00
|
|
|
uint32_t LineNumber;
|
|
|
|
StringRef Name;
|
|
|
|
StringRef Filename;
|
2014-04-21 21:40:16 +00:00
|
|
|
SmallVector<std::unique_ptr<GCOVBlock>, 16> Blocks;
|
|
|
|
SmallVector<std::unique_ptr<GCOVEdge>, 16> Edges;
|
2011-09-28 18:50:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// GCOVBlock - Collects block information.
|
|
|
|
class GCOVBlock {
|
2013-12-13 01:15:07 +00:00
|
|
|
struct EdgeWeight {
|
2015-01-23 22:38:01 +00:00
|
|
|
EdgeWeight(GCOVBlock *D) : Dst(D), Count(0) {}
|
2013-12-13 01:15:07 +00:00
|
|
|
|
|
|
|
GCOVBlock *Dst;
|
|
|
|
uint64_t Count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SortDstEdgesFunctor {
|
|
|
|
bool operator()(const GCOVEdge *E1, const GCOVEdge *E2) {
|
2014-04-21 21:40:16 +00:00
|
|
|
return E1->Dst.Number < E2->Dst.Number;
|
2013-12-13 01:15:07 +00:00
|
|
|
}
|
|
|
|
};
|
2015-01-23 22:38:01 +00:00
|
|
|
|
2011-09-28 18:50:00 +00:00
|
|
|
public:
|
2013-12-03 00:24:44 +00:00
|
|
|
typedef SmallVectorImpl<GCOVEdge *>::const_iterator EdgeIterator;
|
|
|
|
|
2015-01-23 22:38:01 +00:00
|
|
|
GCOVBlock(GCOVFunction &P, uint32_t N)
|
|
|
|
: Parent(P), Number(N), Counter(0), DstEdgesAreSorted(true), SrcEdges(),
|
|
|
|
DstEdges(), Lines() {}
|
2011-09-28 18:50:00 +00:00
|
|
|
~GCOVBlock();
|
2013-12-19 00:29:25 +00:00
|
|
|
const GCOVFunction &getParent() const { return Parent; }
|
2013-12-13 01:15:07 +00:00
|
|
|
void addLine(uint32_t N) { Lines.push_back(N); }
|
|
|
|
uint32_t getLastLine() const { return Lines.back(); }
|
|
|
|
void addCount(size_t DstEdgeNo, uint64_t N);
|
|
|
|
uint64_t getCount() const { return Counter; }
|
|
|
|
|
2013-12-03 00:24:44 +00:00
|
|
|
void addSrcEdge(GCOVEdge *Edge) {
|
2014-04-21 21:40:16 +00:00
|
|
|
assert(&Edge->Dst == this); // up to caller to ensure edge is valid
|
2013-12-03 00:24:44 +00:00
|
|
|
SrcEdges.push_back(Edge);
|
|
|
|
}
|
|
|
|
void addDstEdge(GCOVEdge *Edge) {
|
2014-04-21 21:40:16 +00:00
|
|
|
assert(&Edge->Src == this); // up to caller to ensure edge is valid
|
2013-12-13 01:15:07 +00:00
|
|
|
// Check if adding this edge causes list to become unsorted.
|
2014-04-21 21:40:16 +00:00
|
|
|
if (DstEdges.size() && DstEdges.back()->Dst.Number > Edge->Dst.Number)
|
2013-12-13 01:15:07 +00:00
|
|
|
DstEdgesAreSorted = false;
|
2013-12-03 00:24:44 +00:00
|
|
|
DstEdges.push_back(Edge);
|
|
|
|
}
|
|
|
|
size_t getNumSrcEdges() const { return SrcEdges.size(); }
|
|
|
|
size_t getNumDstEdges() const { return DstEdges.size(); }
|
2013-12-13 01:15:07 +00:00
|
|
|
void sortDstEdges();
|
2013-12-03 00:24:44 +00:00
|
|
|
|
|
|
|
EdgeIterator src_begin() const { return SrcEdges.begin(); }
|
|
|
|
EdgeIterator src_end() const { return SrcEdges.end(); }
|
2015-01-23 22:57:02 +00:00
|
|
|
iterator_range<EdgeIterator> srcs() const {
|
|
|
|
return make_range(src_begin(), src_end());
|
|
|
|
}
|
|
|
|
|
2013-12-03 00:24:44 +00:00
|
|
|
EdgeIterator dst_begin() const { return DstEdges.begin(); }
|
|
|
|
EdgeIterator dst_end() const { return DstEdges.end(); }
|
2015-01-23 22:57:02 +00:00
|
|
|
iterator_range<EdgeIterator> dsts() const {
|
|
|
|
return make_range(dst_begin(), dst_end());
|
|
|
|
}
|
2013-12-03 00:24:44 +00:00
|
|
|
|
2013-11-19 20:33:32 +00:00
|
|
|
void dump() const;
|
2011-09-28 18:50:00 +00:00
|
|
|
void collectLineCounts(FileInfo &FI);
|
2015-01-23 22:38:01 +00:00
|
|
|
|
2011-09-28 18:50:00 +00:00
|
|
|
private:
|
2013-11-14 00:32:00 +00:00
|
|
|
GCOVFunction &Parent;
|
2011-09-28 18:50:00 +00:00
|
|
|
uint32_t Number;
|
|
|
|
uint64_t Counter;
|
2013-12-13 01:15:07 +00:00
|
|
|
bool DstEdgesAreSorted;
|
2013-12-03 00:24:44 +00:00
|
|
|
SmallVector<GCOVEdge *, 16> SrcEdges;
|
|
|
|
SmallVector<GCOVEdge *, 16> DstEdges;
|
2013-11-14 00:32:00 +00:00
|
|
|
SmallVector<uint32_t, 16> Lines;
|
2011-09-28 18:50:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileInfo {
|
2015-01-23 22:38:01 +00:00
|
|
|
// It is unlikely--but possible--for multiple functions to be on the same
|
|
|
|
// line.
|
|
|
|
// Therefore this typedef allows LineData.Functions to store multiple
|
|
|
|
// functions
|
2013-12-13 01:15:07 +00:00
|
|
|
// per instance. This is rare, however, so optimize for the common case.
|
|
|
|
typedef SmallVector<const GCOVFunction *, 1> FunctionVector;
|
|
|
|
typedef DenseMap<uint32_t, FunctionVector> FunctionLines;
|
|
|
|
typedef SmallVector<const GCOVBlock *, 4> BlockVector;
|
|
|
|
typedef DenseMap<uint32_t, BlockVector> BlockLines;
|
|
|
|
|
|
|
|
struct LineData {
|
2014-05-07 02:11:23 +00:00
|
|
|
LineData() : LastLine(0) {}
|
2013-12-13 01:15:07 +00:00
|
|
|
BlockLines Blocks;
|
|
|
|
FunctionLines Functions;
|
2014-05-07 02:11:23 +00:00
|
|
|
uint32_t LastLine;
|
2013-12-13 01:15:07 +00:00
|
|
|
};
|
2013-12-18 21:12:51 +00:00
|
|
|
|
|
|
|
struct GCOVCoverage {
|
2015-01-23 22:38:01 +00:00
|
|
|
GCOVCoverage(StringRef Name)
|
|
|
|
: Name(Name), LogicalLines(0), LinesExec(0), Branches(0),
|
|
|
|
BranchesExec(0), BranchesTaken(0) {}
|
2013-12-18 21:12:51 +00:00
|
|
|
|
2013-12-19 00:29:25 +00:00
|
|
|
StringRef Name;
|
|
|
|
|
2013-12-18 21:12:51 +00:00
|
|
|
uint32_t LogicalLines;
|
|
|
|
uint32_t LinesExec;
|
|
|
|
|
|
|
|
uint32_t Branches;
|
|
|
|
uint32_t BranchesExec;
|
|
|
|
uint32_t BranchesTaken;
|
|
|
|
};
|
2015-01-23 22:38:01 +00:00
|
|
|
|
2011-09-28 18:50:00 +00:00
|
|
|
public:
|
2015-01-23 22:38:01 +00:00
|
|
|
FileInfo(const GCOVOptions &Options)
|
|
|
|
: Options(Options), LineInfo(), RunCount(0), ProgramCount(0) {}
|
2013-12-13 01:15:07 +00:00
|
|
|
|
2013-12-03 00:38:21 +00:00
|
|
|
void addBlockLine(StringRef Filename, uint32_t Line, const GCOVBlock *Block) {
|
2014-05-07 02:11:23 +00:00
|
|
|
if (Line > LineInfo[Filename].LastLine)
|
|
|
|
LineInfo[Filename].LastLine = Line;
|
2015-01-23 22:38:01 +00:00
|
|
|
LineInfo[Filename].Blocks[Line - 1].push_back(Block);
|
2013-12-13 01:15:07 +00:00
|
|
|
}
|
|
|
|
void addFunctionLine(StringRef Filename, uint32_t Line,
|
|
|
|
const GCOVFunction *Function) {
|
2014-05-07 02:11:23 +00:00
|
|
|
if (Line > LineInfo[Filename].LastLine)
|
|
|
|
LineInfo[Filename].LastLine = Line;
|
2015-01-23 22:38:01 +00:00
|
|
|
LineInfo[Filename].Functions[Line - 1].push_back(Function);
|
2013-10-23 19:45:03 +00:00
|
|
|
}
|
2013-11-05 01:11:58 +00:00
|
|
|
void setRunCount(uint32_t Runs) { RunCount = Runs; }
|
|
|
|
void setProgramCount(uint32_t Programs) { ProgramCount = Programs; }
|
2015-01-23 23:09:27 +00:00
|
|
|
void print(raw_ostream &OS, StringRef MainFilename, StringRef GCNOFile,
|
|
|
|
StringRef GCDAFile);
|
2014-04-23 21:44:55 +00:00
|
|
|
|
2013-12-16 23:24:30 +00:00
|
|
|
private:
|
2014-05-07 02:11:18 +00:00
|
|
|
std::string getCoveragePath(StringRef Filename, StringRef MainFilename);
|
|
|
|
std::unique_ptr<raw_ostream> openCoveragePath(StringRef CoveragePath);
|
2015-01-23 22:38:01 +00:00
|
|
|
void printFunctionSummary(raw_ostream &OS, const FunctionVector &Funcs) const;
|
2014-05-07 02:11:18 +00:00
|
|
|
void printBlockInfo(raw_ostream &OS, const GCOVBlock &Block,
|
2013-12-13 01:15:07 +00:00
|
|
|
uint32_t LineIndex, uint32_t &BlockNo) const;
|
2014-05-07 02:11:18 +00:00
|
|
|
void printBranchInfo(raw_ostream &OS, const GCOVBlock &Block,
|
2013-12-19 00:29:25 +00:00
|
|
|
GCOVCoverage &Coverage, uint32_t &EdgeNo);
|
2014-05-07 02:11:18 +00:00
|
|
|
void printUncondBranchInfo(raw_ostream &OS, uint32_t &EdgeNo,
|
2013-12-16 22:14:02 +00:00
|
|
|
uint64_t Count) const;
|
2013-12-19 00:29:25 +00:00
|
|
|
|
2015-01-23 23:09:27 +00:00
|
|
|
void printCoverage(raw_ostream &OS, const GCOVCoverage &Coverage) const;
|
|
|
|
void printFuncCoverage(raw_ostream &OS) const;
|
|
|
|
void printFileCoverage(raw_ostream &OS) const;
|
2013-12-16 23:24:30 +00:00
|
|
|
|
2013-12-13 01:15:07 +00:00
|
|
|
const GCOVOptions &Options;
|
2013-12-03 00:38:21 +00:00
|
|
|
StringMap<LineData> LineInfo;
|
2013-11-05 01:11:58 +00:00
|
|
|
uint32_t RunCount;
|
2013-10-25 02:22:21 +00:00
|
|
|
uint32_t ProgramCount;
|
2014-02-04 10:45:02 +00:00
|
|
|
|
2015-01-23 22:38:01 +00:00
|
|
|
typedef SmallVector<std::pair<std::string, GCOVCoverage>, 4> FileCoverageList;
|
2014-02-04 10:45:02 +00:00
|
|
|
typedef MapVector<const GCOVFunction *, GCOVCoverage> FuncCoverageMap;
|
|
|
|
|
|
|
|
FileCoverageList FileCoverages;
|
|
|
|
FuncCoverageMap FuncCoverages;
|
2011-09-28 18:50:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|