[cfe-commits] r68798 - in /cfe/trunk: include/clang/Frontend/PCHWriter.h lib/Frontend/PCHWriter.cpp tools/clang-cc/ASTConsumers.h tools/clang-cc/GeneratePCH.cpp
Chris Lattner
sabre at nondot.org
Fri Apr 10 11:08:30 PDT 2009
Author: lattner
Date: Fri Apr 10 13:08:30 2009
New Revision: 68798
URL: http://llvm.org/viewvc/llvm-project?rev=68798&view=rev
Log:
emit tokens, constify the Preprocessor passed down into PCH writer.
Modified:
cfe/trunk/include/clang/Frontend/PCHWriter.h
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/tools/clang-cc/ASTConsumers.h
cfe/trunk/tools/clang-cc/GeneratePCH.cpp
Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=68798&r1=68797&r2=68798&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHWriter.h Fri Apr 10 13:08:30 2009
@@ -77,7 +77,7 @@
pch::TypeID NextTypeID;
void WriteSourceManagerBlock(SourceManager &SourceMgr);
- void WritePreprocessor(Preprocessor &PP);
+ void WritePreprocessor(const Preprocessor &PP);
void WriteType(const Type *T);
void WriteTypesBlock(ASTContext &Context);
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
@@ -92,7 +92,7 @@
PCHWriter(llvm::BitstreamWriter &S);
/// \brief Write a precompiled header for the given AST context.
- void WritePCH(ASTContext &Context, Preprocessor &PP);
+ void WritePCH(ASTContext &Context, const Preprocessor &PP);
/// \brief Emit a source location.
void AddSourceLocation(SourceLocation Loc, RecordData &Record);
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=68798&r1=68797&r2=68798&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Apr 10 13:08:30 2009
@@ -479,7 +479,7 @@
/// \brief Writes the block containing the serialized form of the
/// preprocessor.
///
-void PCHWriter::WritePreprocessor(Preprocessor &PP) {
+void PCHWriter::WritePreprocessor(const Preprocessor &PP) {
// Enter the preprocessor block.
S.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 3);
@@ -527,7 +527,29 @@
S.EmitRecord(Code, Record);
Record.clear();
- // FIXME: Emit the tokens array.
+ // Emit the tokens array.
+ for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) {
+ // Note that we know that the preprocessor does not have any annotation
+ // tokens in it because they are created by the parser, and thus can't be
+ // in a macro definition.
+ const Token &Tok = MI->getReplacementToken(TokNo);
+
+ Record.push_back(Tok.getLocation().getRawEncoding());
+ Record.push_back(Tok.getLength());
+
+ // FIXME: Output the identifier Info ID #!
+ // FIXME: When reading literal tokens, reconstruct the literal pointer if
+ // it is needed.
+ Record.push_back((intptr_t)Tok.getIdentifierInfo());
+
+ // FIXME: Should translate token kind to a stable encoding.
+ Record.push_back(Tok.getKind());
+ // FIXME: Should translate token flags to a stable encoding.
+ Record.push_back(Tok.getFlags());
+
+ S.EmitRecord(pch::PP_TOKEN, Record);
+ Record.clear();
+ }
}
@@ -719,7 +741,7 @@
PCHWriter::PCHWriter(llvm::BitstreamWriter &S)
: S(S), NextTypeID(pch::NUM_PREDEF_TYPE_IDS) { }
-void PCHWriter::WritePCH(ASTContext &Context, Preprocessor &PP) {
+void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) {
// Emit the file header.
S.Emit((unsigned)'C', 8);
S.Emit((unsigned)'P', 8);
Modified: cfe/trunk/tools/clang-cc/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/ASTConsumers.h?rev=68798&r1=68797&r2=68798&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/ASTConsumers.h (original)
+++ cfe/trunk/tools/clang-cc/ASTConsumers.h Fri Apr 10 13:08:30 2009
@@ -68,7 +68,7 @@
const std::string &EmitDir,
Diagnostic &Diags);
-ASTConsumer *CreatePCHGenerator(Preprocessor &PP,
+ASTConsumer *CreatePCHGenerator(const Preprocessor &PP,
const std::string &OutFile);
ASTConsumer *CreateBlockRewriter(const std::string &InFile,
Modified: cfe/trunk/tools/clang-cc/GeneratePCH.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/GeneratePCH.cpp?rev=68798&r1=68797&r2=68798&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/GeneratePCH.cpp (original)
+++ cfe/trunk/tools/clang-cc/GeneratePCH.cpp Fri Apr 10 13:08:30 2009
@@ -29,11 +29,11 @@
namespace {
class VISIBILITY_HIDDEN PCHGenerator : public ASTConsumer {
- Preprocessor &PP;
+ const Preprocessor &PP;
std::string OutFile;
public:
- explicit PCHGenerator(Preprocessor &PP, const std::string &OutFile)
+ explicit PCHGenerator(const Preprocessor &PP, const std::string &OutFile)
: PP(PP), OutFile(OutFile) { }
virtual void HandleTranslationUnit(ASTContext &Ctx);
@@ -68,7 +68,7 @@
Out.flush();
}
-ASTConsumer *clang::CreatePCHGenerator(Preprocessor &PP,
+ASTConsumer *clang::CreatePCHGenerator(const Preprocessor &PP,
const std::string &OutFile) {
return new PCHGenerator(PP, OutFile);
}
More information about the cfe-commits
mailing list