summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYuchen Wu <yuchenericwu@hotmail.com>2013-12-03 00:15:49 +0000
committerYuchen Wu <yuchenericwu@hotmail.com>2013-12-03 00:15:49 +0000
commitc4b184e229aaa35c2c7b1463a22d6fd4c9f81aec (patch)
tree3cc7087b6f2bf8a6159f537d5968565e909afe82 /lib
parent44de223927a6d32f599574b4d10093ce041c1acd (diff)
downloadllvm-c4b184e229aaa35c2c7b1463a22d6fd4c9f81aec.tar.gz
llvm-c4b184e229aaa35c2c7b1463a22d6fd4c9f81aec.tar.bz2
llvm-c4b184e229aaa35c2c7b1463a22d6fd4c9f81aec.tar.xz
llvm-cov: Split up reading of GCNO and GCDA files.
There are now two functions: readGCNO() and readGCDA(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196173 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/IR/GCOV.cpp90
1 files changed, 49 insertions, 41 deletions
diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp
index b48e147449..3b0dee4016 100644
--- a/lib/IR/GCOV.cpp
+++ b/lib/IR/GCOV.cpp
@@ -50,7 +50,7 @@ bool GCOVFile::read(GCOVBuffer &Buffer) {
while (true) {
if (!Buffer.readFunctionTag()) break;
GCOVFunction *GFun = new GCOVFunction();
- if (!GFun->read(Buffer, Format))
+ if (!GFun->readGCNO(Buffer, Format))
return false;
Functions.push_back(GFun);
}
@@ -66,7 +66,7 @@ bool GCOVFile::read(GCOVBuffer &Buffer) {
errs() << "Unexpected number of functions.\n";
return false;
}
- if (!Functions[i]->read(Buffer, Format))
+ if (!Functions[i]->readGCDA(Buffer, Format))
return false;
}
if (Buffer.readObjectTag()) {
@@ -114,52 +114,18 @@ GCOVFunction::~GCOVFunction() {
DeleteContainerPointers(Blocks);
}
-/// read - Read a function from the buffer. Return false if buffer cursor
-/// does not point to a function tag.
-bool GCOVFunction::read(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
+/// readGCNO - Read a function from the GCNO buffer. Return false if an error
+/// occurs.
+bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
uint32_t Dummy;
if (!Buff.readInt(Dummy)) return false; // Function header length
if (!Buff.readInt(Ident)) return false;
if (!Buff.readInt(Dummy)) return false; // Checksum #1
- if (Format != GCOV::GCNO_402 && Format != GCOV::GCDA_402)
+ if (Format != GCOV::GCNO_402)
if (!Buff.readInt(Dummy)) return false; // Checksum #2
if (!Buff.readString(Name)) return false;
-
- if (Format == GCOV::GCNO_402 || Format == GCOV::GCNO_404)
- if (!Buff.readString(Filename)) return false;
-
- if (Format == GCOV::GCDA_402 || Format == GCOV::GCDA_404) {
- if (!Buff.readArcTag()) {
- errs() << "Arc tag not found.\n";
- return false;
- }
- uint32_t Count;
- if (!Buff.readInt(Count)) return false;
- Count /= 2;
-
- // This for loop adds the counts for each block. A second nested loop is
- // required to combine the edge counts that are contained in the GCDA file.
- for (uint32_t Line = 0; Count > 0; ++Line) {
- if (Line >= Blocks.size()) {
- errs() << "Unexpected number of edges.\n";
- return false;
- }
- GCOVBlock &Block = *Blocks[Line];
- for (size_t Edge = 0, End = Block.getNumEdges(); Edge < End; ++Edge) {
- if (Count == 0) {
- errs() << "Unexpected number of edges.\n";
- return false;
- }
- uint64_t ArcCount;
- if (!Buff.readInt64(ArcCount)) return false;
- Block.addCount(ArcCount);
- --Count;
- }
- }
- return true;
- }
-
+ if (!Buff.readString(Filename)) return false;
if (!Buff.readInt(LineNumber)) return false;
// read blocks.
@@ -226,6 +192,48 @@ bool GCOVFunction::read(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
return true;
}
+/// readGCDA - Read a function from the GCDA buffer. Return false if an error
+/// occurs.
+bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
+ uint32_t Dummy;
+ if (!Buff.readInt(Dummy)) return false; // Function header length
+ if (!Buff.readInt(Ident)) return false;
+ if (!Buff.readInt(Dummy)) return false; // Checksum #1
+ if (Format != GCOV::GCDA_402)
+ if (!Buff.readInt(Dummy)) return false; // Checksum #2
+
+ if (!Buff.readString(Name)) return false;
+
+ if (!Buff.readArcTag()) {
+ errs() << "Arc tag not found.\n";
+ return false;
+ }
+ uint32_t Count;
+ if (!Buff.readInt(Count)) return false;
+ Count /= 2;
+
+ // This for loop adds the counts for each block. A second nested loop is
+ // required to combine the edge counts that are contained in the GCDA file.
+ for (uint32_t Line = 0; Count > 0; ++Line) {
+ if (Line >= Blocks.size()) {
+ errs() << "Unexpected number of edges.\n";
+ return false;
+ }
+ GCOVBlock &Block = *Blocks[Line];
+ for (size_t Edge = 0, End = Block.getNumEdges(); Edge < End; ++Edge) {
+ if (Count == 0) {
+ errs() << "Unexpected number of edges.\n";
+ return false;
+ }
+ uint64_t ArcCount;
+ if (!Buff.readInt64(ArcCount)) return false;
+ Block.addCount(ArcCount);
+ --Count;
+ }
+ }
+ return true;
+}
+
/// dump - Dump GCOVFunction content to dbgs() for debugging purposes.
void GCOVFunction::dump() const {
dbgs() << "===== " << Name << " @ " << Filename << ":" << LineNumber << "\n";