52 lines · cpp
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-exception6//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/Target/Cpp/CppEmitter.h"13#include "mlir/Tools/mlir-translate/Translation.h"14#include "llvm/Support/CommandLine.h"15 16using namespace mlir;17 18namespace mlir {19 20//===----------------------------------------------------------------------===//21// Cpp registration22//===----------------------------------------------------------------------===//23 24void registerToCppTranslation() {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 34 TranslateFromMLIRRegistration reg(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 ®istry) {43 // clang-format off44 registry.insert<cf::ControlFlowDialect,45 emitc::EmitCDialect,46 func::FuncDialect>();47 // clang-format on48 });49}50 51} // namespace mlir52