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