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