1 //===- TableGen.cpp - Top-Level TableGen implementation for Clang ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the main function for Clang's TableGen.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "TableGenBackends.h" // Declares all backends.
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 GenClangAttrClasses,
27 GenClangAttrParserStringSwitches,
28 GenClangAttrImpl,
29 GenClangAttrList,
30 GenClangAttrPCHRead,
31 GenClangAttrPCHWrite,
32 GenClangAttrHasAttributeImpl,
33 GenClangAttrSpellingListIndex,
34 GenClangAttrASTVisitor,
35 GenClangAttrTemplateInstantiate,
36 GenClangAttrParsedAttrList,
37 GenClangAttrParsedAttrImpl,
38 GenClangAttrParsedAttrKinds,
39 GenClangAttrDump,
40 GenClangDiagsDefs,
41 GenClangDiagGroups,
42 GenClangDiagsIndexName,
43 GenClangCommentNodes,
44 GenClangDeclNodes,
45 GenClangStmtNodes,
46 GenClangSACheckers,
47 GenClangCommentHTMLTags,
48 GenClangCommentHTMLTagsProperties,
49 GenClangCommentHTMLNamedCharacterReferences,
50 GenClangCommentCommandInfo,
51 GenClangCommentCommandList,
52 GenArmNeon,
53 GenArmNeonSema,
54 GenArmNeonTest,
55 GenAttrDocs
56 };
57
58 namespace {
59 cl::opt<ActionType> Action(
60 cl::desc("Action to perform:"),
61 cl::values(
62 clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes",
63 "Generate clang attribute clases"),
64 clEnumValN(GenClangAttrParserStringSwitches,
65 "gen-clang-attr-parser-string-switches",
66 "Generate all parser-related attribute string switches"),
67 clEnumValN(GenClangAttrImpl, "gen-clang-attr-impl",
68 "Generate clang attribute implementations"),
69 clEnumValN(GenClangAttrList, "gen-clang-attr-list",
70 "Generate a clang attribute list"),
71 clEnumValN(GenClangAttrPCHRead, "gen-clang-attr-pch-read",
72 "Generate clang PCH attribute reader"),
73 clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
74 "Generate clang PCH attribute writer"),
75 clEnumValN(GenClangAttrHasAttributeImpl,
76 "gen-clang-attr-has-attribute-impl",
77 "Generate a clang attribute spelling list"),
78 clEnumValN(GenClangAttrSpellingListIndex,
79 "gen-clang-attr-spelling-index",
80 "Generate a clang attribute spelling index"),
81 clEnumValN(GenClangAttrASTVisitor,
82 "gen-clang-attr-ast-visitor",
83 "Generate a recursive AST visitor for clang attributes"),
84 clEnumValN(GenClangAttrTemplateInstantiate,
85 "gen-clang-attr-template-instantiate",
86 "Generate a clang template instantiate code"),
87 clEnumValN(GenClangAttrParsedAttrList,
88 "gen-clang-attr-parsed-attr-list",
89 "Generate a clang parsed attribute list"),
90 clEnumValN(GenClangAttrParsedAttrImpl,
91 "gen-clang-attr-parsed-attr-impl",
92 "Generate the clang parsed attribute helpers"),
93 clEnumValN(GenClangAttrParsedAttrKinds,
94 "gen-clang-attr-parsed-attr-kinds",
95 "Generate a clang parsed attribute kinds"),
96 clEnumValN(GenClangAttrDump, "gen-clang-attr-dump",
97 "Generate clang attribute dumper"),
98 clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
99 "Generate Clang diagnostics definitions"),
100 clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
101 "Generate Clang diagnostic groups"),
102 clEnumValN(GenClangDiagsIndexName, "gen-clang-diags-index-name",
103 "Generate Clang diagnostic name index"),
104 clEnumValN(GenClangCommentNodes, "gen-clang-comment-nodes",
105 "Generate Clang AST comment nodes"),
106 clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
107 "Generate Clang AST declaration nodes"),
108 clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
109 "Generate Clang AST statement nodes"),
110 clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
111 "Generate Clang Static Analyzer checkers"),
112 clEnumValN(GenClangCommentHTMLTags, "gen-clang-comment-html-tags",
113 "Generate efficient matchers for HTML tag "
114 "names that are used in documentation comments"),
115 clEnumValN(GenClangCommentHTMLTagsProperties,
116 "gen-clang-comment-html-tags-properties",
117 "Generate efficient matchers for HTML tag "
118 "properties"),
119 clEnumValN(GenClangCommentHTMLNamedCharacterReferences,
120 "gen-clang-comment-html-named-character-references",
121 "Generate function to translate named character "
122 "references to UTF-8 sequences"),
123 clEnumValN(GenClangCommentCommandInfo, "gen-clang-comment-command-info",
124 "Generate command properties for commands that "
125 "are used in documentation comments"),
126 clEnumValN(GenClangCommentCommandList, "gen-clang-comment-command-list",
127 "Generate list of commands that are used in "
128 "documentation comments"),
129 clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"),
130 clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
131 "Generate ARM NEON sema support for clang"),
132 clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
133 "Generate ARM NEON tests for clang"),
134 clEnumValN(GenAttrDocs, "gen-attr-docs",
135 "Generate attribute documentation"),
136 clEnumValEnd));
137
138 cl::opt<std::string>
139 ClangComponent("clang-component",
140 cl::desc("Only use warnings from specified component"),
141 cl::value_desc("component"), cl::Hidden);
142
ClangTableGenMain(raw_ostream & OS,RecordKeeper & Records)143 bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
144 switch (Action) {
145 case GenClangAttrClasses:
146 EmitClangAttrClass(Records, OS);
147 break;
148 case GenClangAttrParserStringSwitches:
149 EmitClangAttrParserStringSwitches(Records, OS);
150 break;
151 case GenClangAttrImpl:
152 EmitClangAttrImpl(Records, OS);
153 break;
154 case GenClangAttrList:
155 EmitClangAttrList(Records, OS);
156 break;
157 case GenClangAttrPCHRead:
158 EmitClangAttrPCHRead(Records, OS);
159 break;
160 case GenClangAttrPCHWrite:
161 EmitClangAttrPCHWrite(Records, OS);
162 break;
163 case GenClangAttrHasAttributeImpl:
164 EmitClangAttrHasAttrImpl(Records, OS);
165 break;
166 case GenClangAttrSpellingListIndex:
167 EmitClangAttrSpellingListIndex(Records, OS);
168 break;
169 case GenClangAttrASTVisitor:
170 EmitClangAttrASTVisitor(Records, OS);
171 break;
172 case GenClangAttrTemplateInstantiate:
173 EmitClangAttrTemplateInstantiate(Records, OS);
174 break;
175 case GenClangAttrParsedAttrList:
176 EmitClangAttrParsedAttrList(Records, OS);
177 break;
178 case GenClangAttrParsedAttrImpl:
179 EmitClangAttrParsedAttrImpl(Records, OS);
180 break;
181 case GenClangAttrParsedAttrKinds:
182 EmitClangAttrParsedAttrKinds(Records, OS);
183 break;
184 case GenClangAttrDump:
185 EmitClangAttrDump(Records, OS);
186 break;
187 case GenClangDiagsDefs:
188 EmitClangDiagsDefs(Records, OS, ClangComponent);
189 break;
190 case GenClangDiagGroups:
191 EmitClangDiagGroups(Records, OS);
192 break;
193 case GenClangDiagsIndexName:
194 EmitClangDiagsIndexName(Records, OS);
195 break;
196 case GenClangCommentNodes:
197 EmitClangASTNodes(Records, OS, "Comment", "");
198 break;
199 case GenClangDeclNodes:
200 EmitClangASTNodes(Records, OS, "Decl", "Decl");
201 EmitClangDeclContext(Records, OS);
202 break;
203 case GenClangStmtNodes:
204 EmitClangASTNodes(Records, OS, "Stmt", "");
205 break;
206 case GenClangSACheckers:
207 EmitClangSACheckers(Records, OS);
208 break;
209 case GenClangCommentHTMLTags:
210 EmitClangCommentHTMLTags(Records, OS);
211 break;
212 case GenClangCommentHTMLTagsProperties:
213 EmitClangCommentHTMLTagsProperties(Records, OS);
214 break;
215 case GenClangCommentHTMLNamedCharacterReferences:
216 EmitClangCommentHTMLNamedCharacterReferences(Records, OS);
217 break;
218 case GenClangCommentCommandInfo:
219 EmitClangCommentCommandInfo(Records, OS);
220 break;
221 case GenClangCommentCommandList:
222 EmitClangCommentCommandList(Records, OS);
223 break;
224 case GenArmNeon:
225 EmitNeon(Records, OS);
226 break;
227 case GenArmNeonSema:
228 EmitNeonSema(Records, OS);
229 break;
230 case GenArmNeonTest:
231 EmitNeonTest(Records, OS);
232 break;
233 case GenAttrDocs:
234 EmitClangAttrDocs(Records, OS);
235 break;
236 }
237
238 return false;
239 }
240 }
241
main(int argc,char ** argv)242 int main(int argc, char **argv) {
243 sys::PrintStackTraceOnErrorSignal();
244 PrettyStackTraceProgram X(argc, argv);
245 cl::ParseCommandLineOptions(argc, argv);
246
247 return TableGenMain(argv[0], &ClangTableGenMain);
248 }
249
250 #ifdef __has_feature
251 #if __has_feature(address_sanitizer)
252 #include <sanitizer/lsan_interface.h>
253 // Disable LeakSanitizer for this binary as it has too many leaks that are not
254 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h .
__lsan_is_turned_off()255 int __lsan_is_turned_off() { return 1; }
256 #endif // __has_feature(address_sanitizer)
257 #endif // defined(__has_feature)
258