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(
"PureVirtualInterfaceMethod");
62 return def->isSubClassOf(
"InterfaceMethodDeclaration");
68 auto value = def->getValueAsString(
"body").trim();
69 return value.empty() ? std::optional<StringRef>() : value;
75 auto value = def->getValueAsString(
"defaultBody").trim();
76 return value.empty() ? std::optional<StringRef>() : value;
81 auto value = def->getValueAsString(
"description");
82 return value.empty() ? std::optional<StringRef>() : value;
96 assert(def->isSubClassOf(
"Interface") &&
97 "must be subclass of TableGen 'Interface' class");
100 auto *listInit = dyn_cast<ListInit>(def->getValueInit(
"methods"));
106 for (
const Init *init : listInit->getElements()) {
108 cast<DefInit>(init)->getDef()->getValueAsString(
"name").str();
109 while (!uniqueNames.insert(name).second) {
110 name = name +
"_" + std::to_string(uniqueNames.size());
112 methods.emplace_back(cast<DefInit>(init)->getDef(), name);
116 auto *basesInit = dyn_cast<ListInit>(def->getValueInit(
"baseInterfaces"));
122 for (
const auto &baseBaseInterface : baseInterface.getBaseInterfaces())
123 addBaseInterfaceFn(baseBaseInterface);
126 if (basesAdded.contains(baseInterface.getName()))
128 baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
129 basesAdded.insert(baseInterface.getName());
131 for (
const Init *init : basesInit->getElements())
132 addBaseInterfaceFn(Interface(cast<DefInit>(init)->getDef()));
137 return def->getValueAsString(
"cppInterfaceName");
144 if (cppNamespace.empty())
146 return (cppNamespace +
"::" + name).str();
151 return def->getValueAsString(
"cppNamespace");
159 auto value = def->getValueAsString(
"description");
160 return value.empty() ? std::optional<StringRef>() : value;
165 auto value = def->getValueAsString(
"extraClassDeclaration");
166 return value.empty() ? std::optional<StringRef>() : value;
171 auto value = def->getValueAsString(
"extraTraitClassDeclaration");
172 return value.empty() ? std::optional<StringRef>() : value;
177 auto value = def->getValueAsString(
"extraSharedClassDeclaration");
178 return value.empty() ? std::optional<StringRef>() : value;
182 auto value = def->getValueAsString(
"extraClassOf");
183 return value.empty() ? std::optional<StringRef>() : value;
189 if (!isa<OpInterface>(
this))
191 auto value = def->getValueAsString(
"verify");
192 return value.empty() ? std::optional<StringRef>() : value;
196 return def->getValueAsBit(
"verifyWithRegions");
204 return interface->
getDef().isSubClassOf(
"AttrInterface");
212 return interface->
getDef().isSubClassOf(
"OpInterface");
220 return interface->
getDef().isSubClassOf(
"TypeInterface");
228 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)