1 //===- TapiFile.h - Text-based Dynamic Library Stub -------------*- 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 the TapiFile interface.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_OBJECT_TAPIFILE_H
14 #define LLVM_OBJECT_TAPIFILE_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Object/Binary.h"
18 #include "llvm/Object/ObjectFile.h"
19 #include "llvm/Object/SymbolicFile.h"
20 #include "llvm/Support/Error.h"
21 #include "llvm/Support/MemoryBufferRef.h"
22 #include "llvm/TextAPI/Architecture.h"
23 #include "llvm/TextAPI/InterfaceFile.h"
24 
25 namespace llvm {
26 
27 class raw_ostream;
28 
29 namespace object {
30 
31 class TapiFile : public SymbolicFile {
32 public:
33   TapiFile(MemoryBufferRef Source, const MachO::InterfaceFile &Interface,
34            MachO::Architecture Arch);
35   ~TapiFile() override;
36 
37   void moveSymbolNext(DataRefImpl &DRI) const override;
38 
39   Error printSymbolName(raw_ostream &OS, DataRefImpl DRI) const override;
40 
41   Expected<uint32_t> getSymbolFlags(DataRefImpl DRI) const override;
42 
43   basic_symbol_iterator symbol_begin() const override;
44 
45   basic_symbol_iterator symbol_end() const override;
46 
47   Expected<SymbolRef::Type> getSymbolType(DataRefImpl DRI) const;
48 
hasSegmentInfo()49   bool hasSegmentInfo() { return FileKind >= MachO::FileType::TBD_V5; }
50 
classof(const Binary * v)51   static bool classof(const Binary *v) { return v->isTapiFile(); }
52 
is64Bit()53   bool is64Bit() const override { return MachO::is64Bit(Arch); }
54 
55 private:
56   struct Symbol {
57     StringRef Prefix;
58     StringRef Name;
59     uint32_t Flags;
60     SymbolRef::Type Type;
61 
SymbolSymbol62     constexpr Symbol(StringRef Prefix, StringRef Name, uint32_t Flags,
63                      SymbolRef::Type Type)
64         : Prefix(Prefix), Name(Name), Flags(Flags), Type(Type) {}
65   };
66 
67   std::vector<Symbol> Symbols;
68   MachO::Architecture Arch;
69   MachO::FileType FileKind;
70 };
71 
72 } // end namespace object.
73 } // end namespace llvm.
74 
75 #endif // LLVM_OBJECT_TAPIFILE_H
76