• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
19 
20 namespace llvm {
21 class MemoryBuffer;
22 }
23 
24 namespace mlir {
25 struct LogicalResult;
26 
27 using ChunkBufferHandler = function_ref<LogicalResult(
28     std::unique_ptr<llvm::MemoryBuffer> chunkBuffer, raw_ostream &os)>;
29 
30 /// Splits the specified buffer on a marker (`// -----`), processes each chunk
31 /// independently according to the normal `processChunkBuffer` logic, and writes
32 /// all results to `os`.
33 ///
34 /// This is used to allow a large number of small independent tests to be put
35 /// into a single file.
36 LogicalResult
37 splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer> originalBuffer,
38                       ChunkBufferHandler processChunkBuffer, raw_ostream &os);
39 } // namespace mlir
40 
41 #endif // MLIR_SUPPORT_TOOLUTILITIES_H
42