brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.9 KiB · 392423f Raw
395 lines · plain
1// RUN: llvm-tblgen -gen-directive-decl -I %p/../../include %s | FileCheck -match-full-lines %s2// RUN: llvm-tblgen -gen-directive-impl -I %p/../../include %s | FileCheck -match-full-lines %s -check-prefix=IMPL3 4include "llvm/Frontend/Directive/DirectiveBase.td"5 6def TestDirectiveLanguage : DirectiveLanguage {7  let name = "Tdl";8 9  let cppNamespace = "tdl";10  let directivePrefix = "TDLD_";11  let clausePrefix = "TDLC_";12  let includeHeader = "tdl.h.inc";13  let flangClauseBaseClass = "TdlClause";14}15 16def TDLC_ClauseA : Clause<[Spelling<"clausea">]> {17  let isImplicit = 1;18}19def TDLC_ClauseB : Clause<[Spelling<"clauseb">]> {20  let isDefault = 1;21  let flangClass = "IntExpr";22  let isValueList = 1;23}24def TDLC_ClauseC : Clause<[Spelling<"clausec">]> {25  let clangClass = "ClauseC";26  let flangClass = "Name";27  let defaultValue = "*";28  let isValueOptional = 1;29}30def TDLC_ClauseD : Clause<[Spelling<"claused">]> {31  let clangClass = "ClauseD";32  let isImplicit = 1;33}34 35def TDL_DirA : Directive<[Spelling<"dira">]> {36  let allowedClauses = [37    VersionedClause<TDLC_ClauseA, 2, 4>,38    VersionedClause<TDLC_ClauseB, 2>39  ];40  let isDefault = 1;41  let association = AS_Block;42  let category = CA_Declarative;43}44 45// CHECK:       #ifndef LLVM_Tdl_INC46// CHECK-NEXT:  #define LLVM_Tdl_INC47// CHECK-EMPTY:48// CHECK-NEXT:  #include "llvm/ADT/ArrayRef.h"49// CHECK-NEXT:  #include "llvm/ADT/Sequence.h"50// CHECK-NEXT:  #include "llvm/ADT/StringRef.h"51// CHECK-NEXT:  #include "llvm/Frontend/Directive/Spelling.h"52// CHECK-NEXT:  #include "llvm/Support/Compiler.h"53// CHECK-NEXT:  #include <cstddef>54// CHECK-NEXT:  #include <utility>55// CHECK-EMPTY:56// CHECK-NEXT:  namespace llvm {57// CHECK-EMPTY:58// CHECK-NEXT:  namespace tdl {59// CHECK-EMPTY:60// CHECK-NEXT:  enum class Association {61// CHECK-NEXT:    Block,62// CHECK-NEXT:    First_ = Block,63// CHECK-NEXT:    Declaration,64// CHECK-NEXT:    Delimited,65// CHECK-NEXT:    LoopNest,66// CHECK-NEXT:    LoopSeq,67// CHECK-NEXT:    None,68// CHECK-NEXT:    Separating,69// CHECK-NEXT:    Last_ = Separating,70// CHECK-NEXT:  };71// CHECK-EMPTY:72// CHECK-NEXT:  static constexpr std::size_t Association_enumSize = 7;73// CHECK-EMPTY:74// CHECK-NEXT:  enum class Category {75// CHECK-NEXT:    Declarative,76// CHECK-NEXT:    First_ = Declarative,77// CHECK-NEXT:    Executable,78// CHECK-NEXT:    Informational,79// CHECK-NEXT:    Meta,80// CHECK-NEXT:    Subsidiary,81// CHECK-NEXT:    Utility,82// CHECK-NEXT:    Last_ = Utility,83// CHECK-NEXT:  };84// CHECK-EMPTY:85// CHECK-NEXT:  static constexpr std::size_t Category_enumSize = 6;86// CHECK-EMPTY:87// CHECK-NEXT:  enum class SourceLanguage : uint32_t {88// CHECK-NEXT:    C = 1U,89// CHECK-NEXT:    Fortran = 2U,90// CHECK-NEXT:    LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Fortran)91// CHECK-NEXT:  };92// CHECK-EMPTY:93// CHECK-NEXT:  static constexpr std::size_t SourceLanguage_enumSize = 2;94// CHECK-EMPTY:95// CHECK-NEXT:  enum class Directive {96// CHECK-NEXT:    TDLD_dira,97// CHECK-NEXT:    First_ = TDLD_dira,98// CHECK-NEXT:    Last_ = TDLD_dira,99// CHECK-NEXT:  };100// CHECK-EMPTY:101// CHECK-NEXT:  static constexpr std::size_t Directive_enumSize = 1;102// CHECK-EMPTY:103// CHECK-NEXT:  enum class Clause {104// CHECK-NEXT:    TDLC_clausea,105// CHECK-NEXT:    First_ = TDLC_clausea,106// CHECK-NEXT:    TDLC_clauseb,107// CHECK-NEXT:    TDLC_clausec,108// CHECK-NEXT:    TDLC_claused,109// CHECK-NEXT:    Last_ = TDLC_claused,110// CHECK-NEXT:  };111// CHECK-EMPTY:112// CHECK-NEXT:  static constexpr std::size_t Clause_enumSize = 4;113// CHECK-EMPTY:114// CHECK-NEXT:  // Enumeration helper functions115// CHECK-NEXT:  LLVM_ABI std::pair<Directive, directive::VersionRange> getTdlDirectiveKindAndVersions(StringRef Str);116// CHECK-NEXT:  inline Directive getTdlDirectiveKind(StringRef Str) {117// CHECK-NEXT:    return getTdlDirectiveKindAndVersions(Str).first;118// CHECK-NEXT:  }119// CHECK-EMPTY:120// CHECK-NEXT:  LLVM_ABI StringRef getTdlDirectiveName(Directive D, unsigned Ver = 0);121// CHECK-EMPTY:122// CHECK-NEXT:  LLVM_ABI std::pair<Clause, directive::VersionRange> getTdlClauseKindAndVersions(StringRef Str);123// CHECK-EMPTY:124// CHECK-NEXT:  inline Clause getTdlClauseKind(StringRef Str) {125// CHECK-NEXT:    return getTdlClauseKindAndVersions(Str).first;126// CHECK-NEXT:  }127// CHECK-EMPTY:128// CHECK-NEXT:  LLVM_ABI StringRef getTdlClauseName(Clause C, unsigned Ver = 0);129// CHECK-EMPTY:130// CHECK-NEXT:  /// Return true if \p C is a valid clause for \p D in version \p Version.131// CHECK-NEXT:  LLVM_ABI bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);132// CHECK-EMPTY:133// CHECK-NEXT:  constexpr std::size_t getMaxLeafCount() { return 0; }134// CHECK-NEXT:  LLVM_ABI Association getDirectiveAssociation(Directive D);135// CHECK-NEXT:  LLVM_ABI Category getDirectiveCategory(Directive D);136// CHECK-NEXT:  LLVM_ABI SourceLanguage getDirectiveLanguages(Directive D);137// CHECK-EMPTY:138// CHECK-NEXT:  } // namespace tdl139// CHECK-EMPTY:140// CHECK-NEXT:  template <> struct enum_iteration_traits<tdl::Association> {141// CHECK-NEXT:    static constexpr bool is_iterable = true;142// CHECK-NEXT:  };143// CHECK-EMPTY:144// CHECK-NEXT:  template <> struct enum_iteration_traits<tdl::Category> {145// CHECK-NEXT:    static constexpr bool is_iterable = true;146// CHECK-NEXT:  };147// CHECK-EMPTY:148// CHECK-NEXT:  template <> struct enum_iteration_traits<tdl::Directive> {149// CHECK-NEXT:    static constexpr bool is_iterable = true;150// CHECK-NEXT:  };151// CHECK-EMPTY:152// CHECK-NEXT:  template <> struct enum_iteration_traits<tdl::Clause> {153// CHECK-NEXT:    static constexpr bool is_iterable = true;154// CHECK-NEXT:  };155// CHECK-EMPTY:156// CHECK-NEXT:  } // namespace llvm157// CHECK-EMPTY:158// CHECK-NEXT:  #endif // LLVM_Tdl_INC159 160// IMPL:      #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS161// IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS162// IMPL-EMPTY:163// IMPL-NEXT: namespace llvm::tdl {164// IMPL-EMPTY:165// IMPL-NEXT:   // Sets for dira166// IMPL-EMPTY:167// IMPL-NEXT:   static  allowedClauses_TDLD_dira {168// IMPL-NEXT:     Clause::TDLC_clausea,169// IMPL-NEXT:     Clause::TDLC_clauseb,170// IMPL-NEXT:   };171// IMPL-EMPTY:172// IMPL-NEXT:   static  allowedOnceClauses_TDLD_dira {173// IMPL-NEXT:   };174// IMPL-EMPTY:175// IMPL-NEXT:   static  allowedExclusiveClauses_TDLD_dira {176// IMPL-NEXT:   };177// IMPL-EMPTY:178// IMPL-NEXT:   static  requiredClauses_TDLD_dira {179// IMPL-NEXT:   };180// IMPL-EMPTY:181// IMPL-NEXT: } // namespace llvm::tdl182// IMPL-EMPTY:183// IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS184// IMPL-EMPTY:185// IMPL-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP186// IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP187// IMPL-EMPTY:188// IMPL-NEXT: {189// IMPL-NEXT:   {llvm::tdl::Directive::TDLD_dira,190// IMPL-NEXT:     {191// IMPL-NEXT:       llvm::tdl::allowedClauses_TDLD_dira,192// IMPL-NEXT:       llvm::tdl::allowedOnceClauses_TDLD_dira,193// IMPL-NEXT:       llvm::tdl::allowedExclusiveClauses_TDLD_dira,194// IMPL-NEXT:       llvm::tdl::requiredClauses_TDLD_dira,195// IMPL-NEXT:     }196// IMPL-NEXT:   },197// IMPL-NEXT: }198// IMPL-EMPTY:199// IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP200// IMPL-EMPTY:201// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES202// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES203// IMPL-EMPTY:204// IMPL-NEXT:  EMPTY_CLASS(Clausea);205// IMPL-NEXT:  WRAPPER_CLASS(Clauseb, std::list<IntExpr>);206// IMPL-NEXT:  WRAPPER_CLASS(Clausec, std::optional<Name>);207// IMPL-NEXT:  EMPTY_CLASS(Claused);208// IMPL-EMPTY:209// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES210// IMPL-EMPTY:211// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST212// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST213// IMPL-EMPTY:214// IMPL-NEXT:  Clausea215// IMPL-NEXT:  , Clauseb216// IMPL-NEXT:  , Clausec217// IMPL-NEXT:  , Claused218// IMPL-EMPTY:219// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST220// IMPL-EMPTY:221// IMPL-NEXT:  #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES222// IMPL-NEXT:  #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES223// IMPL-EMPTY:224// IMPL-NEXT:  NODE(TdlClause, Clausea)225// IMPL-NEXT:  NODE(TdlClause, Clauseb)226// IMPL-NEXT:  NODE(TdlClause, Clausec)227// IMPL-NEXT:  NODE(TdlClause, Claused)228// IMPL-EMPTY:229// IMPL-NEXT:  #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES230// IMPL-EMPTY:231// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_UNPARSE232// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_UNPARSE233// IMPL-EMPTY:234// IMPL-NEXT:  void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }235// IMPL-NEXT:  void Unparse(const TdlClause::Clauseb &x) {236// IMPL-NEXT:    Word("CLAUSEB");237// IMPL-NEXT:    Put("(");238// IMPL-NEXT:    Walk(x.v, ",");239// IMPL-NEXT:    Put(")");240// IMPL-NEXT:  }241// IMPL-NEXT:  void Unparse(const TdlClause::Clausec &x) {242// IMPL-NEXT:  Word("CLAUSEC");243// IMPL-NEXT:    Put("(");244// IMPL-NEXT:    if (x.v.has_value())245// IMPL-NEXT:    Walk(x.v);246// IMPL-NEXT:    else247// IMPL-NEXT:    Put("*");248// IMPL-NEXT:    Put(")");249// IMPL-NEXT:  }250// IMPL-NEXT:  void Before(const TdlClause::Claused &) { Word("CLAUSED"); }251// IMPL-EMPTY:252// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_UNPARSE253 254// IMPL:       #ifdef GEN_CLANG_CLAUSE_CLASS255// IMPL-NEXT:  #undef GEN_CLANG_CLAUSE_CLASS256// IMPL-EMPTY:257// IMPL-NEXT:  #ifndef CLAUSE258// IMPL-NEXT:  #define CLAUSE(Enum, Str, Implicit)259// IMPL-NEXT:  #endif260// IMPL-NEXT:  #ifndef CLAUSE_CLASS261// IMPL-NEXT:  #define CLAUSE_CLASS(Enum, Str, Class)262// IMPL-NEXT:  #endif263// IMPL-NEXT:  #ifndef CLAUSE_NO_CLASS264// IMPL-NEXT:  #define CLAUSE_NO_CLASS(Enum, Str)265// IMPL-NEXT:  #endif266// IMPL-EMPTY:267// IMPL-NEXT:  #define __CLAUSE(Name, Class)                      \268// IMPL-NEXT:    CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \269// IMPL-NEXT:    CLAUSE_CLASS(TDLC_##Name, #Name, Class)270// IMPL-NEXT:  #define __CLAUSE_NO_CLASS(Name)                    \271// IMPL-NEXT:    CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \272// IMPL-NEXT:    CLAUSE_NO_CLASS(TDLC_##Name, #Name)273// IMPL-NEXT:  #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class)  \274// IMPL-NEXT:    CLAUSE(TDLC_##Name, Str, /* Implicit */ true)    \275// IMPL-NEXT:  CLAUSE_CLASS(TDLC_##Name, Str, Class)276// IMPL-NEXT:  #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str)      \277// IMPL-NEXT:    CLAUSE(TDLC_##Name, Str, /* Implicit */ true)    \278// IMPL-NEXT:  CLAUSE_NO_CLASS(TDLC_##Name, Str)279// IMPL-EMPTY:280// IMPL-NEXT:  __IMPLICIT_CLAUSE_NO_CLASS(clausea, "clausea")281// IMPL-NEXT:  __CLAUSE_NO_CLASS(clauseb)282// IMPL-NEXT:  __CLAUSE(clausec, ClauseC)283// IMPL-NEXT:  __IMPLICIT_CLAUSE_CLASS(claused, "claused", ClauseD)284// IMPL-EMPTY:285// IMPL-NEXT:  #undef __IMPLICIT_CLAUSE_NO_CLASS286// IMPL-NEXT:  #undef __IMPLICIT_CLAUSE_CLASS287// IMPL-NEXT:  #undef __CLAUSE_NO_CLASS288// IMPL-NEXT:  #undef __CLAUSE289// IMPL-NEXT:  #undef CLAUSE_NO_CLASS290// IMPL-NEXT:  #undef CLAUSE_CLASS291// IMPL-NEXT:  #undef CLAUSE292// IMPL-EMPTY:293// IMPL-NEXT:  #endif // GEN_CLANG_CLAUSE_CLASS294 295// IMPL:       #ifdef GEN_DIRECTIVES_IMPL296// IMPL-NEXT:  #undef GEN_DIRECTIVES_IMPL297// IMPL-EMPTY:298// IMPL-NEXT:  #include "llvm/Frontend/Directive/Spelling.h"299// IMPL-NEXT:  #include "llvm/Support/ErrorHandling.h"300// IMPL-NEXT:  #include <utility>301// IMPL-EMPTY:302// IMPL-NEXT: std::pair<llvm::tdl::Directive, llvm::directive::VersionRange> llvm::tdl::getTdlDirectiveKindAndVersions(llvm::StringRef Str) {303// IMPL-NEXT:   directive::VersionRange All; // Default-initialized to "all versions"304// IMPL-NEXT:   return StringSwitch<std::pair<Directive, directive::VersionRange>>(Str)305// IMPL-NEXT:     .Case("dira", {TDLD_dira, All})306// IMPL-NEXT:     .Default({TDLD_dira, All});307// IMPL-NEXT: }308// IMPL-EMPTY:309// IMPL-NEXT:  llvm::StringRef llvm::tdl::getTdlDirectiveName(llvm::tdl::Directive Kind, unsigned Version) {310// IMPL-NEXT:    switch (Kind) {311// IMPL-NEXT:      case TDLD_dira:312// IMPL-NEXT:        return "dira";313// IMPL-NEXT:    }314// IMPL-NEXT:    llvm_unreachable("Invalid Tdl Directive kind");315// IMPL-NEXT:  }316// IMPL-EMPTY:317// IMPL-NEXT: std::pair<llvm::tdl::Clause, llvm::directive::VersionRange> llvm::tdl::getTdlClauseKindAndVersions(llvm::StringRef Str) {318// IMPL-NEXT:   directive::VersionRange All; // Default-initialized to "all versions"319// IMPL-NEXT:   return StringSwitch<std::pair<Clause, directive::VersionRange>>(Str)320// IMPL-NEXT:     .Case("clausea", {TDLC_clauseb, All})321// IMPL-NEXT:     .Case("clauseb", {TDLC_clauseb, All})322// IMPL-NEXT:     .Case("clausec", {TDLC_clausec, All})323// IMPL-NEXT:     .Case("claused", {TDLC_clauseb, All})324// IMPL-NEXT:     .Default({TDLC_clauseb, All});325// IMPL-NEXT: }326// IMPL-EMPTY:327// IMPL-NEXT:  llvm::StringRef llvm::tdl::getTdlClauseName(llvm::tdl::Clause Kind, unsigned Version) {328// IMPL-NEXT:    switch (Kind) {329// IMPL-NEXT:      case TDLC_clausea:330// IMPL-NEXT:        return "clausea";331// IMPL-NEXT:      case TDLC_clauseb:332// IMPL-NEXT:        return "clauseb";333// IMPL-NEXT:      case TDLC_clausec:334// IMPL-NEXT:        return "clausec";335// IMPL-NEXT:      case TDLC_claused:336// IMPL-NEXT:        return "claused";337// IMPL-NEXT:    }338// IMPL-NEXT:    llvm_unreachable("Invalid Tdl Clause kind");339// IMPL-NEXT:  }340// IMPL-EMPTY:341// IMPL-NEXT:  bool llvm::tdl::isAllowedClauseForDirective(llvm::tdl::Directive D, llvm::tdl::Clause C, unsigned Version) {342// IMPL-NEXT:    assert(unsigned(D) <= Directive_enumSize);343// IMPL-NEXT:    assert(unsigned(C) <= Clause_enumSize);344// IMPL-NEXT:    switch (D) {345// IMPL-NEXT:      case TDLD_dira:346// IMPL-NEXT:        switch (C) {347// IMPL-NEXT:          case TDLC_clausea:348// IMPL-NEXT:            return 2 <= Version && 4 >= Version;349// IMPL-NEXT:          case TDLC_clauseb:350// IMPL-NEXT:            return 2 <= Version && 2147483647 >= Version;351// IMPL-NEXT:          default:352// IMPL-NEXT:            return false;353// IMPL-NEXT:        }354// IMPL-NEXT:        break;355// IMPL-NEXT:    }356// IMPL-NEXT:    llvm_unreachable("Invalid Tdl Directive kind");357// IMPL-NEXT:  }358// IMPL-EMPTY:359// IMPL-NEXT:  llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive Dir) {360// IMPL-NEXT:    switch (Dir) {361// IMPL-NEXT:    case TDLD_dira:362// IMPL-NEXT:      return Association::Block;363// IMPL-NEXT:    } // switch (Dir)364// IMPL-NEXT:    llvm_unreachable("Unexpected directive");365// IMPL-NEXT:  }366// IMPL-EMPTY:367// IMPL-NEXT:  llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive Dir) {368// IMPL-NEXT:    switch (Dir) {369// IMPL-NEXT:    case TDLD_dira:370// IMPL-NEXT:      return Category::Declarative;371// IMPL-NEXT:    } // switch (Dir)372// IMPL-NEXT:    llvm_unreachable("Unexpected directive");373// IMPL-NEXT:  }374// IMPL-EMPTY:375// IMPL-NEXT:  llvm::tdl::SourceLanguage llvm::tdl::getDirectiveLanguages(llvm::tdl::Directive D) {376// IMPL-NEXT:    switch (D) {377// IMPL-NEXT:    case TDLD_dira:378// IMPL-NEXT:      return SourceLanguage::C | SourceLanguage::Fortran;379// IMPL-NEXT:    } // switch(D)380// IMPL-NEXT:    llvm_unreachable("Unexpected directive");381// IMPL-NEXT:  }382// IMPL-EMPTY:383// IMPL-NEXT:  static_assert(sizeof(llvm::tdl::Directive) == sizeof(int));384// IMPL-NEXT:  {{.*}} static const llvm::tdl::Directive LeafConstructTable[][2] = {385// IMPL-NEXT:    {llvm::tdl::TDLD_dira, static_cast<llvm::tdl::Directive>(0),},386// IMPL-NEXT:  };387// IMPL-EMPTY:388// IMPL-NEXT:  {{.*}} static auto LeafConstructTableEndDirective = LeafConstructTable + 1;389// IMPL-EMPTY:390// IMPL-NEXT:  {{.*}} static const int LeafConstructTableOrdering[] = {391// IMPL-NEXT:    0,392// IMPL-NEXT:  };393// IMPL-EMPTY:394// IMPL-NEXT:  #endif // GEN_DIRECTIVES_IMPL395