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/EmitC/IR/EmitC.h"
10 #include "mlir/Dialect/SCF/SCF.h"
11 #include "mlir/Dialect/StandardOps/IR/Ops.h"
12 #include "mlir/IR/BuiltinOps.h"
13 #include "mlir/IR/Dialect.h"
14 #include "mlir/Target/Cpp/CppEmitter.h"
15 #include "mlir/Translation.h"
16 #include "llvm/Support/CommandLine.h"
17 
18 using namespace mlir;
19 
20 namespace mlir {
21 
22 //===----------------------------------------------------------------------===//
23 // Cpp registration
24 //===----------------------------------------------------------------------===//
25 
26 void 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(false));
31 
32   TranslateFromMLIRRegistration reg(
33       "mlir-to-cpp",
34       [](ModuleOp module, raw_ostream &output) {
35         return emitc::translateToCpp(
36             module, output,
37             /*declareVariablesAtTop=*/declareVariablesAtTop);
38       },
39       [](DialectRegistry &registry) {
40         // clang-format off
41         registry.insert<emitc::EmitCDialect,
42                         StandardOpsDialect,
43                         scf::SCFDialect>();
44         // clang-format on
45       });
46 }
47 
48 } // namespace mlir
49