1//===- TranslateRegistration.cpp - Register translation -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "mlir/Dialect/ControlFlow/IR/ControlFlow.h"
10#include "mlir/Dialect/EmitC/IR/EmitC.h"
11#include "mlir/Dialect/Func/IR/FuncOps.h"
12#include "mlir/IR/BuiltinOps.h"
13#include "mlir/IR/Dialect.h"
14#include "mlir/Target/Cpp/CppEmitter.h"
15#include "mlir/Tools/mlir-translate/Translation.h"
16#include "llvm/Support/CommandLine.h"
17
18using namespace mlir;
19
20namespace mlir {
21
22//===----------------------------------------------------------------------===//
23// Cpp registration
24//===----------------------------------------------------------------------===//
25
26void registerToCppTranslation() {
27 static llvm::cl::opt<bool> declareVariablesAtTop(
28 "declare-variables-at-top",
29 llvm::cl::desc("Declare variables at top when emitting C/C++"),
30 llvm::cl::init(Val: false));
31
32 TranslateFromMLIRRegistration reg(
33 "mlir-to-cpp", "translate from mlir to cpp",
34 [](Operation *op, raw_ostream &output) {
35 return emitc::translateToCpp(
36 op, os&: output,
37 /*declareVariablesAtTop=*/declareVariablesAtTop);
38 },
39 [](DialectRegistry &registry) {
40 // clang-format off
41 registry.insert<cf::ControlFlowDialect,
42 emitc::EmitCDialect,
43 func::FuncDialect>();
44 // clang-format on
45 });
46}
47
48} // namespace mlir
49

source code of mlir/lib/Target/Cpp/TranslateRegistration.cpp