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 TDL_DirA : Directive<"dira"> {
37 let allowedClauses = [
38 VersionedClause<TDLC_ClauseA>,
39 VersionedClause<TDLC_ClauseB>
44 // CHECK: #ifndef LLVM_Tdl_INC
45 // CHECK-NEXT: #define LLVM_Tdl_INC
47 // CHECK-NEXT: #include "llvm/ADT/BitmaskEnum.h"
49 // CHECK-NEXT: namespace llvm {
50 // CHECK-NEXT: class StringRef;
51 // CHECK-NEXT: namespace tdl {
53 // CHECK-NEXT: LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
55 // CHECK-NEXT: enum class Directive {
56 // CHECK-NEXT: TDLD_dira,
59 // CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1;
61 // CHECK-NEXT: constexpr auto TDLD_dira = llvm::tdl::Directive::TDLD_dira;
63 // CHECK-NEXT: enum class Clause {
64 // CHECK-NEXT: TDLC_clausea,
65 // CHECK-NEXT: TDLC_clauseb,
68 // CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 2;
70 // CHECK-NEXT: constexpr auto TDLC_clausea = llvm::tdl::Clause::TDLC_clausea;
71 // CHECK-NEXT: constexpr auto TDLC_clauseb = llvm::tdl::Clause::TDLC_clauseb;
73 // CHECK-NEXT: enum class AKind {
74 // CHECK-NEXT: TDLCV_vala=1,
75 // CHECK-NEXT: TDLCV_valb=2,
76 // CHECK-NEXT: TDLCV_valc=3,
79 // CHECK-NEXT: constexpr auto TDLCV_vala = llvm::tdl::AKind::TDLCV_vala;
80 // CHECK-NEXT: constexpr auto TDLCV_valb = llvm::tdl::AKind::TDLCV_valb;
81 // CHECK-NEXT: constexpr auto TDLCV_valc = llvm::tdl::AKind::TDLCV_valc;
83 // CHECK-NEXT: // Enumeration helper functions
84 // CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str);
86 // CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D);
88 // CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str);
90 // CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C);
92 // CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
93 // CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
95 // CHECK-NEXT: AKind getAKind(StringRef);
96 // CHECK-NEXT: llvm::StringRef getTdlAKindName(AKind);
98 // CHECK-NEXT: } // namespace tdl
99 // CHECK-NEXT: } // namespace llvm
100 // CHECK-NEXT: #endif // LLVM_Tdl_INC
103 // IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
104 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
106 // IMPL-NEXT: namespace llvm {
107 // IMPL-NEXT: namespace tdl {
109 // IMPL-NEXT: // Sets for dira
111 // IMPL-NEXT: static allowedClauses_TDLD_dira {
112 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clausea,
113 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clauseb,
116 // IMPL-NEXT: static allowedOnceClauses_TDLD_dira {
119 // IMPL-NEXT: static allowedExclusiveClauses_TDLD_dira {
122 // IMPL-NEXT: static requiredClauses_TDLD_dira {
124 // IMPL-NEXT: } // namespace tdl
125 // IMPL-NEXT: } // namespace llvm
127 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
129 // IMPL-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
130 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
133 // IMPL-NEXT: {llvm::tdl::Directive::TDLD_dira,
135 // IMPL-NEXT: llvm::tdl::allowedClauses_TDLD_dira,
136 // IMPL-NEXT: llvm::tdl::allowedOnceClauses_TDLD_dira,
137 // IMPL-NEXT: llvm::tdl::allowedExclusiveClauses_TDLD_dira,
138 // IMPL-NEXT: llvm::tdl::requiredClauses_TDLD_dira,
143 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
145 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
146 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
148 // IMPL-NEXT: EMPTY_CLASS(Clausea);
149 // IMPL-NEXT: WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
151 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
153 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
154 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
156 // IMPL-NEXT: Clausea
157 // IMPL-NEXT: , Clauseb
159 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
161 // IMPL-NEXT: #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
162 // IMPL-NEXT: #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
164 // IMPL-NEXT: NODE(TdlClause, Clausea)
165 // IMPL-NEXT: NODE(TdlClause, Clauseb)
167 // IMPL-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
169 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_UNPARSE
170 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_UNPARSE
172 // IMPL-NEXT: void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
173 // IMPL-NEXT: void Unparse(const TdlClause::Clauseb &x) {
174 // IMPL-NEXT: Word("CLAUSEB");
175 // IMPL-NEXT: Walk("(", x.v, ")");
178 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_UNPARSE
180 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_CHECK_ENTER
181 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_CHECK_ENTER
183 // IMPL-NEXT: void Enter(const parser::TdlClause::Clausea &);
184 // IMPL-NEXT: void Enter(const parser::TdlClause::Clauseb &);
186 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_CHECK_ENTER
188 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
189 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
191 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clausea>)
192 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clausea;
193 // IMPL-NEXT: if constexpr (std::is_same_v<A, parser::TdlClause::Clauseb>)
194 // IMPL-NEXT: return llvm::tdl::Clause::TDLC_clauseb;
195 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Parser clause");
197 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_KIND_MAP
199 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSES_PARSER
200 // IMPL-NEXT: #undef GEN_FLANG_CLAUSES_PARSER
202 // IMPL-NEXT: TYPE_PARSER(
203 // IMPL-NEXT: "clauseb" >> construct<TdlClause>(construct<TdlClause::Clauseb>(maybe(parenthesized(Parser<IntExpr>{})))) ||
204 // IMPL-NEXT: "clausea" >> construct<TdlClause>(construct<TdlClause::Clausea>())
207 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSES_PARSER
209 // IMPL-NEXT: #ifdef GEN_CLANG_CLAUSE_CLASS
210 // IMPL-NEXT: #undef GEN_CLANG_CLAUSE_CLASS
212 // IMPL-NEXT: #ifndef CLAUSE
213 // IMPL-NEXT: #define CLAUSE(Enum, Str, Implicit)
215 // IMPL-NEXT: #ifndef CLAUSE_CLASS
216 // IMPL-NEXT: #define CLAUSE_CLASS(Enum, Str, Class)
218 // IMPL-NEXT: #ifndef CLAUSE_NO_CLASS
219 // IMPL-NEXT: #define CLAUSE_NO_CLASS(Enum, Str)
222 // IMPL-NEXT: #define __CLAUSE(Name, Class) \
223 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
224 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, #Name, Class)
225 // IMPL-NEXT: #define __CLAUSE_NO_CLASS(Name) \
226 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
227 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, #Name)
228 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class) \
229 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
230 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, Str, Class)
231 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str) \
232 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
233 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, Str)
235 // IMPL-NEXT: __CLAUSE_NO_CLASS(clausea)
236 // IMPL-NEXT: __CLAUSE_NO_CLASS(clauseb)
238 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_NO_CLASS
239 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_CLASS
240 // IMPL-NEXT: #undef __CLAUSE
241 // IMPL-NEXT: #undef CLAUSE_NO_CLASS
242 // IMPL-NEXT: #undef CLAUSE_CLASS
243 // IMPL-NEXT: #undef CLAUSE
245 // IMPL-NEXT: #endif // GEN_CLANG_CLAUSE_CLASS
248 // IMPL: #ifdef GEN_DIRECTIVES_IMPL
249 // IMPL-NEXT: #undef GEN_DIRECTIVES_IMPL
251 // IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
252 // IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
253 // IMPL-NEXT: .Case("dira",TDLD_dira)
254 // IMPL-NEXT: .Default(TDLD_dira);
257 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) {
258 // IMPL-NEXT: switch (Kind) {
259 // IMPL-NEXT: case TDLD_dira:
260 // IMPL-NEXT: return "dira";
262 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
265 // IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
266 // IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
267 // IMPL-NEXT: .Case("clausea",TDLC_clausea)
268 // IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
269 // IMPL-NEXT: .Default(TDLC_clauseb);
272 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) {
273 // IMPL-NEXT: switch (Kind) {
274 // IMPL-NEXT: case TDLC_clausea:
275 // IMPL-NEXT: return "clausea";
276 // IMPL-NEXT: case TDLC_clauseb:
277 // IMPL-NEXT: return "clauseb";
279 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
282 // IMPL-NEXT: AKind llvm::tdl::getAKind(llvm::StringRef Str) {
283 // IMPL-NEXT: return llvm::StringSwitch<AKind>(Str)
284 // IMPL-NEXT: .Case("vala",TDLCV_vala)
285 // IMPL-NEXT: .Case("valb",TDLCV_valb)
286 // IMPL-NEXT: .Case("valc",TDLCV_valc)
287 // IMPL-NEXT: .Default(TDLCV_valc);
290 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlAKindName(llvm::tdl::AKind x) {
291 // IMPL-NEXT: switch (x) {
292 // IMPL-NEXT: case TDLCV_vala:
293 // IMPL-NEXT: return "vala";
294 // IMPL-NEXT: case TDLCV_valb:
295 // IMPL-NEXT: return "valb";
296 // IMPL-NEXT: case TDLCV_valc:
297 // IMPL-NEXT: return "valc";
299 // IMPL-NEXT: llvm_unreachable("Invalid Tdl AKind kind");
302 // IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
303 // IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
304 // IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
305 // IMPL-NEXT: switch (D) {
306 // IMPL-NEXT: case TDLD_dira:
307 // IMPL-NEXT: switch (C) {
308 // IMPL-NEXT: case TDLC_clausea:
309 // IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
310 // IMPL-NEXT: case TDLC_clauseb:
311 // IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
312 // IMPL-NEXT: default:
313 // IMPL-NEXT: return false;
317 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
320 // IMPL-NEXT: #endif // GEN_DIRECTIVES_IMPL