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