diff options
Diffstat (limited to 'llvm/utils/TableGen/DirectiveEmitter.cpp')
| -rw-r--r-- | llvm/utils/TableGen/DirectiveEmitter.cpp | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp index c9daa9b24155..b21bf369d18e 100644 --- a/llvm/utils/TableGen/DirectiveEmitter.cpp +++ b/llvm/utils/TableGen/DirectiveEmitter.cpp @@ -633,6 +633,43 @@ void GenerateFlangClauseUnparse(const DirectiveLanguage &DirLang, } } +// Generate check in the Enter functions for clauses classes. +void GenerateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang, + raw_ostream &OS) { + + IfDefScope Scope("GEN_FLANG_CLAUSE_CHECK_ENTER", OS); + + OS << "\n"; + for (const auto &C : DirLang.getClauses()) { + Clause Clause{C}; + OS << "void Enter(const parser::" << DirLang.getFlangClauseBaseClass() + << "::" << Clause.getFormattedParserClassName() << " &);\n"; + } +} + +// Generate the mapping for clauses between the parser class and the +// corresponding clause Kind +void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang, + raw_ostream &OS) { + + IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_KIND_MAP", OS); + + OS << "\n"; + for (const auto &C : DirLang.getClauses()) { + Clause Clause{C}; + OS << "if constexpr (std::is_same_v<A, parser::" + << DirLang.getFlangClauseBaseClass() + << "::" << Clause.getFormattedParserClassName(); + OS << ">)\n"; + OS << " return llvm::" << DirLang.getCppNamespace() + << "::Clause::" << DirLang.getClausePrefix() << Clause.getFormattedName() + << ";\n"; + } + + OS << "llvm_unreachable(\"Invalid " << DirLang.getName() + << " Parser clause\");\n"; +} + // Generate the implementation section for the enumeration in the directive // language void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang, @@ -649,6 +686,10 @@ void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang, GenerateFlangClauseDump(DirLang, OS); GenerateFlangClauseUnparse(DirLang, OS); + + GenerateFlangClauseCheckPrototypes(DirLang, OS); + + GenerateFlangClauseParserKindMap(DirLang, OS); } void GenerateClauseClassMacro(const DirectiveLanguage &DirLang, @@ -717,37 +758,11 @@ void GenerateClauseClassMacro(const DirectiveLanguage &DirLang, OS << "#undef CLAUSE\n"; } -// Generate the implementation section for the enumeration in the directive -// language. -void EmitDirectivesGen(RecordKeeper &Records, raw_ostream &OS) { - const auto DirLang = DirectiveLanguage{Records}; - if (DirLang.HasValidityErrors()) - return; - - EmitDirectivesFlangImpl(DirLang, OS); - - GenerateClauseClassMacro(DirLang, OS); -} - -// Generate the implementation for the enumeration in the directive +// Generate the implemenation for the enumeration in the directive // language. This code can be included in library. -void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) { - const auto DirLang = DirectiveLanguage{Records}; - if (DirLang.HasValidityErrors()) - return; - - if (!DirLang.getIncludeHeader().empty()) - OS << "#include \"" << DirLang.getIncludeHeader() << "\"\n\n"; - - OS << "#include \"llvm/ADT/StringRef.h\"\n"; - OS << "#include \"llvm/ADT/StringSwitch.h\"\n"; - OS << "#include \"llvm/Support/ErrorHandling.h\"\n"; - OS << "\n"; - OS << "using namespace llvm;\n"; - llvm::SmallVector<StringRef, 2> Namespaces; - llvm::SplitString(DirLang.getCppNamespace(), Namespaces, "::"); - for (auto Ns : Namespaces) - OS << "using namespace " << Ns << ";\n"; +void EmitDirectivesBasicImpl(const DirectiveLanguage &DirLang, + raw_ostream &OS) { + IfDefScope Scope("GEN_DIRECTIVES_IMPL", OS); // getDirectiveKind(StringRef Str) GenerateGetKind(DirLang.getDirectives(), OS, "Directive", DirLang, @@ -773,4 +788,18 @@ void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) { GenerateIsAllowedClause(DirLang, OS); } +// Generate the implemenation section for the enumeration in the directive +// language. +void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) { + const auto DirLang = DirectiveLanguage{Records}; + if (DirLang.HasValidityErrors()) + return; + + EmitDirectivesFlangImpl(DirLang, OS); + + GenerateClauseClassMacro(DirLang, OS); + + EmitDirectivesBasicImpl(DirLang, OS); +} + } // namespace llvm |
