13 #include "llvm/Support/ScopedPrinter.h"
14 #include "llvm/Support/raw_ostream.h"
30 std::unique_ptr<AttributeConstraint> &constraint = attributeConstraints[name];
34 assert(constraint->getCppClass() == cppClass &&
35 constraint->getSummary() == summary &&
36 "constraint with the same name was already registered with a "
45 std::unique_ptr<TypeConstraint> &constraint = typeConstraints[name];
52 std::unique_ptr<Dialect> &dialect = dialects[name];
54 dialect.reset(
new Dialect(name));
59 auto it = dialects.find(name);
60 return it == dialects.end() ? nullptr : &*it->second;
63 std::pair<Operation *, bool>
65 StringRef nativeClassName,
66 bool supportsResultTypeInferrence, SMLoc loc) {
67 std::pair<StringRef, StringRef> dialectAndName = name.split(
'.');
70 supportsResultTypeInferrence, loc);
74 std::pair<StringRef, StringRef> dialectAndName = name.split(
'.');
76 return dialect->lookupOperation(name);
83 for (
auto &entry : map)
84 storage.push_back(entry.second.get());
85 llvm::sort(storage, [](
const auto &lhs,
const auto &rhs) {
86 return lhs->getName() < rhs->getName();
95 os <<
"Optional<" << cst <<
">";
101 os <<
"Variadic<" << cst <<
">";
106 llvm::ScopedPrinter printer(os);
107 llvm::DictScope odsScope(printer,
"ODSContext");
109 printer.startLine() <<
"Dialect `" << dialect->getName() <<
"` {\n";
113 printer.startLine() <<
"Operation `" << op->getName() <<
"` {\n";
118 if (!attributes.empty()) {
119 printer.startLine() <<
"Attributes { ";
120 llvm::interleaveComma(attributes, os, [&](
const Attribute &attr) {
132 if (!operands.empty()) {
133 printer.startLine() <<
"Operands { ";
134 llvm::interleaveComma(
136 os << operand.
getName() <<
" : ";
145 if (!results.empty()) {
146 printer.startLine() <<
"Results { ";
147 llvm::interleaveComma(results, os, [&](
const OperandOrResult &result) {
148 os << result.
getName() <<
" : ";
160 printer.startLine() <<
"AttributeConstraint `" << cst->getDemangledName()
164 printer.startLine() <<
"Summary: " << cst->getSummary() <<
"\n";
165 printer.startLine() <<
"CppClass: " << cst->getCppClass() <<
"\n";
169 printer.startLine() <<
"TypeConstraint `" << cst->getDemangledName()
173 printer.startLine() <<
"Summary: " << cst->getSummary() <<
"\n";
174 printer.startLine() <<
"CppClass: " << cst->getCppClass() <<
"\n";
SmallVector< T * > sortMapByName(const llvm::StringMap< std::unique_ptr< T >> &map)
This class represents a generic ODS Attribute constraint.
This class provides an ODS representation of a specific operation attribute.
StringRef getName() const
Return the name of this operand.
const AttributeConstraint & getConstraint() const
Return the constraint of this attribute.
bool isOptional() const
Return true if this attribute is optional.
StringRef getDemangledName() const
Return the demangled name of this constraint.
std::pair< Operation *, bool > insertOperation(StringRef name, StringRef summary, StringRef desc, StringRef nativeClassName, bool supportsResultTypeInferrence, SMLoc loc)
Insert a new operation with the context.
const TypeConstraint & insertTypeConstraint(StringRef name, StringRef summary, StringRef cppClass)
Insert a new type constraint with the context.
Dialect & insertDialect(StringRef name)
Insert a new dialect with the context.
const Dialect * lookupDialect(StringRef name) const
Lookup a dialect registered with the given name, or null if no dialect with that name was inserted.
const AttributeConstraint & insertAttributeConstraint(StringRef name, StringRef summary, StringRef cppClass)
Insert a new attribute constraint with the context.
const Operation * lookupOperation(StringRef name) const
Lookup an operation registered with the given name, or null if no operation with that name is registe...
void print(raw_ostream &os) const
Print the contents of this context to the provided stream.
This class represents an ODS dialect, and contains information on the constructs held within the dial...
std::pair< Operation *, bool > insertOperation(StringRef name, StringRef summary, StringRef desc, StringRef nativeClassName, bool supportsResultTypeInferrence, SMLoc loc)
Insert a new operation with the dialect.
This class provides an ODS representation of a specific operation operand or result.
const TypeConstraint & getConstraint() const
Return the constraint of this value.
VariableLengthKind getVariableLengthKind() const
Returns the variable length kind of this value.
StringRef getName() const
Return the name of this value.
This class provides an ODS representation of a specific operation.
This class represents a generic ODS Type constraint.
Include the generated interface declarations.