diff options
author | Adrian Prantl <aprantl@apple.com> | 2015-06-20 18:53:08 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2015-06-20 18:53:08 +0000 |
commit | bb165fb04db511d0f6927133662b74943f76cc39 (patch) | |
tree | 5c8150e9096c41f7a426c704aa4762e6420cd28e /clang/lib/Frontend/PCHContainerOperations.cpp | |
parent | 6ed81cbcdb6e5f07f6ac71a446d970c2db8945a5 (diff) | |
download | llvm-bb165fb04db511d0f6927133662b74943f76cc39.zip llvm-bb165fb04db511d0f6927133662b74943f76cc39.tar.gz llvm-bb165fb04db511d0f6927133662b74943f76cc39.tar.bz2 |
Introduce a PCHContainerOperations interface (NFC).
A PCHContainerOperations abstract interface provides operations for
creating and unwrapping containers for serialized ASTs (precompiled
headers and clang modules). The default implementation is
RawPCHContainerOperations, which uses a flat file for the output.
The main application for this interface will be an
ObjectFilePCHContainerOperations implementation that uses LLVM to
wrap the module in an ELF/Mach-O/COFF container to store debug info
alongside the AST.
rdar://problem/20091852
llvm-svn: 240225
Diffstat (limited to 'clang/lib/Frontend/PCHContainerOperations.cpp')
-rw-r--r-- | clang/lib/Frontend/PCHContainerOperations.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/clang/lib/Frontend/PCHContainerOperations.cpp b/clang/lib/Frontend/PCHContainerOperations.cpp new file mode 100644 index 0000000..fd3278b --- /dev/null +++ b/clang/lib/Frontend/PCHContainerOperations.cpp @@ -0,0 +1,70 @@ +//===--- Frontend/PCHContainerOperations.cpp - PCH Containers ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines PCHContainerOperations and RawPCHContainerOperation. +// +//===----------------------------------------------------------------------===// + +#include "clang/Frontend/PCHContainerOperations.h" +#include "clang/AST/ASTConsumer.h" +#include "llvm/Bitcode/BitstreamReader.h" +#include "llvm/Support/raw_ostream.h" +#include "clang/Lex/ModuleLoader.h" +using namespace clang; + +PCHContainerOperations::~PCHContainerOperations() {} + +namespace { + +/// \brief A PCHContainerGenerator that writes out the PCH to a flat file. +class PCHContainerGenerator : public ASTConsumer { + std::shared_ptr<PCHBuffer> Buffer; + raw_pwrite_stream *OS; + +public: + PCHContainerGenerator(DiagnosticsEngine &Diags, + const HeaderSearchOptions &HSO, + const PreprocessorOptions &PPO, const TargetOptions &TO, + const LangOptions &LO, const std::string &MainFileName, + const std::string &OutputFileName, + llvm::raw_pwrite_stream *OS, + std::shared_ptr<PCHBuffer> Buffer) + : Buffer(Buffer), OS(OS) {} + + virtual ~PCHContainerGenerator() {} + + void HandleTranslationUnit(ASTContext &Ctx) override { + if (Buffer->IsComplete) { + // Make sure it hits disk now. + *OS << Buffer->Data; + OS->flush(); + } + // Free the space of the temporary buffer. + llvm::SmallVector<char, 0> Empty; + Buffer->Data = std::move(Empty); + } +}; +} + +std::unique_ptr<ASTConsumer> +RawPCHContainerOperations::CreatePCHContainerGenerator( + DiagnosticsEngine &Diags, const HeaderSearchOptions &HSO, + const PreprocessorOptions &PPO, const TargetOptions &TO, + const LangOptions &LO, const std::string &MainFileName, + const std::string &OutputFileName, llvm::raw_pwrite_stream *OS, + std::shared_ptr<PCHBuffer> Buffer) const { + return llvm::make_unique<PCHContainerGenerator>( + Diags, HSO, PPO, TO, LO, MainFileName, OutputFileName, OS, Buffer); +} + +void RawPCHContainerOperations::ExtractPCH( + llvm::MemoryBufferRef Buffer, llvm::BitstreamReader &StreamFile) const { + StreamFile.init((const unsigned char *)Buffer.getBufferStart(), + (const unsigned char *)Buffer.getBufferEnd()); +} |