Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Remarks/RemarkStringTable.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- RemarkStringTable.cpp ----------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// Implementation of the Remark string table used at remark generation.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/Remarks/RemarkStringTable.h"
14
#include "llvm/Remarks/RemarkParser.h"
15
#include "llvm/Support/EndianStream.h"
16
#include "llvm/Support/Error.h"
17
#include <vector>
18
19
using namespace llvm;
20
using namespace llvm::remarks;
21
22
0
StringTable::StringTable(const ParsedStringTable &Other) : StrTab() {
23
0
  for (unsigned i = 0, e = Other.size(); i < e; ++i)
24
0
    if (Expected<StringRef> MaybeStr = Other[i])
25
0
      add(*MaybeStr);
26
0
    else
27
0
      llvm_unreachable("Unexpected error while building remarks string table.");
28
0
}
29
30
17
std::pair<unsigned, StringRef> StringTable::add(StringRef Str) {
31
17
  size_t NextID = StrTab.size();
32
17
  auto KV = StrTab.insert({Str, NextID});
33
17
  // If it's a new string, add it to the final size.
34
17
  if (KV.second)
35
16
    SerializedSize += KV.first->first().size() + 1; // +1 for the '\0'
36
17
  // Can be either NextID or the previous ID if the string is already there.
37
17
  return {KV.first->second, KV.first->first()};
38
17
}
39
40
1
void StringTable::serialize(raw_ostream &OS) const {
41
1
  // Emit the sequence of strings.
42
7
  for (StringRef Str : serialize()) {
43
7
    OS << Str;
44
7
    // Explicitly emit a '\0'.
45
7
    OS.write('\0');
46
7
  }
47
1
}
48
49
2
std::vector<StringRef> StringTable::serialize() const {
50
2
  std::vector<StringRef> Strings{StrTab.size()};
51
2
  for (const auto &KV : StrTab)
52
16
    Strings[KV.second] = KV.first();
53
2
  return Strings;
54
2
}