12#include "llvm/ADT/STLExtras.h"
13#include "llvm/ADT/SmallString.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringExtras.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/TypeSwitch.h"
18#include "llvm/Support/FormatVariadic.h"
19#include "llvm/Support/raw_ostream.h"
26#include "Templates/Header.txt"
35struct DialectStrings {
36 std::string dialectName;
37 std::string dialectCppName;
38 std::string dialectCppShortName;
39 std::string dialectBaseTypeName;
41 std::string namespaceOpen;
42 std::string namespaceClose;
43 std::string namespacePath;
49 std::string typeCppName;
55 std::string opCppName;
56 std::string opScopedCppName;
64 std::string nameArray;
65 llvm::raw_string_ostream nameArrayStream(nameArray);
66 nameArrayStream <<
"{\"" << llvm::join(names,
"\", \"") <<
"\"}";
72static std::string legalizeCppName(StringRef name) {
73 if (!name.empty() && llvm::isDigit(name.front()))
74 return (
"_" + name).str();
79static std::string typeToCppName(irdl::TypeOp type) {
80 return llvm::formatv(
"{0}Type", legalizeCppName(convertToCamelFromSnakeCase(
81 type.getSymName(),
true)));
85static std::string opToCppName(irdl::OperationOp op) {
86 const auto opName = op.getSymName();
87 const auto periodIndex = opName.find_last_of(
".");
88 const auto nameSubstr = periodIndex == std::string::npos
90 : opName.substr(periodIndex + 1);
92 "{0}Op", legalizeCppName(convertToCamelFromSnakeCase(nameSubstr,
true)));
99 return llvm::map_to_vector(parts, legalizeCppName);
103static std::string opToScopedCppName(irdl::OperationOp op) {
104 auto names = opToCppNamespaces(op);
105 names.push_back(opToCppName(op));
106 return llvm::join(names,
"::");
110static TypeStrings getStrings(irdl::TypeOp type) {
112 strings.typeName = type.getSymName();
113 strings.typeCppName = typeToCppName(type);
118static OpStrings getStrings(irdl::OperationOp op) {
119 auto operandOp = op.getOp<irdl::OperandsOp>();
120 auto resultOp = op.getOp<irdl::ResultsOp>();
121 auto regionsOp = op.getOp<irdl::RegionsOp>();
124 strings.opName = op.getSymName();
125 strings.opNameSpaces = opToCppNamespaces(op);
126 strings.opCppName = opToCppName(op);
127 strings.opScopedCppName = opToScopedCppName(op);
131 llvm::map_range(operandOp->getNames(), [](
Attribute attr) {
132 return llvm::formatv(
"{0}", cast<StringAttr>(attr));
138 llvm::map_range(resultOp->getNames(), [](
Attribute attr) {
139 return llvm::formatv(
"{0}", cast<StringAttr>(attr));
145 llvm::map_range(regionsOp->getNames(), [](
Attribute attr) {
146 return llvm::formatv(
"{0}", cast<StringAttr>(attr));
155 const TypeStrings &strings) {
156 dict[
"TYPE_NAME"] = strings.typeName;
157 dict[
"TYPE_CPP_NAME"] = strings.typeCppName;
162 const auto operandCount = strings.opOperandNames.size();
163 const auto resultCount = strings.opResultNames.size();
164 const auto regionCount = strings.opRegionNames.size();
166 dict[
"OP_NAME"] = strings.opName;
167 dict[
"OP_CPP_NAME"] = strings.opCppName;
168 dict[
"OP_SCOPED_CPP_NAME"] = strings.opScopedCppName;
169 dict[
"OP_OPERAND_COUNT"] = std::to_string(strings.opOperandNames.size());
170 dict[
"OP_RESULT_COUNT"] = std::to_string(strings.opResultNames.size());
171 dict[
"OP_OPERAND_INITIALIZER_LIST"] =
172 operandCount ? joinNameList(strings.opOperandNames) :
"{\"\"}";
173 dict[
"OP_RESULT_INITIALIZER_LIST"] =
174 resultCount ? joinNameList(strings.opResultNames) :
"{\"\"}";
175 dict[
"OP_REGION_COUNT"] = std::to_string(regionCount);
176 dict[
"NAMESPACE_OPEN"] =
177 (dict[
"NAMESPACE_OPEN"] +
178 llvm::join(llvm::map_range(strings.opNameSpaces,
179 [](llvm::StringRef ref) -> std::string {
180 return llvm::formatv(
"namespace {0} {{",
185 dict[
"NAMESPACE_PATH"] =
186 (dict[
"NAMESPACE_PATH"] +
187 llvm::join(llvm::map_range(strings.opNameSpaces,
188 [](llvm::StringRef ref) -> std::string {
189 return llvm::formatv(
"::{0}", ref);
193 dict[
"NAMESPACE_CLOSE"] =
194 (llvm::join(llvm::map_range(llvm::reverse(strings.opNameSpaces),
195 [](llvm::StringRef ref) -> std::string {
196 return llvm::formatv(
"} // namespace {0}\n",
200 dict[
"NAMESPACE_CLOSE"])
206 const DialectStrings &strings) {
207 dict[
"DIALECT_NAME"] = strings.dialectName;
208 dict[
"DIALECT_BASE_TYPE_NAME"] = strings.dialectBaseTypeName;
209 dict[
"DIALECT_CPP_NAME"] = strings.dialectCppName;
210 dict[
"DIALECT_CPP_SHORT_NAME"] = strings.dialectCppShortName;
211 dict[
"NAMESPACE_OPEN"] = strings.namespaceOpen;
212 dict[
"NAMESPACE_CLOSE"] = strings.namespaceClose;
213 dict[
"NAMESPACE_PATH"] = strings.namespacePath;
216static LogicalResult generateTypedefList(irdl::DialectOp &dialect,
218 auto typeOps = dialect.getOps<irdl::TypeOp>();
219 auto range = llvm::map_range(typeOps, typeToCppName);
224static LogicalResult generateOpList(irdl::DialectOp &dialect,
226 auto operationOps = dialect.getOps<irdl::OperationOp>();
227 auto range = llvm::map_range(operationOps, opToScopedCppName);
237#include
"Templates/TypeDecl.txt"
240 fillDict(dict, getStrings(type));
241 typeDeclTemplate.render(output, dict);
247 const OpStrings &opStrings) {
248 auto opGetters = std::string{};
249 auto resGetters = std::string{};
250 auto regionGetters = std::string{};
251 auto regionAdaptorGetters = std::string{};
253 for (
size_t i = 0, end = opStrings.opOperandNames.size(); i < end; ++i) {
255 llvm::convertToCamelFromSnakeCase(opStrings.opOperandNames[i],
true);
256 opGetters += llvm::formatv(
"::mlir::Value get{0}() { return "
257 "getStructuredOperands({1}).front(); }\n ",
260 for (
size_t i = 0, end = opStrings.opResultNames.size(); i < end; ++i) {
262 llvm::convertToCamelFromSnakeCase(opStrings.opResultNames[i],
true);
263 resGetters += llvm::formatv(
264 R
"(::mlir::Value get{0}() { return ::llvm::cast<::mlir::Value>(getStructuredResults({1}).front()); }
269 for (
size_t i = 0, end = opStrings.opRegionNames.size(); i < end; ++i) {
271 llvm::convertToCamelFromSnakeCase(opStrings.opRegionNames[i],
true);
272 regionAdaptorGetters += llvm::formatv(
273 R
"(::mlir::Region &get{0}() { return *getRegions()[{1}]; }
276 regionGetters += llvm::formatv(
277 R"(::mlir::Region &get{0}() { return (*this)->getRegion({1}); }
282 dict["OP_OPERAND_GETTER_DECLS"] = opGetters;
283 dict[
"OP_RESULT_GETTER_DECLS"] = resGetters;
284 dict[
"OP_REGION_ADAPTER_GETTER_DECLS"] = regionAdaptorGetters;
285 dict[
"OP_REGION_GETTER_DECLS"] = regionGetters;
289 const OpStrings &opStrings) {
290 std::string buildDecls;
291 llvm::raw_string_ostream stream{buildDecls};
294 llvm::join(llvm::map_range(opStrings.opResultNames,
295 [](StringRef name) -> std::string {
296 return llvm::formatv(
297 "::mlir::Type {0}, ",
298 llvm::convertToCamelFromSnakeCase(name));
303 llvm::join(llvm::map_range(opStrings.opOperandNames,
304 [](StringRef name) -> std::string {
305 return llvm::formatv(
306 "::mlir::Value {0}, ",
307 llvm::convertToCamelFromSnakeCase(name));
311 stream << llvm::formatv(
312 R
"(static void build(::mlir::OpBuilder &opBuilder, ::mlir::OperationState &opState, {0} {1} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
313 resultParams, operandParams);
315 stream << llvm::formatv(
316 R
"(static {0} create(::mlir::OpBuilder &opBuilder, ::mlir::Location location, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
317 opStrings.opCppName, resultParams, operandParams);
319 stream << llvm::formatv(
320 R
"(static {0} create(::mlir::ImplicitLocOpBuilder &opBuilder, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {{});)",
321 opStrings.opCppName, resultParams, operandParams);
323 dict[
"OP_BUILD_DECLS"] = buildDecls;
328 const OpStrings &strings) {
330 if (!strings.opRegionNames.empty()) {
331 cppTraitNames.push_back(
332 llvm::formatv(
"::mlir::OpTrait::NRegions<{0}>::Impl",
333 strings.opRegionNames.size())
337 cppTraitNames.emplace_back(
"::mlir::OpTrait::OpInvariants");
339 return cppTraitNames;
346#include
"Templates/PerOperationDecl.txt"
348 const auto opStrings = getStrings(op);
350 fillDict(opDict, opStrings);
353 if (traitNames.empty())
354 opDict[
"OP_TEMPLATE_ARGS"] = opStrings.opCppName;
356 opDict[
"OP_TEMPLATE_ARGS"] = llvm::formatv(
"{0}, {1}", opStrings.opCppName,
357 llvm::join(traitNames,
", "));
362 perOpDeclTemplate.render(output, opDict);
368 DialectStrings &dialectStrings) {
370#include
"Templates/DialectDecl.txt"
373#include
"Templates/TypeHeaderDecl.txt"
377 fillDict(dict, dialectStrings);
379 dialectDeclTemplate.render(output, dict);
380 typeHeaderDeclTemplate.render(output, dict);
382 auto typeOps = dialect.getOps<irdl::TypeOp>();
383 auto operationOps = dialect.getOps<irdl::OperationOp>();
385 for (
auto &&typeOp : typeOps) {
391 if (
failed(generateOpList(dialect, opNames)))
394 auto classDeclarations =
395 llvm::join(llvm::map_range(
397 [](llvm::StringRef name) -> std::string {
398 if (name.contains(
"::")) {
399 auto [scope, className] = name.rsplit(
"::");
400 return llvm::formatv(
"namespace {0} {{\nclass {1};\n}",
403 return llvm::formatv(
"class {0};", name);
406 const auto forwardDeclarations = llvm::formatv(
407 "{1}\n{0}\n{2}", std::move(classDeclarations),
408 dialectStrings.namespaceOpen, dialectStrings.namespaceClose);
410 output << forwardDeclarations;
411 for (
auto &&operationOp : operationOps) {
423 auto regionsOp = op.getOp<irdl::RegionsOp>();
424 if (strings.opRegionNames.empty() || !regionsOp)
427 for (
size_t i = 0; i < strings.opRegionNames.size(); ++i) {
428 std::string regionName = strings.opRegionNames[i];
429 std::string helperFnName =
430 llvm::formatv(
"__mlir_irdl_local_region_constraint_{0}_{1}",
431 strings.opCppName, regionName)
435 std::string condition =
"true";
436 std::string textualConditionName =
"any region";
438 if (
auto regionDefOp =
439 regionsOp->getArgs()[i].getDefiningOp<irdl::RegionOp>()) {
445 if (
auto blockCount = regionDefOp.getNumberOfBlocks()) {
446 conditionParts.push_back(
447 llvm::formatv(
"region.getBlocks().size() == {0}",
450 descriptionParts.push_back(
451 llvm::formatv(
"exactly {0} block(s)", blockCount.value()).str());
455 if (regionDefOp.getConstrainedArguments()) {
456 size_t expectedArgCount = regionDefOp.getEntryBlockArgs().size();
457 conditionParts.push_back(
458 llvm::formatv(
"region.getNumArguments() == {0}", expectedArgCount)
460 descriptionParts.push_back(
461 llvm::formatv(
"{0} entry block argument(s)", expectedArgCount)
466 if (!conditionParts.empty()) {
467 condition = llvm::join(conditionParts,
" && ");
471 if (!descriptionParts.empty()) {
472 textualConditionName =
473 llvm::formatv(
"region with {0}",
474 llvm::join(descriptionParts,
" and "))
479 verifierHelpers.push_back(llvm::formatv(
480 R
"(static ::llvm::LogicalResult {0}(::mlir::Operation *op, ::mlir::Region ®ion, ::llvm::StringRef regionName, unsigned regionIndex) {{
482 return op->emitOpError("region #") << regionIndex
483 << (regionName.empty() ? " " : " ('" + regionName + "') ")
484 << "failed to verify constraint: {2}";
486 return ::mlir::success();
488 helperFnName, condition, textualConditionName));
490 verifierCalls.push_back(llvm::formatv(R"(
491 if (::mlir::failed({0}(*this, (*this)->getRegion({1}), "{2}", {1})))
492 return ::mlir::failure();)",
493 helperFnName, i, regionName)
499 irdl::OperationOp op,
const OpStrings &strings) {
507 std::string verifierDef =
509::llvm::LogicalResult {0}::verifyInvariantsImpl() {{
510 if(::mlir::failed(verify()))
511 return ::mlir::failure();
515 return ::mlir::success();
517 strings.opCppName, llvm::join(verifierCalls, "\n"));
519 dict[
"OP_VERIFIER_HELPERS"] = llvm::join(verifierHelpers,
"\n");
520 dict[
"OP_VERIFIER"] = verifierDef;
524 irdl::OperationOp op) {
526#include "Templates/PerOperationDef.txt"
529 auto opStrings = getStrings(op);
531 fillDict(opDict, opStrings);
533 auto resultTypes = llvm::join(
534 llvm::map_range(opStrings.opResultNames,
535 [](StringRef attr) -> std::string {
536 return llvm::formatv(
"::mlir::Type {0}, ", attr);
539 auto operandTypes = llvm::join(
540 llvm::map_range(opStrings.opOperandNames,
541 [](StringRef attr) -> std::string {
542 return llvm::formatv(
"::mlir::Value {0}, ", attr);
546 llvm::join(llvm::map_range(opStrings.opOperandNames,
547 [](StringRef attr) -> std::string {
548 return llvm::formatv(
549 " opState.addOperands({0});", attr);
552 auto resultAdder = llvm::join(
553 llvm::map_range(opStrings.opResultNames,
554 [](StringRef attr) -> std::string {
555 return llvm::formatv(
" opState.addTypes({0});", attr);
559 const auto buildDefinition = llvm::formatv(
561void {0}::build(::mlir::OpBuilder &opBuilder, ::mlir::OperationState &opState, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {{
566{0} {0}::create(::mlir::OpBuilder &opBuilder, ::mlir::Location location, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {{
567 ::mlir::OperationState __state__(location, getOperationName());
568 build(opBuilder, __state__, {5} {6} attributes);
569 auto __res__ = opBuilder.create(__state__);
570 assert((::llvm::isa<{0}>(__res__)) && "builder didn't return the right type");
571 return ::llvm::cast<{0}>(__res__);
574{0} {0}::create(::mlir::ImplicitLocOpBuilder &opBuilder, {1} {2} ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) {{
575 return create(opBuilder, opBuilder.getLoc(), {5} {6} attributes);
578 opStrings.opCppName, std::move(resultTypes), std::move(operandTypes),
579 std::move(operandAdder), std::move(resultAdder),
580 llvm::join(opStrings.opResultNames, ",") +
581 (!opStrings.opResultNames.empty() ?
"," :
""),
582 llvm::join(opStrings.opOperandNames,
",") +
583 (!opStrings.opOperandNames.empty() ?
"," :
""));
585 opDict[
"OP_BUILD_DEFS"] = buildDefinition;
590 llvm::raw_string_ostream stream{str};
591 perOpDefTemplate.render(stream, opDict);
597 return llvm::formatv(
598 R
"(.Case({1}::{0}::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
599value = {1}::{0}::get(parser.getContext());
600return ::mlir::success(!!value);
602 name, dialectStrings.namespacePath);
606 DialectStrings &dialectStrings) {
609#include "Templates/TypeHeaderDef.txt"
612#include "Templates/TypeDef.txt"
615#include "Templates/DialectDef.txt"
619 fillDict(dict, dialectStrings);
621 typeHeaderDefTemplate.render(output, dict);
624 if (
failed(generateTypedefList(dialect, typeNames)))
627 dict[
"TYPE_LIST"] = llvm::join(
628 llvm::map_range(typeNames,
629 [&dialectStrings](llvm::StringRef name) -> std::string {
630 return llvm::formatv(
631 "{0}::{1}", dialectStrings.namespacePath, name);
635 auto typeVerifierGenerator =
636 [&dialectStrings](llvm::StringRef name) -> std::string {
641 llvm::join(llvm::map_range(typeNames, typeVerifierGenerator),
"\n");
643 dict[
"TYPE_PARSER"] = llvm::formatv(
644 R
"(static ::mlir::OptionalParseResult generatedTypeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type &value) {
645 return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
647 .Default([&](llvm::StringRef keyword, llvm::SMLoc) {{
652 std::move(typeCase));
655 llvm::join(llvm::map_range(typeNames,
656 [&](llvm::StringRef name) -> std::string {
657 return llvm::formatv(
658 R
"(.Case<{1}::{0}>([&](auto t) {
659 printer << {1}::{0}::getMnemonic();
660 return ::mlir::success();
662 name, dialectStrings.namespacePath);
665 dict[
"TYPE_PRINTER"] = llvm::formatv(
666 R
"(static ::llvm::LogicalResult generatedTypePrinter(::mlir::Type def, ::mlir::AsmPrinter &printer) {
667 return ::llvm::TypeSwitch<::mlir::Type, ::llvm::LogicalResult>(def)
669 .Default([](auto) {{ return ::mlir::failure(); });
671 std::move(typePrintCase));
673 dict["TYPE_DEFINES"] =
674 join(map_range(typeNames,
675 [&](StringRef name) -> std::string {
676 return formatv(
"MLIR_DEFINE_EXPLICIT_TYPE_ID({1}::{0})",
677 name, dialectStrings.namespacePath);
681 typeDefTemplate.render(output, dict);
683 auto operations = dialect.getOps<irdl::OperationOp>();
685 if (
failed(generateOpList(dialect, opNames)))
688 const auto commaSeparatedOpList = llvm::join(
690 [&dialectStrings](llvm::StringRef name) -> std::string {
691 return llvm::formatv(
"{0}::{1}", dialectStrings.namespacePath,
696 const auto opDefinitionGenerator = [&dict](irdl::OperationOp op) {
700 const auto perOpDefinitions =
701 llvm::join(llvm::map_range(operations, opDefinitionGenerator),
"\n");
703 dict[
"OP_LIST"] = commaSeparatedOpList;
704 dict[
"OP_CLASSES"] = perOpDefinitions;
705 output << perOpDefinitions;
706 dialectDefTemplate.render(output, dict);
716 .Case(([](irdl::DialectOp) {
return success(); }))
717 .Case(([](irdl::OperationOp) {
return success(); }))
718 .Case(([](irdl::TypeOp) {
return success(); }))
719 .Case(([](irdl::OperandsOp op) -> LogicalResult {
721 op.getVariadicity(), [](irdl::VariadicityAttr attr) {
722 return attr.getValue() == irdl::Variadicity::single;
725 return op.emitError(
"IRDL C++ translation does not yet support "
726 "variadic operations");
728 .Case(([](irdl::ResultsOp op) -> LogicalResult {
730 op.getVariadicity(), [](irdl::VariadicityAttr attr) {
731 return attr.getValue() == irdl::Variadicity::single;
735 "IRDL C++ translation does not yet support variadic results");
737 .Case(([](irdl::AnyOp) {
return success(); }))
738 .Case(([](irdl::RegionOp) {
return success(); }))
739 .Case(([](irdl::RegionsOp) {
return success(); }))
741 return op->
emitError(
"IRDL C++ translation does not yet support "
743 << op->
getName() <<
" operation";
758 static const auto typeDefTempl = detail::Template(
759#include
"Templates/TypeDef.txt"
762 llvm::SmallMapVector<DialectOp, DialectStrings, 2> dialectStringTable;
764 for (
auto dialect : dialects) {
768 StringRef dialectName = dialect.getSymName();
771 std::string namespaceOpen;
772 std::string namespaceClose;
773 std::string namespacePath;
774 llvm::raw_string_ostream namespaceOpenStream(namespaceOpen);
775 llvm::raw_string_ostream namespaceCloseStream(namespaceClose);
776 llvm::raw_string_ostream namespacePathStream(namespacePath);
777 for (
auto &pathElement : namespaceAbsolutePath) {
778 namespaceOpenStream <<
"namespace " << pathElement <<
" {\n";
779 namespacePathStream <<
"::" << pathElement;
782 for (
auto &pathElement : llvm::reverse(namespaceAbsolutePath))
783 namespaceCloseStream <<
"} // namespace " << pathElement <<
"\n";
785 std::string cppShortName =
786 llvm::convertToCamelFromSnakeCase(dialectName,
true);
787 std::string dialectBaseTypeName = llvm::formatv(
"{0}Type", cppShortName);
788 std::string cppName = llvm::formatv(
"{0}Dialect", cppShortName);
790 DialectStrings dialectStrings;
791 dialectStrings.dialectName = dialectName;
792 dialectStrings.dialectBaseTypeName = std::move(dialectBaseTypeName);
793 dialectStrings.dialectCppName = std::move(cppName);
794 dialectStrings.dialectCppShortName = std::move(cppShortName);
795 dialectStrings.namespaceOpen = std::move(namespaceOpen);
796 dialectStrings.namespaceClose = std::move(namespaceClose);
797 dialectStrings.namespacePath = std::move(namespacePath);
799 dialectStringTable[dialect] = std::move(dialectStrings);
806 for (
auto dialect : dialects) {
808 auto &dialectStrings = dialectStringTable[dialect];
809 auto &dialectName = dialectStrings.dialectName;
812 return dialect->emitError(
"Error in Dialect " + dialectName +
813 " while generating headers");
818 for (
auto &dialect : dialects) {
819 auto &dialectStrings = dialectStringTable[dialect];
820 auto &dialectName = dialectStrings.dialectName;
823 return dialect->emitError(
"Error in Dialect " + dialectName +
824 " while generating library");
std::string join(const Ts &...args)
Helper function to concatenate arguments into a std::string.
static LogicalResult verifySupported(irdl::DialectOp dialect)
static LogicalResult generateInclude(irdl::DialectOp dialect, raw_ostream &output, DialectStrings &dialectStrings)
static void generateOpGetterDeclarations(irdl::detail::dictionary &dict, const OpStrings &opStrings)
static SmallVector< std::string > generateTraits(irdl::OperationOp op, const OpStrings &strings)
static void generateOpBuilderDeclarations(irdl::detail::dictionary &dict, const OpStrings &opStrings)
constexpr char declarationMacroFlag[]
constexpr char headerTemplateText[]
static std::string generateTypeVerifierCase(StringRef name, const DialectStrings &dialectStrings)
static LogicalResult generateTypeInclude(irdl::TypeOp type, raw_ostream &output, irdl::detail::dictionary &dict)
static LogicalResult generateOperationInclude(irdl::OperationOp op, raw_ostream &output, const irdl::detail::dictionary &dict)
static void generateRegionConstraintVerifiers(irdl::detail::dictionary &dict, irdl::OperationOp op, const OpStrings &strings, SmallVectorImpl< std::string > &verifierHelpers, SmallVectorImpl< std::string > &verifierCalls)
static LogicalResult generateLib(irdl::DialectOp dialect, raw_ostream &output, DialectStrings &dialectStrings)
constexpr char definitionMacroFlag[]
static std::string generateOpDefinition(irdl::detail::dictionary &dict, irdl::OperationOp op)
static void generateVerifiers(irdl::detail::dictionary &dict, irdl::OperationOp op, const OpStrings &strings)
Attributes are known-constant values of operations.
Operation is the basic unit of execution within MLIR.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
OperationName getName()
The name of an operation is the key identifier for it.
static WalkResult advance()
static WalkResult interrupt()
Template Code as used by IRDL-to-Cpp.
llvm::StringMap< llvm::SmallString< 8 > > dictionary
A dictionary stores a mapping of template variable names to their assigned string values.
LogicalResult translateIRDLDialectToCpp(llvm::ArrayRef< irdl::DialectOp > dialects, raw_ostream &output)
Translates an IRDL dialect definition to a C++ definition that can be used with MLIR.
Include the generated interface declarations.