//===- Translation.h - Translation registry ---------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Registry for user-provided translations. // //===----------------------------------------------------------------------===// #ifndef MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H #define MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H #include "mlir/IR/Operation.h" #include "llvm/Support/CommandLine.h" #include <optional> namespace mlir { template <typename OpTy> class OwningOpRef; /// Interface of the function that translates the sources managed by `sourceMgr` /// to MLIR. The source manager has at least one buffer. The implementation /// should create a new MLIR Operation in the given context and return a /// pointer to it, or a nullptr in case of any error. TranslateSourceMgrToMLIRFunction; TranslateRawSourceMgrToMLIRFunction; /// Interface of the function that translates the given string to MLIR. The /// implementation should create a new MLIR Operation in the given context. If /// source-related error reporting is required from within the function, use /// TranslateSourceMgrToMLIRFunction instead. TranslateStringRefToMLIRFunction; /// Interface of the function that translates MLIR to a different format and /// outputs the result to a stream. It is allowed to modify the operation. TranslateFromMLIRFunction; /// Interface of the function that performs file-to-file translation involving /// MLIR. The input file is held in the given MemoryBuffer; the output file /// should be written to the given raw_ostream. The implementation should create /// all MLIR constructs needed during the process inside the given context. This /// can be used for round-tripping external formats through the MLIR system. TranslateFunction; /// Interface of the function that adds all dialects and dialect extensions used /// for the translation to the given DialectRegistry. DialectRegistrationFunction; /// This class contains all of the components necessary for performing a /// translation. class Translation { … }; /// Use Translate[ToMLIR|FromMLIR]Registration as an initializer that /// registers a function and associates it with name. This requires that a /// translation has not been registered to a given name. `inputAlign` is an /// optional expected alignment for the input data. /// /// Usage: /// /// // At file scope. /// namespace mlir { /// void registerTRexToMLIRRegistration() { /// TranslateToMLIRRegistration Unused(&MySubCommand, [] { ... }); /// } /// } // namespace mlir /// /// \{ struct TranslateToMLIRRegistration { … }; struct TranslateFromMLIRRegistration { … }; struct TranslateRegistration { … }; /// \} /// A command line parser for translation functions. struct TranslationParser : public llvm::cl::parser<const Translation *> { … }; /// Register command-line options used by the translation registry. void registerTranslationCLOptions(); } // namespace mlir #endif // MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H