1//===- ToolUtilities.h - MLIR Tool Utilities --------------------*- 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// This file declares common utilities for implementing MLIR tools.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_SUPPORT_TOOLUTILITIES_H
14#define MLIR_SUPPORT_TOOLUTILITIES_H
15
16#include "mlir/Support/LLVM.h"
17#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/StringRef.h"
19
20#include <memory>
21
22namespace llvm {
23class MemoryBuffer;
24} // namespace llvm
25
26namespace mlir {
27struct LogicalResult;
28
29using ChunkBufferHandler = function_ref<LogicalResult(
30 std::unique_ptr<llvm::MemoryBuffer> chunkBuffer, raw_ostream &os)>;
31
32extern inline const char *const kDefaultSplitMarker = "// -----";
33
34/// Splits the specified buffer on a marker (`// -----` by default), processes
35/// each chunk independently according to the normal `processChunkBuffer` logic,
36/// and writes all results to `os`.
37///
38/// This is used to allow a large number of small independent tests to be put
39/// into a single file. The input split marker is configurable. If it is empty,
40/// merging is disabled, which allows for merging split and non-split code
41/// paths. Output split markers (`//-----` by default) followed by a new line
42/// character, respectively, are placed between each of the processed output
43/// chunks. (The new line character is inserted even if the split marker is
44/// empty.)
45LogicalResult
46splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer> originalBuffer,
47 ChunkBufferHandler processChunkBuffer, raw_ostream &os,
48 llvm::StringRef inputSplitMarker = kDefaultSplitMarker,
49 llvm::StringRef outputSplitMarker = "");
50} // namespace mlir
51
52#endif // MLIR_SUPPORT_TOOLUTILITIES_H
53

source code of mlir/include/mlir/Support/ToolUtilities.h