Skip to content

Commit

Permalink
Update GCOVLines to provide interfaces to write line table and calcul…
Browse files Browse the repository at this point in the history
…ate complete length.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140167 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Devang Patel committed Sep 20, 2011
1 parent f34fa6f commit 16c19a1
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lib/Transforms/Instrumentation/GCOVProfiling.cpp
Expand Up @@ -158,25 +158,34 @@ namespace {
class GCOVBlock;

// Constructed only by requesting it from a GCOVBlock, this object stores a
// list of line numbers representing lines that belong to the block.
// list of line numbers and a single filename, representing lines that belong
// to the block.
class GCOVLines : public GCOVRecord {
public:
void addLine(uint32_t Line) {
Lines.push_back(Line);
}

uint32_t length() {
// FIXME: ??? What is the significance of 2 here ?
return 2 + Lines.size();
// Here 2 = 1 for string lenght + 1 for '0' id#.
return lengthOfGCOVString(Filename) + 2 + Lines.size();
}

void writeOut() {
write(0);
writeGCOVString(Filename);
for (int i = 0, e = Lines.size(); i != e; ++i)
write(Lines[i]);
}
private:
friend class GCOVBlock;

GCOVLines(raw_ostream *os) {
GCOVLines(StringRef F, raw_ostream *os)
: Filename(F) {
this->os = os;
}

StringRef Filename;
SmallVector<uint32_t, 32> Lines;
};

Expand All @@ -188,7 +197,7 @@ namespace {
GCOVLines &getFile(StringRef Filename) {
GCOVLines *&Lines = LinesByFile[Filename];
if (!Lines) {
Lines = new GCOVLines(os);
Lines = new GCOVLines(Filename, os);
}
return *Lines;
}
Expand All @@ -201,20 +210,15 @@ namespace {
uint32_t Len = 3;
for (StringMap<GCOVLines *>::iterator I = LinesByFile.begin(),
E = LinesByFile.end(); I != E; ++I) {
Len = Len + lengthOfGCOVString(I->first()) + I->second->length();
Len += I->second->length();
}

writeBytes(LinesTag, 4);
write(Len);
write(Number);
for (StringMap<GCOVLines *>::iterator I = LinesByFile.begin(),
E = LinesByFile.end(); I != E; ++I) {
write(0);
writeGCOVString(I->first());
for (int i = 0, e = I->second->Lines.size(); i != e; ++i) {
write(I->second->Lines[i]);
}
}
E = LinesByFile.end(); I != E; ++I)
I->second->writeOut();
write(0);
write(0);
}
Expand Down

0 comments on commit 16c19a1

Please sign in to comment.