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