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