summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization/ASTWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-10-18 05:31:06 +0000
committerDouglas Gregor <dgregor@apple.com>2012-10-18 05:31:06 +0000
commit112b907dbb2fe5b22719449ae15e8c3ca10ba44c (patch)
treeccacc1dc847f3bf19ce2cfe4a165c2dd7295016e /clang/lib/Serialization/ASTWriter.cpp
parentb52f717411f0b312ed395fed108a5310bf591ffb (diff)
downloadbcm5719-llvm-112b907dbb2fe5b22719449ae15e8c3ca10ba44c.tar.gz
bcm5719-llvm-112b907dbb2fe5b22719449ae15e8c3ca10ba44c.zip
Start factoring the on-disk records for an AST file into a control
block, which stores information about how the AST file to generated, from the AST block, which stores the actual serialized AST. The information in the control block should be enough to determine whether the AST file is up-to-date and compatible with the current translation unit, and reading it should not cause any side effects that aren't easy to undo. That way, we can back out from an attempt to read an incompatible or out-of-date AST file. Note that there is still more factoring to do. In particular, information about the source files used to generate the AST file (along with their time stamps, sizes, etc.) still resides in the source manager block. llvm-svn: 166166
Diffstat (limited to 'clang/lib/Serialization/ASTWriter.cpp')
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index c37f881d982..b6f302605b1 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -978,11 +978,12 @@ adjustFilenameForRelocatablePCH(const char *Filename, StringRef isysroot) {
return Filename + Pos;
}
-/// \brief Write the AST metadata (e.g., i686-apple-darwin9).
-void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot,
- const std::string &OutputFile) {
+/// \brief Write the control block.
+void ASTWriter::WriteControlBlock(ASTContext &Context, StringRef isysroot,
+ const std::string &OutputFile) {
using namespace llvm;
-
+ Stream.EnterSubblock(CONTROL_BLOCK_ID, 4);
+
// Metadata
const TargetInfo &Target = Context.getTargetInfo();
const TargetOptions &TargetOpts = Target.getTargetOpts();
@@ -1008,6 +1009,7 @@ void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot,
}
Stream.EmitRecord(METADATA, Record);
+ // Imports
if (Chain) {
serialization::ModuleManager &Mgr = Chain->getModuleManager();
llvm::SmallVector<char, 128> ModulePaths;
@@ -1029,6 +1031,22 @@ void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot,
Stream.EmitRecord(IMPORTS, Record);
}
+ // Language options.
+ Record.clear();
+ const LangOptions &LangOpts = Context.getLangOpts();
+#define LANGOPT(Name, Bits, Default, Description) \
+ Record.push_back(LangOpts.Name);
+#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
+ Record.push_back(static_cast<unsigned>(LangOpts.get##Name()));
+#include "clang/Basic/LangOptions.def"
+
+ Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind());
+ AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record);
+
+ Record.push_back(LangOpts.CurrentModule.size());
+ Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end());
+ Stream.EmitRecord(LANGUAGE_OPTIONS, Record);
+
// Original file name and file ID
SourceManager &SM = Context.getSourceManager();
if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
@@ -1079,23 +1097,8 @@ void ASTWriter::WriteMetadata(ASTContext &Context, StringRef isysroot,
Record.push_back(VERSION_CONTROL_BRANCH_REVISION);
Stream.EmitRecordWithBlob(RepoAbbrevCode, Record,
getClangFullRepositoryVersion());
-}
-/// \brief Write the LangOptions structure.
-void ASTWriter::WriteLanguageOptions(const LangOptions &LangOpts) {
- RecordData Record;
-#define LANGOPT(Name, Bits, Default, Description) \
- Record.push_back(LangOpts.Name);
-#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
- Record.push_back(static_cast<unsigned>(LangOpts.get##Name()));
-#include "clang/Basic/LangOptions.def"
-
- Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind());
- AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record);
-
- Record.push_back(LangOpts.CurrentModule.size());
- Record.append(LangOpts.CurrentModule.begin(), LangOpts.CurrentModule.end());
- Stream.EmitRecord(LANGUAGE_OPTIONS, Record);
+ Stream.ExitBlock();
}
//===----------------------------------------------------------------------===//
@@ -3433,12 +3436,13 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
if (!I->second)
AddDeclRef(I->first, KnownNamespaces);
}
-
+
+ // Write the control block
+ WriteControlBlock(Context, isysroot, OutputFile);
+
// Write the remaining AST contents.
RecordData Record;
Stream.EnterSubblock(AST_BLOCK_ID, 5);
- WriteLanguageOptions(Context.getLangOpts());
- WriteMetadata(Context, isysroot, OutputFile);
if (StatCalls && isysroot.empty())
WriteStatCache(*StatCalls);
OpenPOWER on IntegriCloud