Coverage Report

Created: 2018-11-16 02:38

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