aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/PCHWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-27 22:23:34 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-27 22:23:34 +0000
commitab41e63821dc60ad144d0684df8d79a9eef86b75 (patch)
treed6dca3ced09515b1aa4a7e5d024c32c4129bf96b /lib/Frontend/PCHWriter.cpp
parent6bf690fd464b76d35cdf1ac8e4ed693585b36a4d (diff)
Add a header containing the Clang version; make the driver use this
Clang version value rather than hard-coding "1.0". Add PCH and Clang version information into the PCH file. Reject PCH files with the wrong version information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70264 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PCHWriter.cpp')
-rw-r--r--lib/Frontend/PCHWriter.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 817893448a..6b58e25092 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -27,6 +27,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/SourceManagerInternals.h"
#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/Version.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/Bitcode/BitstreamWriter.h"
@@ -341,7 +342,7 @@ void PCHWriter::WriteBlockInfoBlock() {
RECORD(TYPE_OFFSET);
RECORD(DECL_OFFSET);
RECORD(LANGUAGE_OPTIONS);
- RECORD(TARGET_TRIPLE);
+ RECORD(METADATA);
RECORD(IDENTIFIER_OFFSET);
RECORD(IDENTIFIER_TABLE);
RECORD(EXTERNAL_DEFINITIONS);
@@ -440,18 +441,26 @@ void PCHWriter::WriteBlockInfoBlock() {
}
-/// \brief Write the target triple (e.g., i686-apple-darwin9).
-void PCHWriter::WriteTargetTriple(const TargetInfo &Target) {
+/// \brief Write the PCH metadata (e.g., i686-apple-darwin9).
+void PCHWriter::WriteMetadata(const TargetInfo &Target) {
using namespace llvm;
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
- Abbrev->Add(BitCodeAbbrevOp(pch::TARGET_TRIPLE));
- Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Triple name
- unsigned TripleAbbrev = Stream.EmitAbbrev(Abbrev);
+ Abbrev->Add(BitCodeAbbrevOp(pch::METADATA));
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // PCH major
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // PCH minor
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang major
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang minor
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Target triple
+ unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev);
RecordData Record;
- Record.push_back(pch::TARGET_TRIPLE);
+ Record.push_back(pch::METADATA);
+ Record.push_back(pch::VERSION_MAJOR);
+ Record.push_back(pch::VERSION_MINOR);
+ Record.push_back(CLANG_VERSION_MAJOR);
+ Record.push_back(CLANG_VERSION_MINOR);
const char *Triple = Target.getTargetTriple();
- Stream.EmitRecordWithBlob(TripleAbbrev, Record, Triple, strlen(Triple));
+ Stream.EmitRecordWithBlob(AbbrevCode, Record, Triple, strlen(Triple));
}
/// \brief Write the LangOptions structure.
@@ -1672,7 +1681,7 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls) {
// Write the remaining PCH contents.
RecordData Record;
Stream.EnterSubblock(pch::PCH_BLOCK_ID, 4);
- WriteTargetTriple(Context.Target);
+ WriteMetadata(Context.Target);
WriteLanguageOptions(Context.getLangOptions());
if (StatCalls)
WriteStatCache(*StatCalls);