[clang-tools-extra] dc63ad8 - [pseudo] Eliminate dependencies from clang-pseudo-gen. NFC
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 3 11:42:48 PDT 2022
Author: Sam McCall
Date: 2022-06-03T20:42:38+02:00
New Revision: dc63ad8878de6d0b5dc1268691f48035e9234763
URL: https://github.com/llvm/llvm-project/commit/dc63ad8878de6d0b5dc1268691f48035e9234763
DIFF: https://github.com/llvm/llvm-project/commit/dc63ad8878de6d0b5dc1268691f48035e9234763.diff
LOG: [pseudo] Eliminate dependencies from clang-pseudo-gen. NFC
ClangBasic dependency eliminated by replacing our usage of
tok::getPunctuatorSpelling etc with direct use of the *.def file.
Implicit dependencies on clang-tablegen-targets removed as we manage to avoid
any transitive tablegen deps.
After these changes, `ninja clean; ninja pseudo-gen` runs 169 actions only
(basically Support and Demangle).
Differential Revision: https://reviews.llvm.org/D126731
Added:
Modified:
clang-tools-extra/pseudo/gen/CMakeLists.txt
clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/pseudo/gen/CMakeLists.txt b/clang-tools-extra/pseudo/gen/CMakeLists.txt
index a104e05b53da9..25c7596c754f7 100644
--- a/clang-tools-extra/pseudo/gen/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/gen/CMakeLists.txt
@@ -1,4 +1,5 @@
set(LLVM_LINK_COMPONENTS Support)
+list(REMOVE_ITEM LLVM_COMMON_DEPENDS clang-tablegen-targets)
add_clang_executable(pseudo-gen
Main.cpp
diff --git a/clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt b/clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
index d50cb7df2a2cc..f7ada93eeb60b 100644
--- a/clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
@@ -1,18 +1,15 @@
set(LLVM_LINK_COMPONENTS Support)
-# This library intents to keep as minimal dependencies as possible, it is a base
-# library of the cxx generator, to avoid creating long dep paths in the build
-# graph.
+# This library is used by the clang-pseudo-gen tool which runs at build time.
+# Dependencies should be minimal to avoid long dep paths in the build graph.
+# It does use clangBasic headers (tok::TokenKind), but linking is not needed.
+# We have no transitive dependencies on tablegen files.
+list(REMOVE_ITEM LLVM_COMMON_DEPENDS clang-tablegen-targets)
add_clang_library(clangPseudoGrammar
Grammar.cpp
GrammarBNF.cpp
LRGraph.cpp
LRTable.cpp
LRTableBuild.cpp
-
- # FIXME: can we get rid of the clangBasic dependency? We need it for the
- # clang::tok::getTokenName and clang::tok::getPunctuatorSpelling functions, we
- # could consider remimplement these functions.
- LINK_LIBS
- clangBasic
)
+
diff --git a/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp b/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
index e048f8753d9d9..d974d807d2547 100644
--- a/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
+++ b/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
@@ -167,19 +167,16 @@ std::vector<llvm::DenseSet<SymbolID>> followSets(const Grammar &G) {
}
static llvm::ArrayRef<std::string> getTerminalNames() {
- static const std::vector<std::string> *TerminalNames = []() {
- static std::vector<std::string> TerminalNames;
- TerminalNames.reserve(NumTerminals);
- for (unsigned I = 0; I < NumTerminals; ++I) {
- tok::TokenKind K = static_cast<tok::TokenKind>(I);
- if (const auto *Punc = tok::getPunctuatorSpelling(K))
- TerminalNames.push_back(Punc);
- else
- TerminalNames.push_back(llvm::StringRef(tok::getTokenName(K)).upper());
- }
- return &TerminalNames;
+ static const auto &TerminalNames = []() {
+ auto &TerminalNames = *new std::array<std::string, NumTerminals>;
+#define PUNCTUATOR(Tok, Spelling) TerminalNames[tok::Tok] = Spelling;
+#define KEYWORD(Keyword, Condition) \
+ TerminalNames[tok::kw_##Keyword] = llvm::StringRef(#Keyword).upper();
+#define TOK(Tok) TerminalNames[tok::Tok] = llvm::StringRef(#Tok).upper();
+#include "clang/Basic/TokenKinds.def"
+ return TerminalNames;
}();
- return *TerminalNames;
+ return TerminalNames;
}
GrammarTable::GrammarTable() : Terminals(getTerminalNames()) {}
More information about the cfe-commits
mailing list