17330f729Sjoerg //===- TapiUniversal.cpp --------------------------------------------------===// 27330f729Sjoerg // 37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information. 57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 67330f729Sjoerg // 77330f729Sjoerg //===----------------------------------------------------------------------===// 87330f729Sjoerg // 97330f729Sjoerg // This file defines the Text-based Dynamic Library Stub format. 107330f729Sjoerg // 117330f729Sjoerg //===----------------------------------------------------------------------===// 127330f729Sjoerg 137330f729Sjoerg #include "llvm/Object/TapiUniversal.h" 147330f729Sjoerg #include "llvm/ADT/StringRef.h" 157330f729Sjoerg #include "llvm/Object/Error.h" 167330f729Sjoerg #include "llvm/Support/MemoryBuffer.h" 17*82d56013Sjoerg #include "llvm/TextAPI/TextAPIReader.h" 187330f729Sjoerg 197330f729Sjoerg using namespace llvm; 207330f729Sjoerg using namespace MachO; 217330f729Sjoerg using namespace object; 227330f729Sjoerg TapiUniversal(MemoryBufferRef Source,Error & Err)237330f729SjoergTapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err) 247330f729Sjoerg : Binary(ID_TapiUniversal, Source) { 25*82d56013Sjoerg Expected<std::unique_ptr<InterfaceFile>> Result = TextAPIReader::get(Source); 267330f729Sjoerg ErrorAsOutParameter ErrAsOuParam(&Err); 277330f729Sjoerg if (!Result) { 287330f729Sjoerg Err = Result.takeError(); 297330f729Sjoerg return; 307330f729Sjoerg } 317330f729Sjoerg ParsedFile = std::move(Result.get()); 327330f729Sjoerg 33*82d56013Sjoerg auto FlattenObjectInfo = [this](const auto &File) { 34*82d56013Sjoerg StringRef Name = File->getInstallName(); 35*82d56013Sjoerg for (const Architecture Arch : File->getArchitectures()) 36*82d56013Sjoerg Libraries.emplace_back(Library({Name, Arch})); 37*82d56013Sjoerg }; 38*82d56013Sjoerg 39*82d56013Sjoerg FlattenObjectInfo(ParsedFile); 40*82d56013Sjoerg // Get inlined documents from tapi file. 41*82d56013Sjoerg for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents()) 42*82d56013Sjoerg FlattenObjectInfo(File); 437330f729Sjoerg } 447330f729Sjoerg 457330f729Sjoerg TapiUniversal::~TapiUniversal() = default; 467330f729Sjoerg 477330f729Sjoerg Expected<std::unique_ptr<TapiFile>> getAsObjectFile() const487330f729SjoergTapiUniversal::ObjectForArch::getAsObjectFile() const { 497330f729Sjoerg return std::unique_ptr<TapiFile>(new TapiFile(Parent->getMemoryBufferRef(), 507330f729Sjoerg *Parent->ParsedFile.get(), 51*82d56013Sjoerg Parent->Libraries[Index].Arch)); 527330f729Sjoerg } 537330f729Sjoerg 547330f729Sjoerg Expected<std::unique_ptr<TapiUniversal>> create(MemoryBufferRef Source)557330f729SjoergTapiUniversal::create(MemoryBufferRef Source) { 567330f729Sjoerg Error Err = Error::success(); 577330f729Sjoerg std::unique_ptr<TapiUniversal> Ret(new TapiUniversal(Source, Err)); 587330f729Sjoerg if (Err) 597330f729Sjoerg return std::move(Err); 607330f729Sjoerg return std::move(Ret); 617330f729Sjoerg } 62