Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 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 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 14 | #include "TableGenBackends.h" // Declares all backends. |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 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; |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 25 | using namespace clang; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 26 | |
| 27 | enum ActionType { |
| 28 | GenClangAttrClasses, |
| 29 | GenClangAttrImpl, |
| 30 | GenClangAttrList, |
| 31 | GenClangAttrPCHRead, |
| 32 | GenClangAttrPCHWrite, |
| 33 | GenClangAttrSpellingList, |
| 34 | GenClangAttrLateParsedList, |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 35 | GenClangAttrTemplateInstantiate, |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 36 | GenClangAttrParsedAttrList, |
| 37 | GenClangAttrParsedAttrKinds, |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 38 | GenClangDiagsDefs, |
| 39 | GenClangDiagGroups, |
| 40 | GenClangDiagsIndexName, |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 41 | GenClangCommentNodes, |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 42 | GenClangDeclNodes, |
| 43 | GenClangStmtNodes, |
| 44 | GenClangSACheckers, |
| 45 | GenOptParserDefs, GenOptParserImpl, |
| 46 | GenArmNeon, |
| 47 | GenArmNeonSema, |
| 48 | GenArmNeonTest |
| 49 | }; |
| 50 | |
| 51 | namespace { |
| 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"), |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 74 | clEnumValN(GenClangAttrTemplateInstantiate, |
| 75 | "gen-clang-attr-template-instantiate", |
| 76 | "Generate a clang template instantiate code"), |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 77 | clEnumValN(GenClangAttrParsedAttrList, |
| 78 | "gen-clang-attr-parsed-attr-list", |
| 79 | "Generate a clang parsed attribute list"), |
| 80 | clEnumValN(GenClangAttrParsedAttrKinds, |
| 81 | "gen-clang-attr-parsed-attr-kinds", |
| 82 | "Generate a clang parsed attribute kinds"), |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 83 | clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs", |
| 84 | "Generate Clang diagnostics definitions"), |
| 85 | clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups", |
| 86 | "Generate Clang diagnostic groups"), |
| 87 | clEnumValN(GenClangDiagsIndexName, |
| 88 | "gen-clang-diags-index-name", |
| 89 | "Generate Clang diagnostic name index"), |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 90 | clEnumValN(GenClangCommentNodes, "gen-clang-comment-nodes", |
| 91 | "Generate Clang AST comment nodes"), |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 92 | clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes", |
| 93 | "Generate Clang AST declaration nodes"), |
| 94 | clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes", |
| 95 | "Generate Clang AST statement nodes"), |
| 96 | clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers", |
| 97 | "Generate Clang Static Analyzer checkers"), |
| 98 | clEnumValN(GenArmNeon, "gen-arm-neon", |
| 99 | "Generate arm_neon.h for clang"), |
| 100 | clEnumValN(GenArmNeonSema, "gen-arm-neon-sema", |
| 101 | "Generate ARM NEON sema support for clang"), |
| 102 | clEnumValN(GenArmNeonTest, "gen-arm-neon-test", |
| 103 | "Generate ARM NEON tests for clang"), |
| 104 | clEnumValEnd)); |
| 105 | |
| 106 | cl::opt<std::string> |
| 107 | ClangComponent("clang-component", |
| 108 | cl::desc("Only use warnings from specified component"), |
| 109 | cl::value_desc("component"), cl::Hidden); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 110 | |
| 111 | class ClangTableGenAction : public TableGenAction { |
| 112 | public: |
| 113 | bool operator()(raw_ostream &OS, RecordKeeper &Records) { |
| 114 | switch (Action) { |
| 115 | case GenClangAttrClasses: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 116 | EmitClangAttrClass(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 117 | break; |
| 118 | case GenClangAttrImpl: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 119 | EmitClangAttrImpl(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 120 | break; |
| 121 | case GenClangAttrList: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 122 | EmitClangAttrList(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 123 | break; |
| 124 | case GenClangAttrPCHRead: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 125 | EmitClangAttrPCHRead(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 126 | break; |
| 127 | case GenClangAttrPCHWrite: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 128 | EmitClangAttrPCHWrite(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 129 | break; |
| 130 | case GenClangAttrSpellingList: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 131 | EmitClangAttrSpellingList(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 132 | break; |
| 133 | case GenClangAttrLateParsedList: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 134 | EmitClangAttrLateParsedList(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 135 | break; |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 136 | case GenClangAttrTemplateInstantiate: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 137 | EmitClangAttrTemplateInstantiate(Records, OS); |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 138 | break; |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 139 | case GenClangAttrParsedAttrList: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 140 | EmitClangAttrParsedAttrList(Records, OS); |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 141 | break; |
| 142 | case GenClangAttrParsedAttrKinds: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 143 | EmitClangAttrParsedAttrKinds(Records, OS); |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 144 | break; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 145 | case GenClangDiagsDefs: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 146 | EmitClangDiagsDefs(Records, OS, ClangComponent); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 147 | break; |
| 148 | case GenClangDiagGroups: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 149 | EmitClangDiagGroups(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 150 | break; |
| 151 | case GenClangDiagsIndexName: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 152 | EmitClangDiagsIndexName(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 153 | break; |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 154 | case GenClangCommentNodes: |
| 155 | EmitClangASTNodes(Records, OS, "Comment", ""); |
| 156 | break; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 157 | case GenClangDeclNodes: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 158 | EmitClangASTNodes(Records, OS, "Decl", "Decl"); |
| 159 | EmitClangDeclContext(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 160 | break; |
| 161 | case GenClangStmtNodes: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 162 | EmitClangASTNodes(Records, OS, "Stmt", ""); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 163 | break; |
| 164 | case GenClangSACheckers: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 165 | EmitClangSACheckers(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 166 | break; |
| 167 | case GenOptParserDefs: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 168 | EmitOptParser(Records, OS, true); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 169 | break; |
| 170 | case GenOptParserImpl: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 171 | EmitOptParser(Records, OS, false); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 172 | break; |
| 173 | case GenArmNeon: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 174 | EmitNeon(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 175 | break; |
| 176 | case GenArmNeonSema: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 177 | EmitNeonSema(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 178 | break; |
| 179 | case GenArmNeonTest: |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 180 | EmitNeonTest(Records, OS); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 181 | break; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | return false; |
| 185 | } |
| 186 | }; |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 187 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 188 | |
| 189 | int main(int argc, char **argv) { |
| 190 | sys::PrintStackTraceOnErrorSignal(); |
| 191 | PrettyStackTraceProgram X(argc, argv); |
| 192 | cl::ParseCommandLineOptions(argc, argv); |
| 193 | |
| 194 | ClangTableGenAction Action; |
| 195 | return TableGenMain(argv[0], Action); |
| 196 | } |