MLIR  22.0.0git
TranslateRegistration.cpp
Go to the documentation of this file.
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 
14 #include "llvm/Support/CommandLine.h"
15 
16 using namespace mlir;
17 
18 namespace mlir {
19 
20 //===----------------------------------------------------------------------===//
21 // Cpp registration
22 //===----------------------------------------------------------------------===//
23 
25  static llvm::cl::opt<bool> declareVariablesAtTop(
26  "declare-variables-at-top",
27  llvm::cl::desc("Declare variables at top when emitting C/C++"),
28  llvm::cl::init(false));
29 
30  static llvm::cl::opt<std::string> fileId(
31  "file-id", llvm::cl::desc("Emit emitc.file ops with matching id"),
32  llvm::cl::init(""));
33 
35  "mlir-to-cpp", "translate from mlir to cpp",
36  [](Operation *op, raw_ostream &output) {
37  return emitc::translateToCpp(
38  op, output,
39  /*declareVariablesAtTop=*/declareVariablesAtTop,
40  /*fileId=*/fileId);
41  },
42  [](DialectRegistry &registry) {
43  // clang-format off
44  registry.insert<cf::ControlFlowDialect,
45  emitc::EmitCDialect,
46  func::FuncDialect>();
47  // clang-format on
48  });
49 }
50 
51 } // namespace mlir
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
LogicalResult translateToCpp(Operation *op, raw_ostream &os, bool declareVariablesAtTop=false, StringRef fileId={})
Translates the given operation to C++ code.
Include the generated interface declarations.
void registerToCppTranslation()