Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Remarks/RemarkStringTable.h
Line
Count
Source
1
//===-- RemarkStringTable.h - Serializing string table ----------*- C++/-*-===//
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
// This class is used to deduplicate and serialize a string table used for
10
// generating remarks.
11
//
12
// For parsing a string table, use ParsedStringTable in RemarkParser.h
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_REMARKS_REMARK_STRING_TABLE_H
17
#define LLVM_REMARKS_REMARK_STRING_TABLE_H
18
19
#include "llvm/ADT/StringMap.h"
20
#include "llvm/ADT/StringRef.h"
21
#include "llvm/Remarks/RemarkParser.h"
22
#include <vector>
23
24
namespace llvm {
25
26
class raw_ostream;
27
28
namespace remarks {
29
30
/// The string table used for serializing remarks.
31
/// This table can be for example serialized in a section to be consumed after
32
/// the compilation.
33
struct StringTable {
34
  /// The string table containing all the unique strings used in the output.
35
  /// It maps a string to an unique ID.
36
  StringMap<unsigned, BumpPtrAllocator> StrTab;
37
  /// Total size of the string table when serialized.
38
  size_t SerializedSize = 0;
39
40
2
  StringTable() = default;
41
42
  /// Disable copy.
43
  StringTable(const StringTable &) = delete;
44
  StringTable &operator=(const StringTable &) = delete;
45
  /// Should be movable.
46
  StringTable(StringTable &&) = default;
47
  StringTable &operator=(StringTable &&) = default;
48
49
  /// Construct a string table from a ParsedStringTable.
50
  StringTable(const ParsedStringTable &Other);
51
52
  /// Add a string to the table. It returns an unique ID of the string.
53
  std::pair<unsigned, StringRef> add(StringRef Str);
54
  /// Serialize the string table to a stream. It is serialized as a little
55
  /// endian uint64 (the size of the table in bytes) followed by a sequence of
56
  /// NULL-terminated strings, where the N-th string is the string with the ID N
57
  /// in the StrTab map.
58
  void serialize(raw_ostream &OS) const;
59
  /// Serialize the string table to a vector. This allows users to do the actual
60
  /// writing to file/memory/other.
61
  /// The string with the ID == N should be the N-th element in the vector.
62
  std::vector<StringRef> serialize() const;
63
};
64
65
} // end namespace remarks
66
} // end namespace llvm
67
68
#endif /* LLVM_REMARKS_REMARK_STRING_TABLE_H */