1//===- FileUtilities.h - utilities for working with files -------*- 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// Common utilities for working with files.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_SUPPORT_FILEUTILITIES_H_
14#define MLIR_SUPPORT_FILEUTILITIES_H_
15
16#include <memory>
17#include <string>
18
19namespace llvm {
20struct Align;
21class MemoryBuffer;
22class ToolOutputFile;
23class StringRef;
24} // namespace llvm
25
26namespace mlir {
27
28/// Open the file specified by its name for reading. Write the error message to
29/// `errorMessage` if errors occur and `errorMessage` is not nullptr.
30std::unique_ptr<llvm::MemoryBuffer>
31openInputFile(llvm::StringRef inputFilename,
32 std::string *errorMessage = nullptr);
33/// Open the file specified by its name for reading, with the given buffer
34/// alignment constraint. Write the error message to `errorMessage` if errors
35/// occur and `errorMessage` is not nullptr.
36std::unique_ptr<llvm::MemoryBuffer>
37openInputFile(llvm::StringRef inputFilename, llvm::Align alignment,
38 std::string *errorMessage = nullptr);
39
40/// Open the file specified by its name for writing. Write the error message to
41/// `errorMessage` if errors occur and `errorMessage` is not nullptr.
42std::unique_ptr<llvm::ToolOutputFile>
43openOutputFile(llvm::StringRef outputFilename,
44 std::string *errorMessage = nullptr);
45
46} // namespace mlir
47
48#endif // MLIR_SUPPORT_FILEUTILITIES_H_
49

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