summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-10 18:00:12 +0000
committerChris Lattner <sabre@nondot.org>2009-04-10 18:00:12 +0000
commitbaa52f47c10b8092d1136ac3d55046557e3f4880 (patch)
tree5a46ffb47ebb3fadd7183ed47b91affacdfca865
parent591854d441b9e471591c98bbd38f6eed5e95ce51 (diff)
downloadbcm5719-llvm-baa52f47c10b8092d1136ac3d55046557e3f4880.tar.gz
bcm5719-llvm-baa52f47c10b8092d1136ac3d55046557e3f4880.zip
emit function-like and object-like macros to the PCH file.
Note that we don't do anything useful with identifier infos yet and don't emit the tokens that the macros are defined to. llvm-svn: 68797
-rw-r--r--clang/include/clang/Frontend/PCHBitCodes.h20
-rw-r--r--clang/include/clang/Lex/Preprocessor.h6
-rw-r--r--clang/lib/Frontend/PCHWriter.cpp50
3 files changed, 76 insertions, 0 deletions
diff --git a/clang/include/clang/Frontend/PCHBitCodes.h b/clang/include/clang/Frontend/PCHBitCodes.h
index e4e50e3aa6b..a8257bf0079 100644
--- a/clang/include/clang/Frontend/PCHBitCodes.h
+++ b/clang/include/clang/Frontend/PCHBitCodes.h
@@ -115,6 +115,26 @@ namespace clang {
/// macro instantiation.
SM_SLOC_INSTANTIATION_ENTRY = 4
};
+
+ /// \brief Record types used within a preprocessor block.
+ enum PreprocessorRecordTypes {
+ // The macros in the PP section are a PP_MACRO_* instance followed by a
+ // list of PP_TOKEN instances for each token in the definition.
+
+ /// \brief An object-like macro definition.
+ /// [PP_MACRO_OBJECT_LIKE, IdentInfoID, SLoc, IsUsed]
+ PP_MACRO_OBJECT_LIKE = 1,
+
+ /// \brief A function-like macro definition.
+ /// [PP_MACRO_FUNCTION_LIKE, <ObjectLikeStuff>, IsC99Varargs, IsGNUVarars,
+ /// NumArgs, ArgIdentInfoID* ]
+ PP_MACRO_FUNCTION_LIKE = 2,
+
+ /// \brief Describes one token.
+ /// [PPTOKEN, SLoc, Length, IdentInfoID, Kind, Flags]
+ PP_TOKEN = 3
+ };
+
/// \defgroup PCHAST Precompiled header AST constants
///
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 68cb372c478..f5b4b361a56 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -585,6 +585,12 @@ public:
/// current line until the tok::eom token is found.
void DiscardUntilEndOfDirective();
+ /// SawDateOrTime - This returns true if the preprocessor has seen a use of
+ /// __DATE__ or __TIME__ in the file so far.
+ bool SawDateOrTime() const {
+ return DATELoc != SourceLocation() || TIMELoc != SourceLocation();
+ }
+
private:
void PushIncludeMacroStack() {
diff --git a/clang/lib/Frontend/PCHWriter.cpp b/clang/lib/Frontend/PCHWriter.cpp
index f80d46ab5d9..05447dcd6ac 100644
--- a/clang/lib/Frontend/PCHWriter.cpp
+++ b/clang/lib/Frontend/PCHWriter.cpp
@@ -17,6 +17,8 @@
#include "clang/AST/DeclContextInternals.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/Type.h"
+#include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/Bitcode/BitstreamWriter.h"
@@ -481,8 +483,56 @@ void PCHWriter::WritePreprocessor(Preprocessor &PP) {
// Enter the preprocessor block.
S.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 3);
+ // If the PCH file contains __DATE__ or __TIME__ emit a warning about this.
+ // FIXME: use diagnostics subsystem for localization etc.
+ if (PP.SawDateOrTime())
+ fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n");
+ RecordData Record;
+
+ // Loop over all the macro definitions that are live at the end of the file,
+ // emitting each to the PP section.
+ // FIXME: Eventually we want to emit an index so that we can lazily load
+ // macros.
+ for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
+ I != E; ++I) {
+ MacroInfo *MI = I->second;
+
+ // Don't emit builtin macros like __LINE__ to the PCH file unless they have
+ // been redefined by the header (in which case they are not isBuiltinMacro).
+ if (MI->isBuiltinMacro())
+ continue;
+
+ IdentifierInfo *II = I->first;
+
+ // FIXME: Output the identifier Info ID #!
+ Record.push_back((intptr_t)II);
+ Record.push_back(MI->getDefinitionLoc().getRawEncoding());
+ Record.push_back(MI->isUsed());
+
+ unsigned Code;
+ if (MI->isObjectLike()) {
+ Code = pch::PP_MACRO_OBJECT_LIKE;
+ } else {
+ Code = pch::PP_MACRO_FUNCTION_LIKE;
+
+ Record.push_back(MI->isC99Varargs());
+ Record.push_back(MI->isGNUVarargs());
+ Record.push_back(MI->getNumArgs());
+ for (MacroInfo::arg_iterator I = MI->arg_begin(), E = MI->arg_end();
+ I != E; ++I)
+ // FIXME: Output the identifier Info ID #!
+ Record.push_back((intptr_t)II);
+ }
+ S.EmitRecord(Code, Record);
+ Record.clear();
+ // FIXME: Emit the tokens array.
+
+ }
+
+ // TODO: someday when PP supports __COUNTER__, emit a record for its value if
+ // non-zero.
S.ExitBlock();
}
OpenPOWER on IntegriCloud