diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-10 21:16:55 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-10 21:16:55 +0000 |
commit | bfbde53ce12cc14ccfc743b9a796f8d9d4458538 (patch) | |
tree | 1ef6a70fe9070769c8a67de4db570c7f0c6cfee2 /clang/lib/Frontend/PCHWriter.cpp | |
parent | ef52cc6b951007dbf85f4708f6b18b0d4d84f287 (diff) | |
download | bcm5719-llvm-bfbde53ce12cc14ccfc743b9a796f8d9d4458538.tar.gz bcm5719-llvm-bfbde53ce12cc14ccfc743b9a796f8d9d4458538.zip |
Encode the target triple in the PCH file, and check that target triple when using the PCH file
llvm-svn: 68824
Diffstat (limited to 'clang/lib/Frontend/PCHWriter.cpp')
-rw-r--r-- | clang/lib/Frontend/PCHWriter.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/Frontend/PCHWriter.cpp b/clang/lib/Frontend/PCHWriter.cpp index 6feb726b428..a31c0c79855 100644 --- a/clang/lib/Frontend/PCHWriter.cpp +++ b/clang/lib/Frontend/PCHWriter.cpp @@ -21,6 +21,7 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/TargetInfo.h" #include "llvm/Bitcode/BitstreamWriter.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/MemoryBuffer.h" @@ -328,6 +329,21 @@ void PCHDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, // PCHWriter Implementation //===----------------------------------------------------------------------===// +/// \brief Write the target triple (e.g., i686-apple-darwin9). +void PCHWriter::WriteTargetTriple(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 = S.EmitAbbrev(Abbrev); + + RecordData Record; + Record.push_back(pch::TARGET_TRIPLE); + const char *Triple = Target.getTargetTriple(); + S.EmitRecordWithBlob(TripleAbbrev, Record, Triple, strlen(Triple)); +} + +/// \brief Write the LangOptions structure. void PCHWriter::WriteLanguageOptions(const LangOptions &LangOpts) { RecordData Record; Record.push_back(LangOpts.Trigraphs); @@ -815,7 +831,8 @@ void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) { DeclsToEmit.push(Context.getTranslationUnitDecl()); // Write the remaining PCH contents. - S.EnterSubblock(pch::PCH_BLOCK_ID, 2); + S.EnterSubblock(pch::PCH_BLOCK_ID, 3); + WriteTargetTriple(Context.Target); WriteLanguageOptions(Context.getLangOptions()); WriteSourceManagerBlock(Context.getSourceManager()); WritePreprocessor(PP); |