LLVM  13.0.0git
DirectiveEmitter.h
Go to the documentation of this file.
1 #ifndef LLVM_TABLEGEN_DIRECTIVEEMITTER_H
2 #define LLVM_TABLEGEN_DIRECTIVEEMITTER_H
3 
5 #include "llvm/TableGen/Record.h"
6 
7 namespace llvm {
8 
9 // Wrapper class that contains DirectiveLanguage's information defined in
10 // DirectiveBase.td and provides helper methods for accessing it.
12 public:
13  explicit DirectiveLanguage(const llvm::RecordKeeper &Records)
14  : Records(Records) {
15  const auto &DirectiveLanguages = getDirectiveLanguages();
16  Def = DirectiveLanguages[0];
17  }
18 
19  StringRef getName() const { return Def->getValueAsString("name"); }
20 
22  return Def->getValueAsString("cppNamespace");
23  }
24 
26  return Def->getValueAsString("directivePrefix");
27  }
28 
30  return Def->getValueAsString("clausePrefix");
31  }
32 
34  return Def->getValueAsString("includeHeader");
35  }
36 
38  return Def->getValueAsString("clauseEnumSetClass");
39  }
40 
42  return Def->getValueAsString("flangClauseBaseClass");
43  }
44 
46  return Def->getValueAsBit("makeEnumAvailableInNamespace");
47  }
48 
50  return Def->getValueAsBit("enableBitmaskEnumInNamespace");
51  }
52 
53  std::vector<Record *> getDirectives() const {
54  return Records.getAllDerivedDefinitions("Directive");
55  }
56 
57  std::vector<Record *> getClauses() const {
58  return Records.getAllDerivedDefinitions("Clause");
59  }
60 
61  bool HasValidityErrors() const;
62 
63 private:
64  const llvm::Record *Def;
65  const llvm::RecordKeeper &Records;
66 
67  std::vector<Record *> getDirectiveLanguages() const {
68  return Records.getAllDerivedDefinitions("DirectiveLanguage");
69  }
70 };
71 
72 // Base record class used for Directive and Clause class defined in
73 // DirectiveBase.td.
74 class BaseRecord {
75 public:
76  explicit BaseRecord(const llvm::Record *Def) : Def(Def) {}
77 
78  StringRef getName() const { return Def->getValueAsString("name"); }
79 
81  return Def->getValueAsString("alternativeName");
82  }
83 
84  // Returns the name of the directive formatted for output. Whitespace are
85  // replaced with underscores.
86  std::string getFormattedName() {
88  std::string N = Name.str();
89  std::replace(N.begin(), N.end(), ' ', '_');
90  return N;
91  }
92 
93  bool isDefault() const { return Def->getValueAsBit("isDefault"); }
94 
95  // Returns the record name.
96  StringRef getRecordName() const { return Def->getName(); }
97 
98 protected:
99  const llvm::Record *Def;
100 };
101 
102 // Wrapper class that contains a Directive's information defined in
103 // DirectiveBase.td and provides helper methods for accessing it.
104 class Directive : public BaseRecord {
105 public:
106  explicit Directive(const llvm::Record *Def) : BaseRecord(Def) {}
107 
108  std::vector<Record *> getAllowedClauses() const {
109  return Def->getValueAsListOfDefs("allowedClauses");
110  }
111 
112  std::vector<Record *> getAllowedOnceClauses() const {
113  return Def->getValueAsListOfDefs("allowedOnceClauses");
114  }
115 
116  std::vector<Record *> getAllowedExclusiveClauses() const {
117  return Def->getValueAsListOfDefs("allowedExclusiveClauses");
118  }
119 
120  std::vector<Record *> getRequiredClauses() const {
121  return Def->getValueAsListOfDefs("requiredClauses");
122  }
123 };
124 
125 // Wrapper class that contains Clause's information defined in DirectiveBase.td
126 // and provides helper methods for accessing it.
127 class Clause : public BaseRecord {
128 public:
129  explicit Clause(const llvm::Record *Def) : BaseRecord(Def) {}
130 
131  // Optional field.
133  return Def->getValueAsString("clangClass");
134  }
135 
136  // Optional field.
138  return Def->getValueAsString("flangClass");
139  }
140 
141  // Get the formatted name for Flang parser class. The generic formatted class
142  // name is constructed from the name were the first letter of each word is
143  // captitalized and the underscores are removed.
144  // ex: async -> Async
145  // num_threads -> NumThreads
147  StringRef Name = Def->getValueAsString("name");
148  std::string N = Name.str();
149  bool Cap = true;
150  std::transform(N.begin(), N.end(), N.begin(), [&Cap](unsigned char C) {
151  if (Cap == true) {
152  C = llvm::toUpper(C);
153  Cap = false;
154  } else if (C == '_') {
155  Cap = true;
156  }
157  return C;
158  });
159  N.erase(std::remove(N.begin(), N.end(), '_'), N.end());
160  return N;
161  }
162 
163  // Optional field.
165  return Def->getValueAsString("enumClauseValue");
166  }
167 
168  std::vector<Record *> getClauseVals() const {
169  return Def->getValueAsListOfDefs("allowedClauseValues");
170  }
171 
172  bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }
173 
174  bool isValueList() const { return Def->getValueAsBit("isValueList"); }
175 
177  return Def->getValueAsString("defaultValue");
178  }
179 
180  bool isImplicit() const { return Def->getValueAsBit("isImplicit"); }
181 };
182 
183 // Wrapper class that contains VersionedClause's information defined in
184 // DirectiveBase.td and provides helper methods for accessing it.
186 public:
187  explicit VersionedClause(const llvm::Record *Def) : Def(Def) {}
188 
189  // Return the specific clause record wrapped in the Clause class.
190  Clause getClause() const { return Clause{Def->getValueAsDef("clause")}; }
191 
192  int64_t getMinVersion() const { return Def->getValueAsInt("minVersion"); }
193 
194  int64_t getMaxVersion() const { return Def->getValueAsInt("maxVersion"); }
195 
196 private:
197  const llvm::Record *Def;
198 };
199 
200 class ClauseVal : public BaseRecord {
201 public:
202  explicit ClauseVal(const llvm::Record *Def) : BaseRecord(Def) {}
203 
204  int getValue() const { return Def->getValueAsInt("value"); }
205 
206  bool isUserVisible() const { return Def->getValueAsBit("isUserValue"); }
207 };
208 
209 } // namespace llvm
210 
211 #endif
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
llvm::DirectiveLanguage::getDirectivePrefix
StringRef getDirectivePrefix() const
Definition: DirectiveEmitter.h:25
llvm::tgtok::Def
@ Def
Definition: TGLexer.h:50
llvm::VersionedClause::getMinVersion
int64_t getMinVersion() const
Definition: DirectiveEmitter.h:192
llvm::RecordKeeper
Definition: Record.h:1754
llvm::BaseRecord::getAlternativeName
StringRef getAlternativeName() const
Definition: DirectiveEmitter.h:80
llvm::Clause::getFormattedParserClassName
std::string getFormattedParserClassName()
Definition: DirectiveEmitter.h:146
llvm::Record::getValueAsListOfDefs
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:2471
llvm::BaseRecord::getFormattedName
std::string getFormattedName()
Definition: DirectiveEmitter.h:86
llvm::BaseRecord::getRecordName
StringRef getRecordName() const
Definition: DirectiveEmitter.h:96
llvm::Clause::isValueList
bool isValueList() const
Definition: DirectiveEmitter.h:174
llvm::Directive::getAllowedOnceClauses
std::vector< Record * > getAllowedOnceClauses() const
Definition: DirectiveEmitter.h:112
replace
static void replace(Module &M, GlobalVariable *Old, GlobalVariable *New)
Definition: ConstantMerge.cpp:114
llvm::BaseRecord::BaseRecord
BaseRecord(const llvm::Record *Def)
Definition: DirectiveEmitter.h:76
llvm::Directive::Directive
Directive(const llvm::Record *Def)
Definition: DirectiveEmitter.h:106
llvm::Directive::getRequiredClauses
std::vector< Record * > getRequiredClauses() const
Definition: DirectiveEmitter.h:120
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::DirectiveLanguage::getName
StringRef getName() const
Definition: DirectiveEmitter.h:19
llvm::DirectiveLanguage::getClauses
std::vector< Record * > getClauses() const
Definition: DirectiveEmitter.h:57
llvm::VersionedClause::VersionedClause
VersionedClause(const llvm::Record *Def)
Definition: DirectiveEmitter.h:187
llvm::Clause::getClangClass
StringRef getClangClass() const
Definition: DirectiveEmitter.h:132
llvm::Clause::getDefaultValue
StringRef getDefaultValue() const
Definition: DirectiveEmitter.h:176
llvm::Clause::getEnumName
StringRef getEnumName() const
Definition: DirectiveEmitter.h:164
llvm::DirectiveLanguage::getIncludeHeader
StringRef getIncludeHeader() const
Definition: DirectiveEmitter.h:33
llvm::DirectiveLanguage::HasValidityErrors
bool HasValidityErrors() const
llvm::Clause::isImplicit
bool isImplicit() const
Definition: DirectiveEmitter.h:180
llvm::Clause
Definition: DirectiveEmitter.h:127
llvm::ClauseVal::ClauseVal
ClauseVal(const llvm::Record *Def)
Definition: DirectiveEmitter.h:202
llvm::VersionedClause::getClause
Clause getClause() const
Definition: DirectiveEmitter.h:190
StringExtras.h
llvm::BaseRecord::isDefault
bool isDefault() const
Definition: DirectiveEmitter.h:93
llvm::DirectiveLanguage::getFlangClauseBaseClass
StringRef getFlangClauseBaseClass() const
Definition: DirectiveEmitter.h:41
llvm::Record
Definition: Record.h:1471
llvm::Clause::isValueOptional
bool isValueOptional() const
Definition: DirectiveEmitter.h:172
llvm::BaseRecord::getName
StringRef getName() const
Definition: DirectiveEmitter.h:78
llvm::sys::fs::remove
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
llvm::RecordKeeper::getAllDerivedDefinitions
std::vector< Record * > getAllDerivedDefinitions(StringRef ClassName) const
Get all the concrete records that inherit from the one specified class.
Definition: Record.cpp:2662
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
llvm::DirectiveLanguage::getDirectives
std::vector< Record * > getDirectives() const
Definition: DirectiveEmitter.h:53
llvm::BaseRecord
Definition: DirectiveEmitter.h:74
llvm::Clause::getClauseVals
std::vector< Record * > getClauseVals() const
Definition: DirectiveEmitter.h:168
llvm::DirectiveLanguage::getCppNamespace
StringRef getCppNamespace() const
Definition: DirectiveEmitter.h:21
llvm::ClauseVal::getValue
int getValue() const
Definition: DirectiveEmitter.h:204
llvm::DirectiveLanguage::getClauseEnumSetClass
StringRef getClauseEnumSetClass() const
Definition: DirectiveEmitter.h:37
llvm::ClauseVal::isUserVisible
bool isUserVisible() const
Definition: DirectiveEmitter.h:206
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::DirectiveLanguage::hasMakeEnumAvailableInNamespace
bool hasMakeEnumAvailableInNamespace() const
Definition: DirectiveEmitter.h:45
llvm::Directive::getAllowedExclusiveClauses
std::vector< Record * > getAllowedExclusiveClauses() const
Definition: DirectiveEmitter.h:116
llvm::DirectiveLanguage
Definition: DirectiveEmitter.h:11
llvm::BaseRecord::Def
const llvm::Record * Def
Definition: DirectiveEmitter.h:99
transform
instcombine should handle this transform
Definition: README.txt:262
llvm::VersionedClause::getMaxVersion
int64_t getMaxVersion() const
Definition: DirectiveEmitter.h:194
llvm::Clause::Clause
Clause(const llvm::Record *Def)
Definition: DirectiveEmitter.h:129
llvm::DirectiveLanguage::hasEnableBitmaskEnumInNamespace
bool hasEnableBitmaskEnumInNamespace() const
Definition: DirectiveEmitter.h:49
llvm::ClauseVal
Definition: DirectiveEmitter.h:200
llvm::Record::getName
StringRef getName() const
Definition: Record.h:1527
N
#define N
llvm::Record::getValueAsBit
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:2557
llvm::DirectiveLanguage::DirectiveLanguage
DirectiveLanguage(const llvm::RecordKeeper &Records)
Definition: DirectiveEmitter.h:13
llvm::Clause::getFlangClass
StringRef getFlangClass() const
Definition: DirectiveEmitter.h:137
llvm::Record::getValueAsString
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:2422
llvm::VersionedClause
Definition: DirectiveEmitter.h:185
llvm::Directive::getAllowedClauses
std::vector< Record * > getAllowedClauses() const
Definition: DirectiveEmitter.h:108
Record.h
llvm::Directive
Definition: DirectiveEmitter.h:104
llvm::DirectiveLanguage::getClausePrefix
StringRef getClausePrefix() const
Definition: DirectiveEmitter.h:29