TableGen.cpp revision bbb3b3237df2284f6f3c34798944fcfa4b43fd34
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  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};
56
57namespace {
58cl::opt<ActionType> Action(
59    cl::desc("Action to perform:"),
60    cl::values(
61        clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes",
62                   "Generate clang attribute clases"),
63        clEnumValN(GenClangAttrExprArgsList, "gen-clang-attr-expr-args-list",
64                   "Generate a clang attribute expression "
65                   "arguments list"),
66        clEnumValN(GenClangAttrImpl, "gen-clang-attr-impl",
67                   "Generate clang attribute implementations"),
68        clEnumValN(GenClangAttrList, "gen-clang-attr-list",
69                   "Generate a clang attribute list"),
70        clEnumValN(GenClangAttrPCHRead, "gen-clang-attr-pch-read",
71                   "Generate clang PCH attribute reader"),
72        clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
73                   "Generate clang PCH attribute writer"),
74        clEnumValN(GenClangAttrSpellingList, "gen-clang-attr-spelling-list",
75                   "Generate a clang attribute spelling list"),
76        clEnumValN(GenClangAttrSpellingListIndex,
77                   "gen-clang-attr-spelling-index",
78                   "Generate a clang attribute spelling index"),
79        clEnumValN(GenClangAttrLateParsedList,
80                   "gen-clang-attr-late-parsed-list",
81                   "Generate a clang attribute LateParsed list"),
82        clEnumValN(GenClangAttrTemplateInstantiate,
83                   "gen-clang-attr-template-instantiate",
84                   "Generate a clang template instantiate code"),
85                    clEnumValN(GenClangAttrParsedAttrList,
86                               "gen-clang-attr-parsed-attr-list",
87                               "Generate a clang parsed attribute list"),
88                    clEnumValN(GenClangAttrParsedAttrImpl,
89                               "gen-clang-attr-parsed-attr-impl",
90                               "Generate the clang parsed attribute helpers"),
91                    clEnumValN(GenClangAttrParsedAttrKinds,
92                               "gen-clang-attr-parsed-attr-kinds",
93                               "Generate a clang parsed attribute kinds"),
94        clEnumValN(GenClangAttrDump, "gen-clang-attr-dump",
95                   "Generate clang attribute dumper"),
96        clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
97                   "Generate Clang diagnostics definitions"),
98        clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
99                   "Generate Clang diagnostic groups"),
100        clEnumValN(GenClangDiagsIndexName, "gen-clang-diags-index-name",
101                   "Generate Clang diagnostic name index"),
102        clEnumValN(GenClangCommentNodes, "gen-clang-comment-nodes",
103                   "Generate Clang AST comment nodes"),
104        clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
105                   "Generate Clang AST declaration nodes"),
106        clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
107                   "Generate Clang AST statement nodes"),
108        clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
109                   "Generate Clang Static Analyzer checkers"),
110        clEnumValN(GenClangCommentHTMLTags, "gen-clang-comment-html-tags",
111                   "Generate efficient matchers for HTML tag "
112                   "names that are used in documentation comments"),
113        clEnumValN(GenClangCommentHTMLTagsProperties,
114                   "gen-clang-comment-html-tags-properties",
115                   "Generate efficient matchers for HTML tag "
116                   "properties"),
117        clEnumValN(GenClangCommentHTMLNamedCharacterReferences,
118                   "gen-clang-comment-html-named-character-references",
119                   "Generate function to translate named character "
120                   "references to UTF-8 sequences"),
121        clEnumValN(GenClangCommentCommandInfo, "gen-clang-comment-command-info",
122                   "Generate command properties for commands that "
123                   "are used in documentation comments"),
124        clEnumValN(GenClangCommentCommandList, "gen-clang-comment-command-list",
125                   "Generate list of commands that are used in "
126                   "documentation comments"),
127        clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"),
128        clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
129                   "Generate ARM NEON sema support for clang"),
130        clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
131                   "Generate ARM NEON tests for clang"),
132        clEnumValEnd));
133
134cl::opt<std::string>
135ClangComponent("clang-component",
136               cl::desc("Only use warnings from specified component"),
137               cl::value_desc("component"), cl::Hidden);
138
139bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
140  switch (Action) {
141  case GenClangAttrClasses:
142    EmitClangAttrClass(Records, OS);
143    break;
144  case GenClangAttrExprArgsList:
145    EmitClangAttrExprArgsList(Records, OS);
146    break;
147  case GenClangAttrImpl:
148    EmitClangAttrImpl(Records, OS);
149    break;
150  case GenClangAttrList:
151    EmitClangAttrList(Records, OS);
152    break;
153  case GenClangAttrPCHRead:
154    EmitClangAttrPCHRead(Records, OS);
155    break;
156  case GenClangAttrPCHWrite:
157    EmitClangAttrPCHWrite(Records, OS);
158    break;
159  case GenClangAttrSpellingList:
160    EmitClangAttrSpellingList(Records, OS);
161    break;
162  case GenClangAttrSpellingListIndex:
163    EmitClangAttrSpellingListIndex(Records, OS);
164    break;
165  case GenClangAttrLateParsedList:
166    EmitClangAttrLateParsedList(Records, OS);
167    break;
168  case GenClangAttrTemplateInstantiate:
169    EmitClangAttrTemplateInstantiate(Records, OS);
170    break;
171  case GenClangAttrParsedAttrList:
172    EmitClangAttrParsedAttrList(Records, OS);
173    break;
174  case GenClangAttrParsedAttrImpl:
175    EmitClangAttrParsedAttrImpl(Records, OS);
176    break;
177  case GenClangAttrParsedAttrKinds:
178    EmitClangAttrParsedAttrKinds(Records, OS);
179    break;
180  case GenClangAttrDump:
181    EmitClangAttrDump(Records, OS);
182    break;
183  case GenClangDiagsDefs:
184    EmitClangDiagsDefs(Records, OS, ClangComponent);
185    break;
186  case GenClangDiagGroups:
187    EmitClangDiagGroups(Records, OS);
188    break;
189  case GenClangDiagsIndexName:
190    EmitClangDiagsIndexName(Records, OS);
191    break;
192  case GenClangCommentNodes:
193    EmitClangASTNodes(Records, OS, "Comment", "");
194    break;
195  case GenClangDeclNodes:
196    EmitClangASTNodes(Records, OS, "Decl", "Decl");
197    EmitClangDeclContext(Records, OS);
198    break;
199  case GenClangStmtNodes:
200    EmitClangASTNodes(Records, OS, "Stmt", "");
201    break;
202  case GenClangSACheckers:
203    EmitClangSACheckers(Records, OS);
204    break;
205  case GenClangCommentHTMLTags:
206    EmitClangCommentHTMLTags(Records, OS);
207    break;
208  case GenClangCommentHTMLTagsProperties:
209    EmitClangCommentHTMLTagsProperties(Records, OS);
210    break;
211  case GenClangCommentHTMLNamedCharacterReferences:
212    EmitClangCommentHTMLNamedCharacterReferences(Records, OS);
213    break;
214  case GenClangCommentCommandInfo:
215    EmitClangCommentCommandInfo(Records, OS);
216    break;
217  case GenClangCommentCommandList:
218    EmitClangCommentCommandList(Records, OS);
219    break;
220  case GenArmNeon:
221    EmitNeon(Records, OS);
222    break;
223  case GenArmNeonSema:
224    EmitNeonSema(Records, OS);
225    break;
226  case GenArmNeonTest:
227    EmitNeonTest(Records, OS);
228    break;
229  }
230
231  return false;
232}
233}
234
235int main(int argc, char **argv) {
236  sys::PrintStackTraceOnErrorSignal();
237  PrettyStackTraceProgram X(argc, argv);
238  cl::ParseCommandLineOptions(argc, argv);
239
240  return TableGenMain(argv[0], &ClangTableGenMain);
241}
242