15 #ifndef LLVM_SUPPORT_GCOV_H
16 #define LLVM_SUPPORT_GCOV_H
62 errs() <<
"Unexpected file type: " << File <<
".\n";
73 errs() <<
"Unexpected file type: " << File <<
".\n";
83 if (VersionStr ==
"*204") {
88 if (VersionStr ==
"*404") {
93 errs() <<
"Unexpected version: " << VersionStr <<
".\n";
101 if (Tag.
empty() || Tag[0] !=
'\0' || Tag[1] !=
'\0' || Tag[2] !=
'\0' ||
113 if (Tag.
empty() || Tag[0] !=
'\0' || Tag[1] !=
'\0' || Tag[2] !=
'\x41' ||
125 if (Tag.
empty() || Tag[0] !=
'\0' || Tag[1] !=
'\0' || Tag[2] !=
'\x43' ||
137 if (Tag.
empty() || Tag[0] !=
'\0' || Tag[1] !=
'\0' || Tag[2] !=
'\x45' ||
149 if (Tag.
empty() || Tag[0] !=
'\0' || Tag[1] !=
'\0' || Tag[2] !=
'\xa1' ||
161 if (Tag.
empty() || Tag[0] !=
'\0' || Tag[1] !=
'\0' || Tag[2] !=
'\0' ||
173 if (Tag.
empty() || Tag[0] !=
'\0' || Tag[1] !=
'\0' || Tag[2] !=
'\0' ||
183 errs() <<
"Unexpected end of memory buffer: " << Cursor + 4 <<
".\n";
188 Val = *(
const uint32_t *)(Str.
data());
196 Val = ((uint64_t)Hi << 32) |
Lo;
209 errs() <<
"Unexpected end of memory buffer: " << Cursor + Len <<
".\n";
230 : GCNOInitialized(
false), Checksum(0), Functions(), RunCount(0),
239 bool GCNOInitialized;
244 uint32_t ProgramCount;
294 EdgeWeight(
GCOVBlock *D) : Dst(D), Count(0) {}
300 struct SortDstEdgesFunctor {
302 return E1->
Dst.Number < E2->
Dst.Number;
310 : Parent(P), Number(N), Counter(0), DstEdgesAreSorted(
true), SrcEdges(),
311 DstEdges(), Lines() {}
316 void addCount(
size_t DstEdgeNo, uint64_t
N);
320 assert(&Edge->
Dst ==
this);
321 SrcEdges.push_back(Edge);
324 assert(&Edge->
Src ==
this);
326 if (DstEdges.size() && DstEdges.back()->Dst.Number > Edge->
Dst.Number)
327 DstEdgesAreSorted =
false;
328 DstEdges.push_back(Edge);
353 bool DstEdgesAreSorted;
371 LineData() : LastLine(0) {}
377 struct GCOVCoverage {
379 :
Name(Name), LogicalLines(0), LinesExec(0), Branches(0),
380 BranchesExec(0), BranchesTaken(0) {}
384 uint32_t LogicalLines;
388 uint32_t BranchesExec;
389 uint32_t BranchesTaken;
394 : Options(Options), LineInfo(), RunCount(0), ProgramCount(0) {}
397 if (Line > LineInfo[Filename].LastLine)
398 LineInfo[Filename].LastLine = Line;
399 LineInfo[Filename].Blocks[Line - 1].push_back(Block);
403 if (Line > LineInfo[Filename].LastLine)
404 LineInfo[Filename].LastLine = Line;
405 LineInfo[Filename].Functions[Line - 1].push_back(Function);
414 std::unique_ptr<raw_ostream> openCoveragePath(
StringRef CoveragePath);
415 void printFunctionSummary(
raw_ostream &OS,
const FunctionVector &Funcs)
const;
417 uint32_t LineIndex, uint32_t &BlockNo)
const;
419 GCOVCoverage &Coverage, uint32_t &EdgeNo);
420 void printUncondBranchInfo(
raw_ostream &OS, uint32_t &EdgeNo,
421 uint64_t Count)
const;
423 void printCoverage(
raw_ostream &OS,
const GCOVCoverage &Coverage)
const;
430 uint32_t ProgramCount;
435 FileCoverageList FileCoverages;
436 FuncCoverageMap FuncCoverages;
GCOVOptions - A struct for passing gcov options between functions.
void push_back(const T &Elt)
iterator_range< EdgeIterator > dsts() const
GCOVBlock(GCOVFunction &P, uint32_t N)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVVersion Version)
readGCNO - Read a function from the GCNO buffer.
EdgeIterator dst_begin() const
bool readInt(uint32_t &Val)
bool readGCDAFormat()
readGCDAFormat - Check GCDA signature is valid at the beginning of buffer.
size_t size() const
size - Get the string size.
GCOVEdge - Collects edge information.
void addFunctionLine(StringRef Filename, uint32_t Line, const GCOVFunction *Function)
void print(raw_ostream &OS, StringRef MainFilename, StringRef GCNOFile, StringRef GCDAFile)
print - Print source files with collected line count information.
uint64_t getCount() const
bool readLineTag()
readLineTag - If cursor points to a line tag then increment the cursor and return true otherwise retu...
void setProgramCount(uint32_t Programs)
SmallVectorImpl< GCOVEdge * >::const_iterator EdgeIterator
BlockIterator block_begin() const
bool readString(StringRef &Str)
size_t getNumBlocks() const
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
uint32_t getChecksum() const
StringRef getBuffer() const
void addBlockLine(StringRef Filename, uint32_t Line, const GCOVBlock *Block)
GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific read operations.
uint32_t getLastLine() const
iterator_range< BlockIterator > blocks() const
StringRef getName() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
EdgeIterator dst_end() const
void collectLineCounts(FileInfo &FI)
collectLineCounts - Collect line counts.
bool readGCDA(GCOVBuffer &Buffer)
readGCDA - Read GCDA buffer.
bool readArcTag()
readArcTag - If cursor points to an gcda arc tag then increment the cursor and return true otherwise ...
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
void addDstEdge(GCOVEdge *Edge)
GCOVBlock - Collects block information.
uint64_t getExitCount() const
getExitCount - Get the number of times the function returned by retrieving the exit block's count...
GCOVFunction(GCOVFile &P)
iterator_range< EdgeIterator > srcs() const
pointee_iterator< SmallVectorImpl< std::unique_ptr< GCOVBlock > >::const_iterator > BlockIterator
void sortDstEdges()
sortDstEdges - Sort destination edges by block number, nop if already sorted.
bool readInt64(uint64_t &Val)
void collectLineCounts(FileInfo &FI)
collectLineCounts - Collect line counts.
EdgeIterator src_begin() const
void addSrcEdge(GCOVEdge *Edge)
void dump() const
dump - Dump GCOVFile content to dbgs() for debugging purposes.
bool readBlockTag()
readBlockTag - If cursor points to a block tag then increment the cursor and return true otherwise re...
BlockIterator block_end() const
bool readGCNOFormat()
readGCNOFormat - Check GCNO signature is valid at the beginning of buffer.
void advanceCursor(uint32_t n)
bool readGCNO(GCOVBuffer &Buffer)
readGCNO - Read GCNO buffer.
const GCOVFunction & getParent() const
bool readEdgeTag()
readEdgeTag - If cursor points to an edge tag then increment the cursor and return true otherwise ret...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
GCOVBuffer(MemoryBuffer *B)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
GCOVEdge(GCOVBlock &S, GCOVBlock &D)
An iterator type that allows iterating over the pointees via some other iterator. ...
void dump() const
dump - Dump GCOVFunction content to dbgs() for debugging purposes.
bool readGCDA(GCOVBuffer &Buffer, GCOV::GCOVVersion Version)
readGCDA - Read a function from the GCDA buffer.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
EdgeIterator src_end() const
A range adaptor for a pair of iterators.
size_t getNumSrcEdges() const
StringRef getFilename() const
GCOVOptions(bool A, bool B, bool C, bool F, bool P, bool U, bool L, bool N)
void collectLineCounts(FileInfo &FI)
collectLineCounts - Collect line counts.
GCOVFunction - Collects function information.
size_t getNumDstEdges() const
void dump() const
dump - Dump GCOVBlock content to dbgs() for debugging purposes.
bool readObjectTag()
readObjectTag - If cursor points to an object summary tag then increment the cursor and return true o...
GCOVFile - Collects coverage information for one pair of coverage file (.gcno and ...
uint64_t getEntryCount() const
getEntryCount - Get the number of times the function was called by retrieving the entry block's count...
uint64_t getCursor() const
~GCOVBlock()
~GCOVBlock - Delete GCOVBlock and its content.
FileInfo(const GCOVOptions &Options)
This class implements an extremely fast bulk output stream that can only output to a stream...
bool readProgramTag()
readProgramTag - If cursor points to a program summary tag then increment the cursor and return true ...
StringRef - Represent a constant reference to a string, i.e.
bool readFunctionTag()
readFunctionTag - If cursor points to a function tag then increment the cursor and return true otherw...
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
void addCount(size_t DstEdgeNo, uint64_t N)
addCount - Add to block counter while storing the edge count.
void setRunCount(uint32_t Runs)
bool readGCOVVersion(GCOV::GCOVVersion &Version)
readGCOVVersion - Read GCOV version.
bool empty() const
empty - Check if the string is empty.