1 // RUN: llvm-tblgen -gen-directive-decl -I %p/../../include %s | FileCheck -match-full-lines %s
2 // RUN: llvm-tblgen -gen-directive-impl -I %p/../../include %s | FileCheck -match-full-lines %s -check-prefix=IMPL
4 include "llvm/Frontend/Directive/DirectiveBase.td"
6 def TestDirectiveLanguage : DirectiveLanguage {
9 let cppNamespace = "tdl";
10 let directivePrefix = "TDLD_";
11 let clausePrefix = "TDLC_";
12 let makeEnumAvailableInNamespace = 1;
13 let enableBitmaskEnumInNamespace = 1;
14 let flangClauseBaseClass = "TdlClause";
17 def TDLCV_vala : ClauseVal<"vala",1,1> {}
18 def TDLCV_valb : ClauseVal<"valb",2,1> {}
19 def TDLCV_valc : ClauseVal<"valc",3,0> { let isDefault = 1; }
21 def TDLC_ClauseA : Clause<"clausea"> {
22 let enumClauseValue = "AKind";
23 let allowedClauseValues = [
30 def TDLC_ClauseB : Clause<"clauseb"> {
31 let flangClass = "IntExpr";
32 let isValueOptional = 1;
36 def TDLC_ClauseC : Clause<"clausec"> {
37 let flangClass = "IntExpr";
41 def TDL_DirA : Directive<"dira"> {
42 let allowedClauses = [
43 VersionedClause<TDLC_ClauseA>,
44 VersionedClause<TDLC_ClauseB>
47 let association = AS_None;
48 let category = CA_Executable;
51 // CHECK: #ifndef LLVM_Tdl_INC
52 // CHECK-NEXT: #define LLVM_Tdl_INC
54 // CHECK-NEXT: #include "llvm/ADT/ArrayRef.h"
55 // CHECK-NEXT: #include "llvm/ADT/BitmaskEnum.h"
56 // CHECK-NEXT: #include <cstddef>
58 // CHECK-NEXT: namespace llvm {
59 // CHECK-NEXT: class StringRef;
60 // CHECK-NEXT: namespace tdl {
62 // CHECK-NEXT: LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
64 // CHECK-NEXT: enum class Association {
66 // CHECK-NEXT: Declaration,
67 // CHECK-NEXT: Delimited,
70 // CHECK-NEXT: Separating,
73 // CHECK-NEXT: static constexpr std::size_t Association_enumSize = 6;
75 // CHECK-NEXT: enum class Category {
76 // CHECK-NEXT: Declarative,
77 // CHECK-NEXT: Executable,
78 // CHECK-NEXT: Informational,
80 // CHECK-NEXT: Subsidiary,
81 // CHECK-NEXT: Utility,
84 // CHECK-NEXT: static constexpr std::size_t Category_enumSize = 6;
86 // CHECK-NEXT: enum class Directive {
87 // CHECK-NEXT: TDLD_dira,
90 // CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1;
92 // CHECK-NEXT: constexpr auto TDLD_dira = llvm::tdl::Directive::TDLD_dira;
94 // CHECK-NEXT: enum class Clause {
95 // CHECK-NEXT: TDLC_clausea,
96 // CHECK-NEXT: TDLC_clauseb,
97 // CHECK-NEXT: TDLC_clausec,
100 // CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 3;
102 // CHECK-NEXT: constexpr auto TDLC_clausea = llvm::tdl::Clause::TDLC_clausea;
103 // CHECK-NEXT: constexpr auto TDLC_clauseb = llvm::tdl::Clause::TDLC_clauseb;
104 // CHECK-NEXT: constexpr auto TDLC_clausec = llvm::tdl::Clause::TDLC_clausec;
106 // CHECK-NEXT: enum class AKind {
107 // CHECK-NEXT: TDLCV_vala=1,
108 // CHECK-NEXT: TDLCV_valb=2,
109 // CHECK-NEXT: TDLCV_valc=3,
112 // CHECK-NEXT: constexpr auto TDLCV_vala = llvm::tdl::AKind::TDLCV_vala;
113 // CHECK-NEXT: constexpr auto TDLCV_valb = llvm::tdl::AKind::TDLCV_valb;
114 // CHECK-NEXT: constexpr auto TDLCV_valc = llvm::tdl::AKind::TDLCV_valc;
116 // CHECK-NEXT: // Enumeration helper functions
117 // CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str);
119 // CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D);
121 // CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str);
123 // CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C);
125 // CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
126 // CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
128 // CHECK-NEXT: constexpr std::size_t getMaxLeafCount() { return 0; }
129 // CHECK-NEXT: Association getDirectiveAssociation(Directive D);
130 // CHECK-NEXT: Category getDirectiveCategory(Directive D);
131 // CHECK-NEXT: AKind getAKind(StringRef);
132 // CHECK-NEXT: llvm::StringRef getTdlAKindName(AKind);
134 // CHECK-NEXT: } // namespace tdl
135 // CHECK-NEXT: } // namespace llvm
136 // CHECK-NEXT: #endif // LLVM_Tdl_INC
139 // IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
140 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
142 // IMPL-NEXT: namespace llvm {
143 // IMPL-NEXT: namespace tdl {
145 // IMPL-NEXT: // Sets for dira
147 // IMPL-NEXT: static allowedClauses_TDLD_dira {
148 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clausea,
149 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clauseb,
152 // IMPL-NEXT: static allowedOnceClauses_TDLD_dira {
155 // IMPL-NEXT: static allowedExclusiveClauses_TDLD_dira {
158 // IMPL-NEXT: static requiredClauses_TDLD_dira {
160 // IMPL-NEXT: } // namespace tdl
161 // IMPL-NEXT: } // namespace llvm
163 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
165 // IMPL-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
166 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
169 // IMPL-NEXT: {llvm::tdl::Directive::TDLD_dira,
171 // IMPL-NEXT: llvm::tdl::allowedClauses_TDLD_dira,
172 // IMPL-NEXT: llvm::tdl::allowedOnceClauses_TDLD_dira,
173 // IMPL-NEXT: llvm::tdl::allowedExclusiveClauses_TDLD_dira,
174 // IMPL-NEXT: llvm::tdl::requiredClauses_TDLD_dira,
179 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
181 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
182 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
184 // IMPL-NEXT: EMPTY_CLASS(Clausea);
185 // IMPL-NEXT: WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
186 // IMPL-NEXT: WRAPPER_CLASS(Clausec, std::list<IntExpr>);
188 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
190 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
191 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
193 // IMPL-NEXT: Clausea
194 // IMPL-NEXT: , Clauseb
195 // IMPL-NEXT: , Clausec
197 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
199 // IMPL-NEXT: #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
200 // IMPL-NEXT: #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
202 // IMPL-NEXT: NODE(TdlClause, Clausea)
203 // IMPL-NEXT: NODE(TdlClause, Clauseb)
204 // IMPL-NEXT: NODE(TdlClause, Clausec)
206 // IMPL-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
208 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_UNPARSE
209 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_UNPARSE
211 // IMPL-NEXT: void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
212 // IMPL-NEXT: void Unparse(const TdlClause::Clauseb &x) {
213 // IMPL-NEXT: Word("CLAUSEB");
214 // IMPL-NEXT: Walk("(", x.v, ")");
216 // IMPL-NEXT: void Unparse(const TdlClause::Clausec &x) {
217 // IMPL-NEXT: Word("CLAUSEC");
218 // IMPL-NEXT: Put("(");
219 // IMPL-NEXT: Walk(x.v, ",");
220 // IMPL-NEXT: Put(")");
223 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_UNPARSE
225 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_CHECK_ENTER
226 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_CHECK_ENTER
228 // IMPL-NEXT: void Enter(const parser::TdlClause::Clausea &);
229 // IMPL-NEXT: void Enter(const parser::TdlClause::Clauseb &);
230 // IMPL-NEXT: void Enter(const parser::TdlClause::Clausec &);
232 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_CHECK_ENTER
234 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
235 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
237 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clausea>)
238 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausea;
239 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clauseb>)
240 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clauseb;
241 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clausec>)
242 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausec;
243 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Parser clause");
245 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_KIND_MAP
247 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSES_PARSER
248 // IMPL-NEXT: #undef GEN_FLANG_CLAUSES_PARSER
250 // IMPL-NEXT: TYPE_PARSER(
251 // IMPL-NEXT: "clausec" >> construct<TdlClause>(construct<TdlClause::Clausec>(parenthesized(nonemptyList(Parser<IntExpr>{})))) ||
252 // IMPL-NEXT: "clauseb" >> construct<TdlClause>(construct<TdlClause::Clauseb>(maybe(parenthesized(Parser<IntExpr>{})))) ||
253 // IMPL-NEXT: "clausea" >> construct<TdlClause>(construct<TdlClause::Clausea>())
256 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSES_PARSER
258 // IMPL-NEXT: #ifdef GEN_CLANG_CLAUSE_CLASS
259 // IMPL-NEXT: #undef GEN_CLANG_CLAUSE_CLASS
261 // IMPL-NEXT: #ifndef CLAUSE
262 // IMPL-NEXT: #define CLAUSE(Enum, Str, Implicit)
264 // IMPL-NEXT: #ifndef CLAUSE_CLASS
265 // IMPL-NEXT: #define CLAUSE_CLASS(Enum, Str, Class)
267 // IMPL-NEXT: #ifndef CLAUSE_NO_CLASS
268 // IMPL-NEXT: #define CLAUSE_NO_CLASS(Enum, Str)
271 // IMPL-NEXT: #define __CLAUSE(Name, Class) \
272 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
273 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, #Name, Class)
274 // IMPL-NEXT: #define __CLAUSE_NO_CLASS(Name) \
275 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
276 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, #Name)
277 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class) \
278 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
279 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, Str, Class)
280 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str) \
281 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
282 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, Str)
284 // IMPL-NEXT: __CLAUSE_NO_CLASS(clausea)
285 // IMPL-NEXT: __CLAUSE_NO_CLASS(clauseb)
286 // IMPL-NEXT: __CLAUSE_NO_CLASS(clausec)
288 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_NO_CLASS
289 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_CLASS
290 // IMPL-NEXT: #undef __CLAUSE_NO_CLASS
291 // IMPL-NEXT: #undef __CLAUSE
292 // IMPL-NEXT: #undef CLAUSE_NO_CLASS
293 // IMPL-NEXT: #undef CLAUSE_CLASS
294 // IMPL-NEXT: #undef CLAUSE
296 // IMPL-NEXT: #endif // GEN_CLANG_CLAUSE_CLASS
299 // IMPL: #ifdef GEN_DIRECTIVES_IMPL
300 // IMPL-NEXT: #undef GEN_DIRECTIVES_IMPL
302 // IMPL-NEXT: #include "llvm/Support/ErrorHandling.h"
304 // IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
305 // IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
306 // IMPL-NEXT: .Case("dira",TDLD_dira)
307 // IMPL-NEXT: .Default(TDLD_dira);
310 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) {
311 // IMPL-NEXT: switch (Kind) {
312 // IMPL-NEXT: case TDLD_dira:
313 // IMPL-NEXT: return "dira";
315 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
318 // IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
319 // IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
320 // IMPL-NEXT: .Case("clausea",TDLC_clausea)
321 // IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
322 // IMPL-NEXT: .Case("clausec",TDLC_clausec)
323 // IMPL-NEXT: .Default(TDLC_clauseb);
326 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) {
327 // IMPL-NEXT: switch (Kind) {
328 // IMPL-NEXT: case TDLC_clausea:
329 // IMPL-NEXT: return "clausea";
330 // IMPL-NEXT: case TDLC_clauseb:
331 // IMPL-NEXT: return "clauseb";
332 // IMPL-NEXT: case TDLC_clausec:
333 // IMPL-NEXT: return "clausec";
335 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
338 // IMPL-NEXT: AKind llvm::tdl::getAKind(llvm::StringRef Str) {
339 // IMPL-NEXT: return llvm::StringSwitch<AKind>(Str)
340 // IMPL-NEXT: .Case("vala",TDLCV_vala)
341 // IMPL-NEXT: .Case("valb",TDLCV_valb)
342 // IMPL-NEXT: .Case("valc",TDLCV_valc)
343 // IMPL-NEXT: .Default(TDLCV_valc);
346 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlAKindName(llvm::tdl::AKind x) {
347 // IMPL-NEXT: switch (x) {
348 // IMPL-NEXT: case TDLCV_vala:
349 // IMPL-NEXT: return "vala";
350 // IMPL-NEXT: case TDLCV_valb:
351 // IMPL-NEXT: return "valb";
352 // IMPL-NEXT: case TDLCV_valc:
353 // IMPL-NEXT: return "valc";
355 // IMPL-NEXT: llvm_unreachable("Invalid Tdl AKind kind");
358 // IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
359 // IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
360 // IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
361 // IMPL-NEXT: switch (D) {
362 // IMPL-NEXT: case TDLD_dira:
363 // IMPL-NEXT: switch (C) {
364 // IMPL-NEXT: case TDLC_clausea:
365 // IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
366 // IMPL-NEXT: case TDLC_clauseb:
367 // IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
368 // IMPL-NEXT: default:
369 // IMPL-NEXT: return false;
373 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
376 // IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive Dir) {
377 // IMPL-NEXT: switch (Dir) {
378 // IMPL-NEXT: case llvm::tdl::Directive::TDLD_dira:
379 // IMPL-NEXT: return llvm::tdl::Association::None;
380 // IMPL-NEXT: } // switch (Dir)
381 // IMPL-NEXT: llvm_unreachable("Unexpected directive");
384 // IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive Dir) {
385 // IMPL-NEXT: switch (Dir) {
386 // IMPL-NEXT: case llvm::tdl::TDLD_dira:
387 // IMPL-NEXT: return llvm::tdl::Category::Executable;
388 // IMPL-NEXT: } // switch (Dir)
389 // IMPL-NEXT: llvm_unreachable("Unexpected directive");
392 // IMPL-NEXT: static_assert(sizeof(llvm::tdl::Directive) == sizeof(int));
393 // IMPL-NEXT: {{.*}} static const llvm::tdl::Directive LeafConstructTable[][2] = {
394 // IMPL-NEXT: {llvm::tdl::TDLD_dira, static_cast<llvm::tdl::Directive>(0),},
397 // IMPL-NEXT: {{.*}} static auto LeafConstructTableEndDirective = LeafConstructTable + 1;
399 // IMPL-NEXT: {{.*}} static const int LeafConstructTableOrdering[] = {
403 // IMPL-NEXT: #endif // GEN_DIRECTIVES_IMPL