xref: /freebsd/contrib/llvm-project/clang/utils/TableGen/TableGen.cpp (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1 //===- TableGen.cpp - Top-Level TableGen implementation for Clang ---------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the main function for Clang's TableGen.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "TableGenBackends.h" // Declares all backends.
14 #include "ASTTableGen.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/PrettyStackTrace.h"
17 #include "llvm/Support/Signals.h"
18 #include "llvm/TableGen/Error.h"
19 #include "llvm/TableGen/Main.h"
20 #include "llvm/TableGen/Record.h"
21 
22 using namespace llvm;
23 using namespace clang;
24 
25 enum ActionType {
26   PrintRecords,
27   DumpJSON,
28   GenClangAttrClasses,
29   GenClangAttrParserStringSwitches,
30   GenClangAttrSubjectMatchRulesParserStringSwitches,
31   GenClangAttrImpl,
32   GenClangAttrList,
33   GenClangAttrDocTable,
34   GenClangAttrSubjectMatchRuleList,
35   GenClangAttrPCHRead,
36   GenClangAttrPCHWrite,
37   GenClangAttrHasAttributeImpl,
38   GenClangAttrSpellingListIndex,
39   GenClangAttrASTVisitor,
40   GenClangAttrTemplateInstantiate,
41   GenClangAttrParsedAttrList,
42   GenClangAttrParsedAttrImpl,
43   GenClangAttrParsedAttrKinds,
44   GenClangAttrTextNodeDump,
45   GenClangAttrNodeTraverse,
46   GenClangBasicReader,
47   GenClangBasicWriter,
48   GenClangDiagsDefs,
49   GenClangDiagGroups,
50   GenClangDiagsIndexName,
51   GenClangCommentNodes,
52   GenClangDeclNodes,
53   GenClangStmtNodes,
54   GenClangTypeNodes,
55   GenClangTypeReader,
56   GenClangTypeWriter,
57   GenClangOpcodes,
58   GenClangSACheckers,
59   GenClangSyntaxNodeList,
60   GenClangSyntaxNodeClasses,
61   GenClangCommentHTMLTags,
62   GenClangCommentHTMLTagsProperties,
63   GenClangCommentHTMLNamedCharacterReferences,
64   GenClangCommentCommandInfo,
65   GenClangCommentCommandList,
66   GenClangOpenCLBuiltins,
67   GenClangOpenCLBuiltinTests,
68   GenArmNeon,
69   GenArmFP16,
70   GenArmBF16,
71   GenArmNeonSema,
72   GenArmNeonTest,
73   GenArmMveHeader,
74   GenArmMveBuiltinDef,
75   GenArmMveBuiltinSema,
76   GenArmMveBuiltinCG,
77   GenArmMveBuiltinAliases,
78   GenArmSveHeader,
79   GenArmSveBuiltins,
80   GenArmSveBuiltinCG,
81   GenArmSveTypeFlags,
82   GenArmSveRangeChecks,
83   GenArmCdeHeader,
84   GenArmCdeBuiltinDef,
85   GenArmCdeBuiltinSema,
86   GenArmCdeBuiltinCG,
87   GenArmCdeBuiltinAliases,
88   GenRISCVVectorHeader,
89   GenRISCVVectorBuiltins,
90   GenRISCVVectorBuiltinCG,
91   GenRISCVVectorBuiltinSema,
92   GenAttrDocs,
93   GenDiagDocs,
94   GenOptDocs,
95   GenDataCollectors,
96   GenTestPragmaAttributeSupportedAttributes
97 };
98 
99 namespace {
100 cl::opt<ActionType> Action(
101     cl::desc("Action to perform:"),
102     cl::values(
103         clEnumValN(PrintRecords, "print-records",
104                    "Print all records to stdout (default)"),
105         clEnumValN(DumpJSON, "dump-json",
106                    "Dump all records as machine-readable JSON"),
107         clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes",
108                    "Generate clang attribute clases"),
109         clEnumValN(GenClangAttrParserStringSwitches,
110                    "gen-clang-attr-parser-string-switches",
111                    "Generate all parser-related attribute string switches"),
112         clEnumValN(GenClangAttrSubjectMatchRulesParserStringSwitches,
113                    "gen-clang-attr-subject-match-rules-parser-string-switches",
114                    "Generate all parser-related attribute subject match rule"
115                    "string switches"),
116         clEnumValN(GenClangAttrImpl, "gen-clang-attr-impl",
117                    "Generate clang attribute implementations"),
118         clEnumValN(GenClangAttrList, "gen-clang-attr-list",
119                    "Generate a clang attribute list"),
120         clEnumValN(GenClangAttrDocTable, "gen-clang-attr-doc-table",
121                    "Generate a table of attribute documentation"),
122         clEnumValN(GenClangAttrSubjectMatchRuleList,
123                    "gen-clang-attr-subject-match-rule-list",
124                    "Generate a clang attribute subject match rule list"),
125         clEnumValN(GenClangAttrPCHRead, "gen-clang-attr-pch-read",
126                    "Generate clang PCH attribute reader"),
127         clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
128                    "Generate clang PCH attribute writer"),
129         clEnumValN(GenClangAttrHasAttributeImpl,
130                    "gen-clang-attr-has-attribute-impl",
131                    "Generate a clang attribute spelling list"),
132         clEnumValN(GenClangAttrSpellingListIndex,
133                    "gen-clang-attr-spelling-index",
134                    "Generate a clang attribute spelling index"),
135         clEnumValN(GenClangAttrASTVisitor, "gen-clang-attr-ast-visitor",
136                    "Generate a recursive AST visitor for clang attributes"),
137         clEnumValN(GenClangAttrTemplateInstantiate,
138                    "gen-clang-attr-template-instantiate",
139                    "Generate a clang template instantiate code"),
140         clEnumValN(GenClangAttrParsedAttrList,
141                    "gen-clang-attr-parsed-attr-list",
142                    "Generate a clang parsed attribute list"),
143         clEnumValN(GenClangAttrParsedAttrImpl,
144                    "gen-clang-attr-parsed-attr-impl",
145                    "Generate the clang parsed attribute helpers"),
146         clEnumValN(GenClangAttrParsedAttrKinds,
147                    "gen-clang-attr-parsed-attr-kinds",
148                    "Generate a clang parsed attribute kinds"),
149         clEnumValN(GenClangAttrTextNodeDump, "gen-clang-attr-text-node-dump",
150                    "Generate clang attribute text node dumper"),
151         clEnumValN(GenClangAttrNodeTraverse, "gen-clang-attr-node-traverse",
152                    "Generate clang attribute traverser"),
153         clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
154                    "Generate Clang diagnostics definitions"),
155         clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
156                    "Generate Clang diagnostic groups"),
157         clEnumValN(GenClangDiagsIndexName, "gen-clang-diags-index-name",
158                    "Generate Clang diagnostic name index"),
159         clEnumValN(GenClangBasicReader, "gen-clang-basic-reader",
160                    "Generate Clang BasicReader classes"),
161         clEnumValN(GenClangBasicWriter, "gen-clang-basic-writer",
162                    "Generate Clang BasicWriter classes"),
163         clEnumValN(GenClangCommentNodes, "gen-clang-comment-nodes",
164                    "Generate Clang AST comment nodes"),
165         clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
166                    "Generate Clang AST declaration nodes"),
167         clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
168                    "Generate Clang AST statement nodes"),
169         clEnumValN(GenClangTypeNodes, "gen-clang-type-nodes",
170                    "Generate Clang AST type nodes"),
171         clEnumValN(GenClangTypeReader, "gen-clang-type-reader",
172                    "Generate Clang AbstractTypeReader class"),
173         clEnumValN(GenClangTypeWriter, "gen-clang-type-writer",
174                    "Generate Clang AbstractTypeWriter class"),
175         clEnumValN(GenClangOpcodes, "gen-clang-opcodes",
176                    "Generate Clang constexpr interpreter opcodes"),
177         clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
178                    "Generate Clang Static Analyzer checkers"),
179         clEnumValN(GenClangSyntaxNodeList, "gen-clang-syntax-node-list",
180                    "Generate list of Clang Syntax Tree node types"),
181         clEnumValN(GenClangSyntaxNodeClasses, "gen-clang-syntax-node-classes",
182                    "Generate definitions of Clang Syntax Tree node clasess"),
183         clEnumValN(GenClangCommentHTMLTags, "gen-clang-comment-html-tags",
184                    "Generate efficient matchers for HTML tag "
185                    "names that are used in documentation comments"),
186         clEnumValN(GenClangCommentHTMLTagsProperties,
187                    "gen-clang-comment-html-tags-properties",
188                    "Generate efficient matchers for HTML tag "
189                    "properties"),
190         clEnumValN(GenClangCommentHTMLNamedCharacterReferences,
191                    "gen-clang-comment-html-named-character-references",
192                    "Generate function to translate named character "
193                    "references to UTF-8 sequences"),
194         clEnumValN(GenClangCommentCommandInfo, "gen-clang-comment-command-info",
195                    "Generate command properties for commands that "
196                    "are used in documentation comments"),
197         clEnumValN(GenClangCommentCommandList, "gen-clang-comment-command-list",
198                    "Generate list of commands that are used in "
199                    "documentation comments"),
200         clEnumValN(GenClangOpenCLBuiltins, "gen-clang-opencl-builtins",
201                    "Generate OpenCL builtin declaration handlers"),
202         clEnumValN(GenClangOpenCLBuiltinTests, "gen-clang-opencl-builtin-tests",
203                    "Generate OpenCL builtin declaration tests"),
204         clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"),
205         clEnumValN(GenArmFP16, "gen-arm-fp16", "Generate arm_fp16.h for clang"),
206         clEnumValN(GenArmBF16, "gen-arm-bf16", "Generate arm_bf16.h for clang"),
207         clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
208                    "Generate ARM NEON sema support for clang"),
209         clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
210                    "Generate ARM NEON tests for clang"),
211         clEnumValN(GenArmSveHeader, "gen-arm-sve-header",
212                    "Generate arm_sve.h for clang"),
213         clEnumValN(GenArmSveBuiltins, "gen-arm-sve-builtins",
214                    "Generate arm_sve_builtins.inc for clang"),
215         clEnumValN(GenArmSveBuiltinCG, "gen-arm-sve-builtin-codegen",
216                    "Generate arm_sve_builtin_cg_map.inc for clang"),
217         clEnumValN(GenArmSveTypeFlags, "gen-arm-sve-typeflags",
218                    "Generate arm_sve_typeflags.inc for clang"),
219         clEnumValN(GenArmSveRangeChecks, "gen-arm-sve-sema-rangechecks",
220                    "Generate arm_sve_sema_rangechecks.inc for clang"),
221         clEnumValN(GenArmMveHeader, "gen-arm-mve-header",
222                    "Generate arm_mve.h for clang"),
223         clEnumValN(GenArmMveBuiltinDef, "gen-arm-mve-builtin-def",
224                    "Generate ARM MVE builtin definitions for clang"),
225         clEnumValN(GenArmMveBuiltinSema, "gen-arm-mve-builtin-sema",
226                    "Generate ARM MVE builtin sema checks for clang"),
227         clEnumValN(GenArmMveBuiltinCG, "gen-arm-mve-builtin-codegen",
228                    "Generate ARM MVE builtin code-generator for clang"),
229         clEnumValN(GenArmMveBuiltinAliases, "gen-arm-mve-builtin-aliases",
230                    "Generate list of valid ARM MVE builtin aliases for clang"),
231         clEnumValN(GenArmCdeHeader, "gen-arm-cde-header",
232                    "Generate arm_cde.h for clang"),
233         clEnumValN(GenArmCdeBuiltinDef, "gen-arm-cde-builtin-def",
234                    "Generate ARM CDE builtin definitions for clang"),
235         clEnumValN(GenArmCdeBuiltinSema, "gen-arm-cde-builtin-sema",
236                    "Generate ARM CDE builtin sema checks for clang"),
237         clEnumValN(GenArmCdeBuiltinCG, "gen-arm-cde-builtin-codegen",
238                    "Generate ARM CDE builtin code-generator for clang"),
239         clEnumValN(GenArmCdeBuiltinAliases, "gen-arm-cde-builtin-aliases",
240                    "Generate list of valid ARM CDE builtin aliases for clang"),
241         clEnumValN(GenRISCVVectorHeader, "gen-riscv-vector-header",
242                    "Generate riscv_vector.h for clang"),
243         clEnumValN(GenRISCVVectorBuiltins, "gen-riscv-vector-builtins",
244                    "Generate riscv_vector_builtins.inc for clang"),
245         clEnumValN(GenRISCVVectorBuiltinCG, "gen-riscv-vector-builtin-codegen",
246                    "Generate riscv_vector_builtin_cg.inc for clang"),
247         clEnumValN(GenRISCVVectorBuiltinSema, "gen-riscv-vector-builtin-sema",
248                    "Generate riscv_vector_builtin_sema.inc for clang"),
249         clEnumValN(GenAttrDocs, "gen-attr-docs",
250                    "Generate attribute documentation"),
251         clEnumValN(GenDiagDocs, "gen-diag-docs",
252                    "Generate diagnostic documentation"),
253         clEnumValN(GenOptDocs, "gen-opt-docs", "Generate option documentation"),
254         clEnumValN(GenDataCollectors, "gen-clang-data-collectors",
255                    "Generate data collectors for AST nodes"),
256         clEnumValN(GenTestPragmaAttributeSupportedAttributes,
257                    "gen-clang-test-pragma-attribute-supported-attributes",
258                    "Generate a list of attributes supported by #pragma clang "
259                    "attribute for testing purposes")));
260 
261 cl::opt<std::string>
262 ClangComponent("clang-component",
263                cl::desc("Only use warnings from specified component"),
264                cl::value_desc("component"), cl::Hidden);
265 
266 bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
267   switch (Action) {
268   case PrintRecords:
269     OS << Records;           // No argument, dump all contents
270     break;
271   case DumpJSON:
272     EmitJSON(Records, OS);
273     break;
274   case GenClangAttrClasses:
275     EmitClangAttrClass(Records, OS);
276     break;
277   case GenClangAttrParserStringSwitches:
278     EmitClangAttrParserStringSwitches(Records, OS);
279     break;
280   case GenClangAttrSubjectMatchRulesParserStringSwitches:
281     EmitClangAttrSubjectMatchRulesParserStringSwitches(Records, OS);
282     break;
283   case GenClangAttrImpl:
284     EmitClangAttrImpl(Records, OS);
285     break;
286   case GenClangAttrList:
287     EmitClangAttrList(Records, OS);
288     break;
289   case GenClangAttrDocTable:
290     EmitClangAttrDocTable(Records, OS);
291     break;
292   case GenClangAttrSubjectMatchRuleList:
293     EmitClangAttrSubjectMatchRuleList(Records, OS);
294     break;
295   case GenClangAttrPCHRead:
296     EmitClangAttrPCHRead(Records, OS);
297     break;
298   case GenClangAttrPCHWrite:
299     EmitClangAttrPCHWrite(Records, OS);
300     break;
301   case GenClangAttrHasAttributeImpl:
302     EmitClangAttrHasAttrImpl(Records, OS);
303     break;
304   case GenClangAttrSpellingListIndex:
305     EmitClangAttrSpellingListIndex(Records, OS);
306     break;
307   case GenClangAttrASTVisitor:
308     EmitClangAttrASTVisitor(Records, OS);
309     break;
310   case GenClangAttrTemplateInstantiate:
311     EmitClangAttrTemplateInstantiate(Records, OS);
312     break;
313   case GenClangAttrParsedAttrList:
314     EmitClangAttrParsedAttrList(Records, OS);
315     break;
316   case GenClangAttrParsedAttrImpl:
317     EmitClangAttrParsedAttrImpl(Records, OS);
318     break;
319   case GenClangAttrParsedAttrKinds:
320     EmitClangAttrParsedAttrKinds(Records, OS);
321     break;
322   case GenClangAttrTextNodeDump:
323     EmitClangAttrTextNodeDump(Records, OS);
324     break;
325   case GenClangAttrNodeTraverse:
326     EmitClangAttrNodeTraverse(Records, OS);
327     break;
328   case GenClangDiagsDefs:
329     EmitClangDiagsDefs(Records, OS, ClangComponent);
330     break;
331   case GenClangDiagGroups:
332     EmitClangDiagGroups(Records, OS);
333     break;
334   case GenClangDiagsIndexName:
335     EmitClangDiagsIndexName(Records, OS);
336     break;
337   case GenClangCommentNodes:
338     EmitClangASTNodes(Records, OS, CommentNodeClassName, "");
339     break;
340   case GenClangDeclNodes:
341     EmitClangASTNodes(Records, OS, DeclNodeClassName, "Decl");
342     EmitClangDeclContext(Records, OS);
343     break;
344   case GenClangStmtNodes:
345     EmitClangASTNodes(Records, OS, StmtNodeClassName, "");
346     break;
347   case GenClangTypeNodes:
348     EmitClangTypeNodes(Records, OS);
349     break;
350   case GenClangTypeReader:
351     EmitClangTypeReader(Records, OS);
352     break;
353   case GenClangTypeWriter:
354     EmitClangTypeWriter(Records, OS);
355     break;
356   case GenClangBasicReader:
357     EmitClangBasicReader(Records, OS);
358     break;
359   case GenClangBasicWriter:
360     EmitClangBasicWriter(Records, OS);
361     break;
362   case GenClangOpcodes:
363     EmitClangOpcodes(Records, OS);
364     break;
365   case GenClangSACheckers:
366     EmitClangSACheckers(Records, OS);
367     break;
368   case GenClangCommentHTMLTags:
369     EmitClangCommentHTMLTags(Records, OS);
370     break;
371   case GenClangCommentHTMLTagsProperties:
372     EmitClangCommentHTMLTagsProperties(Records, OS);
373     break;
374   case GenClangCommentHTMLNamedCharacterReferences:
375     EmitClangCommentHTMLNamedCharacterReferences(Records, OS);
376     break;
377   case GenClangCommentCommandInfo:
378     EmitClangCommentCommandInfo(Records, OS);
379     break;
380   case GenClangCommentCommandList:
381     EmitClangCommentCommandList(Records, OS);
382     break;
383   case GenClangOpenCLBuiltins:
384     EmitClangOpenCLBuiltins(Records, OS);
385     break;
386   case GenClangOpenCLBuiltinTests:
387     EmitClangOpenCLBuiltinTests(Records, OS);
388     break;
389   case GenClangSyntaxNodeList:
390     EmitClangSyntaxNodeList(Records, OS);
391     break;
392   case GenClangSyntaxNodeClasses:
393     EmitClangSyntaxNodeClasses(Records, OS);
394     break;
395   case GenArmNeon:
396     EmitNeon(Records, OS);
397     break;
398   case GenArmFP16:
399     EmitFP16(Records, OS);
400     break;
401   case GenArmBF16:
402     EmitBF16(Records, OS);
403     break;
404   case GenArmNeonSema:
405     EmitNeonSema(Records, OS);
406     break;
407   case GenArmNeonTest:
408     EmitNeonTest(Records, OS);
409     break;
410   case GenArmMveHeader:
411     EmitMveHeader(Records, OS);
412     break;
413   case GenArmMveBuiltinDef:
414     EmitMveBuiltinDef(Records, OS);
415     break;
416   case GenArmMveBuiltinSema:
417     EmitMveBuiltinSema(Records, OS);
418     break;
419   case GenArmMveBuiltinCG:
420     EmitMveBuiltinCG(Records, OS);
421     break;
422   case GenArmMveBuiltinAliases:
423     EmitMveBuiltinAliases(Records, OS);
424     break;
425   case GenArmSveHeader:
426     EmitSveHeader(Records, OS);
427     break;
428   case GenArmSveBuiltins:
429     EmitSveBuiltins(Records, OS);
430     break;
431   case GenArmSveBuiltinCG:
432     EmitSveBuiltinCG(Records, OS);
433     break;
434   case GenArmSveTypeFlags:
435     EmitSveTypeFlags(Records, OS);
436     break;
437   case GenArmSveRangeChecks:
438     EmitSveRangeChecks(Records, OS);
439     break;
440   case GenArmCdeHeader:
441     EmitCdeHeader(Records, OS);
442     break;
443   case GenArmCdeBuiltinDef:
444     EmitCdeBuiltinDef(Records, OS);
445     break;
446   case GenArmCdeBuiltinSema:
447     EmitCdeBuiltinSema(Records, OS);
448     break;
449   case GenArmCdeBuiltinCG:
450     EmitCdeBuiltinCG(Records, OS);
451     break;
452   case GenArmCdeBuiltinAliases:
453     EmitCdeBuiltinAliases(Records, OS);
454     break;
455   case GenRISCVVectorHeader:
456     EmitRVVHeader(Records, OS);
457     break;
458   case GenRISCVVectorBuiltins:
459     EmitRVVBuiltins(Records, OS);
460     break;
461   case GenRISCVVectorBuiltinCG:
462     EmitRVVBuiltinCG(Records, OS);
463     break;
464   case GenRISCVVectorBuiltinSema:
465     EmitRVVBuiltinSema(Records, OS);
466     break;
467   case GenAttrDocs:
468     EmitClangAttrDocs(Records, OS);
469     break;
470   case GenDiagDocs:
471     EmitClangDiagDocs(Records, OS);
472     break;
473   case GenOptDocs:
474     EmitClangOptDocs(Records, OS);
475     break;
476   case GenDataCollectors:
477     EmitClangDataCollectors(Records, OS);
478     break;
479   case GenTestPragmaAttributeSupportedAttributes:
480     EmitTestPragmaAttributeSupportedAttributes(Records, OS);
481     break;
482   }
483 
484   return false;
485 }
486 }
487 
488 int main(int argc, char **argv) {
489   sys::PrintStackTraceOnErrorSignal(argv[0]);
490   PrettyStackTraceProgram X(argc, argv);
491   cl::ParseCommandLineOptions(argc, argv);
492 
493   llvm_shutdown_obj Y;
494 
495   return TableGenMain(argv[0], &ClangTableGenMain);
496 }
497 
498 #ifdef __has_feature
499 #if __has_feature(address_sanitizer)
500 #include <sanitizer/lsan_interface.h>
501 // Disable LeakSanitizer for this binary as it has too many leaks that are not
502 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
503 int __lsan_is_turned_off() { return 1; }
504 #endif  // __has_feature(address_sanitizer)
505 #endif  // defined(__has_feature)
506