1 //===- TableGen.cpp - Top-Level TableGen implementation for Clang ---------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains the main function for Clang's TableGen. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "TableGenBackends.h" // Declares all backends. 14 #include "llvm/Support/CommandLine.h" 15 #include "llvm/Support/PrettyStackTrace.h" 16 #include "llvm/Support/Signals.h" 17 #include "llvm/TableGen/Error.h" 18 #include "llvm/TableGen/Main.h" 19 #include "llvm/TableGen/Record.h" 20 21 using namespace llvm; 22 using namespace clang; 23 24 enum ActionType { 25 PrintRecords, 26 DumpJSON, 27 GenClangAttrClasses, 28 GenClangAttrParserStringSwitches, 29 GenClangAttrSubjectMatchRulesParserStringSwitches, 30 GenClangAttrImpl, 31 GenClangAttrList, 32 GenClangAttrSubjectMatchRuleList, 33 GenClangAttrPCHRead, 34 GenClangAttrPCHWrite, 35 GenClangAttrHasAttributeImpl, 36 GenClangAttrSpellingListIndex, 37 GenClangAttrASTVisitor, 38 GenClangAttrTemplateInstantiate, 39 GenClangAttrParsedAttrList, 40 GenClangAttrParsedAttrImpl, 41 GenClangAttrParsedAttrKinds, 42 GenClangAttrTextNodeDump, 43 GenClangAttrNodeTraverse, 44 GenClangDiagsDefs, 45 GenClangDiagGroups, 46 GenClangDiagsIndexName, 47 GenClangCommentNodes, 48 GenClangDeclNodes, 49 GenClangStmtNodes, 50 GenClangSACheckers, 51 GenClangCommentHTMLTags, 52 GenClangCommentHTMLTagsProperties, 53 GenClangCommentHTMLNamedCharacterReferences, 54 GenClangCommentCommandInfo, 55 GenClangCommentCommandList, 56 GenClangOpenCLBuiltins, 57 GenArmNeon, 58 GenArmFP16, 59 GenArmNeonSema, 60 GenArmNeonTest, 61 GenAttrDocs, 62 GenDiagDocs, 63 GenOptDocs, 64 GenDataCollectors, 65 GenTestPragmaAttributeSupportedAttributes 66 }; 67 68 namespace { 69 cl::opt<ActionType> Action( 70 cl::desc("Action to perform:"), 71 cl::values( 72 clEnumValN(PrintRecords, "print-records", 73 "Print all records to stdout (default)"), 74 clEnumValN(DumpJSON, "dump-json", 75 "Dump all records as machine-readable JSON"), 76 clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes", 77 "Generate clang attribute clases"), 78 clEnumValN(GenClangAttrParserStringSwitches, 79 "gen-clang-attr-parser-string-switches", 80 "Generate all parser-related attribute string switches"), 81 clEnumValN(GenClangAttrSubjectMatchRulesParserStringSwitches, 82 "gen-clang-attr-subject-match-rules-parser-string-switches", 83 "Generate all parser-related attribute subject match rule" 84 "string switches"), 85 clEnumValN(GenClangAttrImpl, "gen-clang-attr-impl", 86 "Generate clang attribute implementations"), 87 clEnumValN(GenClangAttrList, "gen-clang-attr-list", 88 "Generate a clang attribute list"), 89 clEnumValN(GenClangAttrSubjectMatchRuleList, 90 "gen-clang-attr-subject-match-rule-list", 91 "Generate a clang attribute subject match rule list"), 92 clEnumValN(GenClangAttrPCHRead, "gen-clang-attr-pch-read", 93 "Generate clang PCH attribute reader"), 94 clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write", 95 "Generate clang PCH attribute writer"), 96 clEnumValN(GenClangAttrHasAttributeImpl, 97 "gen-clang-attr-has-attribute-impl", 98 "Generate a clang attribute spelling list"), 99 clEnumValN(GenClangAttrSpellingListIndex, 100 "gen-clang-attr-spelling-index", 101 "Generate a clang attribute spelling index"), 102 clEnumValN(GenClangAttrASTVisitor, "gen-clang-attr-ast-visitor", 103 "Generate a recursive AST visitor for clang attributes"), 104 clEnumValN(GenClangAttrTemplateInstantiate, 105 "gen-clang-attr-template-instantiate", 106 "Generate a clang template instantiate code"), 107 clEnumValN(GenClangAttrParsedAttrList, 108 "gen-clang-attr-parsed-attr-list", 109 "Generate a clang parsed attribute list"), 110 clEnumValN(GenClangAttrParsedAttrImpl, 111 "gen-clang-attr-parsed-attr-impl", 112 "Generate the clang parsed attribute helpers"), 113 clEnumValN(GenClangAttrParsedAttrKinds, 114 "gen-clang-attr-parsed-attr-kinds", 115 "Generate a clang parsed attribute kinds"), 116 clEnumValN(GenClangAttrTextNodeDump, "gen-clang-attr-text-node-dump", 117 "Generate clang attribute text node dumper"), 118 clEnumValN(GenClangAttrNodeTraverse, "gen-clang-attr-node-traverse", 119 "Generate clang attribute traverser"), 120 clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs", 121 "Generate Clang diagnostics definitions"), 122 clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups", 123 "Generate Clang diagnostic groups"), 124 clEnumValN(GenClangDiagsIndexName, "gen-clang-diags-index-name", 125 "Generate Clang diagnostic name index"), 126 clEnumValN(GenClangCommentNodes, "gen-clang-comment-nodes", 127 "Generate Clang AST comment nodes"), 128 clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes", 129 "Generate Clang AST declaration nodes"), 130 clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes", 131 "Generate Clang AST statement nodes"), 132 clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers", 133 "Generate Clang Static Analyzer checkers"), 134 clEnumValN(GenClangCommentHTMLTags, "gen-clang-comment-html-tags", 135 "Generate efficient matchers for HTML tag " 136 "names that are used in documentation comments"), 137 clEnumValN(GenClangCommentHTMLTagsProperties, 138 "gen-clang-comment-html-tags-properties", 139 "Generate efficient matchers for HTML tag " 140 "properties"), 141 clEnumValN(GenClangCommentHTMLNamedCharacterReferences, 142 "gen-clang-comment-html-named-character-references", 143 "Generate function to translate named character " 144 "references to UTF-8 sequences"), 145 clEnumValN(GenClangCommentCommandInfo, "gen-clang-comment-command-info", 146 "Generate command properties for commands that " 147 "are used in documentation comments"), 148 clEnumValN(GenClangCommentCommandList, "gen-clang-comment-command-list", 149 "Generate list of commands that are used in " 150 "documentation comments"), 151 clEnumValN(GenClangOpenCLBuiltins, "gen-clang-opencl-builtins", 152 "Generate OpenCL builtin declaration handlers"), 153 clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"), 154 clEnumValN(GenArmFP16, "gen-arm-fp16", "Generate arm_fp16.h for clang"), 155 clEnumValN(GenArmNeonSema, "gen-arm-neon-sema", 156 "Generate ARM NEON sema support for clang"), 157 clEnumValN(GenArmNeonTest, "gen-arm-neon-test", 158 "Generate ARM NEON tests for clang"), 159 clEnumValN(GenAttrDocs, "gen-attr-docs", 160 "Generate attribute documentation"), 161 clEnumValN(GenDiagDocs, "gen-diag-docs", 162 "Generate diagnostic documentation"), 163 clEnumValN(GenOptDocs, "gen-opt-docs", "Generate option documentation"), 164 clEnumValN(GenDataCollectors, "gen-clang-data-collectors", 165 "Generate data collectors for AST nodes"), 166 clEnumValN(GenTestPragmaAttributeSupportedAttributes, 167 "gen-clang-test-pragma-attribute-supported-attributes", 168 "Generate a list of attributes supported by #pragma clang " 169 "attribute for testing purposes"))); 170 171 cl::opt<std::string> 172 ClangComponent("clang-component", 173 cl::desc("Only use warnings from specified component"), 174 cl::value_desc("component"), cl::Hidden); 175 176 bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) { 177 switch (Action) { 178 case PrintRecords: 179 OS << Records; // No argument, dump all contents 180 break; 181 case DumpJSON: 182 EmitJSON(Records, OS); 183 break; 184 case GenClangAttrClasses: 185 EmitClangAttrClass(Records, OS); 186 break; 187 case GenClangAttrParserStringSwitches: 188 EmitClangAttrParserStringSwitches(Records, OS); 189 break; 190 case GenClangAttrSubjectMatchRulesParserStringSwitches: 191 EmitClangAttrSubjectMatchRulesParserStringSwitches(Records, OS); 192 break; 193 case GenClangAttrImpl: 194 EmitClangAttrImpl(Records, OS); 195 break; 196 case GenClangAttrList: 197 EmitClangAttrList(Records, OS); 198 break; 199 case GenClangAttrSubjectMatchRuleList: 200 EmitClangAttrSubjectMatchRuleList(Records, OS); 201 break; 202 case GenClangAttrPCHRead: 203 EmitClangAttrPCHRead(Records, OS); 204 break; 205 case GenClangAttrPCHWrite: 206 EmitClangAttrPCHWrite(Records, OS); 207 break; 208 case GenClangAttrHasAttributeImpl: 209 EmitClangAttrHasAttrImpl(Records, OS); 210 break; 211 case GenClangAttrSpellingListIndex: 212 EmitClangAttrSpellingListIndex(Records, OS); 213 break; 214 case GenClangAttrASTVisitor: 215 EmitClangAttrASTVisitor(Records, OS); 216 break; 217 case GenClangAttrTemplateInstantiate: 218 EmitClangAttrTemplateInstantiate(Records, OS); 219 break; 220 case GenClangAttrParsedAttrList: 221 EmitClangAttrParsedAttrList(Records, OS); 222 break; 223 case GenClangAttrParsedAttrImpl: 224 EmitClangAttrParsedAttrImpl(Records, OS); 225 break; 226 case GenClangAttrParsedAttrKinds: 227 EmitClangAttrParsedAttrKinds(Records, OS); 228 break; 229 case GenClangAttrTextNodeDump: 230 EmitClangAttrTextNodeDump(Records, OS); 231 break; 232 case GenClangAttrNodeTraverse: 233 EmitClangAttrNodeTraverse(Records, OS); 234 break; 235 case GenClangDiagsDefs: 236 EmitClangDiagsDefs(Records, OS, ClangComponent); 237 break; 238 case GenClangDiagGroups: 239 EmitClangDiagGroups(Records, OS); 240 break; 241 case GenClangDiagsIndexName: 242 EmitClangDiagsIndexName(Records, OS); 243 break; 244 case GenClangCommentNodes: 245 EmitClangASTNodes(Records, OS, "Comment", ""); 246 break; 247 case GenClangDeclNodes: 248 EmitClangASTNodes(Records, OS, "Decl", "Decl"); 249 EmitClangDeclContext(Records, OS); 250 break; 251 case GenClangStmtNodes: 252 EmitClangASTNodes(Records, OS, "Stmt", ""); 253 break; 254 case GenClangSACheckers: 255 EmitClangSACheckers(Records, OS); 256 break; 257 case GenClangCommentHTMLTags: 258 EmitClangCommentHTMLTags(Records, OS); 259 break; 260 case GenClangCommentHTMLTagsProperties: 261 EmitClangCommentHTMLTagsProperties(Records, OS); 262 break; 263 case GenClangCommentHTMLNamedCharacterReferences: 264 EmitClangCommentHTMLNamedCharacterReferences(Records, OS); 265 break; 266 case GenClangCommentCommandInfo: 267 EmitClangCommentCommandInfo(Records, OS); 268 break; 269 case GenClangCommentCommandList: 270 EmitClangCommentCommandList(Records, OS); 271 break; 272 case GenClangOpenCLBuiltins: 273 EmitClangOpenCLBuiltins(Records, OS); 274 break; 275 case GenArmNeon: 276 EmitNeon(Records, OS); 277 break; 278 case GenArmFP16: 279 EmitFP16(Records, OS); 280 break; 281 case GenArmNeonSema: 282 EmitNeonSema(Records, OS); 283 break; 284 case GenArmNeonTest: 285 EmitNeonTest(Records, OS); 286 break; 287 case GenAttrDocs: 288 EmitClangAttrDocs(Records, OS); 289 break; 290 case GenDiagDocs: 291 EmitClangDiagDocs(Records, OS); 292 break; 293 case GenOptDocs: 294 EmitClangOptDocs(Records, OS); 295 break; 296 case GenDataCollectors: 297 EmitClangDataCollectors(Records, OS); 298 break; 299 case GenTestPragmaAttributeSupportedAttributes: 300 EmitTestPragmaAttributeSupportedAttributes(Records, OS); 301 break; 302 } 303 304 return false; 305 } 306 } 307 308 int main(int argc, char **argv) { 309 sys::PrintStackTraceOnErrorSignal(argv[0]); 310 PrettyStackTraceProgram X(argc, argv); 311 cl::ParseCommandLineOptions(argc, argv); 312 313 llvm_shutdown_obj Y; 314 315 return TableGenMain(argv[0], &ClangTableGenMain); 316 } 317 318 #ifdef __has_feature 319 #if __has_feature(address_sanitizer) 320 #include <sanitizer/lsan_interface.h> 321 // Disable LeakSanitizer for this binary as it has too many leaks that are not 322 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h . 323 int __lsan_is_turned_off() { return 1; } 324 #endif // __has_feature(address_sanitizer) 325 #endif // defined(__has_feature) 326