Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions llvm/test/TableGen/directive1.td
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions llvm/test/TableGen/directive2.td
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
36 changes: 10 additions & 26 deletions llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 different for clang vs flang, as 2 structs with the
// same name but different 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,
Expand All @@ -963,23 +955,15 @@ 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.
// The struct holds the 4 sets of enumeration for the 4 kinds of clauses
// 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";

Expand Down