Simplify the interface of PCHContainerGenerator and friends

by passing in a CompilerInstance instead of all its individual members.

NFC.

llvm-svn: 248053
This commit is contained in:
Adrian Prantl 2015-09-18 22:10:59 +00:00
parent e0e0796d83
commit 0391406e95
5 changed files with 31 additions and 54 deletions

View File

@ -23,10 +23,9 @@ class ObjectFilePCHContainerWriter : public PCHContainerWriter {
/// PCHGenerator that produces a wrapper file format
/// that also contains full debug info for the module.
std::unique_ptr<ASTConsumer> 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,
DiagnosticsEngine &Diags, const CompilerInstance &CI,
const std::string &MainFileName, const std::string &OutputFileName,
llvm::raw_pwrite_stream *OS,
std::shared_ptr<PCHBuffer> Buffer) const override;
};

View File

@ -27,10 +27,7 @@ namespace clang {
class ASTConsumer;
class CodeGenOptions;
class DiagnosticsEngine;
class HeaderSearchOptions;
class LangOptions;
class PreprocessorOptions;
class TargetOptions;
class CompilerInstance;
struct PCHBuffer {
bool IsComplete;
@ -49,11 +46,9 @@ public:
/// PCHGenerator that produces a wrapper file format containing a
/// serialized AST bitstream.
virtual std::unique_ptr<ASTConsumer> 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 = 0;
DiagnosticsEngine &Diags, const CompilerInstance &CI,
const std::string &MainFileName, const std::string &OutputFileName,
llvm::raw_pwrite_stream *OS, std::shared_ptr<PCHBuffer> Buffer) const = 0;
};
/// This abstract interface provides operations for unwrapping
@ -78,10 +73,9 @@ class RawPCHContainerWriter : public PCHContainerWriter {
/// Return an ASTConsumer that can be chained with a
/// PCHGenerator that writes the module to a flat file.
std::unique_ptr<ASTConsumer> 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,
DiagnosticsEngine &Diags, const CompilerInstance &CI,
const std::string &MainFileName, const std::string &OutputFileName,
llvm::raw_pwrite_stream *OS,
std::shared_ptr<PCHBuffer> Buffer) const override;
};

View File

@ -18,6 +18,7 @@
#include "clang/Basic/TargetInfo.h"
#include "clang/CodeGen/BackendUtil.h"
#include "clang/Frontend/CodeGenOptions.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Serialization/ASTWriter.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Bitcode/BitstreamReader.h"
@ -115,15 +116,15 @@ class PCHContainerGenerator : public ASTConsumer {
};
public:
PCHContainerGenerator(DiagnosticsEngine &diags,
const HeaderSearchOptions &HSO,
const PreprocessorOptions &PPO, const TargetOptions &TO,
const LangOptions &LO, const std::string &MainFileName,
PCHContainerGenerator(DiagnosticsEngine &diags, const CompilerInstance &CI,
const std::string &MainFileName,
const std::string &OutputFileName,
raw_pwrite_stream *OS,
std::shared_ptr<PCHBuffer> Buffer)
: Diags(diags), Ctx(nullptr), HeaderSearchOpts(HSO), PreprocessorOpts(PPO),
TargetOpts(TO), LangOpts(LO), OS(OS), Buffer(Buffer) {
: Diags(diags), Ctx(nullptr), HeaderSearchOpts(CI.getHeaderSearchOpts()),
PreprocessorOpts(CI.getPreprocessorOpts()),
TargetOpts(CI.getTargetOpts()), LangOpts(CI.getLangOpts()), OS(OS),
Buffer(Buffer) {
// The debug info output isn't affected by CodeModel and
// ThreadModel, but the backend expects them to be nonempty.
CodeGenOpts.CodeModel = "default";
@ -252,13 +253,11 @@ public:
std::unique_ptr<ASTConsumer>
ObjectFilePCHContainerWriter::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);
DiagnosticsEngine &Diags, const CompilerInstance &CI,
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, CI, MainFileName,
OutputFileName, OS, Buffer);
}
void ObjectFilePCHContainerReader::ExtractPCH(

View File

@ -92,11 +92,8 @@ GeneratePCHAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Consumers.push_back(llvm::make_unique<PCHGenerator>(
CI.getPreprocessor(), OutputFile, nullptr, Sysroot, Buffer));
Consumers.push_back(
CI.getPCHContainerWriter().CreatePCHContainerGenerator(
CI.getDiagnostics(), CI.getHeaderSearchOpts(),
CI.getPreprocessorOpts(), CI.getTargetOpts(), CI.getLangOpts(),
InFile, OutputFile, OS, Buffer));
Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
CI.getDiagnostics(), CI, InFile, OutputFile, OS, Buffer));
return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
}
@ -140,11 +137,8 @@ GenerateModuleAction::CreateASTConsumer(CompilerInstance &CI,
CI.getPreprocessor(), OutputFile, Module, Sysroot, Buffer,
/*AllowASTWithErrors*/false,
/*IncludeTimestamps*/+CI.getFrontendOpts().BuildingImplicitModule));
Consumers.push_back(
CI.getPCHContainerWriter().CreatePCHContainerGenerator(
CI.getDiagnostics(), CI.getHeaderSearchOpts(),
CI.getPreprocessorOpts(), CI.getTargetOpts(), CI.getLangOpts(),
InFile, OutputFile, OS, Buffer));
Consumers.push_back(CI.getPCHContainerWriter().CreatePCHContainerGenerator(
CI.getDiagnostics(), CI, InFile, OutputFile, OS, Buffer));
return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
}

View File

@ -27,13 +27,7 @@ class RawPCHContainerGenerator : public ASTConsumer {
raw_pwrite_stream *OS;
public:
RawPCHContainerGenerator(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,
RawPCHContainerGenerator(llvm::raw_pwrite_stream *OS,
std::shared_ptr<PCHBuffer> Buffer)
: Buffer(Buffer), OS(OS) {}
@ -54,13 +48,10 @@ public:
} // anonymous namespace
std::unique_ptr<ASTConsumer> RawPCHContainerWriter::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<RawPCHContainerGenerator>(
Diags, HSO, PPO, TO, LO, MainFileName, OutputFileName, OS, Buffer);
DiagnosticsEngine &Diags, const CompilerInstance &CI,
const std::string &MainFileName, const std::string &OutputFileName,
llvm::raw_pwrite_stream *OS, std::shared_ptr<PCHBuffer> Buffer) const {
return llvm::make_unique<RawPCHContainerGenerator>(OS, Buffer);
}
void RawPCHContainerReader::ExtractPCH(