1 //===- TapiUniversal.cpp --------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the Text-based Dynamic Library Stub format.
11 //===----------------------------------------------------------------------===//
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"
21 using namespace MachO
;
22 using namespace object
;
24 TapiUniversal::TapiUniversal(MemoryBufferRef Source
, Error
&Err
)
25 : Binary(ID_TapiUniversal
, Source
) {
26 Expected
<std::unique_ptr
<InterfaceFile
>> Result
= TextAPIReader::get(Source
);
27 ErrorAsOutParameter
ErrAsOuParam(&Err
);
29 Err
= Result
.takeError();
32 ParsedFile
= std::move(Result
.get());
34 auto FlattenObjectInfo
= [this](const auto &File
) {
35 StringRef Name
= File
->getInstallName();
36 for (const Architecture Arch
: File
->getArchitectures())
37 Libraries
.emplace_back(Library({Name
, Arch
}));
40 FlattenObjectInfo(ParsedFile
);
41 // Get inlined documents from tapi file.
42 for (const std::shared_ptr
<InterfaceFile
> &File
: ParsedFile
->documents())
43 FlattenObjectInfo(File
);
46 TapiUniversal::~TapiUniversal() = default;
48 Expected
<std::unique_ptr
<TapiFile
>>
49 TapiUniversal::ObjectForArch::getAsObjectFile() const {
50 return std::make_unique
<TapiFile
>(Parent
->getMemoryBufferRef(),
52 Parent
->Libraries
[Index
].Arch
);
55 Expected
<std::unique_ptr
<TapiUniversal
>>
56 TapiUniversal::create(MemoryBufferRef Source
) {
57 Error Err
= Error::success();
58 std::unique_ptr
<TapiUniversal
> Ret(new TapiUniversal(Source
, Err
));
60 return std::move(Err
);
61 return std::move(Ret
);