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/Arithmetic/IR/Arithmetic.h"
10 #include "mlir/Dialect/EmitC/IR/EmitC.h"
11 #include "mlir/Dialect/Math/IR/Math.h"
12 #include "mlir/Dialect/SCF/SCF.h"
13 #include "mlir/Dialect/StandardOps/IR/Ops.h"
14 #include "mlir/IR/BuiltinOps.h"
15 #include "mlir/IR/Dialect.h"
16 #include "mlir/Target/Cpp/CppEmitter.h"
17 #include "mlir/Translation.h"
18 #include "llvm/Support/CommandLine.h"
19 
20 using namespace mlir;
21 
22 namespace mlir {
23 
24 //===----------------------------------------------------------------------===//
25 // Cpp registration
26 //===----------------------------------------------------------------------===//
27 
28 void registerToCppTranslation() {
29   static llvm::cl::opt<bool> declareVariablesAtTop(
30       "declare-variables-at-top",
31       llvm::cl::desc("Declare variables at top when emitting C/C++"),
32       llvm::cl::init(false));
33 
34   TranslateFromMLIRRegistration reg(
35       "mlir-to-cpp",
36       [](ModuleOp module, raw_ostream &output) {
37         return emitc::translateToCpp(
38             module, output,
39             /*declareVariablesAtTop=*/declareVariablesAtTop);
40       },
41       [](DialectRegistry &registry) {
42         // clang-format off
43         registry.insert<arith::ArithmeticDialect,
44                         emitc::EmitCDialect,
45                         math::MathDialect,
46                         StandardOpsDialect,
47                         scf::SCFDialect>();
48         // clang-format on
49       });
50 }
51 
52 } // namespace mlir
53