clang
15.0.0git
lib
Serialization
PCHContainerOperations.cpp
Go to the documentation of this file.
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
PCHContainerWriter::~PCHContainerWriter
() {}
23
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
: Buffer(
std
::move(Buffer)), OS(
std
::move(OS)) {}
36
37
~RawPCHContainerGenerator()
override
=
default
;
38
39
void
HandleTranslationUnit(
ASTContext
&Ctx)
override
{
40
if
(Buffer->IsComplete) {
41
// Make sure it hits disk now.
42
*OS << Buffer->Data;
43
OS->flush();
44
}
45
// Free the space of the temporary buffer.
46
llvm::SmallVector<char, 0>
Empty;
47
Buffer->Data = std::move(Empty);
48
}
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
std::shared_ptr<PCHBuffer> Buffer)
const
{
57
return
std::make_unique<RawPCHContainerGenerator>(std::move(OS), Buffer);
58
}
59
60
StringRef
61
RawPCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer)
const
{
62
return
Buffer.getBuffer();
63
}
64
65
PCHContainerOperations::PCHContainerOperations
() {
66
registerWriter
(std::make_unique<RawPCHContainerWriter>());
67
registerReader
(std::make_unique<RawPCHContainerReader>());
68
}
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition:
CMakeLists.txt:22
clang::PCHContainerOperations::PCHContainerOperations
PCHContainerOperations()
Automatically registers a RawPCHContainerWriter and RawPCHContainerReader.
Definition:
PCHContainerOperations.cpp:65
llvm::SmallVector< char, 0 >
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition:
ASTContext.h:208
clang::ASTConsumer
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition:
ASTConsumer.h:33
ModuleLoader.h
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition:
CompilerInstance.h:72
clang::PCHContainerOperations::registerReader
void registerReader(std::unique_ptr< PCHContainerReader > Reader)
Definition:
PCHContainerOperations.h:98
clang::PCHContainerWriter::~PCHContainerWriter
virtual ~PCHContainerWriter()=0
Definition:
PCHContainerOperations.cpp:22
clang::PCHContainerOperations::registerWriter
void registerWriter(std::unique_ptr< PCHContainerWriter > Writer)
Definition:
PCHContainerOperations.h:95
ASTConsumer.h
PCHContainerOperations.h
std
Definition:
Format.h:4296
clang
Definition:
CalledOnceCheck.h:17
clang::PCHContainerReader::~PCHContainerReader
virtual ~PCHContainerReader()=0
Definition:
PCHContainerOperations.cpp:23
Generated on Tue May 24 2022 22:10:56 for clang by
1.8.17