14 #include "../EmissionPrinter.h"
15 #include "mlir/Dialect/EmitC/IR/EmitC.h"
16 #include "llvm/ADT/SmallString.h"
18 using namespace mlir::emitc;
19 using namespace circt;
29 using OpEmissionPattern::OpEmissionPattern;
32 p <<
"#include " << (op.getIsStandardInclude() ?
"<" :
"\"")
33 << op.getInclude() << (op.getIsStandardInclude() ?
">" :
"\"") <<
"\n";
39 using OpEmissionPattern::OpEmissionPattern;
42 if (value.getDefiningOp<ApplyOp>()) {
47 return Precedence::ADDRESS_OF;
53 auto applyOp = value.getDefiningOp<ApplyOp>();
54 p << applyOp.getApplicableOperator();
56 .emitWithParensOnLowerPrecedence(Precedence::ADDRESS_OF);
68 using OpEmissionPattern::OpEmissionPattern;
71 if (
auto callOp = value.getDefiningOp<CallOpaqueOp>()) {
73 if (callOp->getNumResults() == 1 && !callOp.getTemplateArgs())
74 return Precedence::FUNCTION_CALL;
80 printCallOp(value.getDefiningOp<CallOpaqueOp>(), p);
83 bool matchStatement(Operation *op)
override {
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);
129 using OpEmissionPattern::OpEmissionPattern;
132 if (value.getDefiningOp<CastOp>())
133 return Precedence::CAST;
138 auto castOp = value.getDefiningOp<CastOp>();
140 p.
emitType(castOp.getDest().getType());
143 .emitWithParensOnLowerPrecedence(Precedence::CAST);
149 using OpEmissionPattern::OpEmissionPattern;
152 if (value.getDefiningOp<ConstantOp>())
153 return Precedence::LIT;
158 p.
emitAttr(value.getDefiningOp<ConstantOp>().getValue());
164 using OpEmissionPattern::OpEmissionPattern;
167 if (
auto varOp = value.getDefiningOp<VariableOp>()) {
168 if (!varOp->getAttrOfType<StringAttr>(
"name"))
170 return Precedence::VAR;
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.
This is a convenience class providing default implementations for operation emission patterns.
This is a convenience class providing default implementations for type emission patterns.