TableGen.cpp revision 99ba9e3bd70671f3441fb974895f226a83ce0e66
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
29using namespace llvm;
30
31enum ActionType {
32  GenClangAttrClasses,
33  GenClangAttrImpl,
34  GenClangAttrList,
35  GenClangAttrPCHRead,
36  GenClangAttrPCHWrite,
37  GenClangAttrSpellingList,
38  GenClangAttrLateParsedList,
39  GenClangDiagsDefs,
40  GenClangDiagGroups,
41  GenClangDiagsIndexName,
42  GenClangDeclNodes,
43  GenClangStmtNodes,
44  GenClangSACheckers,
45  GenOptParserDefs, GenOptParserImpl,
46  GenArmNeon,
47  GenArmNeonSema,
48  GenArmNeonTest
49};
50
51namespace {
52  cl::opt<ActionType>
53  Action(cl::desc("Action to perform:"),
54         cl::values(clEnumValN(GenOptParserDefs, "gen-opt-parser-defs",
55                               "Generate option definitions"),
56                    clEnumValN(GenOptParserImpl, "gen-opt-parser-impl",
57                               "Generate option parser implementation"),
58                    clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes",
59                               "Generate clang attribute clases"),
60                    clEnumValN(GenClangAttrImpl, "gen-clang-attr-impl",
61                               "Generate clang attribute implementations"),
62                    clEnumValN(GenClangAttrList, "gen-clang-attr-list",
63                               "Generate a clang attribute list"),
64                    clEnumValN(GenClangAttrPCHRead, "gen-clang-attr-pch-read",
65                               "Generate clang PCH attribute reader"),
66                    clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write",
67                               "Generate clang PCH attribute writer"),
68                    clEnumValN(GenClangAttrSpellingList,
69                               "gen-clang-attr-spelling-list",
70                               "Generate a clang attribute spelling list"),
71                    clEnumValN(GenClangAttrLateParsedList,
72                               "gen-clang-attr-late-parsed-list",
73                               "Generate a clang attribute LateParsed list"),
74                    clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs",
75                               "Generate Clang diagnostics definitions"),
76                    clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups",
77                               "Generate Clang diagnostic groups"),
78                    clEnumValN(GenClangDiagsIndexName,
79                               "gen-clang-diags-index-name",
80                               "Generate Clang diagnostic name index"),
81                    clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes",
82                               "Generate Clang AST declaration nodes"),
83                    clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes",
84                               "Generate Clang AST statement nodes"),
85                    clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers",
86                               "Generate Clang Static Analyzer checkers"),
87                    clEnumValN(GenArmNeon, "gen-arm-neon",
88                               "Generate arm_neon.h for clang"),
89                    clEnumValN(GenArmNeonSema, "gen-arm-neon-sema",
90                               "Generate ARM NEON sema support for clang"),
91                    clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
92                               "Generate ARM NEON tests for clang"),
93                    clEnumValEnd));
94
95  cl::opt<std::string>
96  ClangComponent("clang-component",
97                 cl::desc("Only use warnings from specified component"),
98                 cl::value_desc("component"), cl::Hidden);
99
100class ClangTableGenAction : public TableGenAction {
101public:
102  bool operator()(raw_ostream &OS, RecordKeeper &Records) {
103    switch (Action) {
104    case GenClangAttrClasses:
105      ClangAttrClassEmitter(Records).run(OS);
106      break;
107    case GenClangAttrImpl:
108      ClangAttrImplEmitter(Records).run(OS);
109      break;
110    case GenClangAttrList:
111      ClangAttrListEmitter(Records).run(OS);
112      break;
113    case GenClangAttrPCHRead:
114      ClangAttrPCHReadEmitter(Records).run(OS);
115      break;
116    case GenClangAttrPCHWrite:
117      ClangAttrPCHWriteEmitter(Records).run(OS);
118      break;
119    case GenClangAttrSpellingList:
120      ClangAttrSpellingListEmitter(Records).run(OS);
121      break;
122    case GenClangAttrLateParsedList:
123      ClangAttrLateParsedListEmitter(Records).run(OS);
124      break;
125    case GenClangDiagsDefs:
126      ClangDiagsDefsEmitter(Records, ClangComponent).run(OS);
127      break;
128    case GenClangDiagGroups:
129      ClangDiagGroupsEmitter(Records).run(OS);
130      break;
131    case GenClangDiagsIndexName:
132      ClangDiagsIndexNameEmitter(Records).run(OS);
133      break;
134    case GenClangDeclNodes:
135      ClangASTNodesEmitter(Records, "Decl", "Decl").run(OS);
136      ClangDeclContextEmitter(Records).run(OS);
137      break;
138    case GenClangStmtNodes:
139      ClangASTNodesEmitter(Records, "Stmt", "").run(OS);
140      break;
141    case GenClangSACheckers:
142      ClangSACheckersEmitter(Records).run(OS);
143      break;
144    case GenOptParserDefs:
145      OptParserEmitter(Records, true).run(OS);
146      break;
147    case GenOptParserImpl:
148      OptParserEmitter(Records, false).run(OS);
149      break;
150    case GenArmNeon:
151      NeonEmitter(Records).run(OS);
152      break;
153    case GenArmNeonSema:
154      NeonEmitter(Records).runHeader(OS);
155      break;
156    case GenArmNeonTest:
157      NeonEmitter(Records).runTests(OS);
158      break;
159    default:
160      assert(1 && "Invalid Action");
161      return true;
162    }
163
164    return false;
165  }
166};
167}
168
169int main(int argc, char **argv) {
170  sys::PrintStackTraceOnErrorSignal();
171  PrettyStackTraceProgram X(argc, argv);
172  cl::ParseCommandLineOptions(argc, argv);
173
174  ClangTableGenAction Action;
175  return TableGenMain(argv[0], Action);
176}
177