blob: 14eb71f0300d3f40261c5bc18c98f595ab03b205 [file] [log] [blame]
Devang Patel8dfb6552011-10-04 17:24:48 +00001//===- GCOVr.cpp - LLVM coverage tool -------------------------------------===//
Devang Patel37140652011-09-28 18:50:00 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
NAKAMURA Takumi3b551962013-11-14 11:44:58 +000010// GCOV implements the interface to read and write coverage files that use
Devang Patel8dfb6552011-10-04 17:24:48 +000011// 'gcov' format.
Devang Patel37140652011-09-28 18:50:00 +000012//
Devang Patel37140652011-09-28 18:50:00 +000013//===----------------------------------------------------------------------===//
14
Yuchen Wu03678152013-10-25 02:22:24 +000015#include "llvm/Support/Debug.h"
Devang Patel8dfb6552011-10-04 17:24:48 +000016#include "llvm/Support/GCOV.h"
Devang Patel37140652011-09-28 18:50:00 +000017#include "llvm/ADT/OwningPtr.h"
Devang Patela9e8a252011-09-29 16:46:47 +000018#include "llvm/ADT/STLExtras.h"
Bob Wilson3461bed2013-10-22 05:09:41 +000019#include "llvm/Support/Format.h"
Devang Patel37140652011-09-28 18:50:00 +000020#include "llvm/Support/MemoryObject.h"
21#include "llvm/Support/system_error.h"
22using namespace llvm;
23
24//===----------------------------------------------------------------------===//
25// GCOVFile implementation.
26
27/// ~GCOVFile - Delete GCOVFile and its content.
28GCOVFile::~GCOVFile() {
29 DeleteContainerPointers(Functions);
30}
31
Yuchen Wubec4e902013-12-04 04:49:23 +000032/// readGCNO - Read GCNO buffer.
33bool GCOVFile::readGCNO(GCOVBuffer &Buffer) {
34 if (!Buffer.readGCNOFormat()) return false;
35 if (!Buffer.readGCOVVersion(Version)) return false;
36
37 if (!Buffer.readInt(Checksum)) return false;
38 while (true) {
39 if (!Buffer.readFunctionTag()) break;
Yuchen Wu57529972013-12-04 05:42:28 +000040 GCOVFunction *GFun = new GCOVFunction(*this);
Yuchen Wubec4e902013-12-04 04:49:23 +000041 if (!GFun->readGCNO(Buffer, Version))
42 return false;
43 Functions.push_back(GFun);
44 }
45
Yuchen Wu21517e42013-12-04 05:07:36 +000046 GCNOInitialized = true;
Yuchen Wubec4e902013-12-04 04:49:23 +000047 return true;
Devang Patele5a8f2f92011-09-29 17:06:40 +000048}
49
Yuchen Wubec4e902013-12-04 04:49:23 +000050/// readGCDA - Read GCDA buffer. It is required that readGCDA() can only be
51/// called after readGCNO().
52bool GCOVFile::readGCDA(GCOVBuffer &Buffer) {
Yuchen Wu21517e42013-12-04 05:07:36 +000053 assert(GCNOInitialized && "readGCDA() can only be called after readGCNO()");
Yuchen Wubec4e902013-12-04 04:49:23 +000054 if (!Buffer.readGCDAFormat()) return false;
55 GCOV::GCOVVersion GCDAVersion;
56 if (!Buffer.readGCOVVersion(GCDAVersion)) return false;
57 if (Version != GCDAVersion) {
58 errs() << "GCOV versions do not match.\n";
Devang Patel37140652011-09-28 18:50:00 +000059 return false;
Yuchen Wubec4e902013-12-04 04:49:23 +000060 }
Devang Patel37140652011-09-28 18:50:00 +000061
Yuchen Wubec4e902013-12-04 04:49:23 +000062 uint32_t GCDAChecksum;
63 if (!Buffer.readInt(GCDAChecksum)) return false;
64 if (Checksum != GCDAChecksum) {
Yuchen Wu57529972013-12-04 05:42:28 +000065 errs() << "File checksums do not match: " << Checksum << " != "
66 << GCDAChecksum << ".\n";
Yuchen Wubec4e902013-12-04 04:49:23 +000067 return false;
68 }
69 for (size_t i = 0, e = Functions.size(); i < e; ++i) {
70 if (!Buffer.readFunctionTag()) {
71 errs() << "Unexpected number of functions.\n";
Yuchen Wubabe7492013-11-20 04:15:05 +000072 return false;
73 }
Yuchen Wubec4e902013-12-04 04:49:23 +000074 if (!Functions[i]->readGCDA(Buffer, Version))
75 return false;
76 }
77 if (Buffer.readObjectTag()) {
78 uint32_t Length;
79 uint32_t Dummy;
80 if (!Buffer.readInt(Length)) return false;
81 if (!Buffer.readInt(Dummy)) return false; // checksum
82 if (!Buffer.readInt(Dummy)) return false; // num
83 if (!Buffer.readInt(RunCount)) return false;;
84 Buffer.advanceCursor(Length-3);
85 }
86 while (Buffer.readProgramTag()) {
87 uint32_t Length;
88 if (!Buffer.readInt(Length)) return false;
89 Buffer.advanceCursor(Length);
90 ++ProgramCount;
Yuchen Wu14ae8e62013-10-25 02:22:21 +000091 }
92
Devang Patel37140652011-09-28 18:50:00 +000093 return true;
94}
95
Yuchen Wu03678152013-10-25 02:22:24 +000096/// dump - Dump GCOVFile content to dbgs() for debugging purposes.
Yuchen Wuef6909d2013-11-19 20:33:32 +000097void GCOVFile::dump() const {
98 for (SmallVectorImpl<GCOVFunction *>::const_iterator I = Functions.begin(),
Bill Wendlingea6397f2012-07-19 00:11:40 +000099 E = Functions.end(); I != E; ++I)
Devang Patel37140652011-09-28 18:50:00 +0000100 (*I)->dump();
101}
102
103/// collectLineCounts - Collect line counts. This must be used after
104/// reading .gcno and .gcda files.
105void GCOVFile::collectLineCounts(FileInfo &FI) {
Craig Topperaf0dea12013-07-04 01:31:24 +0000106 for (SmallVectorImpl<GCOVFunction *>::iterator I = Functions.begin(),
NAKAMURA Takumi3b551962013-11-14 11:44:58 +0000107 E = Functions.end(); I != E; ++I)
Devang Patel37140652011-09-28 18:50:00 +0000108 (*I)->collectLineCounts(FI);
Yuchen Wu30672d92013-11-05 01:11:58 +0000109 FI.setRunCount(RunCount);
Yuchen Wu14ae8e62013-10-25 02:22:21 +0000110 FI.setProgramCount(ProgramCount);
Devang Patel37140652011-09-28 18:50:00 +0000111}
112
113//===----------------------------------------------------------------------===//
114// GCOVFunction implementation.
115
116/// ~GCOVFunction - Delete GCOVFunction and its content.
117GCOVFunction::~GCOVFunction() {
118 DeleteContainerPointers(Blocks);
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000119 DeleteContainerPointers(Edges);
Devang Patel37140652011-09-28 18:50:00 +0000120}
121
Yuchen Wuba718332013-12-03 00:15:49 +0000122/// readGCNO - Read a function from the GCNO buffer. Return false if an error
123/// occurs.
Yuchen Wubec4e902013-12-04 04:49:23 +0000124bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
Yuchen Wue28da842013-11-14 00:07:15 +0000125 uint32_t Dummy;
126 if (!Buff.readInt(Dummy)) return false; // Function header length
127 if (!Buff.readInt(Ident)) return false;
Daniel Jasper87a24d52013-12-04 08:57:17 +0000128 if (!Buff.readInt(Checksum)) return false;
Yuchen Wu57529972013-12-04 05:42:28 +0000129 if (Version != GCOV::V402) {
130 uint32_t CfgChecksum;
131 if (!Buff.readInt(CfgChecksum)) return false;
132 if (Parent.getChecksum() != CfgChecksum) {
133 errs() << "File checksums do not match: " << Parent.getChecksum()
134 << " != " << CfgChecksum << " in (" << Name << ").\n";
135 return false;
136 }
137 }
Yuchen Wue28da842013-11-14 00:07:15 +0000138 if (!Buff.readString(Name)) return false;
Yuchen Wuba718332013-12-03 00:15:49 +0000139 if (!Buff.readString(Filename)) return false;
Yuchen Wue28da842013-11-14 00:07:15 +0000140 if (!Buff.readInt(LineNumber)) return false;
Devang Patel37140652011-09-28 18:50:00 +0000141
142 // read blocks.
Yuchen Wue28da842013-11-14 00:07:15 +0000143 if (!Buff.readBlockTag()) {
144 errs() << "Block tag not found.\n";
145 return false;
146 }
147 uint32_t BlockCount;
148 if (!Buff.readInt(BlockCount)) return false;
Bob Wilson868e6e32013-10-22 20:02:36 +0000149 for (uint32_t i = 0, e = BlockCount; i != e; ++i) {
Yuchen Wue28da842013-11-14 00:07:15 +0000150 if (!Buff.readInt(Dummy)) return false; // Block flags;
Yuchen Wud738bee2013-11-14 00:32:00 +0000151 Blocks.push_back(new GCOVBlock(*this, i));
Devang Patel37140652011-09-28 18:50:00 +0000152 }
153
154 // read edges.
155 while (Buff.readEdgeTag()) {
Yuchen Wue28da842013-11-14 00:07:15 +0000156 uint32_t EdgeCount;
157 if (!Buff.readInt(EdgeCount)) return false;
158 EdgeCount = (EdgeCount - 1) / 2;
159 uint32_t BlockNo;
160 if (!Buff.readInt(BlockNo)) return false;
161 if (BlockNo >= BlockCount) {
Yuchen Wu57529972013-12-04 05:42:28 +0000162 errs() << "Unexpected block number (in " << Name << ").\n";
Yuchen Wue28da842013-11-14 00:07:15 +0000163 return false;
164 }
Bob Wilson868e6e32013-10-22 20:02:36 +0000165 for (uint32_t i = 0, e = EdgeCount; i != e; ++i) {
Yuchen Wue28da842013-11-14 00:07:15 +0000166 uint32_t Dst;
167 if (!Buff.readInt(Dst)) return false;
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000168 GCOVEdge *Edge = new GCOVEdge(Blocks[BlockNo], Blocks[Dst]);
169 Edges.push_back(Edge);
170 Blocks[BlockNo]->addDstEdge(Edge);
171 Blocks[Dst]->addSrcEdge(Edge);
Yuchen Wue28da842013-11-14 00:07:15 +0000172 if (!Buff.readInt(Dummy)) return false; // Edge flag
Devang Patel37140652011-09-28 18:50:00 +0000173 }
174 }
175
176 // read line table.
177 while (Buff.readLineTag()) {
Yuchen Wue28da842013-11-14 00:07:15 +0000178 uint32_t LineTableLength;
179 if (!Buff.readInt(LineTableLength)) return false;
Bob Wilson00928bc2013-10-22 19:54:32 +0000180 uint32_t EndPos = Buff.getCursor() + LineTableLength*4;
Yuchen Wue28da842013-11-14 00:07:15 +0000181 uint32_t BlockNo;
182 if (!Buff.readInt(BlockNo)) return false;
183 if (BlockNo >= BlockCount) {
Yuchen Wu57529972013-12-04 05:42:28 +0000184 errs() << "Unexpected block number (in " << Name << ").\n";
Yuchen Wue28da842013-11-14 00:07:15 +0000185 return false;
Devang Patel37140652011-09-28 18:50:00 +0000186 }
Yuchen Wue28da842013-11-14 00:07:15 +0000187 GCOVBlock *Block = Blocks[BlockNo];
188 if (!Buff.readInt(Dummy)) return false; // flag
189 while (Buff.getCursor() != (EndPos - 4)) {
Yuchen Wud738bee2013-11-14 00:32:00 +0000190 StringRef F;
191 if (!Buff.readString(F)) return false;
192 if (F != Filename) {
Yuchen Wu57529972013-12-04 05:42:28 +0000193 errs() << "Multiple sources for a single basic block (in "
194 << Name << ").\n";
Yuchen Wud738bee2013-11-14 00:32:00 +0000195 return false;
196 }
Yuchen Wue28da842013-11-14 00:07:15 +0000197 if (Buff.getCursor() == (EndPos - 4)) break;
198 while (true) {
199 uint32_t Line;
200 if (!Buff.readInt(Line)) return false;
201 if (!Line) break;
Yuchen Wud738bee2013-11-14 00:32:00 +0000202 Block->addLine(Line);
Yuchen Wue28da842013-11-14 00:07:15 +0000203 }
204 }
205 if (!Buff.readInt(Dummy)) return false; // flag
Devang Patel37140652011-09-28 18:50:00 +0000206 }
207 return true;
208}
209
Yuchen Wuba718332013-12-03 00:15:49 +0000210/// readGCDA - Read a function from the GCDA buffer. Return false if an error
211/// occurs.
Yuchen Wubec4e902013-12-04 04:49:23 +0000212bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
Yuchen Wuba718332013-12-03 00:15:49 +0000213 uint32_t Dummy;
214 if (!Buff.readInt(Dummy)) return false; // Function header length
Daniel Jasper87a24d52013-12-04 08:57:17 +0000215
Yuchen Wu57529972013-12-04 05:42:28 +0000216 uint32_t GCDAIdent;
217 if (!Buff.readInt(GCDAIdent)) return false;
218 if (Ident != GCDAIdent) {
219 errs() << "Function identifiers do not match: " << Ident << " != "
220 << GCDAIdent << " (in " << Name << ").\n";
221 return false;
222 }
Yuchen Wuba718332013-12-03 00:15:49 +0000223
Daniel Jasper87a24d52013-12-04 08:57:17 +0000224 uint32_t GCDAChecksum;
225 if (!Buff.readInt(GCDAChecksum)) return false;
226 if (Checksum != GCDAChecksum) {
227 errs() << "Function checksums do not match: " << Checksum << " != "
228 << GCDAChecksum << " (in " << Name << ").\n";
229 return false;
230 }
Yuchen Wu57529972013-12-04 05:42:28 +0000231
232 uint32_t CfgChecksum;
233 if (Version != GCOV::V402) {
234 if (!Buff.readInt(CfgChecksum)) return false;
235 if (Parent.getChecksum() != CfgChecksum) {
236 errs() << "File checksums do not match: " << Parent.getChecksum()
237 << " != " << CfgChecksum << " (in " << Name << ").\n";
238 return false;
239 }
240 }
241
242 StringRef GCDAName;
243 if (!Buff.readString(GCDAName)) return false;
244 if (Name != GCDAName) {
245 errs() << "Function names do not match: " << Name << " != " << GCDAName
246 << ".\n";
247 return false;
248 }
Yuchen Wuba718332013-12-03 00:15:49 +0000249
250 if (!Buff.readArcTag()) {
Yuchen Wu57529972013-12-04 05:42:28 +0000251 errs() << "Arc tag not found (in " << Name << ").\n";
Yuchen Wuba718332013-12-03 00:15:49 +0000252 return false;
253 }
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000254
Yuchen Wuba718332013-12-03 00:15:49 +0000255 uint32_t Count;
256 if (!Buff.readInt(Count)) return false;
257 Count /= 2;
258
259 // This for loop adds the counts for each block. A second nested loop is
260 // required to combine the edge counts that are contained in the GCDA file.
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000261 for (uint32_t BlockNo = 0; Count > 0; ++BlockNo) {
262 // The last block is always reserved for exit block
263 if (BlockNo >= Blocks.size()-1) {
Yuchen Wu57529972013-12-04 05:42:28 +0000264 errs() << "Unexpected number of edges (in " << Name << ").\n";
Yuchen Wuba718332013-12-03 00:15:49 +0000265 return false;
266 }
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000267 GCOVBlock &Block = *Blocks[BlockNo];
268 for (size_t EdgeNo = 0, End = Block.getNumDstEdges(); EdgeNo < End;
269 ++EdgeNo) {
Yuchen Wuba718332013-12-03 00:15:49 +0000270 if (Count == 0) {
Yuchen Wu57529972013-12-04 05:42:28 +0000271 errs() << "Unexpected number of edges (in " << Name << ").\n";
Yuchen Wuba718332013-12-03 00:15:49 +0000272 return false;
273 }
274 uint64_t ArcCount;
275 if (!Buff.readInt64(ArcCount)) return false;
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000276 Block.addCount(EdgeNo, ArcCount);
Yuchen Wuba718332013-12-03 00:15:49 +0000277 --Count;
278 }
279 }
280 return true;
281}
282
Yuchen Wu03678152013-10-25 02:22:24 +0000283/// dump - Dump GCOVFunction content to dbgs() for debugging purposes.
Yuchen Wuef6909d2013-11-19 20:33:32 +0000284void GCOVFunction::dump() const {
Yuchen Wu03678152013-10-25 02:22:24 +0000285 dbgs() << "===== " << Name << " @ " << Filename << ":" << LineNumber << "\n";
Yuchen Wuef6909d2013-11-19 20:33:32 +0000286 for (SmallVectorImpl<GCOVBlock *>::const_iterator I = Blocks.begin(),
Bill Wendlingea6397f2012-07-19 00:11:40 +0000287 E = Blocks.end(); I != E; ++I)
Devang Patel37140652011-09-28 18:50:00 +0000288 (*I)->dump();
289}
290
291/// collectLineCounts - Collect line counts. This must be used after
292/// reading .gcno and .gcda files.
293void GCOVFunction::collectLineCounts(FileInfo &FI) {
Craig Topperaf0dea12013-07-04 01:31:24 +0000294 for (SmallVectorImpl<GCOVBlock *>::iterator I = Blocks.begin(),
Bill Wendlingea6397f2012-07-19 00:11:40 +0000295 E = Blocks.end(); I != E; ++I)
Devang Patel37140652011-09-28 18:50:00 +0000296 (*I)->collectLineCounts(FI);
297}
298
299//===----------------------------------------------------------------------===//
300// GCOVBlock implementation.
301
302/// ~GCOVBlock - Delete GCOVBlock and its content.
303GCOVBlock::~GCOVBlock() {
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000304 SrcEdges.clear();
305 DstEdges.clear();
Yuchen Wud738bee2013-11-14 00:32:00 +0000306 Lines.clear();
Devang Patel37140652011-09-28 18:50:00 +0000307}
308
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000309/// addCount - Add to block counter while storing the edge count. If the
310/// destination has no outgoing edges, also update that block's count too.
311void GCOVBlock::addCount(size_t DstEdgeNo, uint64_t N) {
312 assert(DstEdgeNo < DstEdges.size()); // up to caller to ensure EdgeNo is valid
313 DstEdges[DstEdgeNo]->Count = N;
314 Counter += N;
315 if (!DstEdges[DstEdgeNo]->Dst->getNumDstEdges())
316 DstEdges[DstEdgeNo]->Dst->Counter += N;
317}
318
Devang Patel37140652011-09-28 18:50:00 +0000319/// collectLineCounts - Collect line counts. This must be used after
320/// reading .gcno and .gcda files.
321void GCOVBlock::collectLineCounts(FileInfo &FI) {
Yuchen Wud738bee2013-11-14 00:32:00 +0000322 for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(),
Bill Wendlingea6397f2012-07-19 00:11:40 +0000323 E = Lines.end(); I != E; ++I)
Yuchen Wu8f1c8812013-12-03 00:38:21 +0000324 FI.addBlockLine(Parent.getFilename(), *I, this);
Devang Patel37140652011-09-28 18:50:00 +0000325}
326
Yuchen Wu03678152013-10-25 02:22:24 +0000327/// dump - Dump GCOVBlock content to dbgs() for debugging purposes.
Yuchen Wuef6909d2013-11-19 20:33:32 +0000328void GCOVBlock::dump() const {
Yuchen Wu03678152013-10-25 02:22:24 +0000329 dbgs() << "Block : " << Number << " Counter : " << Counter << "\n";
Yuchen Wu8ad9b042013-12-03 00:24:44 +0000330 if (!SrcEdges.empty()) {
331 dbgs() << "\tSource Edges : ";
332 for (EdgeIterator I = SrcEdges.begin(), E = SrcEdges.end(); I != E; ++I) {
333 const GCOVEdge *Edge = *I;
334 dbgs() << Edge->Src->Number << " (" << Edge->Count << "), ";
335 }
336 dbgs() << "\n";
337 }
338 if (!DstEdges.empty()) {
339 dbgs() << "\tDestination Edges : ";
340 for (EdgeIterator I = DstEdges.begin(), E = DstEdges.end(); I != E; ++I) {
341 const GCOVEdge *Edge = *I;
342 dbgs() << Edge->Dst->Number << " (" << Edge->Count << "), ";
343 }
Yuchen Wu03678152013-10-25 02:22:24 +0000344 dbgs() << "\n";
Devang Patel37140652011-09-28 18:50:00 +0000345 }
346 if (!Lines.empty()) {
Yuchen Wu03678152013-10-25 02:22:24 +0000347 dbgs() << "\tLines : ";
Yuchen Wuef6909d2013-11-19 20:33:32 +0000348 for (SmallVectorImpl<uint32_t>::const_iterator I = Lines.begin(),
Yuchen Wud738bee2013-11-14 00:32:00 +0000349 E = Lines.end(); I != E; ++I)
350 dbgs() << (*I) << ",";
351 dbgs() << "\n";
Devang Patel37140652011-09-28 18:50:00 +0000352 }
353}
354
355//===----------------------------------------------------------------------===//
Devang Patel37140652011-09-28 18:50:00 +0000356// FileInfo implementation.
357
Devang Patel37140652011-09-28 18:50:00 +0000358/// print - Print source files with collected line count information.
Yuchen Wu21517e42013-12-04 05:07:36 +0000359void FileInfo::print(StringRef GCNOFile, StringRef GCDAFile) const {
Yuchen Wu8f1c8812013-12-03 00:38:21 +0000360 for (StringMap<LineData>::const_iterator I = LineInfo.begin(),
Yuchen Wuef6909d2013-11-19 20:33:32 +0000361 E = LineInfo.end(); I != E; ++I) {
Devang Patel37140652011-09-28 18:50:00 +0000362 StringRef Filename = I->first();
Devang Patel37140652011-09-28 18:50:00 +0000363 OwningPtr<MemoryBuffer> Buff;
364 if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
365 errs() << Filename << ": " << ec.message() << "\n";
366 return;
367 }
Benjamin Kramer67421c12013-11-15 09:44:17 +0000368 StringRef AllLines = Buff->getBuffer();
Yuchen Wu8aac4f62013-11-19 20:57:20 +0000369
Yuchen Wu26326ad2013-12-03 00:57:11 +0000370 std::string CovFilename = Filename.str() + ".llcov";
371 std::string ErrorInfo;
372 raw_fd_ostream OS(CovFilename.c_str(), ErrorInfo);
373 if (!ErrorInfo.empty())
374 errs() << ErrorInfo << "\n";
375
Yuchen Wu8aac4f62013-11-19 20:57:20 +0000376 OS << " -: 0:Source:" << Filename << "\n";
Yuchen Wu21517e42013-12-04 05:07:36 +0000377 OS << " -: 0:Graph:" << GCNOFile << "\n";
378 OS << " -: 0:Data:" << GCDAFile << "\n";
Yuchen Wu8aac4f62013-11-19 20:57:20 +0000379 OS << " -: 0:Runs:" << RunCount << "\n";
380 OS << " -: 0:Programs:" << ProgramCount << "\n";
381
Yuchen Wu1c068162013-12-03 01:35:31 +0000382 const LineData &Line = I->second;
383 for (uint32_t i = 0; !AllLines.empty(); ++i) {
384 LineData::const_iterator BlocksIt = Line.find(i);
385
386 // Add up the block counts to form line counts.
387 if (BlocksIt != Line.end()) {
Yuchen Wu8f1c8812013-12-03 00:38:21 +0000388 const BlockVector &Blocks = BlocksIt->second;
389 uint64_t LineCount = 0;
390 for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
391 I != E; ++I) {
392 LineCount += (*I)->getCount();
393 }
394 if (LineCount == 0)
Yuchen Wudbcf1972013-11-02 00:09:17 +0000395 OS << " #####:";
Yuchen Wu48342ee2013-10-23 19:45:03 +0000396 else
Yuchen Wu8f1c8812013-12-03 00:38:21 +0000397 OS << format("%9" PRIu64 ":", LineCount);
Yuchen Wu48342ee2013-10-23 19:45:03 +0000398 } else {
Yuchen Wudbcf1972013-11-02 00:09:17 +0000399 OS << " -:";
Yuchen Wu48342ee2013-10-23 19:45:03 +0000400 }
Devang Patel37140652011-09-28 18:50:00 +0000401 std::pair<StringRef, StringRef> P = AllLines.split('\n');
Yuchen Wu1c068162013-12-03 01:35:31 +0000402 OS << format("%5u:", i+1) << P.first << "\n";
Devang Patel37140652011-09-28 18:50:00 +0000403 AllLines = P.second;
404 }
405 }
406}