Path: blob/main/contrib/llvm-project/llvm/lib/Object/TapiUniversal.cpp
35232 views
//===- TapiUniversal.cpp --------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the Text-based Dynamic Library Stub format.9//10//===----------------------------------------------------------------------===//1112#include "llvm/Object/TapiUniversal.h"13#include "llvm/ADT/StringRef.h"14#include "llvm/Object/Error.h"15#include "llvm/Object/TapiFile.h"16#include "llvm/TextAPI/ArchitectureSet.h"17#include "llvm/TextAPI/TextAPIReader.h"1819using namespace llvm;20using namespace MachO;21using namespace object;2223TapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err)24: Binary(ID_TapiUniversal, Source) {25Expected<std::unique_ptr<InterfaceFile>> Result = TextAPIReader::get(Source);26ErrorAsOutParameter ErrAsOuParam(&Err);27if (!Result) {28Err = Result.takeError();29return;30}31ParsedFile = std::move(Result.get());3233auto FlattenObjectInfo = [this](const auto &File) {34StringRef Name = File->getInstallName();35for (const Architecture Arch : File->getArchitectures())36Libraries.emplace_back(Library({Name, Arch}));37};3839FlattenObjectInfo(ParsedFile);40// Get inlined documents from tapi file.41for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents())42FlattenObjectInfo(File);43}4445TapiUniversal::~TapiUniversal() = default;4647Expected<std::unique_ptr<TapiFile>>48TapiUniversal::ObjectForArch::getAsObjectFile() const {49return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(),50*Parent->ParsedFile,51Parent->Libraries[Index].Arch);52}5354Expected<std::unique_ptr<TapiUniversal>>55TapiUniversal::create(MemoryBufferRef Source) {56Error Err = Error::success();57std::unique_ptr<TapiUniversal> Ret(new TapiUniversal(Source, Err));58if (Err)59return std::move(Err);60return std::move(Ret);61}626364