Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/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
143k
PCHContainerWriter::~PCHContainerWriter() {}
23
143k
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
6.75k
      : Buffer(std::move(Buffer)), OS(std::move(OS)) {}
36
37
6.75k
  ~RawPCHContainerGenerator() override = default;
38
39
6.75k
  void HandleTranslationUnit(ASTContext &Ctx) override {
40
6.75k
    if (Buffer->IsComplete) {
41
      // Make sure it hits disk now.
42
6.68k
      *OS << Buffer->Data;
43
6.68k
      OS->flush();
44
6.68k
    }
45
    // Free the space of the temporary buffer.
46
6.75k
    llvm::SmallVector<char, 0> Empty;
47
6.75k
    Buffer->Data = std::move(Empty);
48
6.75k
  }
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
6.75k
    std::shared_ptr<PCHBuffer> Buffer) const {
57
6.75k
  return std::make_unique<RawPCHContainerGenerator>(std::move(OS), Buffer);
58
6.75k
}
59
60
217k
ArrayRef<llvm::StringRef> RawPCHContainerReader::getFormats() const {
61
217k
  static StringRef Raw("raw");
62
217k
  return ArrayRef(Raw);
63
217k
}
64
65
StringRef
66
919k
RawPCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const {
67
919k
  return Buffer.getBuffer();
68
919k
}
69
70
108k
PCHContainerOperations::PCHContainerOperations() {
71
108k
  registerWriter(std::make_unique<RawPCHContainerWriter>());
72
108k
  registerReader(std::make_unique<RawPCHContainerReader>());
73
108k
}