MLIR  19.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 
12 #include "mlir/IR/BuiltinOps.h"
13 #include "mlir/IR/Dialect.h"
16 #include "llvm/Support/CommandLine.h"
17 
18 using namespace mlir;
19 
20 namespace mlir {
21 
22 //===----------------------------------------------------------------------===//
23 // Cpp registration
24 //===----------------------------------------------------------------------===//
25 
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 
33  "mlir-to-cpp", "translate from mlir to cpp",
34  [](Operation *op, raw_ostream &output) {
35  return emitc::translateToCpp(
36  op, 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
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)
Translates the given operation to C++ code.
Include the generated interface declarations.
void registerToCppTranslation()