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