This upstreams the Cpp emitter, initially presented with [1], from [2] to MLIR core. Together with the previously upstreamed EmitC dialect [3], the target allows to translate MLIR to C/C++. [1] https://reviews.llvm.org/D76571 [2] https://github.com/iml130/mlir-emitc [3] https://reviews.llvm.org/D103969 Co-authored-by: Jacques Pienaar <jpienaar@google.com> Co-authored-by: Simon Camphausen <simon.camphausen@iml.fraunhofer.de> Co-authored-by: Oliver Scherf <oliver.scherf@iml.fraunhofer.de> Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D104632
49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
//===- TranslateRegistration.cpp - Register translation -------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/EmitC/IR/EmitC.h"
|
|
#include "mlir/Dialect/SCF/SCF.h"
|
|
#include "mlir/Dialect/StandardOps/IR/Ops.h"
|
|
#include "mlir/IR/BuiltinOps.h"
|
|
#include "mlir/IR/Dialect.h"
|
|
#include "mlir/Target/Cpp/CppEmitter.h"
|
|
#include "mlir/Translation.h"
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
using namespace mlir;
|
|
|
|
namespace mlir {
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Cpp registration
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void registerToCppTranslation() {
|
|
static llvm::cl::opt<bool> declareVariablesAtTop(
|
|
"declare-variables-at-top",
|
|
llvm::cl::desc("Declare variables at top when emitting C/C++"),
|
|
llvm::cl::init(false));
|
|
|
|
TranslateFromMLIRRegistration reg(
|
|
"mlir-to-cpp",
|
|
[](ModuleOp module, raw_ostream &output) {
|
|
return emitc::translateToCpp(
|
|
module, output,
|
|
/*declareVariablesAtTop=*/declareVariablesAtTop);
|
|
},
|
|
[](DialectRegistry ®istry) {
|
|
// clang-format off
|
|
registry.insert<emitc::EmitCDialect,
|
|
StandardOpsDialect,
|
|
scf::SCFDialect>();
|
|
// clang-format on
|
|
});
|
|
}
|
|
|
|
} // namespace mlir
|