10#include "llvm/ADT/FunctionExtras.h"
11#include "llvm/ADT/StringSet.h"
12#include "llvm/TableGen/Error.h"
13#include "llvm/TableGen/Record.h"
23using llvm::StringInit;
30 : def(def), uniqueName(uniqueName) {
31 const DagInit *args = def->getValueAsDag(
"arguments");
32 for (
unsigned i = 0, e = args->getNumArgs(); i != e; ++i) {
33 arguments.push_back({cast<StringInit>(args->getArg(i))->getValue(),
34 args->getArgNameStr(i)});
39 return def->getValueAsString(
"returnType");
44 return def->getValueAsString(
"name");
52 return def->isSubClassOf(
"StaticInterfaceMethod");
57 return def->isSubClassOf(
"InterfaceMethodDeclaration");
63 auto value = def->getValueAsString(
"body").trim();
64 return value.empty() ? std::optional<StringRef>() : value;
70 auto value = def->getValueAsString(
"defaultBody").trim();
71 return value.empty() ? std::optional<StringRef>() : value;
76 auto value = def->getValueAsString(
"description");
77 return value.empty() ? std::optional<StringRef>() : value;
91 assert(def->isSubClassOf(
"Interface") &&
92 "must be subclass of TableGen 'Interface' class");
95 auto *listInit = dyn_cast<ListInit>(def->getValueInit(
"methods"));
101 for (
const Init *init : listInit->getElements()) {
103 cast<DefInit>(init)->getDef()->getValueAsString(
"name").str();
104 while (!uniqueNames.insert(name).second) {
105 name = name +
"_" + std::to_string(uniqueNames.size());
107 methods.emplace_back(cast<DefInit>(init)->getDef(), name);
111 auto *basesInit = dyn_cast<ListInit>(def->getValueInit(
"baseInterfaces"));
117 for (
const auto &baseBaseInterface : baseInterface.getBaseInterfaces())
118 addBaseInterfaceFn(baseBaseInterface);
121 if (basesAdded.contains(baseInterface.getName()))
123 baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
124 basesAdded.insert(baseInterface.getName());
126 for (
const Init *init : basesInit->getElements())
127 addBaseInterfaceFn(Interface(cast<DefInit>(init)->getDef()));
132 return def->getValueAsString(
"cppInterfaceName");
139 if (cppNamespace.empty())
141 return (cppNamespace +
"::" + name).str();
146 return def->getValueAsString(
"cppNamespace");
154 auto value = def->getValueAsString(
"description");
155 return value.empty() ? std::optional<StringRef>() : value;
160 auto value = def->getValueAsString(
"extraClassDeclaration");
161 return value.empty() ? std::optional<StringRef>() : value;
166 auto value = def->getValueAsString(
"extraTraitClassDeclaration");
167 return value.empty() ? std::optional<StringRef>() : value;
172 auto value = def->getValueAsString(
"extraSharedClassDeclaration");
173 return value.empty() ? std::optional<StringRef>() : value;
177 auto value = def->getValueAsString(
"extraClassOf");
178 return value.empty() ? std::optional<StringRef>() : value;
184 if (!isa<OpInterface>(
this))
186 auto value = def->getValueAsString(
"verify");
187 return value.empty() ? std::optional<StringRef>() : value;
191 return def->getValueAsBit(
"verifyWithRegions");
199 return interface->
getDef().isSubClassOf(
"AttrInterface");
207 return interface->
getDef().isSubClassOf(
"OpInterface");
215 return interface->
getDef().isSubClassOf(
"TypeInterface");
223 return interface->
getDef().isSubClassOf(
"DialectInterface");
bool isDeclaration() const
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
const llvm::Record & getDef() const
std::string getFullyQualifiedName() const
StringRef getCppNamespace() const
StringRef getName() const
Include the generated interface declarations.
llvm::StringSet< AllocatorTy > StringSet
Interface(const llvm::Record *def)
static bool classof(const Interface *interface)
Interface(const llvm::Record *def)
static bool classof(const Interface *interface)
Interface(const llvm::Record *def)
static bool classof(const Interface *interface)
Interface(const llvm::Record *def)
static bool classof(const Interface *interface)