LLVM 20.0.0git
TapiFile.cpp
Go to the documentation of this file.
1//===- TapiFile.cpp -------------------------------------------------------===//
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 defines the Text-based Dynamcic Library Stub format.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/StringRef.h"
16#include "llvm/Object/Error.h"
21#include "llvm/TextAPI/Symbol.h"
22
23using namespace llvm;
24using namespace MachO;
25using namespace object;
26
27static uint32_t getFlags(const Symbol *Sym) {
29 if (Sym->isUndefined())
31 else
33
36
37 return Flags;
38}
39
42 if (Sym->isData())
44 else if (Sym->isText())
46
47 return Type;
48}
49
51 Architecture Arch)
52 : SymbolicFile(ID_TapiFile, Source), Arch(Arch),
53 FileKind(Interface.getFileType()) {
54 for (const auto *Symbol : Interface.symbols()) {
55 if (!Symbol->getArchitectures().has(Arch))
56 continue;
57
58 switch (Symbol->getKind()) {
59 case EncodeKind::GlobalSymbol:
60 Symbols.emplace_back(StringRef(), Symbol->getName(), getFlags(Symbol),
62 break;
63 case EncodeKind::ObjectiveCClass:
64 if (Interface.getPlatforms().count(PLATFORM_MACOS) && Arch == AK_i386) {
65 Symbols.emplace_back(ObjC1ClassNamePrefix, Symbol->getName(),
67 } else {
68 Symbols.emplace_back(ObjC2ClassNamePrefix, Symbol->getName(),
70 Symbols.emplace_back(ObjC2MetaClassNamePrefix, Symbol->getName(),
72 }
73 break;
74 case EncodeKind::ObjectiveCClassEHType:
75 Symbols.emplace_back(ObjC2EHTypePrefix, Symbol->getName(),
77 break;
78 case EncodeKind::ObjectiveCInstanceVariable:
79 Symbols.emplace_back(ObjC2IVarPrefix, Symbol->getName(), getFlags(Symbol),
81 break;
82 }
83 }
84}
85
86TapiFile::~TapiFile() = default;
87
88void TapiFile::moveSymbolNext(DataRefImpl &DRI) const { DRI.d.a++; }
89
91 assert(DRI.d.a < Symbols.size() && "Attempt to access symbol out of bounds");
92 const Symbol &Sym = Symbols[DRI.d.a];
93 OS << Sym.Prefix << Sym.Name;
94 return Error::success();
95}
96
98 assert(DRI.d.a < Symbols.size() && "Attempt to access symbol out of bounds");
99 return Symbols[DRI.d.a].Type;
100}
101
103 assert(DRI.d.a < Symbols.size() && "Attempt to access symbol out of bounds");
104 return Symbols[DRI.d.a].Flags;
105}
106
108 DataRefImpl DRI;
109 DRI.d.a = 0;
110 return BasicSymbolRef{DRI, this};
111}
112
114 DataRefImpl DRI;
115 DRI.d.a = Symbols.size();
116 return BasicSymbolRef{DRI, this};
117}
Symbol * Sym
Definition: ELF_riscv.cpp:479
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
static uint32_t getFlags(const Symbol *Sym)
Definition: TapiFile.cpp:27
static SymbolRef::Type getType(const Symbol *Sym)
Definition: TapiFile.cpp:40
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
bool has(Architecture Arch) const
Defines the interface file.
bool isData() const
Definition: Symbol.h:130
bool isWeakDefined() const
Definition: Symbol.h:109
bool isUndefined() const
Definition: Symbol.h:122
ArchitectureSet getArchitectures() const
Definition: Symbol.h:104
StringRef getName() const
Definition: Symbol.h:103
bool isText() const
Definition: Symbol.h:134
EncodeKind getKind() const
Definition: Symbol.h:102
bool isWeakReferenced() const
Definition: Symbol.h:113
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition: SymbolicFile.h:103
unsigned int getType() const
Definition: Binary.h:104
Expected< SymbolRef::Type > getSymbolType(DataRefImpl DRI) const
Definition: TapiFile.cpp:97
void moveSymbolNext(DataRefImpl &DRI) const override
Definition: TapiFile.cpp:88
Expected< uint32_t > getSymbolFlags(DataRefImpl DRI) const override
Definition: TapiFile.cpp:102
basic_symbol_iterator symbol_end() const override
Definition: TapiFile.cpp:113
TapiFile(MemoryBufferRef Source, const MachO::InterfaceFile &Interface, MachO::Architecture Arch)
Definition: TapiFile.cpp:50
Error printSymbolName(raw_ostream &OS, DataRefImpl DRI) const override
Definition: TapiFile.cpp:90
basic_symbol_iterator symbol_begin() const override
Definition: TapiFile.cpp:107
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
constexpr StringLiteral ObjC2IVarPrefix
Definition: Symbol.h:66
constexpr StringLiteral ObjC1ClassNamePrefix
Definition: Symbol.h:62
constexpr StringLiteral ObjC2ClassNamePrefix
Definition: Symbol.h:63
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:27
constexpr StringLiteral ObjC2MetaClassNamePrefix
Definition: Symbol.h:64
constexpr StringLiteral ObjC2EHTypePrefix
Definition: Symbol.h:65
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
struct llvm::object::DataRefImpl::@368 d