Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Serialization/PCHContainerOperations.h
Line
Count
Source
1
//===--- Serialization/PCHContainerOperations.h - PCH Containers --*- 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
#ifndef LLVM_CLANG_SERIALIZATION_PCHCONTAINEROPERATIONS_H
10
#define LLVM_CLANG_SERIALIZATION_PCHCONTAINEROPERATIONS_H
11
12
#include "clang/Basic/Module.h"
13
#include "llvm/ADT/SmallVector.h"
14
#include "llvm/ADT/StringMap.h"
15
#include "llvm/Support/MemoryBuffer.h"
16
#include <memory>
17
18
namespace llvm {
19
class raw_pwrite_stream;
20
}
21
22
namespace clang {
23
24
class ASTConsumer;
25
class CodeGenOptions;
26
class DiagnosticsEngine;
27
class CompilerInstance;
28
29
struct PCHBuffer {
30
  ASTFileSignature Signature;
31
  llvm::SmallVector<char, 0> Data;
32
  bool IsComplete;
33
};
34
35
/// This abstract interface provides operations for creating
36
/// containers for serialized ASTs (precompiled headers and clang
37
/// modules).
38
class PCHContainerWriter {
39
public:
40
  virtual ~PCHContainerWriter() = 0;
41
  virtual llvm::StringRef getFormat() const = 0;
42
43
  /// Return an ASTConsumer that can be chained with a
44
  /// PCHGenerator that produces a wrapper file format containing a
45
  /// serialized AST bitstream.
46
  virtual std::unique_ptr<ASTConsumer>
47
  CreatePCHContainerGenerator(CompilerInstance &CI,
48
                              const std::string &MainFileName,
49
                              const std::string &OutputFileName,
50
                              std::unique_ptr<llvm::raw_pwrite_stream> OS,
51
                              std::shared_ptr<PCHBuffer> Buffer) const = 0;
52
};
53
54
/// This abstract interface provides operations for unwrapping
55
/// containers for serialized ASTs (precompiled headers and clang
56
/// modules).
57
class PCHContainerReader {
58
public:
59
  virtual ~PCHContainerReader() = 0;
60
  /// Equivalent to the format passed to -fmodule-format=
61
  virtual llvm::StringRef getFormat() const = 0;
62
63
  /// Returns the serialized AST inside the PCH container Buffer.
64
  virtual llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const = 0;
65
};
66
67
/// Implements write operations for a raw pass-through PCH container.
68
class RawPCHContainerWriter : public PCHContainerWriter {
69
48.6k
  llvm::StringRef getFormat() const override { return "raw"; }
70
71
  /// Return an ASTConsumer that can be chained with a
72
  /// PCHGenerator that writes the module to a flat file.
73
  std::unique_ptr<ASTConsumer>
74
  CreatePCHContainerGenerator(CompilerInstance &CI,
75
                              const std::string &MainFileName,
76
                              const std::string &OutputFileName,
77
                              std::unique_ptr<llvm::raw_pwrite_stream> OS,
78
                              std::shared_ptr<PCHBuffer> Buffer) const override;
79
};
80
81
/// Implements read operations for a raw pass-through PCH container.
82
class RawPCHContainerReader : public PCHContainerReader {
83
49.8k
  llvm::StringRef getFormat() const override { return "raw"; }
84
85
  /// Simply returns the buffer contained in Buffer.
86
  llvm::StringRef ExtractPCH(llvm::MemoryBufferRef Buffer) const override;
87
};
88
89
/// A registry of PCHContainerWriter and -Reader objects for different formats.
90
class PCHContainerOperations {
91
  llvm::StringMap<std::unique_ptr<PCHContainerWriter>> Writers;
92
  llvm::StringMap<std::unique_ptr<PCHContainerReader>> Readers;
93
public:
94
  /// Automatically registers a RawPCHContainerWriter and
95
  /// RawPCHContainerReader.
96
  PCHContainerOperations();
97
85.8k
  void registerWriter(std::unique_ptr<PCHContainerWriter> Writer) {
98
85.8k
    Writers[Writer->getFormat()] = std::move(Writer);
99
85.8k
  }
100
85.8k
  void registerReader(std::unique_ptr<PCHContainerReader> Reader) {
101
85.8k
    Readers[Reader->getFormat()] = std::move(Reader);
102
85.8k
  }
103
3.45k
  const PCHContainerWriter *getWriterOrNull(llvm::StringRef Format) {
104
3.45k
    return Writers[Format].get();
105
3.45k
  }
106
51.1k
  const PCHContainerReader *getReaderOrNull(llvm::StringRef Format) {
107
51.1k
    return Readers[Format].get();
108
51.1k
  }
109
1.16k
  const PCHContainerReader &getRawReader() {
110
1.16k
    return *getReaderOrNull("raw");
111
1.16k
  }
112
};
113
114
}
115
116
#endif