TableGen.cpp revision 3796d1539a39b999fd50bed7aea726ef6f845e17
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
22using namespace llvm;
23using namespace clang;
24
25enum ActionType {
26  GenClangAttrClasses,
27  GenClangAttrExprArgsList,
28  GenClangAttrImpl,
29  GenClangAttrList,
30  GenClangAttrPCHRead,
31  GenClangAttrPCHWrite,
32  GenClangAttrSpellingList,
33  GenClangAttrSpellingListIndex,
34  GenClangAttrLateParsedList,
35  GenClangAttrTemplateInstantiate,
36  GenClangAttrParsedAttrList,
37  GenClangAttrParsedAttrKinds,
38  GenClangAttrDump,
39  GenClangDiagsDefs,
40  GenClangDiagGroups,
41  GenClangDiagsIndexName,
42  GenClangCommentNodes,
43  GenClangDeclNodes,
44  GenClangStmtNodes,
45  GenClangSACheckers,
46  GenClangCommentHTMLTags,
47  GenClangCommentHTMLTagsProperties,
48  GenClangCommentHTMLNamedCharacterReferences,
49  GenClangCommentCommandInfo,
50  GenClangCommentCommandList,
51  GenOptParserDefs, GenOptParserImpl,
52  GenArmNeon,
53  GenArmNeonSema,
54  GenArmNeonTest
55};
56
57namespace {
58  cl::opt<ActionType>
59  Action(cl::desc("Action to perform:"),
60         cl::values(clEnumValN(GenOptParserDefs, "gen-opt-parser-defs",
61                               "Generate option definitions"),
62                    clEnumValN(GenOptParserImpl, "gen-opt-parser-impl",
63                               "Generate option parser implementation"),
64                    clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes",
65                               "Generate clang attribute clases"),
66                    clEnumValN(GenClangAttrExprArgsList,
67                               "gen-clang-attr-expr-args-list",
68                               "Generate a clang attribute expression "
69                               "arguments list"),
70                    clEnumValN(GenClangAttrImpl, "gen-clang-attr-impl",
71                               "Generate clang attribute implementations"),
72                    clEnumValN(GenClangAttrList, "gen-clang-attr-list",
73                               "Generate a clang attribute list"),
74                    clEnumValN(GenClangAttrPCHRead, "gen-clang-attr-pch-read",
75                               "Generate clang PCH attribute reader"),
76                    clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
77                               "Generate clang PCH attribute writer"),
78                    clEnumValN(GenClangAttrSpellingList,
79                               "gen-clang-attr-spelling-list",
80                               "Generate a clang attribute spelling list"),
81                    clEnumValN(GenClangAttrSpellingListIndex,
82                               "gen-clang-attr-spelling-index",
83                               "Generate a clang attribute spelling index"),
84                    clEnumValN(GenClangAttrLateParsedList,
85                               "gen-clang-attr-late-parsed-list",
86                               "Generate a clang attribute LateParsed list"),
87                    clEnumValN(GenClangAttrTemplateInstantiate,
88                               "gen-clang-attr-template-instantiate",
89                               "Generate a clang template instantiate code"),
90                    clEnumValN(GenClangAttrParsedAttrList,
91                               "gen-clang-attr-parsed-attr-list",
92                               "Generate a clang parsed attribute list"),
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,
103                               "gen-clang-diags-index-name",
104                               "Generate Clang diagnostic name index"),
105                    clEnumValN(GenClangCommentNodes, "gen-clang-comment-nodes",
106                               "Generate Clang AST comment nodes"),
107                    clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
108                               "Generate Clang AST declaration nodes"),
109                    clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
110                               "Generate Clang AST statement nodes"),
111                    clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
112                               "Generate Clang Static Analyzer checkers"),
113                    clEnumValN(GenClangCommentHTMLTags,
114                               "gen-clang-comment-html-tags",
115                               "Generate efficient matchers for HTML tag "
116                               "names that are used in documentation comments"),
117                    clEnumValN(GenClangCommentHTMLTagsProperties,
118                               "gen-clang-comment-html-tags-properties",
119                               "Generate efficient matchers for HTML tag "
120                               "properties"),
121                    clEnumValN(GenClangCommentHTMLNamedCharacterReferences,
122                               "gen-clang-comment-html-named-character-references",
123                               "Generate function to translate named character "
124                               "references to UTF-8 sequences"),
125                    clEnumValN(GenClangCommentCommandInfo,
126                               "gen-clang-comment-command-info",
127                               "Generate command properties for commands that "
128                               "are used in documentation comments"),
129                    clEnumValN(GenClangCommentCommandList,
130                               "gen-clang-comment-command-list",
131                               "Generate list of commands that are used in "
132                               "documentation comments"),
133                    clEnumValN(GenArmNeon, "gen-arm-neon",
134                               "Generate arm_neon.h for clang"),
135                    clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
136                               "Generate ARM NEON sema support for clang"),
137                    clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
138                               "Generate ARM NEON tests for clang"),
139                    clEnumValEnd));
140
141  cl::opt<std::string>
142  ClangComponent("clang-component",
143                 cl::desc("Only use warnings from specified component"),
144                 cl::value_desc("component"), cl::Hidden);
145
146bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
147  switch (Action) {
148  case GenClangAttrClasses:
149    EmitClangAttrClass(Records, OS);
150    break;
151  case GenClangAttrExprArgsList:
152    EmitClangAttrExprArgsList(Records, OS);
153    break;
154  case GenClangAttrImpl:
155    EmitClangAttrImpl(Records, OS);
156    break;
157  case GenClangAttrList:
158    EmitClangAttrList(Records, OS);
159    break;
160  case GenClangAttrPCHRead:
161    EmitClangAttrPCHRead(Records, OS);
162    break;
163  case GenClangAttrPCHWrite:
164    EmitClangAttrPCHWrite(Records, OS);
165    break;
166  case GenClangAttrSpellingList:
167    EmitClangAttrSpellingList(Records, OS);
168    break;
169  case GenClangAttrSpellingListIndex:
170    EmitClangAttrSpellingListIndex(Records, OS);
171    break;
172  case GenClangAttrLateParsedList:
173    EmitClangAttrLateParsedList(Records, OS);
174    break;
175  case GenClangAttrTemplateInstantiate:
176    EmitClangAttrTemplateInstantiate(Records, OS);
177    break;
178  case GenClangAttrParsedAttrList:
179    EmitClangAttrParsedAttrList(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 GenOptParserDefs:
225    EmitOptParser(Records, OS, true);
226    break;
227  case GenOptParserImpl:
228    EmitOptParser(Records, OS, false);
229    break;
230  case GenArmNeon:
231    EmitNeon(Records, OS);
232    break;
233  case GenArmNeonSema:
234    EmitNeonSema(Records, OS);
235    break;
236  case GenArmNeonTest:
237    EmitNeonTest(Records, OS);
238    break;
239  }
240
241  return false;
242}
243}
244
245int main(int argc, char **argv) {
246  sys::PrintStackTraceOnErrorSignal();
247  PrettyStackTraceProgram X(argc, argv);
248  cl::ParseCommandLineOptions(argc, argv);
249
250  return TableGenMain(argv[0], &ClangTableGenMain);
251}
252