Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Serialization/PCHContainerOperations.cpp
Line
Count
Source
1
//=== Serialization/PCHContainerOperations.cpp - 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
//  This file defines PCHContainerOperations and RawPCHContainerOperation.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Serialization/PCHContainerOperations.h"
14
#include "clang/AST/ASTConsumer.h"
15
#include "clang/Lex/ModuleLoader.h"
16
#include "llvm/Bitstream/BitstreamReader.h"
17
#include "llvm/Support/raw_ostream.h"
18
#include <utility>
19
20
using namespace clang;
21
22
56.9k
PCHContainerWriter::~PCHContainerWriter() {}
23
56.9k
PCHContainerReader::~PCHContainerReader() {}
24
25
namespace {
26
27
/// A PCHContainerGenerator that writes out the PCH to a flat file.
28
class RawPCHContainerGenerator : public ASTConsumer {
29
  std::shared_ptr<PCHBuffer> Buffer;
30
  std::unique_ptr<raw_pwrite_stream> OS;
31
32
public:
33
  RawPCHContainerGenerator(std::unique_ptr<llvm::raw_pwrite_stream> OS,
34
                           std::shared_ptr<PCHBuffer> Buffer)
35
3.43k
      : Buffer(std::move(Buffer)), OS(std::move(OS)) {}
36
37
3.43k
  ~RawPCHContainerGenerator() override = default;
38
39
3.42k
  void HandleTranslationUnit(ASTContext &Ctx) override {
40
3.42k
    if (Buffer->IsComplete) {
41
3.39k
      // Make sure it hits disk now.
42
3.39k
      *OS << Buffer->Data;
43
3.39k
      OS->flush();
44
3.39k
    }
45
3.42k
    // Free the space of the temporary buffer.
46
3.42k
    llvm::SmallVector<char, 0> Empty;
47
3.42k
    Buffer->Data = std::move(Empty);
48
3.42k
  }
49
};
50
51
} // anonymous namespace
52
53
std::unique_ptr<ASTConsumer> RawPCHContainerWriter::CreatePCHContainerGenerator(
54
    CompilerInstance &CI, const std::string &MainFileName,
55
    const std::string &OutputFileName, std::unique_ptr<llvm::raw_pwrite_stream> OS,
56
3.43k
    std::shared_ptr<PCHBuffer> Buffer) const {
57
3.43k
  return llvm::make_unique<RawPCHContainerGenerator>(std::move(OS), Buffer);
58
3.43k
}
59
60
StringRef
61
16.0k
RawPCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const {
62
16.0k
  return Buffer.getBuffer();
63
16.0k
}
64
65
48.6k
PCHContainerOperations::PCHContainerOperations() {
66
48.6k
  registerWriter(llvm::make_unique<RawPCHContainerWriter>());
67
48.6k
  registerReader(llvm::make_unique<RawPCHContainerReader>());
68
48.6k
}