• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 using namespace llvm;
25 using namespace clang;
26 
27 enum 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   GenClangCommentCommandInfo,
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(GenClangCommentNodes, "gen-clang-comment-nodes",
94                                "Generate Clang AST comment nodes"),
95                     clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
96                                "Generate Clang AST declaration nodes"),
97                     clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
98                                "Generate Clang AST statement nodes"),
99                     clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
100                                "Generate Clang Static Analyzer checkers"),
101                     clEnumValN(GenClangCommentHTMLTags,
102                                "gen-clang-comment-html-tags",
103                                "Generate efficient matchers for HTML tag "
104                                "names that are used in documentation comments"),
105                     clEnumValN(GenClangCommentHTMLTagsProperties,
106                                "gen-clang-comment-html-tags-properties",
107                                "Generate efficient matchers for HTML tag "
108                                "properties"),
109                     clEnumValN(GenClangCommentCommandInfo,
110                                "gen-clang-comment-command-info",
111                                "Generate list of commands that are used in "
112                                "documentation comments"),
113                     clEnumValN(GenArmNeon, "gen-arm-neon",
114                                "Generate arm_neon.h for clang"),
115                     clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
116                                "Generate ARM NEON sema support for clang"),
117                     clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
118                                "Generate ARM NEON tests for clang"),
119                     clEnumValEnd));
120 
121   cl::opt<std::string>
122   ClangComponent("clang-component",
123                  cl::desc("Only use warnings from specified component"),
124                  cl::value_desc("component"), cl::Hidden);
125 
126 class ClangTableGenAction : public TableGenAction {
127 public:
operator ()(raw_ostream & OS,RecordKeeper & Records)128   bool operator()(raw_ostream &OS, RecordKeeper &Records) {
129     switch (Action) {
130     case GenClangAttrClasses:
131       EmitClangAttrClass(Records, OS);
132       break;
133     case GenClangAttrImpl:
134       EmitClangAttrImpl(Records, OS);
135       break;
136     case GenClangAttrList:
137       EmitClangAttrList(Records, OS);
138       break;
139     case GenClangAttrPCHRead:
140       EmitClangAttrPCHRead(Records, OS);
141       break;
142     case GenClangAttrPCHWrite:
143       EmitClangAttrPCHWrite(Records, OS);
144       break;
145     case GenClangAttrSpellingList:
146       EmitClangAttrSpellingList(Records, OS);
147       break;
148     case GenClangAttrLateParsedList:
149       EmitClangAttrLateParsedList(Records, OS);
150       break;
151     case GenClangAttrTemplateInstantiate:
152       EmitClangAttrTemplateInstantiate(Records, OS);
153       break;
154     case GenClangAttrParsedAttrList:
155       EmitClangAttrParsedAttrList(Records, OS);
156       break;
157     case GenClangAttrParsedAttrKinds:
158       EmitClangAttrParsedAttrKinds(Records, OS);
159       break;
160     case GenClangDiagsDefs:
161       EmitClangDiagsDefs(Records, OS, ClangComponent);
162       break;
163     case GenClangDiagGroups:
164       EmitClangDiagGroups(Records, OS);
165       break;
166     case GenClangDiagsIndexName:
167       EmitClangDiagsIndexName(Records, OS);
168       break;
169     case GenClangCommentNodes:
170       EmitClangASTNodes(Records, OS, "Comment", "");
171       break;
172     case GenClangDeclNodes:
173       EmitClangASTNodes(Records, OS, "Decl", "Decl");
174       EmitClangDeclContext(Records, OS);
175       break;
176     case GenClangStmtNodes:
177       EmitClangASTNodes(Records, OS, "Stmt", "");
178       break;
179     case GenClangSACheckers:
180       EmitClangSACheckers(Records, OS);
181       break;
182     case GenClangCommentHTMLTags:
183       EmitClangCommentHTMLTags(Records, OS);
184       break;
185     case GenClangCommentHTMLTagsProperties:
186       EmitClangCommentHTMLTagsProperties(Records, OS);
187       break;
188     case GenClangCommentCommandInfo:
189       EmitClangCommentCommandInfo(Records, OS);
190       break;
191     case GenOptParserDefs:
192       EmitOptParser(Records, OS, true);
193       break;
194     case GenOptParserImpl:
195       EmitOptParser(Records, OS, false);
196       break;
197     case GenArmNeon:
198       EmitNeon(Records, OS);
199       break;
200     case GenArmNeonSema:
201       EmitNeonSema(Records, OS);
202       break;
203     case GenArmNeonTest:
204       EmitNeonTest(Records, OS);
205       break;
206     }
207 
208     return false;
209   }
210 };
211 }
212 
main(int argc,char ** argv)213 int main(int argc, char **argv) {
214   sys::PrintStackTraceOnErrorSignal();
215   PrettyStackTraceProgram X(argc, argv);
216   cl::ParseCommandLineOptions(argc, argv);
217 
218   ClangTableGenAction Action;
219   return TableGenMain(argv[0], Action);
220 }
221