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