10 #include "llvm/ADT/FunctionExtras.h"
11 #include "llvm/ADT/StringSet.h"
12 #include "llvm/TableGen/Error.h"
13 #include "llvm/TableGen/Record.h"
22 using llvm::StringInit;
29 : def(def), uniqueName(uniqueName) {
30 const DagInit *args = def->getValueAsDag(
"arguments");
31 for (
unsigned i = 0, e = args->getNumArgs(); i != e; ++i) {
32 arguments.push_back({cast<StringInit>(args->getArg(i))->getValue(),
33 args->getArgNameStr(i)});
38 return def->getValueAsString(
"returnType");
43 return def->getValueAsString(
"name");
51 return def->isSubClassOf(
"StaticInterfaceMethod");
57 auto value = def->getValueAsString(
"body").trim();
58 return value.empty() ? std::optional<StringRef>() : value;
64 auto value = def->getValueAsString(
"defaultBody").trim();
65 return value.empty() ? std::optional<StringRef>() : value;
70 auto value = def->getValueAsString(
"description");
71 return value.empty() ? std::optional<StringRef>() : value;
85 assert(def->isSubClassOf(
"Interface") &&
86 "must be subclass of TableGen 'Interface' class");
89 auto *listInit = dyn_cast<ListInit>(def->getValueInit(
"methods"));
95 for (
const Init *init : listInit->getElements()) {
97 cast<DefInit>(init)->getDef()->getValueAsString(
"name").str();
98 while (!uniqueNames.insert(name).second) {
99 name = name +
"_" + std::to_string(uniqueNames.size());
101 methods.emplace_back(cast<DefInit>(init)->getDef(), name);
105 auto *basesInit = dyn_cast<ListInit>(def->getValueInit(
"baseInterfaces"));
108 llvm::unique_function<void(
Interface)> addBaseInterfaceFn =
111 for (
const auto &baseBaseInterface : baseInterface.getBaseInterfaces())
112 addBaseInterfaceFn(baseBaseInterface);
115 if (basesAdded.contains(baseInterface.getName()))
117 baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
118 basesAdded.insert(baseInterface.getName());
120 for (
const Init *init : basesInit->getElements())
121 addBaseInterfaceFn(
Interface(cast<DefInit>(init)->getDef()));
126 return def->getValueAsString(
"cppInterfaceName");
133 if (cppNamespace.empty())
135 return (cppNamespace +
"::" + name).str();
140 return def->getValueAsString(
"cppNamespace");
148 auto value = def->getValueAsString(
"description");
149 return value.empty() ? std::optional<StringRef>() : value;
154 auto value = def->getValueAsString(
"extraClassDeclaration");
155 return value.empty() ? std::optional<StringRef>() : value;
160 auto value = def->getValueAsString(
"extraTraitClassDeclaration");
161 return value.empty() ? std::optional<StringRef>() : value;
166 auto value = def->getValueAsString(
"extraSharedClassDeclaration");
167 return value.empty() ? std::optional<StringRef>() : value;
171 auto value = def->getValueAsString(
"extraClassOf");
172 return value.empty() ? std::optional<StringRef>() : value;
178 if (!isa<OpInterface>(
this))
180 auto value = def->getValueAsString(
"verify");
181 return value.empty() ? std::optional<StringRef>() : value;
185 return def->getValueAsBit(
"verifyWithRegions");
193 return interface->
getDef().isSubClassOf(
"AttrInterface");
201 return interface->
getDef().isSubClassOf(
"OpInterface");
209 return interface->
getDef().isSubClassOf(
"TypeInterface");
StringRef getReturnType() const
std::optional< StringRef > getDefaultImplementation() const
ArrayRef< Argument > getArguments() const
InterfaceMethod(const llvm::Record *def, std::string uniqueName)
std::optional< StringRef > getBody() const
StringRef getUniqueName() const
StringRef getName() const
std::optional< StringRef > getDescription() const
Interface(const llvm::Record *def)
std::optional< StringRef > getExtraClassOf() const
std::optional< StringRef > getDescription() const
std::optional< StringRef > getExtraClassDeclaration() const
std::optional< StringRef > getExtraSharedClassDeclaration() const
ArrayRef< InterfaceMethod > getMethods() const
std::optional< StringRef > getExtraTraitClassDeclaration() const
bool verifyWithRegions() const
std::optional< StringRef > getVerify() const
std::string getFullyQualifiedName() const
StringRef getCppNamespace() const
const llvm::Record & getDef() const
StringRef getName() const
Include the generated interface declarations.
static bool classof(const Interface *interface)
static bool classof(const Interface *interface)
static bool classof(const Interface *interface)