LLVM 22.0.0git
TapiUniversal.cpp
Go to the documentation of this file.
1//===- TapiUniversal.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 Dynamic Library Stub format.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/StringRef.h"
17
18using namespace llvm;
19using namespace MachO;
20using namespace object;
21
23 : Binary(ID_TapiUniversal, Source) {
25 ErrorAsOutParameter ErrAsOuParam(Err);
26 if (!Result) {
27 Err = Result.takeError();
28 return;
29 }
30 ParsedFile = std::move(Result.get());
31
32 auto FlattenObjectInfo = [this](const auto &File,
33 std::optional<size_t> DocIdx = std::nullopt) {
34 StringRef Name = File->getInstallName();
35 for (const Architecture Arch : File->getArchitectures())
36 Libraries.emplace_back(Library({Name, Arch, DocIdx}));
37 };
38 FlattenObjectInfo(ParsedFile);
39 // Get inlined documents from tapi file.
40 size_t DocIdx = 0;
41 for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents())
42 FlattenObjectInfo(File, DocIdx++);
43}
44
46
49 const auto &InlinedDocuments = Parent->ParsedFile->documents();
50 const Library &CurrLib = Parent->Libraries[Index];
51 assert(
52 (isTopLevelLib() || (CurrLib.DocumentIdx.has_value() &&
53 (InlinedDocuments.size() > *CurrLib.DocumentIdx))) &&
54 "Index into documents exceeds the container for them");
56 ? Parent->ParsedFile.get()
57 : InlinedDocuments[*CurrLib.DocumentIdx].get();
58 return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(), *IF,
59 CurrLib.Arch);
60}
61
64 Error Err = Error::success();
65 std::unique_ptr<TapiUniversal> Ret(new TapiUniversal(Source, Err));
66 if (Err)
67 return std::move(Err);
68 return std::move(Ret);
69}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
std::string Name
Helper for Errors used as out-parameters.
Definition: Error.h:1144
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
Tagged union holding either a T or a Error.
Definition: Error.h:485
Defines the interface file.
static LLVM_ABI Expected< std::unique_ptr< InterfaceFile > > get(MemoryBufferRef InputBuffer)
Parse and get an InterfaceFile that represents the full library.
Definition: TextStub.cpp:1098
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
MemoryBufferRef getMemoryBufferRef() const
Definition: Binary.cpp:43
LLVM_ABI Expected< std::unique_ptr< TapiFile > > getAsObjectFile() const
TapiUniversal(MemoryBufferRef Source, Error &Err)
static Expected< std::unique_ptr< TapiUniversal > > create(MemoryBufferRef Source)
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:28
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18