MLIR 24.0.0git
MlirTranslateMain.h
Go to the documentation of this file.
1//===- MlirTranslateMain.h - MLIR Translation Driver main -------*- C++ -*-===//
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// Main entry function for mlir-translate for when built as standalone binary.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_TOOLS_MLIRTRANSLATE_MLIRTRANSLATEMAIN_H
14#define MLIR_TOOLS_MLIRTRANSLATE_MLIRTRANSLATEMAIN_H
15
16#include "mlir/IR/Diagnostics.h"
17#include "mlir/Support/LLVM.h"
19#include "llvm/ADT/StringRef.h"
20
21#include <memory>
22#include <string>
23#include <utility>
24
25namespace llvm {
26class MemoryBuffer;
27class raw_ostream;
28} // namespace llvm
29
30namespace mlir {
31class Translation;
32
33/// Configuration options for the mlir-translate driver.
35public:
37 allowUnregisteredDialectsFlag = allow;
38 return *this;
39 }
41 return allowUnregisteredDialectsFlag;
42 }
43
45 errorDiagnosticsOnlyFlag = errorOnly;
46 return *this;
47 }
49 return errorDiagnosticsOnlyFlag;
50 }
51
53 splitInputFile(std::string splitMarker = kDefaultSplitMarker) {
54 inputSplitMarker = std::move(splitMarker);
55 return *this;
56 }
57 StringRef getInputSplitMarker() const { return inputSplitMarker; }
58
59 MlirTranslateMainConfig &outputSplitMarker(std::string splitMarker) {
60 outputSplitMarkerFlag = std::move(splitMarker);
61 return *this;
62 }
63 StringRef getOutputSplitMarker() const { return outputSplitMarkerFlag; }
64
67 verifyDiagnosticsLevel = level;
68 return *this;
69 }
71 return verifyDiagnosticsLevel;
72 }
73
74private:
75 bool allowUnregisteredDialectsFlag = false;
76 bool errorDiagnosticsOnlyFlag = false;
77 std::string inputSplitMarker;
78 std::string outputSplitMarkerFlag;
79 SourceMgrDiagnosticVerifierHandler::Level verifyDiagnosticsLevel =
81};
82
83/// Apply the requested translations to an input buffer and write the result to
84/// the output stream.
85LogicalResult mlirTranslateMain(std::unique_ptr<llvm::MemoryBuffer> input,
86 llvm::raw_ostream &output,
87 ArrayRef<const Translation *> translations,
88 const MlirTranslateMainConfig &config = {});
89
90/// Translate to/from an MLIR module from/to an external representation (e.g.
91/// LLVM IR, SPIRV binary, ...). This is the entry point for the implementation
92/// of tools like `mlir-translate`. The translation to perform is parsed from
93/// the command line. The `toolName` argument is used for the header displayed
94/// by `--help`.
95LogicalResult mlirTranslateMain(int argc, char **argv, StringRef toolName);
96} // namespace mlir
97
98#endif // MLIR_TOOLS_MLIRTRANSLATE_MLIRTRANSLATEMAIN_H
Configuration options for the mlir-translate driver.
MlirTranslateMainConfig & outputSplitMarker(std::string splitMarker)
MlirTranslateMainConfig & splitInputFile(std::string splitMarker=kDefaultSplitMarker)
StringRef getOutputSplitMarker() const
StringRef getInputSplitMarker() const
MlirTranslateMainConfig & verifyDiagnostics(SourceMgrDiagnosticVerifierHandler::Level level)
SourceMgrDiagnosticVerifierHandler::Level getVerifyDiagnosticsLevel() const
MlirTranslateMainConfig & errorDiagnosticsOnly(bool errorOnly)
MlirTranslateMainConfig & allowUnregisteredDialects(bool allow)
This class contains all of the components necessary for performing a translation.
Definition Translation.h:61
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:227
Include the generated interface declarations.
LogicalResult mlirTranslateMain(std::unique_ptr< llvm::MemoryBuffer > input, llvm::raw_ostream &output, ArrayRef< const Translation * > translations, const MlirTranslateMainConfig &config={})
Apply the requested translations to an input buffer and write the result to the output stream.
const char *const kDefaultSplitMarker