LLVM 19.0.0git
DirectiveEmitter.h
Go to the documentation of this file.
1#ifndef LLVM_TABLEGEN_DIRECTIVEEMITTER_H
2#define LLVM_TABLEGEN_DIRECTIVEEMITTER_H
3
8#include <algorithm>
9#include <string>
10#include <vector>
11
12namespace llvm {
13
14// Wrapper class that contains DirectiveLanguage's information defined in
15// DirectiveBase.td and provides helper methods for accessing it.
17public:
18 explicit DirectiveLanguage(const llvm::RecordKeeper &Records)
19 : Records(Records) {
20 const auto &DirectiveLanguages = getDirectiveLanguages();
21 Def = DirectiveLanguages[0];
22 }
23
24 StringRef getName() const { return Def->getValueAsString("name"); }
25
27 return Def->getValueAsString("cppNamespace");
28 }
29
31 return Def->getValueAsString("directivePrefix");
32 }
33
35 return Def->getValueAsString("clausePrefix");
36 }
37
39 return Def->getValueAsString("clauseEnumSetClass");
40 }
41
43 return Def->getValueAsString("flangClauseBaseClass");
44 }
45
47 return Def->getValueAsBit("makeEnumAvailableInNamespace");
48 }
49
51 return Def->getValueAsBit("enableBitmaskEnumInNamespace");
52 }
53
54 std::vector<Record *> getAssociations() const {
55 return Records.getAllDerivedDefinitions("Association");
56 }
57
58 std::vector<Record *> getDirectives() const {
59 return Records.getAllDerivedDefinitions("Directive");
60 }
61
62 std::vector<Record *> getClauses() const {
63 return Records.getAllDerivedDefinitions("Clause");
64 }
65
66 bool HasValidityErrors() const;
67
68private:
69 const llvm::Record *Def;
70 const llvm::RecordKeeper &Records;
71
72 std::vector<Record *> getDirectiveLanguages() const {
73 return Records.getAllDerivedDefinitions("DirectiveLanguage");
74 }
75};
76
77// Base record class used for Directive and Clause class defined in
78// DirectiveBase.td.
80public:
81 explicit BaseRecord(const llvm::Record *Def) : Def(Def) {}
82
83 StringRef getName() const { return Def->getValueAsString("name"); }
84
86 return Def->getValueAsString("alternativeName");
87 }
88
89 // Returns the name of the directive formatted for output. Whitespace are
90 // replaced with underscores.
91 std::string getFormattedName() {
93 std::string N = Name.str();
94 std::replace(N.begin(), N.end(), ' ', '_');
95 return N;
96 }
97
98 bool isDefault() const { return Def->getValueAsBit("isDefault"); }
99
100 // Returns the record name.
101 StringRef getRecordName() const { return Def->getName(); }
102
103protected:
105};
106
107// Wrapper class that contains a Directive's information defined in
108// DirectiveBase.td and provides helper methods for accessing it.
109class Directive : public BaseRecord {
110public:
111 explicit Directive(const llvm::Record *Def) : BaseRecord(Def) {}
112
113 std::vector<Record *> getAllowedClauses() const {
114 return Def->getValueAsListOfDefs("allowedClauses");
115 }
116
117 std::vector<Record *> getAllowedOnceClauses() const {
118 return Def->getValueAsListOfDefs("allowedOnceClauses");
119 }
120
121 std::vector<Record *> getAllowedExclusiveClauses() const {
122 return Def->getValueAsListOfDefs("allowedExclusiveClauses");
123 }
124
125 std::vector<Record *> getRequiredClauses() const {
126 return Def->getValueAsListOfDefs("requiredClauses");
127 }
128
129 std::vector<Record *> getLeafConstructs() const {
130 return Def->getValueAsListOfDefs("leafConstructs");
131 }
132
133 Record *getAssociation() const { return Def->getValueAsDef("association"); }
134};
135
136// Wrapper class that contains Clause's information defined in DirectiveBase.td
137// and provides helper methods for accessing it.
138class Clause : public BaseRecord {
139public:
140 explicit Clause(const llvm::Record *Def) : BaseRecord(Def) {}
141
142 // Optional field.
144 return Def->getValueAsString("clangClass");
145 }
146
147 // Optional field.
149 return Def->getValueAsString("flangClass");
150 }
151
152 // Get the formatted name for Flang parser class. The generic formatted class
153 // name is constructed from the name were the first letter of each word is
154 // captitalized and the underscores are removed.
155 // ex: async -> Async
156 // num_threads -> NumThreads
159 std::string N = Name.str();
160 bool Cap = true;
161 std::transform(N.begin(), N.end(), N.begin(), [&Cap](unsigned char C) {
162 if (Cap == true) {
163 C = llvm::toUpper(C);
164 Cap = false;
165 } else if (C == '_') {
166 Cap = true;
167 }
168 return C;
169 });
170 llvm::erase(N, '_');
171 return N;
172 }
173
174 // Optional field.
176 return Def->getValueAsString("enumClauseValue");
177 }
178
179 std::vector<Record *> getClauseVals() const {
180 return Def->getValueAsListOfDefs("allowedClauseValues");
181 }
182
183 bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }
184
185 bool isValueList() const { return Def->getValueAsBit("isValueList"); }
186
188 return Def->getValueAsString("defaultValue");
189 }
190
191 bool isImplicit() const { return Def->getValueAsBit("isImplicit"); }
192
193 std::vector<StringRef> getAliases() const {
194 return Def->getValueAsListOfStrings("aliases");
195 }
196
197 StringRef getPrefix() const { return Def->getValueAsString("prefix"); }
198
199 bool isPrefixOptional() const {
200 return Def->getValueAsBit("isPrefixOptional");
201 }
202};
203
204// Wrapper class that contains VersionedClause's information defined in
205// DirectiveBase.td and provides helper methods for accessing it.
207public:
208 explicit VersionedClause(const llvm::Record *Def) : Def(Def) {}
209
210 // Return the specific clause record wrapped in the Clause class.
211 Clause getClause() const { return Clause{Def->getValueAsDef("clause")}; }
212
213 int64_t getMinVersion() const { return Def->getValueAsInt("minVersion"); }
214
215 int64_t getMaxVersion() const { return Def->getValueAsInt("maxVersion"); }
216
217private:
218 const llvm::Record *Def;
219};
220
221class ClauseVal : public BaseRecord {
222public:
223 explicit ClauseVal(const llvm::Record *Def) : BaseRecord(Def) {}
224
225 int getValue() const { return Def->getValueAsInt("value"); }
226
227 bool isUserVisible() const { return Def->getValueAsBit("isUserValue"); }
228};
229
230} // namespace llvm
231
232#endif
std::string Name
if(VerifyEach)
This file contains some templates that are useful if you are working with the STL at all.
This file contains some functions that are useful when dealing with strings.
std::string getFormattedName()
StringRef getRecordName() const
StringRef getName() const
bool isDefault() const
StringRef getAlternativeName() const
BaseRecord(const llvm::Record *Def)
const llvm::Record * Def
ClauseVal(const llvm::Record *Def)
int getValue() const
bool isUserVisible() const
StringRef getClangClass() const
bool isImplicit() const
StringRef getDefaultValue() const
bool isValueOptional() const
bool isValueList() const
StringRef getFlangClass() const
std::vector< StringRef > getAliases() const
std::vector< Record * > getClauseVals() const
StringRef getEnumName() const
bool isPrefixOptional() const
std::string getFormattedParserClassName()
Clause(const llvm::Record *Def)
StringRef getPrefix() const
bool hasMakeEnumAvailableInNamespace() const
bool HasValidityErrors() const
std::vector< Record * > getAssociations() const
StringRef getClausePrefix() const
std::vector< Record * > getDirectives() const
StringRef getClauseEnumSetClass() const
std::vector< Record * > getClauses() const
StringRef getName() const
DirectiveLanguage(const llvm::RecordKeeper &Records)
StringRef getDirectivePrefix() const
bool hasEnableBitmaskEnumInNamespace() const
StringRef getCppNamespace() const
StringRef getFlangClauseBaseClass() const
Record * getAssociation() const
std::vector< Record * > getAllowedOnceClauses() const
std::vector< Record * > getLeafConstructs() const
Directive(const llvm::Record *Def)
std::vector< Record * > getRequiredClauses() const
std::vector< Record * > getAllowedClauses() const
std::vector< Record * > getAllowedExclusiveClauses() const
std::vector< Record * > getAllDerivedDefinitions(StringRef ClassName) const
Get all the concrete records that inherit from the one specified class.
Definition: Record.cpp:3224
bool getValueAsBit(StringRef FieldName) const
This method looks up the specified field and returns its value as a bit, throwing an exception if the...
Definition: Record.cpp:3081
Record * getValueAsDef(StringRef FieldName) const
This method looks up the specified field and returns its value as a Record, throwing an exception if ...
Definition: Record.cpp:3054
StringRef getName() const
Definition: Record.h:1711
std::vector< Record * > getValueAsListOfDefs(StringRef FieldName) const
This method looks up the specified field and returns its value as a vector of records,...
Definition: Record.cpp:2995
StringRef getValueAsString(StringRef FieldName) const
This method looks up the specified field and returns its value as a string, throwing an exception if ...
Definition: Record.cpp:2946
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
int64_t getMinVersion() const
Clause getClause() const
int64_t getMaxVersion() const
VersionedClause(const llvm::Record *Def)
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
Definition: STLExtras.h:2068
#define N