summaryrefslogtreecommitdiffstats
path: root/llvm/lib/TableGen
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2019-05-14 13:04:25 +0000
committerTim Northover <tnorthover@apple.com>2019-05-14 13:04:25 +0000
commit717b62a146ae7ea106c520144a20db1aad9d53bb (patch)
treeb98630b95cc876a6f1e974a4b1ba05c14808e4e1 /llvm/lib/TableGen
parent62f5b591f4f3b995f2eb1dec416a8731e5e408d8 (diff)
downloadbcm5719-llvm-717b62a146ae7ea106c520144a20db1aad9d53bb.tar.gz
bcm5719-llvm-717b62a146ae7ea106c520144a20db1aad9d53bb.zip
TableGen: support #ifndef in addition to #ifdef.
TableGen has a limited preprocessor, which only really supports easier. llvm-svn: 360670
Diffstat (limited to 'llvm/lib/TableGen')
-rw-r--r--llvm/lib/TableGen/TGLexer.cpp18
-rw-r--r--llvm/lib/TableGen/TGLexer.h2
2 files changed, 14 insertions, 6 deletions
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index b9420253b2b..d28c62b3133 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -36,6 +36,7 @@ struct {
const char *Word;
} PreprocessorDirs[] = {
{ tgtok::Ifdef, "ifdef" },
+ { tgtok::Ifndef, "ifndef" },
{ tgtok::Else, "else" },
{ tgtok::Endif, "endif" },
{ tgtok::Define, "define" }
@@ -676,21 +677,28 @@ tgtok::TokKind TGLexer::lexPreprocessor(
PrintFatalError("lexPreprocessor() called for unknown "
"preprocessor directive");
- if (Kind == tgtok::Ifdef) {
+ if (Kind == tgtok::Ifdef || Kind == tgtok::Ifndef) {
StringRef MacroName = prepLexMacroName();
+ StringRef IfTokName = Kind == tgtok::Ifdef ? "#ifdef" : "#ifndef";
if (MacroName.empty())
- return ReturnError(TokStart, "Expected macro name after #ifdef");
+ return ReturnError(TokStart, "Expected macro name after " + IfTokName);
bool MacroIsDefined = DefinedMacros.count(MacroName) != 0;
+ // Canonicalize ifndef to ifdef equivalent
+ if (Kind == tgtok::Ifndef) {
+ MacroIsDefined = !MacroIsDefined;
+ Kind = tgtok::Ifdef;
+ }
+
// Regardless of whether we are processing tokens or not,
// we put the #ifdef control on stack.
PrepIncludeStack.back()->push_back(
{Kind, MacroIsDefined, SMLoc::getFromPointer(TokStart)});
if (!prepSkipDirectiveEnd())
- return ReturnError(CurPtr,
- "Only comments are supported after #ifdef NAME");
+ return ReturnError(CurPtr, "Only comments are supported after " +
+ IfTokName + " NAME");
// If we were not processing tokens before this #ifdef,
// then just return back to the lines skipping code.
@@ -714,7 +722,7 @@ tgtok::TokKind TGLexer::lexPreprocessor(
// Check if this #else is correct before calling prepSkipDirectiveEnd(),
// which will move CurPtr away from the beginning of #else.
if (PrepIncludeStack.back()->empty())
- return ReturnError(TokStart, "#else without #ifdef");
+ return ReturnError(TokStart, "#else without #ifdef or #ifndef");
PreprocessorControlDesc IfdefEntry = PrepIncludeStack.back()->back();
diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h
index 4b42d31de53..3085ab2c047 100644
--- a/llvm/lib/TableGen/TGLexer.h
+++ b/llvm/lib/TableGen/TGLexer.h
@@ -65,7 +65,7 @@ namespace tgtok {
// Preprocessing tokens for internal usage by the lexer.
// They are never returned as a result of Lex().
- Ifdef, Else, Endif, Define
+ Ifdef, Ifndef, Else, Endif, Define
};
}
OpenPOWER on IntegriCloud