xref: /freebsd/contrib/llvm-project/llvm/include/llvm/TextAPI/TextAPIWriter.h (revision d98f4f0698ef0c5178882c544b4c38542d4780f0)
1 //===--- TextAPIWriter.h - Text API Writer ----------------------*- 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 #ifndef LLVM_TEXTAPI_TEXTAPIWRITER_H
10 #define LLVM_TEXTAPI_TEXTAPIWRITER_H
11 
12 #include "llvm/ADT/StringSwitch.h"
13 #include "llvm/Support/Compiler.h"
14 #include "llvm/TextAPI/InterfaceFile.h"
15 
16 namespace llvm {
17 
18 class Error;
19 class raw_ostream;
20 
21 namespace MachO {
22 
23 class TextAPIWriter {
24 public:
25   TextAPIWriter() = delete;
26 
27   /// Write TAPI text file contents into stream.
28   ///
29   /// \param OS Stream to write to.
30   /// \param File Library attributes to write as text file.
31   /// \param FileKind File format to write text file as. If not specified, it
32   /// will read from File.
33   /// \param Compact Whether to limit whitespace in text file.
34   LLVM_ABI static Error
35   writeToStream(raw_ostream &OS, const InterfaceFile &File,
36                 const FileType FileKind = FileType::Invalid,
37                 bool Compact = false);
38 
39   /// Get TAPI FileType from the input string.
40   ///
41   /// \param FT String of input to map to FileType.
42   static FileType parseFileType(const StringRef FT) {
43     return StringSwitch<FileType>(FT)
44         .Case("tbd-v1", FileType::TBD_V1)
45         .Case("tbd-v2", FileType::TBD_V2)
46         .Case("tbd-v3", FileType::TBD_V3)
47         .Case("tbd-v4", FileType::TBD_V4)
48         .Case("tbd-v5", FileType::TBD_V5)
49         .Default(FileType::Invalid);
50   }
51 };
52 
53 } // end namespace MachO.
54 } // end namespace llvm.
55 
56 #endif // LLVM_TEXTAPI_TEXTAPIWRITER_H
57