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 includeHeader = "tdl.h.inc";
13 let flangClauseBaseClass = "TdlClause";
16 def TDLC_ClauseA : Clause<"clausea"> {
19 def TDLC_ClauseB : Clause<"clauseb"> {
21 let flangClass = "IntExpr";
24 def TDLC_ClauseC : Clause<"clausec"> {
25 let clangClass = "ClauseC";
26 let flangClass = "Name";
27 let defaultValue = "*";
28 let isValueOptional = 1;
30 def TDLC_ClauseD : Clause<"claused"> {
31 let clangClass = "ClauseD";
35 def TDL_DirA : Directive<"dira"> {
36 let allowedClauses = [
37 VersionedClause<TDLC_ClauseA, 2, 4>,
38 VersionedClause<TDLC_ClauseB, 2>
41 let association = AS_Block;
42 let category = CA_Declarative;
45 // CHECK: #ifndef LLVM_Tdl_INC
46 // CHECK-NEXT: #define LLVM_Tdl_INC
48 // CHECK-NEXT: #include "llvm/ADT/ArrayRef.h"
49 // CHECK-NEXT: #include <cstddef>
51 // CHECK-NEXT: namespace llvm {
52 // CHECK-NEXT: class StringRef;
53 // CHECK-NEXT: namespace tdl {
55 // CHECK-NEXT: enum class Association {
57 // CHECK-NEXT: Declaration,
58 // CHECK-NEXT: Delimited,
61 // CHECK-NEXT: Separating,
64 // CHECK-NEXT: static constexpr std::size_t Association_enumSize = 6;
66 // CHECK-NEXT: enum class Category {
67 // CHECK-NEXT: Declarative,
68 // CHECK-NEXT: Executable,
69 // CHECK-NEXT: Informational,
71 // CHECK-NEXT: Subsidiary,
72 // CHECK-NEXT: Utility,
75 // CHECK-NEXT: static constexpr std::size_t Category_enumSize = 6;
77 // CHECK-NEXT: enum class Directive {
78 // CHECK-NEXT: TDLD_dira,
81 // CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1;
83 // CHECK-NEXT: enum class Clause {
84 // CHECK-NEXT: TDLC_clausea,
85 // CHECK-NEXT: TDLC_clauseb,
86 // CHECK-NEXT: TDLC_clausec,
87 // CHECK-NEXT: TDLC_claused,
90 // CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 4;
92 // CHECK-NEXT: // Enumeration helper functions
93 // CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str);
95 // CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D);
97 // CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str);
99 // CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C);
101 // CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
102 // CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
104 // CHECK-NEXT: constexpr std::size_t getMaxLeafCount() { return 0; }
105 // CHECK-NEXT: Association getDirectiveAssociation(Directive D);
106 // CHECK-NEXT: Category getDirectiveCategory(Directive D);
107 // CHECK-NEXT: } // namespace tdl
108 // CHECK-NEXT: } // namespace llvm
109 // CHECK-NEXT: #endif // LLVM_Tdl_INC
111 // IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
112 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
114 // IMPL-NEXT: namespace llvm {
115 // IMPL-NEXT: namespace tdl {
117 // IMPL-NEXT: // Sets for dira
119 // IMPL-NEXT: static allowedClauses_TDLD_dira {
120 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clausea,
121 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clauseb,
124 // IMPL-NEXT: static allowedOnceClauses_TDLD_dira {
127 // IMPL-NEXT: static allowedExclusiveClauses_TDLD_dira {
130 // IMPL-NEXT: static requiredClauses_TDLD_dira {
132 // IMPL-NEXT: } // namespace tdl
133 // IMPL-NEXT: } // namespace llvm
135 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
137 // IMPL-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
138 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
141 // IMPL-NEXT: {llvm::tdl::Directive::TDLD_dira,
143 // IMPL-NEXT: llvm::tdl::allowedClauses_TDLD_dira,
144 // IMPL-NEXT: llvm::tdl::allowedOnceClauses_TDLD_dira,
145 // IMPL-NEXT: llvm::tdl::allowedExclusiveClauses_TDLD_dira,
146 // IMPL-NEXT: llvm::tdl::requiredClauses_TDLD_dira,
151 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
153 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
154 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
156 // IMPL-NEXT: EMPTY_CLASS(Clausea);
157 // IMPL-NEXT: WRAPPER_CLASS(Clauseb, std::list<IntExpr>);
158 // IMPL-NEXT: WRAPPER_CLASS(Clausec, std::optional<Name>);
159 // IMPL-NEXT: EMPTY_CLASS(Claused);
161 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
163 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
164 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
166 // IMPL-NEXT: Clausea
167 // IMPL-NEXT: , Clauseb
168 // IMPL-NEXT: , Clausec
169 // IMPL-NEXT: , Claused
171 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
173 // IMPL-NEXT: #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
174 // IMPL-NEXT: #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
176 // IMPL-NEXT: NODE(TdlClause, Clausea)
177 // IMPL-NEXT: NODE(TdlClause, Clauseb)
178 // IMPL-NEXT: NODE(TdlClause, Clausec)
179 // IMPL-NEXT: NODE(TdlClause, Claused)
181 // IMPL-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
183 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_UNPARSE
184 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_UNPARSE
186 // IMPL-NEXT: void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
187 // IMPL-NEXT: void Unparse(const TdlClause::Clauseb &x) {
188 // IMPL-NEXT: Word("CLAUSEB");
189 // IMPL-NEXT: Put("(");
190 // IMPL-NEXT: Walk(x.v, ",");
191 // IMPL-NEXT: Put(")");
193 // IMPL-NEXT: void Unparse(const TdlClause::Clausec &x) {
194 // IMPL-NEXT: Word("CLAUSEC");
195 // IMPL-NEXT: Put("(");
196 // IMPL-NEXT: if (x.v.has_value())
197 // IMPL-NEXT: Walk(x.v);
199 // IMPL-NEXT: Put("*");
200 // IMPL-NEXT: Put(")");
202 // IMPL-NEXT: void Before(const TdlClause::Claused &) { Word("CLAUSED"); }
204 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_UNPARSE
206 // IMPL: #ifdef GEN_CLANG_CLAUSE_CLASS
207 // IMPL-NEXT: #undef GEN_CLANG_CLAUSE_CLASS
209 // IMPL-NEXT: #ifndef CLAUSE
210 // IMPL-NEXT: #define CLAUSE(Enum, Str, Implicit)
212 // IMPL-NEXT: #ifndef CLAUSE_CLASS
213 // IMPL-NEXT: #define CLAUSE_CLASS(Enum, Str, Class)
215 // IMPL-NEXT: #ifndef CLAUSE_NO_CLASS
216 // IMPL-NEXT: #define CLAUSE_NO_CLASS(Enum, Str)
219 // IMPL-NEXT: #define __CLAUSE(Name, Class) \
220 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
221 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, #Name, Class)
222 // IMPL-NEXT: #define __CLAUSE_NO_CLASS(Name) \
223 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
224 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, #Name)
225 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class) \
226 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
227 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, Str, Class)
228 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str) \
229 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
230 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, Str)
232 // IMPL-NEXT: __IMPLICIT_CLAUSE_NO_CLASS(clausea, "clausea")
233 // IMPL-NEXT: __CLAUSE_NO_CLASS(clauseb)
234 // IMPL-NEXT: __CLAUSE(clausec, ClauseC)
235 // IMPL-NEXT: __IMPLICIT_CLAUSE_CLASS(claused, "claused", ClauseD)
237 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_NO_CLASS
238 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_CLASS
239 // IMPL-NEXT: #undef __CLAUSE_NO_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
247 // IMPL: #ifdef GEN_DIRECTIVES_IMPL
248 // IMPL-NEXT: #undef GEN_DIRECTIVES_IMPL
250 // IMPL-NEXT: #include "llvm/Support/ErrorHandling.h"
252 // IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
253 // IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
254 // IMPL-NEXT: .Case("dira",TDLD_dira)
255 // IMPL-NEXT: .Default(TDLD_dira);
258 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) {
259 // IMPL-NEXT: switch (Kind) {
260 // IMPL-NEXT: case TDLD_dira:
261 // IMPL-NEXT: return "dira";
263 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
266 // IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
267 // IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
268 // IMPL-NEXT: .Case("clausea",TDLC_clauseb)
269 // IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
270 // IMPL-NEXT: .Case("clausec",TDLC_clausec)
271 // IMPL-NEXT: .Case("claused",TDLC_clauseb)
272 // IMPL-NEXT: .Default(TDLC_clauseb);
275 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) {
276 // IMPL-NEXT: switch (Kind) {
277 // IMPL-NEXT: case TDLC_clausea:
278 // IMPL-NEXT: return "clausea";
279 // IMPL-NEXT: case TDLC_clauseb:
280 // IMPL-NEXT: return "clauseb";
281 // IMPL-NEXT: case TDLC_clausec:
282 // IMPL-NEXT: return "clausec";
283 // IMPL-NEXT: case TDLC_claused:
284 // IMPL-NEXT: return "claused";
286 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
289 // IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
290 // IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
291 // IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
292 // IMPL-NEXT: switch (D) {
293 // IMPL-NEXT: case TDLD_dira:
294 // IMPL-NEXT: switch (C) {
295 // IMPL-NEXT: case TDLC_clausea:
296 // IMPL-NEXT: return 2 <= Version && 4 >= Version;
297 // IMPL-NEXT: case TDLC_clauseb:
298 // IMPL-NEXT: return 2 <= Version && 2147483647 >= Version;
299 // IMPL-NEXT: default:
300 // IMPL-NEXT: return false;
304 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
307 // IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive Dir) {
308 // IMPL-NEXT: switch (Dir) {
309 // IMPL-NEXT: case llvm::tdl::Directive::TDLD_dira:
310 // IMPL-NEXT: return llvm::tdl::Association::Block;
311 // IMPL-NEXT: } // switch (Dir)
312 // IMPL-NEXT: llvm_unreachable("Unexpected directive");
315 // IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive Dir) {
316 // IMPL-NEXT: switch (Dir) {
317 // IMPL-NEXT: case llvm::tdl::TDLD_dira:
318 // IMPL-NEXT: return llvm::tdl::Category::Declarative;
319 // IMPL-NEXT: } // switch (Dir)
320 // IMPL-NEXT: llvm_unreachable("Unexpected directive");
323 // IMPL-NEXT: static_assert(sizeof(llvm::tdl::Directive) == sizeof(int));
324 // IMPL-NEXT: {{.*}} static const llvm::tdl::Directive LeafConstructTable[][2] = {
325 // IMPL-NEXT: {llvm::tdl::TDLD_dira, static_cast<llvm::tdl::Directive>(0),},
328 // IMPL-NEXT: {{.*}} static auto LeafConstructTableEndDirective = LeafConstructTable + 1;
330 // IMPL-NEXT: {{.*}} static const int LeafConstructTableOrdering[] = {
334 // IMPL-NEXT: #endif // GEN_DIRECTIVES_IMPL