15 using namespace circt;
22 if (pat->matchStatement(op)) {
23 pat->emitStatement(op, *
this);
30 mlir::emitError(op->getLoc(),
"no emission pattern found for '")
31 << op->getName() <<
"'\n";
32 os <<
"\n<<UNSUPPORTED OPERATION (" << op->getName() <<
")>>\n";
40 if (pat->match(type)) {
41 pat->emitType(type, *
this);
48 mlir::emitError(
currentLoc,
"no emission pattern found for type ")
50 os <<
"<<UNSUPPORTED TYPE (" << type <<
")>>";
58 if (pat->match(attr)) {
59 pat->emitAttr(attr, *
this);
64 mlir::emitError(
currentLoc,
"no emission pattern found for attribute ")
66 os <<
"<<UNSUPPORTED ATTRIBUTE (" << attr <<
")>>";
71 auto *op = isa<BlockArgument>(value) ? value.getParentRegion()->getParentOp()
72 : value.getDefiningOp();
79 return InlineEmitter([=]() { pat->emitInlined(value, *
this); },
88 mlir::emitError(value.getLoc(),
"inlining not supported for value '")
90 err.attachNote(requestLoc) <<
"requested to be inlined here";
92 [=]() {
os <<
"<<INVALID VALUE TO INLINE (" << value <<
")>>"; },
97 auto scope =
os.scope(
"{\n",
"}\n");
102 Region ®ion, mlir::raw_indented_ostream::DelimitedScope &scope) {
103 assert(region.hasOneBlock() &&
104 "only regions with exactly one block are supported for now");
106 for (Operation &op : region.getBlocks().front()) {
112 const Twine &message) {
114 os <<
"<<ERROR (" << message <<
")>>";
115 return op->emitOpError();
120 os <<
"<<ERROR (" << message <<
")>>";
130 os << std::to_string(num);
136 StringRef rParen)
const {
assert(baseType &&"element must be base type")
This is intended to be the driving class for all pattern-based IR emission.
void emitRegion(Region ®ion)
Emit the given region to the ostream associated with this printer.
void emitOp(Operation *op)
Emit the given operation as a statement to the ostream associated with this printer according to the ...
FrozenAttrEmissionPatternSet attrPatterns
InlineEmitter getInlinable(Value value)
Emit the expression represented by the given value to the ostream associated with this printer accord...
void emitAttr(Attribute attr)
Emit the given attribute to the ostream associated with this printer according to the emission patter...
EmissionPrinter & operator<<(StringRef str)
FrozenTypeEmissionPatternSet typePatterns
void emitType(Type type)
Emit the given type to the ostream associated with this printer according to the emission patterns re...
InFlightDiagnostic emitError(Operation *op, const Twine &message)
Emit an error on the operation and fail emission.
mlir::raw_indented_ostream & os
FrozenOpEmissionPatternSet opPatterns
const OpSpecificNativePatternListT & getSpecificNativePatterns() const
Return the native patterns held by this set.
This class is returned to a pattern that requested inlined emission of a value.
EmissionPrinter & printer
std::function< void()> emitter
void emitWithParensOnLowerPrecedence(Precedence prec, StringRef lParen="(", StringRef rParen=")") const
This class allows a pattern's match function for inlining to pass its result's precedence to the patt...
Precedence getPrecedence() const
Precedence
This enum encodes the precedence of C++ expressions.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.