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 "ASTTableGen.h" 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 PrintRecords, 27 DumpJSON, 28 GenClangAttrClasses, 29 GenClangAttrParserStringSwitches, 30 GenClangAttrSubjectMatchRulesParserStringSwitches, 31 GenClangAttrImpl, 32 GenClangAttrList, 33 GenClangAttrSubjectMatchRuleList, 34 GenClangAttrPCHRead, 35 GenClangAttrPCHWrite, 36 GenClangAttrHasAttributeImpl, 37 GenClangAttrSpellingListIndex, 38 GenClangAttrASTVisitor, 39 GenClangAttrTemplateInstantiate, 40 GenClangAttrParsedAttrList, 41 GenClangAttrParsedAttrImpl, 42 GenClangAttrParsedAttrKinds, 43 GenClangAttrTextNodeDump, 44 GenClangAttrNodeTraverse, 45 GenClangBasicReader, 46 GenClangBasicWriter, 47 GenClangDiagsDefs, 48 GenClangDiagGroups, 49 GenClangDiagsIndexName, 50 GenClangCommentNodes, 51 GenClangDeclNodes, 52 GenClangStmtNodes, 53 GenClangTypeNodes, 54 GenClangTypeReader, 55 GenClangTypeWriter, 56 GenClangOpcodes, 57 GenClangSACheckers, 58 GenClangSyntaxNodeList, 59 GenClangSyntaxNodeClasses, 60 GenClangCommentHTMLTags, 61 GenClangCommentHTMLTagsProperties, 62 GenClangCommentHTMLNamedCharacterReferences, 63 GenClangCommentCommandInfo, 64 GenClangCommentCommandList, 65 GenClangOpenCLBuiltins, 66 GenArmNeon, 67 GenArmFP16, 68 GenArmBF16, 69 GenArmNeonSema, 70 GenArmNeonTest, 71 GenArmMveHeader, 72 GenArmMveBuiltinDef, 73 GenArmMveBuiltinSema, 74 GenArmMveBuiltinCG, 75 GenArmMveBuiltinAliases, 76 GenArmSveHeader, 77 GenArmSveBuiltins, 78 GenArmSveBuiltinCG, 79 GenArmSveTypeFlags, 80 GenArmSveRangeChecks, 81 GenArmCdeHeader, 82 GenArmCdeBuiltinDef, 83 GenArmCdeBuiltinSema, 84 GenArmCdeBuiltinCG, 85 GenArmCdeBuiltinAliases, 86 GenAttrDocs, 87 GenDiagDocs, 88 GenOptDocs, 89 GenDataCollectors, 90 GenTestPragmaAttributeSupportedAttributes 91 }; 92 93 namespace { 94 cl::opt<ActionType> Action( 95 cl::desc("Action to perform:"), 96 cl::values( 97 clEnumValN(PrintRecords, "print-records", 98 "Print all records to stdout (default)"), 99 clEnumValN(DumpJSON, "dump-json", 100 "Dump all records as machine-readable JSON"), 101 clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes", 102 "Generate clang attribute clases"), 103 clEnumValN(GenClangAttrParserStringSwitches, 104 "gen-clang-attr-parser-string-switches", 105 "Generate all parser-related attribute string switches"), 106 clEnumValN(GenClangAttrSubjectMatchRulesParserStringSwitches, 107 "gen-clang-attr-subject-match-rules-parser-string-switches", 108 "Generate all parser-related attribute subject match rule" 109 "string switches"), 110 clEnumValN(GenClangAttrImpl, "gen-clang-attr-impl", 111 "Generate clang attribute implementations"), 112 clEnumValN(GenClangAttrList, "gen-clang-attr-list", 113 "Generate a clang attribute list"), 114 clEnumValN(GenClangAttrSubjectMatchRuleList, 115 "gen-clang-attr-subject-match-rule-list", 116 "Generate a clang attribute subject match rule list"), 117 clEnumValN(GenClangAttrPCHRead, "gen-clang-attr-pch-read", 118 "Generate clang PCH attribute reader"), 119 clEnumValN(GenClangAttrPCHWrite, "gen-clang-attr-pch-write", 120 "Generate clang PCH attribute writer"), 121 clEnumValN(GenClangAttrHasAttributeImpl, 122 "gen-clang-attr-has-attribute-impl", 123 "Generate a clang attribute spelling list"), 124 clEnumValN(GenClangAttrSpellingListIndex, 125 "gen-clang-attr-spelling-index", 126 "Generate a clang attribute spelling index"), 127 clEnumValN(GenClangAttrASTVisitor, "gen-clang-attr-ast-visitor", 128 "Generate a recursive AST visitor for clang attributes"), 129 clEnumValN(GenClangAttrTemplateInstantiate, 130 "gen-clang-attr-template-instantiate", 131 "Generate a clang template instantiate code"), 132 clEnumValN(GenClangAttrParsedAttrList, 133 "gen-clang-attr-parsed-attr-list", 134 "Generate a clang parsed attribute list"), 135 clEnumValN(GenClangAttrParsedAttrImpl, 136 "gen-clang-attr-parsed-attr-impl", 137 "Generate the clang parsed attribute helpers"), 138 clEnumValN(GenClangAttrParsedAttrKinds, 139 "gen-clang-attr-parsed-attr-kinds", 140 "Generate a clang parsed attribute kinds"), 141 clEnumValN(GenClangAttrTextNodeDump, "gen-clang-attr-text-node-dump", 142 "Generate clang attribute text node dumper"), 143 clEnumValN(GenClangAttrNodeTraverse, "gen-clang-attr-node-traverse", 144 "Generate clang attribute traverser"), 145 clEnumValN(GenClangDiagsDefs, "gen-clang-diags-defs", 146 "Generate Clang diagnostics definitions"), 147 clEnumValN(GenClangDiagGroups, "gen-clang-diag-groups", 148 "Generate Clang diagnostic groups"), 149 clEnumValN(GenClangDiagsIndexName, "gen-clang-diags-index-name", 150 "Generate Clang diagnostic name index"), 151 clEnumValN(GenClangBasicReader, "gen-clang-basic-reader", 152 "Generate Clang BasicReader classes"), 153 clEnumValN(GenClangBasicWriter, "gen-clang-basic-writer", 154 "Generate Clang BasicWriter classes"), 155 clEnumValN(GenClangCommentNodes, "gen-clang-comment-nodes", 156 "Generate Clang AST comment nodes"), 157 clEnumValN(GenClangDeclNodes, "gen-clang-decl-nodes", 158 "Generate Clang AST declaration nodes"), 159 clEnumValN(GenClangStmtNodes, "gen-clang-stmt-nodes", 160 "Generate Clang AST statement nodes"), 161 clEnumValN(GenClangTypeNodes, "gen-clang-type-nodes", 162 "Generate Clang AST type nodes"), 163 clEnumValN(GenClangTypeReader, "gen-clang-type-reader", 164 "Generate Clang AbstractTypeReader class"), 165 clEnumValN(GenClangTypeWriter, "gen-clang-type-writer", 166 "Generate Clang AbstractTypeWriter class"), 167 clEnumValN(GenClangOpcodes, "gen-clang-opcodes", 168 "Generate Clang constexpr interpreter opcodes"), 169 clEnumValN(GenClangSACheckers, "gen-clang-sa-checkers", 170 "Generate Clang Static Analyzer checkers"), 171 clEnumValN(GenClangSyntaxNodeList, "gen-clang-syntax-node-list", 172 "Generate list of Clang Syntax Tree node types"), 173 clEnumValN(GenClangSyntaxNodeClasses, "gen-clang-syntax-node-classes", 174 "Generate definitions of Clang Syntax Tree node clasess"), 175 clEnumValN(GenClangCommentHTMLTags, "gen-clang-comment-html-tags", 176 "Generate efficient matchers for HTML tag " 177 "names that are used in documentation comments"), 178 clEnumValN(GenClangCommentHTMLTagsProperties, 179 "gen-clang-comment-html-tags-properties", 180 "Generate efficient matchers for HTML tag " 181 "properties"), 182 clEnumValN(GenClangCommentHTMLNamedCharacterReferences, 183 "gen-clang-comment-html-named-character-references", 184 "Generate function to translate named character " 185 "references to UTF-8 sequences"), 186 clEnumValN(GenClangCommentCommandInfo, "gen-clang-comment-command-info", 187 "Generate command properties for commands that " 188 "are used in documentation comments"), 189 clEnumValN(GenClangCommentCommandList, "gen-clang-comment-command-list", 190 "Generate list of commands that are used in " 191 "documentation comments"), 192 clEnumValN(GenClangOpenCLBuiltins, "gen-clang-opencl-builtins", 193 "Generate OpenCL builtin declaration handlers"), 194 clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"), 195 clEnumValN(GenArmFP16, "gen-arm-fp16", "Generate arm_fp16.h for clang"), 196 clEnumValN(GenArmBF16, "gen-arm-bf16", "Generate arm_bf16.h for clang"), 197 clEnumValN(GenArmNeonSema, "gen-arm-neon-sema", 198 "Generate ARM NEON sema support for clang"), 199 clEnumValN(GenArmNeonTest, "gen-arm-neon-test", 200 "Generate ARM NEON tests for clang"), 201 clEnumValN(GenArmSveHeader, "gen-arm-sve-header", 202 "Generate arm_sve.h for clang"), 203 clEnumValN(GenArmSveBuiltins, "gen-arm-sve-builtins", 204 "Generate arm_sve_builtins.inc for clang"), 205 clEnumValN(GenArmSveBuiltinCG, "gen-arm-sve-builtin-codegen", 206 "Generate arm_sve_builtin_cg_map.inc for clang"), 207 clEnumValN(GenArmSveTypeFlags, "gen-arm-sve-typeflags", 208 "Generate arm_sve_typeflags.inc for clang"), 209 clEnumValN(GenArmSveRangeChecks, "gen-arm-sve-sema-rangechecks", 210 "Generate arm_sve_sema_rangechecks.inc for clang"), 211 clEnumValN(GenArmMveHeader, "gen-arm-mve-header", 212 "Generate arm_mve.h for clang"), 213 clEnumValN(GenArmMveBuiltinDef, "gen-arm-mve-builtin-def", 214 "Generate ARM MVE builtin definitions for clang"), 215 clEnumValN(GenArmMveBuiltinSema, "gen-arm-mve-builtin-sema", 216 "Generate ARM MVE builtin sema checks for clang"), 217 clEnumValN(GenArmMveBuiltinCG, "gen-arm-mve-builtin-codegen", 218 "Generate ARM MVE builtin code-generator for clang"), 219 clEnumValN(GenArmMveBuiltinAliases, "gen-arm-mve-builtin-aliases", 220 "Generate list of valid ARM MVE builtin aliases for clang"), 221 clEnumValN(GenArmCdeHeader, "gen-arm-cde-header", 222 "Generate arm_cde.h for clang"), 223 clEnumValN(GenArmCdeBuiltinDef, "gen-arm-cde-builtin-def", 224 "Generate ARM CDE builtin definitions for clang"), 225 clEnumValN(GenArmCdeBuiltinSema, "gen-arm-cde-builtin-sema", 226 "Generate ARM CDE builtin sema checks for clang"), 227 clEnumValN(GenArmCdeBuiltinCG, "gen-arm-cde-builtin-codegen", 228 "Generate ARM CDE builtin code-generator for clang"), 229 clEnumValN(GenArmCdeBuiltinAliases, "gen-arm-cde-builtin-aliases", 230 "Generate list of valid ARM CDE builtin aliases for clang"), 231 clEnumValN(GenAttrDocs, "gen-attr-docs", 232 "Generate attribute documentation"), 233 clEnumValN(GenDiagDocs, "gen-diag-docs", 234 "Generate diagnostic documentation"), 235 clEnumValN(GenOptDocs, "gen-opt-docs", "Generate option documentation"), 236 clEnumValN(GenDataCollectors, "gen-clang-data-collectors", 237 "Generate data collectors for AST nodes"), 238 clEnumValN(GenTestPragmaAttributeSupportedAttributes, 239 "gen-clang-test-pragma-attribute-supported-attributes", 240 "Generate a list of attributes supported by #pragma clang " 241 "attribute for testing purposes"))); 242 243 cl::opt<std::string> 244 ClangComponent("clang-component", 245 cl::desc("Only use warnings from specified component"), 246 cl::value_desc("component"), cl::Hidden); 247 248 bool ClangTableGenMain(raw_ostream &OS, RecordKeeper &Records) { 249 switch (Action) { 250 case PrintRecords: 251 OS << Records; // No argument, dump all contents 252 break; 253 case DumpJSON: 254 EmitJSON(Records, OS); 255 break; 256 case GenClangAttrClasses: 257 EmitClangAttrClass(Records, OS); 258 break; 259 case GenClangAttrParserStringSwitches: 260 EmitClangAttrParserStringSwitches(Records, OS); 261 break; 262 case GenClangAttrSubjectMatchRulesParserStringSwitches: 263 EmitClangAttrSubjectMatchRulesParserStringSwitches(Records, OS); 264 break; 265 case GenClangAttrImpl: 266 EmitClangAttrImpl(Records, OS); 267 break; 268 case GenClangAttrList: 269 EmitClangAttrList(Records, OS); 270 break; 271 case GenClangAttrSubjectMatchRuleList: 272 EmitClangAttrSubjectMatchRuleList(Records, OS); 273 break; 274 case GenClangAttrPCHRead: 275 EmitClangAttrPCHRead(Records, OS); 276 break; 277 case GenClangAttrPCHWrite: 278 EmitClangAttrPCHWrite(Records, OS); 279 break; 280 case GenClangAttrHasAttributeImpl: 281 EmitClangAttrHasAttrImpl(Records, OS); 282 break; 283 case GenClangAttrSpellingListIndex: 284 EmitClangAttrSpellingListIndex(Records, OS); 285 break; 286 case GenClangAttrASTVisitor: 287 EmitClangAttrASTVisitor(Records, OS); 288 break; 289 case GenClangAttrTemplateInstantiate: 290 EmitClangAttrTemplateInstantiate(Records, OS); 291 break; 292 case GenClangAttrParsedAttrList: 293 EmitClangAttrParsedAttrList(Records, OS); 294 break; 295 case GenClangAttrParsedAttrImpl: 296 EmitClangAttrParsedAttrImpl(Records, OS); 297 break; 298 case GenClangAttrParsedAttrKinds: 299 EmitClangAttrParsedAttrKinds(Records, OS); 300 break; 301 case GenClangAttrTextNodeDump: 302 EmitClangAttrTextNodeDump(Records, OS); 303 break; 304 case GenClangAttrNodeTraverse: 305 EmitClangAttrNodeTraverse(Records, OS); 306 break; 307 case GenClangDiagsDefs: 308 EmitClangDiagsDefs(Records, OS, ClangComponent); 309 break; 310 case GenClangDiagGroups: 311 EmitClangDiagGroups(Records, OS); 312 break; 313 case GenClangDiagsIndexName: 314 EmitClangDiagsIndexName(Records, OS); 315 break; 316 case GenClangCommentNodes: 317 EmitClangASTNodes(Records, OS, CommentNodeClassName, ""); 318 break; 319 case GenClangDeclNodes: 320 EmitClangASTNodes(Records, OS, DeclNodeClassName, "Decl"); 321 EmitClangDeclContext(Records, OS); 322 break; 323 case GenClangStmtNodes: 324 EmitClangASTNodes(Records, OS, StmtNodeClassName, ""); 325 break; 326 case GenClangTypeNodes: 327 EmitClangTypeNodes(Records, OS); 328 break; 329 case GenClangTypeReader: 330 EmitClangTypeReader(Records, OS); 331 break; 332 case GenClangTypeWriter: 333 EmitClangTypeWriter(Records, OS); 334 break; 335 case GenClangBasicReader: 336 EmitClangBasicReader(Records, OS); 337 break; 338 case GenClangBasicWriter: 339 EmitClangBasicWriter(Records, OS); 340 break; 341 case GenClangOpcodes: 342 EmitClangOpcodes(Records, OS); 343 break; 344 case GenClangSACheckers: 345 EmitClangSACheckers(Records, OS); 346 break; 347 case GenClangCommentHTMLTags: 348 EmitClangCommentHTMLTags(Records, OS); 349 break; 350 case GenClangCommentHTMLTagsProperties: 351 EmitClangCommentHTMLTagsProperties(Records, OS); 352 break; 353 case GenClangCommentHTMLNamedCharacterReferences: 354 EmitClangCommentHTMLNamedCharacterReferences(Records, OS); 355 break; 356 case GenClangCommentCommandInfo: 357 EmitClangCommentCommandInfo(Records, OS); 358 break; 359 case GenClangCommentCommandList: 360 EmitClangCommentCommandList(Records, OS); 361 break; 362 case GenClangOpenCLBuiltins: 363 EmitClangOpenCLBuiltins(Records, OS); 364 break; 365 case GenClangSyntaxNodeList: 366 EmitClangSyntaxNodeList(Records, OS); 367 break; 368 case GenClangSyntaxNodeClasses: 369 EmitClangSyntaxNodeClasses(Records, OS); 370 break; 371 case GenArmNeon: 372 EmitNeon(Records, OS); 373 break; 374 case GenArmFP16: 375 EmitFP16(Records, OS); 376 break; 377 case GenArmBF16: 378 EmitBF16(Records, OS); 379 break; 380 case GenArmNeonSema: 381 EmitNeonSema(Records, OS); 382 break; 383 case GenArmNeonTest: 384 EmitNeonTest(Records, OS); 385 break; 386 case GenArmMveHeader: 387 EmitMveHeader(Records, OS); 388 break; 389 case GenArmMveBuiltinDef: 390 EmitMveBuiltinDef(Records, OS); 391 break; 392 case GenArmMveBuiltinSema: 393 EmitMveBuiltinSema(Records, OS); 394 break; 395 case GenArmMveBuiltinCG: 396 EmitMveBuiltinCG(Records, OS); 397 break; 398 case GenArmMveBuiltinAliases: 399 EmitMveBuiltinAliases(Records, OS); 400 break; 401 case GenArmSveHeader: 402 EmitSveHeader(Records, OS); 403 break; 404 case GenArmSveBuiltins: 405 EmitSveBuiltins(Records, OS); 406 break; 407 case GenArmSveBuiltinCG: 408 EmitSveBuiltinCG(Records, OS); 409 break; 410 case GenArmSveTypeFlags: 411 EmitSveTypeFlags(Records, OS); 412 break; 413 case GenArmSveRangeChecks: 414 EmitSveRangeChecks(Records, OS); 415 break; 416 case GenArmCdeHeader: 417 EmitCdeHeader(Records, OS); 418 break; 419 case GenArmCdeBuiltinDef: 420 EmitCdeBuiltinDef(Records, OS); 421 break; 422 case GenArmCdeBuiltinSema: 423 EmitCdeBuiltinSema(Records, OS); 424 break; 425 case GenArmCdeBuiltinCG: 426 EmitCdeBuiltinCG(Records, OS); 427 break; 428 case GenArmCdeBuiltinAliases: 429 EmitCdeBuiltinAliases(Records, OS); 430 break; 431 case GenAttrDocs: 432 EmitClangAttrDocs(Records, OS); 433 break; 434 case GenDiagDocs: 435 EmitClangDiagDocs(Records, OS); 436 break; 437 case GenOptDocs: 438 EmitClangOptDocs(Records, OS); 439 break; 440 case GenDataCollectors: 441 EmitClangDataCollectors(Records, OS); 442 break; 443 case GenTestPragmaAttributeSupportedAttributes: 444 EmitTestPragmaAttributeSupportedAttributes(Records, OS); 445 break; 446 } 447 448 return false; 449 } 450 } 451 452 int main(int argc, char **argv) { 453 sys::PrintStackTraceOnErrorSignal(argv[0]); 454 PrettyStackTraceProgram X(argc, argv); 455 cl::ParseCommandLineOptions(argc, argv); 456 457 llvm_shutdown_obj Y; 458 459 return TableGenMain(argv[0], &ClangTableGenMain); 460 } 461 462 #ifdef __has_feature 463 #if __has_feature(address_sanitizer) 464 #include <sanitizer/lsan_interface.h> 465 // Disable LeakSanitizer for this binary as it has too many leaks that are not 466 // very interesting to fix. See compiler-rt/include/sanitizer/lsan_interface.h . 467 int __lsan_is_turned_off() { return 1; } 468 #endif // __has_feature(address_sanitizer) 469 #endif // defined(__has_feature) 470