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 "ClangASTNodesEmitter.h"
15 #include "ClangAttrEmitter.h"
16 #include "ClangDiagnosticsEmitter.h"
17 #include "ClangSACheckersEmitter.h"
18 #include "NeonEmitter.h"
19 #include "OptParserEmitter.h"
20
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/PrettyStackTrace.h"
23 #include "llvm/Support/Signals.h"
24 #include "llvm/TableGen/Error.h"
25 #include "llvm/TableGen/Main.h"
26 #include "llvm/TableGen/Record.h"
27 #include "llvm/TableGen/TableGenAction.h"
28
29 using namespace llvm;
30
31 enum ActionType {
32 GenClangAttrClasses,
33 GenClangAttrImpl,
34 GenClangAttrList,
35 GenClangAttrPCHRead,
36 GenClangAttrPCHWrite,
37 GenClangAttrSpellingList,
38 GenClangAttrLateParsedList,
39 GenClangAttrTemplateInstantiate,
40 GenClangAttrParsedAttrList,
41 GenClangAttrParsedAttrKinds,
42 GenClangDiagsDefs,
43 GenClangDiagGroups,
44 GenClangDiagsIndexName,
45 GenClangDeclNodes,
46 GenClangStmtNodes,
47 GenClangSACheckers,
48 GenOptParserDefs, GenOptParserImpl,
49 GenArmNeon,
50 GenArmNeonSema,
51 GenArmNeonTest
52 };
53
54 namespace {
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(GenClangAttrLateParsedList,
75 "gen-clang-attr-late-parsed-list",
76 "Generate a clang attribute LateParsed list"),
77 clEnumValN(GenClangAttrTemplateInstantiate,
78 "gen-clang-attr-template-instantiate",
79 "Generate a clang template instantiate code"),
80 clEnumValN(GenClangAttrParsedAttrList,
81 "gen-clang-attr-parsed-attr-list",
82 "Generate a clang parsed attribute list"),
83 clEnumValN(GenClangAttrParsedAttrKinds,
84 "gen-clang-attr-parsed-attr-kinds",
85 "Generate a clang parsed attribute kinds"),
86 clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
87 "Generate Clang diagnostics definitions"),
88 clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
89 "Generate Clang diagnostic groups"),
90 clEnumValN(GenClangDiagsIndexName,
91 "gen-clang-diags-index-name",
92 "Generate Clang diagnostic name index"),
93 clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
94 "Generate Clang AST declaration nodes"),
95 clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
96 "Generate Clang AST statement nodes"),
97 clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
98 "Generate Clang Static Analyzer checkers"),
99 clEnumValN(GenArmNeon, "gen-arm-neon",
100 "Generate arm_neon.h for clang"),
101 clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
102 "Generate ARM NEON sema support for clang"),
103 clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
104 "Generate ARM NEON tests for clang"),
105 clEnumValEnd));
106
107 cl::opt<std::string>
108 ClangComponent("clang-component",
109 cl::desc("Only use warnings from specified component"),
110 cl::value_desc("component"), cl::Hidden);
111
112 class ClangTableGenAction : public TableGenAction {
113 public:
operator ()(raw_ostream & OS,RecordKeeper & Records)114 bool operator()(raw_ostream &OS, RecordKeeper &Records) {
115 switch (Action) {
116 case GenClangAttrClasses:
117 ClangAttrClassEmitter(Records).run(OS);
118 break;
119 case GenClangAttrImpl:
120 ClangAttrImplEmitter(Records).run(OS);
121 break;
122 case GenClangAttrList:
123 ClangAttrListEmitter(Records).run(OS);
124 break;
125 case GenClangAttrPCHRead:
126 ClangAttrPCHReadEmitter(Records).run(OS);
127 break;
128 case GenClangAttrPCHWrite:
129 ClangAttrPCHWriteEmitter(Records).run(OS);
130 break;
131 case GenClangAttrSpellingList:
132 ClangAttrSpellingListEmitter(Records).run(OS);
133 break;
134 case GenClangAttrLateParsedList:
135 ClangAttrLateParsedListEmitter(Records).run(OS);
136 break;
137 case GenClangAttrTemplateInstantiate:
138 ClangAttrTemplateInstantiateEmitter(Records).run(OS);
139 break;
140 case GenClangAttrParsedAttrList:
141 ClangAttrParsedAttrListEmitter(Records).run(OS);
142 break;
143 case GenClangAttrParsedAttrKinds:
144 ClangAttrParsedAttrKindsEmitter(Records).run(OS);
145 break;
146 case GenClangDiagsDefs:
147 ClangDiagsDefsEmitter(Records, ClangComponent).run(OS);
148 break;
149 case GenClangDiagGroups:
150 ClangDiagGroupsEmitter(Records).run(OS);
151 break;
152 case GenClangDiagsIndexName:
153 ClangDiagsIndexNameEmitter(Records).run(OS);
154 break;
155 case GenClangDeclNodes:
156 ClangASTNodesEmitter(Records, "Decl", "Decl").run(OS);
157 ClangDeclContextEmitter(Records).run(OS);
158 break;
159 case GenClangStmtNodes:
160 ClangASTNodesEmitter(Records, "Stmt", "").run(OS);
161 break;
162 case GenClangSACheckers:
163 ClangSACheckersEmitter(Records).run(OS);
164 break;
165 case GenOptParserDefs:
166 OptParserEmitter(Records, true).run(OS);
167 break;
168 case GenOptParserImpl:
169 OptParserEmitter(Records, false).run(OS);
170 break;
171 case GenArmNeon:
172 NeonEmitter(Records).run(OS);
173 break;
174 case GenArmNeonSema:
175 NeonEmitter(Records).runHeader(OS);
176 break;
177 case GenArmNeonTest:
178 NeonEmitter(Records).runTests(OS);
179 break;
180 }
181
182 return false;
183 }
184 };
185 }
186
main(int argc,char ** argv)187 int main(int argc, char **argv) {
188 sys::PrintStackTraceOnErrorSignal();
189 PrettyStackTraceProgram X(argc, argv);
190 cl::ParseCommandLineOptions(argc, argv);
191
192 ClangTableGenAction Action;
193 return TableGenMain(argv[0], Action);
194 }
195