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<ApplyOp>()) {
53 auto applyOp = value.getDefiningOp<ApplyOp>();
54 p << applyOp.getApplicableOperator();
56 .emitWithParensOnLowerPrecedence(Precedence::ADDRESS_OF);
71 if (
auto callOp = value.getDefiningOp<CallOpaqueOp>()) {
73 if (callOp->getNumResults() == 1 && !callOp.getTemplateArgs())
80 printCallOp(value.getDefiningOp<CallOpaqueOp>(), p);
85 if (
auto callOp = dyn_cast<CallOpaqueOp>(op))
86 return callOp->getNumResults() <= 1 && !callOp.getTemplateArgs();
91 if (callOp->getNumResults() != 0)
94 printCallOp(callOp, p);
100 p << callOp.getCallee();
104 if (!callOp.getArgs()) {
105 llvm::interleaveComma(callOp.getOperands(), p, [&](Value operand) {
106 p.getInlinable(operand).emitWithParensOnLowerPrecedence(
110 llvm::interleaveComma(callOp.getArgs().value(), p, [&](Attribute attr) {
111 if (auto idx = dyn_cast<IntegerAttr>(attr)) {
112 if (isa<IndexType>(idx.getType())) {
113 p.getInlinable(callOp.getOperands()[idx.getInt()])
114 .emitWithParensOnLowerPrecedence(Precedence::COMMA);
132 if (value.getDefiningOp<CastOp>())
138 auto castOp = value.getDefiningOp<CastOp>();
140 p.
emitType(castOp.getDest().getType());
143 .emitWithParensOnLowerPrecedence(Precedence::CAST);
152 if (value.getDefiningOp<ConstantOp>())
158 p.
emitAttr(value.getDefiningOp<ConstantOp>().getValue());
167 if (
auto varOp = value.getDefiningOp<VariableOp>()) {
168 if (!varOp->getAttrOfType<StringAttr>(
"name"))
176 p << value.getDefiningOp()->getAttrOfType<StringAttr>(
"name").getValue();
180 p.
emitType(op.getResult().getType());
181 p <<
" " << op->getAttrOfType<StringAttr>(
"name").getValue();
202 p << type.getValue();
228 p << attr.getValue();
240 patterns.add<IncludeEmitter, ApplyOpEmitter, CallOpEmitter, CastOpEmitter,
246 patterns.add<OpaqueTypeEmitter, PointerTypeEmitter, LValueTypeEmitter>();
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.