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 static llvm::cl::opt<std::string> fileId(
33 "file-id", llvm::cl::desc("Emit emitc.file ops with matching id"),
34 llvm::cl::init(Val: ""));
35
36 TranslateFromMLIRRegistration reg(
37 "mlir-to-cpp", "translate from mlir to cpp",
38 [](Operation *op, raw_ostream &output) {
39 return emitc::translateToCpp(
40 op, os&: output,
41 /*declareVariablesAtTop=*/declareVariablesAtTop,
42 /*fileId=*/fileId);
43 },
44 [](DialectRegistry &registry) {
45 // clang-format off
46 registry.insert<cf::ControlFlowDialect,
47 emitc::EmitCDialect,
48 func::FuncDialect>();
49 // clang-format on
50 });
51}
52
53} // namespace mlir
54

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

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