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 "llvm/Support/Compiler.h"
57 // CHECK-NEXT: #include <cstddef>
59 // CHECK-NEXT: namespace llvm {
60 // CHECK-NEXT: class StringRef;
61 // CHECK-NEXT: namespace tdl {
63 // CHECK-NEXT: LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
65 // CHECK-NEXT: enum class Association {
67 // CHECK-NEXT: Declaration,
68 // CHECK-NEXT: Delimited,
71 // CHECK-NEXT: Separating,
74 // CHECK-NEXT: static constexpr std::size_t Association_enumSize = 6;
76 // CHECK-NEXT: enum class Category {
77 // CHECK-NEXT: Declarative,
78 // CHECK-NEXT: Executable,
79 // CHECK-NEXT: Informational,
81 // CHECK-NEXT: Subsidiary,
82 // CHECK-NEXT: Utility,
85 // CHECK-NEXT: static constexpr std::size_t Category_enumSize = 6;
87 // CHECK-NEXT: enum class Directive {
88 // CHECK-NEXT: TDLD_dira,
91 // CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1;
93 // CHECK-NEXT: constexpr auto TDLD_dira = llvm::tdl::Directive::TDLD_dira;
95 // CHECK-NEXT: enum class Clause {
96 // CHECK-NEXT: TDLC_clausea,
97 // CHECK-NEXT: TDLC_clauseb,
98 // CHECK-NEXT: TDLC_clausec,
101 // CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 3;
103 // CHECK-NEXT: constexpr auto TDLC_clausea = llvm::tdl::Clause::TDLC_clausea;
104 // CHECK-NEXT: constexpr auto TDLC_clauseb = llvm::tdl::Clause::TDLC_clauseb;
105 // CHECK-NEXT: constexpr auto TDLC_clausec = llvm::tdl::Clause::TDLC_clausec;
107 // CHECK-NEXT: enum class AKind {
108 // CHECK-NEXT: TDLCV_vala=1,
109 // CHECK-NEXT: TDLCV_valb=2,
110 // CHECK-NEXT: TDLCV_valc=3,
113 // CHECK-NEXT: constexpr auto TDLCV_vala = llvm::tdl::AKind::TDLCV_vala;
114 // CHECK-NEXT: constexpr auto TDLCV_valb = llvm::tdl::AKind::TDLCV_valb;
115 // CHECK-NEXT: constexpr auto TDLCV_valc = llvm::tdl::AKind::TDLCV_valc;
117 // CHECK-NEXT: // Enumeration helper functions
118 // CHECK-NEXT: LLVM_ABI Directive getTdlDirectiveKind(llvm::StringRef Str);
120 // CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlDirectiveName(Directive D);
122 // CHECK-NEXT: LLVM_ABI Clause getTdlClauseKind(llvm::StringRef Str);
124 // CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlClauseName(Clause C);
126 // CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
127 // CHECK-NEXT: LLVM_ABI bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
129 // CHECK-NEXT: constexpr std::size_t getMaxLeafCount() { return 0; }
130 // CHECK-NEXT: LLVM_ABI Association getDirectiveAssociation(Directive D);
131 // CHECK-NEXT: LLVM_ABI Category getDirectiveCategory(Directive D);
132 // CHECK-NEXT: LLVM_ABI AKind getAKind(StringRef);
133 // CHECK-NEXT: LLVM_ABI llvm::StringRef getTdlAKindName(AKind);
135 // CHECK-NEXT: } // namespace tdl
136 // CHECK-NEXT: } // namespace llvm
137 // CHECK-NEXT: #endif // LLVM_Tdl_INC
140 // IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
141 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
143 // IMPL-NEXT: namespace llvm {
144 // IMPL-NEXT: namespace tdl {
146 // IMPL-NEXT: // Sets for dira
148 // IMPL-NEXT: static allowedClauses_TDLD_dira {
149 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clausea,
150 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clauseb,
153 // IMPL-NEXT: static allowedOnceClauses_TDLD_dira {
156 // IMPL-NEXT: static allowedExclusiveClauses_TDLD_dira {
159 // IMPL-NEXT: static requiredClauses_TDLD_dira {
161 // IMPL-NEXT: } // namespace tdl
162 // IMPL-NEXT: } // namespace llvm
164 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
166 // IMPL-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
167 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
170 // IMPL-NEXT: {llvm::tdl::Directive::TDLD_dira,
172 // IMPL-NEXT: llvm::tdl::allowedClauses_TDLD_dira,
173 // IMPL-NEXT: llvm::tdl::allowedOnceClauses_TDLD_dira,
174 // IMPL-NEXT: llvm::tdl::allowedExclusiveClauses_TDLD_dira,
175 // IMPL-NEXT: llvm::tdl::requiredClauses_TDLD_dira,
180 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
182 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
183 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
185 // IMPL-NEXT: EMPTY_CLASS(Clausea);
186 // IMPL-NEXT: WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
187 // IMPL-NEXT: WRAPPER_CLASS(Clausec, std::list<IntExpr>);
189 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
191 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
192 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
194 // IMPL-NEXT: Clausea
195 // IMPL-NEXT: , Clauseb
196 // IMPL-NEXT: , Clausec
198 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
200 // IMPL-NEXT: #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
201 // IMPL-NEXT: #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
203 // IMPL-NEXT: NODE(TdlClause, Clausea)
204 // IMPL-NEXT: NODE(TdlClause, Clauseb)
205 // IMPL-NEXT: NODE(TdlClause, Clausec)
207 // IMPL-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
209 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_UNPARSE
210 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_UNPARSE
212 // IMPL-NEXT: void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
213 // IMPL-NEXT: void Unparse(const TdlClause::Clauseb &x) {
214 // IMPL-NEXT: Word("CLAUSEB");
215 // IMPL-NEXT: Walk("(", x.v, ")");
217 // IMPL-NEXT: void Unparse(const TdlClause::Clausec &x) {
218 // IMPL-NEXT: Word("CLAUSEC");
219 // IMPL-NEXT: Put("(");
220 // IMPL-NEXT: Walk(x.v, ",");
221 // IMPL-NEXT: Put(")");
224 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_UNPARSE
226 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_CHECK_ENTER
227 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_CHECK_ENTER
229 // IMPL-NEXT: void Enter(const parser::TdlClause::Clausea &);
230 // IMPL-NEXT: void Enter(const parser::TdlClause::Clauseb &);
231 // IMPL-NEXT: void Enter(const parser::TdlClause::Clausec &);
233 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_CHECK_ENTER
235 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
236 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
238 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clausea>)
239 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausea;
240 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clauseb>)
241 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clauseb;
242 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clausec>)
243 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausec;
244 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Parser clause");
246 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_KIND_MAP
248 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSES_PARSER
249 // IMPL-NEXT: #undef GEN_FLANG_CLAUSES_PARSER
251 // IMPL-NEXT: TYPE_PARSER(
252 // IMPL-NEXT: "clausec" >> construct<TdlClause>(construct<TdlClause::Clausec>(parenthesized(nonemptyList(Parser<IntExpr>{})))) ||
253 // IMPL-NEXT: "clauseb" >> construct<TdlClause>(construct<TdlClause::Clauseb>(maybe(parenthesized(Parser<IntExpr>{})))) ||
254 // IMPL-NEXT: "clausea" >> construct<TdlClause>(construct<TdlClause::Clausea>())
257 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSES_PARSER
259 // IMPL-NEXT: #ifdef GEN_CLANG_CLAUSE_CLASS
260 // IMPL-NEXT: #undef GEN_CLANG_CLAUSE_CLASS
262 // IMPL-NEXT: #ifndef CLAUSE
263 // IMPL-NEXT: #define CLAUSE(Enum, Str, Implicit)
265 // IMPL-NEXT: #ifndef CLAUSE_CLASS
266 // IMPL-NEXT: #define CLAUSE_CLASS(Enum, Str, Class)
268 // IMPL-NEXT: #ifndef CLAUSE_NO_CLASS
269 // IMPL-NEXT: #define CLAUSE_NO_CLASS(Enum, Str)
272 // IMPL-NEXT: #define __CLAUSE(Name, Class) \
273 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
274 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, #Name, Class)
275 // IMPL-NEXT: #define __CLAUSE_NO_CLASS(Name) \
276 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
277 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, #Name)
278 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class) \
279 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
280 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, Str, Class)
281 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str) \
282 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
283 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, Str)
285 // IMPL-NEXT: __CLAUSE_NO_CLASS(clausea)
286 // IMPL-NEXT: __CLAUSE_NO_CLASS(clauseb)
287 // IMPL-NEXT: __CLAUSE_NO_CLASS(clausec)
289 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_NO_CLASS
290 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_CLASS
291 // IMPL-NEXT: #undef __CLAUSE_NO_CLASS
292 // IMPL-NEXT: #undef __CLAUSE
293 // IMPL-NEXT: #undef CLAUSE_NO_CLASS
294 // IMPL-NEXT: #undef CLAUSE_CLASS
295 // IMPL-NEXT: #undef CLAUSE
297 // IMPL-NEXT: #endif // GEN_CLANG_CLAUSE_CLASS
300 // IMPL: #ifdef GEN_DIRECTIVES_IMPL
301 // IMPL-NEXT: #undef GEN_DIRECTIVES_IMPL
303 // IMPL-NEXT: #include "llvm/Support/ErrorHandling.h"
305 // IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
306 // IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
307 // IMPL-NEXT: .Case("dira",TDLD_dira)
308 // IMPL-NEXT: .Default(TDLD_dira);
311 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) {
312 // IMPL-NEXT: switch (Kind) {
313 // IMPL-NEXT: case TDLD_dira:
314 // IMPL-NEXT: return "dira";
316 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
319 // IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
320 // IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
321 // IMPL-NEXT: .Case("clausea",TDLC_clausea)
322 // IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
323 // IMPL-NEXT: .Case("clausec",TDLC_clausec)
324 // IMPL-NEXT: .Default(TDLC_clauseb);
327 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) {
328 // IMPL-NEXT: switch (Kind) {
329 // IMPL-NEXT: case TDLC_clausea:
330 // IMPL-NEXT: return "clausea";
331 // IMPL-NEXT: case TDLC_clauseb:
332 // IMPL-NEXT: return "clauseb";
333 // IMPL-NEXT: case TDLC_clausec:
334 // IMPL-NEXT: return "clausec";
336 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
339 // IMPL-NEXT: AKind llvm::tdl::getAKind(llvm::StringRef Str) {
340 // IMPL-NEXT: return llvm::StringSwitch<AKind>(Str)
341 // IMPL-NEXT: .Case("vala",TDLCV_vala)
342 // IMPL-NEXT: .Case("valb",TDLCV_valb)
343 // IMPL-NEXT: .Case("valc",TDLCV_valc)
344 // IMPL-NEXT: .Default(TDLCV_valc);
347 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlAKindName(llvm::tdl::AKind x) {
348 // IMPL-NEXT: switch (x) {
349 // IMPL-NEXT: case TDLCV_vala:
350 // IMPL-NEXT: return "vala";
351 // IMPL-NEXT: case TDLCV_valb:
352 // IMPL-NEXT: return "valb";
353 // IMPL-NEXT: case TDLCV_valc:
354 // IMPL-NEXT: return "valc";
356 // IMPL-NEXT: llvm_unreachable("Invalid Tdl AKind kind");
359 // IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
360 // IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
361 // IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
362 // IMPL-NEXT: switch (D) {
363 // IMPL-NEXT: case TDLD_dira:
364 // IMPL-NEXT: switch (C) {
365 // IMPL-NEXT: case TDLC_clausea:
366 // IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
367 // IMPL-NEXT: case TDLC_clauseb:
368 // IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
369 // IMPL-NEXT: default:
370 // IMPL-NEXT: return false;
374 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
377 // IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive Dir) {
378 // IMPL-NEXT: switch (Dir) {
379 // IMPL-NEXT: case llvm::tdl::Directive::TDLD_dira:
380 // IMPL-NEXT: return llvm::tdl::Association::None;
381 // IMPL-NEXT: } // switch (Dir)
382 // IMPL-NEXT: llvm_unreachable("Unexpected directive");
385 // IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive Dir) {
386 // IMPL-NEXT: switch (Dir) {
387 // IMPL-NEXT: case llvm::tdl::TDLD_dira:
388 // IMPL-NEXT: return llvm::tdl::Category::Executable;
389 // IMPL-NEXT: } // switch (Dir)
390 // IMPL-NEXT: llvm_unreachable("Unexpected directive");
393 // IMPL-NEXT: static_assert(sizeof(llvm::tdl::Directive) == sizeof(int));
394 // IMPL-NEXT: {{.*}} static const llvm::tdl::Directive LeafConstructTable[][2] = {
395 // IMPL-NEXT: {llvm::tdl::TDLD_dira, static_cast<llvm::tdl::Directive>(0),},
398 // IMPL-NEXT: {{.*}} static auto LeafConstructTableEndDirective = LeafConstructTable + 1;
400 // IMPL-NEXT: {{.*}} static const int LeafConstructTableOrdering[] = {
404 // IMPL-NEXT: #endif // GEN_DIRECTIVES_IMPL