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