llvm-project
62 строки · 2.1 Кб
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
13#include "llvm/Object/TapiUniversal.h"
14#include "llvm/ADT/StringRef.h"
15#include "llvm/Object/Error.h"
16#include "llvm/Object/TapiFile.h"
17#include "llvm/TextAPI/ArchitectureSet.h"
18#include "llvm/TextAPI/TextAPIReader.h"
19
20using namespace llvm;
21using namespace MachO;
22using namespace object;
23
24TapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err)
25: Binary(ID_TapiUniversal, Source) {
26Expected<std::unique_ptr<InterfaceFile>> Result = TextAPIReader::get(Source);
27ErrorAsOutParameter ErrAsOuParam(&Err);
28if (!Result) {
29Err = Result.takeError();
30return;
31}
32ParsedFile = std::move(Result.get());
33
34auto FlattenObjectInfo = [this](const auto &File) {
35StringRef Name = File->getInstallName();
36for (const Architecture Arch : File->getArchitectures())
37Libraries.emplace_back(Library({Name, Arch}));
38};
39
40FlattenObjectInfo(ParsedFile);
41// Get inlined documents from tapi file.
42for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents())
43FlattenObjectInfo(File);
44}
45
46TapiUniversal::~TapiUniversal() = default;
47
48Expected<std::unique_ptr<TapiFile>>
49TapiUniversal::ObjectForArch::getAsObjectFile() const {
50return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(),
51*Parent->ParsedFile,
52Parent->Libraries[Index].Arch);
53}
54
55Expected<std::unique_ptr<TapiUniversal>>
56TapiUniversal::create(MemoryBufferRef Source) {
57Error Err = Error::success();
58std::unique_ptr<TapiUniversal> Ret(new TapiUniversal(Source, Err));
59if (Err)
60return std::move(Err);
61return std::move(Ret);
62}
63