blob: 57fd2bf286a226bbd35de8d5a440230e815f3ac7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
#pragma once
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#ifndef LLVM_TABLEGEN_DIRECTIVEEMITTER_H
#define LLVM_TABLEGEN_DIRECTIVEEMITTER_H
#include "llvm/ADT/StringExtras.h"
#include "llvm/TableGen/Record.h"
namespace llvm {
// Wrapper class that contains DirectiveLanguage's information defined in
// DirectiveBase.td and provides helper methods for accessing it.
class DirectiveLanguage {
public:
explicit DirectiveLanguage(const llvm::RecordKeeper &Records)
: Records(Records) {
const auto &DirectiveLanguages = getDirectiveLanguages();
Def = DirectiveLanguages[0];
}
StringRef getName() const { return Def->getValueAsString("name"); }
StringRef getCppNamespace() const {
return Def->getValueAsString("cppNamespace");
}
StringRef getDirectivePrefix() const {
return Def->getValueAsString("directivePrefix");
}
StringRef getClausePrefix() const {
return Def->getValueAsString("clausePrefix");
}
StringRef getClauseEnumSetClass() const {
return Def->getValueAsString("clauseEnumSetClass");
}
StringRef getFlangClauseBaseClass() const {
return Def->getValueAsString("flangClauseBaseClass");
}
bool hasMakeEnumAvailableInNamespace() const {
return Def->getValueAsBit("makeEnumAvailableInNamespace");
}
bool hasEnableBitmaskEnumInNamespace() const {
return Def->getValueAsBit("enableBitmaskEnumInNamespace");
}
std::vector<Record *> getDirectives() const {
return Records.getAllDerivedDefinitions("Directive");
}
std::vector<Record *> getClauses() const {
return Records.getAllDerivedDefinitions("Clause");
}
bool HasValidityErrors() const;
private:
const llvm::Record *Def;
const llvm::RecordKeeper &Records;
std::vector<Record *> getDirectiveLanguages() const {
return Records.getAllDerivedDefinitions("DirectiveLanguage");
}
};
// Base record class used for Directive and Clause class defined in
// DirectiveBase.td.
class BaseRecord {
public:
explicit BaseRecord(const llvm::Record *Def) : Def(Def) {}
StringRef getName() const { return Def->getValueAsString("name"); }
StringRef getAlternativeName() const {
return Def->getValueAsString("alternativeName");
}
// Returns the name of the directive formatted for output. Whitespace are
// replaced with underscores.
std::string getFormattedName() {
StringRef Name = Def->getValueAsString("name");
std::string N = Name.str();
std::replace(N.begin(), N.end(), ' ', '_');
return N;
}
bool isDefault() const { return Def->getValueAsBit("isDefault"); }
// Returns the record name.
StringRef getRecordName() const { return Def->getName(); }
protected:
const llvm::Record *Def;
};
// Wrapper class that contains a Directive's information defined in
// DirectiveBase.td and provides helper methods for accessing it.
class Directive : public BaseRecord {
public:
explicit Directive(const llvm::Record *Def) : BaseRecord(Def) {}
std::vector<Record *> getAllowedClauses() const {
return Def->getValueAsListOfDefs("allowedClauses");
}
std::vector<Record *> getAllowedOnceClauses() const {
return Def->getValueAsListOfDefs("allowedOnceClauses");
}
std::vector<Record *> getAllowedExclusiveClauses() const {
return Def->getValueAsListOfDefs("allowedExclusiveClauses");
}
std::vector<Record *> getRequiredClauses() const {
return Def->getValueAsListOfDefs("requiredClauses");
}
};
// Wrapper class that contains Clause's information defined in DirectiveBase.td
// and provides helper methods for accessing it.
class Clause : public BaseRecord {
public:
explicit Clause(const llvm::Record *Def) : BaseRecord(Def) {}
// Optional field.
StringRef getClangClass() const {
return Def->getValueAsString("clangClass");
}
// Optional field.
StringRef getFlangClass() const {
return Def->getValueAsString("flangClass");
}
// Get the formatted name for Flang parser class. The generic formatted class
// name is constructed from the name were the first letter of each word is
// captitalized and the underscores are removed.
// ex: async -> Async
// num_threads -> NumThreads
std::string getFormattedParserClassName() {
StringRef Name = Def->getValueAsString("name");
std::string N = Name.str();
bool Cap = true;
std::transform(N.begin(), N.end(), N.begin(), [&Cap](unsigned char C) {
if (Cap == true) {
C = llvm::toUpper(C);
Cap = false;
} else if (C == '_') {
Cap = true;
}
return C;
});
llvm::erase_value(N, '_');
return N;
}
// Optional field.
StringRef getEnumName() const {
return Def->getValueAsString("enumClauseValue");
}
std::vector<Record *> getClauseVals() const {
return Def->getValueAsListOfDefs("allowedClauseValues");
}
bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }
bool isValueList() const { return Def->getValueAsBit("isValueList"); }
StringRef getDefaultValue() const {
return Def->getValueAsString("defaultValue");
}
bool isImplicit() const { return Def->getValueAsBit("isImplicit"); }
};
// Wrapper class that contains VersionedClause's information defined in
// DirectiveBase.td and provides helper methods for accessing it.
class VersionedClause {
public:
explicit VersionedClause(const llvm::Record *Def) : Def(Def) {}
// Return the specific clause record wrapped in the Clause class.
Clause getClause() const { return Clause{Def->getValueAsDef("clause")}; }
int64_t getMinVersion() const { return Def->getValueAsInt("minVersion"); }
int64_t getMaxVersion() const { return Def->getValueAsInt("maxVersion"); }
private:
const llvm::Record *Def;
};
class ClauseVal : public BaseRecord {
public:
explicit ClauseVal(const llvm::Record *Def) : BaseRecord(Def) {}
int getValue() const { return Def->getValueAsInt("value"); }
bool isUserVisible() const { return Def->getValueAsBit("isUserValue"); }
};
} // namespace llvm
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
|