Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 9f65c56

Browse files
committed
Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230454 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d68bbb9 commit 9f65c56

File tree

83 files changed

+91
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+91
-456
lines changed

docs/PCHInternals.rst

-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ be included at the beginning of the translation unit. The extensions to the
6565
AST file format required for modules are discussed in the section on
6666
:ref:`modules <pchinternals-modules>`.
6767

68-
Clang's AST files are Mach-O, ELF, or COFF containers that contain a
69-
``__clangast`` section which holds the AST bitstream.
70-
7168
Clang's AST files are designed with a compact on-disk representation, which
7269
minimizes both creation time and the time required to initially load the AST
7370
file. The AST file itself contains a serialized representation of Clang's

include/clang/CodeGen/CodeGenModuleContainer.h

-34
This file was deleted.

include/clang/Frontend/FrontendActions.h

-8
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@ class DeclContextPrintAction : public ASTFrontendAction {
6969
StringRef InFile) override;
7070
};
7171

72-
/// \brief Emits the output of a GeneratePCHAction or GenerateModuleAction into
73-
/// a Mach-O/ELF/COFF container.
74-
class GeneratePCMContainerAction : public FrontendAction {
75-
protected:
76-
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
77-
StringRef InFile) override;
78-
};
79-
8072
class GeneratePCHAction : public ASTFrontendAction {
8173
protected:
8274
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,

include/clang/Serialization/ASTReader.h

-4
Original file line numberDiff line numberDiff line change
@@ -1127,10 +1127,6 @@ class ASTReader
11271127
public:
11281128
void ResolveImportedPath(ModuleFile &M, std::string &Filename);
11291129
static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1130-
/// \brief Initialize a BitstreamReader with the `__clangast` section from an
1131-
/// object file container found in Buffer.
1132-
static void InitStreamFileWithModule(llvm::MemoryBufferRef Buffer,
1133-
llvm::BitstreamReader &StreamFile);
11341130

11351131
private:
11361132
struct ImportedModule {

include/clang/Serialization/ASTWriter.h

+5-13
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,10 @@ class PCHGenerator : public SemaConsumer {
823823
std::string OutputFile;
824824
clang::Module *Module;
825825
std::string isysroot;
826+
raw_ostream *Out;
826827
Sema *SemaPtr;
827-
// This buffer is always large, but BitstreamWriter really wants a
828-
// SmallVectorImpl<char>.
829-
SmallVector<char, 0> Buffer;
828+
SmallVector<char, 128> Buffer;
830829
llvm::BitstreamWriter Stream;
831-
std::function<void(SmallVectorImpl<char>*)>
832-
SerializationFinishedCallback;
833830
ASTWriter Writer;
834831
bool AllowASTWithErrors;
835832
bool HasEmittedPCH;
@@ -839,21 +836,16 @@ class PCHGenerator : public SemaConsumer {
839836
const ASTWriter &getWriter() const { return Writer; }
840837

841838
public:
842-
PCHGenerator(const Preprocessor &PP,
843-
StringRef OutputFile,
839+
PCHGenerator(const Preprocessor &PP, StringRef OutputFile,
844840
clang::Module *Module,
845-
StringRef isysroot,
841+
StringRef isysroot, raw_ostream *Out,
846842
bool AllowASTWithErrors = false);
847843
~PCHGenerator();
848844
void InitializeSema(Sema &S) override { SemaPtr = &S; }
849845
void HandleTranslationUnit(ASTContext &Ctx) override;
850846
ASTMutationListener *GetASTMutationListener() override;
851847
ASTDeserializationListener *GetASTDeserializationListener() override;
852-
/// \brief Register a callback to be invoked when the serialization is done.
853-
void RegisterSerializationFinishedCallback(
854-
const std::function<void(SmallVectorImpl<char>*)> Fn) {
855-
SerializationFinishedCallback = Fn;
856-
}
848+
857849
bool hasEmittedPCH() const { return HasEmittedPCH; }
858850
};
859851

lib/CodeGen/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(LLVM_LINK_COMPONENTS
2-
${LLVM_TARGETS_TO_BUILD}
32
Analysis
43
BitReader
54
BitWriter
@@ -64,7 +63,6 @@ add_clang_library(clangCodeGen
6463
CodeGenAction.cpp
6564
CodeGenFunction.cpp
6665
CodeGenModule.cpp
67-
CodeGenModuleContainer.cpp
6866
CodeGenPGO.cpp
6967
CodeGenTBAA.cpp
7068
CodeGenTypes.cpp

lib/CodeGen/CodeGenModuleContainer.cpp

-150
This file was deleted.

lib/Frontend/ASTUnit.cpp

+2-16
Original file line numberDiff line numberDiff line change
@@ -914,20 +914,13 @@ class PrecompilePreambleConsumer : public PCHGenerator {
914914
unsigned &Hash;
915915
std::vector<Decl *> TopLevelDecls;
916916
PrecompilePreambleAction *Action;
917-
raw_ostream *Out;
918-
SmallVectorImpl<char> *SerializedASTBuffer;
919917

920918
public:
921919
PrecompilePreambleConsumer(ASTUnit &Unit, PrecompilePreambleAction *Action,
922920
const Preprocessor &PP, StringRef isysroot,
923921
raw_ostream *Out)
924-
: PCHGenerator(PP, "", nullptr, isysroot, /*AllowASTWithErrors=*/true),
925-
Unit(Unit), Hash(Unit.getCurrentTopLevelHashValue()), Action(Action),
926-
Out(Out) {
927-
RegisterSerializationFinishedCallback(
928-
[&](SmallVectorImpl<char> *Buf){
929-
SerializedASTBuffer = Buf;
930-
});
922+
: PCHGenerator(PP, "", nullptr, isysroot, Out, /*AllowASTWithErrors=*/true),
923+
Unit(Unit), Hash(Unit.getCurrentTopLevelHashValue()), Action(Action) {
931924
Hash = 0;
932925
}
933926

@@ -948,13 +941,6 @@ class PrecompilePreambleConsumer : public PCHGenerator {
948941
void HandleTranslationUnit(ASTContext &Ctx) override {
949942
PCHGenerator::HandleTranslationUnit(Ctx);
950943
if (hasEmittedPCH()) {
951-
// Write the generated bitstream to "Out".
952-
Out->write((char *)&SerializedASTBuffer->front(),
953-
SerializedASTBuffer->size());
954-
// Make sure it hits disk now.
955-
Out->flush();
956-
SerializedASTBuffer->clear();
957-
958944
// Translate the top-level declarations we captured during
959945
// parsing into declaration IDs in the precompiled
960946
// preamble. This will allow us to deserialize those top-level

lib/Frontend/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ add_clang_library(clangFrontend
4545
LINK_LIBS
4646
clangAST
4747
clangBasic
48-
clangCodeGen
4948
clangDriver
5049
clangEdit
5150
clangLex

lib/Frontend/ChainedIncludesSource.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,11 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
156156
&Clang->getPreprocessor());
157157
Clang->createASTContext();
158158

159-
auto consumer = llvm::make_unique<PCHGenerator>(Clang->getPreprocessor(),
160-
"-", nullptr, /*isysroot=*/"");
161-
SmallVectorImpl<char> *serialAST;
162-
consumer->RegisterSerializationFinishedCallback(
163-
[&](SmallVectorImpl<char> *Buf){
164-
serialAST = Buf;
165-
});
159+
SmallVector<char, 256> serialAST;
160+
llvm::raw_svector_ostream OS(serialAST);
161+
auto consumer =
162+
llvm::make_unique<PCHGenerator>(Clang->getPreprocessor(), "-", nullptr,
163+
/*isysroot=*/"", &OS);
166164
Clang->getASTContext().setASTMutationListener(
167165
consumer->GetASTMutationListener());
168166
Clang->setASTConsumer(std::move(consumer));
@@ -199,9 +197,7 @@ IntrusiveRefCntPtr<ExternalSemaSource> clang::createChainedIncludesSource(
199197

200198
ParseAST(Clang->getSema());
201199
Clang->getDiagnosticClient().EndSourceFile();
202-
SerialBufs.push_back(llvm::MemoryBuffer::
203-
getMemBufferCopy(StringRef(serialAST->data(), serialAST->size())));
204-
serialAST->clear();
200+
SerialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(OS.str()));
205201
source->CIs.push_back(Clang.release());
206202
}
207203

0 commit comments

Comments
 (0)