LLVM  14.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("clauseEnumSetClass");
35  }
36 
38  return Def->getValueAsString("flangClauseBaseClass");
39  }
40 
42  return Def->getValueAsBit("makeEnumAvailableInNamespace");
43  }
44 
46  return Def->getValueAsBit("enableBitmaskEnumInNamespace");
47  }
48 
49  std::vector<Record *> getDirectives() const {
50  return Records.getAllDerivedDefinitions("Directive");
51  }
52 
53  std::vector<Record *> getClauses() const {
54  return Records.getAllDerivedDefinitions("Clause");
55  }
56 
57  bool HasValidityErrors() const;
58 
59 private:
60  const llvm::Record *Def;
61  const llvm::RecordKeeper &Records;
62 
63  std::vector<Record *> getDirectiveLanguages() const {
64  return Records.getAllDerivedDefinitions("DirectiveLanguage");
65  }
66 };
67 
68 // Base record class used for Directive and Clause class defined in
69 // DirectiveBase.td.
70 class BaseRecord {
71 public:
72  explicit BaseRecord(const llvm::Record *Def) : Def(Def) {}
73 
74  StringRef getName() const { return Def->getValueAsString("name"); }
75 
77  return Def->getValueAsString("alternativeName");
78  }
79 
80  // Returns the name of the directive formatted for output. Whitespace are
81  // replaced with underscores.
82  std::string getFormattedName() {
84  std::string N = Name.str();
85  std::replace(N.begin(), N.end(), ' ', '_');
86  return N;
87  }
88 
89  bool isDefault() const { return Def->getValueAsBit("isDefault"); }
90 
91  // Returns the record name.
92  StringRef getRecordName() const { return Def->getName(); }
93 
94 protected:
95  const llvm::Record *Def;
96 };
97 
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 {
101 public:
102  explicit Directive(const llvm::Record *Def) : BaseRecord(Def) {}
103 
104  std::vector<Record *> getAllowedClauses() const {
105  return Def->getValueAsListOfDefs("allowedClauses");
106  }
107 
108  std::vector<Record *> getAllowedOnceClauses() const {
109  return Def->getValueAsListOfDefs("allowedOnceClauses");
110  }
111 
112  std::vector<Record *> getAllowedExclusiveClauses() const {
113  return Def->getValueAsListOfDefs("allowedExclusiveClauses");
114  }
115 
116  std::vector<Record *> getRequiredClauses() const {
117  return Def->getValueAsListOfDefs("requiredClauses");
118  }
119 };
120 
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 {
124 public:
125  explicit Clause(const llvm::Record *Def) : BaseRecord(Def) {}
126 
127  // Optional field.
129  return Def->getValueAsString("clangClass");
130  }
131 
132  // Optional field.
134  return Def->getValueAsString("flangClass");
135  }
136 
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
143  StringRef Name = Def->getValueAsString("name");
144  std::string N = Name.str();
145  bool Cap = true;
146  std::transform(N.begin(), N.end(), N.begin(), [&Cap](unsigned char C) {
147  if (Cap == true) {
148  C = llvm::toUpper(C);
149  Cap = false;
150  } else if (C == '_') {
151  Cap = true;
152  }
153  return C;
154  });
155  N.erase(std::remove(N.begin(), N.end(), '_'), N.end());
156  return N;
157  }
158 
159  // Optional field.
161  return Def->getValueAsString("enumClauseValue");
162  }
163 
164  std::vector<Record *> getClauseVals() const {
165  return Def->getValueAsListOfDefs("allowedClauseValues");
166  }
167 
168  bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }
169 
170  bool isValueList() const { return Def->getValueAsBit("isValueList"); }
171 
173  return Def->getValueAsString("defaultValue");
174  }
175 
176  bool isImplicit() const { return Def->getValueAsBit("isImplicit"); }
177 };
178 
179 // Wrapper class that contains VersionedClause's information defined in
180 // DirectiveBase.td and provides helper methods for accessing it.
182 public:
183  explicit VersionedClause(const llvm::Record *Def) : Def(Def) {}
184 
185  // Return the specific clause record wrapped in the Clause class.
186  Clause getClause() const { return Clause{Def->getValueAsDef("clause")}; }
187 
188  int64_t getMinVersion() const { return Def->getValueAsInt("minVersion"); }
189 
190  int64_t getMaxVersion() const { return Def->getValueAsInt("maxVersion"); }
191 
192 private:
193  const llvm::Record *Def;
194 };
195 
196 class ClauseVal : public BaseRecord {
197 public:
198  explicit ClauseVal(const llvm::Record *Def) : BaseRecord(Def) {}
199 
200  int getValue() const { return Def->getValueAsInt("value"); }
201 
202  bool isUserVisible() const { return Def->getValueAsBit("isUserValue"); }
203 };
204 
205 } // namespace llvm
206 
207 #endif
llvm
---------------------— PointerInfo ------------------------------------—
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:188
llvm::RecordKeeper
Definition: Record.h:1771
llvm::BaseRecord::getAlternativeName
StringRef getAlternativeName() const
Definition: DirectiveEmitter.h:76
llvm::Clause::getFormattedParserClassName
std::string getFormattedParserClassName()
Definition: DirectiveEmitter.h:142
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:2521
llvm::BaseRecord::getFormattedName
std::string getFormattedName()
Definition: DirectiveEmitter.h:82
llvm::BaseRecord::getRecordName
StringRef getRecordName() const
Definition: DirectiveEmitter.h:92
llvm::Clause::isValueList
bool isValueList() const
Definition: DirectiveEmitter.h:170
llvm::Directive::getAllowedOnceClauses
std::vector< Record * > getAllowedOnceClauses() const
Definition: DirectiveEmitter.h:108
replace
static void replace(Module &M, GlobalVariable *Old, GlobalVariable *New)
Definition: ConstantMerge.cpp:116
llvm::BaseRecord::BaseRecord
BaseRecord(const llvm::Record *Def)
Definition: DirectiveEmitter.h:72
llvm::Directive::Directive
Directive(const llvm::Record *Def)
Definition: DirectiveEmitter.h:102
llvm::Directive::getRequiredClauses
std::vector< Record * > getRequiredClauses() const
Definition: DirectiveEmitter.h:116
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:53
llvm::VersionedClause::VersionedClause
VersionedClause(const llvm::Record *Def)
Definition: DirectiveEmitter.h:183
llvm::Clause::getClangClass
StringRef getClangClass() const
Definition: DirectiveEmitter.h:128
llvm::Clause::getDefaultValue
StringRef getDefaultValue() const
Definition: DirectiveEmitter.h:172
llvm::Clause::getEnumName
StringRef getEnumName() const
Definition: DirectiveEmitter.h:160
llvm::DirectiveLanguage::HasValidityErrors
bool HasValidityErrors() const
llvm::Clause::isImplicit
bool isImplicit() const
Definition: DirectiveEmitter.h:176
llvm::Clause
Definition: DirectiveEmitter.h:123
llvm::ClauseVal::ClauseVal
ClauseVal(const llvm::Record *Def)
Definition: DirectiveEmitter.h:198
llvm::VersionedClause::getClause
Clause getClause() const
Definition: DirectiveEmitter.h:186
StringExtras.h
llvm::BaseRecord::isDefault
bool isDefault() const
Definition: DirectiveEmitter.h:89
llvm::DirectiveLanguage::getFlangClauseBaseClass
StringRef getFlangClauseBaseClass() const
Definition: DirectiveEmitter.h:37
llvm::Record
Definition: Record.h:1472
llvm::Clause::isValueOptional
bool isValueOptional() const
Definition: DirectiveEmitter.h:168
llvm::BaseRecord::getName
StringRef getName() const
Definition: DirectiveEmitter.h:74
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:2727
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
llvm::DirectiveLanguage::getDirectives
std::vector< Record * > getDirectives() const
Definition: DirectiveEmitter.h:49
llvm::BaseRecord
Definition: DirectiveEmitter.h:70
llvm::Clause::getClauseVals
std::vector< Record * > getClauseVals() const
Definition: DirectiveEmitter.h:164
llvm::DirectiveLanguage::getCppNamespace
StringRef getCppNamespace() const
Definition: DirectiveEmitter.h:21
llvm::ClauseVal::getValue
int getValue() const
Definition: DirectiveEmitter.h:200
llvm::DirectiveLanguage::getClauseEnumSetClass
StringRef getClauseEnumSetClass() const
Definition: DirectiveEmitter.h:33
llvm::ClauseVal::isUserVisible
bool isUserVisible() const
Definition: DirectiveEmitter.h:202
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::DirectiveLanguage::hasMakeEnumAvailableInNamespace
bool hasMakeEnumAvailableInNamespace() const
Definition: DirectiveEmitter.h:41
llvm::Directive::getAllowedExclusiveClauses
std::vector< Record * > getAllowedExclusiveClauses() const
Definition: DirectiveEmitter.h:112
llvm::DirectiveLanguage
Definition: DirectiveEmitter.h:11
llvm::BaseRecord::Def
const llvm::Record * Def
Definition: DirectiveEmitter.h:95
transform
instcombine should handle this transform
Definition: README.txt:262
llvm::VersionedClause::getMaxVersion
int64_t getMaxVersion() const
Definition: DirectiveEmitter.h:190
llvm::Clause::Clause
Clause(const llvm::Record *Def)
Definition: DirectiveEmitter.h:125
llvm::DirectiveLanguage::hasEnableBitmaskEnumInNamespace
bool hasEnableBitmaskEnumInNamespace() const
Definition: DirectiveEmitter.h:45
llvm::ClauseVal
Definition: DirectiveEmitter.h:196
llvm::Record::getName
StringRef getName() const
Definition: Record.h:1540
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:2607
llvm::DirectiveLanguage::DirectiveLanguage
DirectiveLanguage(const llvm::RecordKeeper &Records)
Definition: DirectiveEmitter.h:13
llvm::Clause::getFlangClass
StringRef getFlangClass() const
Definition: DirectiveEmitter.h:133
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:2472
llvm::VersionedClause
Definition: DirectiveEmitter.h:181
llvm::Directive::getAllowedClauses
std::vector< Record * > getAllowedClauses() const
Definition: DirectiveEmitter.h:104
Record.h
llvm::Directive
Definition: DirectiveEmitter.h:100
llvm::DirectiveLanguage::getClausePrefix
StringRef getClausePrefix() const
Definition: DirectiveEmitter.h:29