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 | |
19 | namespace llvm { |
20 | struct Align; |
21 | class MemoryBuffer; |
22 | class ToolOutputFile; |
23 | class StringRef; |
24 | } // namespace llvm |
25 | |
26 | namespace 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. |
30 | std::unique_ptr<llvm::MemoryBuffer> |
31 | openInputFile(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. |
36 | std::unique_ptr<llvm::MemoryBuffer> |
37 | openInputFile(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. |
42 | std::unique_ptr<llvm::ToolOutputFile> |
43 | openOutputFile(llvm::StringRef outputFilename, |
44 | std::string *errorMessage = nullptr); |
45 | |
46 | } // namespace mlir |
47 | |
48 | #endif // MLIR_SUPPORT_FILEUTILITIES_H_ |
49 | |