Skip to content

Commit

Permalink
[tblgen][directive] Fix clause parser generation for list value
Browse files Browse the repository at this point in the history
The clause parser generation was not taking into account the
`isValueList` flag. This patch updates the emitter to generate
the correct code.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D153801
  • Loading branch information
clementval committed Jun 27, 2023
1 parent 06a9975 commit ed73375
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion llvm/test/TableGen/directive1.td
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def TDLC_ClauseB : Clause<"clauseb"> {
let isDefault = 1;
}

def TDLC_ClauseC : Clause<"clausec"> {
let flangClass = "IntExpr";
let isValueList = 1;
}

def TDL_DirA : Directive<"dira"> {
let allowedClauses = [
VersionedClause<TDLC_ClauseA>,
Expand Down Expand Up @@ -63,12 +68,14 @@ def TDL_DirA : Directive<"dira"> {
// CHECK-NEXT: enum class Clause {
// CHECK-NEXT: TDLC_clausea,
// CHECK-NEXT: TDLC_clauseb,
// CHECK-NEXT: TDLC_clausec,
// CHECK-NEXT: };
// CHECK-EMPTY:
// CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 2;
// CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 3;
// CHECK-EMPTY:
// CHECK-NEXT: constexpr auto TDLC_clausea = llvm::tdl::Clause::TDLC_clausea;
// CHECK-NEXT: constexpr auto TDLC_clauseb = llvm::tdl::Clause::TDLC_clauseb;
// CHECK-NEXT: constexpr auto TDLC_clausec = llvm::tdl::Clause::TDLC_clausec;
// CHECK-EMPTY:
// CHECK-NEXT: enum class AKind {
// CHECK-NEXT: TDLCV_vala=1,
Expand Down Expand Up @@ -147,6 +154,7 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-EMPTY:
// IMPL-NEXT: EMPTY_CLASS(Clausea);
// IMPL-NEXT: WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
// IMPL-NEXT: WRAPPER_CLASS(Clausec, std::list<IntExpr>);
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
// IMPL-EMPTY:
Expand All @@ -155,6 +163,7 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-EMPTY:
// IMPL-NEXT: Clausea
// IMPL-NEXT: , Clauseb
// IMPL-NEXT: , Clausec
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
// IMPL-EMPTY:
Expand All @@ -163,6 +172,7 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-EMPTY:
// IMPL-NEXT: NODE(TdlClause, Clausea)
// IMPL-NEXT: NODE(TdlClause, Clauseb)
// IMPL-NEXT: NODE(TdlClause, Clausec)
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
// IMPL-EMPTY:
Expand All @@ -174,6 +184,12 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-NEXT: Word("CLAUSEB");
// IMPL-NEXT: Walk("(", x.v, ")");
// IMPL-NEXT: }
// IMPL-NEXT: void Unparse(const TdlClause::Clausec &x) {
// IMPL-NEXT: Word("CLAUSEC");
// IMPL-NEXT: Put("(");
// IMPL-NEXT: Walk(x.v, ",");
// IMPL-NEXT: Put(")");
// IMPL-NEXT: }
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_UNPARSE
// IMPL-EMPTY:
Expand All @@ -182,6 +198,7 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-EMPTY:
// IMPL-NEXT: void Enter(const parser::TdlClause::Clausea &);
// IMPL-NEXT: void Enter(const parser::TdlClause::Clauseb &);
// IMPL-NEXT: void Enter(const parser::TdlClause::Clausec &);
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_CHECK_ENTER
// IMPL-EMPTY:
Expand All @@ -192,6 +209,8 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausea;
// IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clauseb>)
// IMPL-NEXT: return llvm::tdl::Clause::TDLC_clauseb;
// IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clausec>)
// IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausec;
// IMPL-NEXT: llvm_unreachable("Invalid Tdl Parser clause");
// IMPL-EMPTY:
// IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_KIND_MAP
Expand All @@ -200,6 +219,7 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-NEXT: #undef GEN_FLANG_CLAUSES_PARSER
// IMPL-EMPTY:
// IMPL-NEXT: TYPE_PARSER(
// IMPL-NEXT: "clausec" >> construct<TdlClause>(construct<TdlClause::Clausec>(parenthesized(nonemptyList(Parser<IntExpr>{})))) ||
// IMPL-NEXT: "clauseb" >> construct<TdlClause>(construct<TdlClause::Clauseb>(maybe(parenthesized(Parser<IntExpr>{})))) ||
// IMPL-NEXT: "clausea" >> construct<TdlClause>(construct<TdlClause::Clausea>())
// IMPL-NEXT: )
Expand Down Expand Up @@ -234,6 +254,7 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-EMPTY:
// IMPL-NEXT: __CLAUSE_NO_CLASS(clausea)
// IMPL-NEXT: __CLAUSE_NO_CLASS(clauseb)
// IMPL-NEXT: __CLAUSE_NO_CLASS(clausec)
// IMPL-EMPTY:
// IMPL-NEXT: #undef __IMPLICIT_CLAUSE_NO_CLASS
// IMPL-NEXT: #undef __IMPLICIT_CLAUSE_CLASS
Expand Down Expand Up @@ -266,6 +287,7 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
// IMPL-NEXT: .Case("clausea",TDLC_clausea)
// IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
// IMPL-NEXT: .Case("clausec",TDLC_clausec)
// IMPL-NEXT: .Default(TDLC_clauseb);
// IMPL-NEXT: }
// IMPL-EMPTY:
Expand All @@ -275,6 +297,8 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-NEXT: return "clausea";
// IMPL-NEXT: case TDLC_clauseb:
// IMPL-NEXT: return "clauseb";
// IMPL-NEXT: case TDLC_clausec:
// IMPL-NEXT: return "clausec";
// IMPL-NEXT: }
// IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
// IMPL-NEXT: }
Expand Down
4 changes: 4 additions & 0 deletions llvm/utils/TableGen/DirectiveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ static void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
if (Clause.isValueOptional())
OS << "maybe(";
OS << "parenthesized(";
if (Clause.isValueList())
OS << "nonemptyList(";

if (!Clause.getPrefix().empty())
OS << "\"" << Clause.getPrefix() << ":\" >> ";
Expand All @@ -740,6 +742,8 @@ static void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
OS << Parser;
if (!Clause.getPrefix().empty() && Clause.isPrefixOptional())
OS << " || " << Parser;
if (Clause.isValueList()) // close nonemptyList(.
OS << ")";
OS << ")"; // close parenthesized(.

if (Clause.isValueOptional()) // close maybe(.
Expand Down

0 comments on commit ed73375

Please sign in to comment.