10 #include "llvm/ADT/FunctionExtras.h"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/ADT/StringSet.h"
13 #include "llvm/Support/FormatVariadic.h"
14 #include "llvm/TableGen/Error.h"
15 #include "llvm/TableGen/Record.h"
24 using llvm::StringInit;
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");
49 return def->isSubClassOf(
"StaticInterfaceMethod");
54 auto value = def->getValueAsString(
"body");
55 return value.empty() ? std::optional<StringRef>() : value;
60 auto value = def->getValueAsString(
"defaultBody");
61 return value.empty() ? std::optional<StringRef>() : value;
66 auto value = def->getValueAsString(
"description");
67 return value.empty() ? std::optional<StringRef>() : value;
81 assert(def->isSubClassOf(
"Interface") &&
82 "must be subclass of TableGen 'Interface' class");
85 auto *listInit = dyn_cast<ListInit>(def->getValueInit(
"methods"));
86 for (
const Init *init : listInit->getValues())
87 methods.emplace_back(cast<DefInit>(init)->getDef());
90 auto *basesInit = dyn_cast<ListInit>(def->getValueInit(
"baseInterfaces"));
93 llvm::unique_function<void(
Interface)> addBaseInterfaceFn =
96 for (
const auto &baseBaseInterface : baseInterface.getBaseInterfaces())
97 addBaseInterfaceFn(baseBaseInterface);
100 if (basesAdded.contains(baseInterface.getName()))
102 baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
103 basesAdded.insert(baseInterface.getName());
105 for (
const Init *init : basesInit->getValues())
106 addBaseInterfaceFn(
Interface(cast<DefInit>(init)->getDef()));
111 return def->getValueAsString(
"cppInterfaceName");
118 if (cppNamespace.empty())
120 return (cppNamespace +
"::" + name).str();
125 return def->getValueAsString(
"cppNamespace");
133 auto value = def->getValueAsString(
"description");
134 return value.empty() ? std::optional<StringRef>() : value;
139 auto value = def->getValueAsString(
"extraClassDeclaration");
140 return value.empty() ? std::optional<StringRef>() : value;
145 auto value = def->getValueAsString(
"extraTraitClassDeclaration");
146 return value.empty() ? std::optional<StringRef>() : value;
151 auto value = def->getValueAsString(
"extraSharedClassDeclaration");
152 return value.empty() ? std::optional<StringRef>() : value;
156 auto value = def->getValueAsString(
"extraClassOf");
157 return value.empty() ? std::optional<StringRef>() : value;
163 if (!isa<OpInterface>(
this))
165 auto value = def->getValueAsString(
"verify");
166 return value.empty() ? std::optional<StringRef>() : value;
170 return def->getValueAsBit(
"verifyWithRegions");
178 return interface->
getDef().isSubClassOf(
"AttrInterface");
186 return interface->
getDef().isSubClassOf(
"OpInterface");
194 return interface->
getDef().isSubClassOf(
"TypeInterface");
InterfaceMethod(const llvm::Record *def)
StringRef getReturnType() const
std::optional< StringRef > getDefaultImplementation() const
ArrayRef< Argument > getArguments() const
std::optional< StringRef > getBody() 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)