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>
49 // CHECK: #ifndef LLVM_Tdl_INC
50 // CHECK-NEXT: #define LLVM_Tdl_INC
52 // CHECK-NEXT: #include "llvm/ADT/BitmaskEnum.h"
54 // CHECK-NEXT: namespace llvm {
55 // CHECK-NEXT: class StringRef;
56 // CHECK-NEXT: namespace tdl {
58 // CHECK-NEXT: LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
60 // CHECK-NEXT: enum class Directive {
61 // CHECK-NEXT: TDLD_dira,
64 // CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1;
66 // CHECK-NEXT: constexpr auto TDLD_dira = llvm::tdl::Directive::TDLD_dira;
68 // CHECK-NEXT: enum class Clause {
69 // CHECK-NEXT: TDLC_clausea,
70 // CHECK-NEXT: TDLC_clauseb,
71 // CHECK-NEXT: TDLC_clausec,
74 // CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 3;
76 // CHECK-NEXT: constexpr auto TDLC_clausea = llvm::tdl::Clause::TDLC_clausea;
77 // CHECK-NEXT: constexpr auto TDLC_clauseb = llvm::tdl::Clause::TDLC_clauseb;
78 // CHECK-NEXT: constexpr auto TDLC_clausec = llvm::tdl::Clause::TDLC_clausec;
80 // CHECK-NEXT: enum class AKind {
81 // CHECK-NEXT: TDLCV_vala=1,
82 // CHECK-NEXT: TDLCV_valb=2,
83 // CHECK-NEXT: TDLCV_valc=3,
86 // CHECK-NEXT: constexpr auto TDLCV_vala = llvm::tdl::AKind::TDLCV_vala;
87 // CHECK-NEXT: constexpr auto TDLCV_valb = llvm::tdl::AKind::TDLCV_valb;
88 // CHECK-NEXT: constexpr auto TDLCV_valc = llvm::tdl::AKind::TDLCV_valc;
90 // CHECK-NEXT: // Enumeration helper functions
91 // CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str);
93 // CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D);
95 // CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str);
97 // CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C);
99 // CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
100 // CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
102 // CHECK-NEXT: AKind getAKind(StringRef);
103 // CHECK-NEXT: llvm::StringRef getTdlAKindName(AKind);
105 // CHECK-NEXT: } // namespace tdl
106 // CHECK-NEXT: } // namespace llvm
107 // CHECK-NEXT: #endif // LLVM_Tdl_INC
110 // IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
111 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
113 // IMPL-NEXT: namespace llvm {
114 // IMPL-NEXT: namespace tdl {
116 // IMPL-NEXT: // Sets for dira
118 // IMPL-NEXT: static allowedClauses_TDLD_dira {
119 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clausea,
120 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clauseb,
123 // IMPL-NEXT: static allowedOnceClauses_TDLD_dira {
126 // IMPL-NEXT: static allowedExclusiveClauses_TDLD_dira {
129 // IMPL-NEXT: static requiredClauses_TDLD_dira {
131 // IMPL-NEXT: } // namespace tdl
132 // IMPL-NEXT: } // namespace llvm
134 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
136 // IMPL-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
137 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
140 // IMPL-NEXT: {llvm::tdl::Directive::TDLD_dira,
142 // IMPL-NEXT: llvm::tdl::allowedClauses_TDLD_dira,
143 // IMPL-NEXT: llvm::tdl::allowedOnceClauses_TDLD_dira,
144 // IMPL-NEXT: llvm::tdl::allowedExclusiveClauses_TDLD_dira,
145 // IMPL-NEXT: llvm::tdl::requiredClauses_TDLD_dira,
150 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
152 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
153 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
155 // IMPL-NEXT: EMPTY_CLASS(Clausea);
156 // IMPL-NEXT: WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
157 // IMPL-NEXT: WRAPPER_CLASS(Clausec, std::list<IntExpr>);
159 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
161 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
162 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
164 // IMPL-NEXT: Clausea
165 // IMPL-NEXT: , Clauseb
166 // IMPL-NEXT: , Clausec
168 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
170 // IMPL-NEXT: #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
171 // IMPL-NEXT: #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
173 // IMPL-NEXT: NODE(TdlClause, Clausea)
174 // IMPL-NEXT: NODE(TdlClause, Clauseb)
175 // IMPL-NEXT: NODE(TdlClause, Clausec)
177 // IMPL-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
179 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_UNPARSE
180 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_UNPARSE
182 // IMPL-NEXT: void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
183 // IMPL-NEXT: void Unparse(const TdlClause::Clauseb &x) {
184 // IMPL-NEXT: Word("CLAUSEB");
185 // IMPL-NEXT: Walk("(", x.v, ")");
187 // IMPL-NEXT: void Unparse(const TdlClause::Clausec &x) {
188 // IMPL-NEXT: Word("CLAUSEC");
189 // IMPL-NEXT: Put("(");
190 // IMPL-NEXT: Walk(x.v, ",");
191 // IMPL-NEXT: Put(")");
194 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_UNPARSE
196 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_CHECK_ENTER
197 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_CHECK_ENTER
199 // IMPL-NEXT: void Enter(const parser::TdlClause::Clausea &);
200 // IMPL-NEXT: void Enter(const parser::TdlClause::Clauseb &);
201 // IMPL-NEXT: void Enter(const parser::TdlClause::Clausec &);
203 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_CHECK_ENTER
205 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
206 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
208 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clausea>)
209 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausea;
210 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clauseb>)
211 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clauseb;
212 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clausec>)
213 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausec;
214 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Parser clause");
216 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_KIND_MAP
218 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSES_PARSER
219 // IMPL-NEXT: #undef GEN_FLANG_CLAUSES_PARSER
221 // IMPL-NEXT: TYPE_PARSER(
222 // IMPL-NEXT: "clausec" >> construct<TdlClause>(construct<TdlClause::Clausec>(parenthesized(nonemptyList(Parser<IntExpr>{})))) ||
223 // IMPL-NEXT: "clauseb" >> construct<TdlClause>(construct<TdlClause::Clauseb>(maybe(parenthesized(Parser<IntExpr>{})))) ||
224 // IMPL-NEXT: "clausea" >> construct<TdlClause>(construct<TdlClause::Clausea>())
227 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSES_PARSER
229 // IMPL-NEXT: #ifdef GEN_CLANG_CLAUSE_CLASS
230 // IMPL-NEXT: #undef GEN_CLANG_CLAUSE_CLASS
232 // IMPL-NEXT: #ifndef CLAUSE
233 // IMPL-NEXT: #define CLAUSE(Enum, Str, Implicit)
235 // IMPL-NEXT: #ifndef CLAUSE_CLASS
236 // IMPL-NEXT: #define CLAUSE_CLASS(Enum, Str, Class)
238 // IMPL-NEXT: #ifndef CLAUSE_NO_CLASS
239 // IMPL-NEXT: #define CLAUSE_NO_CLASS(Enum, Str)
242 // IMPL-NEXT: #define __CLAUSE(Name, Class) \
243 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
244 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, #Name, Class)
245 // IMPL-NEXT: #define __CLAUSE_NO_CLASS(Name) \
246 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
247 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, #Name)
248 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class) \
249 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
250 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, Str, Class)
251 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str) \
252 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
253 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, Str)
255 // IMPL-NEXT: __CLAUSE_NO_CLASS(clausea)
256 // IMPL-NEXT: __CLAUSE_NO_CLASS(clauseb)
257 // IMPL-NEXT: __CLAUSE_NO_CLASS(clausec)
259 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_NO_CLASS
260 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_CLASS
261 // IMPL-NEXT: #undef __CLAUSE
262 // IMPL-NEXT: #undef CLAUSE_NO_CLASS
263 // IMPL-NEXT: #undef CLAUSE_CLASS
264 // IMPL-NEXT: #undef CLAUSE
266 // IMPL-NEXT: #endif // GEN_CLANG_CLAUSE_CLASS
269 // IMPL: #ifdef GEN_DIRECTIVES_IMPL
270 // IMPL-NEXT: #undef GEN_DIRECTIVES_IMPL
272 // IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
273 // IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
274 // IMPL-NEXT: .Case("dira",TDLD_dira)
275 // IMPL-NEXT: .Default(TDLD_dira);
278 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) {
279 // IMPL-NEXT: switch (Kind) {
280 // IMPL-NEXT: case TDLD_dira:
281 // IMPL-NEXT: return "dira";
283 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
286 // IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
287 // IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
288 // IMPL-NEXT: .Case("clausea",TDLC_clausea)
289 // IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
290 // IMPL-NEXT: .Case("clausec",TDLC_clausec)
291 // IMPL-NEXT: .Default(TDLC_clauseb);
294 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) {
295 // IMPL-NEXT: switch (Kind) {
296 // IMPL-NEXT: case TDLC_clausea:
297 // IMPL-NEXT: return "clausea";
298 // IMPL-NEXT: case TDLC_clauseb:
299 // IMPL-NEXT: return "clauseb";
300 // IMPL-NEXT: case TDLC_clausec:
301 // IMPL-NEXT: return "clausec";
303 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
306 // IMPL-NEXT: AKind llvm::tdl::getAKind(llvm::StringRef Str) {
307 // IMPL-NEXT: return llvm::StringSwitch<AKind>(Str)
308 // IMPL-NEXT: .Case("vala",TDLCV_vala)
309 // IMPL-NEXT: .Case("valb",TDLCV_valb)
310 // IMPL-NEXT: .Case("valc",TDLCV_valc)
311 // IMPL-NEXT: .Default(TDLCV_valc);
314 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlAKindName(llvm::tdl::AKind x) {
315 // IMPL-NEXT: switch (x) {
316 // IMPL-NEXT: case TDLCV_vala:
317 // IMPL-NEXT: return "vala";
318 // IMPL-NEXT: case TDLCV_valb:
319 // IMPL-NEXT: return "valb";
320 // IMPL-NEXT: case TDLCV_valc:
321 // IMPL-NEXT: return "valc";
323 // IMPL-NEXT: llvm_unreachable("Invalid Tdl AKind kind");
326 // IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
327 // IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
328 // IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
329 // IMPL-NEXT: switch (D) {
330 // IMPL-NEXT: case TDLD_dira:
331 // IMPL-NEXT: switch (C) {
332 // IMPL-NEXT: case TDLC_clausea:
333 // IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
334 // IMPL-NEXT: case TDLC_clauseb:
335 // IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
336 // IMPL-NEXT: default:
337 // IMPL-NEXT: return false;
341 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
344 // IMPL-NEXT: #endif // GEN_DIRECTIVES_IMPL