|
14 | 14 | #include "mlir/IR/BuiltinTypes.h"
|
15 | 15 | #include "mlir/IR/Dialect.h"
|
16 | 16 | #include "mlir/IR/Operation.h"
|
| 17 | +#include "mlir/IR/SymbolTable.h" |
17 | 18 | #include "mlir/Support/IndentedOstream.h"
|
18 | 19 | #include "mlir/Support/LLVM.h"
|
19 | 20 | #include "mlir/Target/Cpp/CppEmitter.h"
|
@@ -855,8 +856,9 @@ static LogicalResult printFunctionBody(CppEmitter &emitter,
|
855 | 856 | // needs to be printed after the closing brace.
|
856 | 857 | // When generating code for an emitc.for and emitc.verbatim op, printing a
|
857 | 858 | // trailing semicolon is handled within the printOperation function.
|
858 |
| - bool trailingSemicolon = !isa<cf::CondBranchOp, emitc::ForOp, emitc::IfOp, |
859 |
| - emitc::LiteralOp, emitc::VerbatimOp>(op); |
| 859 | + bool trailingSemicolon = |
| 860 | + !isa<cf::CondBranchOp, emitc::DeclareFuncOp, emitc::ForOp, |
| 861 | + emitc::IfOp, emitc::LiteralOp, emitc::VerbatimOp>(op); |
860 | 862 |
|
861 | 863 | if (failed(emitter.emitOperation(
|
862 | 864 | op, /*trailingSemicolon=*/trailingSemicolon)))
|
@@ -938,6 +940,37 @@ static LogicalResult printOperation(CppEmitter &emitter,
|
938 | 940 | return success();
|
939 | 941 | }
|
940 | 942 |
|
| 943 | +static LogicalResult printOperation(CppEmitter &emitter, |
| 944 | + DeclareFuncOp declareFuncOp) { |
| 945 | + CppEmitter::Scope scope(emitter); |
| 946 | + raw_indented_ostream &os = emitter.ostream(); |
| 947 | + |
| 948 | + auto functionOp = SymbolTable::lookupNearestSymbolFrom<emitc::FuncOp>( |
| 949 | + declareFuncOp, declareFuncOp.getSymNameAttr()); |
| 950 | + |
| 951 | + if (!functionOp) |
| 952 | + return failure(); |
| 953 | + |
| 954 | + if (functionOp.getSpecifiers()) { |
| 955 | + for (Attribute specifier : functionOp.getSpecifiersAttr()) { |
| 956 | + os << cast<StringAttr>(specifier).str() << " "; |
| 957 | + } |
| 958 | + } |
| 959 | + |
| 960 | + if (failed(emitter.emitTypes(functionOp.getLoc(), |
| 961 | + functionOp.getFunctionType().getResults()))) |
| 962 | + return failure(); |
| 963 | + os << " " << functionOp.getName(); |
| 964 | + |
| 965 | + os << "("; |
| 966 | + Operation *operation = functionOp.getOperation(); |
| 967 | + if (failed(printFunctionArgs(emitter, operation, functionOp.getArguments()))) |
| 968 | + return failure(); |
| 969 | + os << ");"; |
| 970 | + |
| 971 | + return success(); |
| 972 | +} |
| 973 | + |
941 | 974 | CppEmitter::CppEmitter(raw_ostream &os, bool declareVariablesAtTop)
|
942 | 975 | : os(os), declareVariablesAtTop(declareVariablesAtTop) {
|
943 | 976 | valueInScopeCount.push(0);
|
@@ -1251,10 +1284,10 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
|
1251 | 1284 | // EmitC ops.
|
1252 | 1285 | .Case<emitc::AddOp, emitc::ApplyOp, emitc::AssignOp, emitc::CallOp,
|
1253 | 1286 | emitc::CallOpaqueOp, emitc::CastOp, emitc::CmpOp,
|
1254 |
| - emitc::ConstantOp, emitc::DivOp, emitc::ExpressionOp, |
1255 |
| - emitc::ForOp, emitc::FuncOp, emitc::IfOp, emitc::IncludeOp, |
1256 |
| - emitc::MulOp, emitc::RemOp, emitc::ReturnOp, emitc::SubOp, |
1257 |
| - emitc::VariableOp, emitc::VerbatimOp>( |
| 1287 | + emitc::ConstantOp, emitc::DeclareFuncOp, emitc::DivOp, |
| 1288 | + emitc::ExpressionOp, emitc::ForOp, emitc::FuncOp, emitc::IfOp, |
| 1289 | + emitc::IncludeOp, emitc::MulOp, emitc::RemOp, emitc::ReturnOp, |
| 1290 | + emitc::SubOp, emitc::VariableOp, emitc::VerbatimOp>( |
1258 | 1291 | [&](auto op) { return printOperation(*this, op); })
|
1259 | 1292 | // Func ops.
|
1260 | 1293 | .Case<func::CallOp, func::ConstantOp, func::FuncOp, func::ReturnOp>(
|
|
0 commit comments