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/TapiFile.h" 16 #include "llvm/TextAPI/TextAPIReader.h" 17 18 using namespace llvm; 19 using namespace MachO; 20 using namespace object; 21 22 TapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err) 23 : Binary(ID_TapiUniversal, Source) { 24 Expected<std::unique_ptr<InterfaceFile>> Result = TextAPIReader::get(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 StringRef Name = File->getInstallName(); 34 for (const Architecture Arch : File->getArchitectures()) 35 Libraries.emplace_back(Library({Name, Arch})); 36 }; 37 38 FlattenObjectInfo(ParsedFile); 39 // Get inlined documents from tapi file. 40 for (const std::shared_ptr<InterfaceFile> &File : ParsedFile->documents()) 41 FlattenObjectInfo(File); 42 } 43 44 TapiUniversal::~TapiUniversal() = default; 45 46 Expected<std::unique_ptr<TapiFile>> 47 TapiUniversal::ObjectForArch::getAsObjectFile() const { 48 return std::make_unique<TapiFile>(Parent->getMemoryBufferRef(), 49 *Parent->ParsedFile, 50 Parent->Libraries[Index].Arch); 51 } 52 53 Expected<std::unique_ptr<TapiUniversal>> 54 TapiUniversal::create(MemoryBufferRef Source) { 55 Error Err = Error::success(); 56 std::unique_ptr<TapiUniversal> Ret(new TapiUniversal(Source, Err)); 57 if (Err) 58 return std::move(Err); 59 return std::move(Ret); 60 } 61