[llvm] d568601 - [NFC][TableGen] Adopt NamespaceEmitter in DirectiveEmitter (#165600)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 5 07:46:16 PST 2025
Author: Rahul Joshi
Date: 2025-11-05T07:46:12-08:00
New Revision: d568601d5a0c7c315d8038f4dc24e0ccd97a1ba0
URL: https://github.com/llvm/llvm-project/commit/d568601d5a0c7c315d8038f4dc24e0ccd97a1ba0
DIFF: https://github.com/llvm/llvm-project/commit/d568601d5a0c7c315d8038f4dc24e0ccd97a1ba0.diff
LOG: [NFC][TableGen] Adopt NamespaceEmitter in DirectiveEmitter (#165600)
Added:
Modified:
llvm/test/TableGen/directive1.td
llvm/test/TableGen/directive2.td
llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td
index 8648651f3d714..5bd7890e0ddd1 100644
--- a/llvm/test/TableGen/directive1.td
+++ b/llvm/test/TableGen/directive1.td
@@ -186,8 +186,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-EMPTY:
-// IMPL-NEXT: namespace llvm {
-// IMPL-NEXT: namespace tdl {
+// IMPL-NEXT: namespace llvm::tdl {
// IMPL-EMPTY:
// IMPL-NEXT: // Sets for dira
// IMPL-EMPTY:
@@ -204,8 +203,8 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL-EMPTY:
// IMPL-NEXT: static requiredClauses_TDLD_dira {
// IMPL-NEXT: };
-// IMPL-NEXT: } // namespace tdl
-// IMPL-NEXT: } // namespace llvm
+// IMPL-EMPTY:
+// IMPL-NEXT: } // namespace llvm::tdl
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-EMPTY:
diff --git a/llvm/test/TableGen/directive2.td b/llvm/test/TableGen/directive2.td
index 96022d7647440..eaaf82ddaaf41 100644
--- a/llvm/test/TableGen/directive2.td
+++ b/llvm/test/TableGen/directive2.td
@@ -159,8 +159,7 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-EMPTY:
-// IMPL-NEXT: namespace llvm {
-// IMPL-NEXT: namespace tdl {
+// IMPL-NEXT: namespace llvm::tdl {
// IMPL-EMPTY:
// IMPL-NEXT: // Sets for dira
// IMPL-EMPTY:
@@ -177,8 +176,8 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL-EMPTY:
// IMPL-NEXT: static requiredClauses_TDLD_dira {
// IMPL-NEXT: };
-// IMPL-NEXT: } // namespace tdl
-// IMPL-NEXT: } // namespace llvm
+// IMPL-EMPTY:
+// IMPL-NEXT: } // namespace llvm::tdl
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
// IMPL-EMPTY:
diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
index d33bf45595e2e..0bb743dc8a7f5 100644
--- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
@@ -359,7 +359,6 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
OS << " static constexpr bool is_iterable = true;\n";
OS << "};\n";
}
- LlvmNS.close();
}
// Given a list of spellings (for a given clause/directive), order them
@@ -931,27 +930,20 @@ static void generateClauseSet(ArrayRef<const Record *> VerClauses,
// Generate an enum set for the 4 kinds of clauses linked to a directive.
static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
Frontend FE, raw_ostream &OS) {
+ IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
+ "_DIRECTIVE_CLAUSE_SETS");
- std::string IfDefName{"GEN_"};
- IfDefName += getFESpelling(FE).upper();
- IfDefName += "_DIRECTIVE_CLAUSE_SETS";
- IfDefEmitter Scope(OS, IfDefName);
-
- StringRef Namespace =
- getFESpelling(FE == Frontend::Flang ? Frontend::LLVM : FE);
+ std::string Namespace =
+ getFESpelling(FE == Frontend::Flang ? Frontend::LLVM : FE).str();
// The namespace has to be
diff erent for clang vs flang, as 2 structs with the
// same name but
diff erent layout is UB. So just put the 'clang' on in the
// clang namespace.
- OS << "namespace " << Namespace << " {\n";
-
- // Open namespaces defined in the directive language.
- SmallVector<StringRef, 2> Namespaces;
- SplitString(DirLang.getCppNamespace(), Namespaces, "::");
- for (auto Ns : Namespaces)
- OS << "namespace " << Ns << " {\n";
+ // Additionally, open namespaces defined in the directive language.
+ if (!DirLang.getCppNamespace().empty())
+ Namespace += "::" + DirLang.getCppNamespace().str();
+ NamespaceEmitter NS(OS, Namespace);
for (const Directive Dir : DirLang.getDirectives()) {
- OS << "\n";
OS << "// Sets for " << Dir.getSpellingForIdentifier() << "\n";
generateClauseSet(Dir.getAllowedClauses(), OS, "allowedClauses_", Dir,
@@ -963,12 +955,6 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
generateClauseSet(Dir.getRequiredClauses(), OS, "requiredClauses_", Dir,
DirLang, FE);
}
-
- // Closing namespaces
- for (auto Ns : reverse(Namespaces))
- OS << "} // namespace " << Ns << "\n";
-
- OS << "} // namespace " << Namespace << "\n";
}
// Generate a map of directive (key) with DirectiveClauses struct as values.
@@ -976,10 +962,8 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
// allowances (allowed, allowed once, allowed exclusive and required).
static void generateDirectiveClauseMap(const DirectiveLanguage &DirLang,
Frontend FE, raw_ostream &OS) {
- std::string IfDefName{"GEN_"};
- IfDefName += getFESpelling(FE).upper();
- IfDefName += "_DIRECTIVE_CLAUSE_MAP";
- IfDefEmitter Scope(OS, IfDefName);
+ IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
+ "_DIRECTIVE_CLAUSE_MAP");
OS << "{\n";
More information about the llvm-commits
mailing list