1 //===- TableGen.cpp - Top-Level TableGen implementation for Clang ---------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains the main function for Clang's TableGen.
11 //===----------------------------------------------------------------------===//
13 #include "TableGenBackends.h" // Declares all backends.
14 #include "ASTTableGen.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/ManagedStatic.h"
17 #include "llvm/Support/PrettyStackTrace.h"
18 #include "llvm/Support/Signals.h"
19 #include "llvm/TableGen/Error.h"
20 #include "llvm/TableGen/Main.h"
21 #include "llvm/TableGen/Record.h"
24 using namespace clang
;
30 GenClangAttrParserStringSwitches
,
31 GenClangAttrSubjectMatchRulesParserStringSwitches
,
34 GenClangAttrCanPrintLeftList
,
35 GenClangAttrMustPrintLeftList
,
37 GenClangAttrSubjectMatchRuleList
,
40 GenClangAttrTokenKinds
,
41 GenClangAttrHasAttributeImpl
,
42 GenClangAttrSpellingListIndex
,
43 GenClangAttrASTVisitor
,
44 GenClangAttrTemplateInstantiate
,
45 GenClangAttrParsedAttrList
,
46 GenClangAttrParsedAttrImpl
,
47 GenClangAttrParsedAttrKinds
,
48 GenClangAttrTextNodeDump
,
49 GenClangAttrNodeTraverse
,
54 GenClangDiagsIndexName
,
63 GenClangSyntaxNodeList
,
64 GenClangSyntaxNodeClasses
,
65 GenClangCommentHTMLTags
,
66 GenClangCommentHTMLTagsProperties
,
67 GenClangCommentHTMLNamedCharacterReferences
,
68 GenClangCommentCommandInfo
,
69 GenClangCommentCommandList
,
70 GenClangOpenCLBuiltins
,
71 GenClangOpenCLBuiltinHeader
,
72 GenClangOpenCLBuiltinTests
,
82 GenArmMveBuiltinAliases
,
96 GenArmCdeBuiltinAliases
,
98 GenRISCVVectorBuiltins
,
99 GenRISCVVectorBuiltinCG
,
100 GenRISCVVectorBuiltinSema
,
101 GenRISCVSiFiveVectorBuiltins
,
102 GenRISCVSiFiveVectorBuiltinCG
,
103 GenRISCVSiFiveVectorBuiltinSema
,
108 GenTestPragmaAttributeSupportedAttributes
112 cl::opt
<ActionType
> Action(
113 cl::desc("Action to perform:"),
115 clEnumValN(PrintRecords
, "print-records",
116 "Print all records to stdout (default)"),
117 clEnumValN(DumpJSON
, "dump-json",
118 "Dump all records as machine-readable JSON"),
119 clEnumValN(GenClangAttrClasses
, "gen-clang-attr-classes",
120 "Generate clang attribute clases"),
121 clEnumValN(GenClangAttrParserStringSwitches
,
122 "gen-clang-attr-parser-string-switches",
123 "Generate all parser-related attribute string switches"),
124 clEnumValN(GenClangAttrSubjectMatchRulesParserStringSwitches
,
125 "gen-clang-attr-subject-match-rules-parser-string-switches",
126 "Generate all parser-related attribute subject match rule"
128 clEnumValN(GenClangAttrImpl
, "gen-clang-attr-impl",
129 "Generate clang attribute implementations"),
130 clEnumValN(GenClangAttrList
, "gen-clang-attr-list",
131 "Generate a clang attribute list"),
132 clEnumValN(GenClangAttrCanPrintLeftList
,
133 "gen-clang-attr-can-print-left-list",
134 "Generate list of attributes that can be printed on left "
136 clEnumValN(GenClangAttrMustPrintLeftList
,
137 "gen-clang-attr-must-print-left-list",
138 "Generate list of attributes that must be printed on left "
140 clEnumValN(GenClangAttrDocTable
, "gen-clang-attr-doc-table",
141 "Generate a table of attribute documentation"),
142 clEnumValN(GenClangAttrSubjectMatchRuleList
,
143 "gen-clang-attr-subject-match-rule-list",
144 "Generate a clang attribute subject match rule list"),
145 clEnumValN(GenClangAttrPCHRead
, "gen-clang-attr-pch-read",
146 "Generate clang PCH attribute reader"),
147 clEnumValN(GenClangAttrPCHWrite
, "gen-clang-attr-pch-write",
148 "Generate clang PCH attribute writer"),
149 clEnumValN(GenClangAttrTokenKinds
, "gen-clang-attr-token-kinds",
150 "Generate a list of attribute-related clang tokens"),
151 clEnumValN(GenClangAttrHasAttributeImpl
,
152 "gen-clang-attr-has-attribute-impl",
153 "Generate a clang attribute spelling list"),
154 clEnumValN(GenClangAttrSpellingListIndex
,
155 "gen-clang-attr-spelling-index",
156 "Generate a clang attribute spelling index"),
157 clEnumValN(GenClangAttrASTVisitor
, "gen-clang-attr-ast-visitor",
158 "Generate a recursive AST visitor for clang attributes"),
159 clEnumValN(GenClangAttrTemplateInstantiate
,
160 "gen-clang-attr-template-instantiate",
161 "Generate a clang template instantiate code"),
162 clEnumValN(GenClangAttrParsedAttrList
,
163 "gen-clang-attr-parsed-attr-list",
164 "Generate a clang parsed attribute list"),
165 clEnumValN(GenClangAttrParsedAttrImpl
,
166 "gen-clang-attr-parsed-attr-impl",
167 "Generate the clang parsed attribute helpers"),
168 clEnumValN(GenClangAttrParsedAttrKinds
,
169 "gen-clang-attr-parsed-attr-kinds",
170 "Generate a clang parsed attribute kinds"),
171 clEnumValN(GenClangAttrTextNodeDump
, "gen-clang-attr-text-node-dump",
172 "Generate clang attribute text node dumper"),
173 clEnumValN(GenClangAttrNodeTraverse
, "gen-clang-attr-node-traverse",
174 "Generate clang attribute traverser"),
175 clEnumValN(GenClangDiagsDefs
, "gen-clang-diags-defs",
176 "Generate Clang diagnostics definitions"),
177 clEnumValN(GenClangDiagGroups
, "gen-clang-diag-groups",
178 "Generate Clang diagnostic groups"),
179 clEnumValN(GenClangDiagsIndexName
, "gen-clang-diags-index-name",
180 "Generate Clang diagnostic name index"),
181 clEnumValN(GenClangBasicReader
, "gen-clang-basic-reader",
182 "Generate Clang BasicReader classes"),
183 clEnumValN(GenClangBasicWriter
, "gen-clang-basic-writer",
184 "Generate Clang BasicWriter classes"),
185 clEnumValN(GenClangCommentNodes
, "gen-clang-comment-nodes",
186 "Generate Clang AST comment nodes"),
187 clEnumValN(GenClangDeclNodes
, "gen-clang-decl-nodes",
188 "Generate Clang AST declaration nodes"),
189 clEnumValN(GenClangStmtNodes
, "gen-clang-stmt-nodes",
190 "Generate Clang AST statement nodes"),
191 clEnumValN(GenClangTypeNodes
, "gen-clang-type-nodes",
192 "Generate Clang AST type nodes"),
193 clEnumValN(GenClangTypeReader
, "gen-clang-type-reader",
194 "Generate Clang AbstractTypeReader class"),
195 clEnumValN(GenClangTypeWriter
, "gen-clang-type-writer",
196 "Generate Clang AbstractTypeWriter class"),
197 clEnumValN(GenClangOpcodes
, "gen-clang-opcodes",
198 "Generate Clang constexpr interpreter opcodes"),
199 clEnumValN(GenClangSACheckers
, "gen-clang-sa-checkers",
200 "Generate Clang Static Analyzer checkers"),
201 clEnumValN(GenClangSyntaxNodeList
, "gen-clang-syntax-node-list",
202 "Generate list of Clang Syntax Tree node types"),
203 clEnumValN(GenClangSyntaxNodeClasses
, "gen-clang-syntax-node-classes",
204 "Generate definitions of Clang Syntax Tree node clasess"),
205 clEnumValN(GenClangCommentHTMLTags
, "gen-clang-comment-html-tags",
206 "Generate efficient matchers for HTML tag "
207 "names that are used in documentation comments"),
208 clEnumValN(GenClangCommentHTMLTagsProperties
,
209 "gen-clang-comment-html-tags-properties",
210 "Generate efficient matchers for HTML tag "
212 clEnumValN(GenClangCommentHTMLNamedCharacterReferences
,
213 "gen-clang-comment-html-named-character-references",
214 "Generate function to translate named character "
215 "references to UTF-8 sequences"),
216 clEnumValN(GenClangCommentCommandInfo
, "gen-clang-comment-command-info",
217 "Generate command properties for commands that "
218 "are used in documentation comments"),
219 clEnumValN(GenClangCommentCommandList
, "gen-clang-comment-command-list",
220 "Generate list of commands that are used in "
221 "documentation comments"),
222 clEnumValN(GenClangOpenCLBuiltins
, "gen-clang-opencl-builtins",
223 "Generate OpenCL builtin declaration handlers"),
224 clEnumValN(GenClangOpenCLBuiltinHeader
,
225 "gen-clang-opencl-builtin-header",
226 "Generate OpenCL builtin header"),
227 clEnumValN(GenClangOpenCLBuiltinTests
, "gen-clang-opencl-builtin-tests",
228 "Generate OpenCL builtin declaration tests"),
229 clEnumValN(GenArmNeon
, "gen-arm-neon", "Generate arm_neon.h for clang"),
230 clEnumValN(GenArmFP16
, "gen-arm-fp16", "Generate arm_fp16.h for clang"),
231 clEnumValN(GenArmBF16
, "gen-arm-bf16", "Generate arm_bf16.h for clang"),
232 clEnumValN(GenArmNeonSema
, "gen-arm-neon-sema",
233 "Generate ARM NEON sema support for clang"),
234 clEnumValN(GenArmNeonTest
, "gen-arm-neon-test",
235 "Generate ARM NEON tests for clang"),
236 clEnumValN(GenArmSveHeader
, "gen-arm-sve-header",
237 "Generate arm_sve.h for clang"),
238 clEnumValN(GenArmSveBuiltins
, "gen-arm-sve-builtins",
239 "Generate arm_sve_builtins.inc for clang"),
240 clEnumValN(GenArmSveBuiltinCG
, "gen-arm-sve-builtin-codegen",
241 "Generate arm_sve_builtin_cg_map.inc for clang"),
242 clEnumValN(GenArmSveTypeFlags
, "gen-arm-sve-typeflags",
243 "Generate arm_sve_typeflags.inc for clang"),
244 clEnumValN(GenArmSveRangeChecks
, "gen-arm-sve-sema-rangechecks",
245 "Generate arm_sve_sema_rangechecks.inc for clang"),
246 clEnumValN(GenArmSmeHeader
, "gen-arm-sme-header",
247 "Generate arm_sme.h for clang"),
248 clEnumValN(GenArmSmeBuiltins
, "gen-arm-sme-builtins",
249 "Generate arm_sme_builtins.inc for clang"),
250 clEnumValN(GenArmSmeBuiltinCG
, "gen-arm-sme-builtin-codegen",
251 "Generate arm_sme_builtin_cg_map.inc for clang"),
252 clEnumValN(GenArmSmeRangeChecks
, "gen-arm-sme-sema-rangechecks",
253 "Generate arm_sme_sema_rangechecks.inc for clang"),
254 clEnumValN(GenArmMveHeader
, "gen-arm-mve-header",
255 "Generate arm_mve.h for clang"),
256 clEnumValN(GenArmMveBuiltinDef
, "gen-arm-mve-builtin-def",
257 "Generate ARM MVE builtin definitions for clang"),
258 clEnumValN(GenArmMveBuiltinSema
, "gen-arm-mve-builtin-sema",
259 "Generate ARM MVE builtin sema checks for clang"),
260 clEnumValN(GenArmMveBuiltinCG
, "gen-arm-mve-builtin-codegen",
261 "Generate ARM MVE builtin code-generator for clang"),
262 clEnumValN(GenArmMveBuiltinAliases
, "gen-arm-mve-builtin-aliases",
263 "Generate list of valid ARM MVE builtin aliases for clang"),
264 clEnumValN(GenArmCdeHeader
, "gen-arm-cde-header",
265 "Generate arm_cde.h for clang"),
266 clEnumValN(GenArmCdeBuiltinDef
, "gen-arm-cde-builtin-def",
267 "Generate ARM CDE builtin definitions for clang"),
268 clEnumValN(GenArmCdeBuiltinSema
, "gen-arm-cde-builtin-sema",
269 "Generate ARM CDE builtin sema checks for clang"),
270 clEnumValN(GenArmCdeBuiltinCG
, "gen-arm-cde-builtin-codegen",
271 "Generate ARM CDE builtin code-generator for clang"),
272 clEnumValN(GenArmCdeBuiltinAliases
, "gen-arm-cde-builtin-aliases",
273 "Generate list of valid ARM CDE builtin aliases for clang"),
274 clEnumValN(GenRISCVVectorHeader
, "gen-riscv-vector-header",
275 "Generate riscv_vector.h for clang"),
276 clEnumValN(GenRISCVVectorBuiltins
, "gen-riscv-vector-builtins",
277 "Generate riscv_vector_builtins.inc for clang"),
278 clEnumValN(GenRISCVVectorBuiltinCG
, "gen-riscv-vector-builtin-codegen",
279 "Generate riscv_vector_builtin_cg.inc for clang"),
280 clEnumValN(GenRISCVVectorBuiltinSema
, "gen-riscv-vector-builtin-sema",
281 "Generate riscv_vector_builtin_sema.inc for clang"),
282 clEnumValN(GenRISCVSiFiveVectorBuiltins
, "gen-riscv-sifive-vector-builtins",
283 "Generate riscv_sifive_vector_builtins.inc for clang"),
284 clEnumValN(GenRISCVSiFiveVectorBuiltinCG
, "gen-riscv-sifive-vector-builtin-codegen",
285 "Generate riscv_sifive_vector_builtin_cg.inc for clang"),
286 clEnumValN(GenRISCVSiFiveVectorBuiltinSema
, "gen-riscv-sifive-vector-builtin-sema",
287 "Generate riscv_sifive_vector_builtin_sema.inc for clang"),
288 clEnumValN(GenAttrDocs
, "gen-attr-docs",
289 "Generate attribute documentation"),
290 clEnumValN(GenDiagDocs
, "gen-diag-docs",
291 "Generate diagnostic documentation"),
292 clEnumValN(GenOptDocs
, "gen-opt-docs", "Generate option documentation"),
293 clEnumValN(GenDataCollectors
, "gen-clang-data-collectors",
294 "Generate data collectors for AST nodes"),
295 clEnumValN(GenTestPragmaAttributeSupportedAttributes
,
296 "gen-clang-test-pragma-attribute-supported-attributes",
297 "Generate a list of attributes supported by #pragma clang "
298 "attribute for testing purposes")));
301 ClangComponent("clang-component",
302 cl::desc("Only use warnings from specified component"),
303 cl::value_desc("component"), cl::Hidden
);
305 bool ClangTableGenMain(raw_ostream
&OS
, RecordKeeper
&Records
) {
308 OS
<< Records
; // No argument, dump all contents
311 EmitJSON(Records
, OS
);
313 case GenClangAttrClasses
:
314 EmitClangAttrClass(Records
, OS
);
316 case GenClangAttrParserStringSwitches
:
317 EmitClangAttrParserStringSwitches(Records
, OS
);
319 case GenClangAttrSubjectMatchRulesParserStringSwitches
:
320 EmitClangAttrSubjectMatchRulesParserStringSwitches(Records
, OS
);
322 case GenClangAttrImpl
:
323 EmitClangAttrImpl(Records
, OS
);
325 case GenClangAttrList
:
326 EmitClangAttrList(Records
, OS
);
328 case GenClangAttrCanPrintLeftList
:
329 EmitClangAttrPrintList("CanPrintOnLeft", Records
, OS
);
331 case GenClangAttrMustPrintLeftList
:
332 EmitClangAttrPrintList("PrintOnLeft", Records
, OS
);
334 case GenClangAttrDocTable
:
335 EmitClangAttrDocTable(Records
, OS
);
337 case GenClangAttrSubjectMatchRuleList
:
338 EmitClangAttrSubjectMatchRuleList(Records
, OS
);
340 case GenClangAttrPCHRead
:
341 EmitClangAttrPCHRead(Records
, OS
);
343 case GenClangAttrPCHWrite
:
344 EmitClangAttrPCHWrite(Records
, OS
);
346 case GenClangAttrTokenKinds
:
347 EmitClangAttrTokenKinds(Records
, OS
);
349 case GenClangAttrHasAttributeImpl
:
350 EmitClangAttrHasAttrImpl(Records
, OS
);
352 case GenClangAttrSpellingListIndex
:
353 EmitClangAttrSpellingListIndex(Records
, OS
);
355 case GenClangAttrASTVisitor
:
356 EmitClangAttrASTVisitor(Records
, OS
);
358 case GenClangAttrTemplateInstantiate
:
359 EmitClangAttrTemplateInstantiate(Records
, OS
);
361 case GenClangAttrParsedAttrList
:
362 EmitClangAttrParsedAttrList(Records
, OS
);
364 case GenClangAttrParsedAttrImpl
:
365 EmitClangAttrParsedAttrImpl(Records
, OS
);
367 case GenClangAttrParsedAttrKinds
:
368 EmitClangAttrParsedAttrKinds(Records
, OS
);
370 case GenClangAttrTextNodeDump
:
371 EmitClangAttrTextNodeDump(Records
, OS
);
373 case GenClangAttrNodeTraverse
:
374 EmitClangAttrNodeTraverse(Records
, OS
);
376 case GenClangDiagsDefs
:
377 EmitClangDiagsDefs(Records
, OS
, ClangComponent
);
379 case GenClangDiagGroups
:
380 EmitClangDiagGroups(Records
, OS
);
382 case GenClangDiagsIndexName
:
383 EmitClangDiagsIndexName(Records
, OS
);
385 case GenClangCommentNodes
:
386 EmitClangASTNodes(Records
, OS
, CommentNodeClassName
, "");
388 case GenClangDeclNodes
:
389 EmitClangASTNodes(Records
, OS
, DeclNodeClassName
, "Decl");
390 EmitClangDeclContext(Records
, OS
);
392 case GenClangStmtNodes
:
393 EmitClangASTNodes(Records
, OS
, StmtNodeClassName
, "");
395 case GenClangTypeNodes
:
396 EmitClangTypeNodes(Records
, OS
);
398 case GenClangTypeReader
:
399 EmitClangTypeReader(Records
, OS
);
401 case GenClangTypeWriter
:
402 EmitClangTypeWriter(Records
, OS
);
404 case GenClangBasicReader
:
405 EmitClangBasicReader(Records
, OS
);
407 case GenClangBasicWriter
:
408 EmitClangBasicWriter(Records
, OS
);
410 case GenClangOpcodes
:
411 EmitClangOpcodes(Records
, OS
);
413 case GenClangSACheckers
:
414 EmitClangSACheckers(Records
, OS
);
416 case GenClangCommentHTMLTags
:
417 EmitClangCommentHTMLTags(Records
, OS
);
419 case GenClangCommentHTMLTagsProperties
:
420 EmitClangCommentHTMLTagsProperties(Records
, OS
);
422 case GenClangCommentHTMLNamedCharacterReferences
:
423 EmitClangCommentHTMLNamedCharacterReferences(Records
, OS
);
425 case GenClangCommentCommandInfo
:
426 EmitClangCommentCommandInfo(Records
, OS
);
428 case GenClangCommentCommandList
:
429 EmitClangCommentCommandList(Records
, OS
);
431 case GenClangOpenCLBuiltins
:
432 EmitClangOpenCLBuiltins(Records
, OS
);
434 case GenClangOpenCLBuiltinHeader
:
435 EmitClangOpenCLBuiltinHeader(Records
, OS
);
437 case GenClangOpenCLBuiltinTests
:
438 EmitClangOpenCLBuiltinTests(Records
, OS
);
440 case GenClangSyntaxNodeList
:
441 EmitClangSyntaxNodeList(Records
, OS
);
443 case GenClangSyntaxNodeClasses
:
444 EmitClangSyntaxNodeClasses(Records
, OS
);
447 EmitNeon(Records
, OS
);
450 EmitFP16(Records
, OS
);
453 EmitBF16(Records
, OS
);
456 EmitNeonSema(Records
, OS
);
459 EmitNeonTest(Records
, OS
);
461 case GenArmMveHeader
:
462 EmitMveHeader(Records
, OS
);
464 case GenArmMveBuiltinDef
:
465 EmitMveBuiltinDef(Records
, OS
);
467 case GenArmMveBuiltinSema
:
468 EmitMveBuiltinSema(Records
, OS
);
470 case GenArmMveBuiltinCG
:
471 EmitMveBuiltinCG(Records
, OS
);
473 case GenArmMveBuiltinAliases
:
474 EmitMveBuiltinAliases(Records
, OS
);
476 case GenArmSveHeader
:
477 EmitSveHeader(Records
, OS
);
479 case GenArmSveBuiltins
:
480 EmitSveBuiltins(Records
, OS
);
482 case GenArmSveBuiltinCG
:
483 EmitSveBuiltinCG(Records
, OS
);
485 case GenArmSveTypeFlags
:
486 EmitSveTypeFlags(Records
, OS
);
488 case GenArmSveRangeChecks
:
489 EmitSveRangeChecks(Records
, OS
);
491 case GenArmSmeHeader
:
492 EmitSmeHeader(Records
, OS
);
494 case GenArmSmeBuiltins
:
495 EmitSmeBuiltins(Records
, OS
);
497 case GenArmSmeBuiltinCG
:
498 EmitSmeBuiltinCG(Records
, OS
);
500 case GenArmSmeRangeChecks
:
501 EmitSmeRangeChecks(Records
, OS
);
503 case GenArmCdeHeader
:
504 EmitCdeHeader(Records
, OS
);
506 case GenArmCdeBuiltinDef
:
507 EmitCdeBuiltinDef(Records
, OS
);
509 case GenArmCdeBuiltinSema
:
510 EmitCdeBuiltinSema(Records
, OS
);
512 case GenArmCdeBuiltinCG
:
513 EmitCdeBuiltinCG(Records
, OS
);
515 case GenArmCdeBuiltinAliases
:
516 EmitCdeBuiltinAliases(Records
, OS
);
518 case GenRISCVVectorHeader
:
519 EmitRVVHeader(Records
, OS
);
521 case GenRISCVVectorBuiltins
:
522 EmitRVVBuiltins(Records
, OS
);
524 case GenRISCVVectorBuiltinCG
:
525 EmitRVVBuiltinCG(Records
, OS
);
527 case GenRISCVVectorBuiltinSema
:
528 EmitRVVBuiltinSema(Records
, OS
);
530 case GenRISCVSiFiveVectorBuiltins
:
531 EmitRVVBuiltins(Records
, OS
);
533 case GenRISCVSiFiveVectorBuiltinCG
:
534 EmitRVVBuiltinCG(Records
, OS
);
536 case GenRISCVSiFiveVectorBuiltinSema
:
537 EmitRVVBuiltinSema(Records
, OS
);
540 EmitClangAttrDocs(Records
, OS
);
543 EmitClangDiagDocs(Records
, OS
);
546 EmitClangOptDocs(Records
, OS
);
548 case GenDataCollectors
:
549 EmitClangDataCollectors(Records
, OS
);
551 case GenTestPragmaAttributeSupportedAttributes
:
552 EmitTestPragmaAttributeSupportedAttributes(Records
, OS
);
560 int main(int argc
, char **argv
) {
561 sys::PrintStackTraceOnErrorSignal(argv
[0]);
562 PrettyStackTraceProgram
X(argc
, argv
);
563 cl::ParseCommandLineOptions(argc
, argv
);
567 return TableGenMain(argv
[0], &ClangTableGenMain
);
571 #if __has_feature(address_sanitizer)
572 #include <sanitizer/lsan_interface.h>
573 // Disable LeakSanitizer for this binary as it has too many leaks that are not
574 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
575 int __lsan_is_turned_off() { return 1; }
576 #endif // __has_feature(address_sanitizer)
577 #endif // defined(__has_feature)