1 #ifndef LLVM_TABLEGEN_DIRECTIVEEMITTER_H
2 #define LLVM_TABLEGEN_DIRECTIVEEMITTER_H
4 #include "llvm/ADT/StringExtras.h"
5 #include "llvm/TableGen/Record.h"
9 // Wrapper class that contains DirectiveLanguage's information defined in
10 // DirectiveBase.td and provides helper methods for accessing it.
11 class DirectiveLanguage {
13 explicit DirectiveLanguage(const llvm::RecordKeeper &Records)
15 const auto &DirectiveLanguages = getDirectiveLanguages();
16 Def = DirectiveLanguages[0];
19 StringRef getName() const { return Def->getValueAsString("name"); }
21 StringRef getCppNamespace() const {
22 return Def->getValueAsString("cppNamespace");
25 StringRef getDirectivePrefix() const {
26 return Def->getValueAsString("directivePrefix");
29 StringRef getClausePrefix() const {
30 return Def->getValueAsString("clausePrefix");
33 StringRef getClauseEnumSetClass() const {
34 return Def->getValueAsString("clauseEnumSetClass");
37 StringRef getFlangClauseBaseClass() const {
38 return Def->getValueAsString("flangClauseBaseClass");
41 bool hasMakeEnumAvailableInNamespace() const {
42 return Def->getValueAsBit("makeEnumAvailableInNamespace");
45 bool hasEnableBitmaskEnumInNamespace() const {
46 return Def->getValueAsBit("enableBitmaskEnumInNamespace");
49 std::vector<Record *> getDirectives() const {
50 return Records.getAllDerivedDefinitions("Directive");
53 std::vector<Record *> getClauses() const {
54 return Records.getAllDerivedDefinitions("Clause");
57 bool HasValidityErrors() const;
60 const llvm::Record *Def;
61 const llvm::RecordKeeper &Records;
63 std::vector<Record *> getDirectiveLanguages() const {
64 return Records.getAllDerivedDefinitions("DirectiveLanguage");
68 // Base record class used for Directive and Clause class defined in
72 explicit BaseRecord(const llvm::Record *Def) : Def(Def) {}
74 StringRef getName() const { return Def->getValueAsString("name"); }
76 StringRef getAlternativeName() const {
77 return Def->getValueAsString("alternativeName");
80 // Returns the name of the directive formatted for output. Whitespace are
81 // replaced with underscores.
82 std::string getFormattedName() {
83 StringRef Name = Def->getValueAsString("name");
84 std::string N = Name.str();
85 std::replace(N.begin(), N.end(), ' ', '_');
89 bool isDefault() const { return Def->getValueAsBit("isDefault"); }
91 // Returns the record name.
92 StringRef getRecordName() const { return Def->getName(); }
95 const llvm::Record *Def;
98 // Wrapper class that contains a Directive's information defined in
99 // DirectiveBase.td and provides helper methods for accessing it.
100 class Directive : public BaseRecord {
102 explicit Directive(const llvm::Record *Def) : BaseRecord(Def) {}
104 std::vector<Record *> getAllowedClauses() const {
105 return Def->getValueAsListOfDefs("allowedClauses");
108 std::vector<Record *> getAllowedOnceClauses() const {
109 return Def->getValueAsListOfDefs("allowedOnceClauses");
112 std::vector<Record *> getAllowedExclusiveClauses() const {
113 return Def->getValueAsListOfDefs("allowedExclusiveClauses");
116 std::vector<Record *> getRequiredClauses() const {
117 return Def->getValueAsListOfDefs("requiredClauses");
121 // Wrapper class that contains Clause's information defined in DirectiveBase.td
122 // and provides helper methods for accessing it.
123 class Clause : public BaseRecord {
125 explicit Clause(const llvm::Record *Def) : BaseRecord(Def) {}
128 StringRef getClangClass() const {
129 return Def->getValueAsString("clangClass");
133 StringRef getFlangClass() const {
134 return Def->getValueAsString("flangClass");
137 // Get the formatted name for Flang parser class. The generic formatted class
138 // name is constructed from the name were the first letter of each word is
139 // captitalized and the underscores are removed.
140 // ex: async -> Async
141 // num_threads -> NumThreads
142 std::string getFormattedParserClassName() {
143 StringRef Name = Def->getValueAsString("name");
144 std::string N = Name.str();
146 std::transform(N.begin(), N.end(), N.begin(), [&Cap](unsigned char C) {
148 C = llvm::toUpper(C);
150 } else if (C == '_') {
155 llvm::erase_value(N, '_');
160 StringRef getEnumName() const {
161 return Def->getValueAsString("enumClauseValue");
164 std::vector<Record *> getClauseVals() const {
165 return Def->getValueAsListOfDefs("allowedClauseValues");
168 bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }
170 bool isValueList() const { return Def->getValueAsBit("isValueList"); }
172 StringRef getDefaultValue() const {
173 return Def->getValueAsString("defaultValue");
176 bool isImplicit() const { return Def->getValueAsBit("isImplicit"); }
179 // Wrapper class that contains VersionedClause's information defined in
180 // DirectiveBase.td and provides helper methods for accessing it.
181 class VersionedClause {
183 explicit VersionedClause(const llvm::Record *Def) : Def(Def) {}
185 // Return the specific clause record wrapped in the Clause class.
186 Clause getClause() const { return Clause{Def->getValueAsDef("clause")}; }
188 int64_t getMinVersion() const { return Def->getValueAsInt("minVersion"); }
190 int64_t getMaxVersion() const { return Def->getValueAsInt("maxVersion"); }
193 const llvm::Record *Def;
196 class ClauseVal : public BaseRecord {
198 explicit ClauseVal(const llvm::Record *Def) : BaseRecord(Def) {}
200 int getValue() const { return Def->getValueAsInt("value"); }
202 bool isUserVisible() const { return Def->getValueAsBit("isUserValue"); }