10#include "llvm/ADT/FunctionExtras.h"
11#include "llvm/ADT/StringSet.h"
12#include "llvm/ADT/Twine.h"
13#include "llvm/TableGen/Error.h"
14#include "llvm/TableGen/Record.h"
24using llvm::StringInit;
31 : def(def), uniqueName(uniqueName) {
32 const DagInit *args = def->getValueAsDag(
"arguments");
33 for (
unsigned i = 0, e = args->getNumArgs(); i != e; ++i) {
34 const Init *arg = args->getArg(i);
35 const auto *strArg = dyn_cast<StringInit>(arg);
37 llvm::PrintFatalError(
39 "expected string type for interface method argument #" + Twine(i) +
40 " ('" + args->getArgNameStr(i) +
"') in '" + def->getName() +
41 "', but got '" + arg->getAsString() +
"'");
42 arguments.push_back({strArg->getValue(), args->getArgNameStr(i)});
47 return def->getValueAsString(
"returnType");
52 return def->getValueAsString(
"name");
60 return def->isSubClassOf(
"StaticInterfaceMethod");
65 return def->isSubClassOf(
"PureVirtualInterfaceMethod");
70 return def->isSubClassOf(
"InterfaceMethodDeclaration");
76 auto value = def->getValueAsString(
"body").trim();
77 return value.empty() ? std::optional<StringRef>() : value;
83 auto value = def->getValueAsString(
"defaultBody").trim();
84 return value.empty() ? std::optional<StringRef>() : value;
89 auto value = def->getValueAsString(
"description");
90 return value.empty() ? std::optional<StringRef>() : value;
104 assert(def->isSubClassOf(
"Interface") &&
105 "must be subclass of TableGen 'Interface' class");
108 auto *listInit = dyn_cast<ListInit>(def->getValueInit(
"methods"));
114 for (
const Init *init : listInit->getElements()) {
116 cast<DefInit>(init)->getDef()->getValueAsString(
"name").str();
117 while (!uniqueNames.insert(name).second) {
118 name = name +
"_" + std::to_string(uniqueNames.size());
120 methods.emplace_back(cast<DefInit>(init)->getDef(), name);
124 auto *basesInit = dyn_cast<ListInit>(def->getValueInit(
"baseInterfaces"));
130 for (
const auto &baseBaseInterface : baseInterface.getBaseInterfaces())
131 addBaseInterfaceFn(baseBaseInterface);
134 if (basesAdded.contains(baseInterface.getName()))
136 baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
137 basesAdded.insert(baseInterface.getName());
139 for (
const Init *init : basesInit->getElements())
140 addBaseInterfaceFn(Interface(cast<DefInit>(init)->getDef()));
145 return def->getValueAsString(
"cppInterfaceName");
152 if (cppNamespace.empty())
154 return (cppNamespace +
"::" + name).str();
159 return def->getValueAsString(
"cppNamespace");
167 auto value = def->getValueAsString(
"description");
168 return value.empty() ? std::optional<StringRef>() : value;
173 auto value = def->getValueAsString(
"extraClassDeclaration");
174 return value.empty() ? std::optional<StringRef>() : value;
179 auto value = def->getValueAsString(
"extraTraitClassDeclaration");
180 return value.empty() ? std::optional<StringRef>() : value;
185 auto value = def->getValueAsString(
"extraSharedClassDeclaration");
186 return value.empty() ? std::optional<StringRef>() : value;
190 auto value = def->getValueAsString(
"extraClassOf");
191 return value.empty() ? std::optional<StringRef>() : value;
197 if (!isa<OpInterface>(
this))
199 auto value = def->getValueAsString(
"verify");
200 return value.empty() ? std::optional<StringRef>() : value;
204 return def->getValueAsBit(
"verifyWithRegions");
212 return interface->
getDef().isSubClassOf(
"AttrInterface");
220 return interface->
getDef().isSubClassOf(
"OpInterface");
228 return interface->
getDef().isSubClassOf(
"TypeInterface");
236 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
bool isPureVirtual() 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)