mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-17 22:00:41 +00:00

to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
//=== Serialization/PCHContainerOperations.cpp - PCH Containers -*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines PCHContainerOperations and RawPCHContainerOperation.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Serialization/PCHContainerOperations.h"
|
|
#include "clang/AST/ASTConsumer.h"
|
|
#include "clang/Lex/ModuleLoader.h"
|
|
#include "llvm/Bitcode/BitstreamReader.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include <utility>
|
|
|
|
using namespace clang;
|
|
|
|
PCHContainerWriter::~PCHContainerWriter() {}
|
|
PCHContainerReader::~PCHContainerReader() {}
|
|
|
|
namespace {
|
|
|
|
/// A PCHContainerGenerator that writes out the PCH to a flat file.
|
|
class RawPCHContainerGenerator : public ASTConsumer {
|
|
std::shared_ptr<PCHBuffer> Buffer;
|
|
std::unique_ptr<raw_pwrite_stream> OS;
|
|
|
|
public:
|
|
RawPCHContainerGenerator(std::unique_ptr<llvm::raw_pwrite_stream> OS,
|
|
std::shared_ptr<PCHBuffer> Buffer)
|
|
: Buffer(std::move(Buffer)), OS(std::move(OS)) {}
|
|
|
|
~RawPCHContainerGenerator() override = default;
|
|
|
|
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);
|
|
}
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
std::unique_ptr<ASTConsumer> RawPCHContainerWriter::CreatePCHContainerGenerator(
|
|
CompilerInstance &CI, const std::string &MainFileName,
|
|
const std::string &OutputFileName, std::unique_ptr<llvm::raw_pwrite_stream> OS,
|
|
std::shared_ptr<PCHBuffer> Buffer) const {
|
|
return llvm::make_unique<RawPCHContainerGenerator>(std::move(OS), Buffer);
|
|
}
|
|
|
|
StringRef
|
|
RawPCHContainerReader::ExtractPCH(llvm::MemoryBufferRef Buffer) const {
|
|
return Buffer.getBuffer();
|
|
}
|
|
|
|
PCHContainerOperations::PCHContainerOperations() {
|
|
registerWriter(llvm::make_unique<RawPCHContainerWriter>());
|
|
registerReader(llvm::make_unique<RawPCHContainerReader>());
|
|
}
|