MLIR  21.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 
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(""));
35 
37  "mlir-to-cpp", "translate from mlir to cpp",
38  [](Operation *op, raw_ostream &output) {
39  return emitc::translateToCpp(
40  op, 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
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()