| 1 | //===- TranslationRegistration.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/Target/IRDLToCpp/TranslationRegistration.h" |
| 10 | #include "mlir/Dialect/IRDL/IR/IRDL.h" |
| 11 | #include "mlir/IR/BuiltinOps.h" |
| 12 | #include "mlir/Target/IRDLToCpp/IRDLToCpp.h" |
| 13 | #include "mlir/Tools/mlir-translate/Translation.h" |
| 14 | #include "llvm/ADT/TypeSwitch.h" |
| 15 | #include "llvm/Support/Casting.h" |
| 16 | |
| 17 | using namespace mlir; |
| 18 | |
| 19 | namespace mlir { |
| 20 | |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | // Translation registration |
| 23 | //===----------------------------------------------------------------------===// |
| 24 | |
| 25 | void registerIRDLToCppTranslation() { |
| 26 | TranslateFromMLIRRegistration reg( |
| 27 | "irdl-to-cpp" , "translate IRDL dialect definitions to C++ definitions" , |
| 28 | [](Operation *op, raw_ostream &output) { |
| 29 | return TypeSwitch<Operation *, LogicalResult>(op) |
| 30 | .Case<irdl::DialectOp>([&](irdl::DialectOp dialectOp) { |
| 31 | return irdl::translateIRDLDialectToCpp(dialectOp, output); |
| 32 | }) |
| 33 | .Case<ModuleOp>([&](ModuleOp moduleOp) { |
| 34 | for (Operation &op : moduleOp.getBody()->getOperations()) |
| 35 | if (auto dialectOp = llvm::dyn_cast<irdl::DialectOp>(op)) |
| 36 | if (failed( |
| 37 | irdl::translateIRDLDialectToCpp(dialectOp, output))) |
| 38 | return failure(); |
| 39 | return success(); |
| 40 | }) |
| 41 | .Default([](Operation *op) { |
| 42 | return op->emitError( |
| 43 | "unsupported operation for IRDL to C++ translation" ); |
| 44 | }); |
| 45 | }, |
| 46 | [](DialectRegistry ®istry) { registry.insert<irdl::IRDLDialect>(); }); |
| 47 | } |
| 48 | |
| 49 | } // namespace mlir |
| 50 | |