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