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>
43 // CHECK: #ifndef LLVM_Tdl_INC
44 // CHECK-NEXT: #define LLVM_Tdl_INC
46 // CHECK-NEXT: namespace llvm {
47 // CHECK-NEXT: class StringRef;
48 // CHECK-NEXT: namespace tdl {
50 // CHECK-NEXT: enum class Directive {
51 // CHECK-NEXT: TDLD_dira,
54 // CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1;
56 // CHECK-NEXT: enum class Clause {
57 // CHECK-NEXT: TDLC_clausea,
58 // CHECK-NEXT: TDLC_clauseb,
59 // CHECK-NEXT: TDLC_clausec,
60 // CHECK-NEXT: TDLC_claused,
63 // CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 4;
65 // CHECK-NEXT: // Enumeration helper functions
66 // CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str);
68 // CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D);
70 // CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str);
72 // CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C);
74 // CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version.
75 // CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
77 // CHECK-NEXT: } // namespace tdl
78 // CHECK-NEXT: } // namespace llvm
79 // CHECK-NEXT: #endif // LLVM_Tdl_INC
81 // IMPL: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
82 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
84 // IMPL-NEXT: namespace llvm {
85 // IMPL-NEXT: namespace tdl {
87 // IMPL-NEXT: // Sets for dira
89 // IMPL-NEXT: static allowedClauses_TDLD_dira {
90 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clausea,
91 // IMPL-NEXT: llvm::tdl::Clause::TDLC_clauseb,
94 // IMPL-NEXT: static allowedOnceClauses_TDLD_dira {
97 // IMPL-NEXT: static allowedExclusiveClauses_TDLD_dira {
100 // IMPL-NEXT: static requiredClauses_TDLD_dira {
102 // IMPL-NEXT: } // namespace tdl
103 // IMPL-NEXT: } // namespace llvm
105 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
107 // IMPL-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
108 // IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
111 // IMPL-NEXT: {llvm::tdl::Directive::TDLD_dira,
113 // IMPL-NEXT: llvm::tdl::allowedClauses_TDLD_dira,
114 // IMPL-NEXT: llvm::tdl::allowedOnceClauses_TDLD_dira,
115 // IMPL-NEXT: llvm::tdl::allowedExclusiveClauses_TDLD_dira,
116 // IMPL-NEXT: llvm::tdl::requiredClauses_TDLD_dira,
121 // IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
123 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
124 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
126 // IMPL-NEXT: EMPTY_CLASS(Clausea);
127 // IMPL-NEXT: WRAPPER_CLASS(Clauseb, std::list<IntExpr>);
128 // IMPL-NEXT: WRAPPER_CLASS(Clausec, std::optional<Name>);
129 // IMPL-NEXT: EMPTY_CLASS(Claused);
131 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
133 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
134 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
136 // IMPL-NEXT: Clausea
137 // IMPL-NEXT: , Clauseb
138 // IMPL-NEXT: , Clausec
139 // IMPL-NEXT: , Claused
141 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
143 // IMPL-NEXT: #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
144 // IMPL-NEXT: #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
146 // IMPL-NEXT: NODE(TdlClause, Clausea)
147 // IMPL-NEXT: NODE(TdlClause, Clauseb)
148 // IMPL-NEXT: NODE(TdlClause, Clausec)
149 // IMPL-NEXT: NODE(TdlClause, Claused)
151 // IMPL-NEXT: #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
153 // IMPL-NEXT: #ifdef GEN_FLANG_CLAUSE_UNPARSE
154 // IMPL-NEXT: #undef GEN_FLANG_CLAUSE_UNPARSE
156 // IMPL-NEXT: void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
157 // IMPL-NEXT: void Unparse(const TdlClause::Clauseb &x) {
158 // IMPL-NEXT: Word("CLAUSEB");
159 // IMPL-NEXT: Put("(");
160 // IMPL-NEXT: Walk(x.v, ",");
161 // IMPL-NEXT: Put(")");
163 // IMPL-NEXT: void Unparse(const TdlClause::Clausec &x) {
164 // IMPL-NEXT: Word("CLAUSEC");
165 // IMPL-NEXT: Put("(");
166 // IMPL-NEXT: if (x.v.has_value())
167 // IMPL-NEXT: Walk(x.v);
169 // IMPL-NEXT: Put("*");
170 // IMPL-NEXT: Put(")");
172 // IMPL-NEXT: void Before(const TdlClause::Claused &) { Word("CLAUSED"); }
174 // IMPL-NEXT: #endif // GEN_FLANG_CLAUSE_UNPARSE
176 // IMPL: #ifdef GEN_CLANG_CLAUSE_CLASS
177 // IMPL-NEXT: #undef GEN_CLANG_CLAUSE_CLASS
179 // IMPL-NEXT: #ifndef CLAUSE
180 // IMPL-NEXT: #define CLAUSE(Enum, Str, Implicit)
182 // IMPL-NEXT: #ifndef CLAUSE_CLASS
183 // IMPL-NEXT: #define CLAUSE_CLASS(Enum, Str, Class)
185 // IMPL-NEXT: #ifndef CLAUSE_NO_CLASS
186 // IMPL-NEXT: #define CLAUSE_NO_CLASS(Enum, Str)
189 // IMPL-NEXT: #define __CLAUSE(Name, Class) \
190 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
191 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, #Name, Class)
192 // IMPL-NEXT: #define __CLAUSE_NO_CLASS(Name) \
193 // IMPL-NEXT: CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
194 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, #Name)
195 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class) \
196 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
197 // IMPL-NEXT: CLAUSE_CLASS(TDLC_##Name, Str, Class)
198 // IMPL-NEXT: #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str) \
199 // IMPL-NEXT: CLAUSE(TDLC_##Name, Str, /* Implicit */ true) \
200 // IMPL-NEXT: CLAUSE_NO_CLASS(TDLC_##Name, Str)
202 // IMPL-NEXT: __IMPLICIT_CLAUSE_NO_CLASS(clausea, "clausea")
203 // IMPL-NEXT: __CLAUSE_NO_CLASS(clauseb)
204 // IMPL-NEXT: __CLAUSE(clausec, ClauseC)
205 // IMPL-NEXT: __IMPLICIT_CLAUSE_CLASS(claused, "claused", ClauseD)
207 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_NO_CLASS
208 // IMPL-NEXT: #undef __IMPLICIT_CLAUSE_CLASS
209 // IMPL-NEXT: #undef __CLAUSE
210 // IMPL-NEXT: #undef CLAUSE_NO_CLASS
211 // IMPL-NEXT: #undef CLAUSE_CLASS
212 // IMPL-NEXT: #undef CLAUSE
214 // IMPL-NEXT: #endif // GEN_CLANG_CLAUSE_CLASS
216 // IMPL: #ifdef GEN_DIRECTIVES_IMPL
217 // IMPL-NEXT: #undef GEN_DIRECTIVES_IMPL
219 // IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
220 // IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
221 // IMPL-NEXT: .Case("dira",TDLD_dira)
222 // IMPL-NEXT: .Default(TDLD_dira);
225 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) {
226 // IMPL-NEXT: switch (Kind) {
227 // IMPL-NEXT: case TDLD_dira:
228 // IMPL-NEXT: return "dira";
230 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
233 // IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) {
234 // IMPL-NEXT: return llvm::StringSwitch<Clause>(Str)
235 // IMPL-NEXT: .Case("clausea",TDLC_clauseb)
236 // IMPL-NEXT: .Case("clauseb",TDLC_clauseb)
237 // IMPL-NEXT: .Case("clausec",TDLC_clausec)
238 // IMPL-NEXT: .Case("claused",TDLC_clauseb)
239 // IMPL-NEXT: .Default(TDLC_clauseb);
242 // IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) {
243 // IMPL-NEXT: switch (Kind) {
244 // IMPL-NEXT: case TDLC_clausea:
245 // IMPL-NEXT: return "clausea";
246 // IMPL-NEXT: case TDLC_clauseb:
247 // IMPL-NEXT: return "clauseb";
248 // IMPL-NEXT: case TDLC_clausec:
249 // IMPL-NEXT: return "clausec";
250 // IMPL-NEXT: case TDLC_claused:
251 // IMPL-NEXT: return "claused";
253 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind");
256 // IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
257 // IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
258 // IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
259 // IMPL-NEXT: switch (D) {
260 // IMPL-NEXT: case TDLD_dira:
261 // IMPL-NEXT: switch (C) {
262 // IMPL-NEXT: case TDLC_clausea:
263 // IMPL-NEXT: return 2 <= Version && 4 >= Version;
264 // IMPL-NEXT: case TDLC_clauseb:
265 // IMPL-NEXT: return 2 <= Version && 2147483647 >= Version;
266 // IMPL-NEXT: default:
267 // IMPL-NEXT: return false;
271 // IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
274 // IMPL-NEXT: #endif // GEN_DIRECTIVES_IMPL