14#include "../EmissionPrinter.h"
15#include "mlir/Dialect/EmitC/IR/EmitC.h"
16#include "llvm/ADT/SmallString.h"
18using namespace mlir::emitc;
32 p <<
"#include " << (op.getIsStandardInclude() ?
"<" :
"\"")
33 << op.getInclude() << (op.getIsStandardInclude() ?
">" :
"\"") <<
"\n";
42 if (value.getDefiningOp<AddressOfOp>())
48 auto addressOfOp = value.getDefiningOp<AddressOfOp>();
51 .emitWithParensOnLowerPrecedence(Precedence::ADDRESS_OF);
61 if (value.getDefiningOp<DereferenceOp>())
67 auto dereferenceOp = value.getDefiningOp<DereferenceOp>();
70 .emitWithParensOnLowerPrecedence(Precedence::ADDRESS_OF);
85 if (
auto callOp = value.getDefiningOp<CallOpaqueOp>()) {
87 if (callOp->getNumResults() == 1 && !callOp.getTemplateArgs())
94 printCallOp(value.getDefiningOp<CallOpaqueOp>(), p);
99 if (
auto callOp = dyn_cast<CallOpaqueOp>(op))
100 return callOp->getNumResults() <= 1 && !callOp.getTemplateArgs();
105 if (callOp->getNumResults() != 0)
108 printCallOp(callOp, p);
114 p << callOp.getCallee();
118 if (!callOp.getArgs()) {
119 llvm::interleaveComma(callOp.getOperands(), p, [&](Value operand) {
120 p.getInlinable(operand).emitWithParensOnLowerPrecedence(
124 llvm::interleaveComma(callOp.getArgs().value(), p, [&](Attribute attr) {
125 if (auto idx = dyn_cast<IntegerAttr>(attr)) {
126 if (isa<IndexType>(idx.getType())) {
127 p.getInlinable(callOp.getOperands()[idx.getInt()])
128 .emitWithParensOnLowerPrecedence(Precedence::COMMA);
146 if (value.getDefiningOp<CastOp>())
152 auto castOp = value.getDefiningOp<CastOp>();
154 p.
emitType(castOp.getDest().getType());
157 .emitWithParensOnLowerPrecedence(Precedence::CAST);
166 if (value.getDefiningOp<ConstantOp>())
172 p.
emitAttr(value.getDefiningOp<ConstantOp>().getValue());
181 if (
auto varOp = value.getDefiningOp<VariableOp>()) {
182 if (!varOp->getAttrOfType<StringAttr>(
"name"))
190 p << value.getDefiningOp()->getAttrOfType<StringAttr>(
"name").getValue();
194 p.
emitType(op.getResult().getType());
195 p <<
" " << op->getAttrOfType<StringAttr>(
"name").getValue();
216 p << type.getValue();
242 p << attr.getValue();
254 patterns.add<IncludeEmitter, AddressOfOpEmitter, DereferenceOpEmitter,
261 patterns.add<OpaqueTypeEmitter, PointerTypeEmitter, LValueTypeEmitter>();
static std::unique_ptr< Context > context
This class collects a set of emission patterns with base type 'PatternTy'.
This is intended to be the driving class for all pattern-based IR emission.
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...
void emitType(Type type)
Emit the given type to the ostream associated with this printer according to the emission patterns re...
This class allows a pattern's match function for inlining to pass its result's precedence to the patt...
void populateEmitCOpEmitters(OpEmissionPatternSet &patterns, MLIRContext *context)
Register EmitC operation emission patterns.
void populateEmitCTypeEmitters(TypeEmissionPatternSet &patterns)
Register EmitC type emission patterns.
void populateEmitCAttrEmitters(AttrEmissionPatternSet &patterns)
Register EmitC attribute emission patterns.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Emit a systemc.cpp.variable operation.
This is a convenience class providing default implementations for attribute emission patterns.
void emitAttr(Attribute attr, EmissionPrinter &p) final
Emit the given attribute to the emission printer.
This is a convenience class providing default implementations for operation emission patterns.
OpEmissionPattern(MLIRContext *context)
void emitInlined(mlir::Value value, EmissionPrinter &p) override
Emit the expression for the given value.
bool matchStatement(mlir::Operation *op) override
Checks if this pattern is applicable to the given operation for statement emission.
void emitStatement(mlir::Operation *op, EmissionPrinter &p) final
Emit zero or more statements for the given operation.
MatchResult matchInlinable(Value value) override
Checks if this pattern is applicable to the given value to emit an inlinable expression.
This is a convenience class providing default implementations for type emission patterns.
void emitType(Type type, EmissionPrinter &p) final
Emit the given type to the emission printer.