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/Support/MemoryBuffer.h"
17 #include "llvm/TextAPI/MachO/TextAPIReader.h"
18 
19 using namespace llvm;
20 using namespace MachO;
21 using namespace object;
22 
23 TapiUniversal::TapiUniversal(MemoryBufferRef Source, Error &Err)
24     : Binary(ID_TapiUniversal, Source) {
25   auto Result = TextAPIReader::get(Source);
26   ErrorAsOutParameter ErrAsOuParam(&Err);
27   if (!Result) {
28     Err = Result.takeError();
29     return;
30   }
31   ParsedFile = std::move(Result.get());
32 
33   auto Archs = ParsedFile->getArchitectures();
34   for (auto Arch : Archs)
35     Architectures.emplace_back(Arch);
36 }
37 
38 TapiUniversal::~TapiUniversal() = default;
39 
40 Expected<std::unique_ptr<TapiFile>>
41 TapiUniversal::ObjectForArch::getAsObjectFile() const {
42   return std::unique_ptr<TapiFile>(new TapiFile(Parent->getMemoryBufferRef(),
43                                                 *Parent->ParsedFile.get(),
44                                                 Parent->Architectures[Index]));
45 }
46 
47 Expected<std::unique_ptr<TapiUniversal>>
48 TapiUniversal::create(MemoryBufferRef Source) {
49   Error Err = Error::success();
50   std::unique_ptr<TapiUniversal> Ret(new TapiUniversal(Source, Err));
51   if (Err)
52     return std::move(Err);
53   return std::move(Ret);
54 }
55